/[drupal]/contributions/modules/og_contact/og_contact.pages.inc
ViewVC logotype

Contents of /contributions/modules/og_contact/og_contact.pages.inc

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


Revision 1.1 - (show annotations) (download) (as text)
Tue Mar 3 17:53:00 2009 UTC (8 months, 3 weeks ago) by gnat
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1
File MIME type: text/x-php
Initial check in for the D6 branch. Lots of features and fixes, as well as refactoring.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Group contact form page callbacks for the OG contact module.
7 */
8
9 /**
10 * Group contact page
11 */
12 function og_contact_page() {
13 global $user;
14
15 if (!flood_is_allowed('og-contact', variable_get('og_contact_hourly_threshold', 3))) {
16 $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('og_contact_hourly_threshold', 3)));
17 }
18 else {
19 $output = drupal_get_form('og_contact_mail_page');
20 }
21
22 return $output;
23 }
24
25 /**
26 * Build the contact form
27 */
28 function og_contact_mail_page(&$form_state) {
29 global $user;
30 $gid = arg(1);
31 $group = og_contact_group_load($gid);
32 $name = $group->name;
33 $admin = og_is_group_admin(node_load($gid));
34 if ($admin == TRUE && variable_get('og_contact_group_admin_single', 1) || user_access('administer og contact form') && variable_get('og_contact_group_admin_single', 1)) {
35 $form['admin_edit'] = array('#value' => l('edit contact form settings', 'node/'. $gid .'/contact/edit') .'<br /><br />');
36 }
37 drupal_set_title(t('Contact %name', array('%name' => $name)));
38 $groups[$gid] = $name;
39
40 if ($gid && og_contact_group_has_form($gid) == TRUE && arg(2) == 'contact') {
41 $form['#token'] = $user->uid ? $user->name . $user->mail : '';
42 if (variable_get('og_contact_custom_info', 0) == 1) {
43 $form['og_contact_information'] = array('#value' => ($group->info != '') ? filter_xss($group->info) : filter_xss_admin(variable_get('og_contact_form_information', t('You can leave a message using the contact form below.'))));
44 }
45 else {
46 $form['og_contact_information'] = array('#value' => filter_xss_admin(variable_get('og_contact_form_information', t('You can leave a message using the contact form below.'))));
47 }
48 $form['name'] = array('#type' => 'textfield',
49 '#title' => t('Your name'),
50 '#maxlength' => 255,
51 '#default_value' => $user->uid ? $user->name : '',
52 '#required' => TRUE,
53 );
54 $form['mail'] = array('#type' => 'textfield',
55 '#title' => t('Your e-mail address'),
56 '#maxlength' => 255,
57 '#default_value' => $user->uid ? $user->mail : '',
58 '#required' => TRUE,
59 );
60 $form['subject'] = array('#type' => 'textfield',
61 '#title' => t('Subject'),
62 '#maxlength' => 255,
63 '#required' => TRUE,
64 );
65 $form['message'] = array('#type' => 'textarea',
66 '#title' => t('Message'),
67 '#required' => TRUE,
68 );
69 // We do not allow anonymous users to send themselves a copy
70 // because it can be abused to spam people.
71 if ($user->uid) {
72 $form['copy'] = array('#type' => 'checkbox',
73 '#title' => t('Send yourself a copy.'),
74 );
75 }
76 $form['gid'] = array('#type' => 'hidden',
77 '#value' => $gid,
78 );
79 $form['submit'] = array('#type' => 'submit',
80 '#value' => t('Send e-mail'),
81 );
82 }
83 else {
84 drupal_set_message('Contact form not configured', 'status');
85 }
86 return $form;
87 }
88
89 /**
90 * Validate the OG contact page form submission.
91 */
92 function og_contact_mail_page_validate($form, &$form_state) {
93 if (!valid_email_address($form_state['values']['mail'])) {
94 form_set_error('mail', t('You must enter a valid e-mail address.'));
95 }
96 }
97
98 /**
99 * Process the contact page form submission.
100 */
101 function og_contact_mail_page_submit($form, &$form_state) {
102 global $language;
103
104 $values = $form_state['values'];
105 // E-mail address of the sender: as the form field is a text field,
106 // all instances of \r and \n have been automatically stripped from it.
107 $from = $values['mail'];
108
109 // Load recipients
110 $recipients = og_contact_get_recipients($values['gid']);
111 // Load group information
112 $group = og_contact_group_load($values['gid']);
113
114 // drupal_mail('og-contact-page-mail', $recipients, $subject,
115 drupal_mail('og_contact', 'page_mail', $recipients, language_default(), $values, $from);
116
117 // If the user requests it, send a copy.
118 if ($values['copy']) {
119 // drupal_mail('og-contact-page-copy', $from, $subject, $body, $from);
120 drupal_mail('og_contact', 'page_copy', $from, $language, $values, $from);
121 }
122
123 // Send an auto-reply if necessary:
124 if ($group->reply) {
125 // drupal_mail('og-contact-page-autoreply', $from, $subject, wordwrap(check_plain($contact->reply)), $contact->recipients);
126 drupal_mail('og_contact', 'page_autoreply', $from, $language, $values);
127 }
128
129 // Log the operation:
130 flood_register_event('og_contact');
131 watchdog('mail', '%name-from sent an e-mail regarding %category.', array('%name-from' => $values['name'] ." [$from]", '%category' => $group->name));
132
133 // Update user:
134 drupal_set_message(t('Your message has been sent.'));
135
136 // Jump to group page rather than back to contact page to avoid contradictory messages if flood control has been activated.
137 $form_state['redirect'] = ('node/'. $group->gid);
138 }

  ViewVC Help
Powered by ViewVC 1.1.2