function mass_contact_mail_page in Mass Contact 5.2
Same name and namespace in other branches
- 5 mass_contact.module \mass_contact_mail_page()
- 6 mass_contact.module \mass_contact_mail_page()
- 7 mass_contact.page.inc \mass_contact_mail_page()
Generates the main Mass Contact mail form.
Return value
An associative array that defines the form to be built.
1 string reference to 'mass_contact_mail_page'
- mass_contact_site_page in ./
mass_contact.module - The mail page
File
- ./
mass_contact.module, line 714 - This is the main code file for the Mass Contact module. This module enables users to contact multiple users through selected roles.
Code
function mass_contact_mail_page() {
global $user;
$categories = array();
$default_category = array();
$default_category_name = '';
$result = db_query('SELECT cid, category, selected FROM {mass_contact} ORDER BY weight, category');
while ($category = db_fetch_object($result)) {
if (user_access('send to users in the ' . $category->category . ' category')) {
$categories[$category->cid] = $category->category;
if ($category->selected) {
$default_category[] = $category->cid;
$default_category_name = $category->category;
}
}
}
if (count($categories) == 1) {
$default_category = array_keys($categories);
$default_category_name = $categories[$default_category[0]];
}
if (count($categories) > 0) {
$form['#attributes'] = array(
'enctype' => "multipart/form-data",
);
$form['#token'] = $user->name . $user->mail;
$form['contact_information'] = array(
'#value' => filter_xss_admin(variable_get('mass_contact_form_information', t('Send an e-mail message using the contact form below.'))),
);
$mass_contact_default_sender_name = variable_get('mass_contact_default_sender_name', '');
if ($mass_contact_default_sender_name) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Your name'),
'#maxlength' => 255,
'#default_value' => $mass_contact_default_sender_name,
'#disabled' => !variable_get('mass_contact_default_sender_changable', 0),
);
}
else {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Your name'),
'#maxlength' => 255,
'#default_value' => $user->uid ? $user->name : '',
'#required' => TRUE,
);
}
$mass_contact_default_sender_email = variable_get('mass_contact_default_sender_email', '');
if ($mass_contact_default_sender_email) {
$form['mail'] = array(
'#type' => 'textfield',
'#title' => t('Your e-mail address'),
'#maxlength' => 255,
'#default_value' => $mass_contact_default_sender_email,
'#disabled' => !variable_get('mass_contact_default_sender_changable', 0),
);
}
else {
$form['mail'] = array(
'#type' => 'textfield',
'#title' => t('Your e-mail address'),
'#maxlength' => 255,
'#default_value' => $user->uid ? $user->mail : '',
'#required' => TRUE,
);
}
if (count($categories) > 1 || !isset($default_category)) {
// Display a choice when one is needed.
$form['cid'] = array(
'#type' => 'select',
'#title' => t('Category'),
'#default_value' => $default_category,
'#options' => $categories,
'#required' => TRUE,
'#multiple' => TRUE,
);
}
else {
// Otherwise, just use the default category.
$form['cid'] = array(
'#type' => 'value',
'#value' => $default_category,
);
$form['cid-info'] = array(
'#type' => 'markup',
'#value' => '<p>Sending to all users subscribed to the ' . $default_category_name . ' category.</p>',
);
}
$optout_setting = variable_get('mass_contact_optout_d', 0);
if ($optout_setting == 1 || $optout_setting == 2) {
// Allow to override or respect opt-outs if admin, otherwise use default.
if (user_access('administer mass contact')) {
$form['optout'] = array(
'#type' => 'checkbox',
'#title' => t('Respect user opt-outs.'),
'#default_value' => 1,
);
}
else {
$form['optout'] = array(
'#type' => 'hidden',
'#default_value' => 1,
);
}
}
// Check if the user can override the BCC setting.
if (variable_get('mass_contact_bcc_d_override', 1)) {
$form['bcc'] = array(
'#type' => 'checkbox',
'#title' => t('Send as BCC (hide recipients).'),
'#default_value' => variable_get('mass_contact_bcc_d', 1),
);
}
else {
$form['bcc'] = array(
'#type' => 'value',
'#value' => variable_get('mass_contact_bcc_d', 1),
);
$form['bcc-info'] = array(
'#type' => 'markup',
'#value' => '<p>' . (variable_get('mass_contact_bcc_d', 1) ? t('Recipients will be hidden.') : t('Recipients will NOT be hidden.')) . '</p>',
);
}
$form['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#maxlength' => 255,
'#required' => TRUE,
);
$form['body_filter']['message'] = array(
'#type' => 'textarea',
'#title' => t('Message'),
'#rows' => 12,
'#required' => TRUE,
);
$form['body_filter']['format'] = filter_form(FILTER_FORMAT_DEFAULT);
// Check if the user can override the HTML setting.
if (variable_get('mass_contact_html_d_override', 1)) {
$form['html'] = array(
'#type' => 'checkbox',
'#title' => t('Send as HTML.'),
'#default_value' => variable_get('mass_contact_html_d', 1),
'#description' => t('This will use the settings for the default input filter. More information about what is available is on the <a href="@formats_settings">Input formats</a> page.', array(
'@formats_settings' => url('filter/tips'),
)),
);
}
else {
$form['html'] = array(
'#type' => 'value',
'#value' => variable_get('mass_contact_html_d', 1),
);
$form['html-info'] = array(
'#type' => 'markup',
'#value' => '<p>' . (variable_get('mass_contact_html_d', 1) ? t('The message will be sent as HTML.') : t('The message will be sent as plain text.')) . '</p>',
);
}
// Show the attachment fields, if allowed.
if (user_access('send mass contact attachments')) {
for ($i = 1; $i <= variable_get('mass_contact_number_of_attachments', '3'); $i++) {
$form['attachment_' . $i] = array(
'#type' => 'file',
'#title' => t('Attachment #!number', array(
'!number' => $i,
)),
);
}
}
// We do not allow anonymous users to send themselves a copy because it
// can be abused to spam people.
if ($user->uid) {
$form['copy'] = array(
'#type' => 'checkbox',
'#title' => t('Send yourself a copy.'),
);
}
if (user_access('choose whether to archive mass contact messages')) {
// Check if the user can override the node copy setting.
if (variable_get('mass_contact_nodecc_d_override', 1)) {
$form['nodecc'] = array(
'#type' => 'checkbox',
'#title' => t('Save a copy as a node.'),
'#default_value' => variable_get('mass_contact_nodecc_d', 1),
);
}
else {
$form['nodecc'] = array(
'#type' => 'hidden',
'#default_value' => variable_get('mass_contact_nodecc_d', 1),
);
}
}
else {
$form['nodecc'] = array(
'#type' => 'hidden',
'#default_value' => variable_get('mass_contact_nodecc_d', 1),
);
}
/*
// Place holder for future use.
$form['preview'] = array(
'#type' => 'button',
'#value' => t('Preview')
);
*/
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send e-mail'),
);
}
else {
$form['error'] = array(
'#value' => '<p><b>' . t('Either you have not created any categories, or you are not allowed to send to any of the existing categories.') . '<br /><br />' . t('Either create at least one category of users to send to, or contact your system administer for access to the existing categories.') . '</b>',
);
}
if (user_access('administer mass contact')) {
$form['tasklist'] = array(
'#type' => 'fieldset',
'#title' => t('Related tasks'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#prefix' => '<p>',
);
$form['tasklist']['list'] = array(
'#value' => '<p><ol>' . '<li>' . l('Set Permissions', 'admin/user/access', array(), NULL, 'module-mass_contact') . '</li>' . '<li>' . l('List current categories', 'admin/build/mass_contact') . '</li>' . '<li>' . l('Add new category', 'admin/build/mass_contact/add') . '</li>' . '<li>' . l('Configure the module', 'admin/build/mass_contact/settings') . '</li>' . '<li>' . l('Help', 'admin/help/mass_contact') . '</li></ol>',
);
}
return $form;
}