access_urls.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Frontend script for multiple access urls
  5. * @package chamilo.admin
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. * @author Yannick Warnier <yannick.warnier@beeznest.com>
  8. */
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. //api_protect_admin_script();
  13. api_protect_global_admin_script();
  14. if (!api_get_multiple_access_url()) {
  15. header('Location: index.php');
  16. exit;
  17. }
  18. $interbreadcrumb[] = array ("url" => 'index.php', 'name' => get_lang('PlatformAdmin'));
  19. $tool_name = get_lang('MultipleAccessURLs');
  20. Display :: display_header($tool_name);
  21. $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
  22. $current_access_url_id = api_get_current_access_url_id();
  23. $url_list = UrlManager::get_url_data();
  24. // Actions
  25. if (isset($_GET['action'])) {
  26. if ($_GET['action'] == 'show_message') {
  27. Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
  28. }
  29. $url_id = (empty($_GET['url_id']) ? 0 : intval($_GET['url_id']));
  30. switch ($_GET['action']) {
  31. case 'delete_url':
  32. $result = UrlManager::delete($url_id);
  33. if ($result) {
  34. Display :: display_normal_message(get_lang('URLDeleted'));
  35. } else {
  36. Display :: display_error_message(get_lang('CannotDeleteURL'));
  37. }
  38. break;
  39. case 'lock':
  40. UrlManager::set_url_status('lock', $url_id);
  41. Display::display_normal_message(get_lang('URLInactive'));
  42. break;
  43. case 'unlock':
  44. UrlManager::set_url_status('unlock', $url_id);
  45. Display::display_normal_message(get_lang('URLActive'));
  46. break;
  47. case 'register':
  48. // we are going to register the admin
  49. if (api_is_platform_admin()) {
  50. if ($current_access_url_id!=-1) {
  51. $url_str = '';
  52. foreach ($url_list as $my_url) {
  53. if (!in_array($my_url['id'], $my_user_url_list)) {
  54. UrlManager::add_user_to_url(api_get_user_id(), $my_url['id']);
  55. $url_str.=$my_url['url'].' <br />';
  56. }
  57. }
  58. Display:: display_normal_message(
  59. get_lang('AdminUserRegisteredToThisURL').': '.$url_str.'<br />',
  60. false
  61. );
  62. }
  63. }
  64. break;
  65. }
  66. }
  67. $parameters['sec_token'] = Security::get_token();
  68. // Checking if the admin is registered in all sites
  69. $url_string = '';
  70. $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
  71. foreach ($url_list as $my_url) {
  72. if (!in_array($my_url['id'], $my_user_url_list)) {
  73. $url_string .= $my_url['url'].' <br />';
  74. }
  75. }
  76. if(!empty($url_string)) {
  77. Display :: display_warning_message(get_lang('AdminShouldBeRegisterInSite').'<br />'.$url_string,false);
  78. }
  79. // checking the current installation
  80. if ($current_access_url_id==-1) {
  81. Display::display_warning_message(get_lang('URLNotConfiguredPleaseChangedTo').': '.api_get_path(WEB_PATH));
  82. } elseif(api_is_platform_admin()) {
  83. $quant= UrlManager::relation_url_user_exist(api_get_user_id(),$current_access_url_id);
  84. if ($quant==0) {
  85. Display:: display_warning_message(
  86. '<a href="'.api_get_self().'?action=register&sec_token='.$parameters['sec_token'].'">'.get_lang('ClickToRegisterAdmin').'</a>',
  87. false
  88. );
  89. }
  90. }
  91. // action menu
  92. echo '<div class="actions">';
  93. echo Display::url(
  94. Display::return_icon('new_link.png', get_lang('AddUrl'), array(), ICON_SIZE_MEDIUM),
  95. api_get_path(WEB_CODE_PATH).'admin/access_url_edit.php'
  96. );
  97. echo Display::url(
  98. Display::return_icon('user.png', get_lang('ManageUsers'), array(), ICON_SIZE_MEDIUM),
  99. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_users_to_url.php'
  100. );
  101. echo Display::url(
  102. Display::return_icon('course.png', get_lang('ManageCourses'), array(), ICON_SIZE_MEDIUM),
  103. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_courses_to_url.php'
  104. );
  105. $userGroup = new UserGroup();
  106. if ($userGroup->getUseMultipleUrl()) {
  107. echo Display::url(
  108. Display::return_icon('class.png', get_lang('ManageUserGroup'), array(), ICON_SIZE_MEDIUM),
  109. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_usergroup_to_url.php'
  110. );
  111. }
  112. if (isMultipleUrlSupport()) {
  113. echo Display::url(
  114. Display::return_icon('folder.png', get_lang('ManageCourseCategories'), array(), ICON_SIZE_MEDIUM),
  115. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_course_category_to_url.php'
  116. );
  117. }
  118. echo '</div>';
  119. $sortable_data = UrlManager::get_url_data();
  120. $urls = array();
  121. foreach ($sortable_data as $row) {
  122. //title
  123. $url = Display::url($row['url'], $row['url'], array('target'=>'_blank'));
  124. $description = $row['description'];
  125. //Status
  126. $active = $row['active'];
  127. if ($active=='1') {
  128. $action='lock';
  129. $image='right';
  130. }
  131. if ($active=='0') {
  132. $action='unlock';
  133. $image='wrong';
  134. }
  135. // you cannot lock the default
  136. if ($row['id']=='1') {
  137. $status = Display::return_icon($image.'.gif', get_lang(ucfirst($action)));
  138. } else {
  139. $status = '<a href="access_urls.php?action='.$action.'&amp;url_id='.$row['id'].'">'.
  140. Display::return_icon($image.'.gif', get_lang(ucfirst($action))).'</a>';
  141. }
  142. // Actions
  143. $url_id = $row['id'];
  144. $actions = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "access_url_edit.php?url_id=$url_id");
  145. if ($url_id != '1') {
  146. $actions .= '<a href="access_urls.php?action=delete_url&amp;url_id='.$url_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;">'.
  147. Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
  148. }
  149. $urls[] = array($url, $description, $status, $actions);
  150. }
  151. $table = new SortableTableFromArrayConfig($urls, 2, 50, 'urls');
  152. $table->set_additional_parameters($parameters);
  153. $table->set_header(0, 'URL');
  154. $table->set_header(1, get_lang('Description'));
  155. $table->set_header(2, get_lang('Active'));
  156. $table->set_header(3, get_lang('Modify'), false);
  157. $table->display();
  158. Display :: display_footer();