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

Contents of /contributions/modules/user_delete/user_delete.module

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


Revision 1.8 - (show annotations) (download) (as text)
Wed Mar 5 14:55:57 2008 UTC (20 months, 3 weeks ago) by sanduhrs
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.7: +2 -2 lines
File MIME type: text/x-php
#225785 by figaro: Description update
1 <?php
2 /* $Id: user_delete.module,v 1.7 2008/01/27 11:03:59 sanduhrs Exp $ */
3
4 /**
5 * @file
6 * Allows users to delete their own account.
7 *
8 * This module will be abandoned when http://drupal.org/node/8 is fixed.
9 *
10 * @author
11 * Stefan Auditor <stefan.auditor@erdfisch.de>
12 */
13
14 /**
15 * Implementation of hook_perm().
16 */
17 function user_delete_perm() {
18 return array('delete own account');
19 }
20
21 /**
22 * Implementation of hook_menu().
23 */
24 function user_delete_menu($may_cache) {
25 global $user;
26 $items = array();
27
28 if (!$may_cache) {
29 $items[] = array(
30 'path' => 'user/'. arg(1) .'/delete',
31 'title' => t('Delete'),
32 'callback' => 'user_edit',
33 'access' => (user_access('administer users') || (user_access('delete own account') && arg(1) == $user->uid)),
34 'type' => MENU_CALLBACK,
35 );
36 $items[] = array(
37 'path' => 'admin/user/user_delete',
38 'title' => t('User delete'),
39 'description' => t("Configure the user delete action."),
40 'callback' => 'drupal_get_form',
41 'callback arguments' => 'user_delete_settings',
42 'access' => user_access('administer users'),
43 );
44 }
45
46 return $items;
47 }
48
49
50 /**
51 * Implementation of hook_form_alter().
52 */
53 function user_delete_form_alter($form_id, &$form) {
54 global $user;
55
56 if($form_id == 'user_edit') {
57 //access check
58 if(user_access('delete own account') && arg(1) == $user->uid) {
59 $form['delete'] = array(
60 '#type' => 'submit',
61 '#value' => t('Delete'),
62 '#weight' => 31,
63 );
64 }
65 }
66 }
67
68 /**
69 * Administrative settings page
70 *
71 * @return array
72 * a form array
73 */
74 function user_delete_settings() {
75 //TODO: add additional settings based on http://drupal.org/node/8#comment-628434
76
77 $form['user_delete_redirect'] = array(
78 '#type' => 'textfield',
79 '#title' => t('Redirection page'),
80 '#default_value' => variable_get('user_delete_redirect', '<front>'),
81 '#description' => t('Choose where to redirect your users after account deletion. Any valid Drupal path will do, e.g. %front or %node', array('%front' => '<front>', '%node' => 'node/1')),
82 '#required' => TRUE,
83 );
84
85 return system_settings_form($form);
86 }
87
88 /**
89 * Implementation of hook_user().
90 */
91 function user_delete_user($op, &$edit, &$account, $category = NULL) {
92 global $user;
93
94 //Note: $account->uid and $user->uid are still available!
95 if ($op == 'delete' && ($account->uid == $user->uid)) {
96 //TODO: add additional actions based on http://drupal.org/node/8#comment-628434
97
98 //Imitate default behaviour
99 //Assign all nodes and comments to anonymous
100 db_query("UPDATE {node} SET uid=0 WHERE uid=%d", $account->uid);
101 db_query("UPDATE {comments} SET uid=0 WHERE uid=%d", $account->uid);
102
103 //Redirect
104 drupal_goto(variable_get('user_delete_redirect', '<front>'));
105 }
106 }

  ViewVC Help
Powered by ViewVC 1.1.2