get_data_from_mail.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. * @package chamilo.cron.user_import
  7. */
  8. /**
  9. * Initialization
  10. */
  11. /* Example of input file:
  12. sam@example.com
  13. Matthew@example.com
  14. HERMAN@example.com
  15. */
  16. die();
  17. //change filename depending on file containing mails list
  18. $list = file('input.txt');
  19. require_once '../../inc/global.inc.php';
  20. $users = Database::get_main_table(TABLE_MAIN_USER);
  21. $string='';
  22. foreach ($list as $mail) {
  23. $mail = trim($mail);
  24. $sql = "SELECT user_id, official_code, firstname, lastname, email FROM $users WHERE email = '$mail'\n";
  25. $res = Database::query($sql);
  26. if ($res === false) { die(mysql_error());}
  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);