users_no_course.php 925 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script select all users with no course subscriptions and
  5. * add it to a selected course.
  6. */
  7. exit;
  8. require __DIR__.'/../../main/inc/global.inc.php';
  9. api_protect_admin_script();
  10. // Course that users with no course will be registered:
  11. $courseCode = '';
  12. $user = Database::get_main_table(TABLE_MAIN_USER);
  13. $userCourse = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  14. $sql = "SELECT * FROM $user WHERE user_id NOT IN (
  15. SELECT user_id FROM $userCourse
  16. ) AND status <> ".ANONYMOUS."
  17. ";
  18. $result = Database::query($sql);
  19. $students = Database::store_result($result);
  20. if (!empty($students)) {
  21. foreach ($students as $student) {
  22. var_dump($student['username'].'- '.$student['user_id']);
  23. $result = CourseManager::subscribeUser($student['user_id'], $courseCode);
  24. var_dump($result);
  25. echo '<br />';
  26. }
  27. }