summaryrefslogtreecommitdiff
path: root/modules/contact/contact.admin.inc
diff options
context:
space:
mode:
Diffstat (limited to 'modules/contact/contact.admin.inc')
-rw-r--r--modules/contact/contact.admin.inc153
1 files changed, 86 insertions, 67 deletions
diff --git a/modules/contact/contact.admin.inc b/modules/contact/contact.admin.inc
index c0d2ca298..e4496462e 100644
--- a/modules/contact/contact.admin.inc
+++ b/modules/contact/contact.admin.inc
@@ -9,28 +9,34 @@
/**
* Categories/list tab.
*/
-function contact_admin_categories() {
+function contact_category_list() {
+ $header = array(
+ t('Category'),
+ t('Recipients'),
+ t('Selected'),
+ array('data' => t('Operations'), 'colspan' => 2),
+ );
$rows = array();
- $header = array(t('Category'), t('Recipients'), t('Selected'), array('data' => t('Operations'), 'colspan' => 2));
-
// Get all the contact categories from the database.
- $result = db_query('SELECT cid, category, recipients, selected FROM {contact} ORDER BY weight, category');
+ $categories = db_query('SELECT cid, category, recipients, selected FROM {contact} ORDER BY weight, category')->fetchAll();
// Loop through the categories and add them to the table.
- foreach ($result as $record) {
+ foreach ($categories as $category) {
$rows[] = array(
- $record->category,
- $record->recipients,
- ($record->selected ? t('Yes') : t('No')),
- l(t('edit'), 'admin/structure/contact/edit/' . $record->cid),
- l(t('delete'), 'admin/structure/contact/delete/' . $record->cid),
+ $category->category,
+ $category->recipients,
+ ($category->selected ? t('Yes') : t('No')),
+ l(t('Edit'), 'admin/structure/contact/edit/' . $category->cid),
+ l(t('Delete'), 'admin/structure/contact/delete/' . $category->cid),
);
}
- // If no categories were found, let the user know.
- if (empty($rows)) {
- $rows[] = array(array('data' => t('No categories available. <a href="@link">Add category</a>.', array('@link' => url('admin/structure/contact/add'))), 'colspan' => 5));
+ if (!$rows) {
+ $rows[] = array(array(
+ 'data' => t('No categories available.'),
+ 'colspan' => 5,
+ ));
}
return theme('table', array('header' => $header, 'rows' => $rows));
@@ -39,52 +45,60 @@ function contact_admin_categories() {
/**
* Category edit page.
*/
-function contact_admin_edit($form, $form_state = array(), $op, $contact = NULL) {
-
- if (empty($contact) || $op == 'add') {
- $contact = array(
- 'category' => '',
- 'recipients' => '',
- 'reply' => '',
- 'weight' => 0,
- 'selected' => 0,
- 'cid' => NULL,
- );
- }
- $form['contact_op'] = array('#type' => 'value', '#value' => $op);
- $form['category'] = array('#type' => 'textfield',
+function contact_category_edit_form($form, &$form_state, array $category = array()) {
+ // If this is a new category, add the default values.
+ $category += array(
+ 'category' => '',
+ 'recipients' => '',
+ 'reply' => '',
+ 'weight' => 0,
+ 'selected' => 0,
+ 'cid' => NULL,
+ );
+
+ $form['category'] = array(
+ '#type' => 'textfield',
'#title' => t('Category'),
'#maxlength' => 255,
- '#default_value' => $contact['category'],
+ '#default_value' => $category['category'],
'#description' => t("Example: 'website feedback' or 'product information'."),
'#required' => TRUE,
);
- $form['recipients'] = array('#type' => 'textarea',
+ $form['recipients'] = array(
+ '#type' => 'textarea',
'#title' => t('Recipients'),
- '#default_value' => $contact['recipients'],
+ '#default_value' => $category['recipients'],
'#description' => t("Example: 'webmaster@example.com' or 'sales@example.com,support@example.com' . To specify multiple recipients, separate each e-mail address with a comma."),
'#required' => TRUE,
);
- $form['reply'] = array('#type' => 'textarea',
+ $form['reply'] = array(
+ '#type' => 'textarea',
'#title' => t('Auto-reply'),
- '#default_value' => $contact['reply'],
+ '#default_value' => $category['reply'],
'#description' => t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'),
);
- $form['weight'] = array('#type' => 'weight',
+ $form['weight'] = array(
+ '#type' => 'weight',
'#title' => t('Weight'),
- '#default_value' => $contact['weight'],
+ '#default_value' => $category['weight'],
'#description' => t('When listing categories, those with lighter (smaller) weights get listed before categories with heavier (larger) weights. Categories with equal weights are sorted alphabetically.'),
);
- $form['selected'] = array('#type' => 'select',
+ $form['selected'] = array(
+ '#type' => 'select',
'#title' => t('Selected'),
- '#options' => array('0' => t('No'), '1' => t('Yes')),
- '#default_value' => $contact['selected'],
+ '#options' => array(
+ 0 => t('No'),
+ 1 => t('Yes'),
+ ),
+ '#default_value' => $category['selected'],
'#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),
);
- $form['cid'] = array('#type' => 'value',
- '#value' => $contact['cid'],
+ $form['cid'] = array(
+ '#type' => 'value',
+ '#value' => $category['cid'],
);
- $form['submit'] = array('#type' => 'submit',
+ $form['submit'] = array(
+ '#type' => 'submit',
'#value' => t('Save'),
);
@@ -94,71 +108,76 @@ function contact_admin_edit($form, $form_state = array(), $op, $contact = NULL)
/**
* Validate the contact category edit page form submission.
*/
-function contact_admin_edit_validate($form, &$form_state) {
+function contact_category_edit_form_validate($form, &$form_state) {
+ // Validate and each e-mail recipient.
$recipients = explode(',', $form_state['values']['recipients']);
- foreach ($recipients as $recipient) {
- if (!valid_email_address(trim($recipient))) {
+ foreach ($recipients as &$recipient) {
+ $recipient = trim($recipient);
+ if (!valid_email_address($recipient)) {
form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient)));
}
}
+ $form_state['values']['recipients'] = implode(',', $recipients);
}
/**
* Process the contact category edit page form submission.
*/
-function contact_admin_edit_submit($form, &$form_state) {
+function contact_category_edit_form_submit($form, &$form_state) {
if ($form_state['values']['selected']) {
// Unselect all other contact categories.
db_update('contact')
->fields(array('selected' => '0'))
->execute();
}
- $recipients = explode(',', $form_state['values']['recipients']);
- foreach ($recipients as $key => $recipient) {
- // E-mail address validation has already been done in _validate.
- $recipients[$key] = trim($recipient);
- }
- $form_state['values']['recipients'] = implode(',', $recipients);
- if (empty($form_state['values']['cid']) || $form_state['values']['contact_op'] == 'add') {
- drupal_write_record('contact', $form_state['values']);
- drupal_set_message(t('Category %category has been added.', array('%category' => $form_state['values']['category'])));
- watchdog('mail', 'Contact form: category %category added.', array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/structure/contact'));
+ if (empty($form_state['values']['cid'])) {
+ drupal_write_record('contact', $form_state['values']);
}
else {
- drupal_write_record('contact', $form_state['values'], 'cid');
- drupal_set_message(t('Category %category has been updated.', array('%category' => $form_state['values']['category'])));
- watchdog('mail', 'Contact form: category %category updated.', array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/structure/contact'));
+ drupal_write_record('contact', $form_state['values'], array('cid'));
}
+ drupal_set_message(t('Category %category has been saved.', array('%category' => $form_state['values']['category'])));
+ watchdog('contact', 'Category %category has been saved.', array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('Edit'), 'admin/structure/contact/edit/' . $form_state['values']['cid']));
$form_state['redirect'] = 'admin/structure/contact';
- return;
}
/**
- * Category delete page.
+ * Form builder for deleting a contact category.
+ *
+ * @see contact_category_delete_form_submit()
*/
-function contact_admin_delete($form, &$form_state, $contact) {
-
+function contact_category_delete_form($form, &$form_state, array $contact) {
$form['contact'] = array(
'#type' => 'value',
'#value' => $contact,
);
- return confirm_form($form, t('Are you sure you want to delete %category?', array('%category' => $contact['category'])), 'admin/structure/contact', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
+ return confirm_form(
+ $form,
+ t('Are you sure you want to delete %category?', array('%category' => $contact['category'])),
+ 'admin/structure/contact',
+ t('This action cannot be undone.'),
+ t('Delete'),
+ t('Cancel')
+ );
}
/**
- * Process category delete form submission.
+ * Submit handler for the confirm delete category form.
+ *
+ * @see contact_category_delete_form()
*/
-function contact_admin_delete_submit($form, &$form_state) {
- $contact = $form_state['values']['contact'];
+function contact_category_delete_form_submit($form, &$form_state) {
+ $contact = $form['contact']['#value'];
+
db_delete('contact')
->condition('cid', $contact['cid'])
->execute();
+
drupal_set_message(t('Category %category has been deleted.', array('%category' => $contact['category'])));
- watchdog('mail', 'Contact form: category %category deleted.', array('%category' => $contact['category']), WATCHDOG_NOTICE);
+ watchdog('contact', 'Category %category has been deleted.', array('%category' => $contact['category']), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/structure/contact';
- return;
}