Projet

Général

Profil

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

root / htmltest / sites / all / modules / views_bulk_operations / actions / user_cancel.action.inc @ c12e7e6a

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
  ));
14
}
15

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

    
37
  return $form;
38
}
39

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

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

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

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

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