<?php
//fuction that calculates time spent on project
function date_diff($d1, $d2){
$d1 = (is_string($d1) ? strtotime($d1) : $d1);
$d2 = (is_string($d2) ? strtotime($d2) : $d2);
$diff_secs = abs($d1 - $d2);
$base_year = min(date("Y", $d1), date("Y", $d2));
$diff = mktime(0, 0, $diff_secs, 1, 1, $base_year);
return array(
"years" => date("Y", $diff) - $base_year,
"months_total" => (date("Y", $diff) - $base_year) * 12 + date("n", $diff) - 1,
"months" => date("n", $diff) - 1,
"days_total" => floor($diff_secs / (3600 * 24)),
"days" => date("j", $diff) - 1,
"hours_total" => floor($diff_secs / 3600),
"hours" => date("G", $diff),
"minutes_total" => floor($diff_secs / 60),
"minutes" => (int) date("i", $diff),
"seconds_total" => $diff_secs,
"seconds" => (int) date("s", $diff)
);
}
// function that coverts calculated time into pure hours and minutes format
function m2h($mins) {
if ($mins < 0) {
$min = Abs($mins);
} else {
$min = $mins;
}
$H = Floor($min / 60);
$M = ($min - ($H 60)) / 100;
$hours = $H + $M;
if ($mins < 0) {
$hours = $hours (-1);
}
$expl = explode(".", $hours);
$H = $expl[0];
if (empty($expl[1])) {
$expl[1] = 00;
}
$M = $expl[1];
if (strlen($M) < 2) {
$M = $M . 0;
}
$hours = $H . ":" . $M;
return $hours;
}
$xartist=$POST['artist'];
//sets wheather there is a date range or not and querys appropriatly
if ($xartist==''){
$xartist=$GET['artist'];
}else{
$xartist = $xartist;
}
//retrieves artist and date range if aplicable
$xday=$POST['day'];
$xmonth=$POST['month'];
$xyear=$POST['year'];
$xdate= $xyear."-".$xmonth."-".$xday;
$xday2=$POST['day2'];
$xmonth2=$POST['month2'];
$xyear2=$POST['year2'];
$xdate2= $xyear2."-".$xmonth2."-".$xday2;
//execute query
if ($xdate=='--'){
$query = "SELECT FROM arttracker WHERE artist= '$xartist' ORDER BY date";
}else{
$query = "SELECT FROM arttracker WHERE date BETWEEN '$xdate' and '$xdate2' AND artist = '$xartist' ORDER BY date";
}
$result = mysql_query($query) or die("Error: " . mysql_error());
$num=mysql_num_rows($result);
$i=0;
//loop to display results
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$date=mysql_result($result,$i,"date");
$timein=mysql_result($result,$i,"timein");
$timeout=mysql_result($result,$i,"timeout");
$work=mysql_result($result,$i,"work");
$billing=mysql_result($result,$i,"billing");
$artist=mysql_result($result,$i,"artist");
$comments=mysql_result($result,$i,"comments");
//alternates row color
$color1 = "#cccccc";
$color2 = "#ffffff";
$row_color = ($i % 2) ? $color1 : $color2;
//executes fuction that calculates total time worked
$totaltime = date_diff($timeout, $timein);
$time=($totaltime['minutes_total']);
//converts time worked from total minutes to hours and minutes format(3:33)
$timediff=m2h($time);
//displays rows
echo "<table cellpadding=4 cellspacing=0 bgcolor=$row_color>";
echo "<tr>";
echo "<td align=right width=5%></td>";
echo "<td width=10% class=admininfo>$artist</td>";
echo "<td width=10% class=admininfo>$date</td>";
echo "<td width=10% class=admininfo>$timein</td>";
echo "<td width=10% class=admininfo>$timeout</td>";
echo "<td width=10% class=admininfo>";
echo $timediff;
echo "</td>";
echo "<td width=10% class=admininfo>$work</td>";
echo "<td width=10% class=admininfo>$billing</td>";
echo "<td width=20% class=admininfo>$comments</td>";
echo "<td width=5%></td>";
echo "</tr>";
echo "</table>";
$i++;
}
?>
<fieldset><legend><font size="-1">Total Time</font></legend>
<table cellpadding="0" cellspacing="0">
<tr>
<td height="5"><font size="-1">
<?
//clearly this is where the total time worked would go
?>[/QUOTE]