resourcelinker.inc.php 71 KB

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