resourcelinker.inc.php 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Patrick Cool - original version
  5. * @author Denes Nagy - further improvements for learning path builder
  6. * @author Roan Embrechts - refactoring to improve code organisation
  7. * @package chamilo.resourcelinker
  8. * @todo use the constants for the tools
  9. * @todo use Database API instead of creating table names locally.
  10. */
  11. /* INIT SECTION */
  12. //$language_file = 'resourcelinker';
  13. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  14. $use_anonymous = true;
  15. require_once 'back_compat.inc.php';
  16. require_once api_get_path(SYS_CODE_PATH).'lang/english/resourcelinker.inc.php';
  17. if (!empty($_course['language'])){
  18. $resource_linker_file = api_get_path(SYS_CODE_PATH).'lang/'.$_course['language'].'/resourcelinker.inc.php';
  19. if (file_exists($resource_linker_file)) {
  20. require_once $resource_linker_file;
  21. }
  22. }
  23. require_once '../exercice/hotpotatoes.lib.php';
  24. /* FUNCTIONS */
  25. function unset_session_resources() {
  26. $_SESSION['addedresource'] = '';
  27. $_SESSION['addedresourceid'] = '';
  28. api_session_unregister(addedresource);
  29. api_session_unregister(addedresourceid);
  30. }
  31. /**
  32. * Insert description here.
  33. */
  34. function show_folder_up() {
  35. global $folder;
  36. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  37. $level = get_levels($folder);
  38. if ($level == 1) {
  39. echo "<a href='".api_get_self()."?content=Document&amp;source_forum=".$_GET['source_forum']."&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'><img src='../img/folder_up.gif' border='0' />".get_lang('LevelUp')."</a>";
  40. }
  41. if ($level && $level != 0 && $level != 1) {
  42. $folder_up=$folder;
  43. $folder_temp=explode('/',$folder);
  44. $last=count($folder_temp)-1;
  45. unset($folder_temp[$last]);
  46. $folder_up=implode('/',$folder_temp);
  47. echo "<a href='".api_get_self()."?content=Document&amp;source_forum=".$_GET['source_forum']."&amp;folder=$folder_up&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'><img src='../img/folder_up.gif' border='0' />".get_lang('LevelUp')."</a>";
  48. }
  49. }
  50. /**
  51. * Shows the documents of the document tool
  52. * @param $folder
  53. */
  54. function show_documents($folder) {
  55. global $_course;
  56. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  57. // Documents are a special case: The teacher can add an invisible document (it will be viewable by the user)
  58. // other tools do not have this feature.
  59. if (is_allowed_to_edit()) {
  60. $visibility = "ip.visibility<>'2'";
  61. } else {
  62. $visibility = "ip.visibility='1'";
  63. }
  64. $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  65. $document_table = Database::get_course_table(TABLE_DOCUMENT);
  66. $sql = "SELECT * from $document_table docs , $item_property_table ip WHERE docs.id=ip.ref AND ip.tool = '".TOOL_DOCUMENT."' AND $visibility AND ip.to_group_id = 0 AND ip.to_user_id IS NULL ORDER BY docs.path ASC";
  67. $result = Database::query($sql);
  68. while ($row = Database::fetch_array($result)) {
  69. if (!$folder) {
  70. if (get_levels($row['path'])-1 == 1) {
  71. // showing the right icon.
  72. if (file_or_folder($row['path'])) {
  73. echo '<img src="../img/file.gif" align="middle" />';
  74. } else {
  75. $image = choose_image($row['path']);
  76. echo "<img src=\"../img/$image\" align=\"middle\" />";
  77. }
  78. // Folders should be clickable.
  79. if (file_or_folder($row['path'])) {
  80. echo "<a href='".api_get_self()."?content=Document";
  81. echo "&folder=".substr($row['path'], 1)."&source_id=$source_id&source_forum=".$_GET['source_forum']."&action=$action&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no'>".substr($row['path'], 1).'</a><br />';
  82. } else {
  83. echo substr($row['path'], 1).' ';
  84. echo showorhide_addresourcelink('Document',$row['id']);
  85. echo '<br />';
  86. }
  87. }
  88. } else {
  89. // We calculate the level we are in by using the $folder in the url.
  90. // We put +1 because it does not start with an / and in the database it does
  91. $level = get_levels($folder) + 1;
  92. // We calculate each level of the database entry.
  93. $file_level=get_levels($row['path'])-1;
  94. // If the level of the database entry is equal to the level we ar in, we put it into an array
  95. // as this is a potential good entry.
  96. if ($file_level == $level) {
  97. $good_paths[] = $row['path'];
  98. $good_ids[] = $row['id'];
  99. }
  100. //$haystack=$row['path'];
  101. //$conform_folder=strstr($haystack, $folder);
  102. //if (str_replace($folder.'/', '', $conform_folder) !== $folder) {
  103. // $good_folders[] = $row['path'];
  104. //echo str_replace($folder.'/', '', $conform_folder);
  105. // echo '<br />';
  106. // }// if (str_replace($folder.'/','',$conform_folder)!==$folder)
  107. } // else (if (!$folder))
  108. } //while ($row=Database::fetch_array($result))
  109. // This is code for the case that we are in a subfolder.
  110. if ($good_paths) {
  111. // We have all the potential good database entries, the good ones are those that start with $folder
  112. foreach ($good_paths as $path) {
  113. if (strstr($path, $folder)) {
  114. $good_key = key($good_paths);
  115. // Showing the right icon.
  116. if (file_or_folder($path)) {
  117. echo '<img src="../img/file.gif" align="middle" />';
  118. } else {
  119. $image = choose_image($path);
  120. echo "<img src=\"../img/$image\" align=\"middle\" />";
  121. }
  122. // Folders should be clickable
  123. if (file_or_folder($path)) {
  124. $path = substr($path, 1); // Remove the first / in folder_up.
  125. $uri = str_replace($folder, $path, $_SERVER['REQUEST_URI']);
  126. $newuri = str_replace('add=', 'addnot=', $uri);
  127. // Using the correct name of the folder.
  128. $folder_name = str_replace($folder.'/', '', $path);
  129. echo "<a href='$newuri'>".$folder_name.'</a><br />';
  130. } else {
  131. echo str_replace("/$folder/", '', $path).' ';
  132. echo showorhide_addresourcelink('Document', $good_ids[$good_key]);
  133. echo '<br />';
  134. }
  135. }
  136. next($good_paths);
  137. }
  138. }
  139. }
  140. /**
  141. * Checks wether something is a file or a folder
  142. * 0 means file, 1 means folder
  143. * @param $filefolder
  144. * @todo: use true and false instead of 1 and 0.
  145. */
  146. function file_or_folder($filefolder) {
  147. global $_course;
  148. global $baseServDir;
  149. $courseDir = $_course['path'].'/document';
  150. $baseWorkDir = api_get_path(SYS_COURSE_PATH).$courseDir;
  151. return (is_dir($baseWorkDir.$filefolder) ? 1 : 0);
  152. }
  153. /**
  154. * Inserts a resource into the database
  155. *
  156. * @param $source_type
  157. * @param $source_id
  158. */
  159. function store_resources($source_type, $source_id) {
  160. global $_course;
  161. $resource_table = Database::get_course_table(TABLE_LINKED_RESOURCES);
  162. $addedresource = $_SESSION['addedresource'];
  163. $addedresourceid = $_SESSION['addedresourceid'];
  164. if ($_SESSION['addedresource']) {
  165. foreach ($addedresource as $resource_type) {
  166. $sql="INSERT INTO $resource_table (source_type, source_id, resource_type, resource_id) VALUES ('$source_type', '$source_id', '$resource_type', '".$addedresourceid[key($addedresource)]."')";
  167. Database::query($sql);
  168. $i=key($addedresource);
  169. next($addedresource);
  170. }
  171. $_SESSION['addedresource']='';
  172. $_SESSION['addedresourceid']='';
  173. }
  174. }
  175. /**
  176. * DEPRECATED - use rl_get_resource_link() instead - DEPRECATED
  177. * Displays the link that opens a new browser window that views the added resource.
  178. *
  179. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  180. * @param $type the type of the tool
  181. * @param $id the id of the resource
  182. * @param $style this is used to style the link (for instance when a resource is hidden => the added resources should also be styled like they are hidden)
  183. * @todo use the constants for the type definitions.
  184. */
  185. function display_addedresource_link($type, $id, $style = '') {
  186. global $_course;
  187. // Styling the link of the added resource.
  188. if ($style != '') {
  189. $styling = ' class="'.$style.'"';
  190. }
  191. switch ($type) {
  192. case 'Agenda':
  193. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA,$_course['dbName']);
  194. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE id=$id");
  195. $myrow = Database::fetch_array($result);
  196. echo '<img src="../img/agenda.gif" align="middle" /> <a href="../calendar/agenda.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
  197. break;
  198. case 'Ad_Valvas':
  199. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT,$_course['dbName']);
  200. $result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id");
  201. $myrow = Database::fetch_array($result);
  202. echo '<img src="../img/valves.gif" align="middle" /> <a href="../announcements/announcements.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
  203. break;
  204. case 'Link':
  205. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK,$_course['dbName']);
  206. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$id");
  207. $myrow = Database::fetch_array($result);
  208. echo '<img src="../img/links.gif" align="middle" /> <a href="#" onclick="javascript:window.open(\'../link/link_goto.php?link_id='.$myrow['id'].'&amp;link_url='.urlencode($myrow['url'])."','MyWindow','width=500,height=400,top='+((screen.height-400)/2)+',left='+((screen.width-500)/2)+',scrollbars=1,resizable=1,menubar=1'); return false;\"".$styling.'>'.$myrow['title']."</a><br />\n";
  209. break;
  210. case 'Exercise':
  211. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST,$_course['dbName']);
  212. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE id=$id");
  213. $myrow = Database::fetch_array($result);
  214. echo '<img src="../img/quiz.gif" align="middle" /> <a href="../exercice/exercice_submit.php?exerciseId='.$myrow['id'].'"'.$styling.'>'.$myrow['title']."</a><br />\n";
  215. break;
  216. case 'Forum':
  217. //incredibly deprecated (2011-02-09)
  218. $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums';
  219. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id");
  220. $myrow = Database::fetch_array($result);
  221. echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewforum.php?forum='.$myrow['forum_id'].'&amp;md5='.$myrow['md5'].'"'.$styling.'>'.$myrow['forum_name']."</a><br />\n";
  222. break;
  223. case 'Thread': //=topics
  224. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  225. $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text';
  226. $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums';
  227. $result = Database::query("SELECT * FROM $tbl_posts posts, $TBL_FORUMS forum WHERE forum.forum_id=posts.forum_id and post_id=$id");
  228. $myrow = Database::fetch_array($result);
  229. // grabbing the title of the post
  230. $sql_title = "SELECT * FROM $tbl_posts_text WHERE post_id=".$myrow["post_id"];
  231. $result_title = Database::query($sql_title);
  232. $myrow_title = Database::fetch_array($result_title);
  233. echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$myrow['topic_id'].'&amp;forum='.$myrow['forum_id'].'&amp;md5='.$myrow['md5'].'"'.$styling.'>'.$myrow_title['post_title']."</a><br />\n";
  234. break;
  235. case 'Post':
  236. $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['dbName']);
  237. $sql = "SELECT * FROM $tbl_post p WHERE post_id = $id";
  238. $result = Database::query($sql);
  239. $post = Database::fetch_object($result);
  240. echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$post->topic_id.'&amp;forum='.$post->forum_id.'"'.$styling.'>'.$post->post_title."</a><br />\n";
  241. break;
  242. case 'Document':
  243. $dbTable = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']);
  244. $result = Database::query("SELECT * FROM $dbTable WHERE id=$id");
  245. $myrow = Database::fetch_array($result);
  246. $pathname = explode('/',$myrow['path']); // Making a correct name for the link.
  247. $last = count($pathname) - 1; // Making a correct name for the link.
  248. $filename = $pathname[$last]; // Making a correct name for the link.
  249. $image = choose_image($filename);
  250. $ext = explode('.', $filename);
  251. $ext = strtolower($ext[sizeof($ext)-1]);
  252. $myrow['path'] = rawurlencode($myrow['path']);
  253. $array_ext=array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png');
  254. if (api_browser_support('svg')){
  255. $array_ext[]='svg';
  256. }
  257. if (api_browser_support('ogg')){
  258. $array_ext[]='ogg';
  259. }
  260. $in_frames = in_array($ext, $array_ext);
  261. echo '<img src="../img/'.$image.'" align="middle" /> <a href="../document/'.($in_frames ? 'showinframes.php?file=' : 'download.php?doc_url=').$myrow['path'].'"'.$styling.'>'.$filename."</a><br />\n";
  262. break;
  263. case 'Externallink':
  264. echo '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.'>'.$id."</a><br />\n";
  265. break;
  266. }
  267. }
  268. /**
  269. * This function is to display the added resources (lessons) in the learning path player and builder
  270. * this function is a modification of display_addedresource_link($type, $id) function
  271. * the two ids are a bit confusing, I admit, but I did not want to change Patrick's work, I was
  272. * building upon it. - Denes
  273. *
  274. * Parameters:
  275. * @param completed - if ="completed" then green presentation with checkbox
  276. * @param id_in_path - if onclick then this lesson will be considered completed, that is the unique index in the items table
  277. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  278. * @param type - that is the correspondent type in the mirror tool (like this is a Link item)
  279. * @param builder - if ="builder" then onclick shows in new window
  280. * @param icon - if ="icon" then the small icon will appear
  281. * if ="wrap" then wrapped settings are used (and no icon is displayed)
  282. * if ="nolink" then only the name is returned with no href and no icon (note:only in this case, the result is not displayed, but returned)
  283. * @todo this function is too long, rewrite
  284. */
  285. function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_path, $builder, $icon, $level = 0) {
  286. global $_course, $learnpath_id, $tbl_learnpath_item, $items;
  287. global $curDirPath, $_configuration, $enableDocumentParsing, $_course, $_user, $_cid;
  288. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM,$_course['dbName']);
  289. $hyperlink_target_parameter = ''; //or e.g. 'target="_blank"'
  290. $length = ((($builder == 'builder') && ($icon == 'nolink')) ? 65 : 32);
  291. if ($builder != 'builder') $origin = 'learnpath'; //origin = learnpath in student view
  292. $linktype = $type;
  293. if (($type == 'Link _self') or ($type == 'Link _blank')) $type = 'Link';
  294. // YW switched litteral tool names to use of constants declared in main_api.lib.php
  295. switch ($type) {
  296. case TOOL_CALENDAR_EVENT:
  297. case 'Agenda':
  298. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA,$_course['dbName']);
  299. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE id=$id");
  300. $myrow = Database::fetch_array($result);
  301. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  302. $result = Database::query($sql); $row = Database::fetch_array($result);
  303. if ($row['title'] != '') { $myrow['title'] = $row['title']; }
  304. $desc = $row['description'];
  305. $agenda_id = $row['item_id'];
  306. echo str_repeat("&nbsp;&gt;", $level);
  307. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  308. if ($icon != 'nolink') {
  309. if ($completed == 'completed') {
  310. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  311. } else {
  312. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  313. //echo "&nbsp;";
  314. }
  315. }
  316. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  317. if ($myrow['title'] == '') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  318. if ($icon == 'nolink') { return(shorten($myrow['title'], $length)); }
  319. if ($icon == 'icon') { echo "<img src='../img/agenda.gif' align=\"absmiddle\" alt='agenda'>"; }
  320. if ($builder != 'builder') {
  321. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path\" class='$completed'>".shorten($myrow['title'], ($length-3*$level))."</a>";
  322. $items[] = api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path";
  323. if ($desc != '') {
  324. if ($icon != 'wrap') {
  325. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>";
  326. } else {
  327. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>";
  328. }
  329. }
  330. } else {
  331. echo "<a href=\"../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id\" class='$completed' target='_blank'>".shorten($myrow['title'], ($length-3*$level))."</a>";
  332. }
  333. break;
  334. case TOOL_ANNOUNCEMENT:
  335. case 'Ad_Valvas':
  336. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT,$_course['dbName']);
  337. $result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id");
  338. $myrow = Database::fetch_array($result);
  339. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  340. $result = Database::query($sql); $row = Database::fetch_array($result);
  341. if ($row['title'] != '') { $myrow['content'] = $row['title']; }
  342. $desc = $row['description'];
  343. $ann_id = $row['item_id'];
  344. echo str_repeat("&nbsp;&gt;", $level);
  345. // The title and the text are in the content field and we only want to display the title.
  346. list($title, $text) = split('<br>', $myrow['content']);
  347. if ($title == '') { $title = $myrow['content']; }
  348. $title = $myrow['title'];
  349. $text = $myrow['content'];
  350. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  351. if ($icon != 'nolink') {
  352. if ($completed == 'completed') {
  353. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  354. } else {
  355. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  356. //echo "&nbsp;";
  357. }
  358. }
  359. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  360. if ($title == '') {
  361. $type = 'Announcement';
  362. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  363. return(true);
  364. }
  365. if ($icon == 'nolink') { return(shorten($title,$length)); }
  366. if ($icon == 'icon') { echo "<img src='../img/valves.gif' align=\"absmiddle\" alt='ad valvas'>"; }
  367. if ($builder != 'builder') {
  368. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$ann_id#$id_in_path\" class='$completed'>".shorten($title, ($length-3*$level))."</a>";
  369. $items[] = api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$ann_id#$id_in_path";
  370. if ($desc != '') {
  371. if ($icon != 'wrap') {
  372. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>";
  373. } else {
  374. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>";
  375. }
  376. }
  377. } else {
  378. echo "<a href=\"../announcements/announcements.php?origin=$origin&ann_id=$ann_id\" class='$completed' target='_blank'>".shorten($title, ($length-3*$level))."</a>";
  379. }
  380. break;
  381. case TOOL_LINK:
  382. case 'Link':
  383. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK,$_course['dbName']);
  384. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$id");
  385. $myrow = Database::fetch_array($result);
  386. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  387. $result = Database::query($sql); $row = Database::fetch_array($result);
  388. if ($row['title'] != '') { $myrow['title'] = $row['title']; }
  389. $desc=$row['description'];
  390. echo str_repeat("&nbsp;&gt;", $level);
  391. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  392. if ($icon != 'nolink') {
  393. if ($completed == 'completed') {
  394. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  395. } else {
  396. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  397. //echo "&nbsp;";
  398. }
  399. }
  400. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  401. if ($myrow['title'] == '') {
  402. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  403. return(true);
  404. }
  405. if ($icon == 'nolink') { return(shorten($myrow['title'], $length)); }
  406. if ($icon == 'icon') {
  407. if ($linktype == 'Link _self') { echo "<img src='../img/links.gif' align=\"absmiddle\" alt='links'>"; }
  408. else { echo "<img src='../img/link_blank.gif' align=\"absmiddle\" alt='blank links'>"; }
  409. }
  410. $thelink = $myrow['url'];
  411. if ($builder != 'builder') {
  412. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path\" class='$completed'>".shorten($myrow['title'], ($length-3*$level))."</a>";
  413. $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path";
  414. if ($desc != '') {
  415. if ($icon != 'wrap') {
  416. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>";
  417. } else {
  418. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>";
  419. }
  420. }
  421. } else {
  422. echo "<a href=\"$thelink\" class='$completed' target='_blank'>".shorten($myrow['title'], ($length-3*$level))."</a>";
  423. }
  424. break;
  425. case TOOL_QUIZ:
  426. case 'Exercise':
  427. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST,$_course['dbName']);
  428. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE id=$id");
  429. $myrow = Database::fetch_array($result);
  430. if ($builder == 'builder') { $origin = 'builder'; }
  431. // This is needed for the exercise_submit.php can delete the session info about tests.
  432. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  433. $result = Database::query($sql);
  434. $row = Database::fetch_array($result);
  435. if ($row['title'] != '') { $myrow['title'] = $row['title']; }
  436. $desc = $row['description'];
  437. echo str_repeat("&nbsp;&gt;", $level);
  438. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  439. if ($icon != 'nolink') {
  440. if ($completed == 'completed') {
  441. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  442. } else {
  443. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  444. //echo "&nbsp;";
  445. }
  446. }
  447. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  448. if ($myrow['title'] == '') {
  449. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  450. return(true);
  451. }
  452. if ($icon == 'nolink') { return(shorten($myrow['title'], $length)); }
  453. if ($icon == 'icon') { echo "<img src='../img/quiz.gif' align=\"absmiddle\" alt='quizz'>"; }
  454. if ($builder != 'builder') {
  455. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path\" class='$completed'>".shorten($myrow['title'], ($length-3*$level))."</a>";
  456. $items[] = api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path";
  457. if ($desc != '') {
  458. if ($icon != 'wrap') {
  459. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>";
  460. } else {
  461. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>";
  462. }
  463. }
  464. } else {
  465. echo "<a href=\"../exercice/exercice_submit.php?origin=$origin&exerciseId=".$myrow['id']."\" class='$completed' target='_blank'>".shorten($myrow['title'], ($length-3*$level))."</a>";
  466. }
  467. break;
  468. case 'hotpotatoes':
  469. case 'HotPotatoes':
  470. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']);
  471. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  472. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE id=$id");
  473. $myrow = Database::fetch_array($result);
  474. $path = $myrow['path'];
  475. $name = GetQuizName($path, $documentPath);
  476. if ($builder == 'builder') { $origin='builder'; }
  477. // This is needed for the exercise_submit.php can delete the session info about tests.
  478. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  479. $result = Database::query($sql); $row = Database::fetch_array($result);
  480. if ($row['title'] != '') { $name=$row['title']; }
  481. $desc = $row['description'];
  482. echo str_repeat("&nbsp;&gt;", $level);
  483. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  484. if ($icon != 'nolink') {
  485. if ($completed == 'completed') {
  486. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  487. } else {
  488. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  489. //echo "&nbsp;";
  490. }
  491. }
  492. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  493. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  494. if ($icon == 'nolink') { return(shorten($name,$length)); }
  495. if ($icon == 'icon') { echo "<img src='../img/jqz.jpg' align=\"absmiddle\" alt='hot potatoes'>"; }
  496. $cid = $_course['official_code'];
  497. if ($builder != 'builder') {
  498. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>";
  499. $items[] = api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path";
  500. if ($desc != '') {
  501. if ($icon != 'wrap') {
  502. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>";
  503. } else {
  504. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>";
  505. }
  506. }
  507. } else {
  508. echo "&nbsp;<a href=\"../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id']."\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  509. }
  510. break;
  511. case TOOL_FORUM:
  512. case 'Forum':
  513. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM,$_course['database']);
  514. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id");
  515. $myrow = Database::fetch_array($result);
  516. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  517. $result = Database::query($sql); $row = Database::fetch_array($result);
  518. if ($row['title'] != '') { $myrow["forum_name"] = $row['title']; }
  519. $desc = $row['description'];
  520. echo str_repeat("&nbsp;&gt;", $level);
  521. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  522. if ($icon != 'nolink') {
  523. if ($completed == 'completed') {
  524. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  525. } else {
  526. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  527. //echo "&nbsp;";
  528. }
  529. }
  530. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  531. if ($myrow["forum_name"]=='') { $type="Forum"; echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('step_deleted2')."</span>"; return(true); }
  532. if ($icon == 'nolink') { return(shorten($myrow['forum_name'], $length)); }
  533. if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
  534. $forumparameters = "forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  535. if ($builder != 'builder') {
  536. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path\" class='$completed'>".shorten($myrow["forum_name"],($length-3*$level))."</a>";
  537. $items[] = api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path";
  538. if ($desc != '') {
  539. if ($icon != 'wrap') {
  540. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  541. } else {
  542. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  543. }
  544. }
  545. } else {
  546. echo "<a href=\"../phpbb/viewforum.php?$forumparameters\" class='$completed' target='_blank'>".shorten($myrow["forum_name"],($length-3*$level))."</a>";
  547. }
  548. break;
  549. case TOOL_THREAD:
  550. case 'Thread': //forum post
  551. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD, $_course['database']);
  552. $sql = "SELECT * FROM $tbl_topics where topic_id=$id";
  553. $result = Database::query($sql);
  554. $myrow = Database::fetch_array($result);
  555. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  556. $result = Database::query($sql); $row = Database::fetch_array($result);
  557. if ($row['title'] != '') { $myrow['topic_title'] = $row['title']; }
  558. $desc = $row['description'];
  559. echo str_repeat("&nbsp;&gt;", $level);
  560. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  561. if ($icon != 'nolink') {
  562. if ($completed == 'completed') {
  563. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  564. } else {
  565. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  566. //echo "&nbsp;";
  567. }
  568. }
  569. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  570. if ($myrow["topic_title"] == '') { $type = "Forum Post"; echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  571. if ($icon == 'nolink') { return(shorten($myrow['topic_title'], $length)); }
  572. if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
  573. if ($builder != 'builder') {
  574. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path\" class='$completed'>".shorten($myrow["topic_title"], ($length-3*$level))."</a>";
  575. $items[] = api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path";
  576. if ($desc != '') {
  577. if ($icon != 'wrap') {
  578. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  579. } else {
  580. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  581. }
  582. }
  583. } else {
  584. echo "<a href=\"../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."\" class='$completed' target='_blank'>".shorten($myrow["topic_title"],($length-3*$level))."</a>";
  585. }
  586. break;
  587. case TOOL_POST:
  588. case 'Post':
  589. //deprecated
  590. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST,$_course['dbName']);
  591. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM,$_course['dbName']);
  592. $result = Database::query("SELECT * FROM $tbl_posts where post_id=$id");
  593. $myrow = Database::fetch_array($result);
  594. // Grabbing the title of the post.
  595. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  596. $result = Database::query($sql); $row=Database::fetch_array($result);
  597. if ($row['title'] != '') { $myrow['post_title'] = $row['title']; }
  598. $desc = $row['description'];
  599. echo str_repeat("&nbsp;&gt;", $level);
  600. $posternom = $myrow['nom']; $posterprenom = $myrow['prenom'];
  601. $posttime = $myrow['post_time']; $posttext = $myrow['post_text'];
  602. $posttitle = $myrow['post_title'];
  603. $posttext = str_replace('"', "'", $posttext);
  604. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  605. if ($icon != 'nolink') {
  606. if ($completed == 'completed') {
  607. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  608. } else {
  609. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  610. //echo "&nbsp;";
  611. }
  612. }
  613. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  614. if ($myrow["post_title"] == '') {
  615. $type = 'Forum';
  616. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true);
  617. }
  618. if ($icon == 'nolink') { return(shorten($myrow["post_title"],$length)); }
  619. if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
  620. if ($builder != 'builder') {
  621. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".intval($_GET['source_forum'])."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path\" class='$completed'>".shorten($myrow["post_title"],($length-3*$level))."</a>"; $items[]=api_get_self()."?action=closelesson&source_forum=".intval($_GET['source_forum'])."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path";
  622. if ($desc != '') {
  623. if ($icon != 'wrap') {
  624. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  625. } else {
  626. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  627. }
  628. }
  629. } else {
  630. echo "<a href=\"../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."\" class='$completed' target='_blank'>".shorten($myrow["post_title"],($length-3*$level))."</a>";
  631. }
  632. break;
  633. case TOOL_DOCUMENT:
  634. case 'Document':
  635. $dbTable = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']);
  636. $mysql = "SELECT * FROM $dbTable WHERE id=$id";
  637. //error_log('New LP - Querying document table: '.$mysql,0);
  638. $result = Database::query($mysql);
  639. $myrow = Database::fetch_array($result);
  640. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  641. $last = count($pathname) - 1; // Making a correct name for the link.
  642. $filename=$pathname[$last]; // Making a correct name for the link.
  643. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  644. echo str_repeat("&nbsp;&gt;", $level);
  645. if ($icon != 'nolink') {
  646. if ($completed=='completed') {
  647. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  648. } else {
  649. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  650. //echo "&nbsp;";
  651. }
  652. }
  653. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  654. $image = choose_image($filename);
  655. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  656. //error_log('New LP - Querying lp_item table: '.$sql, 0);
  657. $result = Database::query($sql); $row = Database::fetch_array($result);
  658. if ($row['title'] != '') { $filename = $row['title']; }
  659. $desc=$row['description'];
  660. if (($myrow['path'] == '') && ($filename == '')) {
  661. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  662. return(true);
  663. }
  664. if ($icon == 'nolink') { return(shorten($filename, $length)); }
  665. if ($icon == 'icon') { echo "<img src='../img/$image' align=\"absmiddle\" alt='$image'>"; }
  666. if ($builder != 'builder')
  667. {
  668. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path\" class='$completed'>".shorten($filename,($length-3*$level))."</a>";
  669. if ($desc != '') {
  670. if ($icon != 'wrap') {
  671. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  672. } else {
  673. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  674. }
  675. } $items[] = api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path";
  676. } else {
  677. $enableDocumentParsing=yes;
  678. if (!$enableDocumentParsing) {
  679. // This is the solution for the non-parsing version in the builder.
  680. $file = urlencode($myrow['path']);
  681. echo "<a href='../document/showinframes.php?file=$file' class='$completed' $hyperlink_target_parameter>".shorten($filename,($length-3*$level))."</a>";
  682. } else {
  683. echo "<a href=\"../document/download.php?doc_url=".$myrow['path']."\" class='$completed' $hyperlink_target_parameter>".shorten($filename,($length-3*$level))."</a>";
  684. }
  685. }
  686. break;
  687. case 'assignments':
  688. case 'Assignments':
  689. $name = get_lang('Assignments');
  690. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  691. $result = Database::query($sql);
  692. $row = Database::fetch_array($result);
  693. if ($row['title'] != '') { $name=$row['title']; }
  694. $desc = $row['description'];
  695. echo str_repeat("&nbsp;&gt;", $level);
  696. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  697. if ($icon != 'nolink') {
  698. if ($completed == 'completed') {
  699. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  700. } else {
  701. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  702. //echo "&nbsp;";
  703. }
  704. }
  705. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  706. if ($name=='') {
  707. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true);
  708. }
  709. if ($icon == 'nolink') { return(shorten($name, $length)); }
  710. if ($icon == 'icon') { echo "<img src='../img/works.gif' align=\"absmiddle\">"; }
  711. if ($builder != 'builder') {
  712. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>"; $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path";
  713. if ($desc != '') {
  714. if ($icon != 'wrap') {
  715. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>";
  716. } else {
  717. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>";
  718. }
  719. }
  720. } else {
  721. echo "<a href=\"../work/work.php\" class='$completed' target='_blank'>".shorten($name, ($length-3*$level))."</a>";
  722. }
  723. break;
  724. case TOOL_DROPBOX:
  725. case 'Dropbox':
  726. $name = get_lang('Dropbox');
  727. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  728. $result = Database::query($sql);
  729. $row = Database::fetch_array($result);
  730. if ($row['title'] != '') { $name = $row['title']; }
  731. $desc = $row['description'];
  732. echo str_repeat("&nbsp;&gt;", $level);
  733. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  734. if ($icon != 'nolink') {
  735. if ($completed == 'completed') {
  736. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  737. } else {
  738. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  739. //echo "&nbsp;";
  740. }
  741. }
  742. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  743. if ($name == '') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  744. if ($icon == 'nolink') { return(shorten($name, $length)); }
  745. if ($icon == 'icon') { echo "<img src='../img/dropbox.gif' align=\"absmiddle\">"; }
  746. if ($builder != 'builder') {
  747. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>"; $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path";
  748. if ($desc != '') {
  749. if ($icon != 'wrap') {
  750. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>"; }
  751. else {
  752. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>"; }
  753. }
  754. } else {
  755. echo "<a href=\"../dropbox/index.php\" class='$completed' target='_blank'>".shorten($name, ($length-3*$level))."</a>";
  756. }
  757. break;
  758. case 'introduction_text':
  759. case 'Introduction_text':
  760. $name = get_lang('IntroductionText');
  761. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  762. $result = Database::query($sql); $row = Database::fetch_array($result);
  763. if ($row['title'] != '') { $name = $row['title']; }
  764. $desc = $row['description'];
  765. echo str_repeat("&nbsp;&gt;", $level);
  766. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  767. if ($icon != 'nolink') {
  768. if ($completed == 'completed') {
  769. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  770. } else {
  771. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  772. //echo "&nbsp;";
  773. }
  774. }
  775. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  776. if ($name == '') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  777. if ($icon == 'nolink') { return(shorten($name, $length)); }
  778. if ($icon == 'icon') { echo "<img src='../img/introduction.gif' align=\"absmiddle\" alt='introduction'>"; }
  779. if ($builder != 'builder') {
  780. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>";
  781. $items[] = api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path";
  782. if ($desc != '') {
  783. if ($icon != 'wrap') {
  784. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>"; }
  785. else {
  786. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>"; }
  787. }
  788. } else {
  789. $s = api_get_path(WEB_COURSE_PATH)."$_cid/index.php?intro_cmdEdit=1";
  790. echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name, ($length-3*$level))."</a>";
  791. }
  792. break;
  793. case TOOL_COURSE_DESCRIPTION:
  794. case 'Course_description':
  795. $name = get_lang('CourseDescription');
  796. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  797. $result = Database::query($sql); $row = Database::fetch_array($result);
  798. if ($row['title'] != '') { $name = $row['title']; }
  799. $desc = $row['description'];
  800. echo str_repeat("&nbsp;&gt;", $level);
  801. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  802. if ($icon != 'nolink') {
  803. if ($completed == 'completed') {
  804. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  805. } else {
  806. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  807. //echo "&nbsp;";
  808. }
  809. }
  810. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  811. if ($name == '') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  812. if ($icon == 'nolink') { return(shorten($name,$length)); }
  813. if ($icon == 'icon') { echo "<img src='../img/info.gif' align=\"absmiddle\" alt='info'>"; }
  814. if ($builder != 'builder') {
  815. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>"; $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path";
  816. if ($desc != '') {
  817. if ($icon != 'wrap') {
  818. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>"; }
  819. else {
  820. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>"; }
  821. }
  822. } else {
  823. $s=api_get_path(WEB_CODE_PATH)."course_description";
  824. echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name, ($length-3*$level))."</a>";
  825. }
  826. break;
  827. case TOOL_GROUP:
  828. case 'Groups':
  829. $name = get_lang('Groups');
  830. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  831. $result = Database::query($sql); $row = Database::fetch_array($result);
  832. if ($row['title'] != '') { $name=$row['title']; }
  833. $desc = $row['description'];
  834. echo str_repeat("&nbsp;&gt;", $level);
  835. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  836. if ($icon != 'nolink') {
  837. if ($completed == 'completed') {
  838. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  839. } else {
  840. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  841. //echo "&nbsp;";
  842. }
  843. }
  844. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  845. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  846. if ($icon == 'nolink') { return(shorten($name, $length)); }
  847. if ($icon == 'icon') { echo "<img src='../img/group.gif' align=\"absmiddle\" alt='group'>"; }
  848. if ($builder != 'builder') {
  849. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>"; $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path";
  850. if ($desc != '') {
  851. if ($icon != 'wrap') {
  852. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>"; }
  853. else {
  854. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>"; }
  855. }
  856. } else {
  857. echo "<a href=\"../group/group.php?origin=$origin\" class='$completed' target='_blank'>".shorten($name, ($length-3*$level))."</a>";
  858. }
  859. break;
  860. case TOOL_USER:
  861. case 'Users':
  862. $name = get_lang('Users');
  863. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  864. $result = Database::query($sql); $row = Database::fetch_array($result);
  865. if ($row['title'] != '') { $name = $row['title']; }
  866. $desc = $row['description'];
  867. echo str_repeat("&nbsp;&gt;", $level);
  868. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  869. if ($icon != 'nolink') {
  870. if ($completed == 'completed') {
  871. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  872. } else {
  873. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  874. //echo "&nbsp;";
  875. }
  876. }
  877. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  878. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  879. if ($icon == 'nolink') { return(shorten($name,$length)); }
  880. if ($icon == 'icon') { echo "<img src='../img/members.gif' align=\"absmiddle\" alt='members'>"; }
  881. if ($builder != 'builder') {
  882. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path\" class='$completed'>".shorten($name,($length-3*$level))."</a>"; $items[]=api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path";
  883. if ($desc != '') {
  884. if ($icon != 'wrap') {
  885. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>"; }
  886. else {
  887. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>"; }
  888. }
  889. } else {
  890. echo "<a href=\"../user/user.php?origin=$origin\" class='$completed' target='_blank'>".shorten($name, ($length-3*$level))."</a>";
  891. }
  892. break;
  893. }//end huge switch-statement
  894. }
  895. /**
  896. * This function is to create and return a link to the added resources (lessons).
  897. * It returns the same thing as display_addedresource_link_in_learnpath() but doesn't display
  898. * anything.
  899. *
  900. * Parameters:
  901. * @param type - that is the correspondent type in the mirror tool (like this is a Link item)
  902. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  903. * @param id_in_path - the unique index in the items table
  904. */
  905. function get_addedresource_link_in_learnpath($type, $id, $id_in_path) {
  906. global $_course, $learnpath_id, $tbl_learnpath_item, $items;
  907. global $curDirPath, $_configuration, $enableDocumentParsing, $_user, $_cid;
  908. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  909. $hyperlink_target_parameter = ''; // or e.g. target='_blank'
  910. $builder = 'player';
  911. $origin = 'learnpath';
  912. $linktype = $type;
  913. if (($type == 'Link _self') || ($type == 'Link _blank')) { $type = 'Link'; }
  914. $link = '';
  915. switch ($type) {
  916. case 'Agenda':
  917. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA,$_course['dbName']);
  918. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE id=$id");
  919. $myrow = Database::fetch_array($result);
  920. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  921. $result = Database::query($sql); $row = Database::fetch_array($result);
  922. if ($row['title'] != '') { $myrow['title'] = $row['title']; }
  923. $desc = $row['description'];
  924. $agenda_id = $row['item_id'];
  925. if ($builder != 'builder') {
  926. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path";
  927. } else {
  928. $link .= "../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id";
  929. }
  930. break;
  931. case 'Ad_Valvas':
  932. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  933. $result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id");
  934. $myrow = Database::fetch_array($result);
  935. if ($builder != 'builder') {
  936. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$id#$id_in_path";
  937. } else {
  938. $link .= "../announcements/announcements.php?origin=$origin&ann_id=$id";
  939. }
  940. break;
  941. case 'Link':
  942. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK,$_course['dbName']);
  943. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$id");
  944. $myrow = Database::fetch_array($result);
  945. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  946. $result = Database::query($sql); $row = Database::fetch_array($result);
  947. $thelink = $myrow['url'];
  948. if ($builder != 'builder') {
  949. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path";
  950. } else {
  951. $link .= $thelink;
  952. }
  953. break;
  954. case 'Exercise':
  955. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST,$_course['dbName']);
  956. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE id=$id");
  957. $myrow = Database::fetch_array($result);
  958. if ($builder == 'builder') { $origin = 'builder'; }
  959. // This is needed for the exercise_submit.php can delete the session info about tests.
  960. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  961. $result = Database::query($sql); $row = Database::fetch_array($result);
  962. if ($row['title'] != '') { $myrow['title'] = $row['title']; }
  963. if ($builder != 'builder') {
  964. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path";
  965. } else {
  966. $link .= "../exercice/exercice_submit.php?origin=$origin&exerciseId=".$myrow["id"];
  967. }
  968. break;
  969. case 'HotPotatoes':
  970. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']);
  971. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  972. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE id=$id");
  973. $myrow = Database::fetch_array($result);
  974. $path = $myrow['path'];
  975. $name = GetQuizName($path, $documentPath);
  976. if ($builder=='builder') { $origin='builder'; }
  977. $cid = $_course['official_code'];
  978. if ($builder != 'builder') {
  979. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path";
  980. } else {
  981. $link .= "../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id'];
  982. }
  983. break;
  984. case 'Forum':
  985. //deprecated
  986. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM,$_course['dbName']); // TODO: This is the old table name, it should be corrected.
  987. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id");
  988. $myrow = Database::fetch_array($result);
  989. if ($builder == 'builder') { $origin = 'builder'; }
  990. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  991. $result = Database::query($sql); $row = Database::fetch_array($result);
  992. if ($row['title'] != '') { $myrow['forum_name'] = $row['title']; }
  993. if ($myrow['forum_name'] == '') { $type = 'Forum'; }
  994. $forumparameters = "forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  995. if ($builder != 'builder') {
  996. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path";
  997. } else {
  998. $link .= "../phpbb/viewforum.php?$forumparameters";
  999. }
  1000. break;
  1001. case 'Thread': //forum post
  1002. //deprecated
  1003. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD,$_course['dbName']);
  1004. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST,$_course['dbName']);
  1005. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM,$_course['dbName']);
  1006. $sql = "SELECT * FROM $tbl_topics where topic_id=$id";
  1007. $result = Database::query($sql);
  1008. $myrow = Database::fetch_array($result);
  1009. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  1010. $result = Database::query($sql); $row = Database::fetch_array($result);
  1011. if ($builder != 'builder') {
  1012. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path";
  1013. } else {
  1014. $link .= "../forum/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1015. }
  1016. break;
  1017. case 'Post':
  1018. //deprecated
  1019. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST,$_course['dbName']);
  1020. $TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
  1021. $result = Database::query("SELECT * FROM $tbl_posts where post_id=$id");
  1022. $myrow = Database::fetch_array($result);
  1023. // Grabbing the title of the post.
  1024. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  1025. $result = Database::query($sql); $row = Database::fetch_array($result);
  1026. if ($row['title'] != '') { $myrow['post_title'] = $row['title']; }
  1027. $desc = $row['description'];
  1028. //$link .= str_repeat("&nbsp;&gt;", $level);
  1029. $posternom = $myrow['nom']; $posterprenom = $myrow['prenom'];
  1030. $posttime = $myrow['post_time']; $posttext = $myrow['post_text'];
  1031. $posttitle = $myrow['post_title'];
  1032. $posttext = str_replace('"', "'", $posttext);
  1033. if ($builder != 'builder') {
  1034. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path";
  1035. } else {
  1036. $link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1037. }
  1038. break;
  1039. case 'Document':
  1040. $dbTable = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']);
  1041. $result = Database::query("SELECT * FROM $dbTable WHERE id=$id");
  1042. $myrow = Database::fetch_array($result);
  1043. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  1044. $last = count($pathname) - 1; // Making a correct name for the link.
  1045. $filename = $pathname[$last]; // Making a correct name for the link.
  1046. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  1047. $result = Database::query($sql); $row = Database::fetch_array($result);
  1048. if ($builder != 'builder') {
  1049. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path";
  1050. } else {
  1051. $enableDocumentParsing = yes;
  1052. if (!$enableDocumentParsing) {
  1053. // This is the solution for the non-parsing version in the builder.
  1054. $file = urlencode($myrow['path']);
  1055. $link .= "../document/showinframes.php?file=$file";
  1056. } else {
  1057. $link .= "../document/download.php?doc_url=".$myrow['path'];
  1058. }
  1059. }
  1060. break;
  1061. case 'Assignments':
  1062. if ($builder != 'builder') {
  1063. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path";
  1064. } else {
  1065. $link .= "../work/work.php";
  1066. }
  1067. break;
  1068. case 'Dropbox':
  1069. if ($builder != 'builder') {
  1070. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path";
  1071. } else {
  1072. $link .= "../dropbox/index.php";
  1073. }
  1074. break;
  1075. case 'Introduction_text':
  1076. if ($builder != 'builder') {
  1077. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path";
  1078. } else {
  1079. $s = api_get_path(WEB_COURSE_PATH)."$_cid/index.php?intro_cmdEdit=1";
  1080. $link .= $s;
  1081. }
  1082. break;
  1083. case 'Course_description':
  1084. if ($builder != 'builder') {
  1085. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path";
  1086. } else {
  1087. $s = api_get_path(WEB_CODE_PATH).'course_description';
  1088. $link .= $s;
  1089. }
  1090. break;
  1091. case 'Groups':
  1092. if ($builder != 'builder') {
  1093. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path";
  1094. } else {
  1095. $link .= "../group/group.php?origin=$origin";
  1096. }
  1097. break;
  1098. case 'Users':
  1099. if ($builder != 'builder') {
  1100. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path";
  1101. } else {
  1102. $link .= "../user/user.php?origin=$origin";
  1103. }
  1104. break;
  1105. }//end huge switch-statement
  1106. return $link;
  1107. }
  1108. /**
  1109. * This function is to remove an resource item from the array
  1110. */
  1111. function remove_resource($resource_key) {
  1112. $addedresource = $_SESSION['addedresource'];
  1113. $addedresourceid = $_SESSION['addedresourceid'];
  1114. unset($addedresource[$resource_key]);
  1115. unset($addedresourceid[$resource_key]);
  1116. $_SESSION['addedresource'] = $addedresource;
  1117. $_SESSION['addedresourceid'] = $addedresourceid ;
  1118. }
  1119. /**
  1120. * This function is to show the button "click to add resource" on the tool page
  1121. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1122. */
  1123. function show_addresource_button($additionalparameters = '') {
  1124. global $charset;
  1125. echo '<label for="addresources"><img src="../img/attachment.gif" /></label><input class="link_alike" type="submit" name="addresources" id="addresources" value="'.api_htmlentities(get_lang('Attachment'), ENT_QUOTES, $charset).'" '.$additionalparameters.' />';
  1126. }
  1127. /**
  1128. * This function is to delete ONE specific resource that were added to a specific item
  1129. * Deprecated
  1130. *//*
  1131. function delete_one_added_resource($source_type, $source_id, $resource_type, $resource_id) {
  1132. //echo "delete_one_added_resource";
  1133. global $_course;
  1134. $TABLERESOURCE = $_course['dbNameGlu'].'resource';
  1135. $sql = "DELETE FROM $TABLERESOURCE WHERE source_type='$source_type' and source_id='$source_id' and resource_type='$resource_type' and resource_id='$resource_id'";
  1136. Database::query($sql);
  1137. }*/
  1138. /**
  1139. * This function is to delete the resources that were added to a specific item
  1140. */
  1141. function delete_added_resource($type, $id) {
  1142. global $_course;
  1143. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);
  1144. $sql = "DELETE FROM $TABLERESOURCE WHERE source_type='$type' and source_id='$id'";
  1145. Database::query($sql);
  1146. }
  1147. /**
  1148. * This function is te delete all resources of a specific type (only used in announcements -- delete all)
  1149. * Author : Frederik Vermeire <frederik.vermeire@pandora.be>
  1150. */
  1151. function delete_all_resources_type($type) {
  1152. global $_course;
  1153. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);
  1154. $sql = "DELETE FROM $TABLERESOURCE WHERE source_type='$type'";
  1155. Database::query($sql);
  1156. }
  1157. /**
  1158. * This function checks wether there are added resources or not
  1159. */
  1160. function check_added_resources($type, $id) {
  1161. global $_course, $origin;
  1162. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);
  1163. $sql = "SELECT * FROM $TABLERESOURCE WHERE source_type='$type' and source_id='$id'";
  1164. $result = Database::query($sql);
  1165. $number_added = Database::num_rows($result);
  1166. if ($number_added != 0)
  1167. return true;
  1168. else
  1169. return false;
  1170. }
  1171. /**
  1172. * this function is to load the resources that were added to a specific item
  1173. * into the session variables
  1174. */
  1175. function edit_added_resources($type, $id) {
  1176. global $_course;
  1177. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);
  1178. $sql="SELECT * FROM $TABLERESOURCE WHERE source_type='$type' and source_id=$id";
  1179. $result=Database::query($sql);
  1180. while ($row=Database::fetch_array($result))
  1181. {
  1182. $addedresource[]=$row["resource_type"];
  1183. $addedresourceid[]=$row["resource_id"];
  1184. }
  1185. $_SESSION['addedresource']=$addedresource;
  1186. $_SESSION['addedresourceid']=$addedresourceid;
  1187. }
  1188. /**
  1189. * this function is store the modified resources
  1190. * first we delete all the added resources in the database,
  1191. * then we add all the resources from the session object.
  1192. */
  1193. function update_added_resources($type, $id) {
  1194. global $_course;
  1195. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);
  1196. // delete all the added resources for this item in the database;
  1197. $sql="DELETE FROM $TABLERESOURCE WHERE source_type='$type' AND source_id='$id'";
  1198. //echo $sql;
  1199. Database::query($sql);
  1200. // Store the resources from the session into the database.
  1201. store_resources($type, $id);
  1202. //delete_added_resource_($type, $id);
  1203. unset_session_resources();
  1204. }
  1205. /**
  1206. * this function is to display the resources that were added to a specific item
  1207. */
  1208. function display_added_resources($type, $id, $style = '') {
  1209. // The array containing the icons
  1210. $arr_icons = array('Agenda'=>'../img/agenda.gif', 'Ad Valvas'=>'../img/valves.gif', 'Link'=>'../img/links.gif', 'Exercise'=>'../img/quiz.gif' );
  1211. global $_course, $origin;
  1212. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);
  1213. $sql = "SELECT * FROM $TABLERESOURCE WHERE source_type='$type' and source_id='$id'";
  1214. $result = Database::query($sql);
  1215. while ($row=Database::fetch_array($result)) {
  1216. if ($origin != 'learnpath') {
  1217. display_addedresource_link($row['resource_type'], $row['resource_id'], $style) ;
  1218. } else {
  1219. display_addedresource_link_in_learnpath($row['resource_type'], $row['resource_id'],'agendaitems','','builder','icon') ; echo "<br>";
  1220. }
  1221. }
  1222. }
  1223. /**
  1224. * This function is to show the added resources when adding an item
  1225. * $showdeleteimg determine if the delete image should appear or not.
  1226. * deleting an added resource is only possible through the resource linker file itself
  1227. */
  1228. function display_resources($showdeleteimg) {
  1229. global $action;
  1230. global $resourceaction;
  1231. global $id;
  1232. global $locationkey;
  1233. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  1234. if ($resourceaction == 'removeresource') {
  1235. remove_resource($locationkey);
  1236. }
  1237. $addedresource = $_SESSION['addedresource'];
  1238. $addedresourceid = $_SESSION['addedresourceid'];
  1239. if (is_array($addedresource)) {
  1240. echo '<table>';
  1241. foreach ($addedresource as $resource) {
  1242. echo '<tr><td>';
  1243. display_addedresource_link($resource, $addedresourceid[key($addedresource)]);
  1244. echo '</td><td width="30">';
  1245. // if $_SERVER['REQUEST_URI'] contains and ?id=xx we have an edit and the url for deleting a session added resource
  1246. // should also contain this id.
  1247. $test = parse_url($_SERVER['REQUEST_URI']);
  1248. $output = array();
  1249. parse_str($test[query], $output);
  1250. if ($showdeleteimg == 1) {
  1251. echo "<a href=".api_get_self()."?showresources=true&amp;source_forum=".$_GET['source_forum']."&amp;resourceaction=removeresource&amp;locationkey=".key($addedresource)."&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no><img src='../img/delete.gif' border='0' alt='resource ".get_lang('Delete')."' /></a><br />";
  1252. }
  1253. echo '</td></tr>';
  1254. next($addedresource);
  1255. }
  1256. echo '</table>';
  1257. }
  1258. else { // it is a string
  1259. echo '';
  1260. }
  1261. } // end of the display_resources function
  1262. /**
  1263. * This function checks wether the link add resource should be displayed next the item in the linker page
  1264. * So we have to check if the specific id of that tool is already in the array of the added resources
  1265. * if it is already in, the link should not be showed since it would make it possible to add
  1266. * the same resource a second time (=duplication of added resources)
  1267. */
  1268. function showorhide_addresourcelink($type, $id) {
  1269. global $from_learnpath, $source_id, $action, $learnpath_id, $chapter_id, $originalresource, $folder, $content, $target;
  1270. $addedresource = $_SESSION['addedresource'];
  1271. $addedresourceid = $_SESSION['addedresourceid'];
  1272. if (is_array($_SESSION['addedresource'])) {
  1273. foreach ($addedresource as $toolcompare) {
  1274. if ($toolcompare==$type && $addedresourceid[key($addedresource)] == $id) {
  1275. $show = 0;
  1276. }
  1277. next($addedresource);
  1278. }
  1279. if ($from_learnpath) { $lang_add_it_or_resource = get_lang('AddIt'); } else { $lang_add_it_or_resource = get_lang('AddResource'); }
  1280. if ($show !== 0) {
  1281. if ($type == 'Document') {
  1282. echo "<a href=".api_get_self()."?content=".$type."&folder=".$folder."&source_forum=".$_GET['source_forum']."&add=".$id."&source_id=$source_id&action=$action&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no>".$lang_add_it_or_resource."</a>";
  1283. } else {
  1284. echo "<a href='".api_get_self()."?content=".$type."&source_forum=".$_GET['source_forum']."&add=".$id."&source_id=$source_id&action=$action&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no&target=$target'>".$lang_add_it_or_resource."</a>";
  1285. }
  1286. }
  1287. }
  1288. else { // if it is not an array, it is a string
  1289. if ($_SESSION['addedresource'] !== $type || $_SESSION['addedresourceid'] !== $id) {
  1290. if ($from_learnpath) { $lang_add_it_or_resource = get_lang('AddIt'); } else { $lang_add_it_or_resource = get_lang('AddResource'); }
  1291. echo "<a href='".api_get_self()."?content=".$type."&folder=".$folder."&source_forum=".$_GET['source_forum']."&add=".$id."&source_id=$source_id&action=$action&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no&target=$target'>".$lang_add_it_or_resource."</a>";
  1292. }
  1293. }
  1294. }
  1295. /**
  1296. * Gets the link to the given added resource.
  1297. *
  1298. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1299. * @author Yannick Warnier <ywarnier@beeznest.org>, Dokeos - rebranding
  1300. * @param string Course code
  1301. * @param string The tool type (using constants declared in main_api.lib.php)
  1302. * @param integer The resource ID
  1303. * @param string Resource style (e.g. when a resource is hidden => the added resources should also be styled like they are hidden)
  1304. * @param boolean Open in a new window (true) or in the current frame/window (false)?
  1305. * @todo use the constants for the type definitions.
  1306. */
  1307. function rl_get_html_resource_link($course_code, $type, $id, $style='', $new_window = true) {
  1308. //$_course = Database::get_course_info($course_code);
  1309. $_course = Database::get_course_info($course_code);
  1310. // Styling the link of the added resource
  1311. if ($style != '') $styling = ' class="'.$style.'"';
  1312. if ($new_window) { $target = ' target = "_blank" '; } else { $target = ' target = "_self" '; }
  1313. $output = '';
  1314. switch ($type) {
  1315. case TOOL_CALENDAR_EVENT:
  1316. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA,$_course['database']);
  1317. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE id=$id");
  1318. $myrow = Database::fetch_array($result);
  1319. $output = '<img src="../img/agenda.gif" align="middle" /> <a href="../calendar/agenda.php"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1320. break;
  1321. case TOOL_ANNOUNCEMENT:
  1322. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT,$_course['database']);
  1323. $result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id");
  1324. $myrow = Database::fetch_array($result);
  1325. $output = '<img src="../img/valves.gif" align="middle" /> <a href="../announcements/announcements.php"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1326. break;
  1327. case TOOL_LINK:
  1328. //doesn't take $target into account
  1329. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK,$_course['database']);
  1330. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$id");
  1331. $myrow = Database::fetch_array($result);
  1332. $output = '<img src="../img/links.gif" align="middle" /> <a href="#" onclick="javascript:window.open(\'../link/link_goto.php?link_id='.$myrow['id'].'&amp;link_url='.urlencode($myrow['url'])."','MyWindow','width=500,height=400,top='+((screen.height-400)/2)+',left='+((screen.width-500)/2)+',scrollbars=1,resizable=1,menubar=1'); return false;\"".$styling.'>'.$myrow['title']."</a><br />\n";
  1333. break;
  1334. case TOOL_QUIZ:
  1335. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST,$_course['database']);
  1336. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE id=$id");
  1337. $myrow = Database::fetch_array($result);
  1338. $output = '<img src="../img/quiz.gif" align="middle" /> <a href="../exercice/exercice_submit.php?exerciseId='.$myrow['id'].'"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1339. break;
  1340. case TOOL_FORUM:
  1341. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM,$_course['database']);
  1342. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id");
  1343. $myrow = Database::fetch_array($result);
  1344. $output = '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewforum.php?forum='.$myrow['forum_id'].'&md5='.$myrow['md5'].'"'.$styling.' '.$target.'>'.$myrow['forum_name']."</a><br />\n";
  1345. break;
  1346. case TOOL_THREAD: //=topics
  1347. //$tbl_forum = Database::get_course_table(TABLE_FORUM,$_course['database']);
  1348. //$tbl_thread = Database::get_course_table(TABLE_FORUM_THREAD,$_course['database']);
  1349. $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']);
  1350. // grabbing the title of the post
  1351. $sql_title = "SELECT * FROM $tbl_post WHERE post_id=".$id;
  1352. $result_title = Database::query($sql_title);
  1353. $myrow_title = Database::fetch_array($result_title);
  1354. $output = '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$myrow_title['thread_id'].'&forum='.$myrow_title['forum_id'].'" '.$styling.' '.$target.'>'.$myrow_title['post_title']."</a><br />\n";
  1355. break;
  1356. case TOOL_POST:
  1357. $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']);
  1358. //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE);
  1359. $sql = "SELECT * FROM $tbl_post p WHERE p.post_id = $id";
  1360. $result = Database::query($sql);
  1361. $post = Database::fetch_array($result);
  1362. $output = '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$post['thread_id'].'&forum='.$post['forum_id'].'"'.$styling.' '.$target.'>'.$post['post_title']."</a><br />\n";
  1363. break;
  1364. case TOOL_DOCUMENT:
  1365. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT,$_course['database']);
  1366. $result = Database::query("SELECT * FROM $tbl_doc WHERE id=$id");
  1367. $myrow = Database::fetch_array($result);
  1368. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  1369. $last = count($pathname) - 1; // Making a correct name for the link.
  1370. $filename = $pathname[$last]; // Making a correct name for the link.
  1371. $image = choose_image($filename);
  1372. $ext = explode('.', $filename);
  1373. $ext = strtolower($ext[sizeof($ext) - 1]);
  1374. $myrow['path'] = rawurlencode($myrow['path']);
  1375. $in_frames = in_array($ext, array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png'));
  1376. $output = '<img src="../img/'.$image.'" align="middle" /> <a href="../document/'.($in_frames ? 'showinframes.php?file=' : 'download.php?doc_url=').$myrow['path'].'"'.$styling.' '.$target.'>'.$filename."</a><br />\n";
  1377. break;
  1378. /*
  1379. case 'Externallink':
  1380. $output = '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.' '.$target.'>'.$id."</a><br />\n";
  1381. break;
  1382. */
  1383. }
  1384. return $output;
  1385. }
  1386. /**
  1387. * Returns an HTML-formatted link to a resource, to incorporate directly into
  1388. * the new learning path tool.
  1389. *
  1390. * The function is a big switch on tool type.
  1391. * In each case, we query the corresponding table for information and build the link
  1392. * with that information.
  1393. * @author Yannick Warnier <ywarnier@beeznest.org> - rebranding based on previous work (display_addedresource_link_in_learnpath())
  1394. * @param string Course code
  1395. * @param integer The learning path ID (in lp table)
  1396. * @param integer The database ID for that item in the lp_item table
  1397. * @param
  1398. * @param string Type (as one of the TOOL_ constants declared in main_api.lib.php)
  1399. * @param integer ID of the database item to get (from that tool's table)
  1400. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  1401. * @param id_in_path - the unique index in the items table
  1402. */
  1403. function rl_get_resource_link_for_learnpath($course_code, $learnpath_id, $id_in_path) {
  1404. //error_log('In rl_get_resource_link_for_learnpath()', 0);
  1405. $_course = Database::get_course_info($course_code);
  1406. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1407. $sql_item = "SELECT * FROM $tbl_lp_item " .
  1408. "WHERE lp_id = $learnpath_id AND id = $id_in_path";
  1409. $res_item = Database::query($sql_item);
  1410. if (Database::num_rows($res_item) < 1) return -1; //exit
  1411. $row_item = Database::fetch_array($res_item);
  1412. $type = strtolower($row_item['item_type']);
  1413. $id = (strcmp($row_item['path'], '') == 0) ? '0' : $row_item['path'];
  1414. $origin = 'learnpath';
  1415. $main_dir_path = api_get_path(WEB_CODE_PATH);
  1416. $main_course_path = api_get_path(WEB_COURSE_PATH).$_course['directory'].'/';
  1417. $link = '';
  1418. switch ($type) {
  1419. case 'dokeos_chapter':
  1420. $link .= $main_dir_path.'newscorm/blank.php';
  1421. case TOOL_CALENDAR_EVENT:
  1422. $link .= $main_dir_path.'calendar/agenda.php?origin='.$origin.'&agenda_id='.$id;
  1423. break;
  1424. case TOOL_ANNOUNCEMENT:
  1425. $link .= $main_dir_path.'announcements/announcements.php?origin='.$origin.'&ann_id='.$id;
  1426. break;
  1427. case TOOL_LINK:
  1428. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK,$_course['database']);
  1429. $result= Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$id");
  1430. $myrow=Database::fetch_array($result);
  1431. $thelink=$myrow["url"];
  1432. $link .= $thelink;
  1433. break;
  1434. case TOOL_QUIZ:
  1435. if (!empty($id)) {
  1436. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST,$_course['database']);
  1437. $sql = "SELECT * FROM $TBL_EXERCICES WHERE id=$id";
  1438. $result= Database::query($sql);
  1439. $myrow=Database::fetch_array($result);
  1440. if ($row_item['title'] != '') { $myrow['title'] = $row_item['title']; }
  1441. $link .= $main_dir_path.'exercice/exercice_submit.php?lp_init=1&origin='.$origin.'&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path.'&exerciseId='.$id;
  1442. }
  1443. break;
  1444. case 'hotpotatoes': //lowercase because of strtolower above
  1445. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  1446. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE id=$id");
  1447. $myrow = Database::fetch_array($result);
  1448. $path = $myrow['path'];
  1449. $link .= $main_dir_path.'exercice/showinframes.php?file='.$path.'' .
  1450. '&origin='.$origin.'&cid='.$course_code.'&uid='.api_get_user_id().'' .
  1451. '&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path;
  1452. break;
  1453. case TOOL_FORUM:
  1454. $link .= $main_dir_path.'forum/viewforum.php?forum='.$id.'&lp=true&origin=learnpath';
  1455. break;
  1456. case TOOL_THREAD: //forum post
  1457. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD, $_course['database']);
  1458. if (!empty($id)) {
  1459. $sql = "SELECT * FROM $tbl_topics where thread_id=$id";
  1460. $result = Database::query($sql);
  1461. $myrow = Database::fetch_array($result);
  1462. $link .= $main_dir_path.'forum/viewthread.php?origin=learnpath&thread='.$id.'' .
  1463. '&forum='.$myrow['forum_id'].'&lp=true';
  1464. }
  1465. break;
  1466. case TOOL_POST:
  1467. $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']);
  1468. $result = Database::query("SELECT * FROM $tbl_post where post_id=$id");
  1469. $myrow = Database::fetch_array($result);
  1470. $title = $myrow['post_title'];
  1471. //$desc = $row_item['description'];
  1472. $posternom = $myrow['poster_name'];
  1473. $posttime = $myrow['post_date'];
  1474. $posttext = $myrow['post_text'];
  1475. $posttitle = $title;
  1476. $posttext = str_replace('"', "'", $posttext);
  1477. $link .= $main_dir_path.'forum/viewthread.php?post='.$id.'' .
  1478. '&thread='.$myrow['thread_id'].'&forum='.$myrow['forum_id'].'' .
  1479. '&lp=true';
  1480. break;
  1481. case TOOL_DOCUMENT:
  1482. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT,$_course['database']);
  1483. $sql = "SELECT * FROM $tbl_doc WHERE id=$id";
  1484. $result = Database::query($sql);
  1485. $myrow = Database::fetch_array($result);
  1486. $docurl = str_replace('%2F', '/', urlencode($myrow['path']));
  1487. $link .= $main_course_path.'document'.$docurl.'?'.api_get_cidreq();
  1488. $openmethod = 2;
  1489. $officedoc = false;
  1490. api_session_register('openmethod');
  1491. api_session_register('officedoc');
  1492. break;
  1493. case 'assignments':
  1494. $link .= $main_dir_path.'work/work.php?origin='.$origin;
  1495. break;
  1496. case TOOL_DROPBOX:
  1497. $link .= $main_dir_path.'dropbox/index.php?origin=learnpath';
  1498. break;
  1499. case 'introduction_text': //DEPRECATED
  1500. $link .= '';
  1501. break;
  1502. case TOOL_COURSE_DESCRIPTION:
  1503. $link .= $main_dir_path.'course_description?origin=learnpath';
  1504. break;
  1505. case TOOL_GROUP:
  1506. $link .= $main_dir_path.'group/group.php?origin='.$origin;
  1507. break;
  1508. case TOOL_USER:
  1509. $link .= $main_dir_path.'user/user.php?origin='.$origin;
  1510. break;
  1511. case 'student_publication' :
  1512. $link .= $main_dir_path.'work/work.php?origin=learnpath';
  1513. break;
  1514. } //end switch
  1515. return $link;
  1516. }
  1517. /**
  1518. * Gets the name of a resource (generally used in learnpath when no name is provided)
  1519. *
  1520. * @author Yannick Warnier <ywarnier@beeznest.org>, Dokeos - rebranding
  1521. * @param string Course code
  1522. * @param string The tool type (using constants declared in main_api.lib.php)
  1523. * @param integer The resource ID
  1524. */
  1525. function rl_get_resource_name($course_code, $learnpath_id, $id_in_path) {
  1526. $_course = Database::get_course_info($course_code);
  1527. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1528. $sql_item = "SELECT * FROM $tbl_lp_item " .
  1529. "WHERE lp_id = $learnpath_id AND id = $id_in_path";
  1530. $res_item = Database::query($sql_item);
  1531. if (Database::num_rows($res_item) < 1) {
  1532. return ''; //exit
  1533. }
  1534. $row_item = Database::fetch_array($res_item);
  1535. $type = strtolower($row_item['item_type']);
  1536. $id = $row_item['ref'];
  1537. $output = '';
  1538. switch ($type) {
  1539. case TOOL_CALENDAR_EVENT:
  1540. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA,$_course['database']);
  1541. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE id=$id");
  1542. $myrow = Database::fetch_array($result);
  1543. $output = $myrow['title'];
  1544. break;
  1545. case TOOL_ANNOUNCEMENT:
  1546. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT,$_course['database']);
  1547. $result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id");
  1548. $myrow = Database::fetch_array($result);
  1549. $output = $myrow['title'];
  1550. break;
  1551. case TOOL_LINK:
  1552. // Doesn't take $target into account.
  1553. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK,$_course['database']);
  1554. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$id");
  1555. $myrow = Database::fetch_array($result);
  1556. $output = $myrow['title'];
  1557. break;
  1558. case TOOL_QUIZ:
  1559. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST,$_course['database']);
  1560. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE id=$id");
  1561. $myrow = Database::fetch_array($result);
  1562. $output = $myrow['title'];
  1563. break;
  1564. case TOOL_FORUM:
  1565. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM,$_course['database']);
  1566. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id");
  1567. $myrow = Database::fetch_array($result);
  1568. $output = $myrow['forum_name'];
  1569. break;
  1570. case TOOL_THREAD: //=topics
  1571. $tbl_post = Database::get_course_table(TABLE_FORUM_POST, $_course['database']);
  1572. // Grabbing the title of the post.
  1573. $sql_title = "SELECT * FROM $tbl_post WHERE post_id=".$id;
  1574. $result_title = Database::query($sql_title);
  1575. $myrow_title = Database::fetch_array($result_title);
  1576. $output = $myrow_title['post_title'];
  1577. break;
  1578. case TOOL_POST:
  1579. $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']);
  1580. //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE);
  1581. $sql = "SELECT * FROM $tbl_post p WHERE p.post_id = $id";
  1582. $result = Database::query($sql);
  1583. $post = Database::fetch_array($result);
  1584. $output = $post['post_title'];
  1585. break;
  1586. case 'dokeos_chapter':
  1587. $title = $row_item['title'];
  1588. if (!empty($title)) {
  1589. $output = $title;
  1590. } else {
  1591. $output = '-';
  1592. }
  1593. break;
  1594. case TOOL_DOCUMENT:
  1595. $title = $row_item['title'];
  1596. if (!empty($title)) {
  1597. $output = $title;
  1598. } else {
  1599. $output = '-';
  1600. }
  1601. break;
  1602. case 'hotpotatoes':
  1603. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT, $_course['database']);
  1604. $result = Database::query("SELECT * FROM $tbl_doc WHERE id=$id");
  1605. $myrow = Database::fetch_array($result);
  1606. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  1607. $last = count($pathname) - 1; // Making a correct name for the link.
  1608. $filename = $pathname[$last]; // Making a correct name for the link.
  1609. $image = choose_image($filename);
  1610. $ext = explode('.', $filename);
  1611. $ext = strtolower($ext[sizeof($ext) - 1]);
  1612. $myrow['path'] = rawurlencode($myrow['path']);
  1613. $in_frames = in_array($ext, array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png'));
  1614. $output = $filename;
  1615. break;
  1616. /*
  1617. case 'externallink':
  1618. $output = '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.' '.$target.'>'.$id."</a><br />\n";
  1619. break;
  1620. */
  1621. }
  1622. return stripslashes($output);
  1623. }