resourcelinker.inc.php 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Patrick Cool - original version
  5. * @author Denes Nagy - further improvements for learning path builder
  6. * @author Roan Embrechts - refactoring to improve code organisation
  7. * @package chamilo.resourcelinker
  8. * @todo use the constants for the tools
  9. * @todo use Database API instead of creating table names locally.
  10. */
  11. /**
  12. * Code
  13. */
  14. /* INIT SECTION */
  15. //$language_file = 'resourcelinker';
  16. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  17. use \ChamiloSession as Session;
  18. $use_anonymous = true;
  19. //require_once '../inc/global.inc.php';
  20. if (!empty($_course['language'])) {
  21. if (isset($resource_linker_file) && file_exists($resource_linker_file)) {
  22. require_once $resource_linker_file;
  23. }
  24. }
  25. require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php';
  26. /* FUNCTIONS */
  27. function unset_session_resources()
  28. {
  29. $_SESSION['addedresource'] = '';
  30. $_SESSION['addedresourceid'] = '';
  31. Session::erase(addedresource);
  32. Session::erase(addedresourceid);
  33. }
  34. /**
  35. * Insert description here.
  36. */
  37. function show_folder_up()
  38. {
  39. global $folder;
  40. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  41. $level = FileManager::get_levels($folder);
  42. if ($level == 1) {
  43. 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'>
  44. ".Display::return_icon('folder_up.gif', get_lang('LevelUp'))."</a>";
  45. }
  46. if ($level && $level != 0 && $level != 1) {
  47. $folder_up = $folder;
  48. $folder_temp = explode('/', $folder);
  49. $last = count($folder_temp) - 1;
  50. unset($folder_temp[$last]);
  51. $folder_up = implode('/', $folder_temp);
  52. 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'>
  53. ".Display::return_icon('folder_up.gif', get_lang('LevelUp'))."</a>";
  54. }
  55. }
  56. /**
  57. * Shows the documents of the document tool
  58. * @param $folder
  59. */
  60. function show_documents($folder)
  61. {
  62. $_course = api_get_course_info();
  63. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  64. // Documents are a special case: The teacher can add an invisible document (it will be viewable by the user)
  65. // other tools do not have this feature.
  66. if (api_is_allowed_to_edit()) {
  67. $visibility = "ip.visibility<>'2'";
  68. } else {
  69. $visibility = "ip.visibility='1'";
  70. }
  71. $course_id = api_get_course_int_id();
  72. $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  73. $document_table = Database::get_course_table(TABLE_DOCUMENT);
  74. $sql = "SELECT * from $document_table docs , $item_property_table ip
  75. WHERE docs.c_id = $course_id AND
  76. ip.c_id = $course_id AND
  77. docs.id=ip.ref AND ip.tool = '".TOOL_DOCUMENT."' AND $visibility AND ip.to_group_id = 0 AND ip.to_user_id IS NULL ORDER BY docs.path ASC";
  78. $result = Database::query($sql);
  79. while ($row = Database::fetch_array($result)) {
  80. if (!$folder) {
  81. if (FileManager::get_levels($row['path']) - 1 == 1) {
  82. // showing the right icon.
  83. if (file_or_folder($row['path'])) {
  84. echo Display::return_icon('file.gif');
  85. } else {
  86. $image = FileManager::choose_image($row['path']);
  87. echo Display::return_icon($image);
  88. }
  89. // Folders should be clickable.
  90. if (file_or_folder($row['path'])) {
  91. echo "<a href='".api_get_self()."?content=Document";
  92. echo "&folder=".substr(
  93. $row['path'],
  94. 1
  95. )."&source_id=$source_id&source_forum=".$_GET['source_forum']."&action=$action&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no'>".substr(
  96. $row['path'],
  97. 1
  98. ).'</a><br />';
  99. } else {
  100. echo substr($row['path'], 1).' ';
  101. echo showorhide_addresourcelink('Document', $row['id']);
  102. echo '<br />';
  103. }
  104. }
  105. } else {
  106. // We calculate the level we are in by using the $folder in the url.
  107. // We put +1 because it does not start with an / and in the database it does
  108. $level = FileManager::get_levels($folder) + 1;
  109. // We calculate each level of the database entry.
  110. $file_level = FileManager::get_levels($row['path']) - 1;
  111. // If the level of the database entry is equal to the level we ar in, we put it into an array
  112. // as this is a potential good entry.
  113. if ($file_level == $level) {
  114. $good_paths[] = $row['path'];
  115. $good_ids[] = $row['id'];
  116. }
  117. //$haystack=$row['path'];
  118. //$conform_folder=strstr($haystack, $folder);
  119. //if (str_replace($folder.'/', '', $conform_folder) !== $folder) {
  120. // $good_folders[] = $row['path'];
  121. //echo str_replace($folder.'/', '', $conform_folder);
  122. // echo '<br />';
  123. // }// if (str_replace($folder.'/','',$conform_folder)!==$folder)
  124. } // else (if (!$folder))
  125. } //while ($row=Database::fetch_array($result))
  126. // This is code for the case that we are in a subfolder.
  127. if ($good_paths) {
  128. // We have all the potential good database entries, the good ones are those that start with $folder
  129. foreach ($good_paths as $path) {
  130. if (strstr($path, $folder)) {
  131. $good_key = key($good_paths);
  132. // Showing the right icon.
  133. if (file_or_folder($path)) {
  134. echo Display::return_icon('file.gif');
  135. } else {
  136. $image = FileManager::choose_image($path);
  137. echo Display::return_icon($image);
  138. }
  139. // Folders should be clickable
  140. if (file_or_folder($path)) {
  141. $path = substr($path, 1); // Remove the first / in folder_up.
  142. $uri = str_replace($folder, $path, $_SERVER['REQUEST_URI']);
  143. $newuri = str_replace('add=', 'addnot=', $uri);
  144. // Using the correct name of the folder.
  145. $folder_name = str_replace($folder.'/', '', $path);
  146. echo "<a href='$newuri'>".$folder_name.'</a><br />';
  147. } else {
  148. echo str_replace("/$folder/", '', $path).' ';
  149. echo showorhide_addresourcelink('Document', $good_ids[$good_key]);
  150. echo '<br />';
  151. }
  152. }
  153. next($good_paths);
  154. }
  155. }
  156. }
  157. /**
  158. * Checks wether something is a file or a folder
  159. * 0 means file, 1 means folder
  160. * @param $filefolder
  161. * @todo use true and false instead of 1 and 0.
  162. */
  163. function file_or_folder($filefolder)
  164. {
  165. $_course = api_get_course_info();
  166. global $baseServDir;
  167. $courseDir = $_course['path'].'/document';
  168. $baseWorkDir = api_get_path(SYS_COURSE_PATH).$courseDir;
  169. return (is_dir($baseWorkDir.$filefolder) ? 1 : 0);
  170. }
  171. /**
  172. * Inserts a resource into the database
  173. *
  174. * @param $source_type
  175. * @param $source_id
  176. */
  177. function store_resources($source_type, $source_id)
  178. {
  179. $_course = api_get_course_info();
  180. $resource_table = Database::get_course_table(TABLE_LINKED_RESOURCES);
  181. $course_id = api_get_course_int_id();
  182. $addedresource = $_SESSION['addedresource'];
  183. $addedresourceid = $_SESSION['addedresourceid'];
  184. if ($_SESSION['addedresource']) {
  185. foreach ($addedresource as $resource_type) {
  186. $sql = "INSERT INTO $resource_table (c_id, source_type, source_id, resource_type, resource_id) VALUES
  187. ($course_id, '$source_type', '$source_id', '$resource_type', '".$addedresourceid[key($addedresource)]."')";
  188. Database::query($sql);
  189. $i = key($addedresource);
  190. next($addedresource);
  191. }
  192. $_SESSION['addedresource'] = '';
  193. $_SESSION['addedresourceid'] = '';
  194. }
  195. }
  196. /**
  197. * DEPRECATED - use rl_get_resource_link() instead - DEPRECATED
  198. * Displays the link that opens a new browser window that views the added resource.
  199. *
  200. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  201. * @param $type the type of the tool
  202. * @param $id the id of the resource
  203. * @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)
  204. * @todo use the constants for the type definitions.
  205. */
  206. function display_addedresource_link($type, $id, $style = '')
  207. {
  208. $_course = api_get_course_info();
  209. $course_id = api_get_course_int_id();
  210. // Styling the link of the added resource.
  211. if ($style != '') {
  212. $styling = ' class="'.$style.'"';
  213. }
  214. switch ($type) {
  215. case 'Agenda':
  216. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  217. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  218. $myrow = Database::fetch_array($result);
  219. echo Display::return_icon('agenda.gif');
  220. echo ' <a href="../calendar/agenda.php"'.$styling.'>'.$myrow['title']."</a>
  221. <br />";
  222. break;
  223. case 'Ad_Valvas':
  224. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  225. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  226. $myrow = Database::fetch_array($result);
  227. echo Display::return_icon('valves.gif');
  228. echo ' <a href="../announcements/announcements.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
  229. break;
  230. case 'Link':
  231. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  232. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  233. $myrow = Database::fetch_array($result);
  234. echo Display::return_icon('links.gif');
  235. echo ' <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.'>'.
  236. $myrow['title']."</a><br />";
  237. break;
  238. case 'Exercise':
  239. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  240. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $id");
  241. $myrow = Database::fetch_array($result);
  242. echo Display::return_icon('quiz.gif');
  243. echo ' <a href="../exercice/exercise_submit.php?exerciseId='.$myrow['id'].'"'.$styling.'>'.$myrow['title']."</a><br />";
  244. break;
  245. case 'Forum':
  246. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  247. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  248. $myrow = Database::fetch_array($result);
  249. echo Display::return_icon('forum.gif');
  250. echo ' <a href="../phpbb/viewforum.php?forum='.$myrow['forum_id'].'&amp;md5='.$myrow['md5'].'"'.$styling.'>'.$myrow['forum_name']."</a><br />";
  251. break;
  252. case 'Thread': //=topics
  253. //@deprecated bb_posts, bb_posts_text, bb_forums
  254. /*
  255. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  256. $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text';
  257. $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums';
  258. $result = Database::query("SELECT * FROM $tbl_posts posts, $TBL_FORUMS forum WHERE forum.forum_id=posts.forum_id and post_id=$id");
  259. $myrow = Database::fetch_array($result);
  260. // grabbing the title of the post
  261. $sql_title = "SELECT * FROM $tbl_posts_text WHERE c_id = $course_id AND post_id=".$myrow["post_id"];
  262. $result_title = Database::query($sql_title);
  263. $myrow_title = Database::fetch_array($result_title);
  264. 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";
  265. */
  266. break;
  267. case 'Post':
  268. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  269. $sql = "SELECT * FROM $tbl_post p WHERE c_id = $course_id AND post_id = $id";
  270. $result = Database::query($sql);
  271. $post = Database::fetch_object($result);
  272. echo Display::return_icon('forum.gif');
  273. echo ' <a href="../phpbb/viewtopic.php?topic='.$post->topic_id.'&amp;forum='.$post->forum_id.'"'.$styling.'>'.$post->post_title."</a><br />";
  274. break;
  275. case 'Document':
  276. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  277. $result = Database::query("SELECT * FROM $dbTable WHERE c_id = $course_id AND id=$id");
  278. $myrow = Database::fetch_array($result);
  279. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  280. $last = count($pathname) - 1; // Making a correct name for the link.
  281. $filename = $pathname[$last]; // Making a correct name for the link.
  282. $image = FileManager::choose_image($filename);
  283. $ext = explode('.', $filename);
  284. $ext = strtolower($ext[sizeof($ext) - 1]);
  285. $myrow['path'] = rawurlencode($myrow['path']);
  286. $array_ext = array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png');
  287. if (api_browser_support('svg')) {
  288. $array_ext[] = 'svg';
  289. }
  290. if (api_browser_support('ogg')) {
  291. $array_ext[] = 'ogg';
  292. }
  293. $in_frames = in_array($ext, $array_ext);
  294. echo Display::return_icon($image);
  295. echo ' <a href="../document/'.($in_frames ? 'showinframes.php?file=' : 'download.php?doc_url=').$myrow['path'].'"'.$styling.'>'.$filename."</a><br />";
  296. break;
  297. case 'Externallink':
  298. echo Display::return_icon('links.gif');
  299. echo ' <a href="'.$id.'"'.$styling.'>'.$id."</a><br />\n";
  300. break;
  301. }
  302. }
  303. /**
  304. * This function is to display the added resources (lessons) in the learning path player and builder
  305. * this function is a modification of display_addedresource_link($type, $id) function
  306. * the two ids are a bit confusing, I admit, but I did not want to change Patrick's work, I was
  307. * building upon it. - Denes
  308. *
  309. * Parameters:
  310. * @param completed - if ="completed" then green presentation with checkbox
  311. * @param id_in_path - if onclick then this lesson will be considered completed, that is the unique index in the items table
  312. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  313. * @param type - that is the correspondent type in the mirror tool (like this is a Link item)
  314. * @param builder - if ="builder" then onclick shows in new window
  315. * @param icon - if ="icon" then the small icon will appear
  316. * if ="wrap" then wrapped settings are used (and no icon is displayed)
  317. * 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)
  318. * @todo this function is too long, rewrite
  319. */
  320. function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_path, $builder, $icon, $level = 0)
  321. {
  322. global $learnpath_id, $tbl_learnpath_item, $items;
  323. global $curDirPath, $_configuration, $enableDocumentParsing, $_user, $_cid;
  324. $_course = api_get_course_info();
  325. $course_id = api_get_course_int_id();
  326. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  327. $hyperlink_target_parameter = ''; //or e.g. 'target="_blank"'
  328. $length = ((($builder == 'builder') && ($icon == 'nolink')) ? 65 : 32);
  329. if ($builder != 'builder') {
  330. $origin = 'learnpath';
  331. } //origin = learnpath in student view
  332. $linktype = $type;
  333. if (($type == 'Link _self') or ($type == 'Link _blank')) {
  334. $type = 'Link';
  335. }
  336. // YW switched litteral tool names to use of constants declared in api.lib.php
  337. switch ($type) {
  338. case TOOL_CALENDAR_EVENT:
  339. case 'Agenda':
  340. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  341. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  342. $myrow = Database::fetch_array($result);
  343. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  344. $result = Database::query($sql);
  345. $row = Database::fetch_array($result);
  346. if ($row['title'] != '') {
  347. $myrow['title'] = $row['title'];
  348. }
  349. $desc = $row['description'];
  350. $agenda_id = $row['item_id'];
  351. echo str_repeat("&nbsp;&gt;", $level);
  352. if (($builder != 'builder') && ($icon != 'wrap')) {
  353. echo "<td>";
  354. }
  355. if ($icon != 'nolink') {
  356. if ($completed == 'completed') {
  357. echo Display::return_icon('checkbox_on2.gif');
  358. //echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  359. } else {
  360. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden' ));
  361. //echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  362. }
  363. }
  364. if (($builder != 'builder') && ($icon != 'wrap')) {
  365. echo "</td><td>";
  366. }
  367. if ($myrow['title'] == '') {
  368. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  369. return (true);
  370. }
  371. if ($icon == 'nolink') {
  372. return (shorten($myrow['title'], $length));
  373. }
  374. if ($icon == 'icon') {
  375. echo Display::return_icon('agenda.gif');
  376. }
  377. if ($builder != 'builder') {
  378. echo "<a href=\"".api_get_self(
  379. )."?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(
  380. $myrow['title'],
  381. ($length - 3 * $level)
  382. )."</a>";
  383. $items[] = api_get_self(
  384. )."?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";
  385. if ($desc != '') {
  386. if ($icon != 'wrap') {
  387. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  388. $desc,
  389. ($length - 3 * $level)
  390. )."</div></td></tr>";
  391. } else {
  392. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  393. $desc,
  394. ($length - 3 * $level)
  395. )."</div>";
  396. }
  397. }
  398. } else {
  399. echo "<a href=\"../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id\" class='$completed' target='_blank'>".shorten(
  400. $myrow['title'],
  401. ($length - 3 * $level)
  402. )."</a>";
  403. }
  404. break;
  405. case TOOL_ANNOUNCEMENT:
  406. case 'Ad_Valvas':
  407. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  408. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  409. $myrow = Database::fetch_array($result);
  410. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  411. $result = Database::query($sql);
  412. $row = Database::fetch_array($result);
  413. if ($row['title'] != '') {
  414. $myrow['content'] = $row['title'];
  415. }
  416. $desc = $row['description'];
  417. $ann_id = $row['item_id'];
  418. echo str_repeat("&nbsp;&gt;", $level);
  419. // The title and the text are in the content field and we only want to display the title.
  420. list($title, $text) = split('<br>', $myrow['content']);
  421. if ($title == '') {
  422. $title = $myrow['content'];
  423. }
  424. $title = $myrow['title'];
  425. $text = $myrow['content'];
  426. if (($builder != 'builder') && ($icon != 'wrap')) {
  427. echo "<td>";
  428. }
  429. if ($icon != 'nolink') {
  430. if ($completed == 'completed') {
  431. echo Display::return_icon('checkbox_on2.gif');
  432. } else {
  433. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  434. //echo "&nbsp;";
  435. }
  436. }
  437. if (($builder != 'builder') && ($icon != 'wrap')) {
  438. echo "</td><td>";
  439. }
  440. if ($title == '') {
  441. $type = 'Announcement';
  442. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  443. 'StepDeleted2'
  444. )."</span>";
  445. return (true);
  446. }
  447. if ($icon == 'nolink') {
  448. return (shorten($title, $length));
  449. }
  450. if ($icon == 'icon') {
  451. echo Display::return_icon('valves.gif');
  452. }
  453. if ($builder != 'builder') {
  454. echo "<a href=\"".api_get_self(
  455. )."?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(
  456. $title,
  457. ($length - 3 * $level)
  458. )."</a>";
  459. $items[] = api_get_self(
  460. )."?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";
  461. if ($desc != '') {
  462. if ($icon != 'wrap') {
  463. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  464. $desc,
  465. ($length - 3 * $level)
  466. )."</div></td></tr>";
  467. } else {
  468. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  469. $desc,
  470. ($length - 3 * $level)
  471. )."</div>";
  472. }
  473. }
  474. } else {
  475. echo "<a href=\"../announcements/announcements.php?origin=$origin&ann_id=$ann_id\" class='$completed' target='_blank'>".shorten(
  476. $title,
  477. ($length - 3 * $level)
  478. )."</a>";
  479. }
  480. break;
  481. case TOOL_LINK:
  482. case 'Link':
  483. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  484. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  485. $myrow = Database::fetch_array($result);
  486. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  487. $result = Database::query($sql);
  488. $row = Database::fetch_array($result);
  489. if ($row['title'] != '') {
  490. $myrow['title'] = $row['title'];
  491. }
  492. $desc = $row['description'];
  493. echo str_repeat("&nbsp;&gt;", $level);
  494. if (($builder != 'builder') && ($icon != 'wrap')) {
  495. echo "<td>";
  496. }
  497. if ($icon != 'nolink') {
  498. if ($completed == 'completed') {
  499. echo Display::return_icon('checkbox_on2.gif');
  500. } else {
  501. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  502. }
  503. }
  504. if (($builder != 'builder') && ($icon != 'wrap')) {
  505. echo "</td><td>";
  506. }
  507. if ($myrow['title'] == '') {
  508. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  509. 'StepDeleted2'
  510. )."</span>";
  511. return (true);
  512. }
  513. if ($icon == 'nolink') {
  514. return (shorten($myrow['title'], $length));
  515. }
  516. if ($icon == 'icon') {
  517. if ($linktype == 'Link _self') {
  518. echo Display::return_icon('links.gif', get_lang('Links'));
  519. } else {
  520. echo Display::return_icon('link_blank.gif');
  521. }
  522. }
  523. $thelink = $myrow['url'];
  524. if ($builder != 'builder') {
  525. echo "<a href=\"".api_get_self(
  526. )."?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(
  527. $myrow['title'],
  528. ($length - 3 * $level)
  529. )."</a>";
  530. $items[] = api_get_self(
  531. )."?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";
  532. if ($desc != '') {
  533. if ($icon != 'wrap') {
  534. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  535. $desc,
  536. ($length - 3 * $level)
  537. )."</div></td></tr>";
  538. } else {
  539. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  540. $desc,
  541. ($length - 3 * $level)
  542. )."</div>";
  543. }
  544. }
  545. } else {
  546. echo "<a href=\"$thelink\" class='$completed' target='_blank'>".shorten(
  547. $myrow['title'],
  548. ($length - 3 * $level)
  549. )."</a>";
  550. }
  551. break;
  552. case TOOL_QUIZ :
  553. case 'Exercise':
  554. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  555. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $id");
  556. $myrow = Database::fetch_array($result);
  557. if ($builder == 'builder') {
  558. $origin = 'builder';
  559. }
  560. // This is needed for the exercise_submit.php can delete the session info about tests.
  561. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  562. $result = Database::query($sql);
  563. $row = Database::fetch_array($result);
  564. if ($row['title'] != '') {
  565. $myrow['title'] = $row['title'];
  566. }
  567. $desc = $row['description'];
  568. echo str_repeat("&nbsp;&gt;", $level);
  569. if (($builder != 'builder') && ($icon != 'wrap')) {
  570. echo "<td>";
  571. }
  572. if ($icon != 'nolink') {
  573. if ($completed == 'completed') {
  574. echo Display::return_icon('checkbox_on2.gif');
  575. } else {
  576. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  577. }
  578. }
  579. if (($builder != 'builder') && ($icon != 'wrap')) {
  580. echo "</td><td>";
  581. }
  582. if ($myrow['title'] == '') {
  583. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  584. 'StepDeleted2'
  585. )."</span>";
  586. return (true);
  587. }
  588. if ($icon == 'nolink') {
  589. return (shorten($myrow['title'], $length));
  590. }
  591. if ($icon == 'icon') {
  592. echo Display::return_icon('quiz.gif');
  593. }
  594. if ($builder != 'builder') {
  595. echo "<a href=\"".api_get_self(
  596. )."?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(
  597. $myrow['title'],
  598. ($length - 3 * $level)
  599. )."</a>";
  600. $items[] = api_get_self(
  601. )."?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";
  602. if ($desc != '') {
  603. if ($icon != 'wrap') {
  604. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  605. $desc,
  606. ($length - 3 * $level)
  607. )."</div></td></tr>";
  608. } else {
  609. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  610. $desc,
  611. ($length - 3 * $level)
  612. )."</div>";
  613. }
  614. }
  615. } else {
  616. echo "<a href=\"../exercice/exercise_submit.php?origin=$origin&exerciseId=".$myrow['id']."\" class='$completed' target='_blank'>".shorten(
  617. $myrow['title'],
  618. ($length - 3 * $level)
  619. )."</a>";
  620. }
  621. break;
  622. case 'hotpotatoes':
  623. case 'HotPotatoes':
  624. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  625. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  626. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND id=$id");
  627. $myrow = Database::fetch_array($result);
  628. $path = $myrow['path'];
  629. $name = GetQuizName($path, $documentPath);
  630. if ($builder == 'builder') {
  631. $origin = 'builder';
  632. }
  633. // This is needed for the exercise_submit.php can delete the session info about tests.
  634. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  635. $result = Database::query($sql);
  636. $row = Database::fetch_array($result);
  637. if ($row['title'] != '') {
  638. $name = $row['title'];
  639. }
  640. $desc = $row['description'];
  641. echo str_repeat("&nbsp;&gt;", $level);
  642. if (($builder != 'builder') && ($icon != 'wrap')) {
  643. echo "<td>";
  644. }
  645. if ($icon != 'nolink') {
  646. if ($completed == 'completed') {
  647. echo Display::return_icon('checkbox_on2.gif');
  648. } else {
  649. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  650. }
  651. }
  652. if (($builder != 'builder') && ($icon != 'wrap')) {
  653. echo "</td><td>";
  654. }
  655. if ($name == '') {
  656. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  657. 'StepDeleted2'
  658. )."</span>";
  659. return (true);
  660. }
  661. if ($icon == 'nolink') {
  662. return (shorten($name, $length));
  663. }
  664. if ($icon == 'icon') {
  665. echo Display::return_icon('jqz.gif');
  666. }
  667. $cid = $_course['official_code'];
  668. if ($builder != 'builder') {
  669. echo "<a href=\"".api_get_self(
  670. )."?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(
  671. $name,
  672. ($length - 3 * $level)
  673. )."</a>";
  674. $items[] = api_get_self(
  675. )."?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";
  676. if ($desc != '') {
  677. if ($icon != 'wrap') {
  678. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  679. $desc,
  680. ($length - 3 * $level)
  681. )."</div></td></tr>";
  682. } else {
  683. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  684. $desc,
  685. ($length - 3 * $level)
  686. )."</div>";
  687. }
  688. }
  689. } else {
  690. echo "&nbsp;<a href=\"../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id']."\" class='$completed' target='_blank'>".shorten(
  691. $name,
  692. ($length - 3 * $level)
  693. )."</a>";
  694. }
  695. break;
  696. case TOOL_FORUM:
  697. case 'Forum':
  698. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  699. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  700. $myrow = Database::fetch_array($result);
  701. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  702. $result = Database::query($sql);
  703. $row = Database::fetch_array($result);
  704. if ($row['title'] != '') {
  705. $myrow["forum_name"] = $row['title'];
  706. }
  707. $desc = $row['description'];
  708. echo str_repeat("&nbsp;&gt;", $level);
  709. if (($builder != 'builder') && ($icon != 'wrap')) {
  710. echo "<td>";
  711. }
  712. if ($icon != 'nolink') {
  713. if ($completed == 'completed') {
  714. echo Display::return_icon('checkbox_on2.gif');
  715. } else {
  716. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  717. }
  718. }
  719. if (($builder != 'builder') && ($icon != 'wrap')) {
  720. echo "</td><td>";
  721. }
  722. if ($myrow["forum_name"] == '') {
  723. $type = "Forum";
  724. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  725. 'StepDeleted2'
  726. )."</span>";
  727. return (true);
  728. }
  729. if ($icon == 'nolink') {
  730. return (shorten($myrow['forum_name'], $length));
  731. }
  732. if ($icon == 'icon') {
  733. echo Display::return_icon('forum.gif');
  734. }
  735. $forumparameters = "forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  736. if ($builder != 'builder') {
  737. echo "<a href=\"".api_get_self(
  738. )."?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(
  739. $myrow["forum_name"],
  740. ($length - 3 * $level)
  741. )."</a>";
  742. $items[] = api_get_self(
  743. )."?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";
  744. if ($desc != '') {
  745. if ($icon != 'wrap') {
  746. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  747. $desc,
  748. ($length - 3 * $level)
  749. )."</div></td></tr>";
  750. } else {
  751. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  752. $desc,
  753. ($length - 3 * $level)
  754. )."</div>";
  755. }
  756. }
  757. } else {
  758. echo "<a href=\"../phpbb/viewforum.php?$forumparameters\" class='$completed' target='_blank'>".shorten(
  759. $myrow["forum_name"],
  760. ($length - 3 * $level)
  761. )."</a>";
  762. }
  763. break;
  764. case TOOL_THREAD:
  765. case 'Thread': //forum post
  766. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD);
  767. $sql = "SELECT * FROM $tbl_topics where c_id = $course_id AND topic_id=$id";
  768. $result = Database::query($sql);
  769. $myrow = Database::fetch_array($result);
  770. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  771. $result = Database::query($sql);
  772. $row = Database::fetch_array($result);
  773. if ($row['title'] != '') {
  774. $myrow['topic_title'] = $row['title'];
  775. }
  776. $desc = $row['description'];
  777. echo str_repeat("&nbsp;&gt;", $level);
  778. if (($builder != 'builder') && ($icon != 'wrap')) {
  779. echo "<td>";
  780. }
  781. if ($icon != 'nolink') {
  782. if ($completed == 'completed') {
  783. echo Display::return_icon('checkbox_on2.gif');
  784. } else {
  785. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  786. }
  787. }
  788. if (($builder != 'builder') && ($icon != 'wrap')) {
  789. echo "</td><td>";
  790. }
  791. if ($myrow["topic_title"] == '') {
  792. $type = "Forum Post";
  793. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  794. 'StepDeleted2'
  795. )."</span>";
  796. return (true);
  797. }
  798. if ($icon == 'nolink') {
  799. return (shorten($myrow['topic_title'], $length));
  800. }
  801. if ($icon == 'icon') {
  802. echo Display::return_icon('forum.gif');
  803. }
  804. if ($builder != 'builder') {
  805. echo "<a href=\"".api_get_self(
  806. )."?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(
  807. $myrow["topic_title"],
  808. ($length - 3 * $level)
  809. )."</a>";
  810. $items[] = api_get_self(
  811. )."?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";
  812. if ($desc != '') {
  813. if ($icon != 'wrap') {
  814. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  815. $desc,
  816. ($length - 3 * $level)
  817. )."</div></td></tr>";
  818. } else {
  819. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  820. $desc,
  821. ($length - 3 * $level)
  822. )."</div>";
  823. }
  824. }
  825. } else {
  826. echo "<a href=\"../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."\" class='$completed' target='_blank'>".shorten(
  827. $myrow["topic_title"],
  828. ($length - 3 * $level)
  829. )."</a>";
  830. }
  831. break;
  832. case TOOL_POST:
  833. case 'Post':
  834. //deprecated
  835. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST);
  836. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  837. $result = Database::query("SELECT * FROM $tbl_posts where c_id = $course_id AND post_id=$id");
  838. $myrow = Database::fetch_array($result);
  839. // Grabbing the title of the post.
  840. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  841. $result = Database::query($sql);
  842. $row = Database::fetch_array($result);
  843. if ($row['title'] != '') {
  844. $myrow['post_title'] = $row['title'];
  845. }
  846. $desc = $row['description'];
  847. echo str_repeat("&nbsp;&gt;", $level);
  848. $posternom = $myrow['nom'];
  849. $posterprenom = $myrow['prenom'];
  850. $posttime = $myrow['post_time'];
  851. $posttext = $myrow['post_text'];
  852. $posttitle = $myrow['post_title'];
  853. $posttext = str_replace('"', "'", $posttext);
  854. if (($builder != 'builder') && ($icon != 'wrap')) {
  855. echo "<td>";
  856. }
  857. if ($icon != 'nolink') {
  858. if ($completed == 'completed') {
  859. echo Display::return_icon('checkbox_on2.gif');
  860. } else {
  861. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  862. }
  863. }
  864. if (($builder != 'builder') && ($icon != 'wrap')) {
  865. echo "</td><td>";
  866. }
  867. if ($myrow["post_title"] == '') {
  868. $type = 'Forum';
  869. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  870. 'StepDeleted2'
  871. )."</span>";
  872. return (true);
  873. }
  874. if ($icon == 'nolink') {
  875. return (shorten($myrow["post_title"], $length));
  876. }
  877. if ($icon == 'icon') {
  878. echo Display::return_icon('forum.gif');
  879. }
  880. if ($builder != 'builder') {
  881. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".intval(
  882. $_GET['source_forum']
  883. )."&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(
  884. $myrow["post_title"],
  885. ($length - 3 * $level)
  886. )."</a>";
  887. $items[] = api_get_self()."?action=closelesson&source_forum=".intval(
  888. $_GET['source_forum']
  889. )."&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";
  890. if ($desc != '') {
  891. if ($icon != 'wrap') {
  892. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  893. $desc,
  894. ($length - 3 * $level)
  895. )."</div></td></tr>";
  896. } else {
  897. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  898. $desc,
  899. ($length - 3 * $level)
  900. )."</div>";
  901. }
  902. }
  903. } else {
  904. echo "<a href=\"../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."\" class='$completed' target='_blank'>".shorten(
  905. $myrow["post_title"],
  906. ($length - 3 * $level)
  907. )."</a>";
  908. }
  909. break;
  910. case TOOL_DOCUMENT:
  911. case 'Document':
  912. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  913. $my_sql = "SELECT * FROM $dbTable WHERE c_id = $course_id AND id=$id";
  914. //error_log('New LP - Querying document table: '.$my_sql,0);
  915. $result = Database::query($my_sql);
  916. $myrow = Database::fetch_array($result);
  917. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  918. $last = count($pathname) - 1; // Making a correct name for the link.
  919. $filename = $pathname[$last]; // Making a correct name for the link.
  920. if (($builder != 'builder') && ($icon != 'wrap')) {
  921. echo "<td>";
  922. }
  923. echo str_repeat("&nbsp;&gt;", $level);
  924. if ($icon != 'nolink') {
  925. if ($completed == 'completed') {
  926. echo Display::return_icon('checkbox_on2.gif');
  927. } else {
  928. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  929. }
  930. }
  931. if (($builder != 'builder') && ($icon != 'wrap')) {
  932. echo "</td><td>";
  933. }
  934. $image = FileManager::choose_image($filename);
  935. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  936. //error_log('New LP - Querying lp_item table: '.$sql, 0);
  937. $result = Database::query($sql);
  938. $row = Database::fetch_array($result);
  939. if ($row['title'] != '') {
  940. $filename = $row['title'];
  941. }
  942. $desc = $row['description'];
  943. if (($myrow['path'] == '') && ($filename == '')) {
  944. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  945. 'StepDeleted2'
  946. )."</span>";
  947. return (true);
  948. }
  949. if ($icon == 'nolink') {
  950. return (shorten($filename, $length));
  951. }
  952. if ($icon == 'icon') {
  953. echo Display::return_icon($image);
  954. }
  955. if ($builder != 'builder') {
  956. echo "<a href=\"".api_get_self(
  957. )."?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(
  958. $filename,
  959. ($length - 3 * $level)
  960. )."</a>";
  961. if ($desc != '') {
  962. if ($icon != 'wrap') {
  963. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  964. $desc,
  965. ($length - 3 * $level)
  966. )."</div></td></tr>";
  967. } else {
  968. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  969. $desc,
  970. ($length - 3 * $level)
  971. )."</div>";
  972. }
  973. }
  974. $items[] = api_get_self(
  975. )."?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";
  976. } else {
  977. $enableDocumentParsing = yes;
  978. if (!$enableDocumentParsing) {
  979. // This is the solution for the non-parsing version in the builder.
  980. $file = urlencode($myrow['path']);
  981. echo "<a href='../document/showinframes.php?file=$file' class='$completed' $hyperlink_target_parameter>".shorten(
  982. $filename,
  983. ($length - 3 * $level)
  984. )."</a>";
  985. } else {
  986. echo "<a href=\"../document/download.php?doc_url=".$myrow['path']."\" class='$completed' $hyperlink_target_parameter>".shorten(
  987. $filename,
  988. ($length - 3 * $level)
  989. )."</a>";
  990. }
  991. }
  992. break;
  993. case 'assignments':
  994. case 'Assignments':
  995. $name = get_lang('Assignments');
  996. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  997. $result = Database::query($sql);
  998. $row = Database::fetch_array($result);
  999. if ($row['title'] != '') {
  1000. $name = $row['title'];
  1001. }
  1002. $desc = $row['description'];
  1003. echo str_repeat("&nbsp;&gt;", $level);
  1004. if (($builder != 'builder') && ($icon != 'wrap')) {
  1005. echo "<td>";
  1006. }
  1007. if ($icon != 'nolink') {
  1008. if ($completed == 'completed') {
  1009. echo Display::return_icon('checkbox_on2.gif');
  1010. } else {
  1011. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  1012. }
  1013. }
  1014. if (($builder != 'builder') && ($icon != 'wrap')) {
  1015. echo "</td><td>";
  1016. }
  1017. if ($name == '') {
  1018. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  1019. 'StepDeleted2'
  1020. )."</span>";
  1021. return (true);
  1022. }
  1023. if ($icon == 'nolink') {
  1024. return (shorten($name, $length));
  1025. }
  1026. if ($icon == 'icon') {
  1027. echo Display::return_icon('works.gif');
  1028. }
  1029. if ($builder != 'builder') {
  1030. echo "<a href=\"".api_get_self(
  1031. )."?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(
  1032. $name,
  1033. ($length - 3 * $level)
  1034. )."</a>";
  1035. $items[] = api_get_self(
  1036. )."?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";
  1037. if ($desc != '') {
  1038. if ($icon != 'wrap') {
  1039. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  1040. $desc,
  1041. ($length - 3 * $level)
  1042. )."</div></td></tr>";
  1043. } else {
  1044. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  1045. $desc,
  1046. ($length - 3 * $level)
  1047. )."</div>";
  1048. }
  1049. }
  1050. } else {
  1051. echo "<a href=\"../work/work.php\" class='$completed' target='_blank'>".shorten(
  1052. $name,
  1053. ($length - 3 * $level)
  1054. )."</a>";
  1055. }
  1056. break;
  1057. case TOOL_DROPBOX:
  1058. case 'Dropbox':
  1059. $name = get_lang('Dropbox');
  1060. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1061. $result = Database::query($sql);
  1062. $row = Database::fetch_array($result);
  1063. if ($row['title'] != '') {
  1064. $name = $row['title'];
  1065. }
  1066. $desc = $row['description'];
  1067. echo str_repeat("&nbsp;&gt;", $level);
  1068. if (($builder != 'builder') && ($icon != 'wrap')) {
  1069. echo "<td>";
  1070. }
  1071. if ($icon != 'nolink') {
  1072. if ($completed == 'completed') {
  1073. echo Display::return_icon('checkbox_on2.gif');
  1074. } else {
  1075. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  1076. }
  1077. }
  1078. if (($builder != 'builder') && ($icon != 'wrap')) {
  1079. echo "</td><td>";
  1080. }
  1081. if ($name == '') {
  1082. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  1083. 'StepDeleted2'
  1084. )."</span>";
  1085. return (true);
  1086. }
  1087. if ($icon == 'nolink') {
  1088. return (shorten($name, $length));
  1089. }
  1090. if ($icon == 'icon') {
  1091. echo Display::return_icon('dropbox.gif');
  1092. }
  1093. if ($builder != 'builder') {
  1094. echo "<a href=\"".api_get_self(
  1095. )."?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(
  1096. $name,
  1097. ($length - 3 * $level)
  1098. )."</a>";
  1099. $items[] = api_get_self(
  1100. )."?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";
  1101. if ($desc != '') {
  1102. if ($icon != 'wrap') {
  1103. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  1104. $desc,
  1105. ($length - 3 * $level)
  1106. )."</div></td></tr>";
  1107. } else {
  1108. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  1109. $desc,
  1110. ($length - 3 * $level)
  1111. )."</div>";
  1112. }
  1113. }
  1114. } else {
  1115. echo "<a href=\"../dropbox/index.php\" class='$completed' target='_blank'>".shorten(
  1116. $name,
  1117. ($length - 3 * $level)
  1118. )."</a>";
  1119. }
  1120. break;
  1121. case 'introduction_text':
  1122. case 'Introduction_text':
  1123. $name = get_lang('IntroductionText');
  1124. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1125. $result = Database::query($sql);
  1126. $row = Database::fetch_array($result);
  1127. if ($row['title'] != '') {
  1128. $name = $row['title'];
  1129. }
  1130. $desc = $row['description'];
  1131. echo str_repeat("&nbsp;&gt;", $level);
  1132. if (($builder != 'builder') && ($icon != 'wrap')) {
  1133. echo "<td>";
  1134. }
  1135. if ($icon != 'nolink') {
  1136. if ($completed == 'completed') {
  1137. echo Display::return_icon('checkbox_on2.gif');
  1138. } else {
  1139. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  1140. }
  1141. }
  1142. if (($builder != 'builder') && ($icon != 'wrap')) {
  1143. echo "</td><td>";
  1144. }
  1145. if ($name == '') {
  1146. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  1147. 'StepDeleted2'
  1148. )."</span>";
  1149. return (true);
  1150. }
  1151. if ($icon == 'nolink') {
  1152. return (shorten($name, $length));
  1153. }
  1154. if ($icon == 'icon') {
  1155. echo Display::return_icon('introduction.gif');
  1156. }
  1157. if ($builder != 'builder') {
  1158. echo "<a href=\"".api_get_self(
  1159. )."?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(
  1160. $name,
  1161. ($length - 3 * $level)
  1162. )."</a>";
  1163. $items[] = api_get_self(
  1164. )."?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";
  1165. if ($desc != '') {
  1166. if ($icon != 'wrap') {
  1167. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  1168. $desc,
  1169. ($length - 3 * $level)
  1170. )."</div></td></tr>";
  1171. } else {
  1172. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  1173. $desc,
  1174. ($length - 3 * $level)
  1175. )."</div>";
  1176. }
  1177. }
  1178. } else {
  1179. $s = api_get_path(WEB_COURSE_PATH)."$_cid/index.php?intro_cmdEdit=1";
  1180. echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name, ($length - 3 * $level))."</a>";
  1181. }
  1182. break;
  1183. case TOOL_COURSE_DESCRIPTION:
  1184. case 'Course_description':
  1185. $name = get_lang('CourseDescription');
  1186. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1187. $result = Database::query($sql);
  1188. $row = Database::fetch_array($result);
  1189. if ($row['title'] != '') {
  1190. $name = $row['title'];
  1191. }
  1192. $desc = $row['description'];
  1193. echo str_repeat("&nbsp;&gt;", $level);
  1194. if (($builder != 'builder') && ($icon != 'wrap')) {
  1195. echo "<td>";
  1196. }
  1197. if ($icon != 'nolink') {
  1198. if ($completed == 'completed') {
  1199. echo Display::return_icon('checkbox_on2.gif');
  1200. } else {
  1201. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  1202. }
  1203. }
  1204. if (($builder != 'builder') && ($icon != 'wrap')) {
  1205. echo "</td><td>";
  1206. }
  1207. if ($name == '') {
  1208. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  1209. 'StepDeleted2'
  1210. )."</span>";
  1211. return (true);
  1212. }
  1213. if ($icon == 'nolink') {
  1214. return (shorten($name, $length));
  1215. }
  1216. if ($icon == 'icon') {
  1217. echo Display::return_icon('info.gif');
  1218. }
  1219. if ($builder != 'builder') {
  1220. echo "<a href=\"".api_get_self(
  1221. )."?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(
  1222. $name,
  1223. ($length - 3 * $level)
  1224. )."</a>";
  1225. $items[] = api_get_self(
  1226. )."?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";
  1227. if ($desc != '') {
  1228. if ($icon != 'wrap') {
  1229. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  1230. $desc,
  1231. ($length - 3 * $level)
  1232. )."</div></td></tr>";
  1233. } else {
  1234. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  1235. $desc,
  1236. ($length - 3 * $level)
  1237. )."</div>";
  1238. }
  1239. }
  1240. } else {
  1241. $s = api_get_path(WEB_CODE_PATH)."course_description";
  1242. echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name, ($length - 3 * $level))."</a>";
  1243. }
  1244. break;
  1245. case TOOL_GROUP:
  1246. case 'Groups':
  1247. $name = get_lang('Groups');
  1248. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1249. $result = Database::query($sql);
  1250. $row = Database::fetch_array($result);
  1251. if ($row['title'] != '') {
  1252. $name = $row['title'];
  1253. }
  1254. $desc = $row['description'];
  1255. echo str_repeat("&nbsp;&gt;", $level);
  1256. if (($builder != 'builder') && ($icon != 'wrap')) {
  1257. echo "<td>";
  1258. }
  1259. if ($icon != 'nolink') {
  1260. if ($completed == 'completed') {
  1261. echo Display::return_icon('checkbox_on2.gif');
  1262. } else {
  1263. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  1264. }
  1265. }
  1266. if (($builder != 'builder') && ($icon != 'wrap')) {
  1267. echo "</td><td>";
  1268. }
  1269. if ($name == '') {
  1270. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  1271. 'StepDeleted2'
  1272. )."</span>";
  1273. return (true);
  1274. }
  1275. if ($icon == 'nolink') {
  1276. return (shorten($name, $length));
  1277. }
  1278. if ($icon == 'icon') {
  1279. echo Display::return_icon('group.gif');
  1280. }
  1281. if ($builder != 'builder') {
  1282. echo "<a href=\"".api_get_self(
  1283. )."?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(
  1284. $name,
  1285. ($length - 3 * $level)
  1286. )."</a>";
  1287. $items[] = api_get_self(
  1288. )."?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";
  1289. if ($desc != '') {
  1290. if ($icon != 'wrap') {
  1291. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  1292. $desc,
  1293. ($length - 3 * $level)
  1294. )."</div></td></tr>";
  1295. } else {
  1296. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  1297. $desc,
  1298. ($length - 3 * $level)
  1299. )."</div>";
  1300. }
  1301. }
  1302. } else {
  1303. echo "<a href=\"../group/group.php?origin=$origin\" class='$completed' target='_blank'>".shorten(
  1304. $name,
  1305. ($length - 3 * $level)
  1306. )."</a>";
  1307. }
  1308. break;
  1309. case TOOL_USER:
  1310. case 'Users':
  1311. $name = get_lang('Users');
  1312. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1313. $result = Database::query($sql);
  1314. $row = Database::fetch_array($result);
  1315. if ($row['title'] != '') {
  1316. $name = $row['title'];
  1317. }
  1318. $desc = $row['description'];
  1319. echo str_repeat("&nbsp;&gt;", $level);
  1320. if (($builder != 'builder') && ($icon != 'wrap')) {
  1321. echo "<td>";
  1322. }
  1323. if ($icon != 'nolink') {
  1324. if ($completed == 'completed') {
  1325. echo Display::return_icon('checkbox_on2.gif');
  1326. } else {
  1327. echo Display::return_icon('checkbox_on2.gif', 'on', array('style' => 'visibility: hidden'));
  1328. }
  1329. }
  1330. if (($builder != 'builder') && ($icon != 'wrap')) {
  1331. echo "</td><td>";
  1332. }
  1333. if ($name == '') {
  1334. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  1335. 'StepDeleted2'
  1336. )."</span>";
  1337. return (true);
  1338. }
  1339. if ($icon == 'nolink') {
  1340. return (shorten($name, $length));
  1341. }
  1342. if ($icon == 'icon') {
  1343. echo Display::return_icon('members.gif');
  1344. }
  1345. if ($builder != 'builder') {
  1346. echo "<a href=\"".api_get_self(
  1347. )."?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(
  1348. $name,
  1349. ($length - 3 * $level)
  1350. )."</a>";
  1351. $items[] = api_get_self(
  1352. )."?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";
  1353. if ($desc != '') {
  1354. if ($icon != 'wrap') {
  1355. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  1356. $desc,
  1357. ($length - 3 * $level)
  1358. )."</div></td></tr>";
  1359. } else {
  1360. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  1361. $desc,
  1362. ($length - 3 * $level)
  1363. )."</div>";
  1364. }
  1365. }
  1366. } else {
  1367. echo "<a href=\"../user/user.php?origin=$origin\" class='$completed' target='_blank'>".shorten(
  1368. $name,
  1369. ($length - 3 * $level)
  1370. )."</a>";
  1371. }
  1372. break;
  1373. }
  1374. //end huge switch-statement
  1375. }
  1376. /**
  1377. * This function is to create and return a link to the added resources (lessons).
  1378. * It returns the same thing as display_addedresource_link_in_learnpath() but doesn't display
  1379. * anything.
  1380. *
  1381. * Parameters:
  1382. * @param type - that is the correspondent type in the mirror tool (like this is a Link item)
  1383. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  1384. * @param id_in_path - the unique index in the items table
  1385. */
  1386. function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
  1387. {
  1388. global $learnpath_id, $tbl_learnpath_item, $items;
  1389. global $curDirPath, $_configuration, $enableDocumentParsing, $_user, $_cid;
  1390. $_course = api_get_course_info();
  1391. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1392. $course_id = api_get_course_int_id();
  1393. $hyperlink_target_parameter = ''; // or e.g. target='_blank'
  1394. $builder = 'player';
  1395. $origin = 'learnpath';
  1396. $linktype = $type;
  1397. if (($type == 'Link _self') || ($type == 'Link _blank')) {
  1398. $type = 'Link';
  1399. }
  1400. $link = '';
  1401. switch ($type) {
  1402. case 'Agenda':
  1403. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  1404. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  1405. $myrow = Database::fetch_array($result);
  1406. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1407. $result = Database::query($sql);
  1408. $row = Database::fetch_array($result);
  1409. if ($row['title'] != '') {
  1410. $myrow['title'] = $row['title'];
  1411. }
  1412. $desc = $row['description'];
  1413. $agenda_id = $row['item_id'];
  1414. if ($builder != 'builder') {
  1415. $link .= api_get_self(
  1416. )."?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";
  1417. } else {
  1418. $link .= "../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id";
  1419. }
  1420. break;
  1421. case 'Ad_Valvas':
  1422. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1423. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  1424. $myrow = Database::fetch_array($result);
  1425. if ($builder != 'builder') {
  1426. $link .= api_get_self(
  1427. )."?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";
  1428. } else {
  1429. $link .= "../announcements/announcements.php?origin=$origin&ann_id=$id";
  1430. }
  1431. break;
  1432. case 'Link':
  1433. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  1434. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  1435. $myrow = Database::fetch_array($result);
  1436. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1437. $result = Database::query($sql);
  1438. $row = Database::fetch_array($result);
  1439. $thelink = $myrow['url'];
  1440. if ($builder != 'builder') {
  1441. $link .= api_get_self(
  1442. )."?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";
  1443. } else {
  1444. $link .= $thelink;
  1445. }
  1446. break;
  1447. case 'Exercise':
  1448. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  1449. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $id");
  1450. $myrow = Database::fetch_array($result);
  1451. if ($builder == 'builder') {
  1452. $origin = 'builder';
  1453. }
  1454. // This is needed for the exercise_submit.php can delete the session info about tests.
  1455. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id = $id_in_path";
  1456. $result = Database::query($sql);
  1457. $row = Database::fetch_array($result);
  1458. if ($row['title'] != '') {
  1459. $myrow['title'] = $row['title'];
  1460. }
  1461. if ($builder != 'builder') {
  1462. $link .= api_get_self(
  1463. )."?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";
  1464. } else {
  1465. $link .= "../exercice/exercise_submit.php?origin=$origin&exerciseId=".$myrow["id"];
  1466. }
  1467. break;
  1468. case 'HotPotatoes':
  1469. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  1470. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  1471. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND id=$id");
  1472. $myrow = Database::fetch_array($result);
  1473. $path = $myrow['path'];
  1474. $name = GetQuizName($path, $documentPath);
  1475. if ($builder == 'builder') {
  1476. $origin = 'builder';
  1477. }
  1478. $cid = $_course['official_code'];
  1479. if ($builder != 'builder') {
  1480. $link .= api_get_self(
  1481. )."?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";
  1482. } else {
  1483. $link .= "../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id'];
  1484. }
  1485. break;
  1486. case 'Forum':
  1487. //deprecated
  1488. $TBL_FORUMS = Database::get_course_table(
  1489. TABLE_FORUM
  1490. ); // TODO: This is the old table name, it should be corrected.
  1491. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  1492. $myrow = Database::fetch_array($result);
  1493. if ($builder == 'builder') {
  1494. $origin = 'builder';
  1495. }
  1496. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1497. $result = Database::query($sql);
  1498. $row = Database::fetch_array($result);
  1499. if ($row['title'] != '') {
  1500. $myrow['forum_name'] = $row['title'];
  1501. }
  1502. if ($myrow['forum_name'] == '') {
  1503. $type = 'Forum';
  1504. }
  1505. $forumparameters = "forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1506. if ($builder != 'builder') {
  1507. $link .= api_get_self(
  1508. )."?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";
  1509. } else {
  1510. $link .= "../phpbb/viewforum.php?$forumparameters";
  1511. }
  1512. break;
  1513. case 'Thread': //forum post
  1514. //deprecated
  1515. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD);
  1516. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST);
  1517. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  1518. $sql = "SELECT * FROM $tbl_topics where c_id = $course_id AND topic_id=$id";
  1519. $result = Database::query($sql);
  1520. $myrow = Database::fetch_array($result);
  1521. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1522. $result = Database::query($sql);
  1523. $row = Database::fetch_array($result);
  1524. if ($builder != 'builder') {
  1525. $link .= api_get_self(
  1526. )."?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";
  1527. } else {
  1528. $link .= "../forum/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1529. }
  1530. break;
  1531. case 'Post':
  1532. //deprecated
  1533. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST);
  1534. $result = Database::query("SELECT * FROM $tbl_posts where c_id = $course_id AND post_id=$id");
  1535. $myrow = Database::fetch_array($result);
  1536. // Grabbing the title of the post.
  1537. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1538. $result = Database::query($sql);
  1539. $row = Database::fetch_array($result);
  1540. if ($row['title'] != '') {
  1541. $myrow['post_title'] = $row['title'];
  1542. }
  1543. $desc = $row['description'];
  1544. //$link .= str_repeat("&nbsp;&gt;", $level);
  1545. $posternom = $myrow['nom'];
  1546. $posterprenom = $myrow['prenom'];
  1547. $posttime = $myrow['post_time'];
  1548. $posttext = $myrow['post_text'];
  1549. $posttitle = $myrow['post_title'];
  1550. $posttext = str_replace('"', "'", $posttext);
  1551. if ($builder != 'builder') {
  1552. $link .= api_get_self(
  1553. )."?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";
  1554. } else {
  1555. $link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1556. }
  1557. break;
  1558. case 'Document':
  1559. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  1560. $result = Database::query("SELECT * FROM $dbTable WHERE id=$id");
  1561. $myrow = Database::fetch_array($result);
  1562. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  1563. $last = count($pathname) - 1; // Making a correct name for the link.
  1564. $filename = $pathname[$last]; // Making a correct name for the link.
  1565. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1566. $result = Database::query($sql);
  1567. $row = Database::fetch_array($result);
  1568. if ($builder != 'builder') {
  1569. $link .= api_get_self(
  1570. )."?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";
  1571. } else {
  1572. $enableDocumentParsing = yes;
  1573. if (!$enableDocumentParsing) {
  1574. // This is the solution for the non-parsing version in the builder.
  1575. $file = urlencode($myrow['path']);
  1576. $link .= "../document/showinframes.php?file=$file";
  1577. } else {
  1578. $link .= "../document/download.php?doc_url=".$myrow['path'];
  1579. }
  1580. }
  1581. break;
  1582. case 'Assignments':
  1583. if ($builder != 'builder') {
  1584. $link .= api_get_self(
  1585. )."?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";
  1586. } else {
  1587. $link .= "../work/work.php";
  1588. }
  1589. break;
  1590. case 'Dropbox':
  1591. if ($builder != 'builder') {
  1592. $link .= api_get_self(
  1593. )."?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";
  1594. } else {
  1595. $link .= "../dropbox/index.php";
  1596. }
  1597. break;
  1598. case 'Introduction_text':
  1599. if ($builder != 'builder') {
  1600. $link .= api_get_self(
  1601. )."?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";
  1602. } else {
  1603. $s = api_get_path(WEB_COURSE_PATH)."$_cid/index.php?intro_cmdEdit=1";
  1604. $link .= $s;
  1605. }
  1606. break;
  1607. case 'Course_description':
  1608. if ($builder != 'builder') {
  1609. $link .= api_get_self(
  1610. )."?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";
  1611. } else {
  1612. $s = api_get_path(WEB_CODE_PATH).'course_description';
  1613. $link .= $s;
  1614. }
  1615. break;
  1616. case 'Groups':
  1617. if ($builder != 'builder') {
  1618. $link .= api_get_self(
  1619. )."?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";
  1620. } else {
  1621. $link .= "../group/group.php?origin=$origin";
  1622. }
  1623. break;
  1624. case 'Users':
  1625. if ($builder != 'builder') {
  1626. $link .= api_get_self(
  1627. )."?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";
  1628. } else {
  1629. $link .= "../user/user.php?origin=$origin";
  1630. }
  1631. break;
  1632. }
  1633. //end huge switch-statement
  1634. return $link;
  1635. }
  1636. /**
  1637. * This function is to remove an resource item from the array
  1638. */
  1639. function remove_resource($resource_key)
  1640. {
  1641. $addedresource = $_SESSION['addedresource'];
  1642. $addedresourceid = $_SESSION['addedresourceid'];
  1643. unset($addedresource[$resource_key]);
  1644. unset($addedresourceid[$resource_key]);
  1645. $_SESSION['addedresource'] = $addedresource;
  1646. $_SESSION['addedresourceid'] = $addedresourceid;
  1647. }
  1648. /**
  1649. * This function is to show the button "click to add resource" on the tool page
  1650. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1651. */
  1652. function show_addresource_button($additionalparameters = '')
  1653. {
  1654. global $charset;
  1655. echo '<label for="addresources">
  1656. '.Display::return_icon('attachment.gif').'
  1657. </label><input class="link_alike" type="submit" name="addresources" id="addresources" value="'.api_htmlentities(
  1658. get_lang('Attachment'),
  1659. ENT_QUOTES,
  1660. $charset
  1661. ).'" '.$additionalparameters.' />';
  1662. }
  1663. /**
  1664. * This function is to delete ONE specific resource that were added to a specific item
  1665. * Deprecated
  1666. */
  1667. /*
  1668. function delete_one_added_resource($source_type, $source_id, $resource_type, $resource_id) {
  1669. //echo "delete_one_added_resource";
  1670. $_course = api_get_course_info();
  1671. $TABLERESOURCE = $_course['dbNameGlu'].'resource';
  1672. $sql = "DELETE FROM $TABLERESOURCE WHERE source_type='$source_type' and source_id='$source_id' and resource_type='$resource_type' and resource_id='$resource_id'";
  1673. Database::query($sql);
  1674. }*/
  1675. /**
  1676. * This function is to delete the resources that were added to a specific item
  1677. */
  1678. function delete_added_resource($type, $id)
  1679. {
  1680. $course_id = api_get_course_int_id();
  1681. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1682. $sql = "DELETE FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' and source_id='$id'";
  1683. Database::query($sql);
  1684. }
  1685. /**
  1686. * This function is te delete all resources of a specific type (only used in announcements -- delete all)
  1687. * Author : Frederik Vermeire <frederik.vermeire@pandora.be>
  1688. */
  1689. function delete_all_resources_type($type)
  1690. {
  1691. $course_id = api_get_course_int_id();
  1692. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1693. $sql = "DELETE FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type'";
  1694. Database::query($sql);
  1695. }
  1696. /**
  1697. * This function checks wether there are added resources or not
  1698. */
  1699. function check_added_resources($type, $id)
  1700. {
  1701. $course_id = api_get_course_int_id();
  1702. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1703. $sql = "SELECT * FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' and source_id='$id'";
  1704. $result = Database::query($sql);
  1705. $number_added = Database::num_rows($result);
  1706. if ($number_added != 0) {
  1707. return true;
  1708. } else {
  1709. return false;
  1710. }
  1711. }
  1712. /**
  1713. * this function is to load the resources that were added to a specific item
  1714. * into the session variables
  1715. */
  1716. function edit_added_resources($type, $id)
  1717. {
  1718. $_course = api_get_course_info();
  1719. $course_id = api_get_course_int_id();
  1720. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1721. $sql = "SELECT * FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' and source_id=$id";
  1722. $result = Database::query($sql);
  1723. while ($row = Database::fetch_array($result)) {
  1724. $addedresource[] = $row["resource_type"];
  1725. $addedresourceid[] = $row["resource_id"];
  1726. }
  1727. $_SESSION['addedresource'] = $addedresource;
  1728. $_SESSION['addedresourceid'] = $addedresourceid;
  1729. }
  1730. /**
  1731. * this function is store the modified resources
  1732. * first we delete all the added resources in the database,
  1733. * then we add all the resources from the session object.
  1734. */
  1735. function update_added_resources($type, $id)
  1736. {
  1737. $_course = api_get_course_info();
  1738. $course_id = api_get_course_int_id();
  1739. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1740. // delete all the added resources for this item in the database;
  1741. $sql = "DELETE FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' AND source_id='$id'";
  1742. //echo $sql;
  1743. Database::query($sql);
  1744. // Store the resources from the session into the database.
  1745. store_resources($type, $id);
  1746. //delete_added_resource_($type, $id);
  1747. unset_session_resources();
  1748. }
  1749. /**
  1750. * this function is to display the resources that were added to a specific item
  1751. */
  1752. function display_added_resources($type, $id, $style = '')
  1753. {
  1754. $course_id = api_get_course_int_id();
  1755. global $origin;
  1756. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1757. $sql = "SELECT * FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' and source_id='$id'";
  1758. $result = Database::query($sql);
  1759. while ($row = Database::fetch_array($result)) {
  1760. if ($origin != 'learnpath') {
  1761. display_addedresource_link($row['resource_type'], $row['resource_id'], $style);
  1762. } else {
  1763. display_addedresource_link_in_learnpath(
  1764. $row['resource_type'],
  1765. $row['resource_id'],
  1766. 'agendaitems',
  1767. '',
  1768. 'builder',
  1769. 'icon'
  1770. );
  1771. echo "<br>";
  1772. }
  1773. }
  1774. }
  1775. /**
  1776. * This function is to show the added resources when adding an item
  1777. * $showdeleteimg determine if the delete image should appear or not.
  1778. * deleting an added resource is only possible through the resource linker file itself
  1779. */
  1780. function display_resources($showdeleteimg)
  1781. {
  1782. global $action;
  1783. global $resourceaction;
  1784. global $id;
  1785. global $locationkey;
  1786. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  1787. if ($resourceaction == 'removeresource') {
  1788. remove_resource($locationkey);
  1789. }
  1790. $addedresource = $_SESSION['addedresource'];
  1791. $addedresourceid = $_SESSION['addedresourceid'];
  1792. if (is_array($addedresource)) {
  1793. echo '<table>';
  1794. foreach ($addedresource as $resource) {
  1795. echo '<tr><td>';
  1796. display_addedresource_link($resource, $addedresourceid[key($addedresource)]);
  1797. echo '</td><td width="30">';
  1798. // if $_SERVER['REQUEST_URI'] contains and ?id=xx we have an edit and the url for deleting a session added resource
  1799. // should also contain this id.
  1800. $test = parse_url($_SERVER['REQUEST_URI']);
  1801. $output = array();
  1802. parse_str($test[query], $output);
  1803. if ($showdeleteimg == 1) {
  1804. echo "<a href=".api_get_self(
  1805. )."?showresources=true&amp;source_forum=".$_GET['source_forum']."&amp;resourceaction=removeresource&amp;locationkey=".key(
  1806. $addedresource
  1807. )."&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no>
  1808. ".Display::return_icon('delete.gif', get_lang('Delete'))."
  1809. </a><br />";
  1810. }
  1811. echo '</td></tr>';
  1812. next($addedresource);
  1813. }
  1814. echo '</table>';
  1815. } else { // it is a string
  1816. echo '';
  1817. }
  1818. } // end of the display_resources function
  1819. /**
  1820. * This function checks wether the link add resource should be displayed next the item in the linker page
  1821. * So we have to check if the specific id of that tool is already in the array of the added resources
  1822. * if it is already in, the link should not be showed since it would make it possible to add
  1823. * the same resource a second time (=duplication of added resources)
  1824. */
  1825. function showorhide_addresourcelink($type, $id)
  1826. {
  1827. global $from_learnpath, $source_id, $action, $learnpath_id, $chapter_id, $originalresource, $folder, $content, $target;
  1828. $addedresource = $_SESSION['addedresource'];
  1829. $addedresourceid = $_SESSION['addedresourceid'];
  1830. if (is_array($_SESSION['addedresource'])) {
  1831. foreach ($addedresource as $toolcompare) {
  1832. if ($toolcompare == $type && $addedresourceid[key($addedresource)] == $id) {
  1833. $show = 0;
  1834. }
  1835. next($addedresource);
  1836. }
  1837. if ($from_learnpath) {
  1838. $lang_add_it_or_resource = get_lang('AddIt');
  1839. } else {
  1840. $lang_add_it_or_resource = get_lang('AddResource');
  1841. }
  1842. if ($show !== 0) {
  1843. if ($type == 'Document') {
  1844. echo "<a href=".api_get_self(
  1845. )."?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>";
  1846. } else {
  1847. echo "<a href='".api_get_self(
  1848. )."?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>";
  1849. }
  1850. }
  1851. } else { // if it is not an array, it is a string
  1852. if ($_SESSION['addedresource'] !== $type || $_SESSION['addedresourceid'] !== $id) {
  1853. if ($from_learnpath) {
  1854. $lang_add_it_or_resource = get_lang('AddIt');
  1855. } else {
  1856. $lang_add_it_or_resource = get_lang('AddResource');
  1857. }
  1858. echo "<a href='".api_get_self(
  1859. )."?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>";
  1860. }
  1861. }
  1862. }
  1863. /**
  1864. * Gets the link to the given added resource.
  1865. *
  1866. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1867. * @author Yannick Warnier <ywarnier@beeznest.org>, Dokeos - rebranding
  1868. * @param string Course code
  1869. * @param string The tool type (using constants declared in api.lib.php)
  1870. * @param integer The resource ID
  1871. * @param string Resource style (e.g. when a resource is hidden => the added resources should also be styled like they are hidden)
  1872. * @param boolean Open in a new window (true) or in the current frame/window (false)?
  1873. * @todo use the constants for the type definitions.
  1874. */
  1875. function rl_get_html_resource_link($course_code, $type, $id, $style = '', $new_window = true)
  1876. {
  1877. $course_id = api_get_course_int_id();
  1878. // Styling the link of the added resource
  1879. if ($style != '') {
  1880. $styling = ' class="'.$style.'"';
  1881. }
  1882. if ($new_window) {
  1883. $target = ' target = "_blank" ';
  1884. } else {
  1885. $target = ' target = "_self" ';
  1886. }
  1887. $output = '';
  1888. switch ($type) {
  1889. case TOOL_CALENDAR_EVENT:
  1890. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  1891. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  1892. $myrow = Database::fetch_array($result);
  1893. $output = Display::return_icon('agenda.gif').' <a href="../calendar/agenda.php"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1894. break;
  1895. case TOOL_ANNOUNCEMENT:
  1896. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1897. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  1898. $myrow = Database::fetch_array($result);
  1899. $output = Display::return_icon('valves.gif').' <a href="../announcements/announcements.php"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1900. break;
  1901. case TOOL_LINK:
  1902. //doesn't take $target into account
  1903. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  1904. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  1905. $myrow = Database::fetch_array($result);
  1906. $output = Display::return_icon('links.gif').' <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 />";
  1907. break;
  1908. case TOOL_QUIZ:
  1909. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  1910. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $id");
  1911. $myrow = Database::fetch_array($result);
  1912. $output = Display::return_icon('quiz.gif').' <a href="../exercice/exercise_submit.php?exerciseId='.$myrow['id'].'"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />";
  1913. break;
  1914. case TOOL_FORUM:
  1915. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  1916. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  1917. $myrow = Database::fetch_array($result);
  1918. $output = Display::return_icon('forum.gif').' <a href="../phpbb/viewforum.php?forum='.$myrow['forum_id'].'&md5='.$myrow['md5'].'"'.$styling.' '.$target.'>'.$myrow['forum_name']."</a><br />";
  1919. break;
  1920. case TOOL_THREAD: //=topics
  1921. //$tbl_forum = Database::get_course_table(TABLE_FORUM);
  1922. //$tbl_thread = Database::get_course_table(TABLE_FORUM_THREAD);
  1923. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  1924. // grabbing the title of the post
  1925. $sql_title = "SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=".$id;
  1926. $result_title = Database::query($sql_title);
  1927. $myrow_title = Database::fetch_array($result_title);
  1928. $output = Display::return_icon('forum.gif').' <a href="../phpbb/viewtopic.php?topic='.$myrow_title['thread_id'].'&forum='.$myrow_title['forum_id'].'" '.$styling.' '.$target.'>'.$myrow_title['post_title']."</a><br />\n";
  1929. break;
  1930. case TOOL_POST:
  1931. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  1932. //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE);
  1933. $sql = "SELECT * FROM $tbl_post p WHERE c_id = $course_id AND p.post_id = $id";
  1934. $result = Database::query($sql);
  1935. $post = Database::fetch_array($result);
  1936. $output = Display::return_icon('forum.gif').' <a href="../phpbb/viewtopic.php?topic='.$post['thread_id'].'&forum='.$post['forum_id'].'"'.$styling.' '.$target.'>'.$post['post_title']."</a><br />";
  1937. break;
  1938. case TOOL_DOCUMENT:
  1939. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  1940. $result = Database::query("SELECT * FROM $tbl_doc WHERE c_id = $course_id AND id=$id");
  1941. $myrow = Database::fetch_array($result);
  1942. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  1943. $last = count($pathname) - 1; // Making a correct name for the link.
  1944. $filename = $pathname[$last]; // Making a correct name for the link.
  1945. $image = FileManager::choose_image($filename);
  1946. $ext = explode('.', $filename);
  1947. $ext = strtolower($ext[sizeof($ext) - 1]);
  1948. $myrow['path'] = rawurlencode($myrow['path']);
  1949. $in_frames = in_array($ext, array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png'));
  1950. $output = Display::return_icon($image).' <a href="../document/'.($in_frames ? 'showinframes.php?file=' : 'download.php?doc_url=').$myrow['path'].'"'.$styling.' '.$target.'>'.$filename."</a><br />";
  1951. break;
  1952. /*
  1953. case 'Externallink':
  1954. $output = '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.' '.$target.'>'.$id."</a><br />\n";
  1955. break;
  1956. */
  1957. }
  1958. return $output;
  1959. }
  1960. /**
  1961. * Returns an HTML-formatted link to a resource, to incorporate directly into
  1962. * the new learning path tool.
  1963. *
  1964. * The function is a big switch on tool type.
  1965. * In each case, we query the corresponding table for information and build the link
  1966. * with that information.
  1967. * @author Yannick Warnier <ywarnier@beeznest.org> - rebranding based on previous work (display_addedresource_link_in_learnpath())
  1968. * @param string Course code
  1969. * @param integer The learning path ID (in lp table)
  1970. * @param integer The database ID for that item in the lp_item table
  1971. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  1972. * @param id_in_path - the unique index in the items table
  1973. */
  1974. function rl_get_resource_link_for_learnpath($course_id, $learnpath_id, $id_in_path)
  1975. {
  1976. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1977. $course_info = api_get_course_info_by_id($course_id);
  1978. $course_id = $course_info['real_id'];
  1979. $course_code = $course_info['code'];
  1980. $session_id = api_get_session_id();
  1981. $learnpath_id = intval($learnpath_id);
  1982. $id_in_path = intval($id_in_path);
  1983. $sql_item = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = $learnpath_id AND id = $id_in_path";
  1984. $res_item = Database::query($sql_item);
  1985. if (Database::num_rows($res_item) < 1) {
  1986. return -1;
  1987. } //exit
  1988. $row_item = Database::fetch_array($res_item);
  1989. $type = strtolower($row_item['item_type']);
  1990. $id = (strcmp($row_item['path'], '') == 0) ? '0' : $row_item['path'];
  1991. $origin = 'learnpath';
  1992. $main_dir_path = api_get_path(WEB_CODE_PATH);
  1993. $main_course_path = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/';
  1994. $link = '';
  1995. switch ($type) {
  1996. case 'dokeos_chapter':
  1997. $link .= $main_dir_path.'newscorm/blank.php';
  1998. case TOOL_CALENDAR_EVENT:
  1999. $link .= $main_dir_path.'calendar/agenda.php?origin='.$origin.'&agenda_id='.$id;
  2000. break;
  2001. case TOOL_ANNOUNCEMENT:
  2002. $link .= $main_dir_path.'announcements/announcements.php?origin='.$origin.'&ann_id='.$id;
  2003. break;
  2004. case TOOL_LINK:
  2005. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  2006. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  2007. $myrow = Database::fetch_array($result);
  2008. $thelink = $myrow["url"];
  2009. $link .= $thelink;
  2010. break;
  2011. case TOOL_QUIZ:
  2012. if (!empty($id)) {
  2013. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  2014. $sql = "SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $id";
  2015. $result = Database::query($sql);
  2016. $myrow = Database::fetch_array($result);
  2017. if ($row_item['title'] != '') {
  2018. $myrow['title'] = $row_item['title'];
  2019. }
  2020. $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;
  2021. }
  2022. break;
  2023. case 'hotpotatoes': //lowercase because of strtolower above
  2024. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  2025. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND id=$id");
  2026. $myrow = Database::fetch_array($result);
  2027. $path = $myrow['path'];
  2028. $link .= $main_dir_path.'exercice/showinframes.php?file='.$path.''.
  2029. '&origin='.$origin.'&cid='.$course_code.'&uid='.api_get_user_id().''.
  2030. '&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path;
  2031. break;
  2032. case TOOL_FORUM:
  2033. $link .= $main_dir_path.'forum/viewforum.php?forum='.$id.'&lp=true&origin=learnpath';
  2034. break;
  2035. case TOOL_THREAD: //forum post
  2036. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD);
  2037. if (!empty($id)) {
  2038. $sql = "SELECT * FROM $tbl_topics WHERE c_id = $course_id AND thread_id=$id";
  2039. $result = Database::query($sql);
  2040. $myrow = Database::fetch_array($result);
  2041. $link .= $main_dir_path.'forum/viewthread.php?origin=learnpath&thread='.$id.''.
  2042. '&forum='.$myrow['forum_id'].'&lp=true';
  2043. }
  2044. break;
  2045. case TOOL_POST:
  2046. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  2047. $result = Database::query("SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=$id");
  2048. $myrow = Database::fetch_array($result);
  2049. $title = $myrow['post_title'];
  2050. //$desc = $row_item['description'];
  2051. $posternom = $myrow['poster_name'];
  2052. $posttime = $myrow['post_date'];
  2053. $posttext = $myrow['post_text'];
  2054. $posttitle = $title;
  2055. $posttext = str_replace('"', "'", $posttext);
  2056. $link .= $main_dir_path.'forum/viewthread.php?post='.$id.''.
  2057. '&thread='.$myrow['thread_id'].'&forum='.$myrow['forum_id'].''.
  2058. '&lp=true';
  2059. break;
  2060. case TOOL_DOCUMENT:
  2061. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  2062. $sql = "SELECT * FROM $tbl_doc WHERE c_id = $course_id AND id=$id";
  2063. $result = Database::query($sql);
  2064. $myrow = Database::fetch_array($result);
  2065. $docurl = str_replace('%2F', '/', urlencode($myrow['path']));
  2066. $link .= $main_course_path.'document'.$docurl.'?'.api_get_cidreq();
  2067. $openmethod = 2;
  2068. $officedoc = false;
  2069. Session::write('openmethod', $openmethod);
  2070. Session::write('officedoc', $officedoc);
  2071. break;
  2072. case 'assignments':
  2073. $link .= $main_dir_path.'work/work.php?origin='.$origin;
  2074. break;
  2075. case TOOL_DROPBOX:
  2076. $link .= $main_dir_path.'dropbox/index.php?origin=learnpath';
  2077. break;
  2078. case 'introduction_text': //DEPRECATED
  2079. $link .= '';
  2080. break;
  2081. case TOOL_COURSE_DESCRIPTION:
  2082. $link .= $main_dir_path.'course_description?origin=learnpath';
  2083. break;
  2084. case TOOL_GROUP:
  2085. $link .= $main_dir_path.'group/group.php?origin='.$origin;
  2086. break;
  2087. case TOOL_USER:
  2088. $link .= $main_dir_path.'user/user.php?origin='.$origin;
  2089. break;
  2090. case 'student_publication' :
  2091. $link .= $main_dir_path.'work/work.php?origin=learnpath';
  2092. break;
  2093. } //end switch
  2094. return $link;
  2095. }
  2096. /**
  2097. * Gets the name of a resource (generally used in learnpath when no name is provided)
  2098. *
  2099. * @author Yannick Warnier <ywarnier@beeznest.org>, Dokeos - rebranding
  2100. * @param string Course code
  2101. * @param string The tool type (using constants declared in api.lib.php)
  2102. * @param integer The resource ID
  2103. */
  2104. function rl_get_resource_name($course_code, $learnpath_id, $id_in_path)
  2105. {
  2106. $_course = api_get_course_info($course_code);
  2107. $course_id = $_course['real_id'];
  2108. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  2109. $sql_item = "SELECT item_type, title, ref FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = $learnpath_id AND id = $id_in_path";
  2110. $res_item = Database::query($sql_item);
  2111. if (Database::num_rows($res_item) < 1) {
  2112. return ''; //exit
  2113. }
  2114. $row_item = Database::fetch_array($res_item);
  2115. $type = strtolower($row_item['item_type']);
  2116. $id = $row_item['ref'];
  2117. $output = '';
  2118. switch ($type) {
  2119. case TOOL_CALENDAR_EVENT:
  2120. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  2121. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  2122. $myrow = Database::fetch_array($result);
  2123. $output = $myrow['title'];
  2124. break;
  2125. case TOOL_ANNOUNCEMENT:
  2126. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  2127. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  2128. $myrow = Database::fetch_array($result);
  2129. $output = $myrow['title'];
  2130. break;
  2131. case TOOL_LINK:
  2132. // Doesn't take $target into account.
  2133. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  2134. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  2135. $myrow = Database::fetch_array($result);
  2136. $output = $myrow['title'];
  2137. break;
  2138. case TOOL_QUIZ:
  2139. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  2140. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $id");
  2141. $myrow = Database::fetch_array($result);
  2142. $output = $myrow['title'];
  2143. break;
  2144. case TOOL_FORUM:
  2145. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  2146. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  2147. $myrow = Database::fetch_array($result);
  2148. $output = $myrow['forum_name'];
  2149. break;
  2150. case TOOL_THREAD: //=topics
  2151. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  2152. // Grabbing the title of the post.
  2153. $sql_title = "SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=".$id;
  2154. $result_title = Database::query($sql_title);
  2155. $myrow_title = Database::fetch_array($result_title);
  2156. $output = $myrow_title['post_title'];
  2157. break;
  2158. case TOOL_POST:
  2159. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  2160. //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE);
  2161. $sql = "SELECT * FROM $tbl_post p WHERE c_id = $course_id AND p.post_id = $id";
  2162. $result = Database::query($sql);
  2163. $post = Database::fetch_array($result);
  2164. $output = $post['post_title'];
  2165. break;
  2166. case 'dokeos_chapter':
  2167. $title = $row_item['title'];
  2168. if (!empty($title)) {
  2169. $output = $title;
  2170. } else {
  2171. $output = '-';
  2172. }
  2173. break;
  2174. case TOOL_DOCUMENT:
  2175. $title = $row_item['title'];
  2176. if (!empty($title)) {
  2177. $output = $title;
  2178. } else {
  2179. $output = '-';
  2180. }
  2181. break;
  2182. case 'hotpotatoes':
  2183. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  2184. $result = Database::query("SELECT * FROM $tbl_doc WHERE c_id = $course_id AND id=$id");
  2185. $myrow = Database::fetch_array($result);
  2186. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  2187. $last = count($pathname) - 1; // Making a correct name for the link.
  2188. $filename = $pathname[$last]; // Making a correct name for the link.
  2189. $image = FileManager::choose_image($filename);
  2190. $ext = explode('.', $filename);
  2191. $ext = strtolower($ext[sizeof($ext) - 1]);
  2192. $myrow['path'] = rawurlencode($myrow['path']);
  2193. $in_frames = in_array($ext, array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png'));
  2194. $output = $filename;
  2195. break;
  2196. /*
  2197. case 'externallink':
  2198. $output = '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.' '.$target.'>'.$id."</a><br />\n";
  2199. break;
  2200. */
  2201. }
  2202. return stripslashes($output);
  2203. }