admin.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Special reporting page for admins.
  5. */
  6. ob_start();
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. $this_section = SECTION_TRACKING;
  10. $nameTools = get_lang('Administrators');
  11. api_block_anonymous_users();
  12. $interbreadcrumb[] = ["url" => "index.php", "name" => get_lang('Reporting')];
  13. Display :: display_header($nameTools);
  14. api_display_tool_title($nameTools);
  15. // Database Table Definitions
  16. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  17. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  18. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  19. $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  20. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  21. $tbl_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
  22. if (isset($_POST['export'])) {
  23. $order_clause = api_is_western_name_order(PERSON_NAME_DATA_EXPORT) ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  24. } else {
  25. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  26. }
  27. $sql = "SELECT user.user_id,lastname,firstname,email
  28. FROM $tbl_user as user, $tbl_admin as admin
  29. WHERE admin.user_id=user.user_id".$order_clause;
  30. $result_admins = Database::query($sql);
  31. if (api_is_western_name_order()) {
  32. echo '<table class="data_table"><tr><th>'.get_lang('First name').'</th><th>'.get_lang('Last name').'</th><th>'.get_lang('e-mail').'</th></tr>';
  33. } else {
  34. echo '<table class="data_table"><tr><th>'.get_lang('Last name').'</th><th>'.get_lang('First name').'</th><th>'.get_lang('e-mail').'</th></tr>';
  35. }
  36. if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
  37. $header[] = get_lang('First name');
  38. $header[] = get_lang('Last name');
  39. } else {
  40. $header[] = get_lang('Last name');
  41. $header[] = get_lang('First name');
  42. }
  43. $header[] = get_lang('e-mail');
  44. if (Database::num_rows($result_admins) > 0) {
  45. while ($admins = Database::fetch_array($result_admins)) {
  46. $user_id = $admins["user_id"];
  47. $lastname = $admins["lastname"];
  48. $firstname = $admins["firstname"];
  49. $email = $admins["email"];
  50. if ($i % 2 == 0) {
  51. $css_class = "row_odd";
  52. if ($i % 20 == 0 && $i != 0) {
  53. if (api_is_western_name_order()) {
  54. echo '<tr><th>'.get_lang('First name').'</th><th>'.get_lang('Last name').'</th><th>'.get_lang('e-mail').'</th></tr>';
  55. } else {
  56. echo '<tr><th>'.get_lang('Last name').'</th><th>'.get_lang('First name').'</th><th>'.get_lang('e-mail').'</th></tr>';
  57. }
  58. }
  59. } else {
  60. $css_class = "row_even";
  61. }
  62. $i++;
  63. if (api_is_western_name_order()) {
  64. echo "<tr class=".$css_class."><td>$firstname</td><td>$lastname</td><td><a href='mailto:".$email."'>$email</a></td></tr>";
  65. } else {
  66. echo "<tr class=".$css_class."><td>$lastname</td><td>$firstname</td><td><a href='mailto:".$email."'>$email</a></td></tr>";
  67. }
  68. if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
  69. $data[$user_id]["firstname"] = $firstname;
  70. $data[$user_id]["lastname"] = $lastname;
  71. } else {
  72. $data[$user_id]["lastname"] = $lastname;
  73. $data[$user_id]["firstname"] = $firstname;
  74. }
  75. $data[$user_id]["email"] = $email;
  76. }
  77. } else {
  78. // No results
  79. echo '<tr><td colspan="3">'.get_lang('No results found').'</td></tr>';
  80. }
  81. echo '</table>';
  82. if (isset($_POST['export'])) {
  83. export_csv($header, $data, 'administrators.csv');
  84. }
  85. echo "
  86. <br /><br />
  87. <form method='post' action='admin.php'>
  88. <button type='submit' class='save' name='export' value='".get_lang('Excel export')."'>
  89. ".get_lang('Excel export')."
  90. </button>
  91. <form>
  92. ";
  93. Display::display_footer();