resourcelinker.inc.php 71 KB

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