contact.admin.inc

Admin page callbacks for the contact module.

Archivo

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

Functions

Nombreorden descendente Descripción
contact_admin_categories Categories/list tab.
contact_admin_delete Category delete page.
contact_admin_delete_submit Process category delete form submission.
contact_admin_edit Category edit page.
contact_admin_edit_submit Process the contact category edit page form submission.
contact_admin_edit_validate Validate the contact category edit page form submission.
contact_admin_settings