resourcelinker.inc.php 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669
  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. * @this is still use?
  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. {
  26. $_SESSION['addedresource']='';
  27. $_SESSION['addedresourceid']='';
  28. api_session_unregister('addedresource');
  29. api_session_unregister('addedresourceid');
  30. }
  31. /**
  32. * Insert description here.
  33. */
  34. function show_folder_up()
  35. {
  36. global $folder;
  37. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  38. $level = get_levels($folder);
  39. if ($level == 1)
  40. {
  41. echo "<a href='".api_get_self()."?content=Document&amp;source_forum=".$_GET['source_forum']."&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'><img src='../img/folder_up.gif' border='0' />".get_lang('LevelUp')."</a>";
  42. }
  43. if ($level and $level != 0 and $level != 1)
  44. {
  45. $folder_up=$folder;
  46. $folder_temp=explode('/',$folder);
  47. $last=count($folder_temp)-1;
  48. unset($folder_temp[$last]);
  49. $folder_up=implode('/',$folder_temp);
  50. 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>";
  51. }
  52. }
  53. /**
  54. * Shows the documents of the document tool
  55. * @param $folder
  56. */
  57. function show_documents($folder)
  58. {
  59. global $_course;
  60. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  61. // documents are a special case: the teacher can add an invisible document (it will be viewable by the user)
  62. // other tools do not have this feature. This only counts
  63. if (is_allowed_to_edit())
  64. {
  65. $visibility="ip.visibility<>'2'";
  66. }
  67. else
  68. {
  69. $visibility="ip.visibility='1'";
  70. }
  71. $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  72. $document_table = Database::get_course_table(TABLE_DOCUMENT);
  73. $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";
  74. $result=Database::query($sql);
  75. while ($row=Database::fetch_array($result))
  76. {
  77. if (!$folder)
  78. {
  79. if (get_levels($row['path'])-1==1)
  80. {
  81. // showing the right icon
  82. if (file_or_folder($row['path']))
  83. {
  84. echo '<img src="../img/file.gif" align="middle" />';
  85. }
  86. else
  87. {
  88. $image = choose_image($row['path']);
  89. echo "<img src=\"../img/$image\" align=\"middle\" />";
  90. }
  91. // folders should be clickable
  92. if (file_or_folder($row['path']))
  93. {
  94. echo "<a href='".api_get_self()."?content=Document";
  95. 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 />';
  96. }
  97. else
  98. {
  99. echo substr($row['path'],1).' ';
  100. echo showorhide_addresourcelink('Document',$row['id']);
  101. echo '<br />';
  102. }
  103. }
  104. }
  105. else
  106. {
  107. // we calculate the level we are in by using the $folder in the url
  108. // we put +1 because it does not start with an / and in the database it does
  109. $level=get_levels($folder)+1;
  110. // we calculate each level of the database entry
  111. $file_level=get_levels($row['path'])-1;
  112. // if the level of the database entry is equal to the level we ar in, we put it into an array
  113. // as this is a potential good entry
  114. if ($file_level==$level)
  115. {
  116. $good_paths[]=$row['path'];
  117. $good_ids[]=$row['id'];
  118. }
  119. //$haystack=$row['path'];
  120. //$conform_folder=strstr($haystack, $folder);
  121. //if (str_replace($folder.'/','',$conform_folder)!==$folder)
  122. // {
  123. // $good_folders[]=$row['path'];
  124. //echo str_replace($folder.'/','',$conform_folder);
  125. // echo '<br />';
  126. // }// if (str_replace($folder.'/','',$conform_folder)!==$folder)
  127. } // else (if (!$folder))
  128. } //while ($row=Database::fetch_array($result))
  129. // this is code for the case that we are in a subfolder
  130. if ($good_paths)
  131. {
  132. // we have all the potential good database entries, the good ones are those that start with $folder
  133. foreach ($good_paths as $path)
  134. {
  135. if (strstr($path,$folder))
  136. {
  137. $good_key=key($good_paths);
  138. // showing the right icon
  139. if (file_or_folder($path))
  140. {
  141. echo '<img src="../img/file.gif" align="middle" />';
  142. }
  143. else
  144. {
  145. $image = choose_image($path);
  146. echo "<img src=\"../img/$image\" align=\"middle\" />";
  147. }
  148. // folders should be clickable
  149. if (file_or_folder($path))
  150. {
  151. $path=substr($path,1); // remove the first / in folder_up
  152. $uri=str_replace($folder,$path,$_SERVER['REQUEST_URI']);
  153. $newuri=str_replace('add=','addnot=',$uri);
  154. //using the correct name of the folder
  155. $folder_name=str_replace($folder.'/','',$path);
  156. echo "<a href='$newuri'>".$folder_name.'</a><br />';
  157. }
  158. else
  159. {
  160. echo str_replace("/$folder/", '',$path).' ';
  161. echo showorhide_addresourcelink('Document',$good_ids[$good_key]);
  162. echo '<br />';
  163. }
  164. }
  165. next($good_paths);
  166. }
  167. }
  168. }
  169. /**
  170. * Checks wether something is a file or a folder
  171. * 0 means file, 1 means folder
  172. * @param $filefolder
  173. * @todo: use true and false instead of 1 and 0.
  174. */
  175. function file_or_folder($filefolder)
  176. {
  177. global $_course;
  178. global $baseServDir;
  179. $courseDir = $_course['path'].'/document';
  180. $baseWorkDir = api_get_path(SYS_COURSE_PATH).$courseDir;
  181. return (is_dir($baseWorkDir.$filefolder) ? 1 : 0);
  182. }
  183. /**
  184. * Inserts a resource into the database
  185. *
  186. * @param $source_type
  187. * @param $source_id
  188. */
  189. function store_resources($source_type, $source_id)
  190. {
  191. global $_course;
  192. $resource_table = Database::get_course_table(TABLE_LINKED_RESOURCES);
  193. $addedresource = $_SESSION['addedresource'];
  194. $addedresourceid = $_SESSION['addedresourceid'];
  195. if ($_SESSION['addedresource'])
  196. {
  197. foreach ($addedresource as $resource_type)
  198. {
  199. $sql="INSERT INTO $resource_table (source_type, source_id, resource_type, resource_id) VALUES ('$source_type', '$source_id', '$resource_type', '".$addedresourceid[key($addedresource)]."')";
  200. Database::query($sql);
  201. $i=key($addedresource);
  202. next($addedresource);
  203. }
  204. $_SESSION['addedresource']='';
  205. $_SESSION['addedresourceid']='';
  206. }
  207. }
  208. /**
  209. * Displays the link that opens a new browser window that views the added resource.
  210. *
  211. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  212. * @param $type the type of the tool
  213. * @param $id the id of the resource
  214. * @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)
  215. * @todo use the constants for the type definitions.
  216. */
  217. function display_addedresource_link($type, $id, $style='')
  218. {
  219. global $_course;
  220. // styling the link of the added resource
  221. if ($style <> '')
  222. {
  223. $styling = ' class="'.$style.'"';
  224. }
  225. switch ($type)
  226. {
  227. case 'Agenda':
  228. $TABLEAGENDA = $_course['dbNameGlu'].'calendar_event';
  229. $result = Database::query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id");
  230. $myrow = Database::fetch_array($result);
  231. echo '<img src="../img/agenda.gif" align="middle" /> <a href="../calendar/agenda.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
  232. break;
  233. case 'Ad_Valvas':
  234. $tbl_announcement = $_course['dbNameGlu'].'announcement';
  235. $result = Database::query("SELECT * FROM `$tbl_announcement` WHERE id=$id");
  236. $myrow = Database::fetch_array($result);
  237. echo '<img src="../img/valves.gif" align="middle" /> <a href="../announcements/announcements.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
  238. break;
  239. case 'Link':
  240. $TABLETOOLLINK = $_course['dbNameGlu'].'link';
  241. $result = Database::query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id");
  242. $myrow = Database::fetch_array($result);
  243. 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";
  244. break;
  245. case 'Exercise':
  246. $TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
  247. $result = Database::query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id");
  248. $myrow = Database::fetch_array($result);
  249. echo '<img src="../img/quiz.gif" align="middle" /> <a href="../exercice/exercice_submit.php?exerciseId='.$myrow['id'].'"'.$styling.'>'.$myrow['title']."</a><br />\n";
  250. break;
  251. case 'Forum':
  252. $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums';
  253. $result = Database::query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id");
  254. $myrow = Database::fetch_array($result);
  255. 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";
  256. break;
  257. case 'Thread': //=topics
  258. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  259. $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text';
  260. $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums';
  261. $result = Database::query("SELECT * FROM `$tbl_posts` posts, `$TBL_FORUMS` forum WHERE forum.forum_id=posts.forum_id and post_id=$id");
  262. $myrow = Database::fetch_array($result);
  263. // grabbing the title of the post
  264. $sql_title = "SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"];
  265. $result_title = Database::query($sql_title);
  266. $myrow_title = Database::fetch_array($result_title);
  267. 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";
  268. break;
  269. case 'Post':
  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 = $_course['dbNameGlu'].'document';
  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 = $_course['dbNameGlu']."calendar_event";
  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 = $_course['dbNameGlu']."announcement";
  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 = $_course['dbNameGlu']."link";
  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 = $_course['dbNameGlu'].'quiz';
  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/exercice_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 = $_course['dbNameGlu'].'document';
  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 = $_course['dbNameGlu']."bb_forums";
  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('step_deleted2')."</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. $tbl_topics = $_course['dbNameGlu'].'bb_topics';
  622. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  623. $TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
  624. $sql="SELECT * FROM `$tbl_topics` where topic_id=$id";
  625. $result= Database::query($sql);
  626. $myrow=Database::fetch_array($result);
  627. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  628. $result=Database::query($sql); $row=Database::fetch_array($result);
  629. if ($row['title'] != '') { $myrow["topic_title"]=$row['title']; }
  630. $desc=$row['description'];
  631. echo str_repeat("&nbsp;&gt;",$level);
  632. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  633. if ($icon != 'nolink')
  634. {
  635. if ($completed=='completed') {
  636. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  637. } else {
  638. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  639. //echo "&nbsp;";
  640. }
  641. }
  642. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  643. if ($myrow["topic_title"]=='') { $type="Forum Post"; echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  644. if ($icon == 'nolink') { return(shorten($myrow["topic_title"],$length)); }
  645. if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
  646. if ($builder != 'builder')
  647. {
  648. 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>";
  649. $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";
  650. if ($desc != '')
  651. {
  652. if ($icon != 'wrap')
  653. {
  654. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  655. }
  656. else
  657. {
  658. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  659. }
  660. }
  661. }
  662. else
  663. {
  664. 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>";
  665. }
  666. break;
  667. case "Post":
  668. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  669. $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text';
  670. $TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
  671. $result= Database::query("SELECT * FROM `$tbl_posts` where post_id=$id");
  672. $myrow=Database::fetch_array($result);
  673. // grabbing the title of the post
  674. $sql_titel="SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"];
  675. $result_titel=Database::query($sql_titel);
  676. $myrow_titel=Database::fetch_array($result_titel);
  677. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  678. $result=Database::query($sql); $row=Database::fetch_array($result);
  679. if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; }
  680. $desc=$row['description'];
  681. echo str_repeat("&nbsp;&gt;",$level);
  682. $posternom=$myrow['nom']; $posterprenom=$myrow['prenom'];
  683. $posttime=$myrow['post_time']; $posttext=$myrow_titel['post_text'];
  684. $posttitle=$myrow_titel['post_title'];
  685. $posttext = str_replace('"',"'",$posttext);
  686. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  687. if ($icon != 'nolink')
  688. {
  689. if ($completed=='completed') {
  690. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  691. } else {
  692. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  693. //echo "&nbsp;";
  694. }
  695. }
  696. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  697. if ($myrow_titel["post_title"]=='')
  698. {
  699. $type="Forum";
  700. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true);
  701. }
  702. if ($icon == 'nolink') { return(shorten($myrow_titel["post_title"],$length)); }
  703. if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
  704. if ($builder != 'builder')
  705. {
  706. 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";
  707. if ($desc != '')
  708. {
  709. if ($icon != 'wrap')
  710. {
  711. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  712. }
  713. else
  714. {
  715. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  716. }
  717. }
  718. }
  719. else
  720. {
  721. 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>";
  722. }
  723. break;
  724. case "Document":
  725. $dbTable = $_course['dbNameGlu']."document";
  726. $result=Database::query("SELECT * FROM `$dbTable` WHERE id=$id");
  727. $myrow=Database::fetch_array($result);
  728. $pathname=explode("/",$myrow["path"]); // making a correct name for the link
  729. $last=count($pathname)-1; // making a correct name for the link
  730. $filename=$pathname[$last]; // making a correct name for the link
  731. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  732. echo str_repeat("&nbsp;&gt;",$level);
  733. if ($icon != 'nolink') {
  734. if ($completed=='completed') {
  735. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  736. } else {
  737. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  738. //echo "&nbsp;";
  739. }
  740. }
  741. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  742. $image=choose_image($filename);
  743. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  744. $result=Database::query($sql); $row=Database::fetch_array($result);
  745. if ($row['title'] != '') { $filename=$row['title']; }
  746. $desc=$row['description'];
  747. if (($myrow["path"]=='') and ($filename=='')) {
  748. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  749. return(true);
  750. }
  751. if ($icon == 'nolink') { return(shorten($filename,$length)); }
  752. if ($icon == 'icon') { echo "<img src='../img/$image' align=\"absmiddle\" alt='$image'>"; }
  753. if ($builder != 'builder')
  754. {
  755. 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>";
  756. if ($desc != '')
  757. {
  758. if ($icon != 'wrap')
  759. {
  760. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  761. }
  762. else
  763. {
  764. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  765. }
  766. } $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";
  767. }
  768. else
  769. {
  770. $enableDocumentParsing='yes';
  771. if (!$enableDocumentParsing)
  772. { //this is the solution for the non-parsing version in the builder
  773. $file=urlencode($myrow["path"]);
  774. echo "<a href='../document/showinframes.php?file=$file' class='$completed' $hyperlink_target_parameter>".shorten($filename,($length-3*$level))."</a>";
  775. }
  776. else
  777. {
  778. echo "<a href=\"../document/download.php?doc_url=".$myrow["path"]."\" class='$completed' $hyperlink_target_parameter>".shorten($filename,($length-3*$level))."</a>";
  779. }
  780. }
  781. break;
  782. case "Assignments":
  783. $name=get_lang('Assignments');
  784. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  785. $result=Database::query($sql); $row=Database::fetch_array($result);
  786. if ($row['title'] != '') { $name=$row['title']; }
  787. $desc=$row['description'];
  788. echo str_repeat("&nbsp;&gt;",$level);
  789. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  790. if ($icon != 'nolink')
  791. {
  792. if ($completed=='completed') {
  793. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  794. } else {
  795. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  796. //echo "&nbsp;";
  797. }
  798. }
  799. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  800. if ($name=='')
  801. {
  802. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true);
  803. }
  804. if ($icon == 'nolink') { return(shorten($name,$length)); }
  805. if ($icon == 'icon') { echo "<img src='../img/works.gif' align=\"absmiddle\">"; }
  806. if ($builder != 'builder')
  807. {
  808. 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";
  809. if ($desc != '')
  810. {
  811. if ($icon != 'wrap')
  812. {
  813. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  814. }
  815. else
  816. {
  817. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  818. }
  819. }
  820. }
  821. else
  822. {
  823. echo "<a href=\"../work/work.php\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  824. }
  825. break;
  826. case "Dropbox":
  827. $name=get_lang('Dropbox');
  828. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  829. $result=Database::query($sql); $row=Database::fetch_array($result);
  830. if ($row['title'] != '') { $name=$row['title']; }
  831. $desc=$row['description'];
  832. echo str_repeat("&nbsp;&gt;",$level);
  833. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  834. if ($icon != 'nolink') {
  835. if ($completed=='completed') {
  836. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  837. } else {
  838. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  839. //echo "&nbsp;";
  840. }
  841. }
  842. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  843. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  844. if ($icon == 'nolink') { return(shorten($name,$length)); }
  845. if ($icon == 'icon') { echo "<img src='../img/dropbox.gif' align=\"absmiddle\">"; }
  846. if ($builder != 'builder')
  847. {
  848. 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";
  849. if ($desc != '') {
  850. if ($icon != 'wrap') {
  851. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
  852. else {
  853. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
  854. }
  855. } else {
  856. echo "<a href=\"../dropbox/index.php\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  857. }
  858. break;
  859. case "Introduction_text":
  860. $name=get_lang('IntroductionText');
  861. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  862. $result=Database::query($sql); $row=Database::fetch_array($result);
  863. if ($row['title'] != '') { $name=$row['title']; }
  864. $desc=$row['description'];
  865. echo str_repeat("&nbsp;&gt;",$level);
  866. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  867. if ($icon != 'nolink') {
  868. if ($completed=='completed') {
  869. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  870. } else {
  871. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  872. //echo "&nbsp;";
  873. }
  874. }
  875. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  876. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  877. if ($icon == 'nolink') { return(shorten($name,$length)); }
  878. if ($icon == 'icon') { echo "<img src='../img/introduction.gif' align=\"absmiddle\" alt='introduction'>"; }
  879. if ($builder != 'builder')
  880. {
  881. 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>";
  882. $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";
  883. if ($desc != '') {
  884. if ($icon != 'wrap') {
  885. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
  886. else {
  887. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
  888. }
  889. } else {
  890. $s = api_get_path(WEB_COURSE_PATH)."$_cid/index.php?intro_cmdEdit=1";
  891. echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  892. }
  893. break;
  894. case "Course_description":
  895. $name=get_lang('CourseDescription');
  896. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  897. $result=Database::query($sql); $row=Database::fetch_array($result);
  898. if ($row['title'] != '') { $name=$row['title']; }
  899. $desc=$row['description'];
  900. echo str_repeat("&nbsp;&gt;",$level);
  901. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  902. if ($icon != 'nolink') {
  903. if ($completed=='completed') {
  904. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  905. } else {
  906. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  907. //echo "&nbsp;";
  908. }
  909. }
  910. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  911. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  912. if ($icon == 'nolink') { return(shorten($name,$length)); }
  913. if ($icon == 'icon') { echo "<img src='../img/info.gif' align=\"absmiddle\" alt='info'>"; }
  914. if ($builder != 'builder')
  915. {
  916. 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";
  917. if ($desc != '') {
  918. if ($icon != 'wrap') {
  919. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
  920. else {
  921. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
  922. }
  923. } else {
  924. $s=api_get_path(WEB_CODE_PATH)."course_description";
  925. echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  926. }
  927. break;
  928. case "Groups":
  929. $name=get_lang('Groups');
  930. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  931. $result=Database::query($sql); $row=Database::fetch_array($result);
  932. if ($row['title'] != '') { $name=$row['title']; }
  933. $desc=$row['description'];
  934. echo str_repeat("&nbsp;&gt;",$level);
  935. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  936. if ($icon != 'nolink') {
  937. if ($completed=='completed') {
  938. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  939. } else {
  940. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  941. //echo "&nbsp;";
  942. }
  943. }
  944. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  945. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  946. if ($icon == 'nolink') { return(shorten($name,$length)); }
  947. if ($icon == 'icon') { echo "<img src='../img/group.gif' align=\"absmiddle\" alt='group'>"; }
  948. if ($builder != 'builder')
  949. {
  950. 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";
  951. if ($desc != '') {
  952. if ($icon != 'wrap') {
  953. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
  954. else {
  955. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
  956. }
  957. } else {
  958. echo "<a href=\"../group/group.php?origin=$origin\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  959. }
  960. break;
  961. case "Users":
  962. $name=get_lang('Users');
  963. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  964. $result=Database::query($sql); $row=Database::fetch_array($result);
  965. if ($row['title'] != '') { $name=$row['title']; }
  966. $desc=$row['description'];
  967. echo str_repeat("&nbsp;&gt;",$level);
  968. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  969. if ($icon != 'nolink') {
  970. if ($completed=='completed') {
  971. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  972. } else {
  973. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  974. //echo "&nbsp;";
  975. }
  976. }
  977. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  978. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  979. if ($icon == 'nolink') { return(shorten($name,$length)); }
  980. if ($icon == 'icon') { echo "<img src='../img/members.gif' align=\"absmiddle\" alt='members'>"; }
  981. if ($builder != 'builder')
  982. {
  983. 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";
  984. if ($desc != '') {
  985. if ($icon != 'wrap') {
  986. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
  987. else {
  988. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
  989. }
  990. } else {
  991. echo "<a href=\"../user/user.php?origin=$origin\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  992. }
  993. break;
  994. }//end huge switch-statement
  995. }
  996. /**
  997. * This function is to create and return a link to the added resources (lessons).
  998. * It returns the same thing as display_addedresource_link_in_learnpath() but doesn't display
  999. * anything.
  1000. *
  1001. * Parameters:
  1002. * @param type - that is the correspondent type in the mirror tool (like this is a Link item)
  1003. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  1004. * @param id_in_path - the unique index in the items table
  1005. */
  1006. function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
  1007. {
  1008. global $_course, $learnpath_id, $tbl_learnpath_item, $items;
  1009. global $curDirPath, $_configuration, $enableDocumentParsing, $_user , $_cid;
  1010. $hyperlink_target_parameter = ""; //or e.g. target='_blank'
  1011. $builder = 'player';
  1012. $origin='learnpath';
  1013. $linktype=$type;
  1014. if (($type=="Link _self") or ($type=="Link _blank")) { $type="Link"; }
  1015. $link = '';
  1016. switch ($type)
  1017. {
  1018. case "Agenda":
  1019. $TABLEAGENDA = $_course['dbNameGlu']."calendar_event";
  1020. $result = Database::query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id");
  1021. $myrow=Database::fetch_array($result);
  1022. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  1023. $result=Database::query($sql); $row=Database::fetch_array($result);
  1024. if ($row['title'] != '') { $myrow["title"]=$row['title']; }
  1025. $desc=$row['description'];
  1026. $agenda_id=$row['item_id'];
  1027. if ($builder != 'builder')
  1028. {
  1029. $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";
  1030. }
  1031. else
  1032. {
  1033. $link .= "../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id";
  1034. }
  1035. break;
  1036. case "Ad_Valvas":
  1037. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1038. $result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id");
  1039. $myrow=Database::fetch_array($result);
  1040. if ($builder != 'builder')
  1041. {
  1042. $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";
  1043. }
  1044. else
  1045. {
  1046. $link .= "../announcements/announcements.php?origin=$origin&ann_id=$id";
  1047. }
  1048. break;
  1049. case "Link" :
  1050. $TABLETOOLLINK = $_course['dbNameGlu']."link";
  1051. $result= Database::query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id");
  1052. $myrow=Database::fetch_array($result);
  1053. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  1054. $result=Database::query($sql); $row=Database::fetch_array($result);
  1055. $thelink=$myrow["url"];
  1056. if ($builder != 'builder')
  1057. {
  1058. $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";
  1059. }
  1060. else
  1061. {
  1062. $link .= $thelink;
  1063. }
  1064. break;
  1065. case "Exercise":
  1066. $TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
  1067. $result= Database::query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id");
  1068. $myrow=Database::fetch_array($result);
  1069. if ($builder=='builder') { $origin='builder'; }
  1070. //this is needed for the exercise_submit.php can delete the session info about tests
  1071. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  1072. $result=Database::query($sql); $row=Database::fetch_array($result);
  1073. if ($row['title'] != '') { $myrow["title"]=$row['title']; }
  1074. if ($builder != 'builder')
  1075. {
  1076. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path";
  1077. }
  1078. else
  1079. {
  1080. $link .= "../exercice/exercice_submit.php?origin=$origin&exerciseId=".$myrow["id"];
  1081. }
  1082. break;
  1083. case "HotPotatoes":
  1084. $TBL_DOCUMENT = $_course['dbNameGlu'].'document';
  1085. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  1086. $result = Database::query("SELECT * FROM `".$TBL_DOCUMENT."` WHERE id=$id");
  1087. $myrow= Database::fetch_array($result);
  1088. $path=$myrow["path"];
  1089. $name=GetQuizName($path,$documentPath);
  1090. if ($builder=='builder') { $origin='builder'; }
  1091. $cid = $_course['official_code'];
  1092. if ($builder != 'builder')
  1093. {
  1094. $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";
  1095. }
  1096. else
  1097. {
  1098. $link .= "../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id']."";
  1099. }
  1100. break;
  1101. case "Forum":
  1102. $TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
  1103. $result= Database::query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id");
  1104. $myrow=Database::fetch_array($result);
  1105. if ($builder=='builder') { $origin='builder'; }
  1106. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  1107. $result=Database::query($sql); $row=Database::fetch_array($result);
  1108. if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; }
  1109. if ($myrow["forum_name"]=='') { $type="Forum"; }
  1110. $forumparameters="forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1111. if ($builder != 'builder')
  1112. {
  1113. $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";
  1114. }
  1115. else
  1116. {
  1117. $link .= "../phpbb/viewforum.php?$forumparameters";
  1118. }
  1119. break;
  1120. case "Thread": //forum post
  1121. $tbl_topics = $_course['dbNameGlu'].'bb_topics';
  1122. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  1123. $TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
  1124. $sql="SELECT * FROM `$tbl_topics` where topic_id=$id";
  1125. $result= Database::query($sql);
  1126. $myrow=Database::fetch_array($result);
  1127. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  1128. $result=Database::query($sql); $row=Database::fetch_array($result);
  1129. if ($builder != 'builder')
  1130. {
  1131. $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";
  1132. }
  1133. else
  1134. {
  1135. $link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1136. }
  1137. break;
  1138. case "Post":
  1139. /* todo REVIEW THIS SECTION - NOT USING VALID TABLES ANYMORE
  1140. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  1141. $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text';
  1142. $TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
  1143. $result= Database::query("SELECT * FROM `$tbl_posts` where post_id=$id");
  1144. $myrow=Database::fetch_array($result);
  1145. // grabbing the title of the post
  1146. $sql_titel="SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"];
  1147. $result_titel=Database::query($sql_titel);
  1148. $myrow_titel=Database::fetch_array($result_titel);
  1149. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  1150. $result=Database::query($sql); $row=Database::fetch_array($result);
  1151. if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; }
  1152. $desc=$row['description'];
  1153. $link .= str_repeat("&nbsp;&gt;",$level);
  1154. $posternom=$myrow['nom']; $posterprenom=$myrow['prenom'];
  1155. $posttime=$myrow['post_time']; $posttext=$myrow_titel['post_text'];
  1156. $posttitle=$myrow_titel['post_title'];
  1157. $posttext = str_replace('"',"'",$posttext);
  1158. if ($builder != 'builder')
  1159. {
  1160. $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";
  1161. }
  1162. else
  1163. {
  1164. $link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1165. }
  1166. */
  1167. break;
  1168. case "Document":
  1169. $dbTable = $_course['dbNameGlu']."document";
  1170. $result=Database::query("SELECT * FROM `$dbTable` WHERE id=$id",__FILE__,__LINE);
  1171. $myrow=Database::fetch_array($result);
  1172. $pathname=explode("/",$myrow["path"]); // making a correct name for the link
  1173. $last=count($pathname)-1; // making a correct name for the link
  1174. $filename=$pathname[$last]; // making a correct name for the link
  1175. $sql="select * from $tbl_learnpath_item where id=$id_in_path";
  1176. $result=Database::query($sql); $row=Database::fetch_array($result);
  1177. if ($builder != 'builder')
  1178. {
  1179. $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";
  1180. }
  1181. else
  1182. {
  1183. $enableDocumentParsing='yes';
  1184. if (!$enableDocumentParsing)
  1185. { //this is the solution for the non-parsing version in the builder
  1186. $file=urlencode($myrow["path"]);
  1187. $link .= "../document/showinframes.php?file=$file";
  1188. }
  1189. else
  1190. {
  1191. $link .= "../document/download.php?doc_url=".$myrow["path"];
  1192. }
  1193. }
  1194. break;
  1195. case "Assignments":
  1196. if ($builder != 'builder')
  1197. {
  1198. $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";
  1199. }
  1200. else
  1201. {
  1202. $link .= "../work/work.php";
  1203. }
  1204. break;
  1205. case "Dropbox":
  1206. if ($builder != 'builder')
  1207. {
  1208. $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";
  1209. } else {
  1210. $link .= "../dropbox/index.php";
  1211. }
  1212. break;
  1213. case "Introduction_text":
  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=Introduction_text&origin=$origin#$id_in_path";
  1217. } else {
  1218. $s = api_get_path(WEB_COURSE_PATH)."$_cid/index.php?intro_cmdEdit=1";
  1219. $link .= $s;
  1220. }
  1221. break;
  1222. case "Course_description":
  1223. if ($builder != 'builder')
  1224. {
  1225. $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";
  1226. } else {
  1227. $s=api_get_path(WEB_CODE_PATH)."course_description";
  1228. $link .= $s;
  1229. }
  1230. break;
  1231. case "Groups":
  1232. if ($builder != 'builder')
  1233. {
  1234. $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";
  1235. } else {
  1236. $link .= "../group/group.php?origin=$origin";
  1237. }
  1238. break;
  1239. case "Users":
  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=Users&origin=$origin#$id_in_path";
  1243. } else {
  1244. $link .= "../user/user.php?origin=$origin";
  1245. }
  1246. break;
  1247. }//end huge switch-statement
  1248. return $link;
  1249. }
  1250. /**
  1251. * This function is to remove an resource item from the array
  1252. */
  1253. function remove_resource($resource_key)
  1254. {
  1255. $addedresource = $_SESSION['addedresource'];
  1256. $addedresourceid = $_SESSION['addedresourceid'];
  1257. unset($addedresource[$resource_key]);
  1258. unset($addedresourceid[$resource_key]);
  1259. $_SESSION['addedresource']=$addedresource;
  1260. $_SESSION['addedresourceid']=$addedresourceid ;
  1261. }
  1262. /**
  1263. * This function is to show the button "click to add resource" on the tool page
  1264. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1265. */
  1266. function show_addresource_button($additionalparameters = '')
  1267. {
  1268. global $charset;
  1269. 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.' />';
  1270. }
  1271. /**
  1272. * this function is to delete ONE specific resource that were added to a specific item
  1273. * Deprecated
  1274. *//*
  1275. function delete_one_added_resource($source_type, $source_id, $resource_type, $resource_id)
  1276. {
  1277. //echo "delete_one_added_resource";
  1278. global $_course;
  1279. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1280. $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$source_type' and source_id='$source_id' and resource_type='$resource_type' and resource_id='$resource_id'";
  1281. Database::query($sql);
  1282. }
  1283. */
  1284. /**
  1285. * this function is to delete the resources that were added to a specific item
  1286. */
  1287. function delete_added_resource($type, $id)
  1288. {
  1289. global $_course;
  1290. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1291. $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'";
  1292. Database::query($sql);
  1293. }
  1294. /**
  1295. * this function is te delete all resources of a specific type (only used in announcements -- delete all)
  1296. * Author : Frederik Vermeire <frederik.vermeire@pandora.be>
  1297. */
  1298. function delete_all_resources_type($type)
  1299. {
  1300. global $_course;
  1301. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1302. $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$type'";
  1303. Database::query($sql);
  1304. }
  1305. /**
  1306. * this function checks wether there are added resources or not
  1307. */
  1308. function check_added_resources($type, $id)
  1309. {
  1310. global $_course, $origin;
  1311. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1312. $sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'";
  1313. $result=Database::query($sql);
  1314. $number_added=Database::num_rows($result);
  1315. if ($number_added<>0)
  1316. return true;
  1317. else
  1318. return false;
  1319. }
  1320. /**
  1321. * this function is to load the resources that were added to a specific item
  1322. * into the session variables
  1323. */
  1324. function edit_added_resources($type, $id)
  1325. {
  1326. global $_course;
  1327. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1328. $sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id=$id";
  1329. $result=Database::query($sql);
  1330. while ($row=Database::fetch_array($result))
  1331. {
  1332. $addedresource[]=$row["resource_type"];
  1333. $addedresourceid[]=$row["resource_id"];
  1334. }
  1335. $_SESSION['addedresource']=$addedresource;
  1336. $_SESSION['addedresourceid']=$addedresourceid;
  1337. }
  1338. /**
  1339. * this function is store the modified resources
  1340. * first we delete all the added resources in the database,
  1341. * then we add all the resources from the session object.
  1342. */
  1343. function update_added_resources($type, $id)
  1344. {
  1345. global $_course;
  1346. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1347. // delete all the added resources for this item in the database;
  1348. $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$type' AND source_id='$id'";
  1349. //echo $sql;
  1350. Database::query($sql);
  1351. // store the resources from the session into the database
  1352. store_resources($type, $id);
  1353. //delete_added_resource_($type, $id);
  1354. unset_session_resources();
  1355. }
  1356. /**
  1357. * this function is to display the resources that were added to a specific item
  1358. */
  1359. function display_added_resources($type, $id, $style='')
  1360. {
  1361. // the array containing the icons
  1362. $arr_icons=array('Agenda'=>'../img/agenda.gif', 'Ad Valvas'=>'../img/valves.gif', 'Link'=>'../img/links.gif', 'Exercise'=>'../img/quiz.gif' );
  1363. global $_course, $origin;
  1364. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1365. $sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'";
  1366. $result=Database::query($sql);
  1367. while ($row=Database::fetch_array($result))
  1368. {
  1369. if ($origin != 'learnpath')
  1370. {
  1371. display_addedresource_link($row['resource_type'], $row['resource_id'], $style) ;
  1372. }
  1373. else
  1374. {
  1375. display_addedresource_link_in_learnpath($row['resource_type'], $row['resource_id'],'agendaitems','','builder','icon') ; echo "<br>";
  1376. }
  1377. }
  1378. }
  1379. /**
  1380. * This function is to show the added resources when adding an item
  1381. * $showdeleteimg determine if the delete image should appear or not.
  1382. * deleting an added resource is only possible through the resource linker file itself
  1383. */
  1384. function display_resources($showdeleteimg)
  1385. {
  1386. global $action;
  1387. global $resourceaction;
  1388. global $id;
  1389. global $locationkey;
  1390. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  1391. if ($resourceaction=="removeresource")
  1392. {
  1393. /* unneccessary because when editing we delete all the added resources from the
  1394. database and add all these from the session
  1395. if ($action=="edit") // we have an edit and thus we delete from the database and from the session
  1396. {
  1397. echo "remove from database";
  1398. echo $_SESSION['source_type']."/";
  1399. echo $id."/";
  1400. $addedresource=$_SESSION['addedresource'];
  1401. $addedresourceid=$_SESSION['addedresourceid'];
  1402. echo $addedresource[$key]."/";
  1403. echo $addedresourceid[$key]."/";
  1404. delete_one_added_resource($_SESSION['source_type'],$id,$addedresource[$key],$addedresourceid[$key]);
  1405. remove_resource($key);
  1406. }
  1407. else // we remove from the session
  1408. {*/
  1409. //echo "remove from session";
  1410. remove_resource($locationkey);
  1411. }
  1412. $addedresource=$_SESSION['addedresource'];
  1413. $addedresourceid=$_SESSION['addedresourceid'];
  1414. if (is_array($addedresource))
  1415. {
  1416. echo '<table>';
  1417. foreach ($addedresource as $resource)
  1418. {
  1419. //echo $resource.":".$addedresourceid[key($addedresource)];
  1420. echo '<tr><td>';
  1421. display_addedresource_link($resource,$addedresourceid[key($addedresource)]);
  1422. echo '</td><td width="30">';
  1423. // if $_SERVER['REQUEST_URI'] contains and ?id=xx we have an edit and the url for deleting a session added resource
  1424. // should also contain this id.
  1425. $test=parse_url($_SERVER['REQUEST_URI']);
  1426. $output = array();
  1427. parse_str($test['query'],$output);
  1428. if ($showdeleteimg==1)
  1429. {
  1430. //if (strstr($_SERVER['REQUEST_URI'],"?id="))
  1431. // { echo " <a href='".api_get_self()."?id=".$output['id']."&amp;"; }
  1432. //else
  1433. // { echo " <a href='".api_get_self()."?"; }
  1434. //action=$action&id=$id&
  1435. //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 />";
  1436. 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 />";
  1437. }
  1438. echo '</td></tr>';
  1439. next($addedresource);
  1440. //$_SESSION['edit']=='';
  1441. }
  1442. echo '</table>';
  1443. }
  1444. else // it is a string
  1445. {
  1446. echo '';
  1447. }
  1448. } // end of the display_resources function
  1449. /**
  1450. * This function checks wether the link add resource should be displayed next the item in the linker page
  1451. * So we have to check if the specific id of that tool is already in the array of the added resources
  1452. * if it is already in, the link should not be showed since it would make it possible to add
  1453. * the same resource a second time (=duplication of added resources)
  1454. */
  1455. function showorhide_addresourcelink($type, $id)
  1456. {
  1457. global $from_learnpath, $source_id, $action, $learnpath_id, $chapter_id, $originalresource, $folder, $content, $target;
  1458. //global $_SESSION['addresource'];
  1459. //global $_SESSION['addresourceid'];
  1460. $addedresource=$_SESSION['addedresource'];
  1461. $addedresourceid=$_SESSION['addedresourceid'];
  1462. if (is_array($_SESSION['addedresource']))
  1463. {
  1464. foreach ($addedresource as $toolcompare)
  1465. {
  1466. //echo $toolcompare;
  1467. //echo "/".$type."/".$id."****";
  1468. //$key=key($addedresource);
  1469. //echo $addedresourceid[$key];
  1470. //print_r($addedresourceid);
  1471. //echo "<br>";
  1472. if ($toolcompare==$type and $addedresourceid[key($addedresource)]==$id)
  1473. {
  1474. $show=0;
  1475. }
  1476. next($addedresource);
  1477. }
  1478. if ($from_learnpath) { $lang_add_it_or_resource=get_lang('AddIt'); } else { $lang_add_it_or_resource=get_lang('AddResource'); }
  1479. if ($show!==0)
  1480. {
  1481. if ($type=="Document")
  1482. {
  1483. 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>";
  1484. }
  1485. else
  1486. {
  1487. 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>";
  1488. }
  1489. }
  1490. }
  1491. else // if it is not an array, it is a string
  1492. {
  1493. if ($_SESSION['addedresource']!==$type or $_SESSION['addedresourceid']!==$id)
  1494. {
  1495. if ($from_learnpath) { $lang_add_it_or_resource=get_lang('AddIt'); } else { $lang_add_it_or_resource=get_lang('AddResource'); }
  1496. 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>";
  1497. }
  1498. }
  1499. }
  1500. ?>