resourcelinker.inc.php 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853
  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. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  12. use ChamiloSession as Session;
  13. $use_anonymous = true;
  14. require_once '../inc/global.inc.php';
  15. if (!empty($_course['language'])){
  16. $resource_linker_file = api_get_path(SYS_CODE_PATH).'lang/'.$_course['language'].'/resourcelinker.inc.php';
  17. if (file_exists($resource_linker_file)) {
  18. require_once $resource_linker_file;
  19. }
  20. }
  21. require_once '../exercice/hotpotatoes.lib.php';
  22. /* FUNCTIONS */
  23. function unset_session_resources() {
  24. $_SESSION['addedresource'] = '';
  25. $_SESSION['addedresourceid'] = '';
  26. Session::erase(addedresource);
  27. Session::erase(addedresourceid);
  28. }
  29. /**
  30. * Insert description here.
  31. */
  32. function show_folder_up() {
  33. global $folder;
  34. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  35. $level = get_levels($folder);
  36. if ($level == 1) {
  37. 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>";
  38. }
  39. if ($level && $level != 0 && $level != 1) {
  40. $folder_up=$folder;
  41. $folder_temp=explode('/',$folder);
  42. $last=count($folder_temp)-1;
  43. unset($folder_temp[$last]);
  44. $folder_up=implode('/',$folder_temp);
  45. echo "<a href='".api_get_self()."?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>";
  46. }
  47. }
  48. /**
  49. * Shows the documents of the document tool
  50. * @param $folder
  51. */
  52. function show_documents($folder) {
  53. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  54. // Documents are a special case: The teacher can add an invisible document (it will be viewable by the user)
  55. // other tools do not have this feature.
  56. if (api_is_allowed_to_edit()) {
  57. $visibility = "ip.visibility<>'2'";
  58. } else {
  59. $visibility = "ip.visibility='1'";
  60. }
  61. $course_id = api_get_course_int_id();
  62. $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  63. $document_table = Database::get_course_table(TABLE_DOCUMENT);
  64. $sql = "SELECT * from $document_table docs , $item_property_table ip
  65. WHERE
  66. docs.c_id = $course_id AND
  67. ip.c_id = $course_id AND
  68. docs.id=ip.ref AND
  69. ip.tool = '".TOOL_DOCUMENT."' AND
  70. $visibility AND
  71. (ip.to_group_id = 0 OR ip.to_group_id IS NULL)AND
  72. ip.to_user_id IS NULL
  73. ORDER BY docs.path ASC";
  74. $result = Database::query($sql);
  75. while ($row = Database::fetch_array($result)) {
  76. if (!$folder) {
  77. if (get_levels($row['path'])-1 == 1) {
  78. // showing the right icon.
  79. if (file_or_folder($row['path'])) {
  80. echo '<img src="../img/file.gif" align="middle" />';
  81. } else {
  82. $image = choose_image($row['path']);
  83. echo "<img src=\"../img/$image\" align=\"middle\" />";
  84. }
  85. // Folders should be clickable.
  86. if (file_or_folder($row['path'])) {
  87. echo "<a href='".api_get_self()."?content=Document";
  88. echo "&folder=".substr($row['path'], 1)."&source_id=$source_id&source_forum=".$_GET['source_forum']."&action=$action&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no'>".substr($row['path'], 1).'</a><br />';
  89. } else {
  90. echo substr($row['path'], 1).' ';
  91. echo showorhide_addresourcelink('Document',$row['id']);
  92. echo '<br />';
  93. }
  94. }
  95. } else {
  96. // We calculate the level we are in by using the $folder in the url.
  97. // We put +1 because it does not start with an / and in the database it does
  98. $level = get_levels($folder) + 1;
  99. // We calculate each level of the database entry.
  100. $file_level=get_levels($row['path'])-1;
  101. // If the level of the database entry is equal to the level we ar in, we put it into an array
  102. // as this is a potential good entry.
  103. if ($file_level == $level) {
  104. $good_paths[] = $row['path'];
  105. $good_ids[] = $row['id'];
  106. }
  107. //$haystack=$row['path'];
  108. //$conform_folder=strstr($haystack, $folder);
  109. //if (str_replace($folder.'/', '', $conform_folder) !== $folder) {
  110. // $good_folders[] = $row['path'];
  111. //echo str_replace($folder.'/', '', $conform_folder);
  112. // echo '<br />';
  113. // }// if (str_replace($folder.'/','',$conform_folder)!==$folder)
  114. } // else (if (!$folder))
  115. } //while ($row=Database::fetch_array($result))
  116. // This is code for the case that we are in a subfolder.
  117. if ($good_paths) {
  118. // We have all the potential good database entries, the good ones are those that start with $folder
  119. foreach ($good_paths as $path) {
  120. if (strstr($path, $folder)) {
  121. $good_key = key($good_paths);
  122. // Showing the right icon.
  123. if (file_or_folder($path)) {
  124. echo '<img src="../img/file.gif" align="middle" />';
  125. } else {
  126. $image = choose_image($path);
  127. echo "<img src=\"../img/$image\" align=\"middle\" />";
  128. }
  129. // Folders should be clickable
  130. if (file_or_folder($path)) {
  131. $path = substr($path, 1); // Remove the first / in folder_up.
  132. $uri = str_replace($folder, $path, $_SERVER['REQUEST_URI']);
  133. $newuri = str_replace('add=', 'addnot=', $uri);
  134. // Using the correct name of the folder.
  135. $folder_name = str_replace($folder.'/', '', $path);
  136. echo "<a href='$newuri'>".$folder_name.'</a><br />';
  137. } else {
  138. echo str_replace("/$folder/", '', $path).' ';
  139. echo showorhide_addresourcelink('Document', $good_ids[$good_key]);
  140. echo '<br />';
  141. }
  142. }
  143. next($good_paths);
  144. }
  145. }
  146. }
  147. /**
  148. * Checks wether something is a file or a folder
  149. * 0 means file, 1 means folder
  150. * @param $filefolder
  151. * @todo use true and false instead of 1 and 0.
  152. */
  153. function file_or_folder($filefolder) {
  154. global $_course;
  155. $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. {
  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. {
  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 $learnpath_id, $items;
  298. global $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. {
  926. global $_course, $learnpath_id;
  927. global $enableDocumentParsing, $_user, $_cid;
  928. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  929. $course_id = api_get_course_int_id();
  930. $hyperlink_target_parameter = ''; // or e.g. target='_blank'
  931. $builder = 'player';
  932. $origin = 'learnpath';
  933. $linktype = $type;
  934. if (($type == 'Link _self') || ($type == 'Link _blank')) { $type = 'Link'; }
  935. $link = '';
  936. switch ($type) {
  937. case 'Agenda':
  938. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  939. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  940. $myrow = Database::fetch_array($result);
  941. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  942. $result = Database::query($sql); $row = Database::fetch_array($result);
  943. if ($row['title'] != '') { $myrow['title'] = $row['title']; }
  944. $desc = $row['description'];
  945. $agenda_id = $row['item_id'];
  946. if ($builder != 'builder') {
  947. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path";
  948. } else {
  949. $link .= "../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id";
  950. }
  951. break;
  952. case 'Ad_Valvas':
  953. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  954. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  955. $myrow = Database::fetch_array($result);
  956. if ($builder != 'builder') {
  957. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$id#$id_in_path";
  958. } else {
  959. $link .= "../announcements/announcements.php?origin=$origin&ann_id=$id";
  960. }
  961. break;
  962. case 'Link':
  963. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  964. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  965. $myrow = Database::fetch_array($result);
  966. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  967. $result = Database::query($sql);
  968. $row = Database::fetch_array($result);
  969. $thelink = $myrow['url'];
  970. if ($builder != 'builder') {
  971. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path";
  972. } else {
  973. $link .= $thelink;
  974. }
  975. break;
  976. case 'Exercise':
  977. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  978. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND id=$id");
  979. $myrow = Database::fetch_array($result);
  980. if ($builder == 'builder') { $origin = 'builder'; }
  981. // This is needed for the exercise_submit.php can delete the session info about tests.
  982. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  983. $result = Database::query($sql); $row = Database::fetch_array($result);
  984. if ($row['title'] != '') { $myrow['title'] = $row['title']; }
  985. if ($builder != 'builder') {
  986. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path";
  987. } else {
  988. $link .= "../exercice/exercise_submit.php?origin=$origin&exerciseId=".$myrow["id"];
  989. }
  990. break;
  991. case 'HotPotatoes':
  992. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  993. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  994. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND id=$id");
  995. $myrow = Database::fetch_array($result);
  996. $path = $myrow['path'];
  997. $name = GetQuizName($path, $documentPath);
  998. if ($builder == 'builder') {
  999. $origin = 'builder';
  1000. }
  1001. $cid = $_course['official_code'];
  1002. if ($builder != 'builder') {
  1003. $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";
  1004. } else {
  1005. $link .= "../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id'];
  1006. }
  1007. break;
  1008. case 'Forum':
  1009. //deprecated
  1010. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM); // TODO: This is the old table name, it should be corrected.
  1011. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  1012. $myrow = Database::fetch_array($result);
  1013. if ($builder == 'builder') { $origin = 'builder'; }
  1014. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1015. $result = Database::query($sql); $row = Database::fetch_array($result);
  1016. if ($row['title'] != '') { $myrow['forum_name'] = $row['title']; }
  1017. if ($myrow['forum_name'] == '') { $type = 'Forum'; }
  1018. $forumparameters = "forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1019. if ($builder != 'builder') {
  1020. $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";
  1021. } else {
  1022. $link .= "../phpbb/viewforum.php?$forumparameters";
  1023. }
  1024. break;
  1025. case 'Thread': //forum post
  1026. //deprecated
  1027. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD);
  1028. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST);
  1029. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  1030. $sql = "SELECT * FROM $tbl_topics where c_id = $course_id AND topic_id=$id";
  1031. $result = Database::query($sql);
  1032. $myrow = Database::fetch_array($result);
  1033. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1034. $result = Database::query($sql); $row = Database::fetch_array($result);
  1035. if ($builder != 'builder') {
  1036. $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";
  1037. } else {
  1038. $link .= "../forum/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1039. }
  1040. break;
  1041. case 'Post':
  1042. //deprecated
  1043. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST);
  1044. $result = Database::query("SELECT * FROM $tbl_posts where c_id = $course_id AND post_id=$id");
  1045. $myrow = Database::fetch_array($result);
  1046. // Grabbing the title of the post.
  1047. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1048. $result = Database::query($sql);
  1049. $row = Database::fetch_array($result);
  1050. if ($row['title'] != '') { $myrow['post_title'] = $row['title']; }
  1051. $desc = $row['description'];
  1052. //$link .= str_repeat("&nbsp;&gt;", $level);
  1053. $posternom = $myrow['nom']; $posterprenom = $myrow['prenom'];
  1054. $posttime = $myrow['post_time']; $posttext = $myrow['post_text'];
  1055. $posttitle = $myrow['post_title'];
  1056. $posttext = str_replace('"', "'", $posttext);
  1057. if ($builder != 'builder') {
  1058. $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";
  1059. } else {
  1060. $link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1061. }
  1062. break;
  1063. case 'Document':
  1064. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  1065. $result = Database::query("SELECT * FROM $dbTable WHERE id=$id");
  1066. $myrow = Database::fetch_array($result);
  1067. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  1068. $last = count($pathname) - 1; // Making a correct name for the link.
  1069. $filename = $pathname[$last]; // Making a correct name for the link.
  1070. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1071. $result = Database::query($sql);
  1072. $row = Database::fetch_array($result);
  1073. if ($builder != 'builder') {
  1074. $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";
  1075. } else {
  1076. $enableDocumentParsing = yes;
  1077. if (!$enableDocumentParsing) {
  1078. // This is the solution for the non-parsing version in the builder.
  1079. $file = urlencode($myrow['path']);
  1080. $link .= "../document/showinframes.php?file=$file";
  1081. } else {
  1082. $link .= "../document/download.php?doc_url=".$myrow['path'];
  1083. }
  1084. }
  1085. break;
  1086. case 'Assignments':
  1087. if ($builder != 'builder') {
  1088. $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";
  1089. } else {
  1090. $link .= "../work/work.php";
  1091. }
  1092. break;
  1093. case 'Dropbox':
  1094. if ($builder != 'builder') {
  1095. $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";
  1096. } else {
  1097. $link .= "../dropbox/index.php";
  1098. }
  1099. break;
  1100. case 'Introduction_text':
  1101. if ($builder != 'builder') {
  1102. $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";
  1103. } else {
  1104. $s = api_get_path(WEB_COURSE_PATH)."$_cid/index.php?intro_cmdEdit=1";
  1105. $link .= $s;
  1106. }
  1107. break;
  1108. case 'Course_description':
  1109. if ($builder != 'builder') {
  1110. $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";
  1111. } else {
  1112. $s = api_get_path(WEB_CODE_PATH).'course_description';
  1113. $link .= $s;
  1114. }
  1115. break;
  1116. case 'Groups':
  1117. if ($builder != 'builder') {
  1118. $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";
  1119. } else {
  1120. $link .= "../group/group.php?origin=$origin";
  1121. }
  1122. break;
  1123. case 'Users':
  1124. if ($builder != 'builder') {
  1125. $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";
  1126. } else {
  1127. $link .= "../user/user.php?origin=$origin";
  1128. }
  1129. break;
  1130. }//end huge switch-statement
  1131. return $link;
  1132. }
  1133. /**
  1134. * This function is to remove an resource item from the array
  1135. */
  1136. function remove_resource($resource_key) {
  1137. $addedresource = $_SESSION['addedresource'];
  1138. $addedresourceid = $_SESSION['addedresourceid'];
  1139. unset($addedresource[$resource_key]);
  1140. unset($addedresourceid[$resource_key]);
  1141. $_SESSION['addedresource'] = $addedresource;
  1142. $_SESSION['addedresourceid'] = $addedresourceid ;
  1143. }
  1144. /**
  1145. * This function is to show the button "click to add resource" on the tool page
  1146. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1147. */
  1148. function show_addresource_button($additionalparameters = '') {
  1149. global $charset;
  1150. 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.' />';
  1151. }
  1152. /**
  1153. * This function is to delete ONE specific resource that were added to a specific item
  1154. * Deprecated
  1155. *//*
  1156. function delete_one_added_resource($source_type, $source_id, $resource_type, $resource_id) {
  1157. //echo "delete_one_added_resource";
  1158. global $_course;
  1159. $TABLERESOURCE = $_course['dbNameGlu'].'resource';
  1160. $sql = "DELETE FROM $TABLERESOURCE WHERE source_type='$source_type' and source_id='$source_id' and resource_type='$resource_type' and resource_id='$resource_id'";
  1161. Database::query($sql);
  1162. }*/
  1163. /**
  1164. * This function is to delete the resources that were added to a specific item
  1165. */
  1166. function delete_added_resource($type, $id)
  1167. {
  1168. $course_id = api_get_course_int_id();
  1169. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1170. $sql = "DELETE FROM $TABLERESOURCE
  1171. WHERE c_id = $course_id AND source_type='$type' and source_id='$id'";
  1172. Database::query($sql);
  1173. }
  1174. /**
  1175. * This function is te delete all resources of a specific type (only used in announcements -- delete all)
  1176. * Author : Frederik Vermeire <frederik.vermeire@pandora.be>
  1177. */
  1178. function delete_all_resources_type($type)
  1179. {
  1180. $course_id = api_get_course_int_id();
  1181. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1182. $sql = "DELETE FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type'";
  1183. Database::query($sql);
  1184. }
  1185. /**
  1186. * This function checks wether there are added resources or not
  1187. */
  1188. function check_added_resources($type, $id) {
  1189. $course_id = api_get_course_int_id();
  1190. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1191. $sql = "SELECT * FROM $TABLERESOURCE
  1192. WHERE c_id = $course_id AND source_type='$type' and source_id='$id'";
  1193. $result = Database::query($sql);
  1194. $number_added = Database::num_rows($result);
  1195. if ($number_added != 0)
  1196. return true;
  1197. else
  1198. return false;
  1199. }
  1200. /**
  1201. * this function is to load the resources that were added to a specific item
  1202. * into the session variables
  1203. */
  1204. function edit_added_resources($type, $id)
  1205. {
  1206. $course_id = api_get_course_int_id();
  1207. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1208. $sql = "SELECT * FROM $TABLERESOURCE
  1209. WHERE c_id = $course_id AND source_type='$type' and source_id=$id";
  1210. $result=Database::query($sql);
  1211. while ($row=Database::fetch_array($result))
  1212. {
  1213. $addedresource[]=$row["resource_type"];
  1214. $addedresourceid[]=$row["resource_id"];
  1215. }
  1216. $_SESSION['addedresource'] = $addedresource;
  1217. $_SESSION['addedresourceid'] = $addedresourceid;
  1218. }
  1219. /**
  1220. * this function is store the modified resources
  1221. * first we delete all the added resources in the database,
  1222. * then we add all the resources from the session object.
  1223. */
  1224. function update_added_resources($type, $id)
  1225. {
  1226. $course_id = api_get_course_int_id();
  1227. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1228. // delete all the added resources for this item in the database;
  1229. $sql = "DELETE FROM $TABLERESOURCE
  1230. WHERE c_id = $course_id AND source_type='$type' AND source_id='$id'";
  1231. //echo $sql;
  1232. Database::query($sql);
  1233. // Store the resources from the session into the database.
  1234. store_resources($type, $id);
  1235. //delete_added_resource_($type, $id);
  1236. unset_session_resources();
  1237. }
  1238. /**
  1239. * this function is to display the resources that were added to a specific item
  1240. */
  1241. function display_added_resources($type, $id, $style = '') {
  1242. $course_id = api_get_course_int_id();
  1243. // The array containing the icons
  1244. $arr_icons = array(
  1245. 'Agenda' => '../img/agenda.gif',
  1246. 'Ad Valvas' => '../img/valves.gif',
  1247. 'Link' => '../img/links.gif',
  1248. 'Exercise' => '../img/quiz.gif',
  1249. );
  1250. global $origin;
  1251. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1252. $sql = "SELECT * FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' and source_id='$id'";
  1253. $result = Database::query($sql);
  1254. while ($row=Database::fetch_array($result)) {
  1255. if ($origin != 'learnpath') {
  1256. display_addedresource_link($row['resource_type'], $row['resource_id'], $style) ;
  1257. } else {
  1258. display_addedresource_link_in_learnpath($row['resource_type'], $row['resource_id'],'agendaitems','','builder','icon') ; echo "<br>";
  1259. }
  1260. }
  1261. }
  1262. /**
  1263. * This function is to show the added resources when adding an item
  1264. * $showdeleteimg determine if the delete image should appear or not.
  1265. * deleting an added resource is only possible through the resource linker file itself
  1266. */
  1267. function display_resources($showdeleteimg) {
  1268. global $action;
  1269. global $resourceaction;
  1270. global $id;
  1271. global $locationkey;
  1272. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  1273. if ($resourceaction == 'removeresource') {
  1274. remove_resource($locationkey);
  1275. }
  1276. $addedresource = $_SESSION['addedresource'];
  1277. $addedresourceid = $_SESSION['addedresourceid'];
  1278. if (is_array($addedresource)) {
  1279. echo '<table>';
  1280. foreach ($addedresource as $resource) {
  1281. echo '<tr><td>';
  1282. display_addedresource_link($resource, $addedresourceid[key($addedresource)]);
  1283. echo '</td><td width="30">';
  1284. // if $_SERVER['REQUEST_URI'] contains and ?id=xx we have an edit and the url for deleting a session added resource
  1285. // should also contain this id.
  1286. $test = parse_url($_SERVER['REQUEST_URI']);
  1287. $output = array();
  1288. parse_str($test[query], $output);
  1289. if ($showdeleteimg == 1) {
  1290. 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 />";
  1291. }
  1292. echo '</td></tr>';
  1293. next($addedresource);
  1294. }
  1295. echo '</table>';
  1296. }
  1297. else { // it is a string
  1298. echo '';
  1299. }
  1300. } // end of the display_resources function
  1301. /**
  1302. * This function checks wether the link add resource should be displayed next the item in the linker page
  1303. * So we have to check if the specific id of that tool is already in the array of the added resources
  1304. * if it is already in, the link should not be showed since it would make it possible to add
  1305. * the same resource a second time (=duplication of added resources)
  1306. */
  1307. function showorhide_addresourcelink($type, $id) {
  1308. global $from_learnpath, $source_id, $action, $learnpath_id, $chapter_id, $originalresource, $folder, $content, $target;
  1309. $addedresource = $_SESSION['addedresource'];
  1310. $addedresourceid = $_SESSION['addedresourceid'];
  1311. if (is_array($_SESSION['addedresource'])) {
  1312. foreach ($addedresource as $toolcompare) {
  1313. if ($toolcompare==$type && $addedresourceid[key($addedresource)] == $id) {
  1314. $show = 0;
  1315. }
  1316. next($addedresource);
  1317. }
  1318. if ($from_learnpath) { $lang_add_it_or_resource = get_lang('AddIt'); } else { $lang_add_it_or_resource = get_lang('AddResource'); }
  1319. if ($show !== 0) {
  1320. if ($type == 'Document') {
  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>".$lang_add_it_or_resource."</a>";
  1322. } else {
  1323. 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>";
  1324. }
  1325. }
  1326. }
  1327. else { // if it is not an array, it is a string
  1328. if ($_SESSION['addedresource'] !== $type || $_SESSION['addedresourceid'] !== $id) {
  1329. if ($from_learnpath) { $lang_add_it_or_resource = get_lang('AddIt'); } else { $lang_add_it_or_resource = get_lang('AddResource'); }
  1330. 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>";
  1331. }
  1332. }
  1333. }
  1334. /**
  1335. * Gets the link to the given added resource.
  1336. *
  1337. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1338. * @author Yannick Warnier <ywarnier@beeznest.org>, Dokeos - rebranding
  1339. * @param string Course code
  1340. * @param string The tool type (using constants declared in main_api.lib.php)
  1341. * @param integer The resource ID
  1342. * @param string Resource style (e.g. when a resource is hidden => the added resources should also be styled like they are hidden)
  1343. * @param boolean Open in a new window (true) or in the current frame/window (false)?
  1344. * @todo use the constants for the type definitions.
  1345. */
  1346. function rl_get_html_resource_link($course_code, $type, $id, $style='', $new_window = true) {
  1347. $_course = api_get_course_info($course_code);
  1348. $course_id = api_get_course_int_id();
  1349. // Styling the link of the added resource
  1350. if ($style != '') $styling = ' class="'.$style.'"';
  1351. if ($new_window) { $target = ' target = "_blank" '; } else { $target = ' target = "_self" '; }
  1352. $output = '';
  1353. switch ($type) {
  1354. case TOOL_CALENDAR_EVENT:
  1355. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  1356. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  1357. $myrow = Database::fetch_array($result);
  1358. $output = '<img src="../img/agenda.gif" align="middle" /> <a href="../calendar/agenda.php"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1359. break;
  1360. case TOOL_ANNOUNCEMENT:
  1361. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1362. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  1363. $myrow = Database::fetch_array($result);
  1364. $output = '<img src="../img/valves.gif" align="middle" /> <a href="../announcements/announcements.php"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1365. break;
  1366. case TOOL_LINK:
  1367. //doesn't take $target into account
  1368. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  1369. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  1370. $myrow = Database::fetch_array($result);
  1371. $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";
  1372. break;
  1373. case TOOL_QUIZ:
  1374. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  1375. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND id=$id");
  1376. $myrow = Database::fetch_array($result);
  1377. $output = '<img src="../img/quiz.gif" align="middle" /> <a href="../exercice/exercise_submit.php?exerciseId='.$myrow['id'].'"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1378. break;
  1379. case TOOL_FORUM:
  1380. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  1381. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  1382. $myrow = Database::fetch_array($result);
  1383. $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";
  1384. break;
  1385. case TOOL_THREAD: //=topics
  1386. //$tbl_forum = Database::get_course_table(TABLE_FORUM);
  1387. //$tbl_thread = Database::get_course_table(TABLE_FORUM_THREAD);
  1388. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  1389. // grabbing the title of the post
  1390. $sql_title = "SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=".$id;
  1391. $result_title = Database::query($sql_title);
  1392. $myrow_title = Database::fetch_array($result_title);
  1393. $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";
  1394. break;
  1395. case TOOL_POST:
  1396. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  1397. //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE);
  1398. $sql = "SELECT * FROM $tbl_post p WHERE c_id = $course_id AND p.post_id = $id";
  1399. $result = Database::query($sql);
  1400. $post = Database::fetch_array($result);
  1401. $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";
  1402. break;
  1403. case TOOL_DOCUMENT:
  1404. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  1405. $result = Database::query("SELECT * FROM $tbl_doc WHERE c_id = $course_id AND id=$id");
  1406. $myrow = Database::fetch_array($result);
  1407. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  1408. $last = count($pathname) - 1; // Making a correct name for the link.
  1409. $filename = $pathname[$last]; // Making a correct name for the link.
  1410. $image = choose_image($filename);
  1411. $ext = explode('.', $filename);
  1412. $ext = strtolower($ext[sizeof($ext) - 1]);
  1413. $myrow['path'] = rawurlencode($myrow['path']);
  1414. $in_frames = in_array($ext, array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png'));
  1415. $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";
  1416. break;
  1417. }
  1418. return $output;
  1419. }
  1420. /**
  1421. * Returns an HTML-formatted link to a resource, to incorporate directly into
  1422. * the new learning path tool.
  1423. *
  1424. * The function is a big switch on tool type.
  1425. * In each case, we query the corresponding table for information and build the link
  1426. * with that information.
  1427. * @author Yannick Warnier <ywarnier@beeznest.org> - rebranding based on previous work (display_addedresource_link_in_learnpath())
  1428. * @param int $course_id Course code
  1429. * @param int $learnpath_id The learning path ID (in lp table)
  1430. * @param int $id_in_path the unique index in the items table
  1431. * @param int $lpViewId
  1432. */
  1433. function rl_get_resource_link_for_learnpath($course_id, $learnpath_id, $id_in_path, $lpViewId)
  1434. {
  1435. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1436. $course_info = api_get_course_info_by_id($course_id);
  1437. $course_id = $course_info['real_id'];
  1438. $course_code = $course_info['code'];
  1439. $session_id = api_get_session_id();
  1440. $learnpath_id = intval($learnpath_id);
  1441. $id_in_path = intval($id_in_path);
  1442. $lpViewId = intval($lpViewId);
  1443. $sql = "SELECT * FROM $tbl_lp_item
  1444. WHERE
  1445. c_id = $course_id AND
  1446. lp_id = $learnpath_id AND
  1447. id = $id_in_path
  1448. ";
  1449. $res_item = Database::query($sql);
  1450. if (Database::num_rows($res_item) < 1) {
  1451. return -1;
  1452. }
  1453. $row_item = Database::fetch_array($res_item);
  1454. $type = strtolower($row_item['item_type']);
  1455. $id = (strcmp($row_item['path'], '') == 0) ? '0' : $row_item['path'];
  1456. $origin = 'learnpath';
  1457. $main_dir_path = api_get_path(WEB_CODE_PATH);
  1458. $main_course_path = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/';
  1459. $link = '';
  1460. switch ($type) {
  1461. case 'dokeos_chapter':
  1462. $link .= $main_dir_path.'newscorm/blank.php';
  1463. case TOOL_CALENDAR_EVENT:
  1464. $link .= $main_dir_path.'calendar/agenda.php?origin='.$origin.'&agenda_id='.$id;
  1465. break;
  1466. case TOOL_ANNOUNCEMENT:
  1467. $link .= $main_dir_path.'announcements/announcements.php?origin='.$origin.'&ann_id='.$id;
  1468. break;
  1469. case TOOL_LINK:
  1470. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  1471. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  1472. $myrow = Database::fetch_array($result);
  1473. $thelink = $myrow["url"];
  1474. $link .= $thelink;
  1475. break;
  1476. case TOOL_QUIZ:
  1477. if (!empty($id)) {
  1478. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  1479. $sql = "SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND id=$id";
  1480. $result= Database::query($sql);
  1481. $myrow=Database::fetch_array($result);
  1482. if ($row_item['title'] != '') {
  1483. $myrow['title'] = $row_item['title'];
  1484. }
  1485. $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;
  1486. }
  1487. break;
  1488. case 'hotpotatoes': //lowercase because of strtolower above
  1489. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  1490. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND id=$id");
  1491. $myrow = Database::fetch_array($result);
  1492. $path = $myrow['path'];
  1493. $link .= $main_dir_path.'exercice/showinframes.php?file='.$path.'' .
  1494. '&origin='.$origin.'&cid='.$course_code.'&uid='.api_get_user_id().'' .
  1495. '&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path.'&lp_view_id='.$lpViewId;
  1496. break;
  1497. case TOOL_FORUM:
  1498. $link .= $main_dir_path.'forum/viewforum.php?forum='.$id.'&lp=true&origin=learnpath';
  1499. break;
  1500. case TOOL_THREAD: //forum post
  1501. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD);
  1502. if (!empty($id)) {
  1503. $sql = "SELECT * FROM $tbl_topics WHERE c_id = $course_id AND thread_id=$id";
  1504. $result = Database::query($sql);
  1505. $myrow = Database::fetch_array($result);
  1506. $link .= $main_dir_path.'forum/viewthread.php?origin=learnpath&thread='.$id.'' .
  1507. '&forum='.$myrow['forum_id'].'&lp=true';
  1508. }
  1509. break;
  1510. case TOOL_POST:
  1511. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  1512. $result = Database::query("SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=$id");
  1513. $myrow = Database::fetch_array($result);
  1514. $title = $myrow['post_title'];
  1515. //$desc = $row_item['description'];
  1516. $posternom = $myrow['poster_name'];
  1517. $posttime = $myrow['post_date'];
  1518. $posttext = $myrow['post_text'];
  1519. $posttitle = $title;
  1520. $posttext = str_replace('"', "'", $posttext);
  1521. $link .= $main_dir_path.'forum/viewthread.php?post='.$id.'' .
  1522. '&thread='.$myrow['thread_id'].'&forum='.$myrow['forum_id'].'' .
  1523. '&lp=true';
  1524. break;
  1525. case TOOL_DOCUMENT:
  1526. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  1527. $sql = "SELECT * FROM $tbl_doc WHERE c_id = $course_id AND id = $id";
  1528. $result = Database::query($sql);
  1529. $myrow = Database::fetch_array($result);
  1530. $docurl = str_replace('%2F', '/', urlencode($myrow['path']));
  1531. $link .= $main_course_path.'document'.$docurl.'?cidReq='.$course_code.'&id_session='.$session_id;
  1532. $openmethod = 2;
  1533. $officedoc = false;
  1534. Session::write('openmethod',$openmethod);
  1535. Session::write('officedoc',$officedoc);
  1536. break;
  1537. case 'assignments':
  1538. $link .= $main_dir_path.'work/work.php?origin='.$origin;
  1539. break;
  1540. case TOOL_DROPBOX:
  1541. $link .= $main_dir_path.'dropbox/index.php?origin=learnpath';
  1542. break;
  1543. case 'introduction_text': //DEPRECATED
  1544. $link .= '';
  1545. break;
  1546. case TOOL_COURSE_DESCRIPTION:
  1547. $link .= $main_dir_path.'course_description?origin=learnpath';
  1548. break;
  1549. case TOOL_GROUP:
  1550. $link .= $main_dir_path.'group/group.php?origin='.$origin;
  1551. break;
  1552. case TOOL_USER:
  1553. $link .= $main_dir_path.'user/user.php?origin='.$origin;
  1554. break;
  1555. case 'student_publication' :
  1556. $link .= $main_dir_path.'work/work.php?origin=learnpath';
  1557. break;
  1558. } //end switch
  1559. return $link;
  1560. }
  1561. /**
  1562. * Gets the name of a resource (generally used in learnpath when no name is provided)
  1563. *
  1564. * @author Yannick Warnier <ywarnier@beeznest.org>, Dokeos - rebranding
  1565. * @param string Course code
  1566. * @param string The tool type (using constants declared in main_api.lib.php)
  1567. * @param integer The resource ID
  1568. */
  1569. function rl_get_resource_name($course_code, $learnpath_id, $id_in_path)
  1570. {
  1571. $_course = api_get_course_info($course_code);
  1572. $course_id = $_course['real_id'];
  1573. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1574. $learnpath_id = intval($learnpath_id);
  1575. $id_in_path = intval($id_in_path);
  1576. $sql_item = "SELECT item_type, title, ref FROM $tbl_lp_item
  1577. WHERE c_id = $course_id AND lp_id = $learnpath_id AND id = $id_in_path";
  1578. $res_item = Database::query($sql_item);
  1579. if (Database::num_rows($res_item) < 1) {
  1580. return '';
  1581. }
  1582. $row_item = Database::fetch_array($res_item);
  1583. $type = strtolower($row_item['item_type']);
  1584. $id = $row_item['ref'];
  1585. $output = '';
  1586. switch ($type) {
  1587. case TOOL_CALENDAR_EVENT:
  1588. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  1589. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  1590. $myrow = Database::fetch_array($result);
  1591. $output = $myrow['title'];
  1592. break;
  1593. case TOOL_ANNOUNCEMENT:
  1594. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1595. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  1596. $myrow = Database::fetch_array($result);
  1597. $output = $myrow['title'];
  1598. break;
  1599. case TOOL_LINK:
  1600. // Doesn't take $target into account.
  1601. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  1602. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  1603. $myrow = Database::fetch_array($result);
  1604. $output = $myrow['title'];
  1605. break;
  1606. case TOOL_QUIZ:
  1607. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  1608. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND id=$id");
  1609. $myrow = Database::fetch_array($result);
  1610. $output = $myrow['title'];
  1611. break;
  1612. case TOOL_FORUM:
  1613. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  1614. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  1615. $myrow = Database::fetch_array($result);
  1616. $output = $myrow['forum_name'];
  1617. break;
  1618. case TOOL_THREAD: //=topics
  1619. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  1620. // Grabbing the title of the post.
  1621. $sql_title = "SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=".$id;
  1622. $result_title = Database::query($sql_title);
  1623. $myrow_title = Database::fetch_array($result_title);
  1624. $output = $myrow_title['post_title'];
  1625. break;
  1626. case TOOL_POST:
  1627. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  1628. //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE);
  1629. $sql = "SELECT * FROM $tbl_post p WHERE c_id = $course_id AND p.post_id = $id";
  1630. $result = Database::query($sql);
  1631. $post = Database::fetch_array($result);
  1632. $output = $post['post_title'];
  1633. break;
  1634. case 'dokeos_chapter':
  1635. $title = $row_item['title'];
  1636. if (!empty($title)) {
  1637. $output = $title;
  1638. } else {
  1639. $output = '-';
  1640. }
  1641. break;
  1642. case TOOL_DOCUMENT:
  1643. $title = $row_item['title'];
  1644. if (!empty($title)) {
  1645. $output = $title;
  1646. } else {
  1647. $output = '-';
  1648. }
  1649. break;
  1650. case 'hotpotatoes':
  1651. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  1652. $result = Database::query("SELECT * FROM $tbl_doc WHERE c_id = $course_id AND id=$id");
  1653. $myrow = Database::fetch_array($result);
  1654. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  1655. $last = count($pathname) - 1; // Making a correct name for the link.
  1656. $filename = $pathname[$last]; // Making a correct name for the link.
  1657. $image = choose_image($filename);
  1658. $ext = explode('.', $filename);
  1659. $ext = strtolower($ext[sizeof($ext) - 1]);
  1660. $myrow['path'] = rawurlencode($myrow['path']);
  1661. $in_frames = in_array($ext, array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png'));
  1662. $output = $filename;
  1663. break;
  1664. /*
  1665. case 'externallink':
  1666. $output = '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.' '.$target.'>'.$id."</a><br />\n";
  1667. break;
  1668. */
  1669. }
  1670. return stripslashes($output);
  1671. }