| 1 |
<?php
|
| 2 |
// $Id: citizenspeak.reports.php,v 1.1 2005/10/15 00:55:27 georgehotelling Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Reporting functionality for the CitizenSpeak module
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Display the form for getting reports, or a report for a node
|
| 11 |
*
|
| 12 |
* @param $nid
|
| 13 |
* A node ID
|
| 14 |
*/
|
| 15 |
function citizenspeak_report($nid) {
|
| 16 |
$edit = $_GET['edit'];
|
| 17 |
$op = (isset($_GET['op']))?$_GET['op']:t('view');
|
| 18 |
$params = array('nid' => $nid);
|
| 19 |
$node = node_load($params);
|
| 20 |
if ($op == t('view')) {
|
| 21 |
$params = array_merge($params,
|
| 22 |
db_fetch_array(db_query("SELECT COUNT(*) AS total_emails, MAX(sent_at) AS last_email FROM {citizenspeak_participants} WHERE nid = %d", $nid)));
|
| 23 |
|
| 24 |
list($params['total_zips'], $params['zips']) = _citizenspeak_get_zips($nid);
|
| 25 |
$output = theme('citizenspeak_statistics_page', $params);
|
| 26 |
echo theme('page', $output);
|
| 27 |
}
|
| 28 |
elseif ($op == t('download')) {
|
| 29 |
$participants = array();
|
| 30 |
$participants_result = db_query("SELECT * FROM {citizenspeak_participants} WHERE nid = %d", $nid);
|
| 31 |
while ($row = db_fetch_array($participants_result)) {
|
| 32 |
$participants[] = $row;
|
| 33 |
}
|
| 34 |
|
| 35 |
switch($edit['format']) {
|
| 36 |
case "dbimport":
|
| 37 |
$report_theme = 'citizenspeak_report_dbimport';
|
| 38 |
$content_type = 'text/tab-separated-values';
|
| 39 |
$ext = 'tab';
|
| 40 |
break;
|
| 41 |
|
| 42 |
case "excel":
|
| 43 |
$report_theme = 'citizenspeak_report_excel';
|
| 44 |
$content_type = 'application/msexcel';
|
| 45 |
$ext = 'xls';
|
| 46 |
break;
|
| 47 |
|
| 48 |
case "text":
|
| 49 |
default:
|
| 50 |
$report_theme = 'citizenspeak_report_text';
|
| 51 |
$content_type = 'text/plain';
|
| 52 |
$ext = 'txt';
|
| 53 |
break;
|
| 54 |
}
|
| 55 |
|
| 56 |
header("Content-Type: $content_type; name=report.$ext");
|
| 57 |
header("Content-Disposition: attachment; filename=report.$ext");
|
| 58 |
print theme($report_theme, $node, $participants);;
|
| 59 |
}
|
| 60 |
}
|
| 61 |
|
| 62 |
/**
|
| 63 |
* Format a collection of participants as a tab separated text file
|
| 64 |
*
|
| 65 |
* @param $node
|
| 66 |
* A CitizenSpeak campaign node
|
| 67 |
*
|
| 68 |
* @param $participants
|
| 69 |
* An array of CitizenSpeak participant row arrays
|
| 70 |
*
|
| 71 |
* @ingroup themeable
|
| 72 |
*/
|
| 73 |
function theme_citizenspeak_report_text($node, $participants) {
|
| 74 |
$output = t("Campaign Report For %title
|
| 75 |
Created %created_date
|
| 76 |
|
| 77 |
Full Name Organization Address City State ZIP Email Phone Fax PS Sent
|
| 78 |
", array(
|
| 79 |
'%title' => $node->title,
|
| 80 |
'%created_date' => format_date($node->created)));
|
| 81 |
|
| 82 |
foreach ($participants as $row) {
|
| 83 |
$output .= join("\t", array($row['name'], $row['organization'], $row['address'], $row['city'], $row['state'], $row['zip'], $row['email'], $row['phone'], $row['fax'], $row['personal_statement'], $row['sent_at']))."\n";
|
| 84 |
}
|
| 85 |
|
| 86 |
return $output;
|
| 87 |
}
|
| 88 |
|
| 89 |
/**
|
| 90 |
* Format a collection of participants as a tab separated text file
|
| 91 |
*
|
| 92 |
* @param $node
|
| 93 |
* A CitizenSpeak campaign node
|
| 94 |
*
|
| 95 |
* @param $participants
|
| 96 |
* An array of CitizenSpeak participant row arrays
|
| 97 |
*
|
| 98 |
* @ingroup themeable
|
| 99 |
*/
|
| 100 |
function theme_citizenspeak_report_excel($node, $participants) {
|
| 101 |
$output = t("Campaign Report For %title
|
| 102 |
Created %created_date
|
| 103 |
|
| 104 |
Full Name Organization Address City State ZIP Email Phone Fax PS Sent
|
| 105 |
", array(
|
| 106 |
'%title' => $node->title,
|
| 107 |
'%created_date' => format_date($node->created)));
|
| 108 |
|
| 109 |
foreach ($participants as $row) {
|
| 110 |
$output .= join("\t", array($row['name'], $row['organization'], $row['address'], $row['city'], $row['state'], '=("'. $row['zip']. '")', $row['email'], $row['phone'], $row['fax'], $row['personal_statement'], $row['sent_at']))."\n";
|
| 111 |
}
|
| 112 |
|
| 113 |
return $output;
|
| 114 |
}
|
| 115 |
|
| 116 |
/**
|
| 117 |
* Format a collection of participants as a tab separated text file
|
| 118 |
*
|
| 119 |
* @param $node
|
| 120 |
* A CitizenSpeak campaign node
|
| 121 |
*
|
| 122 |
* @param $participants
|
| 123 |
* An array of CitizenSpeak participant row arrays
|
| 124 |
*
|
| 125 |
* @ingroup themeable
|
| 126 |
*/
|
| 127 |
function theme_citizenspeak_report_dbimport($node, $participants) {
|
| 128 |
$output = t("Full Name Organization Address City State ZIP Email Phone Fax PS Sent\n");
|
| 129 |
|
| 130 |
foreach ($participants as $row) {
|
| 131 |
$output .= join("\t", array($row['name'], $row['organization'], $row['address'], $row['city'], $row['state'], $row['zip'], $row['email'], $row['phone'], $row['fax'], $row['personal_statement'], $row['sent_at'])). "\n";
|
| 132 |
}
|
| 133 |
|
| 134 |
return $output;
|
| 135 |
}
|
| 136 |
?>
|