cobaltusers.module 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. function cobaltusers_init() {
  3. if (user_access('use cobalt')) {
  4. drupal_add_js(drupal_get_path('module', 'cobalt') . '/js/cobalt.users.js');
  5. }
  6. }
  7. function cobaltusers_menu() {
  8. $items = array();
  9. $items['cobalt/data/users_json/%'] = array(
  10. 'title' => 'Serialized users',
  11. 'page callback' => 'cobaltusers_json',
  12. 'page arguments' => array(2),
  13. 'access arguments' => array('use cobalt'),
  14. 'type' => MENU_CALLBACK,
  15. );
  16. return $items;
  17. }
  18. function cobaltusers_json($last_update) {
  19. // We're just fetching the bare minimum of what we need for the
  20. // user_*_access methods and display.
  21. $res = db_query("SELECT uid, name, access, status FROM {users}
  22. WHERE created > :last_update
  23. ORDER BY uid DESC
  24. LIMIT 100", array(
  25. ':last_update' => $last_update,
  26. ));
  27. $users = array();
  28. foreach ($res as $account) {
  29. if (user_access('administer users')) {
  30. $access = 'rwd';
  31. }
  32. else {
  33. $access = (user_view_access($account)?'r':'') . (user_edit_access($account)?'w':'');
  34. }
  35. if (!empty($access)) {
  36. $users[] = array($account->uid, $account->name, $access);
  37. }
  38. }
  39. print drupal_json_output($users);
  40. exit;
  41. }