link.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. *
  18. * @package chamilo.link
  19. */
  20. require_once __DIR__.'/../inc/global.inc.php';
  21. $current_course_tool = TOOL_LINK;
  22. $this_section = SECTION_COURSES;
  23. api_protect_course_script(true);
  24. $htmlHeadXtra[] = '<script>
  25. $(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[] = ['url' => 'link.php', 'name' => get_lang('Links')];
  67. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add a link')];
  68. }
  69. if ($action === 'addcategory') {
  70. $nameTools = '';
  71. $interbreadcrumb[] = ['url' => 'link.php', 'name' => get_lang('Links')];
  72. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add category')];
  73. }
  74. if ($action === 'editlink') {
  75. $nameTools = get_lang('Edit link');
  76. $interbreadcrumb[] = ['url' => 'link.php', 'name' => get_lang('Links')];
  77. }
  78. // Statistics
  79. Event::event_access_tool(TOOL_LINK);
  80. /* Action Handling */
  81. $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
  82. $scope = isset($_REQUEST['scope']) ? $_REQUEST['scope'] : null;
  83. $show = isset($_REQUEST['show']) && in_array(trim($_REQUEST['show']), ['all', 'none']) ? $_REQUEST['show'] : '';
  84. $categoryId = isset($_REQUEST['category_id']) ? (int) $_REQUEST['category_id'] : '';
  85. $linkListUrl = api_get_self().'?'.api_get_cidreq().'&category_id='.$categoryId.'&show='.$show;
  86. $content = '';
  87. $token = Security::get_existing_token();
  88. $protectedActions = [
  89. 'addlink',
  90. 'editlink',
  91. 'addcategory',
  92. 'editcategory',
  93. 'deletelink',
  94. 'deletecategory',
  95. 'visible',
  96. 'invisible',
  97. 'up',
  98. 'down',
  99. 'move_link_up',
  100. 'move_link_down',
  101. ];
  102. // block access
  103. if (in_array($action, $protectedActions) &&
  104. !api_is_allowed_to_edit(null, true)
  105. ) {
  106. api_not_allowed(true);
  107. }
  108. switch ($action) {
  109. case 'addlink':
  110. $form = Link::getLinkForm(null, 'addlink', $token);
  111. if ($form->validate() && Security::check_token('get')) {
  112. // Here we add a link
  113. $linkId = Link::addlinkcategory('link');
  114. Skill::saveSkills($form, ITEM_TYPE_LINK, $linkId);
  115. Security::clear_token();
  116. header('Location: '.$linkListUrl);
  117. exit;
  118. }
  119. $content = $form->returnForm();
  120. break;
  121. case 'editlink':
  122. $form = Link::getLinkForm($id, 'editlink');
  123. if ($form->validate()) {
  124. Link::editLink($id, $form->getSubmitValues());
  125. Skill::saveSkills($form, ITEM_TYPE_LINK, $id);
  126. header('Location: '.$linkListUrl);
  127. exit;
  128. }
  129. $content = $form->returnForm();
  130. break;
  131. case 'addcategory':
  132. $form = Link::getCategoryForm(null, 'addcategory');
  133. if ($form->validate()) {
  134. // Here we add a category
  135. Link::addlinkcategory('category');
  136. header('Location: '.$linkListUrl);
  137. exit;
  138. }
  139. $content = $form->returnForm();
  140. break;
  141. case 'editcategory':
  142. $form = Link::getCategoryForm($id, 'editcategory');
  143. if ($form->validate()) {
  144. // Here we edit a category
  145. Link::editCategory($id, $form->getSubmitValues());
  146. header('Location: '.$linkListUrl);
  147. exit;
  148. }
  149. $content = $form->returnForm();
  150. break;
  151. case 'deletelink':
  152. // Here we delete a link
  153. Link::deletelinkcategory($id, 'link');
  154. header('Location: '.$linkListUrl);
  155. exit;
  156. break;
  157. case 'deletecategory':
  158. // Here we delete a category
  159. Link::deletelinkcategory($id, 'category');
  160. header('Location: '.$linkListUrl);
  161. exit;
  162. break;
  163. case 'visible':
  164. // Here we edit a category
  165. Link::change_visibility_link($id, $scope);
  166. header('Location: '.$linkListUrl);
  167. exit;
  168. break;
  169. case 'invisible':
  170. // Here we edit a category
  171. Link::change_visibility_link($id, $scope);
  172. header('Location: '.$linkListUrl);
  173. exit;
  174. break;
  175. case 'up':
  176. Link::movecatlink('up', $up);
  177. header('Location: '.$linkListUrl);
  178. exit;
  179. break;
  180. case 'down':
  181. Link::movecatlink('down', $down);
  182. header('Location: '.$linkListUrl);
  183. exit;
  184. break;
  185. case 'move_link_up':
  186. Link::moveLinkUp($id);
  187. header('Location: '.$linkListUrl);
  188. exit;
  189. break;
  190. case 'move_link_down':
  191. Link::moveLinkDown($id);
  192. header('Location: '.$linkListUrl);
  193. exit;
  194. break;
  195. case 'export':
  196. $content = Link::listLinksAndCategories($course_id, $session_id, $categoryId, $show, null, false, true);
  197. $courseInfo = api_get_course_info_by_id($course_id);
  198. if (!empty($session_id)) {
  199. $sessionInfo = api_get_session_info($session_id);
  200. $courseInfo['title'] = $courseInfo['title'].' '.$sessionInfo['name'];
  201. }
  202. $pdf = new PDF();
  203. $pdf->content_to_pdf(
  204. $content,
  205. null,
  206. $courseInfo['title'].'_'.get_lang('Link'),
  207. $courseInfo['code'],
  208. 'D',
  209. false,
  210. null,
  211. false,
  212. true
  213. );
  214. break;
  215. case 'list':
  216. default:
  217. $content = Link::listLinksAndCategories($course_id, $session_id, $categoryId, $show);
  218. break;
  219. }
  220. Display::display_header($nameTools, 'Links');
  221. Display::display_introduction_section(TOOL_LINK);
  222. echo $content;
  223. Display::display_footer();