Navigation Menu

Skip to content

Commit

Permalink
Added multiple lising orders to front page
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Migurski committed May 28, 2011
1 parent 07f4470 commit 56d0cc4
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 20 deletions.
6 changes: 1 addition & 5 deletions client.php
Expand Up @@ -18,12 +18,8 @@
<title><?= $client_info['name'] ?> Client Info</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script src="protovis-r3.2.js" type="text/javascript"></script>
<link rel="stylesheet" href="style.css" type="text/css" media="all">
<script src="client.js" type="text/javascript"></script>
<style type="text/css" title="text/css">
<!--
h1 { font: 18px Georgia; }
-->
</style>
</head>
<body>
<h1><?= $client_info['name'] ?> ($<?= nice_int($client_info['budget']) ?>)</h1>
Expand Down
61 changes: 48 additions & 13 deletions index.php
Expand Up @@ -5,7 +5,9 @@
$dbh = mysql_connect('localhost', 'time', '');
mysql_select_db('timetracking', $dbh);

$client_list = client_list($dbh);
$clients_byname = client_list($dbh, 'by-name');
$clients_bydate = client_list($dbh, 'by-date');
$clients_bysize = client_list($dbh, 'by-size');

mysql_close($dbh);

Expand All @@ -15,25 +17,58 @@
<head>
<title>Stamen Clients</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="style.css" type="text/css" media="all">
<script src="protovis-r3.2.js" type="text/javascript"></script>
<script src="client.js" type="text/javascript"></script>
<style type="text/css" title="text/css">
<!--
h1 { font: 18px Georgia; }
body { font: 18px Georgia; }
div.listing
{
float: left;
width: 16em;
}
-->
</style>
</head>
<body>
<ul>
<? foreach($client_list as $info) { ?>
<li>
<a href="client.php?name=<?= urlencode($info['name']) ?>"><?= $info['name'] ?></a>
<br>
$<?= nice_int($info['budget']) ?>,
ends <?= $info['date'] ?>.
</li>
<? } ?>
</ul>
<h2>Current Projects</h2>

<div class="listing">
<h3>By Name:</h3>
<ul>
<? foreach($clients_byname as $info) { ?>
<li>
<a href="client.php?name=<?= urlencode($info['name']) ?>"><?= $info['name'] ?></a>
</li>
<? } ?>
</ul>
</div>

<div class="listing">
<h3>By End Date:</h3>
<ul>
<? foreach($clients_bydate as $info) { ?>
<li>
<a href="client.php?name=<?= urlencode($info['name']) ?>"><?= $info['name'] ?></a>
<br>
<?= nice_relative_date($info['time']) ?>.
</li>
<? } ?>
</ul>
</div>

<div class="listing">
<h3>By Size:</h3>
<ul>
<? foreach($clients_bysize as $info) { ?>
<li>
<a href="client.php?name=<?= urlencode($info['name']) ?>"><?= $info['name'] ?></a>
<br>
$<?= nice_int($info['budget']) ?>,
<?= nice_days($info['days']) ?> days.
</li>
<? } ?>
</ul>
</div>
</body>
</html>
52 changes: 50 additions & 2 deletions lib.php
Expand Up @@ -93,11 +93,21 @@ function client_people(&$dbh, $name)
return $rows;
}

function client_list(&$dbh)
function client_list(&$dbh, $order)
{
if($order == 'by-date') {
$order = 'ends ASC';

} else if($order == 'by-size') {
$order = 'days DESC';

} else {
$order = 'client ASC';
}

$q = sprintf("SELECT client AS name, ends, days, budget
FROM client_info
ORDER BY client ASC");
ORDER BY {$order}");

$res = mysql_query($q, $dbh);
$rows = array();
Expand Down Expand Up @@ -142,5 +152,43 @@ function nice_int($int)

return $str;
}

function nice_days($val)
{
$str = sprintf('%.1f', $val);
$str = preg_replace('/\.0$/', '', $str);
$str = preg_replace('/\.5$/', '½', $str);
$str = preg_replace('/^0/', '', $str);

return $str;
}

function nice_relative_date($time)
{
$diff = abs($time - time());

if($diff > 45 * 86400) {
$val = round($diff / (30 * 86400));
$unit = 'month';

} elseif($diff > 12 * 86400) {
$val = round($diff / (7 * 86400));
$unit = 'week';

} elseif($diff > 36 * 3600) {
$val = round($diff / 86400);
$unit = 'day';

} else {
return 'Now';
}

$str = sprintf('%d %s%s %s',
$val, $unit,
($val > 1 ? 's' : ''),
($time < time() ? 'ago' : 'from now'));

return $str;
}

?>
2 changes: 2 additions & 0 deletions style.css
@@ -0,0 +1,2 @@
h1, h2 { font: 25px Georgia; }
h3, body { font: 18px Georgia; }

0 comments on commit 56d0cc4

Please sign in to comment.