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. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  16. use \ChamiloSession as Session;
  17. $use_anonymous = true;
  18. require_once '../inc/global.inc.php';
  19. if (!empty($_course['language'])){
  20. $resource_linker_file = api_get_path(SYS_CODE_PATH).'lang/'.$_course['language'].'/resourcelinker.inc.php';
  21. if (file_exists($resource_linker_file)) {
  22. require_once $resource_linker_file;
  23. }
  24. }
  25. require_once '../exercice/hotpotatoes.lib.php';
  26. /* FUNCTIONS */
  27. function unset_session_resources() {
  28. $_SESSION['addedresource'] = '';
  29. $_SESSION['addedresourceid'] = '';
  30. Session::erase(addedresource);
  31. Session::erase(addedresourceid);
  32. }
  33. /**
  34. * Insert description here.
  35. */
  36. function show_folder_up() {
  37. global $folder;
  38. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  39. $level = get_levels($folder);
  40. if ($level == 1) {
  41. echo "<a href='".api_get_self()."?content=Document&amp;source_forum=".$_GET['source_forum']."&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'><img src='../img/folder_up.gif' border='0' />".get_lang('LevelUp')."</a>";
  42. }
  43. if ($level && $level != 0 && $level != 1) {
  44. $folder_up=$folder;
  45. $folder_temp=explode('/',$folder);
  46. $last=count($folder_temp)-1;
  47. unset($folder_temp[$last]);
  48. $folder_up=implode('/',$folder_temp);
  49. echo "<a href='".api_get_self()."?content=Document&amp;source_forum=".$_GET['source_forum']."&amp;folder=$folder_up&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'><img src='../img/folder_up.gif' border='0' />".get_lang('LevelUp')."</a>";
  50. }
  51. }
  52. /**
  53. * Shows the documents of the document tool
  54. * @param $folder
  55. */
  56. function show_documents($folder) {
  57. global $_course;
  58. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  59. // Documents are a special case: The teacher can add an invisible document (it will be viewable by the user)
  60. // other tools do not have this feature.
  61. if (api_is_allowed_to_edit()) {
  62. $visibility = "ip.visibility<>'2'";
  63. } else {
  64. $visibility = "ip.visibility='1'";
  65. }
  66. $course_id = api_get_course_int_id();
  67. $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  68. $document_table = Database::get_course_table(TABLE_DOCUMENT);
  69. $sql = "SELECT * from $document_table docs , $item_property_table ip
  70. WHERE docs.c_id = $course_id AND
  71. ip.c_id = $course_id AND
  72. 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";
  73. $result = Database::query($sql);
  74. while ($row = Database::fetch_array($result)) {
  75. if (!$folder) {
  76. if (get_levels($row['path'])-1 == 1) {
  77. // showing the right icon.
  78. if (file_or_folder($row['path'])) {
  79. echo '<img src="../img/file.gif" align="middle" />';
  80. } else {
  81. $image = choose_image($row['path']);
  82. echo "<img src=\"../img/$image\" align=\"middle\" />";
  83. }
  84. // Folders should be clickable.
  85. if (file_or_folder($row['path'])) {
  86. echo "<a href='".api_get_self()."?content=Document";
  87. 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 />';
  88. } else {
  89. echo substr($row['path'], 1).' ';
  90. echo showorhide_addresourcelink('Document',$row['id']);
  91. echo '<br />';
  92. }
  93. }
  94. } else {
  95. // We calculate the level we are in by using the $folder in the url.
  96. // We put +1 because it does not start with an / and in the database it does
  97. $level = get_levels($folder) + 1;
  98. // We calculate each level of the database entry.
  99. $file_level=get_levels($row['path'])-1;
  100. // If the level of the database entry is equal to the level we ar in, we put it into an array
  101. // as this is a potential good entry.
  102. if ($file_level == $level) {
  103. $good_paths[] = $row['path'];
  104. $good_ids[] = $row['id'];
  105. }
  106. //$haystack=$row['path'];
  107. //$conform_folder=strstr($haystack, $folder);
  108. //if (str_replace($folder.'/', '', $conform_folder) !== $folder) {
  109. // $good_folders[] = $row['path'];
  110. //echo str_replace($folder.'/', '', $conform_folder);
  111. // echo '<br />';
  112. // }// if (str_replace($folder.'/','',$conform_folder)!==$folder)
  113. } // else (if (!$folder))
  114. } //while ($row=Database::fetch_array($result))
  115. // This is code for the case that we are in a subfolder.
  116. if ($good_paths) {
  117. // We have all the potential good database entries, the good ones are those that start with $folder
  118. foreach ($good_paths as $path) {
  119. if (strstr($path, $folder)) {
  120. $good_key = key($good_paths);
  121. // Showing the right icon.
  122. if (file_or_folder($path)) {
  123. echo '<img src="../img/file.gif" align="middle" />';
  124. } else {
  125. $image = choose_image($path);
  126. echo "<img src=\"../img/$image\" align=\"middle\" />";
  127. }
  128. // Folders should be clickable
  129. if (file_or_folder($path)) {
  130. $path = substr($path, 1); // Remove the first / in folder_up.
  131. $uri = str_replace($folder, $path, $_SERVER['REQUEST_URI']);
  132. $newuri = str_replace('add=', 'addnot=', $uri);
  133. // Using the correct name of the folder.
  134. $folder_name = str_replace($folder.'/', '', $path);
  135. echo "<a href='$newuri'>".$folder_name.'</a><br />';
  136. } else {
  137. echo str_replace("/$folder/", '', $path).' ';
  138. echo showorhide_addresourcelink('Document', $good_ids[$good_key]);
  139. echo '<br />';
  140. }
  141. }
  142. next($good_paths);
  143. }
  144. }
  145. }
  146. /**
  147. * Checks wether something is a file or a folder
  148. * 0 means file, 1 means folder
  149. * @param $filefolder
  150. * @todo use true and false instead of 1 and 0.
  151. */
  152. function file_or_folder($filefolder) {
  153. global $_course;
  154. global $baseServDir;
  155. $courseDir = $_course['path'].'/document';
  156. $baseWorkDir = api_get_path(SYS_COURSE_PATH).$courseDir;
  157. return (is_dir($baseWorkDir.$filefolder) ? 1 : 0);
  158. }
  159. /**
  160. * Inserts a resource into the database
  161. *
  162. * @param $source_type
  163. * @param $source_id
  164. */
  165. function store_resources($source_type, $source_id) {
  166. global $_course;
  167. $resource_table = Database::get_course_table(TABLE_LINKED_RESOURCES);
  168. $course_id = api_get_course_int_id();
  169. $addedresource = $_SESSION['addedresource'];
  170. $addedresourceid = $_SESSION['addedresourceid'];
  171. if ($_SESSION['addedresource']) {
  172. foreach ($addedresource as $resource_type) {
  173. $sql="INSERT INTO $resource_table (c_id, source_type, source_id, resource_type, resource_id) VALUES
  174. ($course_id, '$source_type', '$source_id', '$resource_type', '".$addedresourceid[key($addedresource)]."')";
  175. Database::query($sql);
  176. $i=key($addedresource);
  177. next($addedresource);
  178. }
  179. $_SESSION['addedresource']='';
  180. $_SESSION['addedresourceid']='';
  181. }
  182. }
  183. /**
  184. * DEPRECATED - use rl_get_resource_link() instead - DEPRECATED
  185. * Displays the link that opens a new browser window that views the added resource.
  186. *
  187. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  188. * @param $type the type of the tool
  189. * @param $id the id of the resource
  190. * @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)
  191. * @todo use the constants for the type definitions.
  192. */
  193. function display_addedresource_link($type, $id, $style = '') {
  194. global $_course;
  195. $course_id = api_get_course_int_id();
  196. // Styling the link of the added resource.
  197. if ($style != '') {
  198. $styling = ' class="'.$style.'"';
  199. }
  200. switch ($type) {
  201. case 'Agenda':
  202. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  203. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  204. $myrow = Database::fetch_array($result);
  205. echo '<img src="../img/agenda.gif" align="middle" /> <a href="../calendar/agenda.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
  206. break;
  207. case 'Ad_Valvas':
  208. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  209. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  210. $myrow = Database::fetch_array($result);
  211. echo '<img src="../img/valves.gif" align="middle" /> <a href="../announcements/announcements.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
  212. break;
  213. case 'Link':
  214. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  215. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  216. $myrow = Database::fetch_array($result);
  217. 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";
  218. break;
  219. case 'Exercise':
  220. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  221. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND id=$id");
  222. $myrow = Database::fetch_array($result);
  223. echo '<img src="../img/quiz.gif" align="middle" /> <a href="../exercice/exercise_submit.php?exerciseId='.$myrow['id'].'"'.$styling.'>'.$myrow['title']."</a><br />\n";
  224. break;
  225. case 'Forum':
  226. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  227. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  228. $myrow = Database::fetch_array($result);
  229. 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";
  230. break;
  231. case 'Thread': //=topics
  232. //@deprecated bb_posts, bb_posts_text, bb_forums
  233. /*
  234. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  235. $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text';
  236. $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums';
  237. $result = Database::query("SELECT * FROM $tbl_posts posts, $TBL_FORUMS forum WHERE forum.forum_id=posts.forum_id and post_id=$id");
  238. $myrow = Database::fetch_array($result);
  239. // grabbing the title of the post
  240. $sql_title = "SELECT * FROM $tbl_posts_text WHERE c_id = $course_id AND post_id=".$myrow["post_id"];
  241. $result_title = Database::query($sql_title);
  242. $myrow_title = Database::fetch_array($result_title);
  243. 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";
  244. */
  245. break;
  246. case 'Post':
  247. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  248. $sql = "SELECT * FROM $tbl_post p WHERE c_id = $course_id AND post_id = $id";
  249. $result = Database::query($sql);
  250. $post = Database::fetch_object($result);
  251. 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";
  252. break;
  253. case 'Document':
  254. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  255. $result = Database::query("SELECT * FROM $dbTable WHERE c_id = $course_id AND id=$id");
  256. $myrow = Database::fetch_array($result);
  257. $pathname = explode('/',$myrow['path']); // Making a correct name for the link.
  258. $last = count($pathname) - 1; // Making a correct name for the link.
  259. $filename = $pathname[$last]; // Making a correct name for the link.
  260. $image = choose_image($filename);
  261. $ext = explode('.', $filename);
  262. $ext = strtolower($ext[sizeof($ext)-1]);
  263. $myrow['path'] = rawurlencode($myrow['path']);
  264. $array_ext=array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png');
  265. if (api_browser_support('svg')){
  266. $array_ext[]='svg';
  267. }
  268. if (api_browser_support('ogg')){
  269. $array_ext[]='ogg';
  270. }
  271. $in_frames = in_array($ext, $array_ext);
  272. 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";
  273. break;
  274. case 'Externallink':
  275. echo '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.'>'.$id."</a><br />\n";
  276. break;
  277. }
  278. }
  279. /**
  280. * This function is to display the added resources (lessons) in the learning path player and builder
  281. * this function is a modification of display_addedresource_link($type, $id) function
  282. * the two ids are a bit confusing, I admit, but I did not want to change Patrick's work, I was
  283. * building upon it. - Denes
  284. *
  285. * Parameters:
  286. * @param completed - if ="completed" then green presentation with checkbox
  287. * @param id_in_path - if onclick then this lesson will be considered completed, that is the unique index in the items table
  288. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  289. * @param type - that is the correspondent type in the mirror tool (like this is a Link item)
  290. * @param builder - if ="builder" then onclick shows in new window
  291. * @param icon - if ="icon" then the small icon will appear
  292. * if ="wrap" then wrapped settings are used (and no icon is displayed)
  293. * 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)
  294. * @todo this function is too long, rewrite
  295. */
  296. function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_path, $builder, $icon, $level = 0) {
  297. global $_course, $learnpath_id, $tbl_learnpath_item, $items;
  298. global $curDirPath, $_configuration, $enableDocumentParsing, $_course, $_user, $_cid;
  299. $course_id = api_get_course_int_id();
  300. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  301. $hyperlink_target_parameter = ''; //or e.g. 'target="_blank"'
  302. $length = ((($builder == 'builder') && ($icon == 'nolink')) ? 65 : 32);
  303. if ($builder != 'builder') $origin = 'learnpath'; //origin = learnpath in student view
  304. $linktype = $type;
  305. if (($type == 'Link _self') or ($type == 'Link _blank')) $type = 'Link';
  306. // YW switched litteral tool names to use of constants declared in main_api.lib.php
  307. switch ($type) {
  308. case TOOL_CALENDAR_EVENT:
  309. case 'Agenda':
  310. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  311. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  312. $myrow = Database::fetch_array($result);
  313. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  314. $result = Database::query($sql); $row = Database::fetch_array($result);
  315. if ($row['title'] != '') { $myrow['title'] = $row['title']; }
  316. $desc = $row['description'];
  317. $agenda_id = $row['item_id'];
  318. echo str_repeat("&nbsp;&gt;", $level);
  319. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  320. if ($icon != 'nolink') {
  321. if ($completed == 'completed') {
  322. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  323. } else {
  324. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  325. //echo "&nbsp;";
  326. }
  327. }
  328. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  329. if ($myrow['title'] == '') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  330. if ($icon == 'nolink') { return(shorten($myrow['title'], $length)); }
  331. if ($icon == 'icon') { echo "<img src='../img/agenda.gif' align=\"absmiddle\" alt='agenda'>"; }
  332. if ($builder != 'builder') {
  333. 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>";
  334. $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";
  335. if ($desc != '') {
  336. if ($icon != 'wrap') {
  337. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>";
  338. } else {
  339. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>";
  340. }
  341. }
  342. } else {
  343. echo "<a href=\"../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id\" class='$completed' target='_blank'>".shorten($myrow['title'], ($length-3*$level))."</a>";
  344. }
  345. break;
  346. case TOOL_ANNOUNCEMENT:
  347. case 'Ad_Valvas':
  348. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  349. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  350. $myrow = Database::fetch_array($result);
  351. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  352. $result = Database::query($sql);
  353. $row = Database::fetch_array($result);
  354. if ($row['title'] != '') {
  355. $myrow['content'] = $row['title'];
  356. }
  357. $desc = $row['description'];
  358. $ann_id = $row['item_id'];
  359. echo str_repeat("&nbsp;&gt;", $level);
  360. // The title and the text are in the content field and we only want to display the title.
  361. list($title, $text) = explode('<br>', $myrow['content']);
  362. if ($title == '') { $title = $myrow['content']; }
  363. $title = $myrow['title'];
  364. $text = $myrow['content'];
  365. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  366. if ($icon != 'nolink') {
  367. if ($completed == 'completed') {
  368. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  369. } else {
  370. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  371. //echo "&nbsp;";
  372. }
  373. }
  374. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  375. if ($title == '') {
  376. $type = 'Announcement';
  377. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  378. return(true);
  379. }
  380. if ($icon == 'nolink') { return(shorten($title,$length)); }
  381. if ($icon == 'icon') { echo "<img src='../img/valves.gif' align=\"absmiddle\" alt='ad valvas'>"; }
  382. if ($builder != 'builder') {
  383. 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>";
  384. $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";
  385. if ($desc != '') {
  386. if ($icon != 'wrap') {
  387. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>";
  388. } else {
  389. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>";
  390. }
  391. }
  392. } else {
  393. echo "<a href=\"../announcements/announcements.php?origin=$origin&ann_id=$ann_id\" class='$completed' target='_blank'>".shorten($title, ($length-3*$level))."</a>";
  394. }
  395. break;
  396. case TOOL_LINK:
  397. case 'Link':
  398. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  399. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  400. $myrow = Database::fetch_array($result);
  401. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  402. $result = Database::query($sql);
  403. $row = Database::fetch_array($result);
  404. if ($row['title'] != '') { $myrow['title'] = $row['title']; }
  405. $desc=$row['description'];
  406. echo str_repeat("&nbsp;&gt;", $level);
  407. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  408. if ($icon != 'nolink') {
  409. if ($completed == 'completed') {
  410. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  411. } else {
  412. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  413. //echo "&nbsp;";
  414. }
  415. }
  416. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  417. if ($myrow['title'] == '') {
  418. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  419. return(true);
  420. }
  421. if ($icon == 'nolink') { return(shorten($myrow['title'], $length)); }
  422. if ($icon == 'icon') {
  423. if ($linktype == 'Link _self') { echo "<img src='../img/links.gif' align=\"absmiddle\" alt='links'>"; }
  424. else { echo "<img src='../img/link_blank.gif' align=\"absmiddle\" alt='blank links'>"; }
  425. }
  426. $thelink = $myrow['url'];
  427. if ($builder != 'builder') {
  428. 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>";
  429. $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";
  430. if ($desc != '') {
  431. if ($icon != 'wrap') {
  432. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>";
  433. } else {
  434. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>";
  435. }
  436. }
  437. } else {
  438. echo "<a href=\"$thelink\" class='$completed' target='_blank'>".shorten($myrow['title'], ($length-3*$level))."</a>";
  439. }
  440. break;
  441. case TOOL_QUIZ:
  442. case 'Exercise':
  443. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  444. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND id=$id");
  445. $myrow = Database::fetch_array($result);
  446. if ($builder == 'builder') { $origin = 'builder'; }
  447. // This is needed for the exercise_submit.php can delete the session info about tests.
  448. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  449. $result = Database::query($sql);
  450. $row = Database::fetch_array($result);
  451. if ($row['title'] != '') { $myrow['title'] = $row['title']; }
  452. $desc = $row['description'];
  453. echo str_repeat("&nbsp;&gt;", $level);
  454. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  455. if ($icon != 'nolink') {
  456. if ($completed == 'completed') {
  457. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  458. } else {
  459. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  460. //echo "&nbsp;";
  461. }
  462. }
  463. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  464. if ($myrow['title'] == '') {
  465. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  466. return(true);
  467. }
  468. if ($icon == 'nolink') { return(shorten($myrow['title'], $length)); }
  469. if ($icon == 'icon') { echo "<img src='../img/quiz.gif' align=\"absmiddle\" alt='quizz'>"; }
  470. if ($builder != 'builder') {
  471. 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>";
  472. $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";
  473. if ($desc != '') {
  474. if ($icon != 'wrap') {
  475. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>";
  476. } else {
  477. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>";
  478. }
  479. }
  480. } else {
  481. echo "<a href=\"../exercice/exercise_submit.php?origin=$origin&exerciseId=".$myrow['id']."\" class='$completed' target='_blank'>".shorten($myrow['title'], ($length-3*$level))."</a>";
  482. }
  483. break;
  484. case 'hotpotatoes':
  485. case 'HotPotatoes':
  486. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  487. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  488. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND id=$id");
  489. $myrow = Database::fetch_array($result);
  490. $path = $myrow['path'];
  491. $name = GetQuizName($path, $documentPath);
  492. if ($builder == 'builder') { $origin='builder'; }
  493. // This is needed for the exercise_submit.php can delete the session info about tests.
  494. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  495. $result = Database::query($sql); $row = Database::fetch_array($result);
  496. if ($row['title'] != '') { $name=$row['title']; }
  497. $desc = $row['description'];
  498. echo str_repeat("&nbsp;&gt;", $level);
  499. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  500. if ($icon != 'nolink') {
  501. if ($completed == 'completed') {
  502. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  503. } else {
  504. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  505. //echo "&nbsp;";
  506. }
  507. }
  508. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  509. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  510. if ($icon == 'nolink') { return(shorten($name,$length)); }
  511. if ($icon == 'icon') { echo "<img src='../img/jqz.jpg' align=\"absmiddle\" alt='hot potatoes'>"; }
  512. $cid = $_course['official_code'];
  513. if ($builder != 'builder') {
  514. 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>";
  515. $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";
  516. if ($desc != '') {
  517. if ($icon != 'wrap') {
  518. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>";
  519. } else {
  520. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>";
  521. }
  522. }
  523. } else {
  524. 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>";
  525. }
  526. break;
  527. case TOOL_FORUM:
  528. case 'Forum':
  529. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  530. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  531. $myrow = Database::fetch_array($result);
  532. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  533. $result = Database::query($sql); $row = Database::fetch_array($result);
  534. if ($row['title'] != '') { $myrow["forum_name"] = $row['title']; }
  535. $desc = $row['description'];
  536. echo str_repeat("&nbsp;&gt;", $level);
  537. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  538. if ($icon != 'nolink') {
  539. if ($completed == 'completed') {
  540. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  541. } else {
  542. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  543. //echo "&nbsp;";
  544. }
  545. }
  546. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  547. if ($myrow["forum_name"]=='') { $type="Forum"; echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  548. if ($icon == 'nolink') { return(shorten($myrow['forum_name'], $length)); }
  549. if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
  550. $forumparameters = "forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  551. if ($builder != 'builder') {
  552. 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>";
  553. $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";
  554. if ($desc != '') {
  555. if ($icon != 'wrap') {
  556. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  557. } else {
  558. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  559. }
  560. }
  561. } else {
  562. echo "<a href=\"../phpbb/viewforum.php?$forumparameters\" class='$completed' target='_blank'>".shorten($myrow["forum_name"],($length-3*$level))."</a>";
  563. }
  564. break;
  565. case TOOL_THREAD:
  566. case 'Thread': //forum post
  567. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD);
  568. $sql = "SELECT * FROM $tbl_topics where c_id = $course_id AND topic_id=$id";
  569. $result = Database::query($sql);
  570. $myrow = Database::fetch_array($result);
  571. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  572. $result = Database::query($sql); $row = Database::fetch_array($result);
  573. if ($row['title'] != '') { $myrow['topic_title'] = $row['title']; }
  574. $desc = $row['description'];
  575. echo str_repeat("&nbsp;&gt;", $level);
  576. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  577. if ($icon != 'nolink') {
  578. if ($completed == 'completed') {
  579. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  580. } else {
  581. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  582. //echo "&nbsp;";
  583. }
  584. }
  585. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  586. if ($myrow["topic_title"] == '') { $type = "Forum Post"; echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  587. if ($icon == 'nolink') { return(shorten($myrow['topic_title'], $length)); }
  588. if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
  589. if ($builder != 'builder') {
  590. 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>";
  591. $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";
  592. if ($desc != '') {
  593. if ($icon != 'wrap') {
  594. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  595. } else {
  596. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  597. }
  598. }
  599. } else {
  600. 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>";
  601. }
  602. break;
  603. case TOOL_POST:
  604. case 'Post':
  605. //deprecated
  606. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST);
  607. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  608. $result = Database::query("SELECT * FROM $tbl_posts where c_id = $course_id AND post_id=$id");
  609. $myrow = Database::fetch_array($result);
  610. // Grabbing the title of the post.
  611. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  612. $result = Database::query($sql);
  613. $row=Database::fetch_array($result);
  614. if ($row['title'] != '') { $myrow['post_title'] = $row['title']; }
  615. $desc = $row['description'];
  616. echo str_repeat("&nbsp;&gt;", $level);
  617. $posternom = $myrow['nom']; $posterprenom = $myrow['prenom'];
  618. $posttime = $myrow['post_time']; $posttext = $myrow['post_text'];
  619. $posttitle = $myrow['post_title'];
  620. $posttext = str_replace('"', "'", $posttext);
  621. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  622. if ($icon != 'nolink') {
  623. if ($completed == 'completed') {
  624. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  625. } else {
  626. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  627. //echo "&nbsp;";
  628. }
  629. }
  630. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  631. if ($myrow["post_title"] == '') {
  632. $type = 'Forum';
  633. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true);
  634. }
  635. if ($icon == 'nolink') { return(shorten($myrow["post_title"],$length)); }
  636. if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
  637. if ($builder != 'builder') {
  638. 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";
  639. if ($desc != '') {
  640. if ($icon != 'wrap') {
  641. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  642. } else {
  643. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  644. }
  645. }
  646. } else {
  647. 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>";
  648. }
  649. break;
  650. case TOOL_DOCUMENT:
  651. case 'Document':
  652. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  653. $my_sql = "SELECT * FROM $dbTable WHERE c_id = $course_id AND id=$id";
  654. //error_log('New LP - Querying document table: '.$my_sql,0);
  655. $result = Database::query($my_sql);
  656. $myrow = Database::fetch_array($result);
  657. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  658. $last = count($pathname) - 1; // Making a correct name for the link.
  659. $filename=$pathname[$last]; // Making a correct name for the link.
  660. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  661. echo str_repeat("&nbsp;&gt;", $level);
  662. if ($icon != 'nolink') {
  663. if ($completed=='completed') {
  664. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  665. } else {
  666. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  667. //echo "&nbsp;";
  668. }
  669. }
  670. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  671. $image = choose_image($filename);
  672. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  673. //error_log('New LP - Querying lp_item table: '.$sql, 0);
  674. $result = Database::query($sql); $row = Database::fetch_array($result);
  675. if ($row['title'] != '') { $filename = $row['title']; }
  676. $desc=$row['description'];
  677. if (($myrow['path'] == '') && ($filename == '')) {
  678. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  679. return(true);
  680. }
  681. if ($icon == 'nolink') { return(shorten($filename, $length)); }
  682. if ($icon == 'icon') { echo "<img src='../img/$image' align=\"absmiddle\" alt='$image'>"; }
  683. if ($builder != 'builder')
  684. {
  685. 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>";
  686. if ($desc != '') {
  687. if ($icon != 'wrap') {
  688. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  689. } else {
  690. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  691. }
  692. } $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";
  693. } else {
  694. $enableDocumentParsing=yes;
  695. if (!$enableDocumentParsing) {
  696. // This is the solution for the non-parsing version in the builder.
  697. $file = urlencode($myrow['path']);
  698. echo "<a href='../document/showinframes.php?file=$file' class='$completed' $hyperlink_target_parameter>".shorten($filename,($length-3*$level))."</a>";
  699. } else {
  700. echo "<a href=\"../document/download.php?doc_url=".$myrow['path']."\" class='$completed' $hyperlink_target_parameter>".shorten($filename,($length-3*$level))."</a>";
  701. }
  702. }
  703. break;
  704. case 'assignments':
  705. case 'Assignments':
  706. $name = get_lang('Assignments');
  707. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  708. $result = Database::query($sql);
  709. $row = Database::fetch_array($result);
  710. if ($row['title'] != '') { $name=$row['title']; }
  711. $desc = $row['description'];
  712. echo str_repeat("&nbsp;&gt;", $level);
  713. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  714. if ($icon != 'nolink') {
  715. if ($completed == 'completed') {
  716. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  717. } else {
  718. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  719. //echo "&nbsp;";
  720. }
  721. }
  722. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  723. if ($name=='') {
  724. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true);
  725. }
  726. if ($icon == 'nolink') { return(shorten($name, $length)); }
  727. if ($icon == 'icon') { echo "<img src='../img/works.gif' align=\"absmiddle\">"; }
  728. if ($builder != 'builder') {
  729. 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";
  730. if ($desc != '') {
  731. if ($icon != 'wrap') {
  732. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>";
  733. } else {
  734. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>";
  735. }
  736. }
  737. } else {
  738. echo "<a href=\"../work/work.php\" class='$completed' target='_blank'>".shorten($name, ($length-3*$level))."</a>";
  739. }
  740. break;
  741. case TOOL_DROPBOX:
  742. case 'Dropbox':
  743. $name = get_lang('Dropbox');
  744. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  745. $result = Database::query($sql);
  746. $row = Database::fetch_array($result);
  747. if ($row['title'] != '') { $name = $row['title']; }
  748. $desc = $row['description'];
  749. echo str_repeat("&nbsp;&gt;", $level);
  750. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  751. if ($icon != 'nolink') {
  752. if ($completed == 'completed') {
  753. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  754. } else {
  755. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  756. //echo "&nbsp;";
  757. }
  758. }
  759. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  760. if ($name == '') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  761. if ($icon == 'nolink') { return(shorten($name, $length)); }
  762. if ($icon == 'icon') { echo "<img src='../img/dropbox.gif' align=\"absmiddle\">"; }
  763. if ($builder != 'builder') {
  764. 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";
  765. if ($desc != '') {
  766. if ($icon != 'wrap') {
  767. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>"; }
  768. else {
  769. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>"; }
  770. }
  771. } else {
  772. echo "<a href=\"../dropbox/index.php\" class='$completed' target='_blank'>".shorten($name, ($length-3*$level))."</a>";
  773. }
  774. break;
  775. case 'introduction_text':
  776. case 'Introduction_text':
  777. $name = get_lang('IntroductionText');
  778. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  779. $result = Database::query($sql); $row = Database::fetch_array($result);
  780. if ($row['title'] != '') { $name = $row['title']; }
  781. $desc = $row['description'];
  782. echo str_repeat("&nbsp;&gt;", $level);
  783. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  784. if ($icon != 'nolink') {
  785. if ($completed == 'completed') {
  786. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  787. } else {
  788. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  789. //echo "&nbsp;";
  790. }
  791. }
  792. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  793. if ($name == '') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  794. if ($icon == 'nolink') { return(shorten($name, $length)); }
  795. if ($icon == 'icon') { echo "<img src='../img/introduction.gif' align=\"absmiddle\" alt='introduction'>"; }
  796. if ($builder != 'builder') {
  797. 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>";
  798. $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";
  799. if ($desc != '') {
  800. if ($icon != 'wrap') {
  801. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>"; }
  802. else {
  803. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>"; }
  804. }
  805. } else {
  806. $s = api_get_path(WEB_COURSE_PATH)."$_cid/index.php?intro_cmdEdit=1";
  807. echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name, ($length-3*$level))."</a>";
  808. }
  809. break;
  810. case TOOL_COURSE_DESCRIPTION:
  811. case 'Course_description':
  812. $name = get_lang('CourseDescription');
  813. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  814. $result = Database::query($sql); $row = Database::fetch_array($result);
  815. if ($row['title'] != '') { $name = $row['title']; }
  816. $desc = $row['description'];
  817. echo str_repeat("&nbsp;&gt;", $level);
  818. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  819. if ($icon != 'nolink') {
  820. if ($completed == 'completed') {
  821. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  822. } else {
  823. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  824. //echo "&nbsp;";
  825. }
  826. }
  827. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  828. if ($name == '') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  829. if ($icon == 'nolink') { return(shorten($name,$length)); }
  830. if ($icon == 'icon') { echo "<img src='../img/info.gif' align=\"absmiddle\" alt='info'>"; }
  831. if ($builder != 'builder') {
  832. 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";
  833. if ($desc != '') {
  834. if ($icon != 'wrap') {
  835. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>"; }
  836. else {
  837. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>"; }
  838. }
  839. } else {
  840. $s=api_get_path(WEB_CODE_PATH)."course_description";
  841. echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name, ($length-3*$level))."</a>";
  842. }
  843. break;
  844. case TOOL_GROUP:
  845. case 'Groups':
  846. $name = get_lang('Groups');
  847. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  848. $result = Database::query($sql);
  849. $row = Database::fetch_array($result);
  850. if ($row['title'] != '') { $name=$row['title']; }
  851. $desc = $row['description'];
  852. echo str_repeat("&nbsp;&gt;", $level);
  853. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  854. if ($icon != 'nolink') {
  855. if ($completed == 'completed') {
  856. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  857. } else {
  858. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  859. //echo "&nbsp;";
  860. }
  861. }
  862. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  863. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  864. if ($icon == 'nolink') { return(shorten($name, $length)); }
  865. if ($icon == 'icon') { echo "<img src='../img/group.gif' align=\"absmiddle\" alt='group'>"; }
  866. if ($builder != 'builder') {
  867. 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";
  868. if ($desc != '') {
  869. if ($icon != 'wrap') {
  870. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>"; }
  871. else {
  872. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>"; }
  873. }
  874. } else {
  875. echo "<a href=\"../group/group.php?origin=$origin\" class='$completed' target='_blank'>".shorten($name, ($length-3*$level))."</a>";
  876. }
  877. break;
  878. case TOOL_USER:
  879. case 'Users':
  880. $name = get_lang('Users');
  881. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  882. $result = Database::query($sql);
  883. $row = Database::fetch_array($result);
  884. if ($row['title'] != '') { $name = $row['title']; }
  885. $desc = $row['description'];
  886. echo str_repeat("&nbsp;&gt;", $level);
  887. if (($builder != 'builder') && ($icon != 'wrap')) { echo "<td>"; }
  888. if ($icon != 'nolink') {
  889. if ($completed == 'completed') {
  890. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  891. } else {
  892. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  893. //echo "&nbsp;";
  894. }
  895. }
  896. if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
  897. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  898. if ($icon == 'nolink') { return(shorten($name,$length)); }
  899. if ($icon == 'icon') { echo "<img src='../img/members.gif' align=\"absmiddle\" alt='members'>"; }
  900. if ($builder != 'builder') {
  901. 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";
  902. if ($desc != '') {
  903. if ($icon != 'wrap') {
  904. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div></td></tr>"; }
  905. else {
  906. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc, ($length-3*$level))."</div>"; }
  907. }
  908. } else {
  909. echo "<a href=\"../user/user.php?origin=$origin\" class='$completed' target='_blank'>".shorten($name, ($length-3*$level))."</a>";
  910. }
  911. break;
  912. }//end huge switch-statement
  913. }
  914. /**
  915. * This function is to create and return a link to the added resources (lessons).
  916. * It returns the same thing as display_addedresource_link_in_learnpath() but doesn't display
  917. * anything.
  918. *
  919. * Parameters:
  920. * @param type - that is the correspondent type in the mirror tool (like this is a Link item)
  921. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  922. * @param id_in_path - the unique index in the items table
  923. */
  924. function get_addedresource_link_in_learnpath($type, $id, $id_in_path) {
  925. global $_course, $learnpath_id, $tbl_learnpath_item, $items;
  926. global $curDirPath, $_configuration, $enableDocumentParsing, $_user, $_cid;
  927. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  928. $course_id = api_get_course_int_id();
  929. $hyperlink_target_parameter = ''; // or e.g. target='_blank'
  930. $builder = 'player';
  931. $origin = 'learnpath';
  932. $linktype = $type;
  933. if (($type == 'Link _self') || ($type == 'Link _blank')) { $type = 'Link'; }
  934. $link = '';
  935. switch ($type) {
  936. case 'Agenda':
  937. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  938. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  939. $myrow = Database::fetch_array($result);
  940. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  941. $result = Database::query($sql); $row = Database::fetch_array($result);
  942. if ($row['title'] != '') { $myrow['title'] = $row['title']; }
  943. $desc = $row['description'];
  944. $agenda_id = $row['item_id'];
  945. if ($builder != 'builder') {
  946. $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";
  947. } else {
  948. $link .= "../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id";
  949. }
  950. break;
  951. case 'Ad_Valvas':
  952. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  953. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  954. $myrow = Database::fetch_array($result);
  955. if ($builder != 'builder') {
  956. $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";
  957. } else {
  958. $link .= "../announcements/announcements.php?origin=$origin&ann_id=$id";
  959. }
  960. break;
  961. case 'Link':
  962. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  963. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  964. $myrow = Database::fetch_array($result);
  965. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  966. $result = Database::query($sql);
  967. $row = Database::fetch_array($result);
  968. $thelink = $myrow['url'];
  969. if ($builder != 'builder') {
  970. $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";
  971. } else {
  972. $link .= $thelink;
  973. }
  974. break;
  975. case 'Exercise':
  976. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  977. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND id=$id");
  978. $myrow = Database::fetch_array($result);
  979. if ($builder == 'builder') { $origin = 'builder'; }
  980. // This is needed for the exercise_submit.php can delete the session info about tests.
  981. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  982. $result = Database::query($sql); $row = Database::fetch_array($result);
  983. if ($row['title'] != '') { $myrow['title'] = $row['title']; }
  984. if ($builder != 'builder') {
  985. $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";
  986. } else {
  987. $link .= "../exercice/exercise_submit.php?origin=$origin&exerciseId=".$myrow["id"];
  988. }
  989. break;
  990. case 'HotPotatoes':
  991. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  992. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  993. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND id=$id");
  994. $myrow = Database::fetch_array($result);
  995. $path = $myrow['path'];
  996. $name = GetQuizName($path, $documentPath);
  997. if ($builder == 'builder') {
  998. $origin = 'builder';
  999. }
  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 = api_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. return $output;
  1410. }
  1411. /**
  1412. * Returns an HTML-formatted link to a resource, to incorporate directly into
  1413. * the new learning path tool.
  1414. *
  1415. * The function is a big switch on tool type.
  1416. * In each case, we query the corresponding table for information and build the link
  1417. * with that information.
  1418. * @author Yannick Warnier <ywarnier@beeznest.org> - rebranding based on previous work (display_addedresource_link_in_learnpath())
  1419. * @param int $course_id Course code
  1420. * @param int $learnpath_id The learning path ID (in lp table)
  1421. * @param int $id_in_path the unique index in the items table
  1422. * @param int $lpViewId
  1423. */
  1424. function rl_get_resource_link_for_learnpath($course_id, $learnpath_id, $id_in_path, $lpViewId)
  1425. {
  1426. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1427. $course_info = api_get_course_info_by_id($course_id);
  1428. $course_id = $course_info['real_id'];
  1429. $course_code = $course_info['code'];
  1430. $session_id = api_get_session_id();
  1431. $learnpath_id = intval($learnpath_id);
  1432. $id_in_path = intval($id_in_path);
  1433. $lpViewId = intval($lpViewId);
  1434. $sql = "SELECT * FROM $tbl_lp_item
  1435. WHERE
  1436. c_id = $course_id AND
  1437. lp_id = $learnpath_id AND
  1438. id = $id_in_path
  1439. ";
  1440. $res_item = Database::query($sql);
  1441. if (Database::num_rows($res_item) < 1) {
  1442. return -1;
  1443. }
  1444. $row_item = Database::fetch_array($res_item);
  1445. $type = strtolower($row_item['item_type']);
  1446. $id = (strcmp($row_item['path'], '') == 0) ? '0' : $row_item['path'];
  1447. $origin = 'learnpath';
  1448. $main_dir_path = api_get_path(WEB_CODE_PATH);
  1449. $main_course_path = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/';
  1450. $link = '';
  1451. switch ($type) {
  1452. case 'dokeos_chapter':
  1453. $link .= $main_dir_path.'newscorm/blank.php';
  1454. case TOOL_CALENDAR_EVENT:
  1455. $link .= $main_dir_path.'calendar/agenda.php?origin='.$origin.'&agenda_id='.$id;
  1456. break;
  1457. case TOOL_ANNOUNCEMENT:
  1458. $link .= $main_dir_path.'announcements/announcements.php?origin='.$origin.'&ann_id='.$id;
  1459. break;
  1460. case TOOL_LINK:
  1461. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  1462. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  1463. $myrow = Database::fetch_array($result);
  1464. $thelink = $myrow["url"];
  1465. $link .= $thelink;
  1466. break;
  1467. case TOOL_QUIZ:
  1468. if (!empty($id)) {
  1469. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  1470. $sql = "SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND id=$id";
  1471. $result= Database::query($sql);
  1472. $myrow=Database::fetch_array($result);
  1473. if ($row_item['title'] != '') {
  1474. $myrow['title'] = $row_item['title'];
  1475. }
  1476. $link .= $main_dir_path.'exercice/overview.php?cidReq='.$course_code.'&session_id='.$session_id.'&lp_init=1&origin='.$origin.'&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path.'&exerciseId='.$id;
  1477. }
  1478. break;
  1479. case 'hotpotatoes': //lowercase because of strtolower above
  1480. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  1481. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND id=$id");
  1482. $myrow = Database::fetch_array($result);
  1483. $path = $myrow['path'];
  1484. $link .= $main_dir_path.'exercice/showinframes.php?file='.$path.'' .
  1485. '&origin='.$origin.'&cid='.$course_code.'&uid='.api_get_user_id().'' .
  1486. '&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path.'&lp_view_id='.$lpViewId;
  1487. break;
  1488. case TOOL_FORUM:
  1489. $link .= $main_dir_path.'forum/viewforum.php?forum='.$id.'&lp=true&origin=learnpath';
  1490. break;
  1491. case TOOL_THREAD: //forum post
  1492. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD);
  1493. if (!empty($id)) {
  1494. $sql = "SELECT * FROM $tbl_topics WHERE c_id = $course_id AND thread_id=$id";
  1495. $result = Database::query($sql);
  1496. $myrow = Database::fetch_array($result);
  1497. $link .= $main_dir_path.'forum/viewthread.php?origin=learnpath&thread='.$id.'' .
  1498. '&forum='.$myrow['forum_id'].'&lp=true';
  1499. }
  1500. break;
  1501. case TOOL_POST:
  1502. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  1503. $result = Database::query("SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=$id");
  1504. $myrow = Database::fetch_array($result);
  1505. $title = $myrow['post_title'];
  1506. //$desc = $row_item['description'];
  1507. $posternom = $myrow['poster_name'];
  1508. $posttime = $myrow['post_date'];
  1509. $posttext = $myrow['post_text'];
  1510. $posttitle = $title;
  1511. $posttext = str_replace('"', "'", $posttext);
  1512. $link .= $main_dir_path.'forum/viewthread.php?post='.$id.'' .
  1513. '&thread='.$myrow['thread_id'].'&forum='.$myrow['forum_id'].'' .
  1514. '&lp=true';
  1515. break;
  1516. case TOOL_DOCUMENT:
  1517. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  1518. $sql = "SELECT * FROM $tbl_doc WHERE c_id = $course_id AND id = $id";
  1519. $result = Database::query($sql);
  1520. $myrow = Database::fetch_array($result);
  1521. $docurl = str_replace('%2F', '/', urlencode($myrow['path']));
  1522. $link .= $main_course_path.'document'.$docurl.'?cidReq='.$course_code.'&id_session='.$session_id;
  1523. $openmethod = 2;
  1524. $officedoc = false;
  1525. Session::write('openmethod',$openmethod);
  1526. Session::write('officedoc',$officedoc);
  1527. break;
  1528. case 'assignments':
  1529. $link .= $main_dir_path.'work/work.php?origin='.$origin;
  1530. break;
  1531. case TOOL_DROPBOX:
  1532. $link .= $main_dir_path.'dropbox/index.php?origin=learnpath';
  1533. break;
  1534. case 'introduction_text': //DEPRECATED
  1535. $link .= '';
  1536. break;
  1537. case TOOL_COURSE_DESCRIPTION:
  1538. $link .= $main_dir_path.'course_description?origin=learnpath';
  1539. break;
  1540. case TOOL_GROUP:
  1541. $link .= $main_dir_path.'group/group.php?origin='.$origin;
  1542. break;
  1543. case TOOL_USER:
  1544. $link .= $main_dir_path.'user/user.php?origin='.$origin;
  1545. break;
  1546. case 'student_publication' :
  1547. $link .= $main_dir_path.'work/work.php?origin=learnpath';
  1548. break;
  1549. } //end switch
  1550. return $link;
  1551. }
  1552. /**
  1553. * Gets the name of a resource (generally used in learnpath when no name is provided)
  1554. *
  1555. * @author Yannick Warnier <ywarnier@beeznest.org>, Dokeos - rebranding
  1556. * @param string Course code
  1557. * @param string The tool type (using constants declared in main_api.lib.php)
  1558. * @param integer The resource ID
  1559. */
  1560. function rl_get_resource_name($course_code, $learnpath_id, $id_in_path)
  1561. {
  1562. $_course = api_get_course_info($course_code);
  1563. $course_id = $_course['real_id'];
  1564. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1565. $learnpath_id = intval($learnpath_id);
  1566. $id_in_path = intval($id_in_path);
  1567. $sql_item = "SELECT item_type, title, ref FROM $tbl_lp_item
  1568. WHERE c_id = $course_id AND lp_id = $learnpath_id AND id = $id_in_path";
  1569. $res_item = Database::query($sql_item);
  1570. if (Database::num_rows($res_item) < 1) {
  1571. return '';
  1572. }
  1573. $row_item = Database::fetch_array($res_item);
  1574. $type = strtolower($row_item['item_type']);
  1575. $id = $row_item['ref'];
  1576. $output = '';
  1577. switch ($type) {
  1578. case TOOL_CALENDAR_EVENT:
  1579. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  1580. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  1581. $myrow = Database::fetch_array($result);
  1582. $output = $myrow['title'];
  1583. break;
  1584. case TOOL_ANNOUNCEMENT:
  1585. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1586. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  1587. $myrow = Database::fetch_array($result);
  1588. $output = $myrow['title'];
  1589. break;
  1590. case TOOL_LINK:
  1591. // Doesn't take $target into account.
  1592. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  1593. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  1594. $myrow = Database::fetch_array($result);
  1595. $output = $myrow['title'];
  1596. break;
  1597. case TOOL_QUIZ:
  1598. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  1599. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND id=$id");
  1600. $myrow = Database::fetch_array($result);
  1601. $output = $myrow['title'];
  1602. break;
  1603. case TOOL_FORUM:
  1604. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  1605. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  1606. $myrow = Database::fetch_array($result);
  1607. $output = $myrow['forum_name'];
  1608. break;
  1609. case TOOL_THREAD: //=topics
  1610. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  1611. // Grabbing the title of the post.
  1612. $sql_title = "SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=".$id;
  1613. $result_title = Database::query($sql_title);
  1614. $myrow_title = Database::fetch_array($result_title);
  1615. $output = $myrow_title['post_title'];
  1616. break;
  1617. case TOOL_POST:
  1618. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  1619. //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE);
  1620. $sql = "SELECT * FROM $tbl_post p WHERE c_id = $course_id AND p.post_id = $id";
  1621. $result = Database::query($sql);
  1622. $post = Database::fetch_array($result);
  1623. $output = $post['post_title'];
  1624. break;
  1625. case 'dokeos_chapter':
  1626. $title = $row_item['title'];
  1627. if (!empty($title)) {
  1628. $output = $title;
  1629. } else {
  1630. $output = '-';
  1631. }
  1632. break;
  1633. case TOOL_DOCUMENT:
  1634. $title = $row_item['title'];
  1635. if (!empty($title)) {
  1636. $output = $title;
  1637. } else {
  1638. $output = '-';
  1639. }
  1640. break;
  1641. case 'hotpotatoes':
  1642. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  1643. $result = Database::query("SELECT * FROM $tbl_doc WHERE c_id = $course_id AND id=$id");
  1644. $myrow = Database::fetch_array($result);
  1645. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  1646. $last = count($pathname) - 1; // Making a correct name for the link.
  1647. $filename = $pathname[$last]; // Making a correct name for the link.
  1648. $image = choose_image($filename);
  1649. $ext = explode('.', $filename);
  1650. $ext = strtolower($ext[sizeof($ext) - 1]);
  1651. $myrow['path'] = rawurlencode($myrow['path']);
  1652. $in_frames = in_array($ext, array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png'));
  1653. $output = $filename;
  1654. break;
  1655. /*
  1656. case 'externallink':
  1657. $output = '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.' '.$target.'>'.$id."</a><br />\n";
  1658. break;
  1659. */
  1660. }
  1661. return stripslashes($output);
  1662. }