|
<?php |
|
|
// $Id: citizenspeak.lib.php,v 1.3 2005/11/12 18:37:20 georgehotelling Exp $ |
|
|
|
|
|
/** |
|
|
* @file |
|
|
* Helper functions for the CitizenSpeak module |
|
|
*/ |
|
|
|
|
|
function _citizenspeak_get_zips($nid) { |
|
|
$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); |
|
|
$distinct_zips = db_num_rows($zip_result); |
|
|
$zips = array(); |
|
|
|
|
|
while ($row = db_fetch_array($zip_result)) { |
|
|
$zips[] = $row; |
|
|
} |
|
|
|
|
|
$total = db_result(db_query("SELECT COUNT(*) FROM {citizenspeak_participants} WHERE nid = %d", $nid)); |
|
|
|
|
|
return array($distinct_zips, $zips, $total); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Split email addresses into an array |
|
|
* |
|
|
* @param $emails One or more email addresses separated with commas and spaces |
|
|
* @returns array of email addresses |
|
|
*/ |
|
|
function _citizenspeak_split_emails($emails) { |
|
|
return preg_split('/[\s,]+/', $emails); |
|
|
} |
|
|
|
|
|
function _citizenspeak_validate_participation($edit) { |
|
|
$errors = false; |
|
|
if ($edit['name'] == "") { |
|
|
form_set_error('name', t('You must enter your name')); |
|
|
$errors = true; |
|
|
} |
|
|
|
|
|
if (!valid_email_address($edit['email'])) { |
|
|
form_set_error('email', t('You must provide a valid email address')); |
|
|
$errors = true; |
|
|
} |
|
|
|
|
|
if ($edit['address'] == "") { |
|
|
form_set_error('name', t('You must enter your address')); |
|
|
$errors = true; |
|
|
} |
|
|
|
|
|
if ($edit['city'] == "") { |
|
|
form_set_error('city', t('You must enter your city')); |
|
|
$errors = true; |
|
|
} |
|
|
|
|
|
if ($edit['state'] == "") { |
|
|
form_set_error('state', t('You must enter your state')); |
|
|
$errors = true; |
|
|
} |
|
|
|
|
|
if (!_citizenspeak_valid_zipcode($edit['zip'])) { |
|
|
form_set_error('zip', t('You must provide a 5 digit ZIP code')); |
|
|
$errors = true; |
|
|
} |
|
|
|
|
|
return !$errors; |
|
|
} |
|
|
|
|
|
function _citizenspeak_valid_zipcode($zip) { |
|
|
return preg_match('/^\d{5}$/', $zip); |
|
|
} |
|
|
|
|
|
function _citizenspeak_send_reminders($node) { |
|
|
$send_15 = variable_get('citizenspeak_remind_15', false); |
|
|
$send_50 = variable_get('citizenspeak_remind_50', false); |
|
|
$send_100 = variable_get('citizenspeak_remind_100', false); |
|
|
// Skip the DB hit if responses aren't sent |
|
|
if ($send_15 or $send_50 or $send_100) { |
|
|
$responses = db_result(db_query('SELECT COUNT(*) AS responses FROM {citizenspeak_participants} WHERE nid = %d', $node->nid)); |
|
|
|
|
|
// Send the message if we are at a threshold |
|
|
if (($responses == 15 and $send_15) or |
|
|
($responses == 50 and $send_50) or |
|
|
($responses == 100 and $send_100)) { |
|
|
$owner = user_load(array("uid" => $node->uid)); |
|
|
$headers = t('From: %site_name <%site_email>', array("%site_name" => variable_get("site_name", ""), "%site_email" => variable_get("site_mail", ""))); |
|
|
$subject = variable_get('citizenspeak_reminder_subject', CITIZENSPEAK_DEFAULT_REMINDER_SUBJECT); |
|
|
$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))); |
|
|
mail($owner->mail, $subject, $body, $headers); |
|
|
} |
|
|
} |
|
|
} |
|
|
?> |
|
| 1 |
|
<?php |
| 2 |
|
// $Id: citizenspeak.lib.php,v 1.3 2005/11/12 18:37:20 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_send_petition_form_validate($form_id, $edit) { |
| 34 |
|
if ($edit['name'] == '') { |
| 35 |
|
form_set_error('name', t('You must enter your name')); |
| 36 |
|
} |
| 37 |
|
|
| 38 |
|
if (!valid_email_address($edit['email'])) { |
| 39 |
|
form_set_error('email', t('You must provide a valid email address')); |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
if (variable_get('citizenspeak_require_address', 1)) { |
| 43 |
|
if ($edit['address'] == '') { |
| 44 |
|
form_set_error('name', t('You must enter your address')); |
| 45 |
|
} |
| 46 |
|
|
| 47 |
|
if ($edit['city'] == '') { |
| 48 |
|
form_set_error('city', t('You must enter your city')); |
| 49 |
|
} |
| 50 |
|
|
| 51 |
|
if ($edit['state'] == '') { |
| 52 |
|
form_set_error('state', t('You must enter your state')); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
if (!_citizenspeak_valid_zipcode($edit['zip'])) { |
| 56 |
|
form_set_error('zip', t('You must provide a 5 digit ZIP code')); |
| 57 |
|
} |
| 58 |
|
} |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
function _citizenspeak_valid_zipcode($zip) { |
| 62 |
|
return preg_match('/^\d{5}$/', $zip); |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
function _citizenspeak_send_reminders($node) { |
| 66 |
|
$send_15 = variable_get('citizenspeak_remind_15', false); |
| 67 |
|
$send_50 = variable_get('citizenspeak_remind_50', false); |
| 68 |
|
$send_100 = variable_get('citizenspeak_remind_100', false); |
| 69 |
|
// Skip the DB hit if responses aren't sent |
| 70 |
|
if ($send_15 or $send_50 or $send_100) { |
| 71 |
|
$responses = db_result(db_query('SELECT COUNT(*) AS responses FROM {citizenspeak_participants} WHERE nid = %d', $node->nid)); |
| 72 |
|
|
| 73 |
|
// Send the message if we are at a threshold |
| 74 |
|
if (($responses == 15 and $send_15) or |
| 75 |
|
($responses == 50 and $send_50) or |
| 76 |
|
($responses == 100 and $send_100)) { |
| 77 |
|
$owner = user_load(array("uid" => $node->uid)); |
| 78 |
|
$headers = t('From: %site_name <%site_email>', array("%site_name" => variable_get("site_name", ""), "%site_email" => variable_get("site_mail", ""))); |
| 79 |
|
$subject = variable_get('citizenspeak_reminder_subject', CITIZENSPEAK_DEFAULT_REMINDER_SUBJECT); |
| 80 |
|
$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))); |
| 81 |
|
mail($owner->mail, $subject, wordwrap($body, 70), $headers); |
| 82 |
|
} |
| 83 |
|
} |
| 84 |
|
} |