example_fill_users_fields.php 1.3 KB

123456789101112131415161718192021222324252627
  1. <?php
  2. /**
  3. * This script populates the user_extra_fields_value table with a new field which
  4. * contains the username for each user. This allows you to use web
  5. * services to update users based on their username (which is assumed
  6. * to be the same as in the application which calls the webservice).
  7. * This script should be called any time a new user (or a large group of new
  8. * users) is added to the database.
  9. * @package chamilo.webservices
  10. */
  11. //remove the next line to enable the script (this can harm your database so
  12. // don't enable unless you know what you're doing and you have a backup)
  13. die();
  14. // update this ID after you create the corresponding field through the Chamilo
  15. // profile fields manager (admin page, users section) as text field.
  16. // Give this field a name you will later use in original_field_id_name, while
  17. // you will use the normal username of Chamilo users.
  18. $extra_field_id = 9;
  19. require_once('../inc/global.inc.php');
  20. $tuser = Database::get_main_table(TABLE_MAIN_USER);
  21. $tuserfv = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
  22. $sql = "SELECT user_id, username FROM $tuser ORDER BY user_id";
  23. $res = Database::query($sql);
  24. while($row = Database::fetch_array($res)) {
  25. $sql2 = "INSERT INTO $tuserfv (user_id, field_id, field_value) VALUES (".$row['user_id'].", 11,'".$row['username']."')";
  26. $res2 = Database::query($sql2);
  27. }