access_urls.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. Display::addFlash(Display::return_message(get_lang('URLDeleted'), 'normal'));
  32. } else {
  33. Display :: display_error_message(get_lang('CannotDeleteURL'));
  34. }
  35. break;
  36. case 'lock':
  37. UrlManager::set_url_status('lock', $url_id);
  38. Display::addFlash(Display::return_message(get_lang('URLInactive'), 'normal'));
  39. break;
  40. case 'unlock':
  41. UrlManager::set_url_status('unlock', $url_id);
  42. Display::addFlash(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. Display::addFlash(
  56. Display::return_message(
  57. get_lang('AdminUserRegisteredToThisURL').': '.$url_str.'<br />',
  58. 'normal',
  59. false
  60. )
  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(
  78. get_lang('AdminShouldBeRegisterInSite').'<br />'.$url_string,
  79. false
  80. );
  81. }
  82. // checking the current installation
  83. if ($current_access_url_id == -1) {
  84. Display::display_warning_message(
  85. get_lang('URLNotConfiguredPleaseChangedTo').': '.api_get_path(WEB_PATH)
  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. Display:: display_warning_message(
  94. '<a href="'.api_get_self().'?action=register&sec_token='.$parameters['sec_token'].'">'.get_lang('ClickToRegisterAdmin').'</a>',
  95. false
  96. );
  97. }
  98. }
  99. // action menu
  100. echo '<div class="actions">';
  101. echo Display::url(
  102. Display::return_icon('new_link.png', get_lang('AddUrl'), array(), ICON_SIZE_MEDIUM),
  103. api_get_path(WEB_CODE_PATH).'admin/access_url_edit.php'
  104. );
  105. echo Display::url(
  106. Display::return_icon('user.png', get_lang('ManageUsers'), array(), ICON_SIZE_MEDIUM),
  107. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_users_to_url.php'
  108. );
  109. echo Display::url(
  110. Display::return_icon('course.png', get_lang('ManageCourses'), array(), ICON_SIZE_MEDIUM),
  111. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_courses_to_url.php'
  112. );
  113. $userGroup = new UserGroup();
  114. if ($userGroup->getUseMultipleUrl()) {
  115. echo Display::url(
  116. Display::return_icon('class.png', get_lang('ManageUserGroup'), array(), ICON_SIZE_MEDIUM),
  117. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_usergroup_to_url.php'
  118. );
  119. }
  120. echo Display::url(
  121. Display::return_icon('folder.png', get_lang('ManageCourseCategories'), array(), ICON_SIZE_MEDIUM),
  122. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_course_category_to_url.php'
  123. );
  124. echo '</div>';
  125. $sortable_data = UrlManager::get_url_data();
  126. $urls = array();
  127. foreach ($sortable_data as $row) {
  128. //title
  129. $url = Display::url($row['url'], $row['url'], array('target'=>'_blank'));
  130. $description = $row['description'];
  131. //Status
  132. $active = $row['active'];
  133. if ($active == '1') {
  134. $action = 'lock';
  135. $image = 'right';
  136. }
  137. if ($active == '0') {
  138. $action = 'unlock';
  139. $image = 'wrong';
  140. }
  141. // you cannot lock the default
  142. if ($row['id']=='1') {
  143. $status = Display::return_icon($image.'.gif', get_lang(ucfirst($action)));
  144. } else {
  145. $status = '<a href="access_urls.php?action='.$action.'&amp;url_id='.$row['id'].'">'.
  146. Display::return_icon($image.'.gif', get_lang(ucfirst($action))).'</a>';
  147. }
  148. // Actions
  149. $url_id = $row['id'];
  150. $actions = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "access_url_edit.php?url_id=$url_id");
  151. if ($url_id != '1') {
  152. $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;">'.
  153. Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
  154. }
  155. $urls[] = array($url, $description, $status, $actions);
  156. }
  157. $table = new SortableTableFromArrayConfig($urls, 2, 50, 'urls');
  158. $table->set_additional_parameters($parameters);
  159. $table->set_header(0, 'URL');
  160. $table->set_header(1, get_lang('Description'));
  161. $table->set_header(2, get_lang('Active'));
  162. $table->set_header(3, get_lang('Modify'), false);
  163. $table->display();
  164. Display :: display_footer();