access_urls.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2009 Dokeos SPRL
  6. Copyright (c) 2009 Julio Montoya Armas <gugli100@gmail.com>
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. ==============================================================================
  20. * @package dokeos.admin
  21. ==============================================================================
  22. */
  23. // name of the language file that needs to be included
  24. $language_file = 'admin';
  25. $cidReset = true;
  26. require ('../inc/global.inc.php');
  27. $this_section = SECTION_PLATFORM_ADMIN;
  28. api_protect_admin_script();
  29. if (!$_configuration['multiple_access_urls'])
  30. header('Location: index.php');
  31. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  32. $tool_name = get_lang('MultipleAccessURLs');
  33. Display :: display_header($tool_name);
  34. require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php');
  35. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  36. require_once (api_get_path(LIBRARY_PATH).'security.lib.php');
  37. require_once (api_get_path(LIBRARY_PATH).'urlmanager.lib.php');
  38. $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
  39. $current_access_url_id = api_get_current_access_url_id();
  40. $url_list = UrlManager::get_url_data();
  41. // Actions
  42. if (isset ($_GET['action'])) {
  43. if ($_GET['action'] == 'show_message')
  44. Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
  45. $check = Security::check_token('get');
  46. if ($check) {
  47. $url_id=Database::escape_string($_GET['url_id']);
  48. switch ($_GET['action']) {
  49. case 'delete_url' :
  50. $result = UrlManager::delete($url_id);
  51. if ($result) {
  52. Display :: display_normal_message(get_lang('URLDeleted'));
  53. } else {
  54. Display :: display_error_message(get_lang('CannotDeleteURL'));
  55. }
  56. break;
  57. case 'lock' :
  58. UrlManager::set_url_status('lock',$url_id);
  59. Display :: display_normal_message(get_lang('URLInactive'));
  60. break;
  61. case 'unlock';
  62. UrlManager::set_url_status('unlock',$url_id);
  63. Display :: display_normal_message(get_lang('URLActive'));
  64. break;
  65. case 'register';
  66. // we are going to register the admin
  67. if(api_is_platform_admin()) {
  68. if($current_access_url_id!=-1) {
  69. $url_str = '';
  70. foreach($url_list as $my_url) {
  71. if (!in_array($my_url['id'],$my_user_url_list)){
  72. UrlManager::add_user_to_url(api_get_user_id(),$my_url['id']);
  73. $url_str.=$my_url['url'].' ';
  74. }
  75. }
  76. Display :: display_normal_message(get_lang('AdminUserRegisteredToThisURL').': '.$url_str.'<br />',false);
  77. }
  78. }
  79. break;
  80. }
  81. }
  82. Security::clear_token();
  83. }
  84. $parameters['sec_token'] = Security::get_token();
  85. // checking if the admin is registered in all sites
  86. $url_string='';
  87. $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
  88. foreach($url_list as $my_url) {
  89. if (!in_array($my_url['id'],$my_user_url_list)){
  90. $url_string.=$my_url['url'].' ';
  91. }
  92. }
  93. if(!empty($url_string)) {
  94. Display :: display_warning_message(get_lang('AdminShouldBeRegisterInSite').':<br />'.$url_string,false);
  95. }
  96. // checking the current installation
  97. if ($current_access_url_id==-1) {
  98. Display :: display_warning_message(get_lang('URLNotConfiguredPleaseChangedTo').': '.api_get_path(WEB_PATH));
  99. } elseif(api_is_platform_admin()) {
  100. $quant= UrlManager::relation_url_user_exist(api_get_user_id(),$current_access_url_id);
  101. if ($quant==0) {
  102. Display :: display_warning_message('<a href="'.api_get_self().'?action=register&sec_token='.$parameters['sec_token'].'">'.get_lang('ClickToRegisterAdmin').'</a>',false);
  103. }
  104. }
  105. //<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>
  106. // action menu
  107. echo '<div class="actions" style="height:22px;">';
  108. echo '<div style="float:right;">
  109. <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;
  110. <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>
  111. <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>
  112. </div><br />';
  113. echo '</div>';
  114. $table = new SortableTable('urls', 'url_count_mask', 'get_url_data_mask',2);
  115. $table->set_additional_parameters($parameters);
  116. $table->set_header(0, '', false);
  117. $table->set_header(1, get_lang('URL'));
  118. $table->set_header(2, get_lang('Description'));
  119. $table->set_header(3, get_lang('Active'));
  120. //$table->set_header(4, get_lang('Status'));
  121. $table->set_header(4, get_lang('Modify'));
  122. $table->set_column_filter(3, 'active_filter');
  123. //$table->set_column_filter(4, 'status_filter');
  124. $table->set_column_filter(4, 'modify_filter');
  125. //$table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform')));
  126. $table->display();
  127. /*
  128. function status_filter($active, $url_params, $row) {
  129. $url_id =UrlManager::get_url_id($row[1]);
  130. if ($row[0] == $url_id ) {
  131. $action='lock';
  132. $image='right';
  133. } else {
  134. $image='wrong';
  135. }
  136. // you cannot lock the default
  137. $result = Display::return_icon($image.'.gif', get_lang(ucfirst($action)));
  138. return $result;
  139. }
  140. */
  141. function modify_filter($active, $url_params, $row) {
  142. global $charset;
  143. $url_id = $row['0'];
  144. $result .= '<a href="access_url_edit.php?url_id='.$url_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>&nbsp;';
  145. if ($url_id != '1') {
  146. $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>';
  147. }
  148. return $result;
  149. }
  150. function active_filter($active, $url_params, $row) {
  151. $active = $row['3'];
  152. if ($active=='1') {
  153. $action='lock';
  154. $image='right';
  155. }
  156. if ($active=='0') {
  157. $action='unlock';
  158. $image='wrong';
  159. }
  160. // you cannot lock the default
  161. if ($row['0']=='1') {
  162. $result = Display::return_icon($image.'.gif', get_lang(ucfirst($action)));
  163. } else {
  164. $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>';
  165. }
  166. return $result;
  167. }
  168. // this 2 "mask" function are here just because the SortableTable
  169. function get_url_data_mask($id, $url_params=null, $row=null) {
  170. return UrlManager::get_url_data();
  171. }
  172. function url_count_mask() {
  173. return UrlManager::url_count();
  174. }
  175. /*
  176. ==============================================================================
  177. FOOTER
  178. ==============================================================================
  179. */
  180. Display :: display_footer();
  181. ?>