access_urls.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. // name of the language file that needs to be included
  10. $language_file = 'admin';
  11. $cidReset = true;
  12. ////require_once '../inc/global.inc.php';
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. //api_protect_admin_script();
  15. api_protect_global_admin_script();
  16. if (!api_get_multiple_access_url()) {
  17. header('Location: index.php');
  18. exit;
  19. }
  20. $interbreadcrumb[] = array ("url" => 'index.php', 'name' => get_lang('PlatformAdmin'));
  21. $tool_name = get_lang('MultipleAccessURLs');
  22. Display :: display_header($tool_name);
  23. $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
  24. $current_access_url_id = api_get_current_access_url_id();
  25. $url_list = UrlManager::get_url_data();
  26. // Actions
  27. if (isset ($_GET['action'])) {
  28. if ($_GET['action'] == 'show_message') {
  29. Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
  30. }
  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. // action menu
  92. echo '<div class="actions">';
  93. 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');
  94. 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');
  95. 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');
  96. //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');
  97. $userGroup = new Usergroup();
  98. if ($userGroup->getUseMultipleUrl()) {
  99. echo Display::url(
  100. Display::return_icon('class.png', get_lang('ManageUserGroup'), array(), ICON_SIZE_MEDIUM),
  101. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_usergroup_to_url.php'
  102. );
  103. }
  104. if (isMultipleUrlSupport()) {
  105. echo Display::url(
  106. Display::return_icon('folder.png', get_lang('ManageCourseCategories'), array(), ICON_SIZE_MEDIUM),
  107. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_course_category_to_url.php'
  108. );
  109. }
  110. //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');
  111. echo '</div>';
  112. //$table = new SortableTable('urls', 'url_count_mask', 'get_url_data_mask',2);
  113. $sortable_data = UrlManager::get_url_data();
  114. $urls = array();
  115. $types = array(1=>'AccessURL',2=>'SincroServer',3=>'SincroClient');
  116. foreach($sortable_data as $row) {
  117. //title
  118. $url = Display::url($row['url'], $row['url'], array('target'=>'_blank'));
  119. $name = $row['description'];
  120. if (!empty($row['branch_name'])) {
  121. $name = $row['branch_name'];
  122. }
  123. $type = get_lang($types[$row['url_type']]);
  124. $contact = '';
  125. if (!empty($row['admin_mail']) || !empty($row['admin_name']) || !empty($row['admin_phone'])) {
  126. $contact = (!empty($row['admin_name'])?$row['admin_name']:'').
  127. ' &lt;'.(!empty($row['admin_mail'])?$row['admin_mail']:'').
  128. '&gt;, '.(!empty($row['admin_phone'])?$row['admin_phone']:'');
  129. }
  130. $tech = '';
  131. if (!empty($row['dwn_speed']) || !empty($row['up_speed']) || !empty($row['delay'])) {
  132. $tech .= (empty($row['dwn_speed'])?'-':$row['dwn_speed']).'/';
  133. $tech .= (empty($row['up_speed'])?'-':$row['up_speed']).'/';
  134. $tech .= (empty($row['delay'])?'-':$row['delay']);
  135. }
  136. //Status
  137. $active = $row['active'];
  138. if ($active=='1') {
  139. $action='lock';
  140. $image='right';
  141. }
  142. if ($active=='0') {
  143. $action='unlock';
  144. $image='wrong';
  145. }
  146. // you cannot lock the default
  147. if ($row['id']=='1') {
  148. $status = Display::return_icon($image.'.gif', get_lang(ucfirst($action)));
  149. } else {
  150. $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>';
  151. }
  152. //Actions
  153. $url_id = $row['id'];
  154. $actions = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "access_url_edit.php?url_id=$url_id");
  155. if ($url_id != '1') {
  156. $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>';
  157. }
  158. $urls[] = array($url, $name, $type, $tech, $contact, $status, $actions);
  159. }
  160. $table = new SortableTableFromArrayConfig($urls, 2, 50, 'urls');
  161. $table->set_additional_parameters($parameters);
  162. //$table->set_header(0, '');
  163. $table->set_header(0, 'URL');
  164. $table->set_header(1, get_lang('Name'));
  165. $table->set_header(2, get_lang('URLType'));
  166. $table->set_header(3, 'Dl/Ul/Delay in Kbit/s');
  167. $table->set_header(4, get_lang('Contact'));
  168. $table->set_header(5, get_lang('Active'));
  169. $table->set_header(6, get_lang('Modify'), false);
  170. $table->display();
  171. Display :: display_footer();