access_urls.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. } else {
  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. }
  74. Security::clear_token();
  75. }
  76. $parameters['sec_token'] = Security::get_token();
  77. // checking if the admin is registered in all sites
  78. $url_string='';
  79. $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
  80. foreach($url_list as $my_url) {
  81. if (!in_array($my_url['id'],$my_user_url_list)){
  82. $url_string.=$my_url['url'].' <br />';
  83. }
  84. }
  85. if(!empty($url_string)) {
  86. Display :: display_warning_message(get_lang('AdminShouldBeRegisterInSite').'<br />'.$url_string,false);
  87. }
  88. // checking the current installation
  89. if ($current_access_url_id==-1) {
  90. Display :: display_warning_message(get_lang('URLNotConfiguredPleaseChangedTo').': '.api_get_path(WEB_PATH));
  91. } elseif(api_is_platform_admin()) {
  92. $quant= UrlManager::relation_url_user_exist(api_get_user_id(),$current_access_url_id);
  93. if ($quant==0) {
  94. Display :: display_warning_message('<a href="'.api_get_self().'?action=register&sec_token='.$parameters['sec_token'].'">'.get_lang('ClickToRegisterAdmin').'</a>',false);
  95. }
  96. }
  97. // action menu
  98. echo '<div class="actions">';
  99. 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');
  100. 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');
  101. 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');
  102. //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');
  103. echo '</div>';
  104. //$table = new SortableTable('urls', 'url_count_mask', 'get_url_data_mask',2);
  105. $sortable_data = UrlManager::get_url_data();
  106. $urls = array();
  107. $types = array(1=>'AccessURL',2=>'SincroServer',3=>'SincroClient');
  108. foreach($sortable_data as $row) {
  109. //title
  110. $url = Display::url($row['url'], $row['url'], array('target'=>'_blank'));
  111. $name = $row['description'];
  112. if (!empty($row['branch_name'])) {
  113. $name = $row['branch_name'];
  114. }
  115. $type = get_lang($types[$row['url_type']]);
  116. $contact = '';
  117. if (!empty($row['admin_mail']) || !empty($row['admin_name']) || !empty($row['admin_phone'])) {
  118. $contact = (!empty($row['admin_name'])?$row['admin_name']:'').
  119. ' &lt;'.(!empty($row['admin_mail'])?$row['admin_mail']:'').
  120. '&gt;, '.(!empty($row['admin_phone'])?$row['admin_phone']:'');
  121. }
  122. $tech = '';
  123. if (!empty($row['dwn_speed']) || !empty($row['up_speed']) || !empty($row['delay'])) {
  124. $tech .= (empty($row['dwn_speed'])?'-':$row['dwn_speed']).'/';
  125. $tech .= (empty($row['up_speed'])?'-':$row['up_speed']).'/';
  126. $tech .= (empty($row['delay'])?'-':$row['delay']);
  127. }
  128. //Status
  129. $active = $row['active'];
  130. if ($active=='1') {
  131. $action='lock';
  132. $image='right';
  133. }
  134. if ($active=='0') {
  135. $action='unlock';
  136. $image='wrong';
  137. }
  138. // you cannot lock the default
  139. if ($row['id']=='1') {
  140. $status = Display::return_icon($image.'.gif', get_lang(ucfirst($action)));
  141. } else {
  142. $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>';
  143. }
  144. //Actions
  145. $url_id = $row['id'];
  146. $actions = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "access_url_edit.php?url_id=$url_id");
  147. if ($url_id != '1') {
  148. $actions .= '<a href="access_urls.php?action=delete_url&amp;url_id='.$url_id.'&amp;sec_token='.Security::getCurrentToken().'" onclick="javascript:if(!confirm('."'".addslashes(get_lang("ConfirmYourChoice"))."'".')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
  149. }
  150. $urls[] = array($url, $name, $type, $tech, $contact, $status, $actions);
  151. }
  152. $table = new SortableTableFromArrayConfig($urls, 2, 50, 'urls');
  153. $table->set_additional_parameters($parameters);
  154. //$table->set_header(0, '');
  155. $table->set_header(0, 'URL');
  156. $table->set_header(1, get_lang('Name'));
  157. $table->set_header(2, get_lang('URLType'));
  158. $table->set_header(3, 'Dl/Ul/Delay in Kbit/s');
  159. $table->set_header(4, get_lang('Contact'));
  160. $table->set_header(5, get_lang('Active'));
  161. $table->set_header(6, get_lang('Modify'), false);
  162. $table->display();
  163. /* FOOTER */
  164. Display :: display_footer();