resourcelinker.php 41 KB

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