link.php 6.8 KB

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