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

Contents of /contributions/modules/sharedemail/sharedemail.module

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


Revision 1.4 - (show annotations) (download) (as text)
Sat May 23 17:18:56 2009 UTC (6 months ago) by aufumy
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +99 -15 lines
File MIME type: text/x-php
updating head to DRUPAL-6--1-1
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Allows users to share an email address
7 */
8
9 /**
10 * Implementation of hook_help().
11 */
12 function sharedemail_help($path, $arg) {
13 switch ($path) {
14 case 'admin/help#sharedemail':
15 $output = '<p>'. t('Allows users to use the same email address for multiple accounts') .'</p>';
16 return $output;
17 }
18 }
19
20 /**
21 * Implementation of hook_perm().
22 */
23 function sharedemail_perm() {
24 return array('administer sharedemail', 'show warning text');
25 }
26
27 /**
28 * Implementation of hook_menu().
29 */
30 function sharedemail_menu() {
31 $items['admin/settings/sharedemail'] = array(
32 'title' => 'Sharedemail',
33 'description' => 'Configure the message that sharedemail displays.',
34 'page callback' => 'drupal_get_form',
35 'page arguments' => array('sharedemail_admin_settings'),
36 'access arguments' => array('administer sharedemail'),
37 'type' => MENU_NORMAL_ITEM,
38 );
39
40 return $items;
41 }
42
43
44 /**
45 * Configure Sharedemail settings
46 *
47 * @ingroup forms
48 * @see system_settings_form()
49 */
50 function sharedemail_admin_settings() {
51 $form = array();
52
53 $msg = t('WARNING: The e-mail address you are using, has already been registered on this site by another user. '.
54 'You should be aware that personal information such as password resets will be sent to this address. '.
55 'We strongly recommend changing your registered address to a different e-mail address. '.
56 'You can do this at any time from your account page when you login.');
57
58 $form['sharedemail_msg'] = array(
59 '#type' => 'textarea',
60 '#title' => t('Sharedemail Message'),
61 '#default_value' => variable_get('sharedemail_msg', $msg),
62 '#rows' => 15,
63 '#description' => t('Warning message that is only displayed to users with appropriate permission, when they choose to save an email address already used by another user.'),
64 );
65
66 return system_settings_form($form);
67 }
68
69 /**
70 * Implementation of hook_user().
71 */
72 function sharedemail_user($type, &$edit, &$user, $category= NULL) {
73 $mail = isset($edit['mail']) ? $edit['mail'] : '';
74
75 switch ($type) {
76 case 'validate':
77 // If no problems with validation, do nothing
78 if (user_validate_mail($mail)) {
79 return;
80 }
81
82 // Show warning message if more than 1 user with the same email
83 $uid = db_result(db_query("SELECT uid FROM {users} WHERE uid <> %d AND LOWER(mail) = LOWER('%s')", $user->uid, $edit['mail']));
84 if (!empty($uid)) {
85 $edit['mail']= 'sharedemail_'. $mail;
86
87 // Show warning text to those with the proper permission
88 if (user_access('show warning text')) {
89 drupal_set_message(variable_get('sharedemail_msg', ''));
90 }
91 }
92 break;
93 case 'submit':
94 case 'update':
95 if (strpos($mail, 'sharedemail_') == 0 && isset($edit['mail'])) {
96 $edit['mail'] = str_replace('sharedemail_', '', $mail);
97 }
98 break;
99
100 // Creating a new user, this hook is called after db insert
101 case 'insert':
102 $mail = $user->mail;
103 if (strpos($mail, 'sharedemail_') == 0) {
104 $realmail = str_replace('sharedemail_', '', $mail);
105 db_query("UPDATE {users} SET {mail} = '%s' WHERE uid = '%d'", $realmail, $user->uid);
106 $user->mail = $realmail;
107 }
108 break;
109 }
110 }
111
112 /**
113 * Implementation of hook_simpletest().
114 */
115 function sharedemail_simpletest() {
116 $module_name = 'Shared E-mail';
117 $dir = drupal_get_path('module', 'sharedemail') .'/tests';
118 $tests = file_scan_directory($dir, '\.test$');
119 return array_keys($tests);
120 }

  ViewVC Help
Powered by ViewVC 1.1.2