ldap_users_list.php 6.8 KB

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