resourcelinker.inc.php 99 KB

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