ldap_users_list.php 7.3 KB

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