ldap_users_list.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Mustapha Alouani
  5. * @package chamilo.admin
  6. */
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. require('../auth/ldap/authldap.php');
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. api_protect_admin_script();
  12. $action = @$_GET["action"] ?: null;
  13. $login_as_user_id = @$_GET["user_id"] ?: null;
  14. // Login as ...
  15. if ($action == "login_as" && !empty ($login_as_user_id))
  16. {
  17. login_user($login_as_user_id);
  18. }
  19. //if we already have a session id and a user...
  20. /*
  21. if (($_GET['action']=="add_user") && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && $_GET['id_session']>0 ){
  22. header('Location: ldap_import_students_to_session.php?id_session='.$_GET['id_session'].'&ldap_user='.$_GET['id']);
  23. }
  24. */
  25. $interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  26. $tool_name = get_lang('SearchLDAPUsers');
  27. //Display::display_header($tool_name); //cannot display now as we need to redirect
  28. //api_display_tool_title($tool_name);
  29. if (isset ($_GET['action']))
  30. {
  31. $check = Security::check_token('get');
  32. if ($check) {
  33. switch ($_GET['action']) {
  34. case 'show_message':
  35. Display::addFlash(Display::return_message($_GET['message'], 'normal'));
  36. Display::display_header($tool_name);
  37. break;
  38. case 'delete_user':
  39. if ($user_id != $_user['user_id'] && UserManager::delete_user($_GET['user_id'])) {
  40. Display::addFlash(Display::return_message(get_lang('UserDeleted'), 'normal'));
  41. } else {
  42. Display::addFlash(Display::return_message(get_lang('CannotDeleteUser'), 'error'));
  43. }
  44. Display::display_header($tool_name);
  45. break;
  46. case 'lock':
  47. $message = lock_unlock_user('lock', $_GET['user_id']);
  48. Display::addFlash(Display::return_message($message, 'normal'));
  49. Display::display_header($tool_name);
  50. break;
  51. case 'unlock':
  52. $message = lock_unlock_user('unlock', $_GET['user_id']);
  53. Display::addFlash(Display::return_message($message, 'normal'));
  54. Display::display_header($tool_name);
  55. break;
  56. case 'add_user':
  57. $id = $_GET['id'];
  58. $UserList = array();
  59. $userid_match_login = array();
  60. foreach ($id as $user_id) {
  61. $tmp = ldap_add_user($user_id);
  62. $UserList[] = $tmp;
  63. $userid_match_login[$tmp] = $user_id;
  64. }
  65. if (isset($_GET['id_session']) && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && ($_GET['id_session'] > 0)) {
  66. ldap_add_user_to_session($UserList, $_GET['id_session']);
  67. header('Location: resume_session.php?id_session='.intval($_GET['id_session']));
  68. } else {
  69. Display::display_header($tool_name);
  70. if (count($userid_match_login) > 0) {
  71. $message = get_lang('LDAPUsersAddedOrUpdated').':<br />';
  72. foreach ($userid_match_login as $user_id => $login) {
  73. $message .= '- '.$login.'<br />';
  74. }
  75. } else {
  76. $message = get_lang('NoUserAdded');
  77. }
  78. Display::addFlash(Display::return_message($message, 'normal', false));
  79. Display::display_header($tool_name);
  80. }
  81. break;
  82. default:
  83. Display::display_header($tool_name);
  84. }
  85. Security::clear_token();
  86. } else {
  87. Display::display_header($tool_name);
  88. }
  89. } else {
  90. Display::display_header($tool_name);
  91. }
  92. if (isset($_POST['action'])) {
  93. $check = Security::check_token('get');
  94. if ($check) {
  95. switch ($_POST['action']) {
  96. case 'delete':
  97. $number_of_selected_users = count($_POST['id']);
  98. $number_of_deleted_users = 0;
  99. foreach ($_POST['id'] as $index => $user_id) {
  100. if ($user_id != $_user['user_id']) {
  101. if (UserManager::delete_user($user_id)) {
  102. $number_of_deleted_users++;
  103. }
  104. }
  105. }
  106. if ($number_of_selected_users == $number_of_deleted_users) {
  107. echo Display::return_message(get_lang('SelectedUsersDeleted'), 'normal');
  108. } else {
  109. echo Display::return_message(get_lang('SomeUsersNotDeleted'), 'error');
  110. }
  111. break;
  112. case 'add_user':
  113. $number_of_selected_users = count($_POST['id']);
  114. $number_of_added_users = 0;
  115. $UserList = array();
  116. foreach ($_POST['id'] as $index => $user_id) {
  117. if ($user_id != $_user['user_id']) {
  118. $UserList[] = ldap_add_user($user_id);
  119. }
  120. }
  121. if (isset($_GET['id_session']) && (trim($_GET['id_session']) != "")) {
  122. addUserToSession($UserList, $_GET['id_session']);
  123. }
  124. if (count($UserList) > 0) {
  125. echo Display::return_message(
  126. count($UserList)." ".get_lang('LDAPUsersAdded')
  127. );
  128. } else {
  129. echo Display::return_message(get_lang('NoUserAdded'));
  130. }
  131. break;
  132. }
  133. Security::clear_token();
  134. }
  135. }
  136. $form = new FormValidator('advanced_search', 'get');
  137. $form->addText('keyword_username', get_lang('LoginName'), false);
  138. if (api_is_western_name_order()) {
  139. $form->addText('keyword_firstname', get_lang('FirstName'), false);
  140. $form->addText('keyword_lastname', get_lang('LastName'), false);
  141. } else {
  142. $form->addText('keyword_lastname', get_lang('LastName'), false);
  143. $form->addText('keyword_firstname', get_lang('FirstName'), false);
  144. }
  145. if (isset($_GET['id_session'])) {
  146. $form->addElement('hidden', 'id_session', $_GET['id_session']);
  147. }
  148. $type = array();
  149. $type["all"] = get_lang('All');
  150. $type["employee"] = get_lang('Teacher');
  151. $type["student"] = get_lang('Student');
  152. $form->addElement('select', 'keyword_type', get_lang('Status'), $type);
  153. // Structure a rajouer ??
  154. $form->addElement('submit', 'submit', get_lang('Ok'));
  155. //$defaults['keyword_active'] = 1;
  156. //$defaults['keyword_inactive'] = 1;
  157. //$form->setDefaults($defaults);
  158. $form->display();
  159. $parameters['keyword_username'] = @$_GET['keyword_username'] ?: null;
  160. $parameters['keyword_firstname'] = @$_GET['keyword_firstname'] ?: null;
  161. $parameters['keyword_lastname'] = @$_GET['keyword_lastname'] ?: null;
  162. $parameters['keyword_email'] = @$_GET['keyword_email'] ?: null;
  163. if (isset($_GET['id_session'])) {
  164. $parameters['id_session'] = $_GET['id_session'];
  165. }
  166. // Create a sortable table with user-data
  167. $parameters['sec_token'] = Security::get_token();
  168. $table = new SortableTable(
  169. 'users',
  170. 'ldap_get_number_of_users',
  171. 'ldap_get_user_data',
  172. (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2
  173. );
  174. $table->set_additional_parameters($parameters);
  175. $table->set_header(0, '', false);
  176. $table->set_header(1, get_lang('LoginName'));
  177. if (api_is_western_name_order()) {
  178. $table->set_header(2, get_lang('FirstName'));
  179. $table->set_header(3, get_lang('LastName'));
  180. } else {
  181. $table->set_header(2, get_lang('LastName'));
  182. $table->set_header(3, get_lang('FirstName'));
  183. }
  184. $table->set_header(4, get_lang('Email'));
  185. $table->set_header(5, get_lang('Actions'));
  186. //$table->set_column_filter(5, 'email_filter');
  187. //$table->set_column_filter(5, 'active_filter');
  188. $table->set_column_filter(5, 'modify_filter');
  189. $table->set_form_actions(array('add_user' => get_lang('AddLDAPUsers')));
  190. $table->display();
  191. Display::display_footer();