resourcelinker.inc.php 89 KB

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