00001 <?php
00002
00003
00012 function contact_admin_categories() {
00013 $result = db_query('SELECT cid, category, recipients, selected FROM {contact} ORDER BY weight, category');
00014 $rows = array();
00015 while ($category = db_fetch_object($result)) {
00016 $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));
00017 }
00018 $header = array(t('Category'), t('Recipients'), t('Selected'), array('data' => t('Operations'), 'colspan' => 2));
00019
00020 return theme('table', $header, $rows);
00021 }
00022
00026 function contact_admin_edit($form_state = array(), $op, $contact = NULL) {
00027
00028 if (empty($contact) || $op == 'add') {
00029 $contact = array(
00030 'category' => '',
00031 'recipients' => '',
00032 'reply' => '',
00033 'weight' => 0,
00034 'selected' => 0,
00035 'cid' => NULL,
00036 );
00037 }
00038 $form['contact_op'] = array('#type' => 'value', '#value' => $op);
00039 $form['category'] = array('#type' => 'textfield',
00040 '#title' => t('Category'),
00041 '#maxlength' => 255,
00042 '#default_value' => $contact['category'],
00043 '#description' => t("Example: 'website feedback' or 'product information'."),
00044 '#required' => TRUE,
00045 );
00046 $form['recipients'] = array('#type' => 'textarea',
00047 '#title' => t('Recipients'),
00048 '#default_value' => $contact['recipients'],
00049 '#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."),
00050 '#required' => TRUE,
00051 );
00052 $form['reply'] = array('#type' => 'textarea',
00053 '#title' => t('Auto-reply'),
00054 '#default_value' => $contact['reply'],
00055 '#description' => t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'),
00056 );
00057 $form['weight'] = array('#type' => 'weight',
00058 '#title' => t('Weight'),
00059 '#default_value' => $contact['weight'],
00060 '#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.'),
00061 );
00062 $form['selected'] = array('#type' => 'select',
00063 '#title' => t('Selected'),
00064 '#options' => array('0' => t('No'), '1' => t('Yes')),
00065 '#default_value' => $contact['selected'],
00066 '#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),
00067 );
00068 $form['cid'] = array('#type' => 'value',
00069 '#value' => $contact['cid'],
00070 );
00071 $form['submit'] = array('#type' => 'submit',
00072 '#value' => t('Save'),
00073 );
00074
00075 return $form;
00076 }
00077
00081 function contact_admin_edit_validate($form, &$form_state) {
00082 if (empty($form_state['values']['category'])) {
00083 form_set_error('category', t('You must enter a category.'));
00084 }
00085 if (empty($form_state['values']['recipients'])) {
00086 form_set_error('recipients', t('You must enter one or more recipients.'));
00087 }
00088 else {
00089 $recipients = explode(',', $form_state['values']['recipients']);
00090 foreach ($recipients as $recipient) {
00091 if (!valid_email_address(trim($recipient))) {
00092 form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient)));
00093 }
00094 }
00095 }
00096 }
00097
00101 function contact_admin_edit_submit($form, &$form_state) {
00102 if ($form_state['values']['selected']) {
00103
00104 db_query('UPDATE {contact} SET selected = 0');
00105 }
00106 $recipients = explode(',', $form_state['values']['recipients']);
00107 foreach ($recipients as $key => $recipient) {
00108
00109 $recipients[$key] = trim($recipient);
00110 }
00111 $form_state['values']['recipients'] = implode(',', $recipients);
00112 if (empty($form_state['values']['cid']) || $form_state['values']['contact_op'] == 'add') {
00113 drupal_write_record('contact', $form_state['values']);
00114 drupal_set_message(t('Category %category has been added.', array('%category' => $form_state['values']['category'])));
00115 watchdog('mail', 'Contact form: category %category added.', array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
00116
00117 }
00118 else {
00119 drupal_write_record('contact', $form_state['values'], 'cid');
00120 drupal_set_message(t('Category %category has been updated.', array('%category' => $form_state['values']['category'])));
00121 watchdog('mail', 'Contact form: category %category updated.', array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
00122 }
00123
00124 $form_state['redirect'] = 'admin/build/contact';
00125 return;
00126 }
00127
00131 function contact_admin_delete(&$form_state, $contact) {
00132
00133 $form['contact'] = array(
00134 '#type' => 'value',
00135 '#value' => $contact,
00136 );
00137
00138 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'));
00139 }
00140
00144 function contact_admin_delete_submit($form, &$form_state) {
00145 $contact = $form_state['values']['contact'];
00146 db_query("DELETE FROM {contact} WHERE cid = %d", $contact['cid']);
00147 drupal_set_message(t('Category %category has been deleted.', array('%category' => $contact['category'])));
00148 watchdog('mail', 'Contact form: category %category deleted.', array('%category' => $contact['category']), WATCHDOG_NOTICE);
00149
00150 $form_state['redirect'] = 'admin/build/contact';
00151 return;
00152 }
00153
00154 function contact_admin_settings() {
00155 $form['contact_form_information'] = array('#type' => 'textarea',
00156 '#title' => t('Additional information'),
00157 '#default_value' => variable_get('contact_form_information', t('You can leave a message using the contact form below.')),
00158 '#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'))),
00159 );
00160 $form['contact_hourly_threshold'] = array('#type' => 'select',
00161 '#title' => t('Hourly threshold'),
00162 '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50)),
00163 '#default_value' => variable_get('contact_hourly_threshold', 3),
00164 '#description' => t('The maximum number of contact form submissions a user can perform per hour.'),
00165 );
00166 $form['contact_default_status'] = array(
00167 '#type' => 'checkbox',
00168 '#title' => t('Enable personal contact form by default'),
00169 '#default_value' => variable_get('contact_default_status', 1),
00170 '#description' => t('Default status of the personal contact form for new users.'),
00171 );
00172 return system_settings_form($form);
00173 }