link.php 7.1 KB

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