resourcelinker.inc.php 99 KB

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