/[drupal]/contributions/modules/advuser/advuser.module
ViewVC logotype

Contents of /contributions/modules/advuser/advuser.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.17 - (show annotations) (download) (as text)
Mon Apr 6 14:42:20 2009 UTC (7 months, 3 weeks ago) by earnie
Branch: MAIN
CVS Tags: HEAD
Changes since 1.16: +24 -17 lines
File MIME type: text/x-php
Update HEAD to latest version.
1 <?php
2 /**
3 * @file
4 * Advanced user module allows you to select users based on an advanced set of
5 * filtering and apply actions to block, unblock, delete or email the selected
6 * users.
7 *
8 * $Id: advuser.module,v 1.14.2.7 2009/03/18 13:13:12 earnie Exp $
9 **/
10
11 /**
12 * @constants
13 */
14 define('ADVUSER_SUBSTITUTION_TEXT', '<strong>Substitution variables</strong> available in subject and email body<br/><em> %user_name, %user_email, %user_status, %user_created, %user_theme, %user_timezone, %user_language, %user_signature, %site, %uri, %google_user (search google for user email), %yahoo_user (search yahoo for user email)</em>');
15
16 /**
17 * Implementation of hook_perm().
18 */
19 function advuser_perm() {
20 return array(
21 'administer advuser',
22 'access advuser',
23 'send email advuser',
24 'receive email advuser',
25 );
26 }
27
28 /**
29 * Implementation of hook_menu().
30 */
31 function advuser_menu() {
32
33 $items['admin/settings/advuser'] = array(
34 'title' => t('Advanced User'),
35 'description' => t('Advanced User Settings'),
36 'page callback' => 'drupal_get_form',
37 'page arguments' => array('advuser_settings'),
38 'access arguments' => array('administer advuser'),
39 'type' => MENU_NORMAL_ITEM,
40 'file' => 'advuser_filters.inc',
41 );
42
43 $items['admin/user/user/advuser'] = array(
44 'title' => t('Advanced'),
45 'description' => t('List, add, edit and email users.'),
46 'page callback' => 'advuser_admin',
47 'page arguments' => array('list'),
48 'access arguments' => array('access advuser'),
49 'type' => MENU_LOCAL_TASK,
50 'file' => 'advuser_filters.inc',
51 );
52
53 return $items;
54 }
55
56 function advuser_admin($callback_arg = '') {
57 $op = isset($_POST['op']) ? $_POST['op'] : $callback_arg;
58
59 switch ($op) {
60 default: {
61 if ($_POST['accounts'] && $_POST['operation'] == 'delete') {
62 $output = drupal_get_form('advuser_multiple_delete_confirm');
63 }
64 elseif ($_POST['accounts'] && $_POST['operation'] == 'email') {
65 $output = drupal_get_form('advuser_multiple_email_confirm');
66 }
67 else {
68 $output = drupal_get_form('advuser_filter_form');
69 $output .= drupal_get_form('advuser_admin_account');
70 }
71 } break;
72 }
73 return $output;
74 }
75
76 function advuser_admin_account() {
77 $filter = advuser_build_filter_query();
78 $header = array(
79 array(),
80 array('data' => t('Username'), 'field' => 'u.name'),
81 array('data' => t('Status'), 'field' => 'u.status'),
82 );
83 $roles = advuser_user_roles();
84 if (count($roles)) {
85 $header[] = t('Roles');
86 }
87 $header = array_merge($header, array(
88 array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'),
89 array('data' => t('Last access'), 'field' => 'u.access'),
90 ));
91
92 $query = '';
93 $ff = array();
94 $pf = array();
95 foreach (advuser_profile_fields() as $field) {
96 $ff[] = array('data'=>t($field->title), 'field'=>"$field->name.value");
97 $pf[] = "LEFT JOIN {profile_values} $field->name ON $field->name.fid = $field->fid AND $field->name.uid = u.uid";
98 }
99 $header = array_merge($header, $ff);
100 $header[] = t('Operations');
101
102 $filter['join'] .= count($pf) ? ' ' . implode(' ', array_unique($pf)) : NULL;
103
104 $sql = 'SELECT DISTINCT u.uid, u.name, u.status, u.created, u.access '.$pquery.' FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid '. $filter['join'] .' WHERE u.uid != 0 '. $filter['where'];
105
106 $sql .= tablesort_sql($header);
107 $query_count = 'SELECT COUNT(DISTINCT u.uid) FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid '. $filter['join'] .' WHERE u.uid != 0 '. $filter['where'];
108 $result = pager_query($sql, variable_get('advuser_listno', 50), 0, $query_count, $filter['args']);
109
110 $form['options'] = array(
111 '#type' => 'fieldset',
112 '#title' => t('Update options'),
113 '#prefix' => '<div class="container-inline">',
114 '#suffix' => '</div>',
115 );
116 $options = array();
117
118 $operations = module_invoke_all('user_operations');
119 $operations = array_merge($operations,module_invoke_all('advuser_operations'));
120 foreach ($operations as $operation => $array) {
121 $options[$operation] = $array['label'];
122 }
123 $form['options']['operation'] = array(
124 '#type' => 'select',
125 '#options' => $options,
126 '#default_value' => 'unblock',
127 );
128 $form['options']['submit'] = array(
129 '#type' => 'submit',
130 '#value' => t('Update'),
131 );
132
133 $destination = drupal_get_destination();
134
135 $status = array(t('blocked'), t('active'));
136 $roles = advuser_user_roles();
137
138 while ($account = db_fetch_object($result)) {
139 $accounts[$account->uid] = '';
140 $form['name'][$account->uid] = array('#value' => theme('username', $account));
141 $form['status'][$account->uid] = array('#value' => $status[$account->status]);
142 $users_roles = array();
143 $roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = %d', $account->uid);
144 while ($user_role = db_fetch_object($roles_result)) {
145 $users_roles[] = $roles[$user_role->rid];
146 }
147 asort($users_roles);
148 $form['roles'][$account->uid][0] = array('#value' => theme('item_list', $users_roles));
149 $form['member_for'][$account->uid] = array('#value' => format_interval(time() - $account->created));
150 $form['last_access'][$account->uid] = array('#value' => $account->access ? t('@time ago', array('@time' => format_interval(time() - $account->access))) : t('never'));
151 module_invoke('profile', 'load_profile', $account);
152 foreach(advuser_profile_fields() as $field) {
153 $form[$field->name][$account->uid] = array('#value' => profile_view_field($account, $field));
154 }
155 $fv = l(t('edit'), "user/$account->uid/edit", array('query' => $destination));
156 if ($account->uid != 1) {
157 $fv .= ' | ' . l(t('delete'), "user/$account->uid/delete", array('query' => $destination));
158 }
159 $form['operations'][$account->uid] = array('#value' => $fv);
160 }
161 $form['accounts'] = array(
162 '#type' => 'checkboxes',
163 '#options' => $accounts
164 );
165 $form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
166
167 return $form;
168 }
169
170 /**
171 * hook_theme implementation
172 */
173 function advuser_theme() {
174 return array(
175 'advuser_admin_account' => array(
176 'arguments' => array('form' => NULL),
177 ),
178 'advuser_filters' => array(
179 'arguments' => array('form' => NULL),
180 ),
181 );
182 }
183
184 /**
185 * Theme user administration overview.
186 */
187 function theme_advuser_admin_account($form) {
188 static $profile_fields = array();
189 // Overview table:
190 $header = array(
191 theme('table_select_header_cell'),
192 array('data' => t('Username'), 'field' => 'u.name'),
193 array('data' => t('Status'), 'field' => 'u.status'),
194 );
195 $roles = advuser_user_roles();
196 if (count($roles)) {
197 $header[] = t('Roles');
198 }
199 $header = array_merge($header, array(
200 array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'),
201 array('data' => t('Last access'), 'field' => 'u.access'),
202 ));
203
204 $ff = array();
205 foreach (advuser_profile_fields() as $field) {
206 $ff[] = array('data'=>t($field->title), 'field'=>$field->name);
207 }
208 $header = array_merge($header, $ff);
209 $header[] = t('Operations');
210
211 $output = drupal_render($form['options']);
212 if (isset($form['name']) && is_array($form['name'])) {
213 foreach (element_children($form['name']) as $key) {
214 $row = array(
215 drupal_render($form['accounts'][$key]),
216 drupal_render($form['name'][$key]),
217 drupal_render($form['status'][$key]),
218 );
219 $roles = advuser_user_roles();
220 if (count($roles)) {
221 $row[] = drupal_render($form['roles'][$key]);
222 }
223 $row = array_merge($row, array(
224 drupal_render($form['member_for'][$key]),
225 drupal_render($form['last_access'][$key]),
226 ));
227
228 if (module_exists('profile')) {
229 $fields = variable_get('advuser_profile_fields', NULL);
230
231 if (is_array($fields)) {
232 foreach ( $fields as $fid => $value) {
233 if ( $value ) {
234 if (empty($profile_fields[$fid])) {
235
236 $field = db_fetch_object(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid));
237 $profile_fields[$fid] = $field;
238 }
239 else {
240 $field = $profile_fields[$fid];
241 }
242 $row[] = drupal_render($form[$field->name][$key]);
243 }
244 }
245 }
246 }
247 $row[] = drupal_render($form['operations'][$key]);
248 $rows[] = $row;
249 }
250 }
251 else {
252 $rows[] = array(array('data' => t('No users available.'), 'colspan' => '7'));
253 }
254
255 $output .= theme('table', $header, $rows);
256 if ($form['pager']['#value']) {
257 $output .= drupal_render($form['pager']);
258 }
259
260 $output .= drupal_render($form);
261
262 return $output;
263 }
264
265 /**
266 * Submit the user administration update form.
267 */
268 function advuser_admin_account_submit($form, &$form_state) {
269 $operations = module_invoke_all('user_operations');
270 $operations = array_merge($operations,module_invoke_all('advuser_operations'));
271 $operation = $operations[$form_state['values']['operation']];
272 // Filter out unchecked accounts.
273 $accounts = array_filter($form_state['values']['accounts']);
274 if ($function = $operation['callback']) {
275 // Add in callback arguments if present.
276 if (isset($operation['callback arguments'])) {
277 $args = array_merge(array($accounts), $operation['callback arguments']);
278 }
279 else {
280 $args = array($accounts);
281 }
282 call_user_func_array($function, $args);
283
284 cache_clear_all('*', 'cache_menu', TRUE);
285 drupal_set_message(t('The update has been performed.'));
286 }
287 }
288
289 function advuser_admin_account_validate($form, &$form_state) {
290 $form_state['values']['accounts'] = array_filter($form_state['values']['accounts']);
291 if (count($form_state['values']['accounts']) == 0) {
292 form_set_error('', t('No users selected.'));
293 }
294 }
295
296 function advuser_multiple_delete_confirm() {
297 $edit = $_POST;
298
299 $form['accounts'] = array(
300 '#prefix' => '<ul>',
301 '#suffix' => '</ul>',
302 '#tree' => TRUE
303 );
304 // array_filter returns only elements with TRUE values
305 foreach (array_filter($edit['accounts']) as $uid => $value) {
306 $user = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid));
307 $form['accounts'][$uid] = array(
308 '#type' => 'hidden',
309 '#value' => $uid,
310 '#prefix' => '<li>',
311 '#suffix' => check_plain($user) ."</li>\n"
312 );
313 }
314 $form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
315
316 return confirm_form(
317 $form,
318 t('Are you sure you want to delete these users?'),
319 'admin/user/user/advuser', t('This action cannot be undone.'),
320 t('Delete all'),
321 t('Cancel')
322 );
323 }
324
325 function advuser_multiple_delete_confirm_submit($form, &$form_state) {
326 if ($form_state['values']['confirm']) {
327 foreach ($form_state['values']['accounts'] as $uid => $value) {
328 user_delete($form_state['values'], $uid);
329 }
330 drupal_set_message(t('The users have been deleted.'));
331 }
332 $form_state['redirect'] = 'admin/user/user/advuser';
333 }
334
335 /**
336 * Email functionality
337 */
338 function advuser_advuser_operations() {
339 $operations = array(
340 'email' => array(
341 'label' => t('Email selected users')
342 )
343 );
344 return $operations;
345 }
346
347 function advuser_multiple_email_confirm() {
348 $edit = $_POST;
349
350 $form['accounts'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
351 // array_filter returns only elements with TRUE values
352 foreach (array_filter($edit['accounts']) as $uid => $value) {
353 $user = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid));
354 $form['accounts'][$uid] = array(
355 '#type' => 'hidden',
356 '#value' => $uid,
357 '#prefix' => '<li>',
358 '#suffix' => check_plain($user) ."</li>\n"
359 );
360 }
361 $form['operation'] = array(
362 '#type' => 'hidden',
363 '#value' => 'email'
364 );
365
366 $form['variables'] = array(
367 '#type' => 'markup',
368 '#prefix' => '<div class="advuser-inset-panel">',
369 '#value' => t(ADVUSER_SUBSTITUTION_TEXT),
370 '#suffix' => '</div>'
371 );
372
373 $form['mailsubject'] = array(
374 '#type' => 'textfield',
375 '#title' => t('Subject'),
376 '#required' => TRUE,
377 );
378
379 $form['mailbody'] = array(
380 '#type' => 'textarea',
381 '#title' => t('Mail body'),
382 '#required' => TRUE,
383 );
384
385 return confirm_form(
386 $form,
387 t('Are you sure you want to email these users?'),
388 'admin/user/user/advuser',
389 t('This action cannot be undone.'),
390 t('Email'),
391 t('Cancel')
392 );
393 }
394
395 function advuser_multiple_email_confirm_submit($form, &$form_state) {
396 if ($form_state['values']['confirm']) {
397 foreach ($form_state['values']['accounts'] as $uid => $value) {
398 $account = user_load(array('uid' => $uid));
399 $from = variable_get("site_mail", "nobody@$_SERVER[SERVER_NAME]");
400 // these are invariant for all sent emails
401 $variables = _advuser_get_variables($account);
402 $mail_subject = strtr($form_state['values']['mailsubject'], $variables);
403 $mail_body = strtr($form_state['values']['mailbody'], $variables);
404 drupal_mail('advuser', 'advance-user-mail', $account->mail, user_preferred_language($account), array('subject' => $mail_subject, 'body' => $mail_body), $from, TRUE);
405 }
406 drupal_set_message(t('The users have been mailed.'));
407 }
408 $form_state['redirect'] = 'admin/user/user/advuser';
409 }
410
411 /**
412 * Implementation of hook_mail
413 */
414 function advuser_mail($key, &$message, $params) {
415 $message = array_merge($message, $params);
416 }
417
418 /**
419 * advuser settings page
420 */
421 function advuser_settings() {
422
423 $form['advuser_mail'] = array(
424 '#type' => 'fieldset',
425 '#title' => t('Mail notifications on user account activity.'),
426 '#collapsible' => FALSE,
427 '#collapsed' => FALSE,
428 );
429
430 $form['advuser_mail']['variables'] = array(
431 '#type' => 'markup',
432 '#prefix' => '<div class="advuser-inset-panel">',
433 '#value' => t(ADVUSER_SUBSTITUTION_TEXT),
434 '#suffix' => '</div>',
435 );
436
437 //New User Notification
438 $form['advuser_mail']['advuser_new_notify'] = array(
439 '#type' => 'checkbox',
440 '#title' => t('Send notifications on new user registration'),
441 '#description' => t('Notify selected roles when new users register.'),
442 '#default_value' => variable_get('advuser_new_notify', FALSE),
443 );
444
445 $form['advuser_mail']['advuser_new_subject'] = array(
446 '#type' => 'textfield',
447 '#title' => t('Mail subject'),
448 '#description' => t('The subject of the mail that is going to be sent to the user. You may insert substitution variables within this item.'),
449 '#default_value' => variable_get('advuser_new_subject', NULL),
450 );
451
452 $form['advuser_mail']['advuser_new_mail'] = array(
453 '#type' => 'textarea',
454 '#title' => t('Mail body'),
455 '#description' => t('The mail that is going to be sent to the selected roles. You may insert substitution variables within this item.'),
456 '#default_value' => variable_get('advuser_new_mail', NULL),
457 );
458
459 //User change notification
460 $form['advuser_mail']['advuser_modify_notify'] = array(
461 '#type' => 'checkbox',
462 '#title' => t('Send notifications on user profile updates'),
463 '#description' => t('Notify selected roles when users update their profiles.'),
464 '#default_value' => variable_get('advuser_modify_notify', FALSE),
465 );
466
467 $form['advuser_mail']['advuser_modify_subject'] = array(
468 '#type' => 'textfield',
469 '#title' => t('Mail subject'),
470 '#description' => t('The subject of the mail that is going to be sent when a user modifies their profiles. You may insert substitution variables within this item.'),
471 '#default_value' => variable_get('advuser_modify_subject', NULL),
472 );
473 $form['advuser_mail']['advuser_modify_mail'] = array(
474 '#type' => 'textarea',
475 '#title' => t('Mail body'),
476 '#description' => t('The mail that is going to be sent to the selected roles when a user modifies their account. You may insert substitution variables within this item.'),
477 '#default_value' => variable_get('advuser_modify_mail', NULL),
478 );
479
480 //Maximum rows in dataset to display
481 $form['advuser_mail']['advuser_listno'] = array(
482 '#type' => 'select',
483 '#options' => drupal_map_assoc(array(1, 10, 25, 50, 75, 100, 125, 150, 175, 200)),
484 '#title' => t('Number of users in listing'),
485 '#description' => t('Sets how many users to display in table view'),
486 '#default_value' => variable_get('advuser_listno', 50),
487 );
488
489 $sel_roles_count = count(users_by_access('receive email advuser'));
490 if ($sel_roles_count == 0) {
491 $form['advuser_mailonnew']['no_roles_sel_warning'] = array(
492 '#type' => 'markup',
493 '#prefix' => '<div class="advuser-settings-warning">',
494 '#value' => '<strong>WARNING: No users have "receive email advuser" ' .
495 l('access permissions', 'admin/user/access') .
496 '!</strong> - No email notifications will be sent.',
497 '#suffix' => '</div>',
498 );
499 }
500
501 if ( module_exists('profile') ) {
502 $form['advuser_profile'] = array(
503 '#type' => 'fieldset',
504 '#title' => t('Profile module special settings'),
505 '#collapsible' => TRUE,
506 '#collapsed' => TRUE,
507 );
508
509 $fields = array();
510 $result = db_query('SELECT * FROM {profile_fields} ORDER BY category, weight');
511 while ( $row = db_fetch_object($result)) {
512 $fields[$row->fid] = $row->title;
513 }
514
515 $values = array();
516 $options = variable_get('advuser_profile_fields', NULL);
517 foreach ( (array)$options as $opt => $v ) {
518 if ( $v > 0 ) {
519 $values[] = $v;
520 }
521 }
522
523 $form['advuser_profile']['advuser_profile_fields'] = array(
524 '#type' => 'checkboxes',
525 '#description' => t('Profile fields to be used as filters for the users.'),
526 '#title' => t('Profile fields'),
527 '#options' => $fields,
528 '#default_value' => $values,
529 );
530 }
531 return system_settings_form($form);
532 }
533
534 /**
535 * Get a list of substitution variables for the user account
536 * @param $user the user account
537 * @return An associative array of substitution variables
538 */
539 function _advuser_get_variables($user) {
540 return array(
541 '%user_name' => $user->name,
542 '%site' => variable_get("site_name", "drupal"),
543 '%uri' => url('user/'. $user->uid, array('absolute' => TRUE)),
544 '%user_email' => $user->mail,
545 '%user_status' => t($user->status ? 'Active' : 'Blocked'),
546 '%user_theme' => empty($user->theme) ? t('DEFAULT') : $user->theme,
547 '%user_created' => strftime('%x %X', $user->created),
548 '%user_language' => empty($user->language) ? t('DEFAULT') : $user->language,
549 '%user_timezone' => empty($user->timezone) ? '0' : "$user->timezone",
550 '%user_signature' => $user->signature,
551 '%google_user' => "http://www.google.com/search?q=%22$user->mail%22",
552 '%yahoo_user' => "http://search.yahoo.com/search/?p=%22$user->mail%22",
553 );
554 }
555
556 /**
557 * @private
558 * Return a list of users to send notification of user changes.
559 *
560 * @return resource // The result of the db_query.
561 */
562 function _advuser_dbquery_users_to_notify() {
563 $user_where = users_by_access('receive email advuser');
564 $user_where = implode(',', $user_where);
565 return empty($user_where) ? FALSE : db_query('SELECT u.* FROM {users} u WHERE uid IN (' . $user_where . ')');
566 }
567
568
569 /**
570 * Handle user insertion (new users)
571 */
572 function advuser_user_insert($edit, $user, $category) {
573 // Check to see if we notify the administrator of new users.
574 // Only send if the user isn't created by an administrator.
575 $new_notify = variable_get('advuser_new_notify', FALSE) &&
576 ! user_access('administer_users');
577 if ($new_notify) {
578 $from = variable_get("site_mail", ini_get("sendmail_from"));
579 $body = variable_get('advuser_new_mail', NULL);
580 $subject = variable_get('advuser_new_subject', NULL);
581
582 // these are invariant for all sent emails
583 $variables = _advuser_get_variables($user);
584 $user_subject = strtr($subject, $variables);
585 $user_body = strtr($body, $variables);
586
587 watchdog('advuser', "Sending user account mail: subj='$user_subject' body='$user_body'");
588
589 _advuser_mail_roles($user_subject, $user_body, $from);
590 }
591 }
592
593 /**
594 * @public
595 * List of users for given roles
596 *
597 * @param string $perm // The string permission.
598 * @return array // An array of uid.
599 */
600 function users_by_access($perm) {
601 $select_permissions = "SELECT ur.uid FROM {permission} p LEFT JOIN {users_roles} ur ON ur.rid = p.rid WHERE p.perm like '%%%s%%'";
602 $ret = array();
603 $result = db_query($select_permissions, $perm);
604 while ($data = db_fetch_object($result)) {
605 if (isset($data->uid)) {
606 $ret[] = $data->uid;
607 }
608 }
609 return $ret;
610 }
611
612 /**
613 * @private
614 * Mail users in requested notification role.
615 *
616 * @param string $user_subject
617 * @param string $user_body
618 * @param string $from
619 */
620 function _advuser_mail_roles ($user_subject, $user_body, $from) {
621 static $accounts = array();
622 if (empty($mail_list)) {
623 $result = _advuser_dbquery_users_to_notify();
624 while ($row = db_fetch_object($result)) {
625 $accounts[] = $row;
626 }
627 }
628 foreach ($accounts as $account) {
629 drupal_mail('advuser', 'advanced-user-mail', $account->mail, user_preferred_language($account), array('subject' => $user_subject, 'body' => $user_body), $from, TRUE);
630 }
631 }
632
633 /**
634 * TODO: Need 'send test email' -> sends test email for current user account, to current user account
635 */
636
637 /**
638 * Notify administrator of user profile edit.
639 */
640 function advuser_user_update($edit, $user, $category) {
641 // Check to see if we notify the administrator of the modified user profile.
642 // Only send if the user isn't modified by an administrator.
643 $modify_notify = variable_get('advuser_modify_notify', FALSE) &&
644 ! user_access('administer users');
645 if ($modify_notify) {
646 $from = variable_get("site_mail", ini_get("sendmail_from"));
647 $body = variable_get('advuser_modify_mail', NULL);
648 $subject = variable_get('advuser_modify_subject', NULL);
649
650 // these are invariant for all sent emails
651 $variables = _advuser_get_variables($user);
652 $user_subject = strtr($subject, $variables);
653 $user_body = strtr($body, $variables);
654
655 watchdog('advuser', "Sending user account mail: subj='$user_subject' body='$user_body'");
656
657 _advuser_mail_roles($user_subject, $user_body, $from);
658 }
659 }
660
661
662 /**
663 * hook_user implementation
664 */
665 function advuser_user($type, &$edit, &$user, $category = NULL) {
666 $return = NULL;
667 switch ($type) {
668 case 'insert': {
669 $return = advuser_user_insert($edit, $user, $category);
670 } break;
671 case 'after_update': {
672 $return = advuser_user_update($edit, $user, $category);
673 } break;
674 }
675 return $return;
676 }
677
678 /**
679 * Selected Profile Fields
680 * @return array
681 */
682 function advuser_profile_fields() {
683 static $ret = array();
684 if (!count($ret) && module_exists('profile')) {
685 $fields = variable_get('advuser_profile_fields', NULL);
686 if (is_array($fields)) {
687 foreach ( $fields as $fid => $value) {
688 if ( $value ) {
689 $ret[]= db_fetch_object(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid));
690 }
691 }
692 }
693 }
694 return $ret;
695 }
696
697 /**
698 * Profile Field Values
699 *
700 * @param int $fid
701 * @param int $uid
702 * @return mixed
703 */
704 function advuser_profile_value($fid, $uid) {
705 $ret = db_result(db_query("SELECT value FROM {profile_values} WHERE fid = %d and uid = %d", $fid, $uid));
706 if ($ret === FALSE) {
707 $ret = NULL;
708 }
709 return $ret;
710 }
711
712 /**
713 * User Roles for use in ADVUSER.
714 *
715 * @return array
716 */
717 function advuser_user_roles() {
718 static $roles;
719 if (empty($roles)) {
720 $roles = user_roles(1);
721 unset ($roles[DRUPAL_AUTHENTICATED_RID]);
722 }
723 return $roles;
724 }
725
726 // vim:ft=php:sts=2:sw=2:ts=2:et:ai:sta:ff=unix

  ViewVC Help
Powered by ViewVC 1.1.2