resourcelinker.inc.php 109 KB

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