resourcelinker.inc.php 99 KB

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