link.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 = '';
  88. $token = Security::get_existing_token();
  89. switch ($action) {
  90. case 'addlink':
  91. if (api_is_allowed_to_edit(null, true)) {
  92. $form = Link::getLinkForm(null, 'addlink', $token);
  93. if ($form->validate() && Security::check_token('get')) {
  94. // Here we add a link
  95. Link::addlinkcategory("link");
  96. Security::clear_token();
  97. header('Location: '.$linkListUrl);
  98. exit;
  99. }
  100. $content = $form->returnForm();
  101. }
  102. break;
  103. case 'editlink':
  104. $form = Link::getLinkForm($id, 'editlink');
  105. if ($form->validate()) {
  106. Link::editLink($id, $form->getSubmitValues());
  107. header('Location: '.$linkListUrl);
  108. exit;
  109. }
  110. $content = $form->returnForm();
  111. break;
  112. case 'addcategory':
  113. if (api_is_allowed_to_edit(null, true)) {
  114. $form = Link::getCategoryForm(null, 'addcategory');
  115. if ($form->validate()) {
  116. // Here we add a category
  117. Link::addlinkcategory('category');
  118. header('Location: '.$linkListUrl);
  119. exit;
  120. }
  121. $content = $form->returnForm();
  122. }
  123. break;
  124. case 'editcategory':
  125. if (api_is_allowed_to_edit(null, true)) {
  126. $form = Link::getCategoryForm($id, 'editcategory');
  127. if ($form->validate()) {
  128. // Here we edit a category
  129. Link::editCategory($id, $form->getSubmitValues());
  130. header('Location: '.$linkListUrl);
  131. exit;
  132. }
  133. $content = $form->returnForm();
  134. }
  135. break;
  136. case 'deletelink':
  137. // Here we delete a link
  138. Link::deletelinkcategory($id, 'link');
  139. header('Location: '.$linkListUrl);
  140. exit;
  141. break;
  142. case 'deletecategory':
  143. // Here we delete a category
  144. Link::deletelinkcategory($id, 'category');
  145. header('Location: '.$linkListUrl);
  146. exit;
  147. break;
  148. case 'visible':
  149. // Here we edit a category
  150. Link::change_visibility_link($id, $scope);
  151. header('Location: '.$linkListUrl);
  152. exit;
  153. break;
  154. case 'invisible':
  155. // Here we edit a category
  156. Link::change_visibility_link($id, $scope);
  157. header('Location: '.$linkListUrl);
  158. exit;
  159. break;
  160. case 'up':
  161. Link::movecatlink('up', $up);
  162. header('Location: '.$linkListUrl);
  163. exit;
  164. break;
  165. case 'down':
  166. Link::movecatlink('down', $down);
  167. header('Location: '.$linkListUrl);
  168. exit;
  169. break;
  170. case 'move_link_up':
  171. Link::moveLinkUp($id);
  172. header('Location: '.$linkListUrl);
  173. exit;
  174. break;
  175. case 'move_link_down':
  176. Link::moveLinkDown($id);
  177. header('Location: '.$linkListUrl);
  178. exit;
  179. break;
  180. case 'list':
  181. default:
  182. ob_start();
  183. Link::listLinksAndCategories($course_id, $session_id, $categoryId, $show);
  184. $content = ob_get_clean();
  185. break;
  186. }
  187. Display::display_header($nameTools, 'Links');
  188. /* Introduction section */
  189. Display::display_introduction_section(TOOL_LINK);
  190. echo $content;
  191. Display::display_footer();