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