What's new? | Help | Directory | Sign in
Google
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php

// reg_redirect_help function
function reg_redirect_help( $section ) {
switch($section){
case 'admin/modules#description':
return t('reg redirect module v0.01');
}
}

/**
* Implementation of hook_perm().
*/
function reg_redirect_perm() {
return array('reg_redirect');
}

/**
* Implementation of hook_access().
*/
function reg_redirect_access($op, $node) {
if (user_access('reg_redirect')) {
return TRUE;
}
}

/**
* Implementation of hook_menu().
*/
function reg_redirect_menu($may_cache) {
$items = array();
$items[] = array(
'path' => 'register_redirect', 'title' => t('RegisterRedirect'),
'callback' => 'register_redirect_handle',
'access' => user_access('reg_redirect')
);
return $items;
}

// this method changes the role of the user from pre-auth to auth so that
// we can have a fully authenticated user. we also do this
// so that only the pre-auth user can access this module and the only time
// that the user is in the pre-auth state is right after they gave registered.

function reg_redirect_roles_alter(&$user) {
$preauth_id = logintoboggan_validating_id();
$in_pre_auth_role = in_array($preauth_id, array_keys($user->roles));
if ($user->uid && $in_pre_auth_role) {
unset($user->roles[$preauth_id]);
$roles = user_roles(1);
$user->roles[DRUPAL_AUTHENTICATED_RID] = $roles[DRUPAL_AUTHENTICATED_RID];
user_save($user,array('roles' => $user->roles));
cache_clear_all('menu:'. $user->uid, TRUE);
}
}


/*
this is the meat of the register_redirect

basically what happens is:

we check to see if the user wants to sign up for a free or paid membership
if free, then we redirect them to their profile
if paid we redirect them to the membership page where they can choose to sign up

*/

function register_redirect_handle() {
if (!module_exist('civicrm')) return;

global $user,$base_url;
civicrm_initialize(TRUE);

$prop_name = variable_get('reg_redirect_custom_field', '');
// by default we will redirect to the user page
// this is changed below if the user has chosen
// to become a paid member
$reg_successful_msg = variable_get('reg_redirect_free_successful_msg','');
$redirect_url = variable_get('reg_redirect_free_mem_url', '');
$newsletter_signup_fieldname = variable_get('newsletter_signup_fieldname','');

$return_properties = array($prop_name => 1, $newsletter_signup_fieldname => 1);
$lookup_params = array(email => $user->mail);
list($cividata,$dontCare) = crm_contact_search( $lookup_params, $return_properties );

if ( ! is_a( $cividata, 'CRM_Core_Error' ) ) {
if(count($cividata) > 1){
// setting the error here we really
drupal_set_message(t("more than one member with the email: ").$user->mail,'error');
}
// here we are interested in the only element in the array returned by
// crm_contact_search
$cividata = array_shift($cividata);
$wants_paid_membership = $cividata[$prop_name];
if($wants_paid_membership){
$reg_successful_msg = variable_get('reg_redirect_paid_successful_msg','');
$redirect_url = variable_get('reg_redirect_paid_mem_url', 'user');
}

// if the newsletter sign up field is present and positive
// then we add the user to the default newsletter group
if($newsletter_signup_fieldname && isset($cividata[$newsletter_signup_fieldname]) && $cividata[$newsletter_signup_fieldname]){
newsletter_add_user_to_list($user->mail);
}

// set the user to the authenticated user role
reg_redirect_roles_alter($user);
// clear the message queue
// by caling the get_messages function
// ridiculous!
drupal_get_messages();
drupal_set_message($reg_successful_msg);
drupal_goto($redirect_url);
} else {
die( t("Contact data not found").' : '.$user->mail);
}

}

function reg_redirect_settings() {

$form['reg_redirect_heading'] = array(
'#type' => 'markup',
'#value' => t('
<p><b><h2>Register Redirect Settings</h2><b><hr></p>
'),
);

$form['reg_redirect_paid_mem_url'] = array(
'#type' => 'textfield',
'#title' => t('Paid Membership Redirect URL (defaults to "user")'),
'#default_value' => variable_get('reg_redirect_paid_mem_url', ''),
'#size' => 20,
'#maxlength' => 255,
'#description' => t('This is the url of the civicontribute page that is being used to accommodate membership sign up.
A user will be redirected to this URL if they chose to become a paid member'),
);

$form['reg_redirect_free_mem_url'] = array(
'#type' => 'textfield',
'#title' => t('Free Membership Redirect URL (defaults to "user")'),
'#default_value' => variable_get('reg_redirect_free_mem_url', ''),
'#size' => 20,
'#maxlength' => 255,
'#description' => t('This is the url to which a user is redirected if they chose to sign up as a free member only'),
);

$form['reg_redirect_paid_successful_msg'] = array(
'#type' => 'textarea',
'#title' => t('Successful Registration Message (Paid)'),
'#default_value' => variable_get('reg_redirect_paid_successful_msg', ''),
'#size' => 20,
'#maxlength' => 255,
'#description' => t('This is the message that will be displayed to the user after they have successfully
registered and they chose to also sign up for a membership'),
);

$form['reg_redirect_free_successful_msg'] = array(
'#type' => 'textarea',
'#title' => t('Successful Registration Message (Free)'),
'#default_value' => variable_get('reg_redirect_free_successful_msg', ''),
'#size' => 20,
'#maxlength' => 255,
'#description' => t('This is the message that will be displayed to the user after they have successfully
registered and they did not choose to sign up for a membership'),
);

$form['reg_redirect_custom_field'] = array(
'#type' => 'textfield',
'#title' => t('CiviCrm Custom Field Name'),
'#default_value' => variable_get('reg_redirect_custom_field', ''),
'#size' => 20,
'#maxlength' => 255,
'#description' => t('This is the name of the custom data field that is being used as the flag
to indicate whether or not the user chose a paid membership when they signed
up for a web account. for example: custom_23 '),
);

return $form;
}


?>
Show details Hide details

Change log

r88 by shanehill00 on Apr 08, 2007   Diff
cleaning up the reg_redirect module so
that it no longer appears to be a node to
th drupal system
Go to: 
Project members, sign in to write a code review

Older revisions

r82 by shanehill00 on Apr 06, 2007   Diff
changing a 'call-time pass-by-
reference' statement which is now
deprecated
r81 by shanehill00 on Apr 06, 2007   Diff
minor cleanup to make the code a bit
cleaner
r80 by shanehill00 on Apr 06, 2007   Diff
added the capability to include a
newsletter sign up field on the
registration page.  if it is included
and configured correctly and the user
chooses to receive the newsletter when
...
All revisions of this file

File info

Size: 6467 bytes, 184 lines