| 1 |
<?php
|
| 2 |
// $Id: citizenspeak.user.php,v 1.3 2005/11/02 23:48:25 georgehotelling Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Functions for the CitizenSpeak module's hook_user() implementation
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* A set of user information categories is requested.
|
| 11 |
*
|
| 12 |
* @param &$edit
|
| 13 |
* The array of form values submitted by the user.
|
| 14 |
* @param &$user
|
| 15 |
* The user object on which the operation is being performed.
|
| 16 |
* @param $category
|
| 17 |
* The active category of user information being edited.
|
| 18 |
* @return
|
| 19 |
* A linear array of associative arrays. These arrays have keys:
|
| 20 |
* - "name": The internal name of the category.
|
| 21 |
* - "title": The human-readable, localized name of the category.
|
| 22 |
* - "weight": An integer specifying the category's sort ordering.
|
| 23 |
*/
|
| 24 |
|
| 25 |
function citizenspeak_user_categories(&$edit, &$user, $category = false) {
|
| 26 |
// TODO: make weight customizable in admin interface
|
| 27 |
|
| 28 |
if (user_access('customize thank you page', $user)) {
|
| 29 |
return array(array('name' => 'citizenspeak_thank_you', 'title' => t('Customize Thank You Page'), 'weight' => 0));
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
/**
|
| 34 |
* The user account is being deleted. The module should remove its custom
|
| 35 |
* additions to the user object from the database.
|
| 36 |
*
|
| 37 |
* @param &$edit
|
| 38 |
* The array of form values submitted by the user.
|
| 39 |
* @param &$user
|
| 40 |
* The user object on which the operation is being performed.
|
| 41 |
* @param $category
|
| 42 |
* The active category of user information being edited.
|
| 43 |
*/
|
| 44 |
|
| 45 |
function citizenspeak_user_delete(&$edit, &$user, $category = false) {
|
| 46 |
db_query("DELETE FROM {citizenspeak_thankyou_options} WHERE uid = %d", $user->uid);
|
| 47 |
}
|
| 48 |
|
| 49 |
/**
|
| 50 |
* The user account edit form is about to be displayed. The module should
|
| 51 |
* present the form elements it wishes to inject into the form.
|
| 52 |
*
|
| 53 |
* @param &$edit
|
| 54 |
* The array of form values submitted by the user.
|
| 55 |
* @param &$user
|
| 56 |
* The user object on which the operation is being performed.
|
| 57 |
* @param $category
|
| 58 |
* The active category of user information being edited.
|
| 59 |
* @return
|
| 60 |
* A linear array of form groups for the specified category. Each group
|
| 61 |
* is represented as an associative array with keys:
|
| 62 |
* - "title": The human-readable, localized name of the group.
|
| 63 |
* - "data": A string containing the form elements to display.
|
| 64 |
* - "weight": An integer specifying the group's sort ordering.
|
| 65 |
*/
|
| 66 |
|
| 67 |
function citizenspeak_user_form(&$edit, &$user, $category = false) {
|
| 68 |
if ($category == "citizenspeak_thank_you" && user_access('customize thank you page', $user)) {
|
| 69 |
$thank_group = $customize_desc = '';
|
| 70 |
|
| 71 |
$option_desc = form_textfield('Email To', 'volunteer_email', $user->volunteer_email, 25, 255);
|
| 72 |
$customize_desc .= form_checkbox(t('Volunteer Signup'), 'request_volunteers', 1, $user->request_volunteers, $option_desc);
|
| 73 |
|
| 74 |
$option_desc = form_textfield('PayPal ID', 'donation_paypal_id', $user->donation_paypal_id, 25, 255);
|
| 75 |
$customize_desc .= form_checkbox(t('Donation Link'), 'request_donations', 1, $user->request_donations, $option_desc);
|
| 76 |
|
| 77 |
$option_desc = form_textfield('PayPal ID', 'membership_paypal_id', $user->membership_paypal_id, 25, 255);
|
| 78 |
$option_desc .= form_textfield('Dues: $', 'membership_paypal_amount', $user->membership_paypal_amount, 6, 10, t('(yearly)'));
|
| 79 |
$customize_desc .= form_checkbox(t('Membership Link'), 'request_memberships', 1, $user->request_memberships, $option_desc);
|
| 80 |
|
| 81 |
$option_desc = form_select('', 'additional_text_language', $user->additional_text_language, drupal_map_assoc(array('English', 'Spanish')));
|
| 82 |
$option_desc .= form_textarea('', 'additional_text', $user->additional_text, 60, 6);
|
| 83 |
$customize_desc .= form_checkbox(t('Additional Text'), 'include_additional_text', 1, $user->include_additional_text, $option_desc);
|
| 84 |
|
| 85 |
$option_desc = form_textfield('Email To', 'feedback_email', $user->feedback_email, 25, 255);
|
| 86 |
$customize_desc .= form_checkbox(t('Feedback'), 'request_feedback', 1, $user->request_feedback, $option_desc);
|
| 87 |
|
| 88 |
|
| 89 |
$thank_group .= form_radio(t('Customize Standard Page:'), 'use_redirect', 0, !$user->use_redirect, $customize_desc, NULL, true);
|
| 90 |
|
| 91 |
$redirect_desc = form_textfield('', 'redirect_url', $user->redirect_url, 25, 255, t('Your full web address'));
|
| 92 |
$thank_group .= form_radio(t('Use Your Page:'), 'use_redirect', 1, $user->use_redirect, $redirect_desc, NULL, true);
|
| 93 |
|
| 94 |
return array(array('title' => t('Thank You Page'), 'data' => $thank_group, 'weight' => 0));
|
| 95 |
}
|
| 96 |
}
|
| 97 |
|
| 98 |
/**
|
| 99 |
* The user account is being added. The module should save its custom
|
| 100 |
* additions to the user object into the database and set the saved fields
|
| 101 |
* to NULL in $edit.
|
| 102 |
*
|
| 103 |
* @param &$edit
|
| 104 |
* The array of form values submitted by the user.
|
| 105 |
* @param &$user
|
| 106 |
* The user object on which the operation is being performed.
|
| 107 |
* @param $category
|
| 108 |
* The active category of user information being edited.
|
| 109 |
*/
|
| 110 |
|
| 111 |
function citizenspeak_user_insert(&$edit, &$user, $category = false) {
|
| 112 |
db_query("INSERT INTO {citizenspeak_thankyou_options} (uid) VALUES (%d)", $user->uid);
|
| 113 |
}
|
| 114 |
|
| 115 |
/**
|
| 116 |
* The user account is being changed. The module should save its custom
|
| 117 |
* additions to the user object into the database and set the saved fields
|
| 118 |
* to NULL in $edit.
|
| 119 |
*
|
| 120 |
* @param &$edit
|
| 121 |
* The array of form values submitted by the user.
|
| 122 |
* @param &$user
|
| 123 |
* The user object on which the operation is being performed.
|
| 124 |
* @param $category
|
| 125 |
* The active category of user information being edited.
|
| 126 |
*/
|
| 127 |
|
| 128 |
function citizenspeak_user_update(&$edit, &$user, $category = false) {
|
| 129 |
if ($category == "citizenspeak_thank_you" && user_access('customize thank you page', $user)) {
|
| 130 |
db_query("UPDATE {citizenspeak_thankyou_options} SET use_redirect = %d, redirect_url = '%s', request_volunteers = %d, volunteer_email = '%s', request_donations = %d, donation_paypal_id = '%s', request_memberships = %d, membership_paypal_id = '%s', membership_paypal_amount = %.2f, include_additional_text = %d, additional_text_language = '%s', additional_text = '%s', request_feedback = %d, feedback_email = '%s' WHERE uid = %d", $edit['use_redirect'], $edit['redirect_url'], $edit['request_volunteers'], $edit['volunteer_email'], $edit['request_donations'], $edit['donation_paypal_id'], $edit['request_memberships'], $edit['membership_paypal_id'], $edit['membership_paypal_amount'], $edit['include_additional_text'], $edit['additional_text_language'], $edit['additional_text'], $edit['request_feedback'], $edit['feedback_email'], $user->uid);
|
| 131 |
}
|
| 132 |
}
|
| 133 |
|
| 134 |
/**
|
| 135 |
* The user account is about to be modified. The module should validate its
|
| 136 |
* custom additions to the user object, registering errors as necessary.
|
| 137 |
*
|
| 138 |
* @param &$edit
|
| 139 |
* The array of form values submitted by the user.
|
| 140 |
* @param &$user
|
| 141 |
* The user object on which the operation is being performed.
|
| 142 |
* @param $category
|
| 143 |
* The active category of user information being edited.
|
| 144 |
*/
|
| 145 |
|
| 146 |
function citizenspeak_user_validate(&$edit, &$user, $category = false) {
|
| 147 |
if ($category == "citizenspeak_thank_you" && user_access('customize thank you page', $user)) {
|
| 148 |
if ($edit['volunteer_email'] && !valid_email_address($edit['volunteer_email'])) {
|
| 149 |
form_set_error('volunteer_email', 'You must provide a valid email address');
|
| 150 |
}
|
| 151 |
|
| 152 |
if ($edit['feedback_email'] && !valid_email_address($edit['feedback_email'])) {
|
| 153 |
form_set_error('feedback_email', 'You must provide a valid email address');
|
| 154 |
}
|
| 155 |
|
| 156 |
if ($edit['donation_paypal_id'] && !valid_email_address($edit['donation_paypal_id'])) {
|
| 157 |
form_set_error('donation_paypal_id', 'You must provide a valid email address');
|
| 158 |
}
|
| 159 |
|
| 160 |
if ($edit['membership_paypal_id'] && !valid_email_address($edit['membership_paypal_id'])) {
|
| 161 |
form_set_error('membership_paypal_id', 'You must provide a valid email address');
|
| 162 |
}
|
| 163 |
|
| 164 |
if ($edit['redirect_url'] && !valid_url($edit['redirect_url'])) {
|
| 165 |
form_set_error('redirect_url', 'You must provide a valid web address');
|
| 166 |
}
|
| 167 |
}
|
| 168 |
}
|