Code coverage for /20080809/modules/contact/contact.admin.inc

Line #Times calledCode
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
 */
1240
function contact_admin_categories() {
137
  $result = db_query('SELECT cid, category, recipients, selected FROM
{contact} ORDER BY weight, category');
147
  $rows = array();
157
  while ($category = db_fetch_object($result)) {
166
    $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));
176
  }
187
  $header = array(t('Category'), t('Recipients'), t('Selected'),
array('data' => t('Operations'), 'colspan' => 2));
19
207
  return theme('table', $header, $rows);
210
}
22
23
/**
24
 * Category edit page.
25
 */
2640
function contact_admin_edit($form_state = array(), $op, $contact = NULL) {
27
2818
  if (empty($contact) || $op == 'add') {
29
    $contact = array(
3016
      'category' => '',
3116
      'recipients' => '',
3216
      'reply' => '',
3316
      'weight' => 0,
3416
      'selected' => 0,
3516
      'cid' => NULL,
3616
    );
3716
  }
3818
  $form['contact_op'] = array('#type' => 'value', '#value' => $op);
3918
  $form['category'] = array('#type' => 'textfield',
4018
    '#title' => t('Category'),
4118
    '#maxlength' => 255,
4218
    '#default_value' => $contact['category'],
4318
    '#description' => t("Example: 'website feedback' or 'product
information'."),
4418
    '#required' => TRUE,
45
  );
4618
  $form['recipients'] = array('#type' => 'textarea',
4718
    '#title' => t('Recipients'),
4818
    '#default_value' => $contact['recipients'],
4918
    '#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."),
5018
    '#required' => TRUE,
51
  );
5218
  $form['reply'] = array('#type' => 'textarea',
5318
    '#title' => t('Auto-reply'),
5418
    '#default_value' => $contact['reply'],
5518
    '#description' => t('Optional auto-reply. Leave empty if you do not
want to send the user an auto-reply message.'),
56
  );
5718
  $form['weight'] = array('#type' => 'weight',
5818
    '#title' => t('Weight'),
5918
    '#default_value' => $contact['weight'],
6018
    '#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
  );
6218
  $form['selected'] = array('#type' => 'select',
6318
    '#title' => t('Selected'),
6418
    '#options' => array('0' => t('No'), '1' => t('Yes')),
6518
    '#default_value' => $contact['selected'],
6618
    '#description' => t('Set this to <em>Yes</em> if you would like this
category to be selected by default.'),
67
  );
6818
  $form['cid'] = array('#type' => 'value',
6918
    '#value' => $contact['cid'],
70
  );
7118
  $form['submit'] = array('#type' => 'submit',
7218
    '#value' => t('Save'),
73
  );
74
7518
  return $form;
760
}
77
78
/**
79
 * Validate the contact category edit page form submission.
80
 */
8140
function contact_admin_edit_validate($form, &$form_state) {
829
  $recipients = explode(',', $form_state['values']['recipients']);
839
  foreach ($recipients as $recipient) {
849
    if (!valid_email_address(trim($recipient))) {
855
      form_set_error('recipients', t('%recipient is an invalid e-mail
address.', array('%recipient' => $recipient)));
865
    }
879
  }
889
}
89
90
/**
91
 * Process the contact category edit page form submission.
92
 */
9340
function contact_admin_edit_submit($form, &$form_state) {
944
  if ($form_state['values']['selected']) {
95
    // Unselect all other contact categories.
961
    db_query('UPDATE {contact} SET selected = 0');
971
  }
984
  $recipients = explode(',', $form_state['values']['recipients']);
994
  foreach ($recipients as $key => $recipient) {
100
    // E-mail address validation has already been done in _validate.
1014
    $recipients[$key] = trim($recipient);
1024
  }
1034
  $form_state['values']['recipients'] = implode(',', $recipients);
1044
  if (empty($form_state['values']['cid']) ||
$form_state['values']['contact_op'] == 'add') {
1053
    drupal_write_record('contact', $form_state['values']);
1063
    drupal_set_message(t('Category %category has been added.',
array('%category' => $form_state['values']['category'])));
1073
    watchdog('mail', 'Contact form: category %category added.',
array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE,
l(t('view'), 'admin/build/contact'));
108
1093
  }
110
  else {
1111
    drupal_write_record('contact', $form_state['values'], 'cid');
1121
    drupal_set_message(t('Category %category has been updated.',
array('%category' => $form_state['values']['category'])));
1131
    watchdog('mail', 'Contact form: category %category updated.',
array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE,
l(t('view'), 'admin/build/contact'));
114
  }
115
1164
  $form_state['redirect'] = 'admin/build/contact';
1174
  return;
1180
}
119
120
/**
121
 * Category delete page.
122
 */
12340
function contact_admin_delete(&$form_state, $contact) {
124
1256
  $form['contact'] = array(
1266
    '#type' => 'value',
1276
    '#value' => $contact,
128
  );
129
1306
  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'));
1310
}
132
133
/**
134
 * Process category delete form submission.
135
 */
13640
function contact_admin_delete_submit($form, &$form_state) {
1373
  $contact = $form_state['values']['contact'];
1383
  db_query("DELETE FROM {contact} WHERE cid = %d", $contact['cid']);
1393
  drupal_set_message(t('Category %category has been deleted.',
array('%category' => $contact['category'])));
1403
  watchdog('mail', 'Contact form: category %category deleted.',
array('%category' => $contact['category']), WATCHDOG_NOTICE);
141
1423
  $form_state['redirect'] = 'admin/build/contact';
1433
  return;
1440
}
145
14640
function contact_admin_settings() {
1479
  $form['contact_form_information'] = array('#type' => 'textarea',
1489
    '#title' => t('Additional information'),
1499
    '#default_value' => variable_get('contact_form_information', t('You can
leave a message using the contact form below.')),
1509
    '#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
  );
1529
  $form['contact_hourly_threshold'] = array('#type' => 'select',
1539
    '#title' => t('Hourly threshold'),
1549
    '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20,
30, 40, 50)),
1559
    '#default_value' => variable_get('contact_hourly_threshold', 3),
1569
    '#description' => t('The maximum number of contact form submissions a
user can perform per hour.'),
157
  );
1589
  $form['contact_default_status'] = array(
1599
    '#type' => 'checkbox',
1609
    '#title' => t('Enable personal contact form by default'),
1619
    '#default_value' => variable_get('contact_default_status', 1),
1629
    '#description' => t('Default status of the personal contact form for
new users.'),
163
  );
1649
  return system_settings_form($form);
1650
}
16640