File: //home/awaldron/public_html/archive/protech.php
<?php
include("admin/_functions.php");
function client_list() {
$out = '<option></option>'."\n";
$c = quickRSET("SELECT * FROM clients ORDER BY client_name ASC");
for ($i=0; $i < count($c); $i++) {
$out .= '<option value="'.$c[$i][client_id].'">'.$c[$i][client_name].'</option>'.EOL;
}
return $out;
}
dbconnect();
if (isset($_POST[submit])) {
if ($_POST[act] == 'open') {
quickUPDATE("INSERT INTO time (client_id,time_in,time_desc) VALUES (".$_POST[client_id].",".time().",'".$_POST[time_desc]."')");
header('Location: '.self());
} else if ($_POST[act] == 'close') {
$min15 = 60 * 15;
$t_out = $_POST[time_in];
while ($t_out < time()) { $t_out += $min15; }
quickUPDATE("UPDATE time SET time_out=".$t_out." WHERE time_id=".$_POST[time_id]);
header('Location: '.self());
}
}
echo "<body style=\"font:11px Verdana;\">\n";
// CHECK IF I'M WORKING
$working = quickSQL("SELECT COUNT(time_id) FROM time WHERE time_in > 0 AND time_out = 0");
if ($working == 0) {
echo '<P><h2>Alan is currently not working.</h2>'.EOL;
} else {
$open = quickROW("SELECT B.client_name, A.time_id, A.time_in, A.time_desc FROM time as A, clients as B WHERE A.time_in > 0 AND A.time_out = 0 AND A.client_id=B.client_id ORDER BY time_in DESC LIMIT 0,1");
echo '<P><h2>Alan has been working on '.$open[client_name].' for the past '.ceil((time()-$open[time_in]) / 60).' minutes:</h2>'.EOL;
echo '<P>"'.$open[time_desc].'"'.EOL;
}
// Calculate Hours Earned:
$start_month = 7;
$start_year = 2007;
$this_month = date("n");
$this_year = date("Y");
if ($this_month >= $start_month) {
$tot_months = ($this_year - $start_year) * 12;
$tot_months += ($this_month - $start_month);
$hrs_earned = 40 + (40 * $tot_months);
} else {
$tot_months = (($this_year - $start_year) * 12) - 12;
$tot_months += 5 + $this_month;
$hrs_earned = 40 + (40 * $tot_months);
}
// Calculate Hours Worked:
$hrs_worked = 0;
$hrs = quickRSET("SELECT time_in, time_out FROM time WHERE client_id=1 AND time_in > ".mktime(0,0,0,7,1,2007)." AND time_out > 0 ORDER BY time_in DESC");
for ($i=0; $i < count($hrs); $i++) {
$hrs_worked += ($hrs[$i][time_out] - $hrs[$i][time_in]);
}
$hw = $hrs_worked / 3600;
$mw = ($hrs_worked % 3600) / 60;
if ($mw == 0) $mw = "00";
echo '<br><br><table style="font:11px Verdana;">';
echo '<tr><td align="right">Hours earned since 07/07 : </td><td><b>'.$hrs_earned.'<b></td></tr>';
echo '<tr><td align="right">Hours worked since 07/07 : </td><td><b>'.$hw.'</b></td></tr>';
echo '<tr><td align="right"><b>Hours remaining : </b></td><td><b>'.($hrs_earned - $hw).'</b></td></tr>';
echo '</table>';
// Create month drop-down
$months = array("","January","February","March","April","May","June","July","August","September","October","November","December");
echo "<br><br><br><form name=\"selectmonth\" action=\"protech.php\" method=\"get\" onchange=\"document.selectmonth.submit();\">\n";
echo "<p><b>Select month:</b> <SELECT name=\"ym\">\n";
$n=date("n");
$y=date("Y");
$m = ($n < 10 ? "0".$n : $n);
$ym = $y.$m;
while ($ym >= "200707") {
echo "<option value=\"".$ym."\"".($_GET[ym]==$ym?" SELECTED":"").">".$y." - ".$months[$n]."</option>\n";
if (--$n==0) {
$n = 12;
$y--;
}
$m = ($n < 10 ? "0".$n : $n);
$ym = $y.$m;
}
echo "</SELECT> <input type=\"submit\" value=\"Go\">";
echo "</form>";
$tot_mins = 0;
if (isset($_GET[ym])) {
$y = substr($_GET[ym],0,4);
$m = substr($_GET[ym],4,2);
if (substr($m,0,1) == "0") $m = substr($m,1,1);
$min = mktime(0,0,0,$m,1,$y);
$max = mktime(23,59,59,$m,date('t',$min),$y);
} else {
$min = mktime(0,0,0,date('n'),1,date('Y'));
$max = mktime(23,59,59,date('n'),date('t'),date('Y'));
}
$r = quickRSET("SELECT * FROM time as A, clients as B WHERE A.client_id=1 AND A.client_id=B.client_id AND A.time_in > ".$min." AND A.time_out < ".$max." ORDER BY time_in DESC");
echo "<P><table border=0 cellspacing=1 cellpadding=4 bgcolor=\"#CCCCCC\" style=\"font:11px Verdana;\">\n";
echo "<tr bgcolor=\"#DDDDDD\">\n";
echo "<td><b>ID</b></td><td><b>Client</b></td><td><b>Date</b></td><td><b>TimeIn</b></td><td><b>TimeOut</b></td><td><b>Total</b></td><td><b>Description</b></td>\n";
echo "</tr>\n";
for ($i=0; $i < count($r); $i++) {
$mins = (($r[$i][time_out] - $r[$i][time_in]) / 60);
if ($r[$i][time_out] > 0) $tot_mins += $mins;
$h = floor($mins / 60);
$m = $mins % 60;
if ($m == 0) $m = "00";
echo "<tr bgcolor=\"#".($i%2==0?"EEEEEE":"FFFFFF")."\">\n";
echo "<td align=\"center\">".(count($r)-$i)."</td>\n";
echo "<td>".$r[$i][client_name]."</td>\n";
echo "<td align=\"center\">".date("m/d/y",$r[$i][time_in])."</td>\n";
echo "<td align=\"center\">".date("h:i a",$r[$i][time_in])."</td>\n";
echo "<td align=\"center\">".($r[$i][time_out] > 0 ? date("h:i a",$r[$i][time_out]) : "-")."</td>\n";
echo "<td align=\"center\">".($r[$i][time_out] > 0 ? $h.":".$m : "-")."</td>\n";
echo "<td>".$r[$i][time_desc]."</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
//echo '<br><br>'.quickDUMP('SELECT A.time_id, B.client_name, A.time_in, A.time_out, ((A.time_out - A.time_in) / 60) as time_total, A.time_desc FROM time as A, clients as B WHERE A.client_id=B.client_id ORDER BY time_in DESC');
$th = floor($tot_mins / 60);
$tm = $tot_mins % 60;
if ($tm == 0) $tm = "00";
echo "<br><br><b>Total time spent working on Protech in ".date('F',$min)." : $th hours $tm minutes</b>\n";
?>