/[drupal]/drupal/modules/contact/contact.admin.inc
ViewVC logotype

Contents of /drupal/modules/contact/contact.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.18 - (show annotations) (download) (as text)
Fri Oct 9 02:34:07 2009 UTC (7 weeks ago) by dries
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.17: +86 -67 lines
File MIME type: text/x-php
- Patch #599186 by Dave Reid: code clean-ups
1 <?php
2 // $Id: contact.admin.inc,v 1.17 2009/10/09 00:59:56 dries Exp $
3
4 /**
5 * @file
6 * Admin page callbacks for the contact module.
7 */
8
9 /**
10 * Categories/list tab.
11 */
12 function contact_category_list() {
13 $header = array(
14 t('Category'),
15 t('Recipients'),
16 t('Selected'),
17 array('data' => t('Operations'), 'colspan' => 2),
18 );
19 $rows = array();
20
21 // Get all the contact categories from the database.
22 $categories = db_query('SELECT cid, category, recipients, selected FROM {contact} ORDER BY weight, category')->fetchAll();
23
24 // Loop through the categories and add them to the table.
25 foreach ($categories as $category) {
26 $rows[] = array(
27 $category->category,
28 $category->recipients,
29 ($category->selected ? t('Yes') : t('No')),
30 l(t('Edit'), 'admin/structure/contact/edit/' . $category->cid),
31 l(t('Delete'), 'admin/structure/contact/delete/' . $category->cid),
32 );
33 }
34
35 if (!$rows) {
36 $rows[] = array(array(
37 'data' => t('No categories available.'),
38 'colspan' => 5,
39 ));
40 }
41
42 return theme('table', array('header' => $header, 'rows' => $rows));
43 }
44
45 /**
46 * Category edit page.
47 */
48 function contact_category_edit_form($form, &$form_state, array $category = array()) {
49 // If this is a new category, add the default values.
50 $category += array(
51 'category' => '',
52 'recipients' => '',
53 'reply' => '',
54 'weight' => 0,
55 'selected' => 0,
56 'cid' => NULL,
57 );
58
59 $form['category'] = array(
60 '#type' => 'textfield',
61 '#title' => t('Category'),
62 '#maxlength' => 255,
63 '#default_value' => $category['category'],
64 '#description' => t("Example: 'website feedback' or 'product information'."),
65 '#required' => TRUE,
66 );
67 $form['recipients'] = array(
68 '#type' => 'textarea',
69 '#title' => t('Recipients'),
70 '#default_value' => $category['recipients'],
71 '#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."),
72 '#required' => TRUE,
73 );
74 $form['reply'] = array(
75 '#type' => 'textarea',
76 '#title' => t('Auto-reply'),
77 '#default_value' => $category['reply'],
78 '#description' => t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'),
79 );
80 $form['weight'] = array(
81 '#type' => 'weight',
82 '#title' => t('Weight'),
83 '#default_value' => $category['weight'],
84 '#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.'),
85 );
86 $form['selected'] = array(
87 '#type' => 'select',
88 '#title' => t('Selected'),
89 '#options' => array(
90 0 => t('No'),
91 1 => t('Yes'),
92 ),
93 '#default_value' => $category['selected'],
94 '#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),
95 );
96 $form['cid'] = array(
97 '#type' => 'value',
98 '#value' => $category['cid'],
99 );
100 $form['submit'] = array(
101 '#type' => 'submit',
102 '#value' => t('Save'),
103 );
104
105 return $form;
106 }
107
108 /**
109 * Validate the contact category edit page form submission.
110 */
111 function contact_category_edit_form_validate($form, &$form_state) {
112 // Validate and each e-mail recipient.
113 $recipients = explode(',', $form_state['values']['recipients']);
114 foreach ($recipients as &$recipient) {
115 $recipient = trim($recipient);
116 if (!valid_email_address($recipient)) {
117 form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient)));
118 }
119 }
120 $form_state['values']['recipients'] = implode(',', $recipients);
121 }
122
123 /**
124 * Process the contact category edit page form submission.
125 */
126 function contact_category_edit_form_submit($form, &$form_state) {
127 if ($form_state['values']['selected']) {
128 // Unselect all other contact categories.
129 db_update('contact')
130 ->fields(array('selected' => '0'))
131 ->execute();
132 }
133
134 if (empty($form_state['values']['cid'])) {
135 drupal_write_record('contact', $form_state['values']);
136 }
137 else {
138 drupal_write_record('contact', $form_state['values'], array('cid'));
139 }
140
141 drupal_set_message(t('Category %category has been saved.', array('%category' => $form_state['values']['category'])));
142 watchdog('contact', 'Category %category has been saved.', array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('Edit'), 'admin/structure/contact/edit/' . $form_state['values']['cid']));
143 $form_state['redirect'] = 'admin/structure/contact';
144 }
145
146 /**
147 * Form builder for deleting a contact category.
148 *
149 * @see contact_category_delete_form_submit()
150 */
151 function contact_category_delete_form($form, &$form_state, array $contact) {
152 $form['contact'] = array(
153 '#type' => 'value',
154 '#value' => $contact,
155 );
156
157 return confirm_form(
158 $form,
159 t('Are you sure you want to delete %category?', array('%category' => $contact['category'])),
160 'admin/structure/contact',
161 t('This action cannot be undone.'),
162 t('Delete'),
163 t('Cancel')
164 );
165 }
166
167 /**
168 * Submit handler for the confirm delete category form.
169 *
170 * @see contact_category_delete_form()
171 */
172 function contact_category_delete_form_submit($form, &$form_state) {
173 $contact = $form['contact']['#value'];
174
175 db_delete('contact')
176 ->condition('cid', $contact['cid'])
177 ->execute();
178
179 drupal_set_message(t('Category %category has been deleted.', array('%category' => $contact['category'])));
180 watchdog('contact', 'Category %category has been deleted.', array('%category' => $contact['category']), WATCHDOG_NOTICE);
181
182 $form_state['redirect'] = 'admin/structure/contact';
183 }

  ViewVC Help
Powered by ViewVC 1.1.2