example_fill_users_fields.php 1.3 KB

1234567891011121314151617181920212223242526272829
  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. *
  10. * @package chamilo.webservices
  11. */
  12. //remove the next line to enable the script (this can harm your database so
  13. // don't enable unless you know what you're doing and you have a backup)
  14. die();
  15. // update this ID after you create the corresponding field through the Chamilo
  16. // profile fields manager (admin page, users section) as text field.
  17. // Give this field a name you will later use in original_field_id_name, while
  18. // you will use the normal username of Chamilo users.
  19. $extra_field_id = 9;
  20. require_once '../inc/global.inc.php';
  21. $tuser = Database::get_main_table(TABLE_MAIN_USER);
  22. $tuserfv = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
  23. $sql = "SELECT user_id, username FROM $tuser ORDER BY user_id";
  24. $res = Database::query($sql);
  25. while ($row = Database::fetch_array($res)) {
  26. $sql2 = "INSERT INTO $tuserfv (item_id, field_id, value)
  27. VALUES (".$row['user_id'].", 11,'".$row['username']."')";
  28. $res2 = Database::query($sql2);
  29. }