link.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Main script for the links tool.
  5. *
  6. * Features:
  7. * - Organize links into categories;
  8. * - favorites/bookmarks-like interface;
  9. * - move links up/down within a category;
  10. * - move categories up/down;
  11. * - expand/collapse all categories (except the main "non"-category);
  12. * - add link to 'root' category => category-less link is always visible.
  13. *
  14. * @author Julio Montoya code rewritten
  15. * @author Patrick Cool
  16. * @author René Haentjens, added CSV file import (October 2004)
  17. * @package chamilo.link
  18. */
  19. require_once __DIR__.'/../inc/global.inc.php';
  20. $current_course_tool = TOOL_LINK;
  21. $this_section = SECTION_COURSES;
  22. api_protect_course_script(true);
  23. $htmlHeadXtra[] = '<script>
  24. $(document).ready( function() {
  25. for (i=0;i<$(".actions").length;i++) {
  26. if ($(".actions:eq("+i+")").html()=="<table border=\"0\"></table>" || $(".actions:eq("+i+")").html()=="" || $(".actions:eq("+i+")").html()==null) {
  27. $(".actions:eq("+i+")").hide();
  28. }
  29. }
  30. });
  31. function check_url(id, url) {
  32. var url = "'.api_get_path(WEB_AJAX_PATH).'link.ajax.php?a=check_url&url=" +url;
  33. var loading = " '.addslashes(Display::return_icon('loading1.gif')).'";
  34. $("#url_id_"+id).html(loading);
  35. $("#url_id_"+id).load(url);
  36. }
  37. </script>';
  38. // @todo change the $_REQUEST into $_POST or $_GET
  39. // @todo remove this code
  40. $link_submitted = isset($_POST['submitLink']);
  41. $category_submitted = isset($_POST['submitCategory']);
  42. $urlview = !empty($_GET['urlview']) ? $_GET['urlview'] : '';
  43. $submit_import = !empty($_POST['submitImport']) ? $_POST['submitImport'] : '';
  44. $down = !empty($_GET['down']) ? $_GET['down'] : '';
  45. $up = !empty($_GET['up']) ? $_GET['up'] : '';
  46. $catmove = !empty($_GET['catmove']) ? $_GET['catmove'] : '';
  47. $editlink = !empty($_REQUEST['editlink']) ? $_REQUEST['editlink'] : '';
  48. $id = !empty($_REQUEST['id']) ? $_REQUEST['id'] : '';
  49. $urllink = !empty($_REQUEST['urllink']) ? $_REQUEST['urllink'] : '';
  50. $title = !empty($_REQUEST['title']) ? $_REQUEST['title'] : '';
  51. $description = !empty($_REQUEST['description']) ? $_REQUEST['description'] : '';
  52. $selectcategory = !empty($_REQUEST['selectcategory']) ? $_REQUEST['selectcategory'] : '';
  53. $submit_link = isset($_REQUEST['submitLink']);
  54. $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
  55. $category_title = !empty($_REQUEST['category_title']) ? $_REQUEST['category_title'] : '';
  56. $submit_category = isset($_POST['submitCategory']);
  57. $target_link = !empty($_REQUEST['target_link']) ? $_REQUEST['target_link'] : '_self';
  58. $nameTools = get_lang('Links');
  59. $course_id = api_get_course_int_id();
  60. // Condition for the session
  61. $session_id = api_get_session_id();
  62. $condition_session = api_get_session_condition($session_id, true, true);
  63. if ($action === 'addlink') {
  64. $nameTools = '';
  65. $interbreadcrumb[] = array('url' => 'link.php', 'name' => get_lang('Links'));
  66. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddLink'));
  67. }
  68. if ($action === 'addcategory') {
  69. $nameTools = '';
  70. $interbreadcrumb[] = array('url' => 'link.php', 'name' => get_lang('Links'));
  71. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddCategory'));
  72. }
  73. if ($action === 'editlink') {
  74. $nameTools = '';
  75. $interbreadcrumb[] = array('url' => 'link.php', 'name' => get_lang('Links'));
  76. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('EditLink'));
  77. }
  78. // Statistics
  79. Event::event_access_tool(TOOL_LINK);
  80. /* Action Handling */
  81. $nameTools = get_lang('Links');
  82. $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
  83. $scope = isset($_REQUEST['scope']) ? $_REQUEST['scope'] : null;
  84. $show = isset($_REQUEST['show']) && in_array(trim($_REQUEST['show']), ['all', 'none']) ? $_REQUEST['show'] : '';
  85. $categoryId = isset($_REQUEST['category_id']) ? intval($_REQUEST['category_id']) : '';
  86. $linkListUrl = api_get_self().'?'.api_get_cidreq().'&category_id='.$categoryId.'&show='.$show;
  87. $content = null;
  88. switch ($action) {
  89. case 'addlink':
  90. if (api_is_allowed_to_edit(null, true)) {
  91. $form = Link::getLinkForm(null, 'addlink');
  92. if ($form->validate()) {
  93. // Here we add a link
  94. Link::addlinkcategory("link");
  95. header('Location: '.$linkListUrl);
  96. exit;
  97. }
  98. $content = $form->returnForm();
  99. }
  100. break;
  101. case 'editlink':
  102. $form = Link::getLinkForm($id, 'editlink');
  103. if ($form->validate()) {
  104. Link::editLink($id, $form->getSubmitValues());
  105. header('Location: '.$linkListUrl);
  106. exit;
  107. }
  108. $content = $form->returnForm();
  109. break;
  110. case 'addcategory':
  111. if (api_is_allowed_to_edit(null, true)) {
  112. $form = Link::getCategoryForm(null, 'addcategory');
  113. if ($form->validate()) {
  114. // Here we add a category
  115. Link::addlinkcategory('category');
  116. header('Location: '.$linkListUrl);
  117. exit;
  118. }
  119. $content = $form->returnForm();
  120. }
  121. break;
  122. case 'editcategory':
  123. if (api_is_allowed_to_edit(null, true)) {
  124. $form = Link::getCategoryForm($id, 'editcategory');
  125. if ($form->validate()) {
  126. // Here we edit a category
  127. Link::editCategory($id, $form->getSubmitValues());
  128. header('Location: '.$linkListUrl);
  129. exit;
  130. }
  131. $content = $form->returnForm();
  132. }
  133. break;
  134. case 'deletelink':
  135. // Here we delete a link
  136. Link::deletelinkcategory($id, 'link');
  137. header('Location: '.$linkListUrl);
  138. exit;
  139. break;
  140. case 'deletecategory':
  141. // Here we delete a category
  142. Link::deletelinkcategory($id, 'category');
  143. header('Location: '.$linkListUrl);
  144. exit;
  145. break;
  146. case 'visible':
  147. // Here we edit a category
  148. Link::change_visibility_link($id, $scope);
  149. header('Location: '.$linkListUrl);
  150. exit;
  151. break;
  152. case 'invisible':
  153. // Here we edit a category
  154. Link::change_visibility_link($id, $scope);
  155. header('Location: '.$linkListUrl);
  156. exit;
  157. break;
  158. case 'up':
  159. Link::movecatlink('up', $up);
  160. header('Location: '.$linkListUrl);
  161. exit;
  162. break;
  163. case 'down':
  164. Link::movecatlink('down', $down);
  165. header('Location: '.$linkListUrl);
  166. exit;
  167. break;
  168. case 'move_link_up':
  169. Link::moveLinkUp($id);
  170. header('Location: ' . $linkListUrl);
  171. exit;
  172. break;
  173. case 'move_link_down':
  174. Link::moveLinkDown($id);
  175. header('Location: ' . $linkListUrl);
  176. exit;
  177. break;
  178. case 'list':
  179. default:
  180. ob_start();
  181. Link::listLinksAndCategories($course_id, $session_id, $categoryId, $show);
  182. $content = ob_get_clean();
  183. break;
  184. }
  185. Display::display_header($nameTools, 'Links');
  186. /* Introduction section */
  187. Display::display_introduction_section(TOOL_LINK);
  188. echo $content;
  189. Display::display_footer();