access_urls.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. // name of the language file that needs to be included
  8. $language_file = 'admin';
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script();
  13. if (!$_configuration['multiple_access_urls']) {
  14. header('Location: index.php');
  15. exit;
  16. }
  17. $interbreadcrumb[] = array ("url" => 'index.php', 'name' => get_lang('PlatformAdmin'));
  18. $tool_name = get_lang('MultipleAccessURLs');
  19. Display :: display_header($tool_name);
  20. require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
  21. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  22. require_once api_get_path(LIBRARY_PATH).'security.lib.php';
  23. require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
  24. $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
  25. $current_access_url_id = api_get_current_access_url_id();
  26. $url_list = UrlManager::get_url_data();
  27. // Actions
  28. if (isset ($_GET['action'])) {
  29. if ($_GET['action'] == 'show_message')
  30. Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
  31. $check = Security::check_token('get');
  32. if ($check) {
  33. $url_id=Database::escape_string($_GET['url_id']);
  34. switch ($_GET['action']) {
  35. case 'delete_url' :
  36. $result = UrlManager::delete($url_id);
  37. if ($result) {
  38. Display :: display_normal_message(get_lang('URLDeleted'));
  39. } else {
  40. Display :: display_error_message(get_lang('CannotDeleteURL'));
  41. }
  42. break;
  43. case 'lock' :
  44. UrlManager::set_url_status('lock',$url_id);
  45. Display :: display_normal_message(get_lang('URLInactive'));
  46. break;
  47. case 'unlock';
  48. UrlManager::set_url_status('unlock',$url_id);
  49. Display :: display_normal_message(get_lang('URLActive'));
  50. break;
  51. case 'register';
  52. // we are going to register the admin
  53. if(api_is_platform_admin()) {
  54. if($current_access_url_id!=-1) {
  55. $url_str = '';
  56. foreach($url_list as $my_url) {
  57. if (!in_array($my_url['id'],$my_user_url_list)){
  58. UrlManager::add_user_to_url(api_get_user_id(),$my_url['id']);
  59. $url_str.=$my_url['url'].' <br />';
  60. }
  61. }
  62. Display :: display_normal_message(get_lang('AdminUserRegisteredToThisURL').': '.$url_str.'<br />',false);
  63. }
  64. }
  65. break;
  66. }
  67. }
  68. Security::clear_token();
  69. }
  70. $parameters['sec_token'] = Security::get_token();
  71. // checking if the admin is registered in all sites
  72. $url_string='';
  73. $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
  74. foreach($url_list as $my_url) {
  75. if (!in_array($my_url['id'],$my_user_url_list)){
  76. $url_string.=$my_url['url'].' <br />';
  77. }
  78. }
  79. if(!empty($url_string)) {
  80. Display :: display_warning_message(get_lang('AdminShouldBeRegisterInSite').'<br />'.$url_string,false);
  81. }
  82. // checking the current installation
  83. if ($current_access_url_id==-1) {
  84. Display :: display_warning_message(get_lang('URLNotConfiguredPleaseChangedTo').': '.api_get_path(WEB_PATH));
  85. } elseif(api_is_platform_admin()) {
  86. $quant= UrlManager::relation_url_user_exist(api_get_user_id(),$current_access_url_id);
  87. if ($quant==0) {
  88. Display :: display_warning_message('<a href="'.api_get_self().'?action=register&sec_token='.$parameters['sec_token'].'">'.get_lang('ClickToRegisterAdmin').'</a>',false);
  89. }
  90. }
  91. //<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>
  92. // action menu
  93. echo '<div class="actions" style="height:22px;">';
  94. echo '<div style="float:right;">
  95. <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;
  96. <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>
  97. <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>
  98. </div><br />';
  99. echo '</div>';
  100. $table = new SortableTable('urls', 'url_count_mask', 'get_url_data_mask',2);
  101. $table->set_additional_parameters($parameters);
  102. $table->set_header(0, '', false);
  103. $table->set_header(1, get_lang('URL'));
  104. $table->set_header(2, get_lang('Description'));
  105. $table->set_header(3, get_lang('Active'));
  106. $table->set_header(4, get_lang('Modify'));
  107. $table->set_column_filter(3, 'active_filter');
  108. $table->set_column_filter(4, 'modify_filter');
  109. $table->display();
  110. function modify_filter($active, $url_params, $row) {
  111. global $charset;
  112. $url_id = $row['0'];
  113. $result .= '<a href="access_url_edit.php?url_id='.$url_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>&nbsp;';
  114. if ($url_id != '1') {
  115. $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>';
  116. }
  117. return $result;
  118. }
  119. function active_filter($active, $url_params, $row) {
  120. $active = $row['3'];
  121. if ($active=='1') {
  122. $action='lock';
  123. $image='right';
  124. }
  125. if ($active=='0') {
  126. $action='unlock';
  127. $image='wrong';
  128. }
  129. // you cannot lock the default
  130. if ($row['0']=='1') {
  131. $result = Display::return_icon($image.'.gif', get_lang(ucfirst($action)));
  132. } else {
  133. $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>';
  134. }
  135. return $result;
  136. }
  137. // this 2 "mask" function are here just because the SortableTable
  138. function get_url_data_mask($id, $url_params=null, $row=null) {
  139. return UrlManager::get_url_data();
  140. }
  141. function url_count_mask() {
  142. return UrlManager::url_count();
  143. }
  144. /* FOOTER */
  145. Display :: display_footer();
  146. ?>