access_urls.php 6.1 KB

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