access_urls.php 6.7 KB

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