access_urls.php 6.3 KB

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