resourcelinker.inc.php 71 KB

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