resourcelinker.inc.php 71 KB

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