resourcelinker.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Patrick Cool, original code
  5. * @author Denes Nagy - many bugfixes and improvements, adjusted for learning path
  6. * @author Roan Embrechts - refactoring, code cleaning
  7. * @package chamilo.resourcelinker
  8. * @todo reorganise code - This class is used?
  9. * use Database API instead of creating table names locally.
  10. *
  11. */
  12. /**
  13. * INIT SECTION
  14. */
  15. use ChamiloSession as Session;
  16. include ('../inc/global.inc.php');
  17. $this_section=SECTION_COURSES;
  18. api_protect_course_script();
  19. /*
  20. -----------------------------------------------------------
  21. Libraries
  22. -----------------------------------------------------------
  23. */
  24. include ('resourcelinker.inc.php');
  25. /*
  26. -----------------------------------------------------------
  27. Constants and variables
  28. -----------------------------------------------------------
  29. */
  30. $link_table = Database :: get_course_table(TABLE_LINK);
  31. $item_property_table = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  32. $tbl_learnpath_main = Database :: get_course_table(TABLE_LEARNPATH_MAIN);
  33. $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER);
  34. $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM);
  35. $action = $_REQUEST['action'];
  36. $add = $_REQUEST['add'];
  37. $chapter_id = $_REQUEST['chapter_id'];
  38. $content = $_REQUEST['content'];
  39. // Note by Patrick Cool: this has been solved belowd. This piece of code hacking produced too much errors.
  40. /*
  41. if(empty($content)){
  42. //adds a default to the item-type selection
  43. $content = 'Document';
  44. }
  45. */
  46. $folder = $_REQUEST['folder'];
  47. $id = $_REQUEST['id'];
  48. $learnpath_id = $_REQUEST['learnpath_id'];
  49. $originalresource = $_REQUEST['originalresource'];
  50. $show_resources = $_REQUEST['show_resources'];
  51. $source_forum = $_REQUEST['source_forum'];
  52. $source_id = $_REQUEST['source_id'];
  53. $target = $_REQUEST['target'];
  54. $external_link = $_REQUEST['external_link'];
  55. $from_learnpath = $_SESSION['from_learnpath'];
  56. // this variable controls wether the link to add a chapter in a module or
  57. // another chapter is shown. This allows to create multi-level learnpaths,
  58. // but export features are not ready for this, yet, so use at your own risks
  59. // default : false -> do not display link
  60. // This setting should be moved to the platform configuration page in time...
  61. $multi_level_learnpath = true;
  62. /*
  63. ==============================================================================
  64. MAIN CODE
  65. ==============================================================================
  66. */
  67. if ($from_learnpath == 'yes')
  68. {
  69. //start from clear every time in LearnPath Builder
  70. $_SESSION['addedresource'] = null;
  71. $_SESSION['addedresourceid'] = null;
  72. $_SESSION['addedresourceassigned'] = null;
  73. unset ($_SESSION['addedresource']);
  74. unset ($_SESSION['addedresourceid']);
  75. unset ($_SESSION['addedresourceassigned']);
  76. }
  77. // Process a new chapter?
  78. if (!empty ($_POST['add_chapter']) && !empty ($_POST['title']))
  79. {
  80. $title = $_POST['title'];
  81. $description = '';
  82. if (!empty ($_POST['description']))
  83. {
  84. $description = $_POST['description'];
  85. }
  86. // get max display_order so far in this parent chapter
  87. $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE learnpath_id = $learnpath_id "." AND parent_chapter_id = $chapter_id";
  88. $res = Database::query($sql);
  89. $row = Database::fetch_array($res);
  90. $max_temp = $row[0];
  91. $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE "." chapter_id = $chapter_id";
  92. $res = Database::query($sql);
  93. $row = Database::fetch_array($res);
  94. $max_temp2 = $row[0];
  95. if ($max_temp2 > $max_temp)
  96. {
  97. $order = $max_temp2 +1;
  98. }
  99. else
  100. {
  101. $order = $max_temp +1;
  102. }
  103. $sql = "INSERT INTO $tbl_learnpath_chapter "."(learnpath_id,chapter_name,chapter_description,parent_chapter_id,display_order) "." VALUES "."($learnpath_id, '$title', '$description', $chapter_id, $order )";
  104. $res = Database::query($sql);
  105. if ($res !== false)
  106. {
  107. $title = '';
  108. $description = '';
  109. }
  110. }
  111. // This if when a external link is submitted
  112. if (!empty ($_POST['external_link_submit']))
  113. {
  114. $add = true;
  115. if ($add_2_links != "niet toevoegen")
  116. {
  117. // add external link to the links table.
  118. $pos = strpos($external_link, 'ttp:');
  119. if ($pos == '')
  120. {
  121. $external_link = 'http://'.$external_link;
  122. }
  123. $sql = "INSERT INTO $link_table (url, title, category_id) VALUES ('$external_link','$external_link','$add_2_links')";
  124. $result = Database::query($sql);
  125. $addedresource[] = "Link";
  126. $addedresourceid[] = Database::insert_id();
  127. $_SESSION['addedresource'] = $addedresource;
  128. $_SESSION['addedresourceid'] = $addedresourceid;
  129. }
  130. else
  131. {
  132. // do not add external link to the links table
  133. $addedresource[] = "Externallink";
  134. $addedresourceid[] = $external_link;
  135. $_SESSION['addedresource'] = $addedresource;
  136. $_SESSION['addedresourceid'] = $addedresourceid;
  137. }
  138. }
  139. // loading the session variables into local array
  140. $addedresource = $_SESSION['addedresource'];
  141. $addedresourceid = $_SESSION['addedresourceid'];
  142. // This is when a resource was added to the session
  143. if ($add)
  144. {
  145. // adding the new variable to the local array
  146. if (empty ($_POST['external_link_submit']))
  147. {
  148. //that case is already arranged, see upwards
  149. $addedresource[] = $content;
  150. $addedresourceid[] = $add;
  151. }
  152. $addedresourceassigned[] = 0;
  153. // loading the local array into the session variable
  154. $_SESSION['addedresource'] = $addedresource;
  155. $_SESSION['addedresourceid'] = $addedresourceid;
  156. //---------------------------------------
  157. //we assign to chapters immediately !
  158. //---------------------------------------
  159. $resource_added = false;
  160. if ($from_learnpath == 'yes')
  161. {
  162. $i = 0;
  163. //calculating the last order of the items of this chapter
  164. $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE chapter_id=$chapter_id";
  165. $result = Database::query($sql);
  166. if(Database::num_rows($result)==0){
  167. $lastorder_item = 0;
  168. }else{
  169. $row = Database::fetch_array($result);
  170. $lastorder_item = ($row[0]);
  171. }
  172. $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE parent_chapter_id=$chapter_id";
  173. $result = Database::query($sql);
  174. if(Database::num_rows($result)==0){
  175. $lastorder_chapter = 0;
  176. }else{
  177. $row = Database::fetch_array($result);
  178. $lastorder_chapter = ($row[0]);
  179. }
  180. $lastorder = ($lastorder_chapter>$lastorder_item?$lastorder_chapter+1:$lastorder_item+1);
  181. foreach ($addedresource as $addedresource_item)
  182. {
  183. // in the case we added a chapter, add this into the chapters list with the correct parent_id
  184. if ($addedresource_item == "Chap")
  185. {
  186. $sql = "INSERT INTO $tbl_learnpath_chapter ("."'learnpath_id','chapter_name','chapter_description','parent_chapter_id','display_order'".") VALUES (".$learnpath_id.",'".$learnpath_chapter_name."','".$learnpath_chapter_description."',".$chapter_id.",".$lastorder.")";
  187. Database::query($sql);
  188. }
  189. if (!$addedresourceassigned[$i])
  190. {
  191. //not to assign it twice
  192. if ($addedresource_item == "Ass")
  193. {
  194. $addedresource_item = "Assignments";
  195. }
  196. if ($addedresource_item == "Drop")
  197. {
  198. $addedresource_item = "Dropbox";
  199. }
  200. if ($addedresource_item == "Intro")
  201. {
  202. $addedresource_item = "Introduction_text";
  203. }
  204. if ($addedresource_item == "Course_desc")
  205. {
  206. $addedresource_item = "Course_description";
  207. }
  208. if ($addedresource_item == "Group")
  209. {
  210. $addedresource_item = "Groups";
  211. }
  212. if ($addedresource_item == "User")
  213. {
  214. $addedresource_item = "Users";
  215. }
  216. if ($target == '')
  217. {
  218. $target = '_self';
  219. }
  220. if ($addedresource_item == 'Link')
  221. {
  222. $addedresource_item .= ' '.$target;
  223. }
  224. $sql = "INSERT INTO $tbl_learnpath_item (id, chapter_id, item_type, item_id, display_order) VALUES ( '$autoid', '$chapter_id', '$addedresource_item','$addedresourceid[$i]','".$lastorder."')";
  225. $result = Database::query($sql);
  226. $addedresourceassigned[$i] = 1;
  227. $resource_added = true;
  228. }
  229. $i ++;
  230. $lastorder ++;
  231. }
  232. //$_SESSION['addedresource']=null;
  233. //$_SESSION['addedresourceid']=null;
  234. // cleaning up the session once again
  235. $_SESSION['addedresource'] = null;
  236. $_SESSION['addedresourceid'] = null;
  237. $_SESSION['addedresourceassigned'] = null;
  238. unset ($_SESSION['addedresource']);
  239. unset ($_SESSION['addedresourceid']);
  240. unset ($_SESSION['addedresourceassigned']);
  241. }
  242. }
  243. /*
  244. ==============================================================================
  245. BREADCRUMBS
  246. This part is to allow going back to the tool where you came from
  247. in a previous version I used the table tool_list, but since the forum can access the
  248. resource_linker from two different pages (newtopic.php and editpost.php) and this is different
  249. from the link field in tool_list, I decide to hardcode this stuff here.
  250. By doing this, you can easily control which pages can access the toollinker and which not.
  251. ==============================================================================
  252. */
  253. if ($_GET["source_id"])
  254. {
  255. switch ($_GET["source_id"])
  256. {
  257. case "1" : // coming from Agenda
  258. if ($action == "edit")
  259. {
  260. $url = "../calendar/agenda.php?action=edit&id=49&originalresource=$originalresource";
  261. }
  262. elseif ($action == "add")
  263. {
  264. $url = "../calendar/agenda.php?action=add&originalresource=$originalresource";
  265. }
  266. else
  267. {
  268. $url = "../calendar/agenda.php?action=add";
  269. }
  270. $originaltoolname = get_lang("Agenda");
  271. $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
  272. session_unregister('from_learnpath');
  273. unset ($from_learnpath);
  274. break;
  275. case "2" : // coming from forum: new topic
  276. $url = "../phpbb/newtopic.php?forum=$source_forum&md5=$md5";
  277. $originaltoolname = get_lang("ForumAddNewTopic");
  278. $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
  279. session_unregister('from_learnpath');
  280. unset ($from_learnpath);
  281. break;
  282. case "3" : // coming from forum: edit topic
  283. $url = "../phpbb/editpost.php?post_id=$post_id&topic=$topic&forum=$forum&md5=$md5&originalresource=no";
  284. $originaltoolname = get_lang("ForumEditTopic");
  285. $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
  286. session_unregister('from_learnpath');
  287. unset ($from_learnpath);
  288. break;
  289. case "4" : // coming from exercises: edit topic
  290. $url = "../exercice/admin.php?modifyAnswers=$modifyAnswers";
  291. $originaltoolname = get_lang("ExerciseAnswers");
  292. $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
  293. session_unregister('from_learnpath');
  294. unset ($from_learnpath);
  295. break;
  296. case "5" : // coming from learning path
  297. $from_learnpath = 'yes';
  298. Session::write('from_learnpath',$from_learnpath);
  299. break;
  300. /*************************************** end add Frederik.Vermeire@pandora.be *********************************/
  301. }
  302. // We do not come from the learning path. We store the name of the tool & url in a session.
  303. if ($from_learnpath != 'yes')
  304. {
  305. if (!$_SESSION["origintoolurl"] OR $_SESSION["origintoolurl"]<>$interbreadcrumb["url"])
  306. {
  307. $_SESSION["origintoolurl"] = $breadcrumbelement["url"];
  308. $_SESSION["origintoolname"] = $breadcrumbelement["name"];
  309. $interbreadcrumb = "";
  310. }
  311. }
  312. }
  313. // This part of the code is the actual breadcrumb mechanism. If we do not come from the learning path we use
  314. // the information from the session. Else we use the information of the learningpath itself.
  315. if ($from_learnpath != 'yes')
  316. {
  317. $nameTools = get_lang('AddResource');
  318. $interbreadcrumb[] = array ("url" => $_SESSION["origintoolurl"], "name" => $_SESSION["origintoolname"]);
  319. }
  320. else
  321. {
  322. $learnpath_select_query = " SELECT * FROM $tbl_learnpath_main
  323. WHERE learnpath_id=$learnpath_id";
  324. $sql_result = Database::query($learnpath_select_query);
  325. $therow = Database::fetch_array($sql_result);
  326. $learnpath_chapter_query = " SELECT * FROM $tbl_learnpath_chapter
  327. WHERE (learnpath_id = '$learnpath_id' and id = '$chapter_id')";
  328. $sql_result = Database::query($learnpath_chapter_query);
  329. $therow2 = Database::fetch_array($sql_result);
  330. $from_learnpath = 'yes';
  331. session_register('from_learnpath');
  332. $interbreadcrumb[] = array ("url" => "../scorm/scormdocument.php", "name" => get_lang('LearningPath'));
  333. $interbreadcrumb[] = array ("url" => "../learnpath/learnpath_handler.php?learnpath_id=$learnpath_id", "name" => "{$therow['learnpath_name']}");
  334. $interbreadcrumb[] = array ("url" => api_get_self()."?action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no", "name" => "{$therow2['chapter_name']}");
  335. }
  336. $htmlHeadXtra[] = '<script type="text/javascript">
  337. /* <![CDATA[ */
  338. function targetfunc(input)
  339. {
  340. window.location=window.location+"&amp;target="+document.learnpath_link.target.value;
  341. }
  342. /* ]]> */
  343. </script>';
  344. Display :: display_header($nameTools);
  345. echo "<h3>".$nameTools;
  346. if ($from_learnpath == 'yes')
  347. {
  348. echo get_lang("AddResource")." - {$therow2['chapter_name']}";
  349. }
  350. echo "</h3>";
  351. // we retrieve the tools that are active.
  352. // We use this to check which resources a student may add (only the modules that are active)
  353. // see http://www.dokeos.com/forum/viewtopic.php?t=4858
  354. $active_modules=array();
  355. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  356. $sql_select_active="SELECT * FROM $tool_table WHERE visibility='1'";
  357. $result_select_active=Database::query($sql_select_active);
  358. while ($row=Database::fetch_array($result_select_active))
  359. {
  360. $active_modules[]=$row['name'];
  361. }
  362. ?>
  363. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  364. <tr>
  365. <td width="300" valign="top" style='padding-right:15px;'>
  366. <table width="300" border="0" cellspacing="0" cellpadding="0" style='border-right:1px solid grey;'>
  367. <?php if ($from_learnpath != 'yes') { ?>
  368. <tr>
  369. <td width="26%"><b><?php echo get_lang('CourseResources'); ?></b></td>
  370. </tr>
  371. <?php
  372. if (api_is_allowed_to_edit() OR in_array(TOOL_DOCUMENT,$active_modules))
  373. {
  374. ?>
  375. <tr>
  376. <td><?php echo "<a href=\"".api_get_self()."?content=Document&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Document')."</a>"; ?></td>
  377. </tr>
  378. <?php
  379. }
  380. if (api_is_allowed_to_edit() OR in_array(TOOL_CALENDAR_EVENT,$active_modules))
  381. {
  382. ?>
  383. <tr>
  384. <td><?php echo "<a href=\"".api_get_self()."?content=Agenda&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Agenda')."</a>"; ?></td>
  385. </tr>
  386. <?php
  387. }
  388. if (api_is_allowed_to_edit() OR in_array(TOOL_ANNOUNCEMENT,$active_modules))
  389. {
  390. ?>
  391. <tr>
  392. <td><?php echo "<a href=\"".api_get_self()."?content=Ad_Valvas&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('AdValvas')."</a>"; ?></td>
  393. </tr>
  394. <?php
  395. }
  396. if (api_is_allowed_to_edit() OR in_array(TOOL_BB_FORUM,$active_modules))
  397. {
  398. ?>
  399. <tr>
  400. <td><?php echo "<a href=\"".api_get_self()."?content=Forum&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Forum')."</a>"; ?></td>
  401. </tr>
  402. <?php
  403. }
  404. if (api_is_allowed_to_edit() OR in_array(TOOL_LINK,$active_modules))
  405. {
  406. ?>
  407. <tr>
  408. <td><?php echo "<a href=\"".api_get_self()."?content=Link&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Link')."</a>"; ?></td>
  409. </tr>
  410. <?php
  411. }
  412. if (api_is_allowed_to_edit() OR in_array(TOOL_QUIZ,$active_modules))
  413. {
  414. ?>
  415. <tr>
  416. <td><?php echo "<a href=\"".api_get_self()."?content=Exercise&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Exercise')."</a>"; ?></td>
  417. </tr>
  418. <?php
  419. }
  420. }
  421. else
  422. {
  423. ?>
  424. <tr>
  425. <td width="26%"><b><?php echo get_lang('ExportableCourseResources'); ?></b></td>
  426. </tr>
  427. <?php if ($multi_level_learnpath === true ) { ?>
  428. <tr>
  429. <td><?php echo "<a href=\"".api_get_self()."?content=chapter&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Chapter')."</a>"; ?></td>
  430. </tr>
  431. <?php } ?>
  432. <tr>
  433. <td><?php echo "<a href=\"".api_get_self()."?content=Document&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Document')."</a>"; ?></td>
  434. </tr>
  435. <tr>
  436. <td><?php echo "<a href=\"".api_get_self()."?content=Exercise&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Exercise')."</a>"; ?></td>
  437. </tr>
  438. <tr>
  439. <td><?php echo "<a href=\"".api_get_self()."?content=Link&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Link')."</a>"; ?></td>
  440. </tr>
  441. <tr>
  442. <td><?php echo "<a href=\"".api_get_self()."?content=Forum&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Forum')."</a>"; ?></td>
  443. </tr>
  444. <tr>
  445. <td><?php echo "<a href=\"".api_get_self()."?content=Agenda&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Agenda')."</a>"; ?></td>
  446. </tr>
  447. <tr>
  448. <td><?php echo "<a href=\"".api_get_self()."?content=Ad_Valvas&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('AdValvas')."</a>"; ?></td>
  449. </tr>
  450. <tr>
  451. <td><?php echo "<a href=\"".api_get_self()."?content=Course_description&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('CourseDescription')."</a>"; ?></td>
  452. </tr>
  453. <tr>
  454. <td><?php echo "<a href=\"".api_get_self()."?content=Introduction_text&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('IntroductionText')."</a>"; ?></td>
  455. </tr>
  456. <tr>
  457. <td>&nbsp;</td>
  458. </tr>
  459. <tr>
  460. <td width="26%"><b><?php echo get_lang('LMSRelatedCourseMaterial'); ?></b></td>
  461. </tr>
  462. <tr>
  463. <td><?php echo "<a href=\"".api_get_self()."?content=Dropbox&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Dropbox')."</a>"; ?></td>
  464. </tr>
  465. <tr>
  466. <td><?php echo "<a href=\"".api_get_self()."?content=Assignment&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Assignments')."</a>"; ?></td>
  467. </tr>
  468. <tr>
  469. <td><?php echo "<a href=\"".api_get_self()."?content=Groups&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Groups')."</a>"; ?></td>
  470. </tr>
  471. <tr>
  472. <td><?php echo "<a href=\"".api_get_self()."?content=Users&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('Users')."</a>"; ?></td>
  473. </tr>
  474. <?php
  475. }
  476. ?>
  477. <tr>
  478. <td>&nbsp;</td>
  479. </tr>
  480. <tr>
  481. <td><b><?php echo get_lang("ExternalResources"); ?></b></td>
  482. </tr>
  483. <tr>
  484. <td><?php echo "<a href=\"".api_get_self()."?content=Externallink&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('ExternalLink')."</a>"; ?></td>
  485. </tr>
  486. <?php
  487. if ($from_learnpath != 'yes')
  488. {
  489. echo "<tr><td>&nbsp;</td></tr>";
  490. echo "<tr><td><b>".get_lang('ResourcesAdded')." (";
  491. echo count($addedresource);
  492. echo ")</b></td></tr>";
  493. echo "<tr><td nowrap><a href=\"".api_get_self()."?showresources=true&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('ShowDelete')."</a>";
  494. echo "</td></tr>";
  495. }
  496. ?>
  497. <tr>
  498. <td>&nbsp;</td>
  499. </tr>
  500. <!--<tr>
  501. <td><b><?php echo get_lang('BackTo'); ?></b></td>
  502. </tr>//-->
  503. <tr>
  504. <td>
  505. <?php
  506. if ($from_learnpath != 'yes')
  507. {
  508. echo "<form method=\"post\" action=\"{$_SESSION['origintoolurl']}\" style=\"margin: 0px;\"><input type=\"submit\" value=\"".get_lang('Ok')."\"></form>";
  509. }
  510. else
  511. {
  512. echo "<form method=\"get\" action=\"../learnpath/learnpath_handler.php\" style=\"margin: 0px;\"><input type=\"hidden\" name=\"learnpath_id\" value=\"".htmlentities($learnpath_id)."\"><input type=\"submit\" value=\"".' '.get_lang('Ok').' '."\"></form>";
  513. }
  514. ?>
  515. </td>
  516. </tr>
  517. <tr>
  518. <td>&nbsp;</td>
  519. </tr>
  520. </table>
  521. </td>
  522. <td valign="top">
  523. <?php
  524. if ($resource_added)
  525. {
  526. Display :: display_normal_message(get_lang("ResourceAdded"));
  527. }
  528. if ($from_learnpath != 'yes')
  529. {
  530. echo count($addedresource)." ".api_strtolower(get_lang('ResourcesAdded'))."<br/>";
  531. }
  532. //echo "<hr>";
  533. // Agenda items -->
  534. if ($content == "Agenda")
  535. {
  536. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  537. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  538. $sql="SELECT agenda.*, toolitemproperties.*
  539. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  540. WHERE agenda.id = toolitemproperties.ref
  541. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  542. AND (toolitemproperties.to_group_id='0' OR toolitemproperties.to_group_id IS NULL)
  543. AND toolitemproperties.visibility='1'";
  544. $result = Database::query($sql);
  545. while ($myrow = Database::fetch_array($result))
  546. {
  547. echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\">";
  548. echo "<img src='../img/agenda.gif' alt='agenda'>";
  549. echo api_convert_and_format_date($myrow["start_date"], null, date_default_timezone_get())."<br />";
  550. echo "<b>".$myrow["title"]."</b></td></tr><tr><td>";
  551. echo $myrow["content"]."<br />";
  552. showorhide_addresourcelink($content, $myrow["id"]);
  553. echo "</td></tr></table><br />";
  554. }
  555. } // end if ($_GET["resource"]=="Agenda")
  556. /*
  557. -----------------------------------------------------------
  558. chapter
  559. -----------------------------------------------------------
  560. */
  561. if ($content == "chapter")
  562. {
  563. echo '<table><form name="add_chapter" action="'.'" method="POST">'."\n";
  564. echo ' <tr><td>'.get_lang('Title').'</td><td><input type="text" name="title" value="'.$title.'"></input></td></tr>'."\n";
  565. echo ' <tr><td>'.get_lang('Description').'</td><td><input type="text" name="description" value="'.$description.'"></input></td></tr>'."\n";
  566. echo ' <tr><td></td><td><input type="submit" name="add_chapter" value="'.get_lang('AddIt').'"/></td></tr>'."\n";
  567. echo '</form></table>'."\n";
  568. //echo "<hr>";
  569. }
  570. /*
  571. -----------------------------------------------------------
  572. Documents
  573. -----------------------------------------------------------
  574. */
  575. // We show the documents in the following cases
  576. // 1. the link to add documenets in the resource linker was clicked
  577. // 2. we come to the resource linker for the first time (documents = default). In this case it can only be shown if
  578. // a. one is a teacher (documents can be shown even if the tool is inactive)
  579. // b. one is a student AND the documents tool is active. Student cannot add documents if the documents tool is inactive (teacher can do this)
  580. if ($content == "Document" OR (empty($content) AND (api_is_allowed_to_edit() OR in_array(TOOL_DOCUMENT,$active_modules))) AND !$_GET['showresources'])
  581. {
  582. // setting variables for file locations
  583. $baseServDir = $_configuration['root_sys'];
  584. $courseDir = $_course['path']."/document";
  585. $baseWorkDir = $baseServDir.$courseDir;
  586. // showing the link to move one folder up (when not in the root folder)
  587. show_folder_up();
  588. // showing the blue bar with the path in it when we are not in the root
  589. if (get_levels($folder))
  590. {
  591. echo "<table width=\"100%\"><tr><td bgcolor=\"#4171B5\">";
  592. echo "<img src=\"../img/opendir.gif\" alt='directory'><font color=\"#ffffff\"><b>";
  593. echo $folder."</b></font></td></tr></table>";
  594. }
  595. // showing the documents and subfolders of the folder we are in.
  596. show_documents($folder);
  597. //echo "<hr>";
  598. }
  599. /*
  600. -----------------------------------------------------------
  601. Ad Valvas
  602. -----------------------------------------------------------
  603. */
  604. if ($content == "Ad_Valvas")
  605. {
  606. $tbl_announcement = Database :: get_course_table(TABLE_ANNOUNCEMENT);
  607. $sql = "SELECT * FROM ".$tbl_announcement." a, ".$item_property_table." i
  608. WHERE
  609. i.tool = '".TOOL_ANNOUNCEMENT."' AND
  610. a.id=i.ref AND
  611. i.visibility='1' AND
  612. (i.to_group_id = 0 OR i.to_group_id IS NULL) AND
  613. i.to_user_id IS NULL
  614. ORDER BY a.display_order ASC";
  615. $result = Database::query($sql);
  616. while ($myrow = Database::fetch_array($result))
  617. {
  618. echo "<table width=\"100%\"><tr><td>";
  619. echo "<img src='../img/valves.gif' alt='advalvas'>";
  620. echo api_convert_and_format_date($myrow["end_date"], DATE_FORMAT_LONG, date_default_timezone_get());
  621. echo "</td></tr><tr><td>";
  622. echo $myrow["title"]."<br />";
  623. showorhide_addresourcelink($content, $myrow["id"]);
  624. echo "</td></tr></table>";
  625. }
  626. }
  627. /*
  628. -----------------------------------------------------------
  629. Forums
  630. -----------------------------------------------------------
  631. */
  632. if ($content == "Forum")
  633. {
  634. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  635. $TBL_CATAGORIES = Database::get_course_table(TABLE_FORUM_CATEGORY);
  636. $TBL_FORUMTOPICS = Database::get_course_table(TABLE_FORUM_POST);
  637. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST);
  638. $tbl_posts_text = Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE);
  639. echo "<table width='100%'>";
  640. // displaying the categories and the forums
  641. if (!$forum and !$thread)
  642. {
  643. $sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_CATAGORIES." categories WHERE forums.cat_id=categories.cat_id ORDER BY forums.cat_id DESC";
  644. $result = Database::query($sql);
  645. while ($myrow = Database::fetch_array($result))
  646. {
  647. if ($myrow["cat_title"] !== $old_cat_title)
  648. {
  649. echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
  650. }
  651. $old_cat_title = $myrow["cat_title"];
  652. echo "<tr><td><img src='../img/forum.gif'><a href='".api_get_self()."?content=Forum&category=".$myrow["cat_id"]."&forum=".$myrow["forum_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["forum_name"]."</td><td>";
  653. showorhide_addresourcelink("Forum", $myrow["forum_id"]);
  654. echo "</td></tr>";
  655. }
  656. }
  657. //displaying all the threads of one forum
  658. if ($forum)
  659. {
  660. // displaying the category title
  661. $sql = "SELECT * FROM ".$TBL_CATAGORIES." WHERE cat_id=$category";
  662. $result = Database::query($sql);
  663. $myrow = Database::fetch_array($result);
  664. echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
  665. // displaying the forum title
  666. $sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_FORUMTOPICS." topics WHERE forums.forum_id=topics.forum_id";
  667. $result = Database::query($sql);
  668. $myrow = Database::fetch_array($result);
  669. echo "<tr><td bgcolor='#cccccc' colspan='2'><b>".$myrow["forum_name"]."</b></td></tr>";
  670. if (!$thread)
  671. {
  672. // displaying all the threads of this forum
  673. $sql = "SELECT * FROM ".$TBL_FORUMTOPICS." WHERE forum_id=$forum";
  674. $result = Database::query($sql);
  675. while ($myrow = Database::fetch_array($result))
  676. {
  677. echo "<tr><td><a href='".api_get_self()."?content=Forum&category=$category&forum=1&thread=".$myrow["topic_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["topic_title"]."</a> (".$myrow["prenom"]." ".$myrow["nom"].")</td><td>";
  678. showorhide_addresourcelink("Thread", $myrow["topic_id"]);
  679. echo "</td></tr>";
  680. }
  681. }
  682. else
  683. {
  684. // displaying all the replies
  685. $sql = "SELECT * FROM ".$tbl_posts." post, ".$tbl_posts_text." post_text WHERE post_text.post_id=post.post_id and post.topic_id=$thread ORDER BY post_text.post_id ASC";
  686. $result = Database::query($sql);
  687. while ($myrow = Database::fetch_array($result))
  688. {
  689. echo "<tr><td><b>".$myrow["post_title"]."</b><br>";
  690. echo $myrow["post_text"]."</td>";
  691. echo "<td>";
  692. showorhide_addresourcelink("Post", $myrow["post_id"]);
  693. echo "</td></tr><tr><td colspan='2'><hr noshade></td></tr>";
  694. }
  695. }
  696. }
  697. echo "</table>";
  698. }
  699. /*
  700. -----------------------------------------------------------
  701. Links
  702. -----------------------------------------------------------
  703. */
  704. if ($content == "Link")
  705. {
  706. // including the links language file
  707. include ("../lang/$language/link.inc.php");
  708. $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
  709. if (($learnpath_id != '') and ($content == 'Link'))
  710. {
  711. echo "<form name='learnpath_link'><table>";
  712. echo "<tr></td><td align='left'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target' onchange='targetfunc()'><option value='_self' ";
  713. if ($target == '_self')
  714. {
  715. echo "selected";
  716. }
  717. echo ">".get_lang('SameWindow')."</option><option value='_blank'";
  718. if ($target == '_blank')
  719. {
  720. echo "selected";
  721. }
  722. echo ">".get_lang('NewWindow')."</option></select></td></tr></table></form>";
  723. }
  724. // showing the links that are in the root (having no category)
  725. $sql = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE (l.category_id=0 or l.category_id IS NULL) AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1'";
  726. $result = Database::query($sql);
  727. if (Database::num_rows($result) > 0)
  728. {
  729. echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".get_lang('NoCategory')."</i></td></tr></table>";
  730. while ($myrow = Database::fetch_array($result))
  731. {
  732. echo "<img src='../img/links.gif'>".$myrow["title"];
  733. echo "<br>";
  734. showorhide_addresourcelink($content, $myrow["id"]);
  735. echo "<br><br>";
  736. }
  737. }
  738. // showing the categories and the links in it.
  739. $sqlcategories = "SELECT * FROM ".$tbl_categories." ORDER by display_order DESC";
  740. $resultcategories = Database::query($sqlcategories) or die;
  741. while ($myrow = @ Database::fetch_array($resultcategories))
  742. {
  743. $sql_links = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE l.category_id='".$myrow["id"]."' AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1' ORDER BY l.display_order DESC";
  744. echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".$myrow["category_title"]."</i></td></tr></table>";
  745. $result_links = Database::query($sql_links);
  746. while ($myrow = Database::fetch_array($result_links))
  747. {
  748. echo "<img src='../img/links.gif' />".$myrow["title"];
  749. echo "<br>";
  750. showorhide_addresourcelink($content, $myrow["id"]);
  751. echo "<br><br>";
  752. }
  753. }
  754. }
  755. /*
  756. -----------------------------------------------------------
  757. Exercise
  758. -----------------------------------------------------------
  759. */
  760. if (($content == "Exercise") or ($content == "HotPotatoes"))
  761. {
  762. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  763. $result = Database::query("SELECT * FROM ".$TBL_EXERCICES." WHERE active='1' ORDER BY id ASC");
  764. while ($myrow = Database::fetch_array($result))
  765. {
  766. echo "<img src='../img/quiz.gif'>".$myrow["title"]."<br>";
  767. showorhide_addresourcelink($content, $myrow["id"]);
  768. echo "<br><br>";
  769. }
  770. if ($from_learnpath == 'yes')
  771. {
  772. $uploadPath = "/HotPotatoes_files";
  773. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  774. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  775. $sql = "SELECT * FROM ".$TBL_DOCUMENT." WHERE (path LIKE '%htm%' OR path LIKE '%html%') AND path LIKE '".$uploadPath."/%/%' ORDER BY id ASC";
  776. $result = Database::query($sql);
  777. while ($myrow = Database::fetch_array($result))
  778. {
  779. $path = $myrow["path"];
  780. echo "<img src='../img/jqz.gif'>".GetQuizName($path, $documentPath)."<br>";
  781. showorhide_addresourcelink("HotPotatoes", $myrow["id"]);
  782. echo "<br><br>";
  783. }
  784. }
  785. }
  786. /*
  787. -----------------------------------------------------------
  788. External Links
  789. -----------------------------------------------------------
  790. */
  791. if ($content == "Externallink")
  792. {
  793. ?>
  794. <form name="form1" method="post" action="">
  795. <table width="80%" border="0" cellspacing="0" cellpadding="0">
  796. <tr>
  797. <td align="right"><?php echo get_lang('ExternalLink'); ?> : &nbsp;</td>
  798. <td align="left"><input name="external_link" type="text" id="external_link" value="http://"></td>
  799. <?php
  800. if ($learnpath_id != '')
  801. {
  802. echo "</tr><tr><td align='right'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target'><option value='_self'>".get_lang('SameWindow')."</option><option value='_blank'>".get_lang('NewWindow')."</option></select></td>";
  803. }
  804. ?>
  805. </tr>
  806. <tr>
  807. <td><?php if ($is_allowedToEdit) {echo get_lang('AddToLinks');} ?></td>
  808. <td>
  809. <?php if ($is_allowedToEdit){?>
  810. <select name="add_2_links" id="add_2_links">
  811. <option value="niet toevoegen" selected="selected">-<?php echo get_lang('DontAdd'); ?>-</option>
  812. <option value="0"><?php echo get_lang('MainCategory'); ?></option>
  813. <?php
  814. $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
  815. $sql = "SELECT * FROM $tbl_categories ORDER BY display_order ASC";
  816. echo $sql;
  817. $result = Database::query($sql);
  818. while ($row = Database::fetch_array($result))
  819. {
  820. echo "<option value='".$row["id"]."'>".$row["category_title"]."</option>";
  821. }
  822. ?>
  823. </select><?php } ?></td>
  824. </tr>
  825. <tr>
  826. <td>&nbsp;</td>
  827. <td><input name="external_link_submit" type="submit" id="external_link_submit" value="<?php echo get_lang('AddIt'); ?>"></td>
  828. </tr>
  829. <tr>
  830. <td>&nbsp;</td>
  831. <td>&nbsp;</td>
  832. </tr>
  833. <tr>
  834. <td colspan="2">&nbsp;</td>
  835. </tr>
  836. </table>
  837. </form>
  838. <?php
  839. }
  840. /*
  841. -----------------------------------------------------------
  842. Assignments
  843. -----------------------------------------------------------
  844. */
  845. if ($content == "Assignment")
  846. {
  847. echo "<a href=".api_get_self()."?content=Ass&add=Ass&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no>".get_lang('AddAssignmentPage')."</a>";
  848. }
  849. /*
  850. -----------------------------------------------------------
  851. Dropbox
  852. -----------------------------------------------------------
  853. */
  854. if ($content == "Dropbox")
  855. {
  856. echo "<a href='".api_get_self()."?content=Drop&add=Drop&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('DropboxAdd')."</a>";
  857. }
  858. /*
  859. -----------------------------------------------------------
  860. Introduction text
  861. -----------------------------------------------------------
  862. */
  863. if ($content == "Introduction_text")
  864. {
  865. echo "<a href='".api_get_self()."?content=Intro&add=Intro&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('IntroductionTextAdd')."</a>";
  866. }
  867. /*
  868. -----------------------------------------------------------
  869. Course description
  870. -----------------------------------------------------------
  871. */
  872. if ($content == "Course_description")
  873. {
  874. echo "<a href='".api_get_self()."?content=Course_desc&add=Course_desc&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('CourseDescriptionAdd')."</a>";
  875. }
  876. /*
  877. -----------------------------------------------------------
  878. Groups
  879. -----------------------------------------------------------
  880. */
  881. if ($content == "Groups")
  882. {
  883. echo "<a href='".api_get_self()."?content=Group&add=Group&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('$GroupsAdd')."</a>";
  884. }
  885. /*
  886. -----------------------------------------------------------
  887. Users
  888. -----------------------------------------------------------
  889. */
  890. if ($content == "Users")
  891. {
  892. echo "<a href='".api_get_self()."?content=User&add=User&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('UsersAdd')."</a>";
  893. }
  894. if ($showresources)
  895. {
  896. //echo "<h4>".get_lang('ResourceAdded')."</h4>";
  897. display_resources(1);
  898. }
  899. echo "</td></tr></table>";
  900. /*
  901. FOOTER
  902. */
  903. Display :: display_footer();
  904. ?>