| 1 | | <?php |
| 2 | | // $Id: contact.admin.inc,v 1.5 2008/07/02 20:05:11 dries Exp $ |
| 3 | | |
| 4 | | /** |
| 5 | | * @file |
| 6 | | * Admin page callbacks for the contact module. |
| 7 | | */ |
| 8 | | |
| 9 | | /** |
| 10 | | * Categories/list tab. |
| 11 | | */ |
| 12 | 44 | function contact_admin_categories() { |
| 13 | 7 | $result = db_query('SELECT cid, category, recipients, selected FROM
{contact} ORDER BY weight, category'); |
| 14 | 7 | $rows = array(); |
| 15 | 7 | while ($category = db_fetch_object($result)) { |
| 16 | 6 | $rows[] = array($category->category, $category->recipients,
($category->selected ? t('Yes') : t('No')), l(t('edit'),
'admin/build/contact/edit/' . $category->cid), l(t('delete'),
'admin/build/contact/delete/' . $category->cid)); |
| 17 | 6 | } |
| 18 | 7 | $header = array(t('Category'), t('Recipients'), t('Selected'),
array('data' => t('Operations'), 'colspan' => 2)); |
| 19 | | |
| 20 | 7 | return theme('table', $header, $rows); |
| 21 | 0 | } |
| 22 | | |
| 23 | | /** |
| 24 | | * Category edit page. |
| 25 | | */ |
| 26 | 44 | function contact_admin_edit($form_state = array(), $op, $contact = NULL) { |
| 27 | | |
| 28 | 22 | if (empty($contact) || $op == 'add') { |
| 29 | | $contact = array( |
| 30 | 20 | 'category' => '', |
| 31 | 20 | 'recipients' => '', |
| 32 | 20 | 'reply' => '', |
| 33 | 20 | 'weight' => 0, |
| 34 | 20 | 'selected' => 0, |
| 35 | 20 | 'cid' => NULL, |
| 36 | 20 | ); |
| 37 | 20 | } |
| 38 | 22 | $form['contact_op'] = array('#type' => 'value', '#value' => $op); |
| 39 | 22 | $form['category'] = array('#type' => 'textfield', |
| 40 | 22 | '#title' => t('Category'), |
| 41 | 22 | '#maxlength' => 255, |
| 42 | 22 | '#default_value' => $contact['category'], |
| 43 | 22 | '#description' => t("Example: 'website feedback' or 'product
information'."), |
| 44 | 22 | '#required' => TRUE, |
| 45 | | ); |
| 46 | 22 | $form['recipients'] = array('#type' => 'textarea', |
| 47 | 22 | '#title' => t('Recipients'), |
| 48 | 22 | '#default_value' => $contact['recipients'], |
| 49 | 22 | '#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."), |
| 50 | 22 | '#required' => TRUE, |
| 51 | | ); |
| 52 | 22 | $form['reply'] = array('#type' => 'textarea', |
| 53 | 22 | '#title' => t('Auto-reply'), |
| 54 | 22 | '#default_value' => $contact['reply'], |
| 55 | 22 | '#description' => t('Optional auto-reply. Leave empty if you do not
want to send the user an auto-reply message.'), |
| 56 | | ); |
| 57 | 22 | $form['weight'] = array('#type' => 'weight', |
| 58 | 22 | '#title' => t('Weight'), |
| 59 | 22 | '#default_value' => $contact['weight'], |
| 60 | 22 | '#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.'), |
| 61 | | ); |
| 62 | 22 | $form['selected'] = array('#type' => 'select', |
| 63 | 22 | '#title' => t('Selected'), |
| 64 | 22 | '#options' => array('0' => t('No'), '1' => t('Yes')), |
| 65 | 22 | '#default_value' => $contact['selected'], |
| 66 | 22 | '#description' => t('Set this to <em>Yes</em> if you would like this
category to be selected by default.'), |
| 67 | | ); |
| 68 | 22 | $form['cid'] = array('#type' => 'value', |
| 69 | 22 | '#value' => $contact['cid'], |
| 70 | | ); |
| 71 | 22 | $form['submit'] = array('#type' => 'submit', |
| 72 | 22 | '#value' => t('Save'), |
| 73 | | ); |
| 74 | | |
| 75 | 22 | return $form; |
| 76 | 0 | } |
| 77 | | |
| 78 | | /** |
| 79 | | * Validate the contact category edit page form submission. |
| 80 | | */ |
| 81 | 44 | function contact_admin_edit_validate($form, &$form_state) { |
| 82 | 11 | $recipients = explode(',', $form_state['values']['recipients']); |
| 83 | 11 | foreach ($recipients as $recipient) { |
| 84 | 11 | if (!valid_email_address(trim($recipient))) { |
| 85 | 7 | form_set_error('recipients', t('%recipient is an invalid e-mail
address.', array('%recipient' => $recipient))); |
| 86 | 7 | } |
| 87 | 11 | } |
| 88 | 11 | } |
| 89 | | |
| 90 | | /** |
| 91 | | * Process the contact category edit page form submission. |
| 92 | | */ |
| 93 | 44 | function contact_admin_edit_submit($form, &$form_state) { |
| 94 | 4 | if ($form_state['values']['selected']) { |
| 95 | | // Unselect all other contact categories. |
| 96 | 1 | db_query('UPDATE {contact} SET selected = 0'); |
| 97 | 1 | } |
| 98 | 4 | $recipients = explode(',', $form_state['values']['recipients']); |
| 99 | 4 | foreach ($recipients as $key => $recipient) { |
| 100 | | // E-mail address validation has already been done in _validate. |
| 101 | 4 | $recipients[$key] = trim($recipient); |
| 102 | 4 | } |
| 103 | 4 | $form_state['values']['recipients'] = implode(',', $recipients); |
| 104 | 4 | if (empty($form_state['values']['cid']) ||
$form_state['values']['contact_op'] == 'add') { |
| 105 | 3 | drupal_write_record('contact', $form_state['values']); |
| 106 | 3 | drupal_set_message(t('Category %category has been added.',
array('%category' => $form_state['values']['category']))); |
| 107 | 3 | watchdog('mail', 'Contact form: category %category added.',
array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE,
l(t('view'), 'admin/build/contact')); |
| 108 | | |
| 109 | 3 | } |
| 110 | | else { |
| 111 | 1 | drupal_write_record('contact', $form_state['values'], 'cid'); |
| 112 | 1 | drupal_set_message(t('Category %category has been updated.',
array('%category' => $form_state['values']['category']))); |
| 113 | 1 | watchdog('mail', 'Contact form: category %category updated.',
array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE,
l(t('view'), 'admin/build/contact')); |
| 114 | | } |
| 115 | | |
| 116 | 4 | $form_state['redirect'] = 'admin/build/contact'; |
| 117 | 4 | return; |
| 118 | 0 | } |
| 119 | | |
| 120 | | /** |
| 121 | | * Category delete page. |
| 122 | | */ |
| 123 | 44 | function contact_admin_delete(&$form_state, $contact) { |
| 124 | | |
| 125 | 6 | $form['contact'] = array( |
| 126 | 6 | '#type' => 'value', |
| 127 | 6 | '#value' => $contact, |
| 128 | | ); |
| 129 | | |
| 130 | 6 | return confirm_form($form, t('Are you sure you want to delete
%category?', array('%category' => $contact['category'])),
'admin/build/contact', t('This action cannot be undone.'), t('Delete'),
t('Cancel')); |
| 131 | 0 | } |
| 132 | | |
| 133 | | /** |
| 134 | | * Process category delete form submission. |
| 135 | | */ |
| 136 | 44 | function contact_admin_delete_submit($form, &$form_state) { |
| 137 | 3 | $contact = $form_state['values']['contact']; |
| 138 | 3 | db_query("DELETE FROM {contact} WHERE cid = %d", $contact['cid']); |
| 139 | 3 | drupal_set_message(t('Category %category has been deleted.',
array('%category' => $contact['category']))); |
| 140 | 3 | watchdog('mail', 'Contact form: category %category deleted.',
array('%category' => $contact['category']), WATCHDOG_NOTICE); |
| 141 | | |
| 142 | 3 | $form_state['redirect'] = 'admin/build/contact'; |
| 143 | 3 | return; |
| 144 | 0 | } |
| 145 | | |
| 146 | 44 | function contact_admin_settings() { |
| 147 | 9 | $form['contact_form_information'] = array('#type' => 'textarea', |
| 148 | 9 | '#title' => t('Additional information'), |
| 149 | 9 | '#default_value' => variable_get('contact_form_information', t('You can
leave a message using the contact form below.')), |
| 150 | 9 | '#description' => t('Information to show on the <a href="@form">contact
page</a>. Can be anything from submission guidelines to your postal address
or telephone number.', array('@form' => url('contact'))), |
| 151 | | ); |
| 152 | 9 | $form['contact_hourly_threshold'] = array('#type' => 'select', |
| 153 | 9 | '#title' => t('Hourly threshold'), |
| 154 | 9 | '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20,
30, 40, 50)), |
| 155 | 9 | '#default_value' => variable_get('contact_hourly_threshold', 3), |
| 156 | 9 | '#description' => t('The maximum number of contact form submissions a
user can perform per hour.'), |
| 157 | | ); |
| 158 | 9 | $form['contact_default_status'] = array( |
| 159 | 9 | '#type' => 'checkbox', |
| 160 | 9 | '#title' => t('Enable personal contact form by default'), |
| 161 | 9 | '#default_value' => variable_get('contact_default_status', 1), |
| 162 | 9 | '#description' => t('Default status of the personal contact form for
new users.'), |
| 163 | | ); |
| 164 | 9 | return system_settings_form($form); |
| 165 | 0 | } |
| 166 | 44 | |