resourcelinker.inc.php 97 KB

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