resourcelinker.inc.php 98 KB

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