resourcelinker.inc.php 98 KB

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