access_urls.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // name of the language file that needs to be included
  7. $language_file = 'admin';
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. api_protect_admin_script();
  12. if (!$_configuration['multiple_access_urls'])
  13. header('Location: index.php');
  14. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  15. $tool_name = get_lang('MultipleAccessURLs');
  16. Display :: display_header($tool_name);
  17. require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
  18. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  19. require_once api_get_path(LIBRARY_PATH).'security.lib.php';
  20. require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
  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. $check = Security::check_token('get');
  29. if ($check) {
  30. $url_id=Database::escape_string($_GET['url_id']);
  31. switch ($_GET['action']) {
  32. case 'delete_url' :
  33. $result = UrlManager::delete($url_id);
  34. if ($result) {
  35. Display :: display_normal_message(get_lang('URLDeleted'));
  36. } else {
  37. Display :: display_error_message(get_lang('CannotDeleteURL'));
  38. }
  39. break;
  40. case 'lock' :
  41. UrlManager::set_url_status('lock',$url_id);
  42. Display :: display_normal_message(get_lang('URLInactive'));
  43. break;
  44. case 'unlock';
  45. UrlManager::set_url_status('unlock',$url_id);
  46. Display :: display_normal_message(get_lang('URLActive'));
  47. break;
  48. case 'register';
  49. // we are going to register the admin
  50. if(api_is_platform_admin()) {
  51. if($current_access_url_id!=-1) {
  52. $url_str = '';
  53. foreach($url_list as $my_url) {
  54. if (!in_array($my_url['id'],$my_user_url_list)){
  55. UrlManager::add_user_to_url(api_get_user_id(),$my_url['id']);
  56. $url_str.=$my_url['url'].' <br />';
  57. }
  58. }
  59. Display :: display_normal_message(get_lang('AdminUserRegisteredToThisURL').': '.$url_str.'<br />',false);
  60. }
  61. }
  62. break;
  63. }
  64. }
  65. Security::clear_token();
  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('<a href="'.api_get_self().'?action=register&sec_token='.$parameters['sec_token'].'">'.get_lang('ClickToRegisterAdmin').'</a>',false);
  86. }
  87. }
  88. //<a href="'.api_get_path(WEB_CODE_PATH).'admin/access_url_edit_sessions_to_url.php">'.Display::return_icon('sessions.gif',get_lang('ManageSessions'),'').get_lang('ManageSessions').'</a>
  89. // action menu
  90. echo '<div class="actions" style="height:22px;">';
  91. echo '<div style="float:right;">
  92. <a href="'.api_get_path(WEB_CODE_PATH).'admin/access_url_edit.php">'.Display::return_icon('view_more_stats.gif',get_lang('AddUrl'),'').get_lang('AddUrl').'</a>&nbsp;&nbsp;
  93. <a href="'.api_get_path(WEB_CODE_PATH).'admin/access_url_edit_users_to_url.php">'.Display::return_icon('members.gif',get_lang('ManageUsers'),'').get_lang('ManageUsers').'</a>
  94. <a href="'.api_get_path(WEB_CODE_PATH).'admin/access_url_edit_courses_to_url.php">'.Display::return_icon('courses.gif',get_lang('ManageCourses'),'').get_lang('ManageCourses').'</a>
  95. </div><br />';
  96. echo '</div>';
  97. $table = new SortableTable('urls', 'url_count_mask', 'get_url_data_mask',2);
  98. $table->set_additional_parameters($parameters);
  99. $table->set_header(0, '', false);
  100. $table->set_header(1, get_lang('URL'));
  101. $table->set_header(2, get_lang('Description'));
  102. $table->set_header(3, get_lang('Active'));
  103. $table->set_header(4, get_lang('Modify'));
  104. $table->set_column_filter(3, 'active_filter');
  105. $table->set_column_filter(4, 'modify_filter');
  106. $table->display();
  107. function modify_filter($active, $url_params, $row) {
  108. global $charset;
  109. $url_id = $row['0'];
  110. $result .= '<a href="access_url_edit.php?url_id='.$url_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>&nbsp;';
  111. if ($url_id != '1') {
  112. $result .= '<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.gif', get_lang('Delete')).'</a>';
  113. }
  114. return $result;
  115. }
  116. function active_filter($active, $url_params, $row) {
  117. $active = $row['3'];
  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['0']=='1') {
  128. $result = Display::return_icon($image.'.gif', get_lang(ucfirst($action)));
  129. } else {
  130. $result = '<a href="access_urls.php?action='.$action.'&amp;url_id='.$row['0'].'&amp;sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon($image.'.gif', get_lang(ucfirst($action))).'</a>';
  131. }
  132. return $result;
  133. }
  134. // this 2 "mask" function are here just because the SortableTable
  135. function get_url_data_mask($id, $url_params=null, $row=null) {
  136. return UrlManager::get_url_data();
  137. }
  138. function url_count_mask() {
  139. return UrlManager::url_count();
  140. }
  141. /*
  142. ==============================================================================
  143. FOOTER
  144. ==============================================================================
  145. */
  146. Display :: display_footer();
  147. ?>