resourcelinker.inc.php 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679
  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. // 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. $_SESSION['addedresource']='';
  27. $_SESSION['addedresourceid']='';
  28. Session::erase('addedresource');
  29. Session::erase('addedresourceid');
  30. }
  31. /**
  32. * Insert description here.
  33. */
  34. function show_folder_up()
  35. {
  36. global $folder;
  37. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  38. $level = get_levels($folder);
  39. if ($level == 1)
  40. {
  41. echo "<a href='".api_get_self()."?content=Document&amp;source_forum=".$_GET['source_forum']."&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'><img src='../img/folder_up.gif' border='0' />".get_lang('LevelUp')."</a>";
  42. }
  43. if ($level and $level != 0 and $level != 1)
  44. {
  45. $folder_up=$folder;
  46. $folder_temp=explode('/',$folder);
  47. $last=count($folder_temp)-1;
  48. unset($folder_temp[$last]);
  49. $folder_up=implode('/',$folder_temp);
  50. echo "<a href='".api_get_self()."?content=Document&amp;source_forum=".$_GET['source_forum']."&amp;folder=$folder_up&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'><img src='../img/folder_up.gif' border='0' />".get_lang('LevelUp')."</a>";
  51. }
  52. }
  53. /**
  54. * Shows the documents of the document tool
  55. * @param $folder
  56. */
  57. function show_documents($folder)
  58. {
  59. global $_course;
  60. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  61. // documents are a special case: the teacher can add an invisible document (it will be viewable by the user)
  62. // other tools do not have this feature. This only counts
  63. if (api_is_allowed_to_edit())
  64. {
  65. $visibility="ip.visibility<>'2'";
  66. }
  67. else
  68. {
  69. $visibility="ip.visibility='1'";
  70. }
  71. $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  72. $document_table = Database::get_course_table(TABLE_DOCUMENT);
  73. $sql="SELECT * from $document_table docs, $item_property_table ip WHERE docs.id=ip.ref AND ip.tool = '".TOOL_DOCUMENT."' AND $visibility AND ip.to_group_id = 0 AND ip.to_user_id IS NULL ORDER BY docs.path ASC";
  74. $result=Database::query($sql);
  75. while ($row=Database::fetch_array($result))
  76. {
  77. if (!$folder)
  78. {
  79. if (get_levels($row['path'])-1==1)
  80. {
  81. // showing the right icon
  82. if (file_or_folder($row['path']))
  83. {
  84. echo '<img src="../img/file.gif" align="middle" />';
  85. }
  86. else
  87. {
  88. $image = choose_image($row['path']);
  89. echo "<img src=\"../img/$image\" align=\"middle\" />";
  90. }
  91. // folders should be clickable
  92. if (file_or_folder($row['path']))
  93. {
  94. echo "<a href='".api_get_self()."?content=Document";
  95. echo "&amp;folder=".substr($row['path'],1)."&amp;source_id=$source_id&amp;source_forum=".$_GET['source_forum']."&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'>".substr($row['path'],1).'</a><br />';
  96. }
  97. else
  98. {
  99. echo substr($row['path'],1).' ';
  100. echo showorhide_addresourcelink('Document',$row['id']);
  101. echo '<br />';
  102. }
  103. }
  104. }
  105. else
  106. {
  107. // we calculate the level we are in by using the $folder in the url
  108. // we put +1 because it does not start with an / and in the database it does
  109. $level=get_levels($folder)+1;
  110. // we calculate each level of the database entry
  111. $file_level=get_levels($row['path'])-1;
  112. // if the level of the database entry is equal to the level we ar in, we put it into an array
  113. // as this is a potential good entry
  114. if ($file_level==$level)
  115. {
  116. $good_paths[]=$row['path'];
  117. $good_ids[]=$row['id'];
  118. }
  119. //$haystack=$row['path'];
  120. //$conform_folder=strstr($haystack, $folder);
  121. //if (str_replace($folder.'/','',$conform_folder)!==$folder)
  122. // {
  123. // $good_folders[]=$row['path'];
  124. //echo str_replace($folder.'/','',$conform_folder);
  125. // echo '<br />';
  126. // }// if (str_replace($folder.'/','',$conform_folder)!==$folder)
  127. } // else (if (!$folder))
  128. } //while ($row=Database::fetch_array($result))
  129. // this is code for the case that we are in a subfolder
  130. if ($good_paths)
  131. {
  132. // we have all the potential good database entries, the good ones are those that start with $folder
  133. foreach ($good_paths as $path)
  134. {
  135. if (strstr($path,$folder))
  136. {
  137. $good_key=key($good_paths);
  138. // showing the right icon
  139. if (file_or_folder($path))
  140. {
  141. echo '<img src="../img/file.gif" align="middle" />';
  142. }
  143. else
  144. {
  145. $image = choose_image($path);
  146. echo "<img src=\"../img/$image\" align=\"middle\" />";
  147. }
  148. // folders should be clickable
  149. if (file_or_folder($path))
  150. {
  151. $path=substr($path,1); // remove the first / in folder_up
  152. $uri=str_replace($folder,$path,$_SERVER['REQUEST_URI']);
  153. $newuri=str_replace('add=','addnot=',$uri);
  154. //using the correct name of the folder
  155. $folder_name=str_replace($folder.'/','',$path);
  156. echo "<a href='$newuri'>".$folder_name.'</a><br />';
  157. }
  158. else
  159. {
  160. echo str_replace("/$folder/", '',$path).' ';
  161. echo showorhide_addresourcelink('Document',$good_ids[$good_key]);
  162. echo '<br />';
  163. }
  164. }
  165. next($good_paths);
  166. }
  167. }
  168. }
  169. /**
  170. * Checks wether something is a file or a folder
  171. * 0 means file, 1 means folder
  172. * @param $filefolder
  173. * @todo use true and false instead of 1 and 0.
  174. */
  175. function file_or_folder($filefolder)
  176. {
  177. global $_course;
  178. global $baseServDir;
  179. $courseDir = $_course['path'].'/document';
  180. $baseWorkDir = api_get_path(SYS_COURSE_PATH).$courseDir;
  181. return (is_dir($baseWorkDir.$filefolder) ? 1 : 0);
  182. }
  183. /**
  184. * Inserts a resource into the database
  185. *
  186. * @param $source_type
  187. * @param $source_id
  188. */
  189. function store_resources($source_type, $source_id)
  190. {
  191. global $_course;
  192. $resource_table = Database::get_course_table(TABLE_LINKED_RESOURCES);
  193. $addedresource = $_SESSION['addedresource'];
  194. $addedresourceid = $_SESSION['addedresourceid'];
  195. if ($_SESSION['addedresource'])
  196. {
  197. foreach ($addedresource as $resource_type)
  198. {
  199. $sql="INSERT INTO $resource_table (source_type, source_id, resource_type, resource_id) VALUES ('$source_type', '$source_id', '$resource_type', '".$addedresourceid[key($addedresource)]."')";
  200. Database::query($sql);
  201. $i=key($addedresource);
  202. next($addedresource);
  203. }
  204. $_SESSION['addedresource']='';
  205. $_SESSION['addedresourceid']='';
  206. }
  207. }
  208. /**
  209. * Displays the link that opens a new browser window that views the added resource.
  210. *
  211. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  212. * @param $type the type of the tool
  213. * @param $id the id of the resource
  214. * @param $style this is used to style the link (for instance when a resource is hidden => the added resources should also be styled like they are hidden)
  215. * @todo use the constants for the type definitions.
  216. */
  217. function display_addedresource_link($type, $id, $style='')
  218. {
  219. global $_course;
  220. // styling the link of the added resource
  221. if ($style <> '')
  222. {
  223. $styling = ' class="'.$style.'"';
  224. }
  225. $course_id = api_get_course_int_id();
  226. switch ($type)
  227. {
  228. case 'Agenda':
  229. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  230. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND 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);
  236. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND 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);
  241. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND 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);
  247. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND 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);
  253. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND 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);
  281. $result = Database::query("SELECT * FROM $dbTable WHERE c_id = $course_id AND 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. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1333. $course_id = api_get_course_int_id();
  1334. $id = intval($id);
  1335. $type = Database::escape_string($type);
  1336. $sql="SELECT * FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' and source_id=$id";
  1337. $result=Database::query($sql);
  1338. while ($row=Database::fetch_array($result)) {
  1339. $addedresource[]=$row["resource_type"];
  1340. $addedresourceid[]=$row["resource_id"];
  1341. }
  1342. $_SESSION['addedresource']=$addedresource;
  1343. $_SESSION['addedresourceid']=$addedresourceid;
  1344. }
  1345. /**
  1346. * this function is store the modified resources
  1347. * first we delete all the added resources in the database,
  1348. * then we add all the resources from the session object.
  1349. */
  1350. function update_added_resources($type, $id)
  1351. {
  1352. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1353. $course_id = api_get_course_int_id();
  1354. $id = intval($id);
  1355. $type = Database::escape_string($type);
  1356. // delete all the added resources for this item in the database;
  1357. $sql="DELETE FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' AND source_id='$id'";
  1358. //echo $sql;
  1359. Database::query($sql);
  1360. // store the resources from the session into the database
  1361. store_resources($type, $id);
  1362. //delete_added_resource_($type, $id);
  1363. unset_session_resources();
  1364. }
  1365. /**
  1366. * this function is to display the resources that were added to a specific item
  1367. */
  1368. function display_added_resources($type, $id, $style='')
  1369. {
  1370. // the array containing the icons
  1371. $arr_icons=array('Agenda'=>'../img/agenda.gif', 'Ad Valvas'=>'../img/valves.gif', 'Link'=>'../img/links.gif', 'Exercise'=>'../img/quiz.gif' );
  1372. global $_course, $origin;
  1373. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES,$_course['dbName']);
  1374. $sql="SELECT * FROM $TABLERESOURCE WHERE source_type='$type' and source_id='$id'";
  1375. $result=Database::query($sql);
  1376. while ($row=Database::fetch_array($result))
  1377. {
  1378. if ($origin != 'learnpath')
  1379. {
  1380. display_addedresource_link($row['resource_type'], $row['resource_id'], $style) ;
  1381. }
  1382. else
  1383. {
  1384. display_addedresource_link_in_learnpath($row['resource_type'], $row['resource_id'],'agendaitems','','builder','icon') ; echo "<br>";
  1385. }
  1386. }
  1387. }
  1388. /**
  1389. * This function is to show the added resources when adding an item
  1390. * $showdeleteimg determine if the delete image should appear or not.
  1391. * deleting an added resource is only possible through the resource linker file itself
  1392. */
  1393. function display_resources($showdeleteimg)
  1394. {
  1395. global $action;
  1396. global $resourceaction;
  1397. global $id;
  1398. global $locationkey;
  1399. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  1400. if ($resourceaction=="removeresource")
  1401. {
  1402. /* unneccessary because when editing we delete all the added resources from the
  1403. database and add all these from the session
  1404. if ($action=="edit") // we have an edit and thus we delete from the database and from the session
  1405. {
  1406. echo "remove from database";
  1407. echo $_SESSION['source_type']."/";
  1408. echo $id."/";
  1409. $addedresource=$_SESSION['addedresource'];
  1410. $addedresourceid=$_SESSION['addedresourceid'];
  1411. echo $addedresource[$key]."/";
  1412. echo $addedresourceid[$key]."/";
  1413. delete_one_added_resource($_SESSION['source_type'],$id,$addedresource[$key],$addedresourceid[$key]);
  1414. remove_resource($key);
  1415. }
  1416. else // we remove from the session
  1417. {*/
  1418. //echo "remove from session";
  1419. remove_resource($locationkey);
  1420. }
  1421. $addedresource=$_SESSION['addedresource'];
  1422. $addedresourceid=$_SESSION['addedresourceid'];
  1423. if (is_array($addedresource))
  1424. {
  1425. echo '<table>';
  1426. foreach ($addedresource as $resource)
  1427. {
  1428. //echo $resource.":".$addedresourceid[key($addedresource)];
  1429. echo '<tr><td>';
  1430. display_addedresource_link($resource,$addedresourceid[key($addedresource)]);
  1431. echo '</td><td width="30">';
  1432. // if $_SERVER['REQUEST_URI'] contains and ?id=xx we have an edit and the url for deleting a session added resource
  1433. // should also contain this id.
  1434. $test=parse_url($_SERVER['REQUEST_URI']);
  1435. $output = array();
  1436. parse_str($test['query'],$output);
  1437. if ($showdeleteimg==1)
  1438. {
  1439. //if (strstr($_SERVER['REQUEST_URI'],"?id="))
  1440. // { echo " <a href='".api_get_self()."?id=".$output['id']."&amp;"; }
  1441. //else
  1442. // { echo " <a href='".api_get_self()."?"; }
  1443. //action=$action&id=$id&
  1444. //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 />";
  1445. 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 />";
  1446. }
  1447. echo '</td></tr>';
  1448. next($addedresource);
  1449. //$_SESSION['edit']=='';
  1450. }
  1451. echo '</table>';
  1452. }
  1453. else // it is a string
  1454. {
  1455. echo '';
  1456. }
  1457. } // end of the display_resources function
  1458. /**
  1459. * This function checks wether the link add resource should be displayed next the item in the linker page
  1460. * So we have to check if the specific id of that tool is already in the array of the added resources
  1461. * if it is already in, the link should not be showed since it would make it possible to add
  1462. * the same resource a second time (=duplication of added resources)
  1463. */
  1464. function showorhide_addresourcelink($type, $id)
  1465. {
  1466. global $from_learnpath, $source_id, $action, $learnpath_id, $chapter_id, $originalresource, $folder, $content, $target;
  1467. //global $_SESSION['addresource'];
  1468. //global $_SESSION['addresourceid'];
  1469. $addedresource=$_SESSION['addedresource'];
  1470. $addedresourceid=$_SESSION['addedresourceid'];
  1471. if (is_array($_SESSION['addedresource']))
  1472. {
  1473. foreach ($addedresource as $toolcompare)
  1474. {
  1475. //echo $toolcompare;
  1476. //echo "/".$type."/".$id."****";
  1477. //$key=key($addedresource);
  1478. //echo $addedresourceid[$key];
  1479. //print_r($addedresourceid);
  1480. //echo "<br>";
  1481. if ($toolcompare==$type and $addedresourceid[key($addedresource)]==$id)
  1482. {
  1483. $show=0;
  1484. }
  1485. next($addedresource);
  1486. }
  1487. if ($from_learnpath) { $lang_add_it_or_resource=get_lang('AddIt'); } else { $lang_add_it_or_resource=get_lang('AddResource'); }
  1488. if ($show!==0)
  1489. {
  1490. if ($type=="Document")
  1491. {
  1492. 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>";
  1493. }
  1494. else
  1495. {
  1496. 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>";
  1497. }
  1498. }
  1499. }
  1500. else // if it is not an array, it is a string
  1501. {
  1502. if ($_SESSION['addedresource']!==$type or $_SESSION['addedresourceid']!==$id)
  1503. {
  1504. if ($from_learnpath) { $lang_add_it_or_resource=get_lang('AddIt'); } else { $lang_add_it_or_resource=get_lang('AddResource'); }
  1505. 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>";
  1506. }
  1507. }
  1508. }
  1509. ?>