resourcelinker.inc.php 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058
  1. <?php // $Id: resourcelinker.inc.php,v 1.15 2006/08/15 16:34:03 yannoo Exp $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Patrick Cool (patrick.cool@ugent.be)
  9. Copyright (c) Denes Nagy
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  18. Mail: info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. ==============================================================================
  23. * @author Patrick Cool - original version
  24. * @author Denes Nagy - further improvements for learning path builder
  25. * @author Roan Embrechts - refactoring to improve code organisation
  26. * @package dokeos.resourcelinker
  27. * @todo use the constants for the tools
  28. * @todo use Database API instead of creating table names locally.
  29. ==============================================================================
  30. */
  31. /*
  32. ==============================================================================
  33. INIT SECTION
  34. ==============================================================================
  35. */
  36. #$language_file = "resourcelinker";
  37. //flag to allow for anonymous user - needs to be set before global.inc.php
  38. $use_anonymous = true;
  39. require_once('back_compat.inc.php');
  40. include(api_get_path(SYS_CODE_PATH).'lang/english/resourcelinker.inc.php');
  41. if(!empty($_course['language'])){
  42. include(api_get_path(SYS_CODE_PATH).'lang/'.$_course['language'].'/resourcelinker.inc.php');
  43. }
  44. include('../exercice/hotpotatoes.lib.php');
  45. /*
  46. ==============================================================================
  47. FUNCTIONS
  48. ==============================================================================
  49. */
  50. function unset_session_resources()
  51. {
  52. $_SESSION['addedresource']='';
  53. $_SESSION['addedresourceid']='';
  54. api_session_unregister(addedresource);
  55. api_session_unregister(addedresourceid);
  56. }
  57. /**
  58. * Insert description here.
  59. */
  60. function show_folder_up()
  61. {
  62. global $folder;
  63. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  64. $level = get_levels($folder);
  65. if ($level == 1)
  66. {
  67. 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>";
  68. }
  69. if ($level and $level != 0 and $level != 1)
  70. {
  71. $folder_up=$folder;
  72. $folder_temp=explode('/',$folder);
  73. $last=count($folder_temp)-1;
  74. unset($folder_temp[$last]);
  75. $folder_up=implode('/',$folder_temp);
  76. 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>";
  77. }
  78. }
  79. /**
  80. * Shows the documents of the document tool
  81. * @param $folder
  82. */
  83. function show_documents($folder)
  84. {
  85. global $_course;
  86. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  87. // documents are a special case: the teacher can add an invisible document (it will be viewable by the user)
  88. // other tools do not have this feature. This only counts
  89. if (is_allowed_to_edit())
  90. {
  91. $visibility="visibility<>'2'";
  92. }
  93. else
  94. {
  95. $visibility="visibility='1'";
  96. }
  97. $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  98. $document_table = Database::get_course_table(TABLE_DOCUMENT);
  99. $sql="SELECT * from $document_table, $item_property_table WHERE id=ref AND tool = '".TOOL_DOCUMENT."' AND $visibility AND to_group_id = 0 AND to_user_id IS NULL ORDER BY path ASC";
  100. $result=Database::query($sql,__FILE__,__LINE__);
  101. while ($row=Database::fetch_array($result))
  102. {
  103. if (!$folder)
  104. {
  105. if (get_levels($row['path'])-1==1)
  106. {
  107. // showing the right icon
  108. if (file_or_folder($row['path']))
  109. {
  110. echo '<img src="../img/file.gif" align="middle" />';
  111. }
  112. else
  113. {
  114. $image = choose_image($row['path']);
  115. echo "<img src=\"../img/$image\" align=\"middle\" />";
  116. }
  117. // folders should be clickable
  118. if (file_or_folder($row['path']))
  119. {
  120. echo "<a href='".api_get_self()."?content=Document";
  121. echo "&folder=".substr($row['path'],1)."&source_id=$source_id&source_forum=".$_GET['source_forum']."&action=$action&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no'>".substr($row['path'],1).'</a><br />';
  122. }
  123. else
  124. {
  125. echo substr($row['path'],1).' ';
  126. echo showorhide_addresourcelink('Document',$row['id']);
  127. echo '<br />';
  128. }
  129. }
  130. }
  131. else
  132. {
  133. // we calculate the level we are in by using the $folder in the url
  134. // we put +1 because it does not start with an / and in the database it does
  135. $level=get_levels($folder)+1;
  136. // we calculate each level of the database entry
  137. $file_level=get_levels($row['path'])-1;
  138. // if the level of the database entry is equal to the level we ar in, we put it into an array
  139. // as this is a potential good entry
  140. if ($file_level==$level)
  141. {
  142. $good_paths[]=$row['path'];
  143. $good_ids[]=$row['id'];
  144. }
  145. //$haystack=$row['path'];
  146. //$conform_folder=strstr($haystack, $folder);
  147. //if (str_replace($folder.'/','',$conform_folder)!==$folder)
  148. // {
  149. // $good_folders[]=$row['path'];
  150. //echo str_replace($folder.'/','',$conform_folder);
  151. // echo '<br />';
  152. // }// if (str_replace($folder.'/','',$conform_folder)!==$folder)
  153. } // else (if (!$folder))
  154. } //while ($row=Database::fetch_array($result))
  155. // this is code for the case that we are in a subfolder
  156. if ($good_paths)
  157. {
  158. // we have all the potential good database entries, the good ones are those that start with $folder
  159. foreach ($good_paths as $path)
  160. {
  161. if (strstr($path,$folder))
  162. {
  163. $good_key=key($good_paths);
  164. // showing the right icon
  165. if (file_or_folder($path))
  166. {
  167. echo '<img src="../img/file.gif" align="middle" />';
  168. }
  169. else
  170. {
  171. $image = choose_image($path);
  172. echo "<img src=\"../img/$image\" align=\"middle\" />";
  173. }
  174. // folders should be clickable
  175. if (file_or_folder($path))
  176. {
  177. $path=substr($path,1); // remove the first / in folder_up
  178. $uri=str_replace($folder,$path,$_SERVER['REQUEST_URI']);
  179. $newuri=str_replace('add=','addnot=',$uri);
  180. //using the correct name of the folder
  181. $folder_name=str_replace($folder.'/','',$path);
  182. echo "<a href='$newuri'>".$folder_name.'</a><br />';
  183. }
  184. else
  185. {
  186. echo str_replace("/$folder/", '',$path).' ';
  187. echo showorhide_addresourcelink('Document',$good_ids[$good_key]);
  188. echo '<br />';
  189. }
  190. }
  191. next($good_paths);
  192. }
  193. }
  194. }
  195. /**
  196. * Checks wether something is a file or a folder
  197. * 0 means file, 1 means folder
  198. * @param $filefolder
  199. * @todo: use true and false instead of 1 and 0.
  200. */
  201. function file_or_folder($filefolder)
  202. {
  203. global $_course;
  204. global $baseServDir;
  205. $courseDir = $_course['path'].'/document';
  206. $baseWorkDir = api_get_path(SYS_COURSE_PATH).$courseDir;
  207. return (is_dir($baseWorkDir.$filefolder) ? 1 : 0);
  208. }
  209. /**
  210. * Inserts a resource into the database
  211. *
  212. * @param $source_type
  213. * @param $source_id
  214. */
  215. function store_resources($source_type, $source_id)
  216. {
  217. global $_course;
  218. $resource_table = Database::get_course_table(TABLE_LINKED_RESOURCES);
  219. $addedresource = $_SESSION['addedresource'];
  220. $addedresourceid = $_SESSION['addedresourceid'];
  221. if ($_SESSION['addedresource'])
  222. {
  223. foreach ($addedresource as $resource_type)
  224. {
  225. $sql="INSERT INTO $resource_table (source_type, source_id, resource_type, resource_id) VALUES ('$source_type', '$source_id', '$resource_type', '".$addedresourceid[key($addedresource)]."')";
  226. Database::query($sql,__FILE__,__LINE__);
  227. $i=key($addedresource);
  228. next($addedresource);
  229. }
  230. $_SESSION['addedresource']='';
  231. $_SESSION['addedresourceid']='';
  232. }
  233. }
  234. /**
  235. * DEPRECATED - use rl_get_resource_link() instead - DEPRECATED
  236. * Displays the link that opens a new browser window that views the added resource.
  237. *
  238. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  239. * @param $type the type of the tool
  240. * @param $id the id of the resource
  241. * @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)
  242. * @todo use the constants for the type definitions.
  243. */
  244. function display_addedresource_link($type, $id, $style='')
  245. {
  246. global $_course;
  247. // styling the link of the added resource
  248. if ($style <> '')
  249. {
  250. $styling = ' class="'.$style.'"';
  251. }
  252. switch ($type)
  253. {
  254. case 'Agenda':
  255. $TABLEAGENDA = $_course['dbNameGlu'].'calendar_event';
  256. $result = Database::query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__);
  257. $myrow = Database::fetch_array($result);
  258. echo '<img src="../img/agenda.gif" align="middle" /> <a href="../calendar/agenda.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
  259. break;
  260. case 'Ad_Valvas':
  261. $tbl_announcement = $_course['dbNameGlu'].'announcement';
  262. $result = Database::query("SELECT * FROM `$tbl_announcement` WHERE id=$id",__FILE__,__LINE__);
  263. $myrow = Database::fetch_array($result);
  264. echo '<img src="../img/valves.gif" align="middle" /> <a href="../announcements/announcements.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
  265. break;
  266. case 'Link':
  267. $TABLETOOLLINK = $_course['dbNameGlu'].'link';
  268. $result = Database::query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__);
  269. $myrow = Database::fetch_array($result);
  270. 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";
  271. break;
  272. case 'Exercise':
  273. $TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
  274. $result = Database::query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__);
  275. $myrow = Database::fetch_array($result);
  276. echo '<img src="../img/quiz.gif" align="middle" /> <a href="../exercice/exercice_submit.php?exerciseId='.$myrow['id'].'"'.$styling.'>'.$myrow['title']."</a><br />\n";
  277. break;
  278. case 'Forum':
  279. $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums';
  280. $result = Database::query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__);
  281. $myrow = Database::fetch_array($result);
  282. 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";
  283. break;
  284. case 'Thread': //=topics
  285. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  286. $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text';
  287. $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums';
  288. $result = Database::query("SELECT * FROM `$tbl_posts` posts, `$TBL_FORUMS` forum WHERE forum.forum_id=posts.forum_id and post_id=$id",__FILE__,__LINE__);
  289. $myrow = Database::fetch_array($result);
  290. // grabbing the title of the post
  291. $sql_title = "SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"];
  292. $result_title = Database::query($sql_title,__FILE__,__LINE__);
  293. $myrow_title = Database::fetch_array($result_title);
  294. 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";
  295. break;
  296. case 'Post':
  297. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  298. $sql = "SELECT * FROM $tbl_post p WHERE post_id = $id";
  299. $result = Database::query($sql,__FILE__,__LINE__);
  300. $post = Database::fetch_object($result);
  301. 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";
  302. break;
  303. case 'Document':
  304. $dbTable = $_course['dbNameGlu'].'document';
  305. $result = Database::query("SELECT * FROM `$dbTable` WHERE id=$id",__FILE__,__LINE__);
  306. $myrow = Database::fetch_array($result);
  307. $pathname = explode('/',$myrow['path']); // making a correct name for the link
  308. $last = count($pathname) - 1; // making a correct name for the link
  309. $filename = $pathname[$last]; // making a correct name for the link
  310. $image = choose_image($filename);
  311. $ext = explode('.',$filename);
  312. $ext = strtolower($ext[sizeof($ext)-1]);
  313. $myrow['path'] = rawurlencode($myrow['path']);
  314. $in_frames = in_array($ext, array('htm','html','gif','jpg','jpeg','png'));
  315. 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";
  316. break;
  317. case 'Externallink':
  318. echo '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.'>'.$id."</a><br />\n";
  319. break;
  320. }
  321. }
  322. /**
  323. * This function is to display the added resources (lessons) in the learning path player and builder
  324. * this function is a modification of display_addedresource_link($type, $id) function
  325. * the two ids are a bit confusing, I admit, but I did not want to change Patrick's work, I was
  326. * building upon it. - Denes
  327. *
  328. * Parameters:
  329. * @param completed - if ="completed" then green presentation with checkbox
  330. * @param id_in_path - if onclick then this lesson will be considered completed, that is the unique index in the items table
  331. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  332. * @param type - that is the correspondent type in the mirror tool (like this is a Link item)
  333. * @param builder - if ="builder" then onclick shows in new window
  334. * @param icon - if ="icon" then the small icon will appear
  335. * if ="wrap" then wrapped settings are used (and no icon is displayed)
  336. * 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)
  337. * @todo this function is too long, rewrite
  338. */
  339. function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_path, $builder, $icon, $level = 0)
  340. {
  341. global $_course, $learnpath_id, $tbl_learnpath_item, $items;
  342. global $curDirPath, $_configuration, $enableDocumentParsing, $_course, $_user, $_cid;
  343. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  344. $hyperlink_target_parameter = ''; //or e.g. 'target="_blank"'
  345. $length = ((($builder == 'builder') and ($icon == 'nolink')) ? 65 : 32);
  346. if ($builder != 'builder') $origin = 'learnpath'; //origin = learnpath in student view
  347. $linktype = $type;
  348. if (($type == 'Link _self') or ($type == 'Link _blank')) $type = 'Link';
  349. //YW switched litteral tool names to use of constants declared in main_api.lib.php
  350. switch ($type)
  351. {
  352. case TOOL_CALENDAR_EVENT:
  353. case "Agenda":
  354. $TABLEAGENDA = $_course['dbNameGlu']."calendar_event";
  355. $result = Database::query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__);
  356. $myrow=Database::fetch_array($result);
  357. $sql="select * from $tbl_lp_item where id=$id_in_path";
  358. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  359. if ($row['title'] != '') { $myrow["title"]=$row['title']; }
  360. $desc=$row['description'];
  361. $agenda_id=$row['item_id'];
  362. echo str_repeat("&nbsp;&gt;",$level);
  363. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  364. if ($icon != 'nolink')
  365. {
  366. if ($completed=='completed') {
  367. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  368. } else {
  369. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  370. //echo "&nbsp;";
  371. }
  372. }
  373. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  374. if ($myrow["title"]=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  375. if ($icon == 'nolink') { return(shorten($myrow["title"],$length)); }
  376. if ($icon == 'icon') { echo "<img src='../img/agenda.gif' align=\"absmiddle\" alt='agenda'>"; }
  377. if ($builder != 'builder')
  378. {
  379. 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>";
  380. $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";
  381. if ($desc != '')
  382. {
  383. if ($icon != 'wrap')
  384. {
  385. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  386. }
  387. else
  388. {
  389. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  390. }
  391. }
  392. }
  393. else
  394. {
  395. echo "<a href=\"../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id\" class='$completed' target='_blank'>".shorten($myrow["title"],($length-3*$level))."</a>";
  396. }
  397. break;
  398. case TOOL_ANNOUNCEMENT:
  399. case "Ad_Valvas":
  400. $tbl_announcement = $_course['dbNameGlu']."announcement";
  401. $result = Database::query("SELECT * FROM `$tbl_announcement` WHERE id=$id",__FILE__,__LINE__);
  402. $myrow=Database::fetch_array($result);
  403. $sql="select * from $tbl_lp_item where id=$id_in_path";
  404. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  405. if ($row['title'] != '') { $myrow["content"]=$row['title']; }
  406. $desc=$row['description'];
  407. $ann_id=$row['item_id'];
  408. echo str_repeat("&nbsp;&gt;",$level);
  409. // the title and the text are in the content field and we only want to display the title
  410. list($title, $text)=split('<br>',$myrow['content']);
  411. if ($title=='') { $title=$myrow['content']; }
  412. $title=$myrow['title'];
  413. $text=$myrow['content'];
  414. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  415. if ($icon != 'nolink')
  416. {
  417. if ($completed=='completed') {
  418. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  419. } else {
  420. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  421. //echo "&nbsp;";
  422. }
  423. }
  424. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  425. if ($title=='') {
  426. $type="Announcement";
  427. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  428. return(true);
  429. }
  430. if ($icon == 'nolink') { return(shorten($title,$length)); }
  431. if ($icon == 'icon') { echo "<img src='../img/valves.gif' align=\"absmiddle\" alt='ad valvas'>"; }
  432. if ($builder != 'builder')
  433. {
  434. 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>";
  435. $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";
  436. if ($desc != '')
  437. {
  438. if ($icon != 'wrap')
  439. {
  440. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  441. }
  442. else
  443. {
  444. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  445. }
  446. }
  447. }
  448. else
  449. {
  450. echo "<a href=\"../announcements/announcements.php?origin=$origin&ann_id=$ann_id\" class='$completed' target='_blank'>".shorten($title,($length-3*$level))."</a>";
  451. }
  452. break;
  453. case TOOL_LINK:
  454. case "Link" :
  455. $TABLETOOLLINK = $_course['dbNameGlu']."link";
  456. $result= Database::query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__);
  457. $myrow=Database::fetch_array($result);
  458. $sql="select * from $tbl_lp_item where id=$id_in_path";
  459. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  460. if ($row['title'] != '') { $myrow["title"]=$row['title']; }
  461. $desc=$row['description'];
  462. echo str_repeat("&nbsp;&gt;",$level);
  463. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  464. if ($icon != 'nolink')
  465. {
  466. if ($completed=='completed') {
  467. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  468. } else {
  469. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  470. //echo "&nbsp;";
  471. }
  472. }
  473. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  474. if ($myrow["title"]=='')
  475. {
  476. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  477. return(true);
  478. }
  479. if ($icon == 'nolink') { return(shorten($myrow["title"],$length)); }
  480. if ($icon == 'icon')
  481. {
  482. if ($linktype=='Link _self') { echo "<img src='../img/links.gif' align=\"absmiddle\" alt='links'>"; }
  483. else { echo "<img src='../img/link_blank.gif' align=\"absmiddle\" alt='blank links'>"; }
  484. }
  485. $thelink=$myrow["url"];
  486. if ($builder != 'builder')
  487. {
  488. 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>";
  489. $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";
  490. if ($desc != '')
  491. {
  492. if ($icon != 'wrap')
  493. {
  494. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  495. }
  496. else
  497. {
  498. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  499. }
  500. }
  501. }
  502. else
  503. {
  504. echo "<a href=\"$thelink\" class='$completed' target='_blank'>".shorten($myrow["title"],($length-3*$level))."</a>";
  505. }
  506. break;
  507. case TOOL_QUIZ:
  508. case "Exercise":
  509. $TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
  510. $result= Database::query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__);
  511. $myrow=Database::fetch_array($result);
  512. if ($builder=='builder') { $origin='builder'; }
  513. //this is needed for the exercise_submit.php can delete the session info about tests
  514. $sql="select * from $tbl_lp_item where id=$id_in_path";
  515. $result=Database::query($sql,__FILE__,__LINE__);
  516. $row=Database::fetch_array($result);
  517. if ($row['title'] != '') { $myrow["title"]=$row['title']; }
  518. $desc=$row['description'];
  519. echo str_repeat("&nbsp;&gt;",$level);
  520. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  521. if ($icon != 'nolink')
  522. {
  523. if ($completed=='completed') {
  524. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  525. } else {
  526. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  527. //echo "&nbsp;";
  528. }
  529. }
  530. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  531. if ($myrow["title"]=='') {
  532. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  533. return(true);
  534. }
  535. if ($icon == 'nolink') { return(shorten($myrow["title"],$length)); }
  536. if ($icon == 'icon') { echo "<img src='../img/quiz.gif' align=\"absmiddle\" alt='quizz'>"; }
  537. if ($builder != 'builder')
  538. {
  539. 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>";
  540. $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";
  541. if ($desc != '')
  542. {
  543. if ($icon != 'wrap')
  544. {
  545. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  546. }
  547. else
  548. {
  549. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  550. }
  551. }
  552. }
  553. else
  554. {
  555. echo "<a href=\"../exercice/exercice_submit.php?origin=$origin&exerciseId=".$myrow["id"]."\" class='$completed' target='_blank'>".shorten($myrow["title"],($length-3*$level))."</a>";
  556. }
  557. break;
  558. case 'hotpotatoes':
  559. case "HotPotatoes":
  560. $TBL_DOCUMENT = $_course['dbNameGlu'].'document';
  561. $documentPath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document';
  562. $result = Database::query("SELECT * FROM `".$TBL_DOCUMENT."` WHERE id=$id");
  563. $myrow= Database::fetch_array($result);
  564. $path=$myrow["path"];
  565. $name=GetQuizName($path,$documentPath);
  566. if ($builder=='builder') { $origin='builder'; }
  567. //this is needed for the exercise_submit.php can delete the session info about tests
  568. $sql="select * from $tbl_lp_item where id=$id_in_path";
  569. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  570. if ($row['title'] != '') { $name=$row['title']; }
  571. $desc=$row['description'];
  572. echo str_repeat("&nbsp;&gt;",$level);
  573. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  574. if ($icon != 'nolink')
  575. {
  576. if ($completed=='completed') {
  577. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  578. } else {
  579. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  580. //echo "&nbsp;";
  581. }
  582. }
  583. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  584. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  585. if ($icon == 'nolink') { return(shorten($name,$length)); }
  586. if ($icon == 'icon') { echo "<img src='../img/jqz.jpg' align=\"absmiddle\" alt='hot potatoes'>"; }
  587. $cid = $_course['official_code'];
  588. if ($builder != 'builder')
  589. {
  590. 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>";
  591. $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";
  592. if ($desc != '')
  593. {
  594. if ($icon != 'wrap')
  595. {
  596. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  597. }
  598. else
  599. {
  600. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  601. }
  602. }
  603. }
  604. else
  605. {
  606. 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>";
  607. }
  608. break;
  609. case TOOL_FORUM:
  610. case "Forum":
  611. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM,$_course['database']);
  612. $result= Database::query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id",__FILE__,__LINE__);
  613. $myrow=Database::fetch_array($result);
  614. $sql="select * from $tbl_lp_item where id=$id_in_path";
  615. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  616. if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; }
  617. $desc=$row['description'];
  618. echo str_repeat("&nbsp;&gt;",$level);
  619. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  620. if ($icon != 'nolink')
  621. {
  622. if ($completed=='completed') {
  623. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  624. } else {
  625. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  626. //echo "&nbsp;";
  627. }
  628. }
  629. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  630. if ($myrow["forum_name"]=='') { $type="Forum"; echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('step_deleted2')."</span>"; return(true); }
  631. if ($icon == 'nolink') { return(shorten($myrow["forum_name"],$length)); }
  632. if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
  633. $forumparameters="forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  634. if ($builder != 'builder')
  635. {
  636. 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>";
  637. $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";
  638. if ($desc != '')
  639. {
  640. if ($icon != 'wrap')
  641. {
  642. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  643. }
  644. else
  645. {
  646. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  647. }
  648. }
  649. }
  650. else
  651. {
  652. echo "<a href=\"../phpbb/viewforum.php?$forumparameters\" class='$completed' target='_blank'>".shorten($myrow["forum_name"],($length-3*$level))."</a>";
  653. }
  654. break;
  655. case TOOL_THREAD:
  656. case "Thread": //forum post
  657. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD,$_course['database']);
  658. $sql="SELECT * FROM $tbl_topics where topic_id=$id";
  659. $result= Database::query($sql,__FILE__,__LINE__);
  660. $myrow=Database::fetch_array($result);
  661. $sql="select * from $tbl_lp_item where id=$id_in_path";
  662. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  663. if ($row['title'] != '') { $myrow["topic_title"]=$row['title']; }
  664. $desc=$row['description'];
  665. echo str_repeat("&nbsp;&gt;",$level);
  666. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  667. if ($icon != 'nolink')
  668. {
  669. if ($completed=='completed') {
  670. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  671. } else {
  672. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  673. //echo "&nbsp;";
  674. }
  675. }
  676. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  677. if ($myrow["topic_title"]=='') { $type="Forum Post"; echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  678. if ($icon == 'nolink') { return(shorten($myrow["topic_title"],$length)); }
  679. if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
  680. if ($builder != 'builder')
  681. {
  682. 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>";
  683. $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";
  684. if ($desc != '')
  685. {
  686. if ($icon != 'wrap')
  687. {
  688. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  689. }
  690. else
  691. {
  692. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  693. }
  694. }
  695. }
  696. else
  697. {
  698. 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>";
  699. }
  700. break;
  701. case TOOL_POST:
  702. case "Post":
  703. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  704. $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text';
  705. $TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
  706. $result= Database::query("SELECT * FROM `$tbl_posts` where post_id=$id",__FILE__,__LINE__);
  707. $myrow=Database::fetch_array($result);
  708. // grabbing the title of the post
  709. $sql_titel="SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"];
  710. $result_titel=Database::query($sql_titel,__FILE__,__LINE__);
  711. $myrow_titel=Database::fetch_array($result_titel);
  712. $sql="select * from $tbl_lp_item where id=$id_in_path";
  713. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  714. if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; }
  715. $desc=$row['description'];
  716. echo str_repeat("&nbsp;&gt;",$level);
  717. $posternom=$myrow['nom']; $posterprenom=$myrow['prenom'];
  718. $posttime=$myrow['post_time']; $posttext=$myrow_titel['post_text'];
  719. $posttitle=$myrow_titel['post_title'];
  720. $posttext = str_replace('"',"'",$posttext);
  721. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  722. if ($icon != 'nolink')
  723. {
  724. if ($completed=='completed') {
  725. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  726. } else {
  727. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  728. //echo "&nbsp;";
  729. }
  730. }
  731. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  732. if ($myrow_titel["post_title"]=='')
  733. {
  734. $type="Forum";
  735. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true);
  736. }
  737. if ($icon == 'nolink') { return(shorten($myrow_titel["post_title"],$length)); }
  738. if ($icon == 'icon') { echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>"; }
  739. if ($builder != 'builder')
  740. {
  741. 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";
  742. if ($desc != '')
  743. {
  744. if ($icon != 'wrap')
  745. {
  746. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  747. }
  748. else
  749. {
  750. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  751. }
  752. }
  753. }
  754. else
  755. {
  756. 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>";
  757. }
  758. break;
  759. case TOOL_DOCUMENT:
  760. case "Document":
  761. $dbTable = $_course['dbNameGlu']."document";
  762. $mysql = "SELECT * FROM `$dbTable` WHERE id=$id";
  763. //error_log('New LP - Querying document table: '.$mysql,0);
  764. $result = Database::query($mysql,__FILE__,__LINE__);
  765. $myrow=Database::fetch_array($result);
  766. $pathname=explode("/",$myrow["path"]); // making a correct name for the link
  767. $last=count($pathname)-1; // making a correct name for the link
  768. $filename=$pathname[$last]; // making a correct name for the link
  769. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  770. echo str_repeat("&nbsp;&gt;",$level);
  771. if ($icon != 'nolink') {
  772. if ($completed=='completed') {
  773. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  774. } else {
  775. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  776. //echo "&nbsp;";
  777. }
  778. }
  779. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  780. $image=choose_image($filename);
  781. $sql="select * from $tbl_lp_item where id=$id_in_path";
  782. //error_log('New LP - Querying lp_item table: '.$sql,0);
  783. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  784. if ($row['title'] != '') { $filename=$row['title']; }
  785. $desc=$row['description'];
  786. if (($myrow["path"]=='') and ($filename=='')) {
  787. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>";
  788. return(true);
  789. }
  790. if ($icon == 'nolink') { return(shorten($filename,$length)); }
  791. if ($icon == 'icon') { echo "<img src='../img/$image' align=\"absmiddle\" alt='$image'>"; }
  792. if ($builder != 'builder')
  793. {
  794. 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>";
  795. if ($desc != '')
  796. {
  797. if ($icon != 'wrap')
  798. {
  799. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  800. }
  801. else
  802. {
  803. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  804. }
  805. } $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";
  806. }
  807. else
  808. {
  809. $enableDocumentParsing=yes;
  810. if (!$enableDocumentParsing)
  811. { //this is the solution for the non-parsing version in the builder
  812. $file=urlencode($myrow["path"]);
  813. echo "<a href='../document/showinframes.php?file=$file' class='$completed' $hyperlink_target_parameter>".shorten($filename,($length-3*$level))."</a>";
  814. }
  815. else
  816. {
  817. echo "<a href=\"../document/download.php?doc_url=".$myrow["path"]."\" class='$completed' $hyperlink_target_parameter>".shorten($filename,($length-3*$level))."</a>";
  818. }
  819. }
  820. break;
  821. case 'assignments':
  822. case "Assignments":
  823. $name=get_lang('Assignments');
  824. $sql="select * from $tbl_lp_item where id=$id_in_path";
  825. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  826. if ($row['title'] != '') { $name=$row['title']; }
  827. $desc=$row['description'];
  828. echo str_repeat("&nbsp;&gt;",$level);
  829. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  830. if ($icon != 'nolink')
  831. {
  832. if ($completed=='completed') {
  833. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  834. } else {
  835. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  836. //echo "&nbsp;";
  837. }
  838. }
  839. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  840. if ($name=='')
  841. {
  842. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true);
  843. }
  844. if ($icon == 'nolink') { return(shorten($name,$length)); }
  845. if ($icon == 'icon') { echo "<img src='../img/works.gif' align=\"absmiddle\">"; }
  846. if ($builder != 'builder')
  847. {
  848. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=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";
  849. if ($desc != '')
  850. {
  851. if ($icon != 'wrap')
  852. {
  853. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>";
  854. }
  855. else
  856. {
  857. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>";
  858. }
  859. }
  860. }
  861. else
  862. {
  863. echo "<a href=\"../work/work.php\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  864. }
  865. break;
  866. case TOOL_DROPBOX:
  867. case "Dropbox":
  868. $name=get_lang('Dropbox');
  869. $sql="select * from $tbl_lp_item where id=$id_in_path";
  870. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  871. if ($row['title'] != '') { $name=$row['title']; }
  872. $desc=$row['description'];
  873. echo str_repeat("&nbsp;&gt;",$level);
  874. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  875. if ($icon != 'nolink') {
  876. if ($completed=='completed') {
  877. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  878. } else {
  879. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  880. //echo "&nbsp;";
  881. }
  882. }
  883. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  884. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  885. if ($icon == 'nolink') { return(shorten($name,$length)); }
  886. if ($icon == 'icon') { echo "<img src='../img/dropbox.gif' align=\"absmiddle\">"; }
  887. if ($builder != 'builder')
  888. {
  889. 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";
  890. if ($desc != '') {
  891. if ($icon != 'wrap') {
  892. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
  893. else {
  894. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
  895. }
  896. } else {
  897. echo "<a href=\"../dropbox/index.php\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  898. }
  899. break;
  900. case 'introduction_text':
  901. case "Introduction_text":
  902. $name=get_lang('IntroductionText');
  903. $sql="select * from $tbl_lp_item where id=$id_in_path";
  904. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  905. if ($row['title'] != '') { $name=$row['title']; }
  906. $desc=$row['description'];
  907. echo str_repeat("&nbsp;&gt;",$level);
  908. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  909. if ($icon != 'nolink') {
  910. if ($completed=='completed') {
  911. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  912. } else {
  913. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  914. //echo "&nbsp;";
  915. }
  916. }
  917. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  918. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  919. if ($icon == 'nolink') { return(shorten($name,$length)); }
  920. if ($icon == 'icon') { echo "<img src='../img/introduction.gif' align=\"absmiddle\" alt='introduction'>"; }
  921. if ($builder != 'builder')
  922. {
  923. 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>";
  924. $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";
  925. if ($desc != '') {
  926. if ($icon != 'wrap') {
  927. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
  928. else {
  929. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
  930. }
  931. } else {
  932. $s=api_get_path('WEB_COURSE_PATH')."$_cid/index.php?intro_cmdEdit=1";
  933. echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  934. }
  935. break;
  936. case TOOL_COURSE_DESCRIPTION:
  937. case "Course_description":
  938. $name=get_lang('CourseDescription');
  939. $sql="select * from $tbl_lp_item where id=$id_in_path";
  940. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  941. if ($row['title'] != '') { $name=$row['title']; }
  942. $desc=$row['description'];
  943. echo str_repeat("&nbsp;&gt;",$level);
  944. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  945. if ($icon != 'nolink') {
  946. if ($completed=='completed') {
  947. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  948. } else {
  949. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  950. //echo "&nbsp;";
  951. }
  952. }
  953. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  954. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  955. if ($icon == 'nolink') { return(shorten($name,$length)); }
  956. if ($icon == 'icon') { echo "<img src='../img/info.gif' align=\"absmiddle\" alt='info'>"; }
  957. if ($builder != 'builder')
  958. {
  959. 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";
  960. if ($desc != '') {
  961. if ($icon != 'wrap') {
  962. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
  963. else {
  964. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
  965. }
  966. } else {
  967. $s=api_get_path('WEB_CODE_PATH')."course_description";
  968. echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  969. }
  970. break;
  971. case TOOL_GROUP:
  972. case "Groups":
  973. $name=get_lang('Groups');
  974. $sql="select * from $tbl_lp_item where id=$id_in_path";
  975. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  976. if ($row['title'] != '') { $name=$row['title']; }
  977. $desc=$row['description'];
  978. echo str_repeat("&nbsp;&gt;",$level);
  979. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  980. if ($icon != 'nolink') {
  981. if ($completed=='completed') {
  982. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  983. } else {
  984. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  985. //echo "&nbsp;";
  986. }
  987. }
  988. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  989. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  990. if ($icon == 'nolink') { return(shorten($name,$length)); }
  991. if ($icon == 'icon') { echo "<img src='../img/group.gif' align=\"absmiddle\" alt='group'>"; }
  992. if ($builder != 'builder')
  993. {
  994. 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";
  995. if ($desc != '') {
  996. if ($icon != 'wrap') {
  997. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
  998. else {
  999. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
  1000. }
  1001. } else {
  1002. echo "<a href=\"../group/group.php?origin=$origin\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  1003. }
  1004. break;
  1005. case TOOL_USER:
  1006. case "Users":
  1007. $name=get_lang('Users');
  1008. $sql="select * from $tbl_lp_item where id=$id_in_path";
  1009. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  1010. if ($row['title'] != '') { $name=$row['title']; }
  1011. $desc=$row['description'];
  1012. echo str_repeat("&nbsp;&gt;",$level);
  1013. if (($builder != 'builder') and ($icon != 'wrap')) { echo "<td>"; }
  1014. if ($icon != 'nolink') {
  1015. if ($completed=='completed') {
  1016. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  1017. } else {
  1018. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  1019. //echo "&nbsp;";
  1020. }
  1021. }
  1022. if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
  1023. if ($name=='') { echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2')."</span>"; return(true); }
  1024. if ($icon == 'nolink') { return(shorten($name,$length)); }
  1025. if ($icon == 'icon') { echo "<img src='../img/members.gif' align=\"absmiddle\" alt='members'>"; }
  1026. if ($builder != 'builder')
  1027. {
  1028. 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";
  1029. if ($desc != '') {
  1030. if ($icon != 'wrap') {
  1031. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div></td></tr>"; }
  1032. else {
  1033. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten($desc,($length-3*$level))."</div>"; }
  1034. }
  1035. } else {
  1036. echo "<a href=\"../user/user.php?origin=$origin\" class='$completed' target='_blank'>".shorten($name,($length-3*$level))."</a>";
  1037. }
  1038. break;
  1039. }//end huge switch-statement
  1040. }
  1041. /**
  1042. * This function is to create and return a link to the added resources (lessons).
  1043. * It returns the same thing as display_addedresource_link_in_learnpath() but doesn't display
  1044. * anything.
  1045. *
  1046. * Parameters:
  1047. * @param type - that is the correspondent type in the mirror tool (like this is a Link item)
  1048. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  1049. * @param id_in_path - the unique index in the items table
  1050. */
  1051. function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
  1052. {
  1053. global $_course, $learnpath_id, $tbl_learnpath_item, $items;
  1054. global $curDirPath, $_configuration, $enableDocumentParsing, $_user, $_cid;
  1055. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1056. $hyperlink_target_parameter = ""; //or e.g. target='_blank'
  1057. $builder = 'player';
  1058. $origin='learnpath';
  1059. $linktype=$type;
  1060. if (($type=="Link _self") or ($type=="Link _blank")) { $type="Link"; }
  1061. $link = '';
  1062. switch ($type)
  1063. {
  1064. case "Agenda":
  1065. $TABLEAGENDA = $_course['dbNameGlu']."calendar_event";
  1066. $result = Database::query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__);
  1067. $myrow=Database::fetch_array($result);
  1068. $sql="select * from $tbl_lp_item where id=$id_in_path";
  1069. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  1070. if ($row['title'] != '') { $myrow["title"]=$row['title']; }
  1071. $desc=$row['description'];
  1072. $agenda_id=$row['item_id'];
  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=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path";
  1076. }
  1077. else
  1078. {
  1079. $link .= "../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id";
  1080. }
  1081. break;
  1082. case "Ad_Valvas":
  1083. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1084. $result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id",__FILE__,__LINE__);
  1085. $myrow=Database::fetch_array($result);
  1086. if ($builder != 'builder')
  1087. {
  1088. $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";
  1089. }
  1090. else
  1091. {
  1092. $link .= "../announcements/announcements.php?origin=$origin&ann_id=$id";
  1093. }
  1094. break;
  1095. case "Link" :
  1096. $TABLETOOLLINK = $_course['dbNameGlu']."link";
  1097. $result= Database::query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__);
  1098. $myrow=Database::fetch_array($result);
  1099. $sql="select * from $tbl_lp_item where id=$id_in_path";
  1100. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  1101. $thelink=$myrow["url"];
  1102. if ($builder != 'builder')
  1103. {
  1104. $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";
  1105. }
  1106. else
  1107. {
  1108. $link .= $thelink;
  1109. }
  1110. break;
  1111. case "Exercise":
  1112. $TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
  1113. $result= Database::query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__);
  1114. $myrow=Database::fetch_array($result);
  1115. if ($builder=='builder') { $origin='builder'; }
  1116. //this is needed for the exercise_submit.php can delete the session info about tests
  1117. $sql="select * from $tbl_lp_item where id=$id_in_path";
  1118. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  1119. if ($row['title'] != '') { $myrow["title"]=$row['title']; }
  1120. if ($builder != 'builder')
  1121. {
  1122. $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";
  1123. }
  1124. else
  1125. {
  1126. $link .= "../exercice/exercice_submit.php?origin=$origin&exerciseId=".$myrow["id"];
  1127. }
  1128. break;
  1129. case "HotPotatoes":
  1130. $TBL_DOCUMENT = $_course['dbNameGlu'].'document';
  1131. $documentPath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document';
  1132. $result = Database::query("SELECT * FROM `".$TBL_DOCUMENT."` WHERE id=$id");
  1133. $myrow= Database::fetch_array($result);
  1134. $path=$myrow["path"];
  1135. $name=GetQuizName($path,$documentPath);
  1136. if ($builder=='builder') { $origin='builder'; }
  1137. $cid = $_course['official_code'];
  1138. if ($builder != 'builder')
  1139. {
  1140. $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";
  1141. }
  1142. else
  1143. {
  1144. $link .= "../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id'];
  1145. }
  1146. break;
  1147. case "Forum":
  1148. $TBL_FORUMS = $_course['dbNameGlu']."bb_forums"; // TODO: This is the old table name, it should be corrected.
  1149. $result= Database::query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__);
  1150. $myrow=Database::fetch_array($result);
  1151. if ($builder=='builder') { $origin='builder'; }
  1152. $sql="select * from $tbl_lp_item where id=$id_in_path";
  1153. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  1154. if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; }
  1155. if ($myrow["forum_name"]=='') { $type="Forum"; }
  1156. $forumparameters="forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1157. if ($builder != 'builder')
  1158. {
  1159. $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";
  1160. }
  1161. else
  1162. {
  1163. $link .= "../phpbb/viewforum.php?$forumparameters";
  1164. }
  1165. break;
  1166. case "Thread": //forum post
  1167. $tbl_topics = $_course['dbNameGlu'].'bb_topics';
  1168. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  1169. $TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
  1170. $sql="SELECT * FROM `$tbl_topics` where topic_id=$id";
  1171. $result= Database::query($sql,__FILE__,__LINE__);
  1172. $myrow=Database::fetch_array($result);
  1173. $sql="select * from $tbl_lp_item where id=$id_in_path";
  1174. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  1175. if ($builder != 'builder')
  1176. {
  1177. $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";
  1178. }
  1179. else
  1180. {
  1181. $link .= "../forum/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1182. }
  1183. break;
  1184. case "Post":
  1185. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  1186. $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text';
  1187. $TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
  1188. $result= Database::query("SELECT * FROM `$tbl_posts` where post_id=$id",__FILE__,__LINE__);
  1189. $myrow=Database::fetch_array($result);
  1190. // grabbing the title of the post
  1191. $sql_titel="SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"];
  1192. $result_titel=Database::query($sql_titel,__FILE__,__LINE__);
  1193. $myrow_titel=Database::fetch_array($result_titel);
  1194. $sql="select * from $tbl_lp_item where id=$id_in_path";
  1195. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  1196. if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; }
  1197. $desc=$row['description'];
  1198. $link .= str_repeat("&nbsp;&gt;",$level);
  1199. $posternom=$myrow['nom']; $posterprenom=$myrow['prenom'];
  1200. $posttime=$myrow['post_time']; $posttext=$myrow_titel['post_text'];
  1201. $posttitle=$myrow_titel['post_title'];
  1202. $posttext = str_replace('"',"'",$posttext);
  1203. if ($builder != 'builder')
  1204. {
  1205. $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";
  1206. }
  1207. else
  1208. {
  1209. $link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1210. }
  1211. break;
  1212. case "Document":
  1213. $dbTable = $_course['dbNameGlu']."document";
  1214. $result=Database::query("SELECT * FROM `$dbTable` WHERE id=$id",__FILE__,__LINE__);
  1215. $myrow=Database::fetch_array($result);
  1216. $pathname=explode("/",$myrow["path"]); // making a correct name for the link
  1217. $last=count($pathname)-1; // making a correct name for the link
  1218. $filename=$pathname[$last]; // making a correct name for the link
  1219. $sql="select * from $tbl_lp_item where id=$id_in_path";
  1220. $result=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($result);
  1221. if ($builder != 'builder')
  1222. {
  1223. $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";
  1224. }
  1225. else
  1226. {
  1227. $enableDocumentParsing=yes;
  1228. if (!$enableDocumentParsing)
  1229. { //this is the solution for the non-parsing version in the builder
  1230. $file=urlencode($myrow["path"]);
  1231. $link .= "../document/showinframes.php?file=$file";
  1232. }
  1233. else
  1234. {
  1235. $link .= "../document/download.php?doc_url=".$myrow["path"];
  1236. }
  1237. }
  1238. break;
  1239. case "Assignments":
  1240. if ($builder != 'builder')
  1241. {
  1242. $link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path";
  1243. }
  1244. else
  1245. {
  1246. $link .= "../work/work.php";
  1247. }
  1248. break;
  1249. case "Dropbox":
  1250. if ($builder != 'builder')
  1251. {
  1252. $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";
  1253. } else {
  1254. $link .= "../dropbox/index.php";
  1255. }
  1256. break;
  1257. case "Introduction_text":
  1258. if ($builder != 'builder')
  1259. {
  1260. $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";
  1261. } else {
  1262. $s=api_get_path('WEB_COURSE_PATH')."$_cid/index.php?intro_cmdEdit=1";
  1263. $link .= $s;
  1264. }
  1265. break;
  1266. case "Course_description":
  1267. if ($builder != 'builder')
  1268. {
  1269. $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";
  1270. } else {
  1271. $s=api_get_path('WEB_CODE_PATH')."course_description";
  1272. $link .= $s;
  1273. }
  1274. break;
  1275. case "Groups":
  1276. if ($builder != 'builder')
  1277. {
  1278. $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";
  1279. } else {
  1280. $link .= "../group/group.php?origin=$origin";
  1281. }
  1282. break;
  1283. case "Users":
  1284. if ($builder != 'builder')
  1285. {
  1286. $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";
  1287. } else {
  1288. $link .= "../user/user.php?origin=$origin";
  1289. }
  1290. break;
  1291. }//end huge switch-statement
  1292. return $link;
  1293. }
  1294. /**
  1295. * This function is to remove an resource item from the array
  1296. */
  1297. function remove_resource($resource_key)
  1298. {
  1299. $addedresource = $_SESSION['addedresource'];
  1300. $addedresourceid = $_SESSION['addedresourceid'];
  1301. unset($addedresource[$resource_key]);
  1302. unset($addedresourceid[$resource_key]);
  1303. $_SESSION['addedresource']=$addedresource;
  1304. $_SESSION['addedresourceid']=$addedresourceid ;
  1305. }
  1306. /**
  1307. * This function is to show the button "click to add resource" on the tool page
  1308. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1309. */
  1310. function show_addresource_button($additionalparameters = '')
  1311. {
  1312. global $charset;
  1313. 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.' />';
  1314. }
  1315. /**
  1316. * this function is to delete ONE specific resource that were added to a specific item
  1317. */
  1318. function delete_one_added_resource($source_type, $source_id, $resource_type, $resource_id)
  1319. {
  1320. echo "delete_one_added_resource";
  1321. global $_course;
  1322. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1323. $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$source_type' and source_id='$source_id' and resource_type='$resource_type' and resource_id='$resource_id'";
  1324. Database::query($sql,__FILE__,__LINE__);
  1325. }
  1326. /**
  1327. * this function is to delete the resources that were added to a specific item
  1328. */
  1329. function delete_added_resource($type, $id)
  1330. {
  1331. global $_course;
  1332. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1333. $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'";
  1334. Database::query($sql,__FILE__,__LINE__);
  1335. }
  1336. /**
  1337. * this function is te delete all resources of a specific type (only used in announcements -- delete all)
  1338. * Author : Frederik Vermeire <frederik.vermeire@pandora.be>
  1339. */
  1340. function delete_all_resources_type($type)
  1341. {
  1342. global $_course;
  1343. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1344. $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$type'";
  1345. Database::query($sql,__FILE__,__LINE__);
  1346. }
  1347. /**
  1348. * this function checks wether there are added resources or not
  1349. */
  1350. function check_added_resources($type, $id)
  1351. {
  1352. global $_course, $origin;
  1353. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1354. $sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'";
  1355. $result=Database::query($sql,__FILE__,__LINE__);
  1356. $number_added=Database::num_rows($result);
  1357. if ($number_added<>0)
  1358. return true;
  1359. else
  1360. return false;
  1361. }
  1362. /**
  1363. * this function is to load the resources that were added to a specific item
  1364. * into the session variables
  1365. */
  1366. function edit_added_resources($type, $id)
  1367. {
  1368. global $_course;
  1369. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1370. $sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id=$id";
  1371. $result=Database::query($sql,__FILE__,__LINE__);
  1372. while ($row=Database::fetch_array($result))
  1373. {
  1374. $addedresource[]=$row["resource_type"];
  1375. $addedresourceid[]=$row["resource_id"];
  1376. }
  1377. $_SESSION['addedresource']=$addedresource;
  1378. $_SESSION['addedresourceid']=$addedresourceid;
  1379. }
  1380. /**
  1381. * this function is store the modified resources
  1382. * first we delete all the added resources in the database,
  1383. * then we add all the resources from the session object.
  1384. */
  1385. function update_added_resources($type, $id)
  1386. {
  1387. global $_course;
  1388. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1389. // delete all the added resources for this item in the database;
  1390. $sql="DELETE FROM `$TABLERESOURCE` WHERE source_type='$type' AND source_id='$id'";
  1391. //echo $sql;
  1392. Database::query($sql,__FILE__,__LINE__);
  1393. // store the resources from the session into the database
  1394. store_resources($type, $id);
  1395. //delete_added_resource_($type, $id);
  1396. unset_session_resources();
  1397. }
  1398. /**
  1399. * this function is to display the resources that were added to a specific item
  1400. */
  1401. function display_added_resources($type, $id, $style='')
  1402. {
  1403. // the array containing the icons
  1404. $arr_icons=array('Agenda'=>'../img/agenda.gif', 'Ad Valvas'=>'../img/valves.gif', 'Link'=>'../img/links.gif', 'Exercise'=>'../img/quiz.gif' );
  1405. global $_course, $origin;
  1406. $TABLERESOURCE = $_course['dbNameGlu']."resource";
  1407. $sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'";
  1408. $result=Database::query($sql,__FILE__,__LINE__);
  1409. while ($row=Database::fetch_array($result))
  1410. {
  1411. if ($origin != 'learnpath')
  1412. {
  1413. display_addedresource_link($row['resource_type'], $row['resource_id'], $style) ;
  1414. }
  1415. else
  1416. {
  1417. display_addedresource_link_in_learnpath($row['resource_type'], $row['resource_id'],'agendaitems','','builder','icon') ; echo "<br>";
  1418. }
  1419. }
  1420. }
  1421. /**
  1422. * This function is to show the added resources when adding an item
  1423. * $showdeleteimg determine if the delete image should appear or not.
  1424. * deleting an added resource is only possible through the resource linker file itself
  1425. */
  1426. function display_resources($showdeleteimg)
  1427. {
  1428. global $action;
  1429. global $resourceaction;
  1430. global $id;
  1431. global $locationkey;
  1432. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  1433. if ($resourceaction=="removeresource")
  1434. {
  1435. remove_resource($locationkey);
  1436. }
  1437. $addedresource=$_SESSION['addedresource'];
  1438. $addedresourceid=$_SESSION['addedresourceid'];
  1439. if (is_array($addedresource))
  1440. {
  1441. echo '<table>';
  1442. foreach ($addedresource as $resource)
  1443. {
  1444. echo '<tr><td>';
  1445. display_addedresource_link($resource,$addedresourceid[key($addedresource)]);
  1446. echo '</td><td width="30">';
  1447. // if $_SERVER['REQUEST_URI'] contains and ?id=xx we have an edit and the url for deleting a session added resource
  1448. // should also contain this id.
  1449. $test=parse_url($_SERVER['REQUEST_URI']);
  1450. $output = array();
  1451. parse_str($test[query],$output);
  1452. if ($showdeleteimg==1)
  1453. {
  1454. 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 />";
  1455. }
  1456. echo '</td></tr>';
  1457. next($addedresource);
  1458. }
  1459. echo '</table>';
  1460. }
  1461. else // it is a string
  1462. {
  1463. echo '';
  1464. }
  1465. } // end of the display_resources function
  1466. /**
  1467. * This function checks wether the link add resource should be displayed next the item in the linker page
  1468. * So we have to check if the specific id of that tool is already in the array of the added resources
  1469. * if it is already in, the link should not be showed since it would make it possible to add
  1470. * the same resource a second time (=duplication of added resources)
  1471. */
  1472. function showorhide_addresourcelink($type, $id)
  1473. {
  1474. global $from_learnpath, $source_id, $action, $learnpath_id, $chapter_id, $originalresource, $folder, $content, $target;
  1475. $addedresource=$_SESSION['addedresource'];
  1476. $addedresourceid=$_SESSION['addedresourceid'];
  1477. if (is_array($_SESSION['addedresource']))
  1478. {
  1479. foreach ($addedresource as $toolcompare)
  1480. {
  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&lp_id=$learnpath_id&parent_item_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&lp_id=$learnpath_id&parent_item_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&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no&target=$target'>".$lang_add_it_or_resource."</a>";
  1506. }
  1507. }
  1508. }
  1509. /**
  1510. * Gets the link to the given added resource.
  1511. *
  1512. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1513. * @author Yannick Warnier <ywarnier@beeznest.org>, Dokeos - rebranding
  1514. * @param string Course code
  1515. * @param string The tool type (using constants declared in main_api.lib.php)
  1516. * @param integer The resource ID
  1517. * @param string Resource style (e.g. when a resource is hidden => the added resources should also be styled like they are hidden)
  1518. * @param boolean Open in a new window (true) or in the current frame/window (false)?
  1519. * @todo use the constants for the type definitions.
  1520. */
  1521. function rl_get_html_resource_link($course_code, $type, $id, $style='', $new_window=true)
  1522. {
  1523. //$_course = Database::get_course_info($course_code);
  1524. $_course = Database::get_course_info($course_code);
  1525. // styling the link of the added resource
  1526. if ($style <> '') $styling = ' class="'.$style.'"';
  1527. if($new_window == true){ $target = ' target = "_blank" ';}else{$target = ' target = "_self" ';}
  1528. $output = '';
  1529. switch ($type)
  1530. {
  1531. case TOOL_CALENDAR_EVENT:
  1532. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA,$_course['database']);
  1533. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE id=$id",__FILE__,__LINE__);
  1534. $myrow = Database::fetch_array($result);
  1535. $output = '<img src="../img/agenda.gif" align="middle" /> <a href="../calendar/agenda.php"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1536. break;
  1537. case TOOL_ANNOUNCEMENT:
  1538. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT,$_course['database']);
  1539. $result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id",__FILE__,__LINE__);
  1540. $myrow = Database::fetch_array($result);
  1541. $output = '<img src="../img/valves.gif" align="middle" /> <a href="../announcements/announcements.php"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1542. break;
  1543. case TOOL_LINK:
  1544. //doesn't take $target into account
  1545. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK,$_course['database']);
  1546. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$id",__FILE__,__LINE__);
  1547. $myrow = Database::fetch_array($result);
  1548. $output = '<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";
  1549. break;
  1550. case TOOL_QUIZ:
  1551. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST,$_course['database']);
  1552. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE id=$id",__FILE__,__LINE__);
  1553. $myrow = Database::fetch_array($result);
  1554. $output = '<img src="../img/quiz.gif" align="middle" /> <a href="../exercice/exercice_submit.php?exerciseId='.$myrow['id'].'"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1555. break;
  1556. case TOOL_FORUM:
  1557. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM,$_course['database']);
  1558. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id",__FILE__,__LINE__);
  1559. $myrow = Database::fetch_array($result);
  1560. $output = '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewforum.php?forum='.$myrow['forum_id'].'&md5='.$myrow['md5'].'"'.$styling.' '.$target.'>'.$myrow['forum_name']."</a><br />\n";
  1561. break;
  1562. case TOOL_THREAD: //=topics
  1563. //$tbl_forum = Database::get_course_table(TABLE_FORUM,$_course['database']);
  1564. //$tbl_thread = Database::get_course_table(TABLE_FORUM_THREAD,$_course['database']);
  1565. $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']);
  1566. // grabbing the title of the post
  1567. $sql_title = "SELECT * FROM $tbl_post WHERE post_id=".$id;
  1568. $result_title = Database::query($sql_title,__FILE__,__LINE__);
  1569. $myrow_title = Database::fetch_array($result_title);
  1570. $output = '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$myrow_title['thread_id'].'&forum='.$myrow_title['forum_id'].'" '.$styling.' '.$target.'>'.$myrow_title['post_title']."</a><br />\n";
  1571. break;
  1572. case TOOL_POST:
  1573. $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']);
  1574. //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE);
  1575. $sql = "SELECT * FROM $tbl_post p WHERE p.post_id = $id";
  1576. $result = Database::query($sql,__FILE__,__LINE__);
  1577. $post = Database::fetch_array($result);
  1578. $output = '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$post['thread_id'].'&forum='.$post['forum_id'].'"'.$styling.' '.$target.'>'.$post['post_title']."</a><br />\n";
  1579. break;
  1580. case TOOL_DOCUMENT:
  1581. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT,$_course['database']);
  1582. $result = Database::query("SELECT * FROM $tbl_doc WHERE id=$id",__FILE__,__LINE__);
  1583. $myrow = Database::fetch_array($result);
  1584. $pathname = explode('/',$myrow['path']); // making a correct name for the link
  1585. $last = count($pathname) - 1; // making a correct name for the link
  1586. $filename = $pathname[$last]; // making a correct name for the link
  1587. $image = choose_image($filename);
  1588. $ext = explode('.',$filename);
  1589. $ext = strtolower($ext[sizeof($ext)-1]);
  1590. $myrow['path'] = rawurlencode($myrow['path']);
  1591. $in_frames = in_array($ext, array('htm','html','gif','jpg','jpeg','png'));
  1592. $output = '<img src="../img/'.$image.'" align="middle" /> <a href="../document/'.($in_frames ? 'showinframes.php?file=' : 'download.php?doc_url=').$myrow['path'].'"'.$styling.' '.$target.'>'.$filename."</a><br />\n";
  1593. break;
  1594. /*
  1595. case 'Externallink':
  1596. $output = '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.' '.$target.'>'.$id."</a><br />\n";
  1597. break;
  1598. */
  1599. }
  1600. return $output;
  1601. }
  1602. /**
  1603. * Returns an HTML-formatted link to a resource, to incorporate directly into
  1604. * the new learning path tool.
  1605. *
  1606. * The function is a big switch on tool type.
  1607. * In each case, we query the corresponding table for information and build the link
  1608. * with that information.
  1609. * @author Yannick Warnier <ywarnier@beeznest.org> - rebranding based on previous work (display_addedresource_link_in_learnpath())
  1610. * @param string Course code
  1611. * @param integer The learning path ID (in lp table)
  1612. * @param integer The database ID for that item in the lp_item table
  1613. * @param
  1614. * @param string Type (as one of the TOOL_ constants declared in main_api.lib.php)
  1615. * @param integer ID of the database item to get (from that tool's table)
  1616. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  1617. * @param id_in_path - the unique index in the items table
  1618. */
  1619. function rl_get_resource_link_for_learnpath($course_code, $learnpath_id, $id_in_path)
  1620. {
  1621. //error_log('In rl_get_resource_link_for_learnpath()',0);
  1622. $_course = Database::get_course_info($course_code);
  1623. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1624. $sql_item = "SELECT * FROM $tbl_lp_item " .
  1625. "WHERE lp_id = $learnpath_id AND id = $id_in_path";
  1626. $res_item = Database::query($sql_item,__FILE__,__LINE__);
  1627. if(Database::num_rows($res_item)<1) return -1; //exit
  1628. $row_item = Database::fetch_array($res_item);
  1629. $type = strtolower($row_item['item_type']);
  1630. $id = (strcmp($row_item['path'],'')==0) ? '0' : $row_item['path'];
  1631. $origin='learnpath';
  1632. $main_dir_path = api_get_path(WEB_CODE_PATH);
  1633. $main_course_path = api_get_path(WEB_COURSE_PATH).$_course['directory'].'/';
  1634. $link = '';
  1635. switch ($type)
  1636. {
  1637. case 'dokeos_chapter':
  1638. $link .= $main_dir_path.'newscorm/blank.php';
  1639. case TOOL_CALENDAR_EVENT:
  1640. $link .= $main_dir_path.'calendar/agenda.php?origin='.$origin.'&agenda_id='.$id;
  1641. break;
  1642. case TOOL_ANNOUNCEMENT:
  1643. $link .= $main_dir_path.'announcements/announcements.php?origin='.$origin.'&ann_id='.$id;
  1644. break;
  1645. case TOOL_LINK:
  1646. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK,$_course['database']);
  1647. $result= Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$id",__FILE__,__LINE__);
  1648. $myrow=Database::fetch_array($result);
  1649. $thelink=$myrow["url"];
  1650. $link .= $thelink;
  1651. break;
  1652. case TOOL_QUIZ:
  1653. if(!empty($id))
  1654. {
  1655. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST,$_course['database']);
  1656. $sql = "SELECT * FROM $TBL_EXERCICES WHERE id=$id";
  1657. $result= Database::query($sql,__FILE__,__LINE__);
  1658. $myrow=Database::fetch_array($result);
  1659. if ($row_item['title'] != '') { $myrow["title"]=$row_item['title']; }
  1660. $link .= $main_dir_path.'exercice/exercice_submit.php?lp_init=1&origin='.$origin.'&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path.'&exerciseId='.$id;
  1661. }
  1662. break;
  1663. case "hotpotatoes": //lowercase because of strtolower above
  1664. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  1665. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE id=$id",__FILE__,__LINE__);
  1666. $myrow= Database::fetch_array($result);
  1667. $path=$myrow["path"];
  1668. $link .= $main_dir_path.'exercice/showinframes.php?file='.$path.'' .
  1669. '&origin='.$origin.'&cid='.$course_code.'&uid='.api_get_user_id().'' .
  1670. '&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path;
  1671. break;
  1672. case TOOL_FORUM:
  1673. $link .= $main_dir_path.'forum/viewforum.php?forum='.$id.'&lp=true&origin=learnpath';
  1674. break;
  1675. case TOOL_THREAD: //forum post
  1676. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD,$_course['database']);
  1677. if(!empty($id))
  1678. {
  1679. $sql="SELECT * FROM $tbl_topics where thread_id=$id";
  1680. $result= Database::query($sql,__FILE__,__LINE__);
  1681. $myrow=Database::fetch_array($result);
  1682. $link .= $main_dir_path.'forum/viewthread.php?origin=learnpath&thread='.$id.'' .
  1683. '&forum='.$myrow['forum_id'].'&lp=true';
  1684. }
  1685. break;
  1686. case TOOL_POST:
  1687. $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']);
  1688. $result= Database::query("SELECT * FROM $tbl_post where post_id=$id",__FILE__,__LINE__);
  1689. $myrow=Database::fetch_array($result);
  1690. $title=$myrow['post_title'];
  1691. //$desc=$row_item['description'];
  1692. $posternom=$myrow['poster_name'];
  1693. $posttime=$myrow['post_date'];
  1694. $posttext=$myrow['post_text'];
  1695. $posttitle=$title;
  1696. $posttext = str_replace('"',"'",$posttext);
  1697. $link .= $main_dir_path.'forum/viewthread.php?post='.$id.'' .
  1698. '&thread='.$myrow['thread_id'].'&forum='.$myrow['forum_id'].'' .
  1699. '&lp=true';
  1700. break;
  1701. case TOOL_DOCUMENT:
  1702. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT,$_course['database']);
  1703. $sql = "SELECT * FROM $tbl_doc WHERE id=$id";
  1704. $result=Database::query($sql,__FILE__,__LINE__);
  1705. $myrow=Database::fetch_array($result);
  1706. $docurl=str_replace('%2F','/',urlencode($myrow['path']));
  1707. $link .= $main_course_path.'document'.$docurl.'?'.api_get_cidreq();
  1708. $openmethod=2;
  1709. $officedoc=false;
  1710. api_session_register('openmethod');
  1711. api_session_register('officedoc');
  1712. break;
  1713. case "assignments":
  1714. $link .= $main_dir_path.'work/work.php?origin='.$origin;
  1715. break;
  1716. case TOOL_DROPBOX:
  1717. $link .= $main_dir_path.'dropbox/index.php?origin=learnpath';
  1718. break;
  1719. case "introduction_text": //DEPRECATED
  1720. $link .= '';
  1721. break;
  1722. case TOOL_COURSE_DESCRIPTION:
  1723. $link .= $main_dir_path.'course_description?origin='.$learnpath;
  1724. break;
  1725. case TOOL_GROUP:
  1726. $link .= $main_dir_path.'group/group.php?origin='.$origin;
  1727. break;
  1728. case TOOL_USER:
  1729. $link .= $main_dir_path.'user/user.php?origin='.$origin;
  1730. break;
  1731. case 'student_publication' :
  1732. $link .= $main_dir_path.'work/work.php?origin=learnpath';
  1733. break;
  1734. }//end switch
  1735. return $link;
  1736. }
  1737. /**
  1738. * Gets the name of a resource (generally used in learnpath when no name is provided)
  1739. *
  1740. * @author Yannick Warnier <ywarnier@beeznest.org>, Dokeos - rebranding
  1741. * @param string Course code
  1742. * @param string The tool type (using constants declared in main_api.lib.php)
  1743. * @param integer The resource ID
  1744. */
  1745. function rl_get_resource_name($course_code, $learnpath_id, $id_in_path)
  1746. {
  1747. $_course = Database::get_course_info($course_code);
  1748. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1749. $sql_item = "SELECT * FROM $tbl_lp_item " .
  1750. "WHERE lp_id = $learnpath_id AND id = $id_in_path";
  1751. $res_item = Database::query($sql_item,__FILE__,__LINE__);
  1752. if(Database::num_rows($res_item)<1)
  1753. {
  1754. return ''; //exit
  1755. }
  1756. $row_item = Database::fetch_array($res_item);
  1757. $type = strtolower($row_item['item_type']);
  1758. $id = $row_item['ref'];
  1759. $output = '';
  1760. switch ($type)
  1761. {
  1762. case TOOL_CALENDAR_EVENT:
  1763. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA,$_course['database']);
  1764. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE id=$id",__FILE__,__LINE__);
  1765. $myrow = Database::fetch_array($result);
  1766. $output = $myrow['title'];
  1767. break;
  1768. case TOOL_ANNOUNCEMENT:
  1769. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT,$_course['database']);
  1770. $result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id",__FILE__,__LINE__);
  1771. $myrow = Database::fetch_array($result);
  1772. $output = $myrow['title'];
  1773. break;
  1774. case TOOL_LINK:
  1775. //doesn't take $target into account
  1776. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK,$_course['database']);
  1777. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$id",__FILE__,__LINE__);
  1778. $myrow = Database::fetch_array($result);
  1779. $output = $myrow['title'];
  1780. break;
  1781. case TOOL_QUIZ:
  1782. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST,$_course['database']);
  1783. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE id=$id",__FILE__,__LINE__);
  1784. $myrow = Database::fetch_array($result);
  1785. $output = $myrow['title'];
  1786. break;
  1787. case TOOL_FORUM:
  1788. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM,$_course['database']);
  1789. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id",__FILE__,__LINE__);
  1790. $myrow = Database::fetch_array($result);
  1791. $output = $myrow['forum_name'];
  1792. break;
  1793. case TOOL_THREAD: //=topics
  1794. $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']);
  1795. // grabbing the title of the post
  1796. $sql_title = "SELECT * FROM $tbl_post WHERE post_id=".$id;
  1797. $result_title = Database::query($sql_title,__FILE__,__LINE__);
  1798. $myrow_title = Database::fetch_array($result_title);
  1799. $output = $myrow_title['post_title'];
  1800. break;
  1801. case TOOL_POST:
  1802. $tbl_post = Database::get_course_table(TABLE_FORUM_POST,$_course['database']);
  1803. //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE);
  1804. $sql = "SELECT * FROM $tbl_post p WHERE p.post_id = $id";
  1805. $result = Database::query($sql,__FILE__,__LINE__);
  1806. $post = Database::fetch_array($result);
  1807. $output = $post['post_title'];
  1808. break;
  1809. case 'dokeos_chapter':
  1810. $title=$row_item['title'];
  1811. if (!empty($title))
  1812. {
  1813. $output =$title;
  1814. }
  1815. else
  1816. {
  1817. $output ='-';
  1818. }
  1819. break;
  1820. case TOOL_DOCUMENT:
  1821. $title=$row_item['title'];
  1822. if (!empty($title))
  1823. {
  1824. $output =$title;
  1825. }
  1826. else
  1827. {
  1828. $output ='-';
  1829. }
  1830. break;
  1831. case 'hotpotatoes':
  1832. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT,$_course['database']);
  1833. $result = Database::query("SELECT * FROM $tbl_doc WHERE id=$id",__FILE__,__LINE__);
  1834. $myrow = Database::fetch_array($result);
  1835. $pathname = explode('/',$myrow['path']); // making a correct name for the link
  1836. $last = count($pathname) - 1; // making a correct name for the link
  1837. $filename = $pathname[$last]; // making a correct name for the link
  1838. $image = choose_image($filename);
  1839. $ext = explode('.',$filename);
  1840. $ext = strtolower($ext[sizeof($ext)-1]);
  1841. $myrow['path'] = rawurlencode($myrow['path']);
  1842. $in_frames = in_array($ext, array('htm','html','gif','jpg','jpeg','png'));
  1843. $output = $filename;
  1844. break;
  1845. /*
  1846. case 'externallink':
  1847. $output = '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.' '.$target.'>'.$id."</a><br />\n";
  1848. break;
  1849. */
  1850. }
  1851. return stripslashes($output);
  1852. }
  1853. ?>