access_urls.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. /**
  10. * Initialization
  11. */
  12. // name of the language file that needs to be included
  13. $language_file = 'admin';
  14. $cidReset = true;
  15. require_once '../inc/global.inc.php';
  16. $this_section = SECTION_PLATFORM_ADMIN;
  17. //api_protect_admin_script();
  18. api_protect_global_admin_script();
  19. if (!api_get_multiple_access_url()) {
  20. header('Location: index.php');
  21. exit;
  22. }
  23. $interbreadcrumb[] = array ("url" => 'index.php', 'name' => get_lang('PlatformAdmin'));
  24. $tool_name = get_lang('MultipleAccessURLs');
  25. Display :: display_header($tool_name);
  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. /**
  30. * Controller
  31. */
  32. if (isset ($_GET['action'])) {
  33. if ($_GET['action'] == 'show_message') {
  34. Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
  35. }
  36. $check = Security::check_token('get');
  37. if ($check) {
  38. $url_id=Database::escape_string($_GET['url_id']);
  39. switch ($_GET['action']) {
  40. case 'delete_url' :
  41. $result = UrlManager::delete($url_id);
  42. if ($result) {
  43. Display :: display_normal_message(get_lang('URLDeleted'));
  44. } else {
  45. Display :: display_error_message(get_lang('CannotDeleteURL'));
  46. }
  47. break;
  48. case 'lock' :
  49. UrlManager::set_url_status('lock',$url_id);
  50. Display :: display_normal_message(get_lang('URLInactive'));
  51. break;
  52. case 'unlock';
  53. UrlManager::set_url_status('unlock',$url_id);
  54. Display :: display_normal_message(get_lang('URLActive'));
  55. break;
  56. case 'register';
  57. // we are going to register the admin
  58. if(api_is_platform_admin()) {
  59. if($current_access_url_id!=-1) {
  60. $url_str = '';
  61. foreach($url_list as $my_url) {
  62. if (!in_array($my_url['id'],$my_user_url_list)){
  63. UrlManager::add_user_to_url(api_get_user_id(),$my_url['id']);
  64. $url_str.=$my_url['url'].' <br />';
  65. }
  66. }
  67. Display :: display_normal_message(get_lang('AdminUserRegisteredToThisURL').': '.$url_str.'<br />',false);
  68. }
  69. }
  70. break;
  71. }
  72. }
  73. Security::clear_token();
  74. }
  75. $parameters['sec_token'] = Security::get_token();
  76. // checking if the admin is registered in all sites
  77. $url_string='';
  78. $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
  79. foreach($url_list as $my_url) {
  80. if (!in_array($my_url['id'],$my_user_url_list)){
  81. $url_string.=$my_url['url'].' <br />';
  82. }
  83. }
  84. if(!empty($url_string)) {
  85. Display :: display_warning_message(get_lang('AdminShouldBeRegisterInSite').'<br />'.$url_string,false);
  86. }
  87. // checking the current installation
  88. if ($current_access_url_id==-1) {
  89. Display :: display_warning_message(get_lang('URLNotConfiguredPleaseChangedTo').': '.api_get_path(WEB_PATH));
  90. } elseif(api_is_platform_admin()) {
  91. $quant= UrlManager::relation_url_user_exist(api_get_user_id(),$current_access_url_id);
  92. if ($quant==0) {
  93. Display :: display_warning_message('<a href="'.api_get_self().'?action=register&sec_token='.$parameters['sec_token'].'">'.get_lang('ClickToRegisterAdmin').'</a>',false);
  94. }
  95. }
  96. // action menu
  97. echo '<div class="actions">';
  98. 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');
  99. 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');
  100. 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');
  101. //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');
  102. echo '</div>';
  103. //$table = new SortableTable('urls', 'url_count_mask', 'get_url_data_mask',2);
  104. $sortable_data = UrlManager::get_url_data();
  105. $urls = array();
  106. $types = array(1=>'AccessURL',2=>'SincroServer',3=>'SincroClient');
  107. foreach($sortable_data as $row) {
  108. //title
  109. $url = Display::url($row['url'], $row['url'], array('target'=>'_blank'));
  110. $name = $row['description'];
  111. if (!empty($row['branch_name'])) {
  112. $name = $row['branch_name'];
  113. }
  114. $type = get_lang($types[$row['url_type']]);
  115. $contact = '';
  116. if (!empty($row['admin_mail']) || !empty($row['admin_name']) || !empty($row['admin_phone'])) {
  117. $contact = (!empty($row['admin_name'])?$row['admin_name']:'').
  118. ' &lt;'.(!empty($row['admin_mail'])?$row['admin_mail']:'').
  119. '&gt;, '.(!empty($row['admin_phone'])?$row['admin_phone']:'');
  120. }
  121. $tech = '';
  122. if (!empty($row['dwn_speed']) || !empty($row['up_speed']) || !empty($row['delay'])) {
  123. $tech .= (empty($row['dwn_speed'])?'-':$row['dwn_speed']).'/';
  124. $tech .= (empty($row['up_speed'])?'-':$row['up_speed']).'/';
  125. $tech .= (empty($row['delay'])?'-':$row['delay']);
  126. }
  127. //Status
  128. $active = $row['active'];
  129. if ($active=='1') {
  130. $action='lock';
  131. $image='right';
  132. }
  133. if ($active=='0') {
  134. $action='unlock';
  135. $image='wrong';
  136. }
  137. // you cannot lock the default
  138. if ($row['id']=='1') {
  139. $status = Display::return_icon($image.'.gif', get_lang(ucfirst($action)));
  140. } else {
  141. $status = '<a href="access_urls.php?action='.$action.'&amp;url_id='.$row['id'].'&amp;sec_token='.Security::getCurrentToken().'">'.Display::return_icon($image.'.gif', get_lang(ucfirst($action))).'</a>';
  142. }
  143. //Actions
  144. $url_id = $row['id'];
  145. $actions = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "access_url_edit.php?url_id=$url_id");
  146. if ($url_id != '1') {
  147. $actions .= '<a href="access_urls.php?action=delete_url&amp;url_id='.$url_id.'&amp;sec_token='.Security::getCurrentToken().'" 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>';
  148. }
  149. $urls[] = array($url, $name, $type, $tech, $contact, $status, $actions);
  150. }
  151. $table = new SortableTableFromArrayConfig($urls, 2, 50, 'urls');
  152. $table->set_additional_parameters($parameters);
  153. //$table->set_header(0, '');
  154. $table->set_header(0, 'URL');
  155. $table->set_header(1, get_lang('Name'));
  156. $table->set_header(2, get_lang('URLType'));
  157. $table->set_header(3, 'Dl/Ul/Delay in Kbit/s');
  158. $table->set_header(4, get_lang('Contact'));
  159. $table->set_header(5, get_lang('Active'));
  160. $table->set_header(6, get_lang('Modify'), false);
  161. $table->display();
  162. /* FOOTER */
  163. Display :: display_footer();