resourcelinker.inc.php 99 KB

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