resourcelinker.inc.php 99 KB

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