get_data_from_mail.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * This script gets users details of a given list of users
  4. * (given by e-mail) and prints the details in /tmp/list.txt
  5. * To enable script, prefix the first die(); with //.
  6. *
  7. * @package chamilo.cron.user_import
  8. */
  9. /**
  10. * Initialization.
  11. */
  12. /* Example of input file:
  13. sam@example.com
  14. Matthew@example.com
  15. HERMAN@example.com
  16. */
  17. die();
  18. //change filename depending on file containing mails list
  19. $list = file('input.txt');
  20. require_once '../../inc/global.inc.php';
  21. $users = Database::get_main_table(TABLE_MAIN_USER);
  22. $string = '';
  23. foreach ($list as $mail) {
  24. $mail = trim($mail);
  25. $sql = "SELECT user_id, official_code, firstname, lastname, email FROM $users WHERE email = '$mail'\n";
  26. $res = Database::query($sql);
  27. if (Database::num_rows($res) == 0) {
  28. $string .= 'No encontrado;'.$row['email'];
  29. } else {
  30. $row = Database::fetch_assoc($res);
  31. $string .= $row['user_id'].';'.$row['email'].';'.$row['firstname'].';'.$row['lastname'].';'.$row['official_code']."\r\n";
  32. }
  33. }
  34. echo $string;
  35. file_put_contents('/tmp/list.txt', $string);