resourcelinker.inc.php 109 KB

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