Projet

Général

Profil

Paste
Télécharger (2,91 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_bulk_operations / actions / user_cancel.action.inc @ 9df8b457

1
<?php
2
/**
3
  * @file
4
  * VBO action to cancel user accounts.
5
  */
6

    
7
function views_bulk_operations_user_cancel_action_info() {
8
  return array('views_bulk_operations_user_cancel_action' => array(
9
    'type' => 'user',
10
    'label' => t('Cancel user account'),
11
    'configurable' => TRUE,
12
    'behavior' => array('deletes_property'),
13
    'triggers' => array('any'),
14
  ));
15
}
16

    
17
function views_bulk_operations_user_cancel_action_form($context) {
18
  module_load_include('inc', 'user', 'user.pages');
19
  $form['user_cancel_method'] = array(
20
    '#type' => 'item',
21
    '#title' => t('When cancelling these accounts'),
22
  );
23
  $form['user_cancel_method'] += user_cancel_methods();
24
  // Remove method descriptions.
25
  foreach (element_children($form['user_cancel_method']) as $element) {
26
    unset($form['user_cancel_method'][$element]['#description']);
27
  }
28
  $admin_access = user_access('administer users');
29
  $default_notify = variable_get('user_mail_status_canceled_notify', FALSE);
30
  $form['user_cancel_notify'] = array(
31
    '#type' => 'checkbox',
32
    '#title' => t('Notify user when account is canceled.'),
33
    '#default_value' => ($admin_access ? FALSE : $default_notify),
34
    '#access' => $admin_access && $default_notify,
35
    '#description' => t('When enabled, the user will receive an e-mail notification after the account has been cancelled.'),
36
  );
37

    
38
  return $form;
39
}
40

    
41
function views_bulk_operations_user_cancel_action_submit($form, $form_state) {
42
  return array(
43
    'user_cancel_method' => $form_state['values']['user_cancel_method'],
44
    'user_cancel_notify' => $form_state['values']['user_cancel_notify'],
45
  );
46
}
47

    
48
function views_bulk_operations_user_cancel_action($account, $context) {
49
  global $user;
50
  // Prevent the user from cancelling itself.
51
  if ($account->uid == $user->uid) {
52
    return;
53
  }
54

    
55
  // Allow other modules to react on the cancellation.
56
  if ($context['user_cancel_method'] != 'user_cancel_delete') {
57
    module_invoke_all('user_cancel', array(), $account, $context['user_cancel_method']);
58
  }
59

    
60
  switch ($context['user_cancel_method']) {
61
    case 'user_cancel_block':
62
    case 'user_cancel_block_unpublish':
63
    default:
64
      // Send account blocked notification if option was checked.
65
      if (!empty($context['user_cancel_notify'])) {
66
        _user_mail_notify('status_blocked', $account);
67
      }
68
      user_save($account, array('status' => 0));
69
      watchdog('user', 'Blocked user: %name %email.', array('%name' => $account->name, '%email' => '<' . $account->mail . '>'), WATCHDOG_NOTICE);
70
      break;
71

    
72
    case 'user_cancel_reassign':
73
    case 'user_cancel_delete':
74
      // Send account canceled notification if option was checked.
75
      if (!empty($context['user_cancel_notify'])) {
76
        _user_mail_notify('status_canceled', $account);
77
      }
78
      user_delete($account->uid);
79
      watchdog('user', 'Deleted user: %name %email.', array('%name' => $account->name, '%email' => '<' . $account->mail . '>'), WATCHDOG_NOTICE);
80
      break;
81
  }
82
}