/[drupal]/contributions/modules/citizenspeak/citizenspeak.lib.php
ViewVC logotype

Contents of /contributions/modules/citizenspeak/citizenspeak.lib.php

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


Revision 1.3 - (show annotations) (download) (as text)
Sat Nov 12 18:37:20 2005 UTC (4 years ago) by georgehotelling
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5, DRUPAL-4-6
Changes since 1.2: +7 -10 lines
File MIME type: text/x-php
Fixed From: header on reminder emails
1 <?php
2 // $Id: citizenspeak.lib.php,v 1.2 2005/10/29 17:44:47 georgehotelling Exp $
3
4 /**
5 * @file
6 * Helper functions for the CitizenSpeak module
7 */
8
9 function _citizenspeak_get_zips($nid) {
10 $zip_result = db_query("SELECT zip, COUNT(*) AS from_zip FROM {citizenspeak_participants} WHERE nid = %d GROUP BY zip ORDER BY from_zip DESC", $nid);
11 $distinct_zips = db_num_rows($zip_result);
12 $zips = array();
13
14 while ($row = db_fetch_array($zip_result)) {
15 $zips[] = $row;
16 }
17
18 $total = db_result(db_query("SELECT COUNT(*) FROM {citizenspeak_participants} WHERE nid = %d", $nid));
19
20 return array($distinct_zips, $zips, $total);
21 }
22
23 /**
24 * Split email addresses into an array
25 *
26 * @param $emails One or more email addresses separated with commas and spaces
27 * @returns array of email addresses
28 */
29 function _citizenspeak_split_emails($emails) {
30 return preg_split('/[\s,]+/', $emails);
31 }
32
33 function _citizenspeak_validate_participation($edit) {
34 $errors = false;
35 if ($edit['name'] == "") {
36 form_set_error('name', t('You must enter your name'));
37 $errors = true;
38 }
39
40 if (!valid_email_address($edit['email'])) {
41 form_set_error('email', t('You must provide a valid email address'));
42 $errors = true;
43 }
44
45 if ($edit['address'] == "") {
46 form_set_error('name', t('You must enter your address'));
47 $errors = true;
48 }
49
50 if ($edit['city'] == "") {
51 form_set_error('city', t('You must enter your city'));
52 $errors = true;
53 }
54
55 if ($edit['state'] == "") {
56 form_set_error('state', t('You must enter your state'));
57 $errors = true;
58 }
59
60 if (!_citizenspeak_valid_zipcode($edit['zip'])) {
61 form_set_error('zip', t('You must provide a 5 digit ZIP code'));
62 $errors = true;
63 }
64
65 return !$errors;
66 }
67
68 function _citizenspeak_valid_zipcode($zip) {
69 return preg_match('/^\d{5}$/', $zip);
70 }
71
72 function _citizenspeak_send_reminders($node) {
73 $send_15 = variable_get('citizenspeak_remind_15', false);
74 $send_50 = variable_get('citizenspeak_remind_50', false);
75 $send_100 = variable_get('citizenspeak_remind_100', false);
76 // Skip the DB hit if responses aren't sent
77 if ($send_15 or $send_50 or $send_100) {
78 $responses = db_result(db_query('SELECT COUNT(*) AS responses FROM {citizenspeak_participants} WHERE nid = %d', $node->nid));
79
80 // Send the message if we are at a threshold
81 if (($responses == 15 and $send_15) or
82 ($responses == 50 and $send_50) or
83 ($responses == 100 and $send_100)) {
84 $owner = user_load(array("uid" => $node->uid));
85 $headers = t('From: %site_name <%site_email>', array("%site_name" => variable_get("site_name", ""), "%site_email" => variable_get("site_mail", "")));
86 $subject = variable_get('citizenspeak_reminder_subject', CITIZENSPEAK_DEFAULT_REMINDER_SUBJECT);
87 $body = t(variable_get('citizenspeak_reminder_template', CITIZENSPEAK_DEFAULT_REMINDER_TEMPLATE), array("%title" => $node->title, "%count" => $responses, "%url" => url("node/$node->nid/report", null, null, true)));
88 mail($owner->mail, $subject, $body, $headers);
89 }
90 }
91 }
92 ?>

  ViewVC Help
Powered by ViewVC 1.1.2