Better date formatting; stopped temporal paradoxes; changed column name; fixed CSV issue with Excel

git-svn-id: https://svn.mozilla.org/projects/pto/trunk@59606 4eb1ac78-321c-0410-a911-ec516a8615a5
This commit is contained in:
wlee@mozilla.com 2010-01-12 05:27:59 +00:00
Родитель a1f9e87a91
Коммит 3c6c6e8475
4 изменённых файлов: 31 добавлений и 10 удалений

Просмотреть файл

@ -72,7 +72,7 @@ require_once "./templates/header.php";
Formats:
<ul>
<li class="active" title="You're lookin' at it">Table</li>
<li><a class="format" href="?format=csv" id="format-csv" title="Good for spreadsheet software">CSV</a></li>
<li><a class="format" href="?format=csv" id="format-csv" title="Good for spreadsheet software">CSV / Excel</a></li>
<li><a class="format" href="?format=atom" id="format-atom" title="Good for feed readers">Atom</a></li>
<li><a class="format" href="?format=ical" id="format-ical" title="Good for calendar apps">iCal</a></li>
<li><a class="format" href="?format=json" id="format-json" title="Good for mash-ups">JSON</a></li>
@ -162,7 +162,7 @@ require_once "./templates/header.php";
});
opts.from && (opts.from += "000");
opts.to && (opts.to += "000");
fetch(opts);
fetch("all" in opts ? {} : opts);
} else {
$("#view-month").click(); // Fire "View This Month"
}
@ -203,7 +203,7 @@ require_once "./templates/header.php";
var url = "?format=" + $(this).attr("id").replace(/^format-/, '');
$(this).attr("href", url + (opts ? '&' + opts : ''));
});
window.location.hash = opts;
window.location.hash = (opts == "") ? "all" : opts;
$.getJSON("export.php", $.extend({format: "json"}, options), inject);
}
@ -214,7 +214,7 @@ require_once "./templates/header.php";
function inject(data) {
var preferredOrder = "id|givenName|sn|added|hours|start|end|details".split('|');
var fieldNames = {
id: "ID", givenName: "First name", sn: "Last name", added: "Added on",
id: "ID", givenName: "First name", sn: "Last name", added: "Date filed",
hours: "Hours", start: "Start", end: "End", details: "Details"
};
var presentFields = [];

Просмотреть файл

@ -1,6 +1,6 @@
<?php
function output_json($data) {
$correct_mime = FALSE;
$correct_mime = TRUE;
if (strpos($_SERVER["HTTP_ACCEPT"], "application/json") !== FALSE ||
$_GET["valid_mime"] == '1') {
$correct_mime = TRUE;
@ -44,14 +44,15 @@ function output_csv($data) {
);
$field_name_mapping = array(
"id" => "PTO ID", "givenName" => "First name", "sn" => "Last name",
"added" => "Added", "hours" => "Hours", "details" => "Details",
"added" => "Date filed", "hours" => "Hours", "details" => "Details",
"start" => "Start", "end" => "End"
);
$field_names = array();
foreach ($fields as $field) {
$field_names[] = $field_name_mapping[$field];
}
fputcsv($f, $field_names);
# Excel assumes semicolons to be field separators by default.
fputcsv($f, $field_names, ";");
foreach ($data as $pto) {
$row = array();
foreach ($fields as $field) {
@ -61,7 +62,7 @@ function output_csv($data) {
}
$row[] = $pto[$field];
}
fputcsv($f, $row);
fputcsv($f, $row, ";");
}
fclose($f);
die;

10
pto.inc
Просмотреть файл

@ -20,6 +20,16 @@ function maketime($slashed_date) {
return $t;
}
/* Why yes, this name is confusing enough. */
function parse_date($date_to_parse) {
$p = date_parse($date_to_parse);
return mktime(0, 0, 0, $p["month"], $p["day"], $p["year"]);
}
function reformat_date($date_to_parse, $format, $f="date") {
return $f($format, parse_date($date_to_parse));
}
function email_to_alias($email) {
$alias = explode('@', $email);
return $alias[0];

Просмотреть файл

@ -3,6 +3,7 @@ require_once("config.php");
require_once("pto.inc");
require_once("auth.php");
// Validate the input format for various fields.
$validations = array(
"hours" => '/^[1-9]\d*$|^\d*\.\d$/',
"start" => '/^[01]\d\/[0-3]\d\/\d{4}$/',
@ -23,6 +24,15 @@ if (!empty($failures)) {
require_once "./templates/footer.php";
die;
}
// Dismantle attempts to create a temporal paradox.
if (parse_date($_POST["end"]) < parse_date($_POST["start"])) {
require_once "./templates/header.php";
print "<form><p>Temporal paradox! Your PTO ends before it starts!</p></form>";
require_once "./templates/footer.php";
die;
}
$is_editing = $_POST["edit"] == "1";
$id = isset($_POST["id"]) ? (int)$_POST["id"] : NULL;
@ -124,8 +134,8 @@ $tokens = array(
"%notifier%" => $notifier_name,
"%editor%" => $notifier_name,
"%hours%" => $hours,
"%start%" => $_POST["start"],
"%end%" => $_POST["end"],
"%start%" => reformat_date($_POST["start"], "M j, Y"),
"%end%" => reformat_date($_POST["end"], "M j, Y"),
"%details%" => $_POST["details"]
);