function pet_user_form in Previewable email templates 7
Same name and namespace in other branches
- 6 pet.admin.inc \pet_user_form()
Multi-step form for previewing and sending a PET.
1 string reference to 'pet_user_form'
- pet_menu in ./
pet.module - Implements hook_menu().
File
- includes/
pet.admin.inc, line 142 - Contains pages for creating, editing, and deleting previewable email templates (PETs).
Code
function pet_user_form($form, &$form_state, $pet) {
if (pet_isset_or($form_state['storage']['step']) == 3) {
drupal_set_message(t('Email(s) sent'));
unset($form_state['storage']);
}
$step = empty($form_state['storage']['step']) ? 1 : $form_state['storage']['step'];
$form_state['storage']['step'] = $step;
$form_state['storage']['pet'] = $pet;
// Get any query args
$nid = $form_state['storage']['nid'] = pet_is_natural(pet_isset_or($_REQUEST['nid'])) ? $_REQUEST['nid'] : NULL;
$uid = $form_state['storage']['uid'] = pet_is_natural(pet_isset_or($_REQUEST['uid'])) ? $_REQUEST['uid'] : NULL;
$recipient_callback = $form_state['storage']['recipient_callback'] = pet_isset_or($_REQUEST['recipient_callback']) === 'true' || pet_isset_or($_REQUEST['uid']) === '0';
switch ($step) {
case 1:
if ($recipient_callback) {
$default_mail = t('Recipient list will be generated for preview.');
}
elseif (pet_isset_or($form_state['storage']['recipients_raw'])) {
$default_mail = $form_state['storage']['recipients_raw'];
}
else {
$default_mail = '';
if ($uid) {
if ($account = user_load($uid)) {
$default_mail = $account->mail;
}
else {
drupal_set_message(t('Cannot load a user with uid @uid.', array(
'@uid' => $uid,
)), 'error');
}
}
}
$form['recipients'] = array(
'#title' => t('To'),
'#type' => 'textarea',
'#required' => TRUE,
'#rows' => 3,
'#default_value' => $default_mail,
'#description' => t('Enter the recipient(s) separated by lines or commas. A separate email will be sent to each, with token substitution if the email corresponds to a site user.'),
'#disabled' => $recipient_callback,
);
$form['copies'] = array(
'#title' => t('Copies'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => empty($pet->cc_default) && empty($pet->bcc_default),
);
$form['copies']['cc'] = array(
'#title' => t('Cc'),
'#type' => 'textarea',
'#rows' => 3,
'#default_value' => pet_isset_or($form_state['storage']['cc']) ? $form_state['storage']['cc'] : $pet->cc_default,
'#description' => t('Enter any copied emails separated by lines or commas.'),
);
$form['copies']['bcc'] = array(
'#title' => t('Bcc'),
'#type' => 'textarea',
'#rows' => 3,
'#default_value' => pet_isset_or($form_state['storage']['bcc']) ? $form_state['storage']['bcc'] : $pet->bcc_default,
'#description' => t('Enter any blind copied emails separated by lines or commas.'),
);
$form['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#maxlength' => 255,
'#default_value' => pet_isset_or($form_state['storage']['subject']) ? $form_state['storage']['subject'] : $pet->subject,
'#required' => TRUE,
);
if (!(pet_has_mimemail() && $pet->send_plain)) {
$form['mail_body'] = array(
'#type' => 'textarea',
'#title' => t('Body'),
'#default_value' => pet_isset_or($form_state['storage']['mail_body']) ? $form_state['storage']['mail_body'] : $pet->mail_body,
'#rows' => 15,
'#description' => t('Review and edit standard template before previewing. This will not change the template for future emailings, just for this one. To change the template permanently, go to the <a href="@settings">template page</a>. You may use the tokens below.', array(
'@settings' => url('admin/structure/pets/manage/' . $pet->name),
)),
);
}
if (pet_has_mimemail()) {
$form['mimemail'] = array(
'#type' => 'fieldset',
'#title' => t('Plain text body'),
'#collapsible' => TRUE,
'#collapsed' => !(pet_has_mimemail() && $pet->send_plain),
);
$form['mimemail']['mail_body_plain'] = array(
'#type' => 'textarea',
'#title' => t('Plain text body'),
'#default_value' => isset($form_state['storage']['mail_body_plain']) ? $form_state['storage']['mail_body_plain'] : $pet->mail_body_plain,
'#rows' => 15,
'#description' => t('Review and edit plain text template before previewing. This will not change the template for future emailings, just for this one. To change the template permanently, go to the <a href="@settings">template page</a>. You may use the tokens below.', array(
'@settings' => url('admin/structure/pets/manage/' . $pet->name),
)),
);
}
$form['tokens'] = pet_token_help();
$form['preview'] = array(
'#type' => 'submit',
'#value' => t('Preview'),
);
break;
case 2:
$form['info'] = array(
'#value' => t('A preview of the email is shown below. If you\'re satisfied, click Send. If not, click Back to edit the email.'),
);
$form['recipients'] = array(
'#type' => 'textarea',
'#title' => t('To'),
'#rows' => 4,
'#value' => pet_recipients_formatted($form_state['storage']['recipients']),
'#disabled' => TRUE,
);
if ($form_state['values']['cc']) {
$form['cc'] = array(
'#type' => 'textarea',
'#title' => t('CC'),
'#rows' => 4,
'#value' => $form_state['values']['cc'],
'#disabled' => TRUE,
);
}
if ($form_state['values']['bcc']) {
$form['bcc'] = array(
'#type' => 'textarea',
'#title' => t('BCC'),
'#rows' => 4,
'#value' => $form_state['values']['bcc'],
'#disabled' => TRUE,
);
}
$form['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#size' => 80,
'#value' => $form_state['storage']['subject_preview'],
'#disabled' => TRUE,
);
if (!pet_has_mimemail() || !$pet->send_plain) {
$form['body_label'] = array(
'#prefix' => '<div class="pet_body_label">',
'#suffix' => '</div>',
'#markup' => '<label>' . t('Body as HTML') . '</label>',
);
$form['body_preview'] = array(
'#prefix' => '<div class="pet_body_preview">',
'#suffix' => '</div>',
'#markup' => $form_state['storage']['body_preview'],
);
$form['mail_body'] = array(
'#type' => 'textarea',
'#title' => t('Body'),
'#rows' => 15,
'#value' => $form_state['storage']['body_preview'],
'#disabled' => TRUE,
);
}
$plain_text = trim($form_state['storage']['body_preview_plain']);
if (pet_has_mimemail() && ($pet->send_plain || !empty($plain_text))) {
$form['mail_body_plain'] = array(
'#type' => 'textarea',
'#title' => t('Plain text body'),
'#rows' => 15,
'#value' => $form_state['storage']['body_preview_plain'],
'#disabled' => TRUE,
);
}
$form['back'] = array(
'#type' => 'submit',
'#value' => t('Back'),
'#submit' => array(
'pet_user_form_back',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send email(s)'),
);
break;
}
return $form;
}