initial import
git-svn-id: svn://anubis/tipman@1 ce01c143-e732-0410-ac0e-c064f6e6c7ef
6
.htaccess
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
DirectoryIndex login.php index.html
|
||||||
|
|
||||||
|
<Files *.inc>
|
||||||
|
Order allow,deny
|
||||||
|
Deny from all
|
||||||
|
</Files>
|
165
functions.inc
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
<?php
|
||||||
|
function blank_image()
|
||||||
|
{
|
||||||
|
return '<img class="blank" width="1" height="1" src="images/blank.png" alt="blank" />';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function spacer($w = 1, $h = 1)
|
||||||
|
{
|
||||||
|
return '<img class="blank" width="' . $w . '" height="' . $h . '" src="images/blank.png" alt="blank" />';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function round_table($body, $center = 0)
|
||||||
|
{
|
||||||
|
$bi = blank_image();
|
||||||
|
return <<< EOE
|
||||||
|
<table class="round" cellspacing="0" cellpadding="0" border="0">
|
||||||
|
<tr>
|
||||||
|
<td class="corner"><img src="images/b_w_tl.png" height="5" width="5" alt="tl" /></td>
|
||||||
|
<td class="button_top"> $bi </td>
|
||||||
|
<td class="corner"><img src="images/b_w_tr.png" height="5" width="5" alt="tr" /></td>
|
||||||
|
</tr><tr>
|
||||||
|
<td class="button_left"> $bi </td>
|
||||||
|
<td class="button_middle"
|
||||||
|
EOE
|
||||||
|
. (($center == 0) ? '' : 'style="text-align: center;"') . <<< EOE
|
||||||
|
>
|
||||||
|
$body
|
||||||
|
</td>
|
||||||
|
<td class="button_right"> $bi </td>
|
||||||
|
</tr><tr>
|
||||||
|
<td class="corner"><img src="images/b_w_bl.png" height="5" width="5" alt="bl" /></td>
|
||||||
|
<td class="button_bottom"> $bi </td>
|
||||||
|
<td class="corner"><img src="images/b_w_br.png" height="5" width="5" alt="br" /></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
EOE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* return a footer for the page */
|
||||||
|
function footer()
|
||||||
|
{
|
||||||
|
return round_table('<span class="smaller"> Generated by PHP at ' . date('Y-m-d H:i:s') . '</span>', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* connect to the database, return a handle */
|
||||||
|
function connect_db()
|
||||||
|
{
|
||||||
|
global $MYSQL_SERVER, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DB;
|
||||||
|
$dbc = mysql_connect($MYSQL_SERVER, $MYSQL_USER, $MYSQL_PASSWORD);
|
||||||
|
if (!$dbc)
|
||||||
|
die('Could not connect to MySQL server: ' . mysql_error());
|
||||||
|
if (!mysql_select_db($MYSQL_DB))
|
||||||
|
die('Could not select database: ' . mysql_error());
|
||||||
|
return $dbc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* perform a query on the MySQL database */
|
||||||
|
function do_query($query, $dbc)
|
||||||
|
{
|
||||||
|
$qr = mysql_query($query, $dbc);
|
||||||
|
if (!$qr)
|
||||||
|
die('Invalid query: ' . mysql_error());
|
||||||
|
return $qr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* returns the user's ID */
|
||||||
|
function get_userID($user)
|
||||||
|
{
|
||||||
|
$dbc = connect_db();
|
||||||
|
$qr = do_query("SELECT * FROM `users` WHERE `name` = '$user'", $dbc);
|
||||||
|
$ra = mysql_fetch_assoc($qr);
|
||||||
|
if (!$ra)
|
||||||
|
return -1;
|
||||||
|
return $ra['id'];
|
||||||
|
mysql_close($dbc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Returns a 31-element array of tip values for the given month */
|
||||||
|
function get_tips($month, $year, $userID)
|
||||||
|
{
|
||||||
|
$month = sprintf("%02d", $month);
|
||||||
|
$tips = array();
|
||||||
|
for ($i = 0; $i < 31; $i++)
|
||||||
|
$tips[] = 0.0;
|
||||||
|
$dbc = connect_db();
|
||||||
|
$q = do_query("SELECT * FROM `tips` WHERE `user` = '$userID' AND `date` LIKE '$year-$month%'", $dbc);
|
||||||
|
while ($ra = mysql_fetch_assoc($q))
|
||||||
|
{
|
||||||
|
$dt = substr($ra['date'], 8, 2);
|
||||||
|
$tips[$dt - 1] = $ra['amount'];
|
||||||
|
}
|
||||||
|
mysql_free_result($q);
|
||||||
|
mysql_close($dbc);
|
||||||
|
return $tips;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Returns an assoc-array of check values
|
||||||
|
* (hours1, amount1, hours2, amount2) for the given month
|
||||||
|
*/
|
||||||
|
function get_checks($month, $year, $userID)
|
||||||
|
{
|
||||||
|
$month = sprintf("%02d", $month);
|
||||||
|
if (strlen($month) < 2)
|
||||||
|
$month = '0' . $month;
|
||||||
|
$checks = array();
|
||||||
|
$dbc = connect_db();
|
||||||
|
$q = do_query("SELECT * FROM `checks` WHERE `user` = '$userID' AND `date` LIKE '$year-$month%'", $dbc);
|
||||||
|
$dim = date('t', mktime(0, 0, 0, $month, 1, $year));
|
||||||
|
while ($ra = mysql_fetch_assoc($q))
|
||||||
|
{
|
||||||
|
$dt = substr($ra['date'], 8, 2);
|
||||||
|
if ($dt == 15)
|
||||||
|
{
|
||||||
|
$checks['hours1'] = $ra['hours'];
|
||||||
|
$checks['amount1'] = $ra['amount'];
|
||||||
|
}
|
||||||
|
elseif ($dt == $dim)
|
||||||
|
{
|
||||||
|
$checks['hours2'] = $ra['hours'];
|
||||||
|
$checks['amount2'] = $ra['amount'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mysql_free_result($q);
|
||||||
|
mysql_close($dbc);
|
||||||
|
return $checks;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Return a string for the previous month */
|
||||||
|
function get_back_month($month)
|
||||||
|
{
|
||||||
|
$mth = substr($month, 0, 2);
|
||||||
|
$yr = substr($month, 2, 4);
|
||||||
|
$mth = (($mth + 10) % 12) + 1;
|
||||||
|
if ($mth == 12)
|
||||||
|
$yr--;
|
||||||
|
if (strlen($mth) < 2)
|
||||||
|
$mth = "0$mth";
|
||||||
|
return $mth . $yr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Return a string for the next month */
|
||||||
|
function get_next_month($month)
|
||||||
|
{
|
||||||
|
$mth = substr($month, 0, 2);
|
||||||
|
$yr = substr($month, 2, 4);
|
||||||
|
$mth = ($mth % 12) + 1;
|
||||||
|
if ($mth == 1)
|
||||||
|
$yr++;
|
||||||
|
if (strlen($mth) < 2)
|
||||||
|
$mth = "0$mth";
|
||||||
|
return $mth . $yr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
111
functions.js
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
|
||||||
|
var show_tips_array = new Array('show_tips01', 'show_tips02', 'show_tips03', 'nav_tips0', 'nav_tips1', 'nav_tips2', 'nav_tips3', 'nav_tips4');
|
||||||
|
var show_stats_array = new Array('show_stats01', 'show_stats02', 'show_stats03', 'show_stats04', 'nav_stats0', 'nav_stats1', 'nav_stats2', 'nav_stats3', 'nav_stats4');
|
||||||
|
|
||||||
|
var nav_month_vals = new Array('nav_month0', 'nav_month1', 'nav_month2', 'nav_month3', 'nav_month4');
|
||||||
|
var nav_links = new Array('nav_link0', 'nav_link1', 'nav_link2', 'nav_link3', 'nav_link4');
|
||||||
|
|
||||||
|
var month_names = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
|
||||||
|
|
||||||
|
function showTips()
|
||||||
|
{
|
||||||
|
var a = document.getElementById("calendar");
|
||||||
|
a.style.display = 'block';
|
||||||
|
a = document.getElementById("no-calendar");
|
||||||
|
a.style.display = 'none';
|
||||||
|
for (var i = 0; i < show_tips_array.length; i++)
|
||||||
|
document.getElementById(show_tips_array[i]).value = "1";
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideTips()
|
||||||
|
{
|
||||||
|
var a = document.getElementById("calendar");
|
||||||
|
a.style.display = 'none';
|
||||||
|
a = document.getElementById("no-calendar");
|
||||||
|
a.style.display = 'block';
|
||||||
|
for (var i = 0; i < show_tips_array.length; i++)
|
||||||
|
document.getElementById(show_tips_array[i]).value = "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
function showStats()
|
||||||
|
{
|
||||||
|
var a = document.getElementById("stats");
|
||||||
|
a.style.display = 'block';
|
||||||
|
a = document.getElementById("no-stats");
|
||||||
|
a.style.display = 'none';
|
||||||
|
for (var i = 0; i < show_stats_array.length; i++)
|
||||||
|
document.getElementById(show_stats_array[i]).value = "1";
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideStats()
|
||||||
|
{
|
||||||
|
var a = document.getElementById("stats");
|
||||||
|
a.style.display = 'none';
|
||||||
|
a = document.getElementById("no-stats");
|
||||||
|
a.style.display = 'block';
|
||||||
|
for (var i = 0; i < show_stats_array.length; i++)
|
||||||
|
document.getElementById(show_stats_array[i]).value = "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
function nav_up()
|
||||||
|
{
|
||||||
|
var navFirstMth = new String(navFirstMonth);
|
||||||
|
var theMonth = navFirstMth.substring(0,2);
|
||||||
|
var theYear = navFirstMth.substring(2,6);
|
||||||
|
theMonth--;
|
||||||
|
if (theMonth == 0)
|
||||||
|
{
|
||||||
|
theMonth = 12;
|
||||||
|
theYear--;
|
||||||
|
}
|
||||||
|
var newMonth = new String(theMonth);
|
||||||
|
if (newMonth.length < 2)
|
||||||
|
newMonth = "0" + newMonth;
|
||||||
|
navFirstMonth = newMonth.concat(theYear);
|
||||||
|
navIndex++;
|
||||||
|
regen_navbar();
|
||||||
|
}
|
||||||
|
|
||||||
|
function nav_down()
|
||||||
|
{
|
||||||
|
var navFirstMth = new String(navFirstMonth);
|
||||||
|
var theMonth = navFirstMth.substring(0,2);
|
||||||
|
var theYear = navFirstMth.substring(2,6);
|
||||||
|
theMonth++;
|
||||||
|
if (theMonth == 13)
|
||||||
|
{
|
||||||
|
theMonth = 1;
|
||||||
|
theYear++;
|
||||||
|
}
|
||||||
|
var newMonth = new String(theMonth);
|
||||||
|
if (newMonth.length < 2)
|
||||||
|
newMonth = "0" + newMonth;
|
||||||
|
navFirstMonth = newMonth.concat(theYear);
|
||||||
|
navIndex--;
|
||||||
|
regen_navbar();
|
||||||
|
}
|
||||||
|
|
||||||
|
function regen_navbar()
|
||||||
|
{
|
||||||
|
var theMonth = navFirstMonth.substring(0,2);
|
||||||
|
var theYear = navFirstMonth.substring(2,6);
|
||||||
|
for (var i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
theMonth = new String(theMonth);
|
||||||
|
if (theMonth.length < 2)
|
||||||
|
theMonth = "0" + theMonth;
|
||||||
|
var m = document.getElementById(nav_month_vals[i]);
|
||||||
|
m.value = theMonth.concat(theYear);
|
||||||
|
m = document.getElementById(nav_links[i]);
|
||||||
|
if (i == navIndex)
|
||||||
|
m.innerHTML = '<b>' + month_names[theMonth - 1] + ", " + theYear + '</b';
|
||||||
|
else
|
||||||
|
m.innerHTML = month_names[theMonth - 1] + ", " + theYear;
|
||||||
|
theMonth++;
|
||||||
|
if (theMonth == 13)
|
||||||
|
{
|
||||||
|
theMonth = 1;
|
||||||
|
theYear++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
images/b_w_bl.png
Normal file
After Width: | Height: | Size: 272 B |
BIN
images/b_w_br.png
Normal file
After Width: | Height: | Size: 272 B |
BIN
images/b_w_tl.png
Normal file
After Width: | Height: | Size: 208 B |
BIN
images/b_w_tr.png
Normal file
After Width: | Height: | Size: 272 B |
BIN
images/blank.png
Normal file
After Width: | Height: | Size: 172 B |
BIN
images/down_arrow.png
Normal file
After Width: | Height: | Size: 258 B |
BIN
images/left_arrow.png
Normal file
After Width: | Height: | Size: 191 B |
BIN
images/red.png
Normal file
After Width: | Height: | Size: 150 B |
BIN
images/right_arrow.png
Normal file
After Width: | Height: | Size: 191 B |
BIN
images/tipman_big.png
Normal file
After Width: | Height: | Size: 77 KiB |
BIN
images/tipman_small.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
images/up_arrow.png
Normal file
After Width: | Height: | Size: 257 B |
81
login.php
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
include("vars.inc");
|
||||||
|
include("functions.inc");
|
||||||
|
session_start();
|
||||||
|
if (isset($_SESSION['user']))
|
||||||
|
{
|
||||||
|
unset($_SESSION['user']);
|
||||||
|
}
|
||||||
|
if ( $_SERVER['REQUEST_METHOD'] == 'POST' &&
|
||||||
|
isset($_POST['user']) &&
|
||||||
|
isset($_POST['pass']) )
|
||||||
|
{
|
||||||
|
$mc = mysql_connect($MYSQL_SERVER, $MYSQL_USER, $MYSQL_PASSWORD);
|
||||||
|
if (!$mc)
|
||||||
|
die("Could not connect: " . mysql_error());
|
||||||
|
if (!mysql_select_db($MYSQL_DB, $mc))
|
||||||
|
die("Could not select database: " . mysql_error());
|
||||||
|
$mq = mysql_query("SELECT `password` FROM `users` WHERE `name` = '$_POST[user]'", $mc);
|
||||||
|
if (!$mq)
|
||||||
|
die("Query execution error: " . mysql_error());
|
||||||
|
$mr = mysql_fetch_assoc($mq);
|
||||||
|
if ($mr['password'] === $_POST['pass'])
|
||||||
|
{
|
||||||
|
$_SESSION['user'] = $_POST['user'];
|
||||||
|
unset($_SESSION['month']);
|
||||||
|
unset($_SESSION['year']);
|
||||||
|
header("Location: $MY_SERVER/main.php");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$failed_login = 1;
|
||||||
|
}
|
||||||
|
mysql_close($mc);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title></title>
|
||||||
|
<link rel="stylesheet" href="objects.css" />
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
margin: 1em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div style="margin-left: auto; margin-right: auto; width: 50%;">
|
||||||
|
<?php
|
||||||
|
echo round_table( <<< EOF
|
||||||
|
<b>Welcome to $APP_TITLE!</b>
|
||||||
|
EOF
|
||||||
|
, 1
|
||||||
|
);
|
||||||
|
echo '<br />';
|
||||||
|
echo round_table( <<< EOF
|
||||||
|
<form action="login.php" method="post">
|
||||||
|
<p>
|
||||||
|
EOF
|
||||||
|
. (isset($failed_login) ? '<span style="color: red;">Invalid login!</span><br /><br />' : '') . <<< EOF
|
||||||
|
User name: <input type="text" name="user" value="krissy" />
|
||||||
|
<br /><br />
|
||||||
|
Password: <input type="password" name="pass" />
|
||||||
|
<br /><br />
|
||||||
|
<input type="submit" value="Login" /> <input type="reset" />
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
EOF
|
||||||
|
, 1
|
||||||
|
);
|
||||||
|
|
||||||
|
?> </div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
80
main.css
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
body
|
||||||
|
{
|
||||||
|
margin: 0px;
|
||||||
|
margin-left: 12em;
|
||||||
|
padding: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.nav
|
||||||
|
{
|
||||||
|
position: absolute;
|
||||||
|
top: 1em;
|
||||||
|
left: 1em;
|
||||||
|
width: 11em;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.cal
|
||||||
|
{
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
border-style: outset;
|
||||||
|
border-width: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.cal
|
||||||
|
{
|
||||||
|
margin: 0px;
|
||||||
|
padding: 2px;
|
||||||
|
padding-bottom: 2px;
|
||||||
|
border-style: inset;
|
||||||
|
border-width: 1px;
|
||||||
|
font-size: smaller;
|
||||||
|
font-weight: bold;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.stat
|
||||||
|
{
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.statbar
|
||||||
|
{
|
||||||
|
padding-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.stat
|
||||||
|
{
|
||||||
|
text-align: center;
|
||||||
|
font-size: smaller;
|
||||||
|
width: 35;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hideable
|
||||||
|
{
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 1px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.switch
|
||||||
|
{
|
||||||
|
text-decoration: none;
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.switch:hover { color: #666; }
|
||||||
|
|
||||||
|
a.nav_link
|
||||||
|
{
|
||||||
|
display: block;
|
||||||
|
text-decoration: none;
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.nav_link:hover
|
||||||
|
{
|
||||||
|
color: #666;
|
||||||
|
}
|
378
main.php
Normal file
@ -0,0 +1,378 @@
|
|||||||
|
<?php
|
||||||
|
include("vars.inc");
|
||||||
|
include("functions.inc");
|
||||||
|
session_start();
|
||||||
|
if (!isset($_SESSION['user'])) /* disallow access unless authenticated */
|
||||||
|
{
|
||||||
|
header("Location: $MY_SERVER/login.php");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Draw month bar on left
|
||||||
|
* $whichOne : 0-($captions - 1) index of selected one
|
||||||
|
* $showTips : initial value of calendar's visibility
|
||||||
|
*/
|
||||||
|
function draw_nav_bar($whichOne, $showTips, $showStats)
|
||||||
|
{
|
||||||
|
global $userID, $MY_SERVER;
|
||||||
|
$month_val = $_SESSION['month'] . $_SESSION['year'];
|
||||||
|
for ($i = 0; $i < $whichOne; $i++)
|
||||||
|
$month_val = get_back_month($month_val);
|
||||||
|
echo '<div class="nav">';
|
||||||
|
echo '<div style="margin-left: auto; margin-right: auto; width: 40px;">';
|
||||||
|
echo round_table('<a href="javascript:nav_up();"><img style="border-style: none; margin: 0px; padding: 0px;" src="images/up_arrow.png" alt="up" /></a>',
|
||||||
|
1) . '</div>';
|
||||||
|
echo spacer(1, 10);
|
||||||
|
for ($i = 0; $i < 5; $i++)
|
||||||
|
{
|
||||||
|
$month_cap = date('F', mktime(1, 1, 1, substr($month_val, 0, 2))) .
|
||||||
|
', ' . substr($month_val, 2, 4);
|
||||||
|
echo round_table(
|
||||||
|
'<form id="nav' . $i . '" action="' . $_SERVER['PHP_SELF'] . '" method="post" >' .
|
||||||
|
'<input type="hidden" name="action" value="change_month" />' .
|
||||||
|
'<input type="hidden" name="nav_month" value="' . $i . '" />' .
|
||||||
|
'<input type="hidden" id="nav_month' . $i .
|
||||||
|
'" name="new_month" value="' . $month_val .
|
||||||
|
'" />' .
|
||||||
|
'<input type="hidden" id="nav_tips' . $i . '" name="show_tips" value="' . $showTips . '" />' .
|
||||||
|
'<input type="hidden" id="nav_stats' . $i . '" name="show_stats" value="' . $showStats . '" />' .
|
||||||
|
'<a id="nav_link' . $i . '" class="nav_link" href="javascript:document.getElementById(\'nav' . $i . '\').submit();">' .
|
||||||
|
(($i == $whichOne) ? "<b>$month_cap</b>" : $month_cap) .
|
||||||
|
'</a>' .
|
||||||
|
'</form>',
|
||||||
|
1);
|
||||||
|
echo spacer(1, 10);
|
||||||
|
$month_val = get_next_month($month_val);
|
||||||
|
}
|
||||||
|
echo '<div style="margin-left: auto; margin-right: auto; width: 40px;">';
|
||||||
|
echo round_table('<a href="javascript:nav_down();"><img style="border-style: none; margin: 0px; padding: 0px;" src="images/down_arrow.png" alt="up" /></a>', 1) . '</div>';
|
||||||
|
###################
|
||||||
|
# Show year total #
|
||||||
|
###################
|
||||||
|
$year_total = 0.0;
|
||||||
|
for ($i = 1; $i < 13; $i++)
|
||||||
|
{
|
||||||
|
$tips = get_tips($i, $_SESSION['year'], $userID);
|
||||||
|
for ($j = 0; $j < 31; $j++)
|
||||||
|
$year_total += $tips[$j];
|
||||||
|
$checks = get_checks($i, $_SESSION['year'], $userID);
|
||||||
|
$year_total += $checks['amount1'];
|
||||||
|
$year_total += $checks['amount2'];
|
||||||
|
}
|
||||||
|
echo spacer(1,20);
|
||||||
|
echo '<div style="margin-left: auto; margin-right: auto; width: 8em;">' .
|
||||||
|
round_table($_SESSION['year'] . ' total: $' . $year_total, 1) . '</div>';
|
||||||
|
echo spacer(1, 30);
|
||||||
|
echo '<div style="margin-left: auto; margin-right: auto; width: 6em;">' . round_table('<a class="nav_link" href="' . $MY_SERVER . '/login.php">Logout</a>', 1) . '</div>';
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Returns calendar HTML */
|
||||||
|
function calendar($month, $year, $tipVals, $showStats)
|
||||||
|
{
|
||||||
|
$day_captions = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
|
||||||
|
$dateStamp = mktime(0, 0, 0, $month, 1, $year);
|
||||||
|
$dow = date('w', $dateStamp); /* 0-6 */
|
||||||
|
$ret = '<hr /><br /><form action="' . $_SESSION['PHP_SELF'] . '" method="post">' .
|
||||||
|
'<input type="hidden" name="show_tips" value="1" />' .
|
||||||
|
'<input id="show_stats04" type="hidden" name="show_stats" value="' . $showStats . '" />' .
|
||||||
|
'<input type="hidden" name="action" value="save_tips" />' .
|
||||||
|
'<input type="hidden" name="month" value="' . $_SESSION['month'] . '" />' .
|
||||||
|
'<input type="hidden" name="year" value="' . $_SESSION['year'] . '" />' .
|
||||||
|
'<table class="cal" cellpadding="0" cellspacing="0"><tr>';
|
||||||
|
for ($i = 0; $i < 7; $i++)
|
||||||
|
$ret .= '<td class="cal">' . $day_captions[$i] . '</td>';
|
||||||
|
$ret .= '</tr><tr>';
|
||||||
|
for($i = 0; $i < $dow; $i++)
|
||||||
|
$ret .= '<td class="cal"> </td>'; /* pad beginning of month */
|
||||||
|
$col = $dow;
|
||||||
|
$dim = date('t', $dateStamp);
|
||||||
|
for ($i = 0; $i < $dim; $i++)
|
||||||
|
{
|
||||||
|
if ($tipVals[$i] == 0)
|
||||||
|
$tipVals[$i] = '';
|
||||||
|
$io = $i + 1;
|
||||||
|
if ($col == 0)
|
||||||
|
$ret .= '<tr>';
|
||||||
|
$ret .= <<< EOE
|
||||||
|
<td class="cal">$io<br />
|
||||||
|
<input type="text" name="tip$i" value="$tipVals[$i]" size="5" />
|
||||||
|
</td>
|
||||||
|
EOE;
|
||||||
|
$col++;
|
||||||
|
if ($col == 7)
|
||||||
|
{
|
||||||
|
$ret .= "</tr>\n<tr>";
|
||||||
|
$col = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($col > 0)
|
||||||
|
{
|
||||||
|
for (; $col < 7; $col++)
|
||||||
|
$ret .= '<td class="cal"> </td>';
|
||||||
|
$ret .= '</tr>';
|
||||||
|
}
|
||||||
|
$ret .= '</table><br /><div style="text-align: center;"><input type="submit" value="Save Tips" /> <input type="reset" value="Clear Changes" /></div></form>';
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Returns statistics HTML */
|
||||||
|
function stats($month, $year, $tipVals)
|
||||||
|
{
|
||||||
|
$MAX_HEIGHT = 100;
|
||||||
|
$day_captions = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
|
||||||
|
$dayCounts = array();
|
||||||
|
$tipTotals = array();
|
||||||
|
for ($i = 0; $i < 7; $i++)
|
||||||
|
{
|
||||||
|
$dayCounts[] = 0;
|
||||||
|
$tipTotals[] = 0.0;
|
||||||
|
}
|
||||||
|
$dateStamp = mktime(0, 0, 0, $month, 1, $year);
|
||||||
|
$dow = date('w', $dateStamp); /* 0-6 */
|
||||||
|
for ($i = 0; $i < 31; $i++)
|
||||||
|
{
|
||||||
|
if (isset($tipVals[$i]))
|
||||||
|
{
|
||||||
|
$dayCounts[$dow]++;
|
||||||
|
$tipTotals[$dow] += $tipVals[$i];
|
||||||
|
}
|
||||||
|
$dow = ($dow + 1) % 7;
|
||||||
|
}
|
||||||
|
$tipAverages = array();
|
||||||
|
for ($i = 0; $i < 7; $i++)
|
||||||
|
$tipAverages[$i] = $tipTotals[$i] / $dayCounts[$dow];
|
||||||
|
$max = $tipAverages[0];
|
||||||
|
if ($max == 0)
|
||||||
|
$max = 1;
|
||||||
|
for ($i = 0; $i < 7; $i++)
|
||||||
|
if ($tipAverages[$i] > $max)
|
||||||
|
$max = $tipAverages[$i];
|
||||||
|
$ret = '<table class="stat" border="0" cellpadding="0" cellspacing="0"><tr>';
|
||||||
|
$ret .= '<td style="text-align: right; font-size: smaller;" valign="top">$' . ((int) $max) . ' - </td>';
|
||||||
|
for ($i = 0; $i < 7; $i++)
|
||||||
|
$ret .= '<td rowspan="2" class="statbar" valign="bottom"><img src="images/red.png" alt="bar" width="25" height="' .
|
||||||
|
((int)($tipAverages[$i] * $MAX_HEIGHT / $max)) . '" /></td>';
|
||||||
|
$ret .= '</tr><tr><td style="text-align: right; font-size: smaller;" valign="top">$' .
|
||||||
|
((int)($max / 2)) . ' - </td></tr><tr><td style="text-align: right; font-size: smaller;" valign="top">$0 - </td>';
|
||||||
|
for ($i = 0; $i < 7; $i++)
|
||||||
|
$ret .= '<td class="stat">' . $day_captions[$i] . '</td>';
|
||||||
|
$ret .= '</tr></table>';
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialization */
|
||||||
|
if (!isset($_SESSION['year']))
|
||||||
|
$_SESSION['year'] = date('Y');
|
||||||
|
if (!isset($_SESSION['month']))
|
||||||
|
$_SESSION['month'] = date('m');
|
||||||
|
|
||||||
|
|
||||||
|
$userID = get_userID($_SESSION['user']);
|
||||||
|
|
||||||
|
/* Handle POST form input */
|
||||||
|
if ($_POST['action'] == 'change_month')
|
||||||
|
{
|
||||||
|
if (preg_match('/^\d{6}$/', $_POST['new_month']))
|
||||||
|
{
|
||||||
|
$_SESSION['month'] = substr($_POST['new_month'], 0, 2);
|
||||||
|
$_SESSION['year'] = substr($_POST['new_month'], 2, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif ($_POST['action'] == 'save_tips')
|
||||||
|
{
|
||||||
|
$dbc = connect_db();
|
||||||
|
for ($i = 0; $i < 31; $i++)
|
||||||
|
{
|
||||||
|
if (isset($_POST['tip' . $i]))
|
||||||
|
{
|
||||||
|
$val = $_POST['tip' . $i];
|
||||||
|
if (preg_match('/^\d*\.?\d{0,2}$/', $val))
|
||||||
|
{
|
||||||
|
$day = $i + 1;
|
||||||
|
if (strlen($day) < 2)
|
||||||
|
$day = "0$day";
|
||||||
|
do_query("DELETE FROM `tips` WHERE `date` = '$_SESSION[year]-$_SESSION[month]-$day' AND `user` = '$userID'", $dbc);
|
||||||
|
if ($val != 0)
|
||||||
|
do_query("INSERT INTO `tips` VALUES('', $userID, '$_SESSION[year]-$_SESSION[month]-$day', '$val')", $dbc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mysql_close($dbc);
|
||||||
|
}
|
||||||
|
elseif ($_POST['action'] == 'save_checks')
|
||||||
|
{
|
||||||
|
$dbc = connect_db();
|
||||||
|
$pattern = '/^\d*\.?\d{0,2}$/';
|
||||||
|
$h = $_POST['hours1'];
|
||||||
|
$a = $_POST['amount1'];
|
||||||
|
if (preg_match($pattern, $h) && preg_match($pattern, $a))
|
||||||
|
{
|
||||||
|
do_query("DELETE FROM `checks` WHERE `date` = '$_SESSION[year]-$_SESSION[month]-15' AND `user` = '$userID'", $dbc);
|
||||||
|
if ( ($h != 0) || ($a != 0) )
|
||||||
|
do_query("INSERT INTO `checks` VALUES('', '$userID', '$_SESSION[year]-$_SESSION[month]-15', '$h', '$a')", $dbc);
|
||||||
|
}
|
||||||
|
$h = $_POST['hours2'];
|
||||||
|
$a = $_POST['amount2'];
|
||||||
|
if (preg_match($pattern, $h) && preg_match($pattern, $a))
|
||||||
|
{
|
||||||
|
$dim = date('t', mktime(1, 1, 1, $_SESSION['month'], 1, $_SESSION['year']));
|
||||||
|
do_query("DELETE FROM `checks` WHERE `date` = '$_SESSION[year]-$_SESSION[month]-$dim' AND `user` = '$userID'", $dbc);
|
||||||
|
if ( ($h != 0) || ($a != 0) )
|
||||||
|
do_query("INSERT INTO `checks` VALUES('', '$userID', '$_SESSION[year]-$_SESSION[month]-$dim', '$h', '$a')", $dbc);
|
||||||
|
}
|
||||||
|
mysql_close($dbc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set us up some variables for user later on */
|
||||||
|
$thisMonth = date('F', mktime(0, 0, 0, $_SESSION['month']));
|
||||||
|
$thisYear = date('Y', mktime(0, 0, 0, 1, 1, $_SESSION['year']));
|
||||||
|
$nextMonth = sprintf('%02d', (($_SESSION['month'] % 12) + 1)) . (($_SESSION['month'] == 12) ? $thisYear + 1 : $thisYear);
|
||||||
|
$prevMonth = sprintf('%02d', ((($_SESSION['month'] + 10) % 12) + 1)) . (($_SESSION['month'] == 1) ? $thisYear - 1 : $thisYear);
|
||||||
|
$showTips = ( isset($_POST['show_tips']) && ($_POST['show_tips'] == 1) ) ? 1 : 0;
|
||||||
|
$showStats = ( isset($_POST['show_stats']) && ($_POST['show_stats'] == 1) ) ? 1 : 0;
|
||||||
|
$navMonth = $_POST['nav_month'];
|
||||||
|
$navMonth = ( isset($navMonth) && $navMonth >= 0 && $navMonth < 5 ) ? $navMonth : 3;
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title><?php echo $APP_TITLE; ?></title>
|
||||||
|
<link rel="stylesheet" href="objects.css" />
|
||||||
|
<link rel="stylesheet" href="main.css" />
|
||||||
|
<script language="javascript" type="text/javascript" src="functions.js">
|
||||||
|
</script>
|
||||||
|
<script language="javascript" type="text/javascript">
|
||||||
|
<?php
|
||||||
|
$firstNavMonth = $_SESSION['month'] . $_SESSION['year'];
|
||||||
|
for ($i = 0; $i < $navMonth; $i++)
|
||||||
|
$firstNavMonth = get_back_month($firstNavMonth);
|
||||||
|
echo 'var navFirstMonth = new String("' . $firstNavMonth . '");' . "\n";
|
||||||
|
echo 'var navIndex = ' . $navMonth . ';' . "\n";
|
||||||
|
?>
|
||||||
|
</script>
|
||||||
|
<style type="text/css">
|
||||||
|
<?php
|
||||||
|
if ($showTips)
|
||||||
|
echo 'div#no-calendar { display: none; }';
|
||||||
|
else
|
||||||
|
echo 'div#calendar { display: none }';
|
||||||
|
if ($showStats)
|
||||||
|
echo 'div#no-stats { display: none; }';
|
||||||
|
else
|
||||||
|
echo 'div#stats { display: none }';
|
||||||
|
?>
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
/* Draw navigation bar */
|
||||||
|
draw_nav_bar($navMonth, $showTips, $showStats);
|
||||||
|
|
||||||
|
/* Draw title bar */
|
||||||
|
echo round_table( <<< EOE
|
||||||
|
<table width="100%">
|
||||||
|
<tr>
|
||||||
|
<td width="15">
|
||||||
|
<form action="$_SERVER[PHP_SELF]" method="post">
|
||||||
|
<input id="show_tips01" type="hidden" name="show_tips" value="$showTips" />
|
||||||
|
<input id="show_stats01" type="hidden" name="show_stats" value="$showStats" />
|
||||||
|
<input type="hidden" name="nav_month" value="$navMonth" />
|
||||||
|
<input type="hidden" name="action" value="change_month" />
|
||||||
|
<input type="hidden" name="new_month" value="$prevMonth" />
|
||||||
|
<input type="image" src="images/left_arrow.png" alt="backward_month" />
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
<td style="text-align: center;"><b>$thisMonth, $thisYear</b></td>
|
||||||
|
<td width="15">
|
||||||
|
<form action="$_SERVER[PHP_SELF]" method="post">
|
||||||
|
<input id="show_tips02" type="hidden" name="show_tips" value="$showTips" />
|
||||||
|
<input id="show_stats02" type="hidden" name="show_stats" value="$showStats" />
|
||||||
|
<input type="hidden" name="nav_month" value="$navMonth" />
|
||||||
|
<input type="hidden" name="action" value="change_month" />
|
||||||
|
<input type="hidden" name="new_month" value="$nextMonth" />
|
||||||
|
<input type="image" src="images/right_arrow.png" alt="forward_month" />
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
EOE
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
<br />
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/* Draw main body */
|
||||||
|
$tips = get_tips($_SESSION['month'], $_SESSION['year'], $userID);
|
||||||
|
$tip1_total = 0.0;
|
||||||
|
$tip2_total = 0.0;
|
||||||
|
for ($i = 0; $i < 15; $i++)
|
||||||
|
if (isset($tips[$i]))
|
||||||
|
$tip1_total += $tips[$i];
|
||||||
|
for ($i = 15; $i < 31; $i++)
|
||||||
|
if (isset($tips[$i]))
|
||||||
|
$tip2_total += $tips[$i];
|
||||||
|
$checks = get_checks($_SESSION['month'], $_SESSION['year'], $userID);
|
||||||
|
echo round_table( <<< EOE
|
||||||
|
<div id="no-calendar">
|
||||||
|
<span class="smaller"><a class="switch" href="javascript:showTips()">Edit Tips >>></a></span>
|
||||||
|
</div>
|
||||||
|
<div id="calendar">
|
||||||
|
<span class="smaller"><a class="switch" href="javascript:hideTips()"><<< Hide Tips</a></span>
|
||||||
|
<br />
|
||||||
|
EOE
|
||||||
|
. calendar($_SESSION['month'], $_SESSION['year'], $tips, $showStats) . <<< EOE
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
<div id="no-stats">
|
||||||
|
<span class="smaller"><a class="switch" href="javascript:showStats()">Show Stats >>></a></span>
|
||||||
|
</div>
|
||||||
|
<div id="stats">
|
||||||
|
<span class="smaller"><a class="switch" href="javascript:hideStats()"><<< Hide Stats</a></span>
|
||||||
|
<br />
|
||||||
|
EOE
|
||||||
|
. stats($_SESSION['month'], $_SESSION['year'], $tips) . <<< EOE
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
EOE
|
||||||
|
. '<form action="' . $_SESSION['PHP_SELF'] . '" method="post" >' .
|
||||||
|
'<input type="hidden" name="action" value="save_checks" />' .
|
||||||
|
'<b>' . $thisMonth . ' 1 - 15</b><br />' .
|
||||||
|
'<br />Hours: ' .
|
||||||
|
'<input type="text" name="hours1" value="' . $checks['hours1'] . '" size="8" />' .
|
||||||
|
' Check Amount: ' .
|
||||||
|
'<input type="text" name="amount1" value="' . $checks['amount1'] . '" size="8" />' .
|
||||||
|
' Tips: $' . $tip1_total .
|
||||||
|
'<br /><br /><b>' . $thisMonth . ' 16 - ' .
|
||||||
|
date('t', mktime(1, 1, 1, $_SESSION['month'], 1, $_SESSION['year'])) . '</b><br />' .
|
||||||
|
'<br />Hours: ' .
|
||||||
|
'<input type="text" name="hours2" value="' . $checks['hours2'] . '" size="8" />' .
|
||||||
|
' Check Amount: ' .
|
||||||
|
'<input type="text" name="amount2" value="' . $checks['amount2'] . '" size="8" />' .
|
||||||
|
' Tips: $' . $tip2_total .
|
||||||
|
'<br /><br /><input type="submit" value="Save" /> <input type="reset" value="Clear Changes" />' .
|
||||||
|
'<input id="show_tips03" type="hidden" name="show_tips" value="' . $showTips . '" />' .
|
||||||
|
'<input id="show_stats03" type="hidden" name="show_stats" value="' . $showStats . '" />' .
|
||||||
|
'<input type="hidden" name="nav_month" value="' . $navMonth . '" />' .
|
||||||
|
'</form>' .
|
||||||
|
'<hr />' .
|
||||||
|
'<div style="text-align: right;">' .
|
||||||
|
"<b>$thisMonth Total: </b> $" . ($tip1_total + $tip2_total + $checks['amount1'] + $checks['amount2']) .
|
||||||
|
' </div>'
|
||||||
|
,
|
||||||
|
0);
|
||||||
|
echo '<br />';
|
||||||
|
echo footer();
|
||||||
|
?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
21
objects.css
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
form { margin: 0px; }
|
||||||
|
|
||||||
|
table.round
|
||||||
|
{
|
||||||
|
background-color: #ACF;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0px;
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.corner { width: 5px; padding: 0; margin: 0; }
|
||||||
|
td.button_top { border-top-style: solid; border-top-width: 1px; }
|
||||||
|
td.button_left { border-left-style: solid; border-left-width: 1px; }
|
||||||
|
td.button_right { border-right-style: solid; border-right-width: 1px; }
|
||||||
|
td.button_bottom { border-bottom-style: solid; border-bottom-width: 1px; }
|
||||||
|
|
||||||
|
img.blank { border-style: none; margin: 0px; padding: 0px; }
|
||||||
|
|
||||||
|
.smaller { font-size: smaller; }
|
||||||
|
.really-small { font-size: 0.75em; }
|