function uc_checkout_pane_customer in Ubercart 6.2
Same name and namespace in other branches
- 5 uc_cart/uc_cart_checkout_pane.inc \uc_checkout_pane_customer()
- 7.3 uc_cart/uc_cart_checkout_pane.inc \uc_checkout_pane_customer()
Gets the user's email address for login.
1 string reference to 'uc_checkout_pane_customer'
- uc_cart_checkout_pane in uc_cart/
uc_cart.module - Implements hook_checkout_pane().
File
- uc_cart/
uc_cart_checkout_pane.inc, line 35 - Callbacks for the default Ubercart checkout panes and their corresponding helper functions.
Code
function uc_checkout_pane_customer($op, &$arg1, $arg2) {
global $user;
switch ($op) {
case 'view':
if ($user->uid) {
$email = $user->mail;
$description = t('Order information will be sent to your account e-mail listed below.');
// . '<br />'
$contents['primary_email'] = array(
'#type' => 'hidden',
'#value' => $email,
);
$contents['email_text'] = array(
'#value' => '<div>' . t('<b>E-mail address:</b> @email (<a href="!url">edit</a>)', array(
'@email' => $email,
'!url' => url('user/' . $user->uid . '/edit', array(
'query' => drupal_get_destination(),
)),
)) . '</div>',
);
}
else {
$email = $arg1->primary_email;
$description = t('Enter a valid email address for this order or <a href="!url">click here</a> to login with an existing account and return to checkout.', array(
'!url' => url('user/login', array(
'query' => drupal_get_destination(),
)),
));
$contents['primary_email'] = uc_textfield(t('E-mail address'), $email, TRUE, NULL, 64);
}
if (variable_get('uc_cart_email_validation', FALSE) && !$user->uid) {
$contents['primary_email_confirm'] = uc_textfield(t('Confirm e-mail address'), $_SESSION['email_match'] === FALSE ? '' : $email, TRUE, NULL, 64);
if ($_SESSION['email_match'] === FALSE) {
$contents['primary_email_confirm']['#attributes'] = array(
'class' => 'error',
);
unset($_SESSION['email_match']);
}
}
if ($user->uid == 0) {
$contents['new_account'] = array();
if (variable_get('uc_cart_new_account_name', FALSE)) {
$contents['new_account']['name'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#default_value' => isset($arg1->data['new_user']['name']) ? $arg1->data['new_user']['name'] : '',
'#maxlength' => 60,
'#size' => 32,
);
}
if (variable_get('uc_cart_new_account_password', FALSE)) {
$contents['new_account']['pass'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#maxlength' => 32,
'#size' => 32,
);
$contents['new_account']['pass_confirm'] = array(
'#type' => 'password',
'#title' => t('Confirm password'),
'#description' => t('Passwords must match to proceed.'),
'#maxlength' => 32,
'#size' => 32,
);
}
if (!empty($contents['new_account'])) {
$array = array(
'#type' => 'fieldset',
'#title' => t('New account details'),
'#description' => variable_get('uc_cart_new_account_details', t('<b>Optional.</b> New customers may supply custom account details.<br />We will create these for you if no values are entered.')),
'#collapsible' => FALSE,
);
$contents['new_account'] = array_merge($array, $contents['new_account']);
}
}
return array(
'description' => $description,
'contents' => $contents,
);
case 'process':
if (!empty($arg2['primary_email']) && !valid_email_address($arg2['primary_email'])) {
form_set_error('panes][customer][primary_email', t('You must enter a valid e-mail address.'));
}
$arg1->primary_email = $arg2['primary_email'];
if (variable_get('uc_cart_email_validation', FALSE) && !$user->uid && $arg2['primary_email'] !== $arg2['primary_email_confirm']) {
form_set_error('panes][customer][primary_email_confirm', t('The e-mail address did not match.'));
$_SESSION['email_match'] = FALSE;
}
unset($_SESSION['email_match']);
// Invalidate if an account already exists for this e-mail address, and the user is not logged into that account
if (!variable_get('uc_cart_mail_existing', TRUE) && $user->uid == 0 && !empty($arg2['primary_email'])) {
if (db_result(db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER('%s')", $arg2['primary_email'])) > 0) {
form_set_error('panes][customer][primary_email', t('An account already exists for your e-mail address. You will either need to login with this e-mail address or use a different e-mail address.'));
}
}
// If new users can specify names or passwords then...
if ((variable_get('uc_cart_new_account_name', FALSE) || variable_get('uc_cart_new_account_password', FALSE)) && $user->uid == 0) {
// Skip if an account already exists for this e-mail address.
if (variable_get('uc_cart_mail_existing', TRUE) && db_result(db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER('%s')", $arg2['primary_email'])) > 0) {
drupal_set_message(t('An account already exists for your e-mail address. The new account details you entered will be disregarded.'));
}
else {
// Validate the username.
if (variable_get('uc_cart_new_account_name', FALSE) && !empty($arg2['new_account']['name'])) {
$message = user_validate_name($arg2['new_account']['name']);
if (!empty($message)) {
form_set_error('panes][customer][new_account][name', $message);
}
elseif (db_fetch_object(db_query("SELECT uid FROM {users} WHERE LOWER(name) = LOWER('%s')", $arg2['new_account']['name']))) {
form_set_error('panes][customer][new_account][name', t('The username %name is already taken. Please enter a different name or leave the field blank for your username to be your e-mail address.', array(
'%name' => $arg2['new_account']['name'],
)));
}
else {
$arg1->data['new_user']['name'] = $arg2['new_account']['name'];
}
}
// Validate the password.
if (variable_get('uc_cart_new_account_password', FALSE)) {
if (strcmp($arg2['new_account']['pass'], $arg2['new_account']['pass_confirm'])) {
form_set_error('panes][customer][new_account][pass_confirm', t('The passwords you entered did not match. Please try again.'));
}
if (!empty($arg2['new_account']['pass'])) {
$arg1->data['new_user']['hash'] = md5(trim($arg2['new_account']['pass']));
}
}
}
}
if ($user->uid) {
$arg1->uid = $user->uid;
}
return TRUE;
case 'review':
$review[] = array(
'title' => t('E-mail'),
'data' => check_plain($arg1->primary_email),
);
return $review;
case 'settings':
$form['uc_cart_mail_existing'] = array(
'#type' => 'checkbox',
'#title' => t("Allow anonymous customers to use an existing account's email address."),
'#default_value' => variable_get('uc_cart_mail_existing', TRUE),
'#description' => t('If enabled, orders will be attached to the account matching the email address. If disabled, anonymous users using a registered email address must log in or use a different email address.'),
);
$form['uc_cart_email_validation'] = array(
'#type' => 'checkbox',
'#title' => t('Require e-mail confirmation in checkout for anonymous customers.'),
'#default_value' => variable_get('uc_cart_email_validation', FALSE),
);
$form['uc_cart_new_account_name'] = array(
'#type' => 'checkbox',
'#title' => t('Allow anonymous customers to specify a new user account name.'),
'#default_value' => variable_get('uc_cart_new_account_name', FALSE),
);
$form['uc_cart_new_account_password'] = array(
'#type' => 'checkbox',
'#title' => t('Allow anonymous customers to specify a new user account password.'),
'#default_value' => variable_get('uc_cart_new_account_password', FALSE),
);
$form['uc_cart_new_account_details'] = array(
'#type' => 'textarea',
'#title' => t('New account details help message'),
'#description' => t('Enter the help message displayed in the new account details fieldset when shown.'),
'#default_value' => variable_get('uc_cart_new_account_details', t('<b>Optional.</b> New customers may supply custom account details.<br />We will create these for you if no values are entered.')),
);
return $form;
}
}