Revision: 1200
http://mrbs.svn.sourceforge.net/mrbs/?rev=1200&view=rev
Author: cimorrison
Date: 2009-09-23 15:12:05 +0000 (Wed, 23 Sep 2009)
Log Message:
-----------
Added the ability to output reports and summaries as CSV files.
Modified Paths:
--------------
mrbs/trunk/web/lang.en
mrbs/trunk/web/report.php
mrbs/trunk/web/systemdefaults.inc.php
Modified: mrbs/trunk/web/lang.en
===================================================================
--- mrbs/trunk/web/lang.en 2009-09-17 15:25:36 UTC (rev 1199)
+++ mrbs/trunk/web/lang.en 2009-09-23 15:12:05 UTC (rev 1200)
@@ -185,33 +185,37 @@
$vocab["from"] = "From";
// Used in report.php
-$vocab["report_on"] = "Report on Meetings";
-$vocab["report_start"] = "Report start date";
-$vocab["report_end"] = "Report end date";
-$vocab["match_area"] = "Match area";
-$vocab["match_room"] = "Match room";
-$vocab["match_type"] = "Match type";
-$vocab["ctrl_click_type"] = "Use Control-Click to select more than one
type";
-$vocab["match_entry"] = "Match brief description";
-$vocab["match_descr"] = "Match full description";
-$vocab["include"] = "Include";
-$vocab["report_only"] = "Report only";
-$vocab["summary_only"] = "Summary only";
-$vocab["report_and_summary"] = "Report and Summary";
-$vocab["summarize_by"] = "Summarize by";
-$vocab["sum_by_descrip"] = "Brief description";
-$vocab["sum_by_creator"] = "Creator";
-$vocab["entry_found"] = "entry found";
-$vocab["entries_found"] = "entries found";
-$vocab["summary_header"] = "Summary of (Entries) Hours";
-$vocab["summary_header_per"] = "Summary of (Entries) Periods";
-$vocab["total"] = "Total";
-$vocab["submitquery"] = "Run Report";
-$vocab["sort_rep"] = "Sort Report by";
-$vocab["sort_rep_time"] = "Start Date/Time";
-$vocab["rep_dsp"] = "Display in report";
-$vocab["rep_dsp_dur"] = "Duration";
-$vocab["rep_dsp_end"] = "End Time";
+$vocab["report_on"] = "Report on Meetings";
+$vocab["report_start"] = "Report start date";
+$vocab["report_end"] = "Report end date";
+$vocab["match_area"] = "Match area";
+$vocab["match_room"] = "Match room";
+$vocab["match_type"] = "Match type";
+$vocab["ctrl_click_type"] = "Use Control-Click to select more than one
type";
+$vocab["match_entry"] = "Match brief description";
+$vocab["match_descr"] = "Match full description";
+$vocab["include"] = "Include";
+$vocab["report_only"] = "Report only";
+$vocab["summary_only"] = "Summary only";
+$vocab["report_and_summary"] = "Report and Summary";
+$vocab["report_as_csv"] = "Report as CSV";
+$vocab["summary_as_csv"] = "Summary as CSV";
+$vocab["summarize_by"] = "Summarize by";
+$vocab["sum_by_descrip"] = "Brief description";
+$vocab["sum_by_creator"] = "Creator";
+$vocab["entry_found"] = "entry found";
+$vocab["entries_found"] = "entries found";
+$vocab["summary_header"] = "Summary of (Entries) Hours";
+$vocab["summary_header_per"] = "Summary of (Entries) Periods";
+$vocab["entries"] = "entries";
+$vocab["total"] = "Total";
+$vocab["submitquery"] = "Run Report";
+$vocab["sort_rep"] = "Sort Report by";
+$vocab["sort_rep_time"] = "Start Date/Time";
+$vocab["rep_dsp"] = "Display in report";
+$vocab["rep_dsp_dur"] = "Duration";
+$vocab["rep_dsp_end"] = "End Time";
+$vocab["fulldescription_short"] = "Full Description";
// Used in week.php
$vocab["weekbefore"] = "Go To Week Before";
Modified: mrbs/trunk/web/report.php
===================================================================
--- mrbs/trunk/web/report.php 2009-09-17 15:25:36 UTC (rev 1199)
+++ mrbs/trunk/web/report.php 2009-09-23 15:12:05 UTC (rev 1200)
@@ -3,7 +3,14 @@
require_once "defaultincludes.inc";
+// Constant definitions for the value of the summarize parameter. These are
used
+// for bit-wise comparisons. For example summarize=3 means produce both
+// a report and a summary; summaraize=5 means produce a report as a CSV file
+define('REPORT', 01);
+define('SUMMARY', 02);
+define('CSV', 04);
+
function date_time_string($t)
{
global $twentyfourhour_format;
@@ -83,6 +90,62 @@
return $start_date . " - " . $end_date;
}
+// Escape a string for either HTML or CSV output
+function escape($string)
+{
+ global $output_as_csv;
+ if ($output_as_csv)
+ {
+ $string = str_replace('"', '""', $string);
+ }
+ else
+ {
+ $string = mrbs_nl2br(htmlspecialchars($string));
+ }
+ return $string;
+}
+
+// Add $value to a CSV row, escaping the value as well
+// Return the new row
+function csv_row_add_value($row, $value)
+{
+ // if it's not the first entry add a column separator
+ if (!empty($row))
+ {
+ $row .= CSV_COL_SEP;
+ }
+ $row .= '"';
+ $row .= escape($value);
+ $row .= '"';
+ return $row;
+}
+
+// Output the first row (header row) for CSV reports
+function csv_report_header($display)
+{
+ // initialise the row
+ $line = "";
+ // add values, one by one
+ $line = csv_row_add_value($line, get_vocab("area") . ' - ' .
get_vocab("room"));
+ $line = csv_row_add_value($line, get_vocab("namebooker"));
+ if ($display == "d")
+ {
+ $line = csv_row_add_value($line, get_vocab("start_date") . ' - ' .
get_vocab("duration"));
+ }
+ else
+ {
+ $line = csv_row_add_value($line, get_vocab("start_date") . ' - ' .
get_vocab("end_date"));
+ }
+ $line = csv_row_add_value($line, get_vocab("fulldescription_short"));
+ $line = csv_row_add_value($line, get_vocab("type"));
+ $line = csv_row_add_value($line, get_vocab("createdby"));
+ $line = csv_row_add_value($line, get_vocab("lastupdate"));
+ // terminate the row
+ $line .= CSV_ROW_SEP;
+ // output the row
+ echo $line;
+}
+
// Report on one entry. See below for columns in $row[].
// $last_area_room remembers the current area/room.
// $last_date remembers the current date.
@@ -90,20 +153,26 @@
{
global $typel;
global $enable_periods;
+ global $output_as_csv;
+
+ // Initialise the line for CSV reports
+ $line = "";
+
// Display Area/Room, but only when it changes:
- $area_room = htmlspecialchars($row['area_name']) . " - " .
htmlspecialchars($row['room_name']);
+ $area_room = $row['area_name'] . " - " . $row['room_name'];
$date = utf8_strftime("%d-%b-%Y", $row['start_time']);
+
// entries to be sorted on area/room
- echo "<div class=\"div_report\">\n";
+ echo $output_as_csv ? '' : "<div class=\"div_report\">\n";
if( $sortby == "r" )
{
if ($area_room != $last_area_room)
{
- echo "<h2>". get_vocab("room") . ": " . $area_room . "</h2>\n";
+ echo $output_as_csv ? '' : "<h2>". get_vocab("room") . ": " .
escape($area_room) . "</h2>\n";
}
if ($date != $last_date || $area_room != $last_area_room)
{
- echo "<h3>". get_vocab("date") . ": " . $date . "</h3>\n";
+ echo $output_as_csv ? '' : "<h3>". get_vocab("date") . ": " . $date .
"</h3>\n";
$last_date = $date;
}
// remember current area/room that is being processed.
@@ -119,11 +188,11 @@
{
if ($date != $last_date)
{
- echo "<h2>". get_vocab("date") . ": " . $date . "</h2>\n";
+ echo $output_as_csv ? '' : "<h2>". get_vocab("date") . ": " . $date .
"</h2>\n";
}
if ($area_room != $last_area_room || $date != $last_date)
{
- echo "<h3>". get_vocab("room") . ": " . $area_room . "</h3>\n";
+ echo $output_as_csv ? '' : "<h3>". get_vocab("room") . ": " .
escape($area_room) . "</h3>\n";
$last_area_room = $area_room;
}
// remember current date that is being processed.
@@ -134,51 +203,119 @@
$last_date = $date;
}
}
- echo "<div class=\"report_entry_title\">\n";
- echo "<div class=\"report_entry_name\">\n";
- // Brief Description (title), linked to view_entry:
- echo "<a href=\"view_entry.php?id=".$row['entry_id']."\">" .
htmlspecialchars($row['name']) . "</a>\n";
- echo "</div>\n";
+ if ($output_as_csv)
+ {
+ $line = csv_row_add_value($line, $area_room); // for the CSV report put
the area-room name on every line
+ $line = csv_row_add_value($line, $row['name']);
+ }
+ else
+ {
+ echo "<div class=\"report_entry_title\">\n";
- echo "<div class=\"report_entry_when\">\n";
+ echo "<div class=\"report_entry_name\">\n";
+ // Brief Description (title), linked to view_entry:
+ echo "<a href=\"view_entry.php?id=".$row['entry_id']."\">" .
htmlspecialchars($row['name']) . "</a>\n";
+ echo "</div>\n";
+ }
+ echo $output_as_csv ? '' : "<div class=\"report_entry_when\">\n";
+
// what do you want to display duration or end date/time
if( $display == "d" )
{
// Start date/time and duration:
- echo (empty($enable_periods) ?
- describe_span($row['start_time'], $row['end_time']) :
- describe_period_span($row['start_time'], $row['end_time'])) . "\n";
+ $when = (empty($enable_periods) ?
+ describe_span($row['start_time'], $row['end_time']) :
+ describe_period_span($row['start_time'], $row['end_time']));
}
else
{
// Start date/time and End date/time:
- echo (empty($enable_periods) ?
- start_to_end($row['start_time'], $row['end_time']) :
- start_to_end_period($row['start_time'], $row['end_time'])) . "\n";
+ $when = (empty($enable_periods) ?
+ start_to_end($row['start_time'], $row['end_time']) :
+ start_to_end_period($row['start_time'], $row['end_time']));
}
- echo "</div>\n";
- echo "</div>\n";
-
- echo "<table>\n";
- echo "<colgroup>\n";
- echo "<col class=\"col1\">\n";
- echo "<col class=\"col2\">\n";
- echo "</colgroup>\n";
+ if ($output_as_csv)
+ {
+ $line = csv_row_add_value($line, $when);
+ }
+ else
+ {
+ echo "$when\n";
+ echo "</div>\n";
+ echo "</div>\n";
+
+ echo "<table>\n";
+ echo "<colgroup>\n";
+ echo "<col class=\"col1\">\n";
+ echo "<col class=\"col2\">\n";
+ echo "</colgroup>\n";
+ }
// Description:
- echo "<tr><td>" . get_vocab("description") . ":</td><td>" .
- mrbs_nl2br(htmlspecialchars($row['description'])) . "</td></tr>\n";
+ if ($output_as_csv)
+ {
+ $line = csv_row_add_value($line, $row['description']);
+ }
+ else
+ {
+ echo "<tr>\n";
+ echo "<td>" . get_vocab("description") . ":</td>\n";
+ echo "<td>" . escape($row['description']) . "</td>\n";
+ echo "</tr>\n";
+ }
// Entry Type:
$et = empty($typel[$row['type']]) ? "?".$row['type']."?" :
$typel[$row['type']];
- echo "<tr><td>" . get_vocab("type") . ":</td><td>$et</td></tr>\n";
- // Created by and last update timestamp:
- echo "<tr class=\"createdby\"><td>" . get_vocab("createdby") .
":</td><td>" . htmlspecialchars($row['create_by']) . "</td></tr>\n";
- echo "<tr class=\"lastupdate\"><td>" . get_vocab("lastupdate") .
":</td><td>" . date_time_string($row['last_updated']) . "</td></tr>\n";
+ if ($output_as_csv)
+ {
+ $line = csv_row_add_value($line, $et);
+ }
+ else
+ {
+ echo "<tr>\n";
+ echo "<td>" . get_vocab("type") . ":</td>\n";
+ echo "<td>" . escape($et) . "</td>\n";
+ echo "</tr>\n";
+ }
- echo "</table>\n";
- echo "</div>\n\n";
+ // Created by:
+ if ($output_as_csv)
+ {
+ $line = csv_row_add_value($line, $row['create_by']);
+ }
+ else
+ {
+ echo "<tr>\n";
+ echo "<td>" . get_vocab("createdby") . ":</td>\n";
+ echo "<td>" . escape($row['create_by']) . "</td>\n";
+ echo "</tr>\n";
+ }
+
+ // Last updated:
+ if ($output_as_csv)
+ {
+ $line = csv_row_add_value($line, date_time_string($row['last_updated']));
+ }
+ else
+ {
+ echo "<tr>\n";
+ echo "<td>" . get_vocab("lastupdate") . ":</td>\n";
+ echo "<td>" . date_time_string($row['last_updated']) . "</td>\n";
+ echo "</tr>\n";
+ }
+
+ if ($output_as_csv)
+ {
+ // terminate and output the line
+ $line .= CSV_ROW_SEP;
+ echo $line;
+ }
+ else
+ {
+ echo "</table>\n";
+ echo "</div>\n\n";
+ }
}
// Collect summary statistics on one entry. See below for columns in $row[].
@@ -189,10 +326,13 @@
&$room_hash, &$name_hash)
{
global $sumby;
+ global $output_as_csv;
// Use brief description or created by as the name:
- $name = htmlspecialchars($row[($sumby == "d" ? 'name' : 'create_by')]);
- // Area and room separated by break:
- $room = htmlspecialchars($row['area_name']) . "<br>" .
htmlspecialchars($row['room_name']);
+ $name = escape($row[($sumby == "d" ? 'name' : 'create_by')]);
+ // Area and room separated by break (if not CSV):
+ $room = escape($row['area_name']);
+ $room .= ($output_as_csv) ? '/' : "<br>";
+ $room .= escape($row['room_name']);
// Accumulate the number of bookings for this room and name:
@$count[$room][$name]++;
// Accumulate hours used, clipped to report range dates:
@@ -207,12 +347,16 @@
{
global $sumby;
global $periods;
+ global $output_as_csv;
+
$max_periods = count($periods);
// Use brief description or created by as the name:
- $name = htmlspecialchars($row[($sumby == "d" ? 'name' : 'create_by')]);
- // Area and room separated by break:
- $room = htmlspecialchars($row['area_name']) . "<br>" .
htmlspecialchars($row['room_name']);
+ $name = escape($row[($sumby == "d" ? 'name' : 'create_by')]);
+ // Area and room separated by break (if not CSV):
+ $room = escape($row['area_name']);
+ $room .= ($output_as_csv) ? '/' : "<br>";
+ $room .= escape($row['room_name']);
// Accumulate the number of bookings for this room and name:
@$count[$room][$name]++;
// Accumulate hours used, clipped to report range dates:
@@ -226,7 +370,13 @@
// (actually output two cells, so that we can style the counts and hours)
function cell($count, $hours)
{
- echo "<td class=\"count\">($count)</td><td>" . sprintf("%.2f", $hours) .
"</td>\n";
+ global $output_as_csv;
+
+ echo ($output_as_csv) ? CSV_COL_SEP . '"' : "<td class=\"count\">(";
+ echo $count;
+ echo ($output_as_csv) ? '"' . CSV_COL_SEP . '"' : ")</td><td>";
+ echo sprintf("%.2f", $hours);
+ echo ($output_as_csv) ? '"' : "</td>\n";
}
// Output the summary table (a "cross-tab report"). $count and $hours are
@@ -235,6 +385,7 @@
function do_summary(&$count, &$hours, &$room_hash, &$name_hash)
{
global $enable_periods;
+ global $output_as_csv;
// Make a sorted array of area/rooms, and of names, to use for column
// and row indexes. Use the rooms and names hashes built by accumulate().
@@ -254,30 +405,62 @@
$n_rooms = sizeof($rooms);
$n_names = sizeof($names);
- echo "<div id=\"div_summary\">\n";
- echo "<h1>" . (empty($enable_periods) ? get_vocab("summary_header") :
get_vocab("summary_header_per")). "</h1>\n";
- echo "<table>\n";
+ if (!$output_as_csv)
+ {
+ echo "<div id=\"div_summary\">\n";
+ echo "<h1>" . (empty($enable_periods) ? get_vocab("summary_header") :
get_vocab("summary_header_per")). "</h1>\n";
+ echo "<table>\n";
- echo "<thead>\n";
- echo "<tr><th> </th>\n";
+ echo "<thead>\n";
+ echo "<tr>\n";
+ }
+ echo ($output_as_csv) ? '""' . CSV_COL_SEP : "<th> </th>\n";
+
for ($c = 0; $c < $n_rooms; $c++)
{
- echo "<th colspan=\"2\">$rooms[$c]</th>\n";
+ echo ($output_as_csv) ? '"' : "<th colspan=\"2\">";
+ if ($output_as_csv)
+ {
+ echo $rooms[$c] . ' - ' . get_vocab("entries");
+ echo '"' .CSV_COL_SEP . '"';
+ echo $rooms[$c] . ' - ';
+ echo ($enable_periods) ? get_vocab("periods") : get_vocab("hours");
+ }
+ else
+ {
+ echo $rooms[$c];
+ }
+ echo ($output_as_csv) ? '"' . CSV_COL_SEP : "</th>\n";
$col_count_total[$c] = 0;
$col_hours_total[$c] = 0.0;
}
- echo "<th colspan=\"2\"><br>" . get_vocab("total") . "</th></tr>\n";
+ echo ($output_as_csv) ? '"' : "<th colspan=\"2\"><br>";
+ if ($output_as_csv)
+ {
+ echo get_vocab("total") . ' - ' . get_vocab("entries");
+ echo '"' . CSV_COL_SEP . '"';
+ echo get_vocab("total") . ' - ';
+ echo ($enable_periods) ? get_vocab("periods") : get_vocab("hours");
+ }
+ else
+ {
+ echo get_vocab("total");
+ }
+ echo ($output_as_csv) ? '"' : "</th>\n";
+ echo ($output_as_csv) ? CSV_ROW_SEP : "</tr>\n";
$grand_count_total = 0;
$grand_hours_total = 0;
- echo "</thead>\n";
+ echo ($output_as_csv) ? '' : "</thead>\n";
- echo "<tbody>\n";
+ echo ($output_as_csv) ? '' : "<tbody>\n";
for ($r = 0; $r < $n_names; $r++)
{
$row_count_total = 0;
$row_hours_total = 0.0;
$name = $names[$r];
- echo "<tr><td>$name</td>\n";
+ echo ($output_as_csv) ? '"' : "<tr><td>";
+ echo $name;
+ echo ($output_as_csv) ? '"' : "</td>\n";
for ($c = 0; $c < $n_rooms; $c++)
{
$room = $rooms[$c];
@@ -293,22 +476,35 @@
}
else
{
- echo "<td class=\"count\"> </td><td> </td>\n";
+ if ($output_as_csv)
+ {
+ echo CSV_COL_SEP . CSV_COL_SEP;
+ }
+ else
+ {
+ echo "<td class=\"count\"> </td><td> </td>\n";
+ }
}
}
cell($row_count_total, $row_hours_total);
- echo "</tr>\n";
+ echo ($output_as_csv) ? CSV_ROW_SEP : "</tr>\n";
$grand_count_total += $row_count_total;
$grand_hours_total += $row_hours_total;
}
- echo "<tr><td>". get_vocab("total"). "</td>\n";
+ echo ($output_as_csv) ? '"' : "<tr><td>";
+ echo get_vocab("total");
+ echo ($output_as_csv) ? '"' : "</td>\n";
for ($c = 0; $c < $n_rooms; $c++)
{
cell($col_count_total[$c], $col_hours_total[$c]);
}
cell($grand_count_total, $grand_hours_total);
- echo "</tr></tbody></table>\n";
- echo "</div>\n";
+ echo ($output_as_csv) ? CSV_ROW_SEP : "</tr>\n";
+ if (!$output_as_csv)
+ {
+ echo "</tbody></table>\n";
+ echo "</div>\n";
+ }
}
// Get form variables
@@ -346,7 +542,7 @@
// Need to know user name and if they are an admin
$user = getUserName();
-$is_admin = (isset($user) && authGetUserLevel($user)>=2) ;
+$is_admin = (isset($user) && ($user)>=2) ;
//If we dont know the right date then make it up
if (!isset($day) or !isset($month) or !isset($year))
@@ -359,9 +555,24 @@
{
$area = get_default_area();
}
+if (empty($summarize))
+{
+ $summarize = REPORT;
+}
+$output_as_csv = $summarize & CSV;
+
// print the page header
-print_header($day, $month, $year, $area, isset($room) ? $room : "");
+if ($output_as_csv)
+{
+ $filename = ($summarize & REPORT) ? REPORT_FILENAME : SUMMARY_FILENAME;
+ header("Content-type: application/octet-stream");
+ header("Content-Disposition: attachment; filename=\"$filename\"");
+}
+else
+{
+ print_header($day, $month, $year, $area, isset($room) ? $room : "");
+}
if (isset($areamatch))
{
@@ -396,11 +607,7 @@
$To_month = date("m", $To_time);
$To_year = date("Y", $To_time);
}
-// $summarize: 1=report only, 2=summary only, 3=both.
-if (empty($summarize))
-{
- $summarize = 1;
-}
+
// $sumby: d=by brief description, c=by creator.
if (empty($sumby))
{
@@ -418,165 +625,165 @@
}
// Upper part: The form.
-?>
-<div class="screenonly">
+if (!$output_as_csv)
+{
+ ?>
+ <div class="screenonly">
- <form class="form_general" method="get" action="report.php">
- <fieldset>
- <legend><?php echo get_vocab("report_on");?></legend>
+ <form class="form_general" method="get" action="report.php">
+ <fieldset>
+ <legend><?php echo get_vocab("report_on");?></legend>
- <div id="div_report_start">
- <label><?php echo get_vocab("report_start");?>:</label>
- <?php genDateSelector("From_",
- $From_day,
- $From_month,
- $From_year); ?>
+ <div id="div_report_start">
+ <label><?php echo get_vocab("report_start");?>:</label>
+ <?php genDateSelector("From_",
+ $From_day,
+ $From_month,
+ $From_year); ?>
- </div>
+ </div>
- <div id="div_report_end">
- <label><?php echo get_vocab("report_end");?>:</label>
- <?php genDateSelector("To_",
- $To_day,
- $To_month,
- $To_year); ?>
- </div>
+ <div id="div_report_end">
+ <label><?php echo get_vocab("report_end");?>:</label>
+ <?php genDateSelector("To_",
+ $To_day,
+ $To_month,
+ $To_year); ?>
+ </div>
- <div id="div_areamatch">
- <label for="areamatch"><?php echo get_vocab("match_area");?>:</label>
- <input type="text" id="areamatch" name="areamatch" value="<?php echo
$areamatch_default; ?>">
- </div>
+ <div id="div_areamatch">
+ <label for="areamatch"><?php echo get_vocab("match_area");?>:</label>
+ <input type="text" id="areamatch" name="areamatch" value="<?php echo
$areamatch_default; ?>">
+ </div>
- <div id="div_roommatch">
- <label for="roommatch"><?php echo get_vocab("match_room");?>:</label>
- <input type="text" id="roommatch" name="roommatch" value="<?php echo
$roommatch_default; ?>">
- </div>
+ <div id="div_roommatch">
+ <label for="roommatch"><?php echo get_vocab("match_room");?>:</label>
+ <input type="text" id="roommatch" name="roommatch" value="<?php echo
$roommatch_default; ?>">
+ </div>
- <div id="div_typematch">
- <label for="typematch"><?php echo get_vocab("match_type")?>:</label>
- <select id="typematch" name="typematch[]" multiple="multiple" size="5">
- <?php
- foreach ( $typel as $key => $val )
- {
- if (!empty($val) )
+ <div id="div_typematch">
+ <label for="typematch"><?php echo get_vocab("match_type")?>:</label>
+ <select id="typematch" name="typematch[]" multiple="multiple"
size="5">
+ <?php
+ foreach ( $typel as $key => $val )
{
- echo " <option value=\"$key\"" .
- (is_array($typematch_default) && in_array ( $key,
$typematch_default ) ? " selected" : "") .
- ">$val</option>\n";
+ if (!empty($val) )
+ {
+ echo " <option value=\"$key\"" .
+ (is_array($typematch_default) && in_array ( $key,
$typematch_default ) ? " selected" : "") .
+ ">$val</option>\n";
+ }
}
- }
- ?>
- </select>
- <span><?php echo get_vocab("ctrl_click_type") ?></span>
- </div>
+ ?>
+ </select>
+ <span><?php echo get_vocab("ctrl_click_type") ?></span>
+ </div>
- <div id="div_namematch">
- <label for="namematch"><?php echo get_vocab("match_entry");?>:</label>
- <input type="text" id="namematch" name="namematch" value="<?php echo
$namematch_default; ?>">
- </div>
+ <div id="div_namematch">
+ <label for="namematch"><?php echo
get_vocab("match_entry");?>:</label>
+ <input type="text" id="namematch" name="namematch" value="<?php echo
$namematch_default; ?>">
+ </div>
- <div id="div_descrmatch">
- <label for="descrmatch"><?php echo get_vocab("match_descr");?>:</label>
- <input type="text" id="descrmatch" name="descrmatch" value="<?php echo
$descrmatch_default; ?>">
- </div>
+ <div id="div_descrmatch">
+ <label for="descrmatch"><?php echo
get_vocab("match_descr");?>:</label>
+ <input type="text" id="descrmatch" name="descrmatch" value="<?php
echo $descrmatch_default; ?>">
+ </div>
- <div id="div_creatormatch">
- <label for="creatormatch"><?php echo get_vocab("createdby");?>:</label>
- <input type="text" id="creatormatch" name="creatormatch" value="<?php
echo $creatormatch_default; ?>">
- </div>
+ <div id="div_creatormatch">
+ <label for="creatormatch"><?php echo
get_vocab("createdby");?>:</label>
+ <input type="text" id="creatormatch" name="creatormatch"
value="<?php echo $creatormatch_default; ?>">
+ </div>
- <div id="div_summarize">
- <label><?php echo get_vocab("include");?>:</label>
- <div class="group">
- <label>
- <input class="radio" type="radio" name="summarize" value="1"
- <?php
- if ($summarize==1) echo " checked=\"checked\"";
- echo ">" . get_vocab("report_only");
- ?>
- </label>
- <label>
- <input class="radio" type="radio" name="summarize" value="2"
+ <div id="div_summarize">
+ <label><?php echo get_vocab("include");?>:</label>
+ <div class="group">
<?php
- if ($summarize==2) echo " checked=\"checked\"";
- echo ">" . get_vocab("summary_only");
+ // Radio buttons to choose the value of the summarize parameter
+ // Set up an array mapping the button value to the description
+ $buttons = array(REPORT => "report_only",
+ SUMMARY => "summary_only",
+ REPORT+SUMMARY => "report_and_summary",
+ REPORT+CSV => "report_as_csv",
+ SUMMARY+CSV => "summary_as_csv");
+ // Output each radio button
+ foreach ($buttons as $value => $token)
+ {
+ echo "<label>";
+ echo "<input class=\"radio\" type=\"radio\" name=\"summarize\"
value=\"$value\"";
+ if ($summarize == $value) echo " checked=\"checked\"";
+ echo ">" . get_vocab($token);
+ echo "</label>\n";
+ }
?>
- </label>
- <label>
- <input class="radio" type="radio" name="summarize" value="3"
- <?php
- if ($summarize==3) echo " checked=\"checked\"";
- echo ">" . get_vocab("report_and_summary");?>
- </label>
+ </div>
</div>
- </div>
- <div id="div_sortby">
- <label><?php echo get_vocab("sort_rep");?>:</label>
- <div class="group">
- <label>
- <input class="radio" type="radio" name="sortby" value="r"
- <?php
- if ($sortby=="r") echo " checked=\"checked\"";
- echo ">". get_vocab("room");?>
- </label>
- <label>
- <input class="radio" type="radio" name="sortby" value="s"
- <?php
- if ($sortby=="s") echo " checked=\"checked\"";
- echo ">". get_vocab("sort_rep_time");?>
- </label>
+ <div id="div_sortby">
+ <label><?php echo get_vocab("sort_rep");?>:</label>
+ <div class="group">
+ <label>
+ <input class="radio" type="radio" name="sortby" value="r"
+ <?php
+ if ($sortby=="r") echo " checked=\"checked\"";
+ echo ">". get_vocab("room");?>
+ </label>
+ <label>
+ <input class="radio" type="radio" name="sortby" value="s"
+ <?php
+ if ($sortby=="s") echo " checked=\"checked\"";
+ echo ">". get_vocab("sort_rep_time");?>
+ </label>
+ </div>
</div>
- </div>
- <div id="div_display">
- <label><?php echo get_vocab("rep_dsp");?>:</label>
- <div class="group">
- <label>
- <input class="radio" type="radio" name="display" value="d"
- <?php
- if ($display=="d") echo " checked=\"checked\"";
- echo ">". get_vocab("rep_dsp_dur");?>
- </label>
- <label>
- <input class="radio" type="radio" name="display" value="e"
- <?php
- if ($display=="e") echo " checked=\"checked\"";
- echo ">". get_vocab("rep_dsp_end");?>
- </label>
+ <div id="div_display">
+ <label><?php echo get_vocab("rep_dsp");?>:</label>
+ <div class="group">
+ <label>
+ <input class="radio" type="radio" name="display" value="d"
+ <?php
+ if ($display=="d") echo " checked=\"checked\"";
+ echo ">". get_vocab("rep_dsp_dur");?>
+ </label>
+ <label>
+ <input class="radio" type="radio" name="display" value="e"
+ <?php
+ if ($display=="e") echo " checked=\"checked\"";
+ echo ">". get_vocab("rep_dsp_end");?>
+ </label>
+ </div>
</div>
- </div>
- <div id="div_sumby">
- <label><?php echo get_vocab("summarize_by");?>:</label>
- <div class="group">
- <label>
- <input class="radio" type="radio" name="sumby" value="d"
- <?php
- if ($sumby=="d") echo " checked=\"checked\"";
- echo ">" . get_vocab("sum_by_descrip");
- ?>
- </label>
- <label>
- <input class="radio" type="radio" name="sumby" value="c"
- <?php
- if ($sumby=="c") echo " checked=\"checked\"";
- echo ">" . get_vocab("sum_by_creator");
- ?>
- </label>
+ <div id="div_sumby">
+ <label><?php echo get_vocab("summarize_by");?>:</label>
+ <div class="group">
+ <label>
+ <input class="radio" type="radio" name="sumby" value="d"
+ <?php
+ if ($sumby=="d") echo " checked=\"checked\"";
+ echo ">" . get_vocab("sum_by_descrip");
+ ?>
+ </label>
+ <label>
+ <input class="radio" type="radio" name="sumby" value="c"
+ <?php
+ if ($sumby=="c") echo " checked=\"checked\"";
+ echo ">" . get_vocab("sum_by_creator");
+ ?>
+ </label>
+ </div>
</div>
- </div>
- <div id="report_submit">
- <input class="submit" type="submit" value="<?php echo
get_vocab("submitquery") ?>">
- </div>
+ <div id="report_submit">
+ <input class="submit" type="submit" value="<?php echo
get_vocab("submitquery") ?>">
+ </div>
- </fieldset>
- </form>
-</div>
+ </fieldset>
+ </form>
+ </div>
+ <?php
+}
-<?php
-
// Lower part: Results, if called with parameters:
if (isset($areamatch))
{
@@ -698,18 +905,27 @@
{
$last_area_room = "";
$last_date = "";
- echo "<p class=\"report_entries\">" . $nmatch . " "
- . ($nmatch == 1 ? get_vocab("entry_found") : get_vocab("entries_found"))
- . "</p>\n";
+ if (!$output_as_csv)
+ {
+ echo "<p class=\"report_entries\">" . $nmatch . " "
+ . ($nmatch == 1 ? get_vocab("entry_found") : get_vocab("entries_found"))
+ . "</p>\n";
+ }
+
+ // Output the header row for CSV reports
+ if ($output_as_csv && ($summarize & REPORT))
+ {
+ csv_report_header($display);
+ }
for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
{
- if ($summarize & 1)
+ if ($summarize & REPORT)
{
reporton($row, $last_area_room, $last_date, $sortby, $display);
}
- if ($summarize & 2)
+ if ($summarize & SUMMARY)
{
(empty($enable_periods) ?
accumulate($row, $count, $hours, $report_start, $report_end,
@@ -719,13 +935,15 @@
);
}
}
- if ($summarize & 2)
+ if ($summarize & SUMMARY)
{
do_summary($count, $hours, $room_hash, $name_hash);
}
}
}
-require_once "trailer.inc";
-
+if (!$output_as_csv)
+{
+ require_once "trailer.inc";
+}
?>
Modified: mrbs/trunk/web/systemdefaults.inc.php
===================================================================
--- mrbs/trunk/web/systemdefaults.inc.php 2009-09-17 15:25:36 UTC (rev
1199)
+++ mrbs/trunk/web/systemdefaults.inc.php 2009-09-23 15:12:05 UTC (rev
1200)
@@ -657,6 +657,19 @@
/*************
+ * Reports
+ *************/
+
+// Default CSV file names
+define(REPORT_FILENAME, "report.csv");
+define(SUMMARY_FILENAME, "summary.csv");
+
+// CSV format
+define(CSV_ROW_SEP, "\n"); // Separator between rows/records
+define(CSV_COL_SEP, ","); // Separator between columns/fields
+
+
+/*************
* Entry Types
*************/
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits