user.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script displays a list of the users of the current course.
  5. * Course admins can change user perimssions, subscribe and unsubscribe users...
  6. *
  7. * EXPERIMENTAL: support for virtual courses
  8. * - show users registered in virtual and real courses;
  9. * - only show the users of a virtual course if the current user;
  10. * is registered in that virtual course.
  11. *
  12. * Exceptions: platform admin and the course admin will see all virtual courses.
  13. * This is a new feature, there may be bugs.
  14. *
  15. * @todo possibility to edit user-course rights and view statistics for users in virtual courses
  16. * @todo convert normal table display to display function (refactor virtual course display function)
  17. * @todo display table functions need support for align and valign (e.g. to center text in cells) (this is now possible)
  18. * @author Roan Embrechts, refactoring + virtual courses support
  19. * @author Julio Montoya Armas, Several fixes
  20. * @package chamilo.user
  21. */
  22. /**
  23. * Code
  24. */
  25. // name of the language file that needs to be included
  26. $language_file = array('registration', 'admin', 'userInfo', 'registration');
  27. $use_anonymous = true;
  28. require_once '../inc/global.inc.php';
  29. $current_course_tool = TOOL_USER;
  30. $this_section = SECTION_COURSES;
  31. // notice for unauthorized people.
  32. api_protect_course_script(true);
  33. /* Libraries */
  34. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  35. global $_configuration;
  36. if (!api_is_platform_admin(true)) {
  37. if (!api_is_course_admin() && !api_is_coach()) {
  38. if (api_get_course_setting('allow_user_view_user_list') == 0) {
  39. api_not_allowed(true);
  40. }
  41. }
  42. }
  43. /*
  44. Constants and variables
  45. */
  46. $course_code = api_get_course_id();
  47. $session_id = api_get_session_id();
  48. $is_western_name_order = api_is_western_name_order();
  49. $sort_by_first_name = api_sort_by_first_name();
  50. $course_info = api_get_course_info();
  51. $user_id = api_get_user_id();
  52. //Can't auto unregister from a session
  53. if (!empty($session_id)) {
  54. $course_info['unsubscribe'] = 0;
  55. }
  56. /* Unregistering a user section */
  57. if (api_is_allowed_to_edit(null, true)) {
  58. if (isset($_POST['action'])) {
  59. switch ($_POST['action']) {
  60. case 'unsubscribe' :
  61. // Make sure we don't unsubscribe current user from the course
  62. if (is_array($_POST['user'])) {
  63. $user_ids = array_diff($_POST['user'], array($_user['user_id']));
  64. if (count($user_ids) > 0) {
  65. CourseManager::unsubscribe_user($user_ids, $_SESSION['_course']['sysCode']);
  66. $message = get_lang('UsersUnsubscribed');
  67. }
  68. }
  69. }
  70. }
  71. }
  72. $user_image_pdf_size = 80;
  73. if (api_is_allowed_to_edit(null, true)) {
  74. if (isset($_GET['action'])) {
  75. switch ($_GET['action']) {
  76. case 'export' :
  77. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  78. $table_users = Database::get_main_table(TABLE_MAIN_USER);
  79. $is_western_name_order = api_is_western_name_order();
  80. $data = array();
  81. $a_users = array();
  82. if ($_configuration['multiple_access_urls']) {
  83. $current_access_url_id = api_get_current_access_url_id();
  84. }
  85. $extra_fields = UserManager::get_extra_user_data(api_get_user_id(), false, false, false, true);
  86. $extra_fields = array_keys($extra_fields);
  87. $select_email_condition = '';
  88. if (api_get_setting('show_email_addresses') == 'true') {
  89. $select_email_condition = ' user.email, ';
  90. if ($sort_by_first_name) {
  91. $a_users[0] = array('id', get_lang('FirstName'), get_lang('LastName'), get_lang('Username'), get_lang('Email'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active'));
  92. } else {
  93. $a_users[0] = array('id', get_lang('LastName'), get_lang('FirstName'), get_lang('Username'), get_lang('Email'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active'));
  94. }
  95. } else {
  96. if ($sort_by_first_name) {
  97. $a_users[0] = array('id', get_lang('FirstName'), get_lang('LastName'), get_lang('Username'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active'));
  98. } else {
  99. $a_users[0] = array('id', get_lang('LastName'), get_lang('FirstName'), get_lang('Username'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active'));
  100. }
  101. }
  102. $legal = '';
  103. if (isset($course_info['activate_legal']) AND $course_info['activate_legal'] == 1) {
  104. $legal = ', legal_agreement';
  105. $a_users[0][] = get_lang('LegalAgreementAccepted');
  106. }
  107. if ($_GET['type'] == 'pdf') {
  108. if ($is_western_name_order) {
  109. $a_users[0] = array('#', get_lang('UserPicture'), get_lang('OfficialCode'), get_lang('FirstName').', '.get_lang('LastName'));
  110. } else {
  111. $a_users[0] = array('#', get_lang('UserPicture'), get_lang('OfficialCode'), get_lang('LastName').', '.get_lang('FirstName'));
  112. }
  113. }
  114. $a_users[0] = array_merge($a_users[0], $extra_fields);
  115. // users subscribed to the course through a session
  116. if (api_get_session_id()) {
  117. $table_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  118. $table_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  119. $sql_query = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", user.username, $select_email_condition phone, user.official_code, active $legal
  120. FROM $table_session_course_user as session_course_user, $table_users as user, $table_session_user as su";
  121. if ($_configuration['multiple_access_urls']) {
  122. $sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au ';
  123. }
  124. $sql_query .=" WHERE course_code = '$course_code' AND
  125. session_course_user.id_user = user.user_id AND
  126. su.id_user = session_course_user.id_user AND session_course_user.id_session = su.id_session AND
  127. su.moved_to = 0 AND su.moved_status <> ".SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION." AND
  128. session_course_user.id_session = $session_id";
  129. if ($_configuration['multiple_access_urls']) {
  130. $sql_query .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id ";
  131. }
  132. //only users no coaches/teachers
  133. $sql_query .= " AND session_course_user.status = 0 ";
  134. $sql_query .= $sort_by_first_name ? ' ORDER BY user.firstname, user.lastname' : ' ORDER BY user.lastname, user.firstname';
  135. $rs = Database::query($sql_query);
  136. $counter = 1;
  137. while ($user = Database:: fetch_array($rs, 'ASSOC')) {
  138. if (isset($user['legal_agreement'])) {
  139. if ($user['legal_agreement'] == 1) {
  140. $user['legal_agreement'] = get_lang('Yes');
  141. } else {
  142. $user['legal_agreement'] = get_lang('No');
  143. }
  144. }
  145. $extra_fields = UserManager::get_extra_user_data($user['user_id'], false, false, false, true);
  146. if (!empty($extra_fields)) {
  147. foreach($extra_fields as $key => $extra_value) {
  148. $user[$key] = $extra_value;
  149. }
  150. }
  151. $data[] = $user;
  152. if ($_GET['type'] == 'pdf') {
  153. $user_info = api_get_user_info($user['user_id']);
  154. $user_image = Display::img($user_info['avatar'], null, array('width' => $user_image_pdf_size.'px'));
  155. if ($is_western_name_order) {
  156. $user_pdf = array($counter, $user_image, $user['official_code'], $user['firstname'].', '.$user['lastname'] );
  157. } else {
  158. $user_pdf = array($counter, $user_image, $user['official_code'], $user['lastname'].', '.$user['firstname'] );
  159. }
  160. $a_users[] = $user_pdf;
  161. } else {
  162. $a_users[] = $user;
  163. }
  164. $counter++;
  165. }
  166. }
  167. if ($session_id == 0) {
  168. // users directly subscribed to the course
  169. $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  170. $sql_query = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", user.username, $select_email_condition phone, user.official_code, active $legal
  171. FROM $table_course_user as course_user, $table_users as user ";
  172. if ($_configuration['multiple_access_urls']) {
  173. $sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au ';
  174. }
  175. $sql_query .= " WHERE course_code = '$course_code' AND course_user.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND course_user.user_id = user.user_id ";
  176. if ($_configuration['multiple_access_urls']) {
  177. $sql_query .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id ";
  178. }
  179. //only users no teachers/coaches
  180. $sql_query .= " AND course_user.status = 5 ";
  181. $sql_query .= ($sort_by_first_name ? " ORDER BY user.firstname, user.lastname" : " ORDER BY user.lastname, user.firstname");
  182. $rs = Database::query($sql_query);
  183. $counter = 1;
  184. while ($user = Database::fetch_array($rs, 'ASSOC')) {
  185. if (isset($user['legal_agreement'])) {
  186. if ($user['legal_agreement'] == 1) {
  187. $user['legal_agreement'] = get_lang('Yes');
  188. } else {
  189. $user['legal_agreement'] = get_lang('No');
  190. }
  191. }
  192. $extra_fields = UserManager::get_extra_user_data($user['user_id'], false, false, false, true);
  193. if (!empty($extra_fields)) {
  194. foreach ($extra_fields as $key => $extra_value) {
  195. $user[$key] = $extra_value;
  196. }
  197. }
  198. if ($_GET['type'] == 'pdf') {
  199. $user_info = api_get_user_info($user['user_id']);
  200. $user_image = Display::img($user_info['avatar'], null, array('width' => $user_image_pdf_size.'px'));
  201. if ($is_western_name_order) {
  202. $user_pdf = array($counter, $user_image, $user['official_code'], $user['firstname'].', '.$user['lastname'] );
  203. } else {
  204. $user_pdf = array($counter, $user_image, $user['official_code'], $user['lastname'].', '.$user['firstname'] );
  205. }
  206. $a_users[] = $user_pdf;
  207. } else {
  208. $a_users[] = $user;
  209. }
  210. $data[] = $user;
  211. $counter++;
  212. }
  213. }
  214. switch ($_GET['type']) {
  215. case 'csv' :
  216. Export::export_table_csv($a_users);
  217. exit;
  218. case 'xls' :
  219. Export::export_table_xls($a_users);
  220. exit;
  221. case 'pdf' :
  222. $description = '<table class="data_table_no_border">';
  223. if (api_get_session_id()) {
  224. $description .= '<tr><td>'.get_lang('Session').': </td><td class="highlight">'.api_get_session_name(api_get_session_id()).'</td>';
  225. }
  226. $description .= '<tr><td>'.get_lang('Course').': </td><td class="highlight">'.$course_info['name'].'</td>';
  227. $teachers = CourseManager::get_teacher_list_from_course_code($course_info['code']);
  228. //If I'm a teacher in this course show just my name
  229. if (isset($teachers[$user_id])) {
  230. if (!empty($teachers)) {
  231. $teacher_info = $teachers[$user_id];
  232. $description .= '<tr><td>'.get_lang('Teacher').': </td><td class="highlight">'.api_get_person_name($teacher_info['firstname'], $teacher_info['lastname']).'</td>';
  233. }
  234. } else {
  235. //If not show all teachers
  236. $teachers = CourseManager::get_teacher_list_from_course_code_to_string($course_info['code']);
  237. if (!empty($teachers)) {
  238. $description .= '<tr><td>'.get_lang('Teachers').': </td><td class="highlight">'.$teachers.'</td>';
  239. }
  240. }
  241. if (!empty($session_id)) {
  242. //If I'm a coach
  243. $coaches = CourseManager::get_coach_list_from_course_code($course_info['code'], $session_id);
  244. if (isset($coaches) && isset($coaches[$user_id])) {
  245. $user_info = api_get_user_info($user_id);
  246. $description .= '<tr><td>'.get_lang('Coach').': </td><td class="highlight">'.$user_info['complete_name'].'</td>';
  247. } else {
  248. //If not show everything
  249. $teachers = CourseManager::get_coach_list_from_course_code_to_string($course_info['code'], $session_id);
  250. if (!empty($teachers)) {
  251. $description .= '<tr><td>'.get_lang('Coachs').': </td><td class="highlight">'.$coaches.'</td>';
  252. }
  253. }
  254. }
  255. $description .= '<tr><td>'.get_lang('Date').': </td><td class="highlight">'.api_convert_and_format_date(time(), DATE_TIME_FORMAT_LONG).'</td>';
  256. $description .= '</table>';
  257. $header_attributes = array(
  258. array('style' => 'width:10px'),
  259. array('style' => 'width:30px'),
  260. array('style' => 'width:50px'),
  261. array('style' => 'width:500px'),
  262. );
  263. $params = array(
  264. 'add_signatures' => false,
  265. 'filename' => get_lang('UserList'),
  266. 'pdf_title' => get_lang('StudentList'),
  267. 'pdf_description' => $description,
  268. 'header_attributes' => $header_attributes
  269. );
  270. Export::export_table_pdf($a_users, $params);
  271. exit;
  272. }
  273. }
  274. }
  275. } // end if allowed to edit
  276. if (api_is_allowed_to_edit(null, true)) {
  277. // Unregister user from course
  278. if (isset($_REQUEST['unregister']) && $_REQUEST['unregister']) {
  279. if (isset($_GET['user_id']) && is_numeric($_GET['user_id']) && $_GET['user_id'] != $_user['user_id']) {
  280. $user_id = Database::escape_string($_GET['user_id']);
  281. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  282. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  283. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  284. $sql = 'SELECT '.$tbl_user.'.user_id
  285. FROM '.$tbl_user.' user
  286. INNER JOIN '.$tbl_session_rel_user.' reluser
  287. ON user.user_id = reluser.id_user AND reluser.relation_type<>'.SESSION_RELATION_TYPE_RRHH.'
  288. INNER JOIN '.$tbl_session_rel_course.' rel_course
  289. ON rel_course.id_session = reluser.id_session
  290. WHERE user.user_id = "'.$user_id.'"
  291. AND rel_course.course_code = "'.$course_code.'"';
  292. $result = Database::query($sql);
  293. $row = Database::fetch_array($result, 'ASSOC');
  294. if ($row['user_id'] == $user_id || $row['user_id'] == "") {
  295. CourseManager::unsubscribe_user($_GET['user_id'], $_SESSION['_course']['sysCode']);
  296. $message = get_lang('UserUnsubscribed');
  297. } else {
  298. $message = get_lang('ThisStudentIsSubscribeThroughASession');
  299. }
  300. }
  301. }
  302. } else {
  303. //if student can unsubsribe
  304. if (isset($_REQUEST['unregister']) && $_REQUEST['unregister'] == 'yes') {
  305. if ($course_info['unsubscribe'] == 1) {
  306. $user_id = api_get_user_id();
  307. CourseManager::unsubscribe_user($user_id, $course_info['code']);
  308. header('Location: '.api_get_path(WEB_PATH).'user_portal.php');
  309. exit;
  310. }
  311. }
  312. }
  313. /* FUNCTIONS */
  314. function display_user_search_form() {
  315. echo '<form method="get" action="user.php">';
  316. echo get_lang("SearchForUser") . "&nbsp;&nbsp;";
  317. echo '<input type="text" name="keyword" value="'.Security::remove_XSS($_GET['keyword']).'"/>';
  318. echo '<input type="submit" value="'.get_lang('SearchButton').'"/>';
  319. echo '</form>';
  320. }
  321. /* Header */
  322. if (isset($origin) && $origin == 'learnpath') {
  323. Display::display_reduced_header();
  324. } else {
  325. if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
  326. $interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("Users"));
  327. $tool_name = get_lang('SearchResults');
  328. } else {
  329. $tool_name = get_lang('Users');
  330. $origin = 'users';
  331. }
  332. Display::display_header($tool_name, "User");
  333. }
  334. /* MAIN CODE*/
  335. //statistics
  336. event_access_tool(TOOL_USER);
  337. /* Setting the permissions for this page */
  338. $is_allowed_to_track = ($is_courseAdmin || $is_courseTutor);
  339. // Tool introduction
  340. Display::display_introduction_section(TOOL_USER, 'left');
  341. $actions = '';
  342. if ( api_is_allowed_to_edit(null, true)) {
  343. echo '<div class="actions">';
  344. // the action links
  345. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
  346. $actions .= '<a href="subscribe_user.php?'.api_get_cidreq().'">'.Display::return_icon('user_subscribe_course.png',get_lang("SubscribeUserToCourse"),'',ICON_SIZE_MEDIUM).'</a> ';
  347. $actions .= "<a href=\"subscribe_user.php?".api_get_cidreq()."&type=teacher\">".Display::return_icon('teacher_subscribe_course.png', get_lang("SubscribeUserToCourseAsTeacher"),'',ICON_SIZE_MEDIUM)."</a> ";
  348. }
  349. $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&amp;type=csv">'.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'),'',ICON_SIZE_MEDIUM).'</a> ';
  350. $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&amp;type=xls">'.Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).'</a> ';
  351. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
  352. $actions .= '<a href="user_import.php?'.api_get_cidreq().'&action=import">'.Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'),'',ICON_SIZE_MEDIUM).'</a> ';
  353. }
  354. $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&type=pdf">'.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_MEDIUM).'</a> ';
  355. $actions .= "<a href=\"../group/group.php?".api_get_cidreq()."\">".Display::return_icon('group.png', get_lang("GroupUserManagement"),'',ICON_SIZE_MEDIUM)."</a>";
  356. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
  357. $actions .= ' <a class="btn" href="class.php?'.api_get_cidreq().'">'.get_lang('Classes').'</a>';
  358. }
  359. //$actions .= ' <a class="btn" href="social_groups.php?'.api_get_cidreq().'">'.get_lang('SocialGroups').'</a>';
  360. // Build search-form
  361. $form = new FormValidator('search_user', 'get', '', '', null, false);
  362. $renderer = $form->defaultRenderer();
  363. $renderer->setElementTemplate('<span>{element}</span> ');
  364. $form->add_textfield('keyword', '', false);
  365. $form->addElement('style_submit_button', 'submit', get_lang('SearchButton'), 'class="search"');
  366. $form->addElement('static', 'additionalactions', null, $actions);
  367. $form->display();
  368. echo '</div>';
  369. }
  370. if (isset($message)) {
  371. Display::display_confirmation_message($message);
  372. }
  373. /* DISPLAY LIST OF USERS */
  374. /**
  375. * * Get the users to display on the current page.
  376. */
  377. function get_number_of_users() {
  378. $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : null;
  379. return CourseManager::get_users_count_in_course(api_get_course_id(), api_get_session_id(), null, null, null, $keyword);
  380. }
  381. /**
  382. * Get the users to display on the current page.
  383. */
  384. function get_user_data($from, $number_of_items, $column, $direction) {
  385. global $origin;
  386. global $course_info;
  387. global $is_western_name_order;
  388. global $session_id;
  389. $a_users = array();
  390. // limit
  391. $limit = 'LIMIT '.intval($from).','.intval($number_of_items);
  392. if (!in_array($direction, array('ASC', 'DESC'))) {
  393. $direction = 'ASC';
  394. }
  395. switch ($column) {
  396. case 2: //official code
  397. $order_by = 'ORDER BY user.official_code '.$direction;
  398. break;
  399. case 3:
  400. if ($is_western_name_order) {
  401. $order_by = 'ORDER BY user.firstname '.$direction.', user.lastname '.$direction;
  402. } else {
  403. $order_by = 'ORDER BY user.lastname '.$direction.', user.firstname '.$direction;
  404. }
  405. break;
  406. case 4:
  407. if ($is_western_name_order) {
  408. $order_by = 'ORDER BY user.lastname '.$direction.', user.firstname '.$direction;
  409. } else {
  410. $order_by = 'ORDER BY user.firstname '.$direction.', user.lastname '.$direction;
  411. }
  412. break;
  413. case 5: //username
  414. $order_by = 'ORDER BY user.username '.$direction;
  415. break;
  416. default:
  417. if ($is_western_name_order) {
  418. $order_by = 'ORDER BY user.lastname '.$direction.', user.firstname '.$direction;
  419. } else {
  420. $order_by = 'ORDER BY user.firstname '.$direction.', user.lastname '.$direction;
  421. }
  422. break;
  423. }
  424. $session_id = api_get_session_id();
  425. $course_code = api_get_course_id();
  426. $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : null;
  427. $a_course_users = CourseManager :: get_user_list_from_course_code($course_code, $session_id, $limit, $order_by, null, $keyword);
  428. foreach ($a_course_users as $user_id => $o_course_user) {
  429. $groups_name = GroupManager :: get_user_group_name($user_id);
  430. $temp = array();
  431. if (api_is_allowed_to_edit(null, true)) {
  432. //if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
  433. $temp[] = $user_id;
  434. //}
  435. $image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true);
  436. $user_profile = UserManager::get_picture_user($user_id, $image_path['file'], 22, USER_IMAGE_SIZE_SMALL, ' width="22" height="22" ');
  437. if (!api_is_anonymous()) {
  438. $photo = '<a href="userInfo.php?'.api_get_cidreq().'&origin='.$origin.'&amp;uInfo='.$user_id.'" title="'.get_lang('Info').'" ><img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" title="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" /></a>';
  439. } else {
  440. $photo = '<img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" title="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" />';
  441. }
  442. $temp[] = $photo;
  443. $temp[] = $o_course_user['official_code'];
  444. if ($is_western_name_order) {
  445. $temp[] = $o_course_user['firstname'];
  446. $temp[] = $o_course_user['lastname'];
  447. } else {
  448. $temp[] = $o_course_user['lastname'];
  449. $temp[] = $o_course_user['firstname'];
  450. }
  451. $temp[] = $o_course_user['username'];
  452. $temp[] = isset($o_course_user['role']) ? $o_course_user['role'] : null; //Description
  453. $temp[] = implode(', ', $groups_name); //Group
  454. // Status
  455. $default_status = '-';
  456. if ((isset($o_course_user['status_rel']) && $o_course_user['status_rel'] == 1) || (isset($o_course_user['status_session']) && $o_course_user['status_session'] == 2)) {
  457. $default_status = get_lang('CourseManager');
  458. } elseif (isset($o_course_user['tutor_id']) && $o_course_user['tutor_id'] == 1) {
  459. $default_status = get_lang('Tutor');
  460. }
  461. $temp[] = $default_status;
  462. //Active
  463. $temp[] = $o_course_user['active'];
  464. //User id for actions
  465. $temp[] = $user_id;
  466. } else {
  467. $image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true);
  468. $image_repository = $image_path['dir'];
  469. $existing_image = $image_path['file'];
  470. if (!api_is_anonymous()) {
  471. $photo= '<a href="userInfo.php?'.api_get_cidreq().'&origin='.$origin.'&amp;uInfo='.$user_id.'" title="'.get_lang('Info').'" ><img src="'.$image_repository.$existing_image.'" alt="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" width="22" height="22" title="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" /></a>';
  472. } else {
  473. $photo= '<img src="'.$image_repository.$existing_image.'" alt="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" width="22" height="22" title="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" />';
  474. }
  475. $temp[] = $user_id;
  476. $temp[] = $photo;
  477. $temp[] = $o_course_user['official_code'];
  478. if ($is_western_name_order) {
  479. $temp[] = $o_course_user['firstname'];
  480. $temp[] = $o_course_user['lastname'];
  481. } else {
  482. $temp[] = $o_course_user['lastname'];
  483. $temp[] = $o_course_user['firstname'];
  484. }
  485. $temp[] = $o_course_user['username'];
  486. $temp[] = $o_course_user['role'];
  487. $temp[] = implode(', ', $groups_name);//Group
  488. if ($course_info['unsubscribe'] == 1) {
  489. //User id for actions
  490. $temp[] = $user_id;
  491. }
  492. //$temp[] = $o_course_user['official_code'];
  493. }
  494. $a_users[$user_id] = $temp;
  495. }
  496. return $a_users;
  497. }
  498. /**
  499. * Build the active-column of the table to lock or unlock a certain user
  500. * lock = the user can no longer use this account
  501. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  502. * @param int $active the current state of the account
  503. * @param int $user_id The user id
  504. * @param string $url_params
  505. * @return string Some HTML-code with the lock/unlock button
  506. */
  507. function active_filter($active, $url_params, $row) {
  508. global $_user;
  509. if ($active=='1') {
  510. $action='AccountActive';
  511. $image='accept';
  512. }
  513. if ($active=='0') {
  514. $action='AccountInactive';
  515. $image='error';
  516. }
  517. $result = '';
  518. if ($row[count($row)-1]<>$_user['user_id']) { // you cannot lock yourself out otherwise you could disable all the accounts including your own => everybody is locked out and nobody can change it anymore.
  519. $result = '<center><img src="../img/icons/16/'.$image.'.png" border="0" style="vertical-align: middle;" alt="'.get_lang(ucfirst($action)).'" title="'.get_lang(ucfirst($action)).'"/></center>';
  520. }
  521. return $result;
  522. }
  523. /**
  524. * Build the modify-column of the table
  525. * @param int $user_id The user id
  526. * @return string Some HTML-code
  527. */
  528. function modify_filter($user_id) {
  529. global $origin, $_course, $is_allowed_to_track, $charset, $course_info;
  530. $current_user_id = api_get_user_id();
  531. $result = "";
  532. if ($is_allowed_to_track) {
  533. $result .= '<a href="../mySpace/myStudents.php?'.api_get_cidreq().'&student='.$user_id.'&amp;details=true&amp;course='.$_course['id'].'&amp;origin=user_course&amp;id_session='.api_get_session_id().'" title="'.get_lang('Tracking').'" ><img border="0" alt="'.get_lang('Tracking').'" src="../img/icons/22/stats.png" /></a>';
  534. }
  535. //if platform admin, show the login_as icon (this drastically shortens
  536. // time taken by support to test things out)
  537. if (api_is_platform_admin()) {
  538. $result .= ' <a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&amp;user_id='.$user_id.'&amp;sec_token='.Security::getCurrentToken().'">'.Display::return_icon('login_as.gif', get_lang('LoginAs')).'</a>&nbsp;&nbsp;';
  539. }
  540. if (api_is_allowed_to_edit(null, true)) {
  541. // edit
  542. $result .= '<a href="userInfo.php?'.api_get_cidreq().'&origin='.$origin.'&amp;editMainUserInfo='.$user_id.'" title="'.get_lang('Edit').'" >'.Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
  543. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
  544. // unregister
  545. if ($user_id != $current_user_id) {
  546. $result .= '<a class="btn btn-small btn-danger" href="'.api_get_self().'?'.api_get_cidreq().'&unregister=yes&amp;user_id='.$user_id.'" title="'.get_lang('Unreg').' " onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;">'.get_lang('Unreg').'</a>&nbsp;';
  547. } else {
  548. //$result .= Display::return_icon('unsubscribe_course_na.png', get_lang('Unreg'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
  549. }
  550. }
  551. } else {
  552. //Show buttons for unsubscribe
  553. if ($course_info['unsubscribe'] == 1) {
  554. if ($user_id == $current_user_id) {
  555. $result .= '<a class="btn btn-small btn-danger" href="'.api_get_self().'?'.api_get_cidreq().'&unregister=yes&amp;user_id='.$user_id.'" title="'.get_lang('Unreg').' " onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;">'.get_lang('Unreg').'</a>&nbsp;';
  556. }
  557. }
  558. }
  559. return $result;
  560. }
  561. function hide_field() {
  562. return null;
  563. }
  564. $default_column = 3;
  565. $table = new SortableTable('user_list', 'get_number_of_users', 'get_user_data', $default_column);
  566. $parameters['keyword'] = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  567. // Create a sortable table with user-data
  568. $parameters['sec_token'] = Security::get_token();
  569. $table->set_additional_parameters($parameters);
  570. $header_nr = 0;
  571. $table->set_header($header_nr++, '', false);
  572. $table->set_header($header_nr++, get_lang('Photo'), false);
  573. $table->set_header($header_nr++, get_lang('OfficialCode'));
  574. if ($is_western_name_order) {
  575. $table->set_header($header_nr++, get_lang('FirstName'));
  576. $table->set_header($header_nr++, get_lang('LastName'));
  577. } else {
  578. $table->set_header($header_nr++, get_lang('LastName'));
  579. $table->set_header($header_nr++, get_lang('FirstName'));
  580. }
  581. $table->set_header($header_nr++, get_lang('LoginName')); //
  582. $table->set_header($header_nr++, get_lang('Description'), false);
  583. $table->set_header($header_nr++, get_lang('GroupSingle'), false);
  584. if (api_is_allowed_to_edit(null, true) && api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
  585. } else {
  586. $table->set_column_filter(0, 'hide_field');
  587. }
  588. if (api_is_allowed_to_edit(null, true)) {
  589. $table->set_header($header_nr++, get_lang('Status'), false);
  590. $table->set_header($header_nr++, get_lang('Active'), false);
  591. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
  592. $table->set_column_filter(9, 'active_filter');
  593. } else {
  594. $table->set_column_filter(9, 'active_filter');
  595. }
  596. //actions column
  597. $table->set_header($header_nr++, get_lang('Action'), false);
  598. $table->set_column_filter($header_nr-1, 'modify_filter');
  599. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
  600. $table->set_form_actions(array('unsubscribe' => get_lang('Unreg')), 'user');
  601. }
  602. } else {
  603. if ($course_info['unsubscribe'] == 1) {
  604. $table->set_header($header_nr++, get_lang('Action'), false);
  605. $table->set_column_filter($header_nr-1, 'modify_filter');
  606. }
  607. }
  608. $table->display();
  609. if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
  610. $keyword_name = Security::remove_XSS($_GET['keyword']);
  611. echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
  612. }
  613. if (api_get_setting('allow_user_headings') == 'true' && $is_courseAdmin && api_is_allowed_to_edit() && $origin != 'learnpath') { // only course administrators see this line
  614. echo "<div align=\"right\">", "<form method=\"post\" action=\"userInfo.php\">", get_lang("CourseAdministratorOnly"), " : ", "<input type=\"submit\" class=\"save\" name=\"viewDefList\" value=\"".get_lang("DefineHeadings")."\" />", "</form>", "</div>\n";
  615. }
  616. if ($origin != 'learnpath') {
  617. Display::display_footer();
  618. }