resourcelinker.inc.php 71 KB

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