access_urls.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 __DIR__.'/../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. $url_id = (empty($_GET['url_id']) ? 0 : intval($_GET['url_id']));
  27. switch ($_GET['action']) {
  28. case 'delete_url':
  29. $result = UrlManager::delete($url_id);
  30. if ($result) {
  31. echo Display::return_message(get_lang('URLDeleted'), 'normal');
  32. } else {
  33. echo Display::return_message(get_lang('CannotDeleteURL'), 'error');
  34. }
  35. break;
  36. case 'lock':
  37. UrlManager::set_url_status('lock', $url_id);
  38. echo Display::return_message(get_lang('URLInactive'), 'normal');
  39. break;
  40. case 'unlock':
  41. UrlManager::set_url_status('unlock', $url_id);
  42. echo Display::return_message(get_lang('URLActive'), 'normal');
  43. break;
  44. case 'register':
  45. // we are going to register the admin
  46. if (api_is_platform_admin()) {
  47. if ($current_access_url_id != -1) {
  48. $url_str = '';
  49. foreach ($url_list as $my_url) {
  50. if (!in_array($my_url['id'], $my_user_url_list)) {
  51. UrlManager::add_user_to_url(api_get_user_id(), $my_url['id']);
  52. $url_str .= $my_url['url'].' <br />';
  53. }
  54. }
  55. echo Display::return_message(
  56. get_lang('AdminUserRegisteredToThisURL').': '.$url_str.'<br />',
  57. 'normal',
  58. false
  59. );
  60. }
  61. }
  62. break;
  63. }
  64. }
  65. $parameters['sec_token'] = Security::get_token();
  66. // Checking if the admin is registered in all sites
  67. $url_string = '';
  68. $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
  69. foreach ($url_list as $my_url) {
  70. if (!in_array($my_url['id'], $my_user_url_list)) {
  71. $url_string .= $my_url['url'].' <br />';
  72. }
  73. }
  74. if (!empty($url_string)) {
  75. echo Display::return_message(
  76. get_lang('AdminShouldBeRegisterInSite').'<br />'.$url_string,
  77. 'warning',
  78. false
  79. );
  80. }
  81. // checking the current installation
  82. if ($current_access_url_id == -1) {
  83. echo Display::return_message(
  84. get_lang('URLNotConfiguredPleaseChangedTo').': '.api_get_path(WEB_PATH),
  85. 'warning'
  86. );
  87. } elseif (api_is_platform_admin()) {
  88. $quant = UrlManager::relation_url_user_exist(
  89. api_get_user_id(),
  90. $current_access_url_id
  91. );
  92. if ($quant == 0) {
  93. echo Display::return_message(
  94. '<a href="'.api_get_self().'?action=register&sec_token='.$parameters['sec_token'].'">'.get_lang('ClickToRegisterAdmin').'</a>',
  95. 'warning',
  96. false
  97. );
  98. }
  99. }
  100. // action menu
  101. echo '<div class="actions">';
  102. echo Display::url(
  103. Display::return_icon('new_link.png', get_lang('AddUrl'), array(), ICON_SIZE_MEDIUM),
  104. api_get_path(WEB_CODE_PATH).'admin/access_url_edit.php'
  105. );
  106. echo Display::url(
  107. Display::return_icon('user.png', get_lang('ManageUsers'), array(), ICON_SIZE_MEDIUM),
  108. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_users_to_url.php'
  109. );
  110. echo Display::url(
  111. Display::return_icon('course.png', get_lang('ManageCourses'), array(), ICON_SIZE_MEDIUM),
  112. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_courses_to_url.php'
  113. );
  114. $userGroup = new UserGroup();
  115. if ($userGroup->getUseMultipleUrl()) {
  116. echo Display::url(
  117. Display::return_icon('class.png', get_lang('ManageUserGroup'), array(), ICON_SIZE_MEDIUM),
  118. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_usergroup_to_url.php'
  119. );
  120. }
  121. echo Display::url(
  122. Display::return_icon('folder.png', get_lang('ManageCourseCategories'), array(), ICON_SIZE_MEDIUM),
  123. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_course_category_to_url.php'
  124. );
  125. echo '</div>';
  126. $sortable_data = UrlManager::get_url_data();
  127. $urls = array();
  128. foreach ($sortable_data as $row) {
  129. //title
  130. $url = Display::url($row['url'], $row['url'], array('target'=>'_blank'));
  131. $description = $row['description'];
  132. //Status
  133. $active = $row['active'];
  134. if ($active == '1') {
  135. $action = 'lock';
  136. $image = 'right';
  137. }
  138. if ($active == '0') {
  139. $action = 'unlock';
  140. $image = 'wrong';
  141. }
  142. // you cannot lock the default
  143. if ($row['id'] == '1') {
  144. $status = Display::return_icon($image.'.gif', get_lang(ucfirst($action)));
  145. } else {
  146. $status = '<a href="access_urls.php?action='.$action.'&amp;url_id='.$row['id'].'">'.
  147. Display::return_icon($image.'.gif', get_lang(ucfirst($action))).'</a>';
  148. }
  149. // Actions
  150. $url_id = $row['id'];
  151. $actions = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "access_url_edit.php?url_id=$url_id");
  152. if ($url_id != '1') {
  153. $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;">'.
  154. Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
  155. }
  156. $urls[] = array($url, $description, $status, $actions);
  157. }
  158. $table = new SortableTableFromArrayConfig($urls, 2, 50, 'urls');
  159. $table->set_additional_parameters($parameters);
  160. $table->set_header(0, 'URL');
  161. $table->set_header(1, get_lang('Description'));
  162. $table->set_header(2, get_lang('Active'));
  163. $table->set_header(3, get_lang('Modify'), false);
  164. $table->display();
  165. Display :: display_footer();