access_urls.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * Frontend script for multiple access urls
  6. * @package chamilo.admin
  7. * @author Julio Montoya <gugli100@gmail.com>
  8. * @author Yannick Warnier <yannick.warnier@beeznest.com>
  9. */
  10. $cidReset = true;
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_global_admin_script();
  13. if (!api_get_multiple_access_url()) {
  14. header('Location: index.php');
  15. exit;
  16. }
  17. $interbreadcrumb[] = array(
  18. "url" => Container::getRouter()->generate('administration'),
  19. 'name' => get_lang('PlatformAdmin'),
  20. );
  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. $url_id = (empty($_GET['url_id']) ? 0 : intval($_GET['url_id']));
  29. switch ($_GET['action']) {
  30. case 'delete_url':
  31. $result = UrlManager::delete($url_id);
  32. if ($result) {
  33. Display :: display_normal_message(get_lang('URLDeleted'));
  34. } else {
  35. Display :: display_error_message(get_lang('CannotDeleteURL'));
  36. }
  37. break;
  38. case 'lock':
  39. UrlManager::set_url_status('lock', $url_id);
  40. Display::display_normal_message(get_lang('URLInactive'));
  41. break;
  42. case 'unlock':
  43. UrlManager::set_url_status('unlock', $url_id);
  44. Display::display_normal_message(get_lang('URLActive'));
  45. break;
  46. case 'register':
  47. // we are going to register the admin
  48. if (api_is_platform_admin()) {
  49. if ($current_access_url_id!=-1) {
  50. $url_str = '';
  51. foreach ($url_list as $my_url) {
  52. if (!in_array($my_url['id'], $my_user_url_list)) {
  53. UrlManager::add_user_to_url(api_get_user_id(), $my_url['id']);
  54. $url_str.=$my_url['url'].' <br />';
  55. }
  56. }
  57. Display:: display_normal_message(
  58. get_lang('AdminUserRegisteredToThisURL').': '.$url_str.'<br />',
  59. false
  60. );
  61. }
  62. }
  63. break;
  64. }
  65. }
  66. $parameters['sec_token'] = Security::get_token();
  67. // Checking if the admin is registered in all sites
  68. $url_string='';
  69. $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
  70. foreach ($url_list as $my_url) {
  71. if (!in_array($my_url['id'], $my_user_url_list)){
  72. $url_string.=$my_url['url'].' <br />';
  73. }
  74. }
  75. if(!empty($url_string)) {
  76. Display :: display_warning_message(get_lang('AdminShouldBeRegisterInSite').'<br />'.$url_string,false);
  77. }
  78. // checking the current installation
  79. if ($current_access_url_id==-1) {
  80. Display::display_warning_message(get_lang('URLNotConfiguredPleaseChangedTo').': '.api_get_path(WEB_PATH));
  81. } elseif(api_is_platform_admin()) {
  82. $quant= UrlManager::relation_url_user_exist(api_get_user_id(),$current_access_url_id);
  83. if ($quant==0) {
  84. Display :: display_warning_message(
  85. '<a href="'.api_get_self().'?action=register&sec_token='.$parameters['sec_token'].'">'.get_lang('ClickToRegisterAdmin').'</a>',
  86. false
  87. );
  88. }
  89. }
  90. // action menu
  91. echo '<div class="actions">';
  92. echo Display::url(
  93. Display::return_icon('new_link.png', get_lang('AddUrl'), array(), ICON_SIZE_MEDIUM),
  94. api_get_path(WEB_CODE_PATH).'admin/access_url_edit.php'
  95. );
  96. echo Display::url(
  97. Display::return_icon('user.png', get_lang('ManageUsers'), array(), ICON_SIZE_MEDIUM),
  98. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_users_to_url.php'
  99. );
  100. echo Display::url(
  101. Display::return_icon('course.png', get_lang('ManageCourses'), array(), ICON_SIZE_MEDIUM),
  102. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_courses_to_url.php'
  103. );
  104. $userGroup = new UserGroup();
  105. if ($userGroup->getUseMultipleUrl()) {
  106. echo Display::url(
  107. Display::return_icon('class.png', get_lang('ManageUserGroup'), array(), ICON_SIZE_MEDIUM),
  108. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_usergroup_to_url.php'
  109. );
  110. }
  111. echo Display::url(
  112. Display::return_icon('folder.png', get_lang('ManageCourseCategories'), array(), ICON_SIZE_MEDIUM),
  113. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_course_category_to_url.php'
  114. );
  115. echo '</div>';
  116. $sortable_data = UrlManager::get_url_data();
  117. $urls = array();
  118. foreach ($sortable_data as $row) {
  119. //title
  120. $url = Display::url($row['url'], $row['url'], array('target'=>'_blank'));
  121. $description = $row['description'];
  122. //Status
  123. $active = $row['active'];
  124. if ($active=='1') {
  125. $action='lock';
  126. $image='right';
  127. }
  128. if ($active=='0') {
  129. $action='unlock';
  130. $image='wrong';
  131. }
  132. // you cannot lock the default
  133. if ($row['id']=='1') {
  134. $status = Display::return_icon($image.'.gif', get_lang(ucfirst($action)));
  135. } else {
  136. $status = '<a href="access_urls.php?action='.$action.'&amp;url_id='.$row['id'].'">'.
  137. Display::return_icon($image.'.gif', get_lang(ucfirst($action))).'</a>';
  138. }
  139. // Actions
  140. $url_id = $row['id'];
  141. $actions = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "access_url_edit.php?url_id=$url_id");
  142. if ($url_id != '1') {
  143. $actions .= '<a href="access_urls.php?action=delete_url&amp;url_id='.$url_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;">'.
  144. Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
  145. }
  146. $urls[] = array($url, $description, $status, $actions);
  147. }
  148. $table = new SortableTableFromArrayConfig($urls, 2, 50, 'urls');
  149. $table->set_additional_parameters($parameters);
  150. $table->set_header(0, 'URL');
  151. $table->set_header(1, get_lang('Description'));
  152. $table->set_header(2, get_lang('Active'));
  153. $table->set_header(3, get_lang('Modify'), false);
  154. $table->display();
  155. Display :: display_footer();