user.php 33 KB

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