Hallo,
hab mir soetwas auch mal gecoded.. vielleicht hilft dir mein source etwas:
( Werd das ganze teil mal auf sourceforge stellen... )
<?php
include('classen/db.php');
$db = new dbconnect;
$db->db_connect("work.dp.at", "time", "xxxxx", "xxxxx");
$today=date("d.m.Y H:i:s");
$month=date("m");
$day=date("d");
$year=date("Y");
$week=strftime("%U");
$now=date("U");
$jobdone=false;
$db->query("Select come,gone FROM timer WHERE day='$day' AND year='$year' AND month='$month'",1);
if($db->num_rows(1)>0){
list($com,$gon)=$db->fetch_row(1);
if($gon != 0){
$jobdone=true;
}
$cogo="Geht";
$c=1;
}else{
$cogo="Kommt";
$c=2;
}
if(isset($submit)){
if($c==1){
$db->query("UPDATE timer SET gone='$now' WHERE day='$day' AND month='$month' AND year='$year'");
}elseif($c==2){
$db->query("INSERT INTO timer (come, day, week, month, year) VALUES ('$now','$day','$week','$month','$year')");
}
}
// $c 1 == geht, 2 == kommt //
// Monats stunden
$db->query("Select come,gone FROM timer WHERE year='$year' AND month='$month' AND gone!=''");
if($db->num_rows()>0){
while(list($coming,$going)=$db->fetch_row()){
$time=$going-$coming;
$monthh=$monthh+$time;
}
$monthh=round($monthh/3600,2);
}else{
$monthh=0;
}
// wochen stunden
$db->query("Select come,gone FROM timer WHERE year='$year' AND week='$week' AND gone!=''");
if($db->num_rows()>0){
while(list($coming,$going)=$db->fetch_row()){
$time=$going-$coming;
$weekh=$weekh+$time;
}
$weekh=round($weekh/3600,2);
}else{
$weekh=0;
}
?>
<form method="post" action="timer.php">
<input type="hidden" name="com" value="<?php echo $c; ?>">
<table border="0" cellpadding="10" cellspacing="0" width="400" align="center" bgcolor="#C0C0C0">
<tr>
<td colspan="2" align="center"><?php echo $today; ?><br><br><?php if($jobdone){ echo "<b>Du hast für heute eigentlich schon schluss gemacht!</b><br><br>";}?><input type="submit" name="submit" value="<?php echo $cogo; ?>"></td>
</tr>
<tr>
<td align="center">Arbeitsstunden gesamt in diesen Monat:</td><td><?php echo $monthh; ?></td>
</tr>
<tr>
<td align="center">Arbeitsstunden gesamt in dieser Woche:</td><td><?php echo $weekh; ?></td>
</tr>
</table>
</form>
<h3>Überblick</h3>
<?php
// Netto Arbeitszeit berrechnen:
$feiertage=array("01.01.2001","06.01.2001","16.04.2001","01.05.2001","24.05.2001","04.06.2001","14.06.2001","15.08.2001","26.10.2001","01.11.2001","08.12.2001","25.12.2001","26.12.2001");
//
for($i=1;$i!=13;$i++){
$c=1;
$urlaub=0;
$hours=0;
$tage=array();
$db->query("SELECT sum((gone - come)/3600), count(id) FROM timer WHERE month='$i' AND gone!=''",1);
list($h,$da,)=$db->fetch_row(1);
$result=mysql_query("SELECT day FROM timer WHERE month='$i'");
while(list($z)=mysql_fetch_row($result)){ $tage[]=$z; }
if($da!=0) $durch=round($h/$da,2);
$month=date("F",mktime(0, 0, 0, $i+1, 0, date("Y")));
$monthnr=date("m",mktime(0, 0, 0, $i+1, 0, date("Y")));
$days=date("t",mktime(0, 0, 0, $i+1, 0, date("Y")));
$today=date("d");
while($c!=$days){
$w=date("w",mktime(0, 0, 0, $i, $c, date("Y")));
$dat=date("d.m.Y",mktime(0, 0, 0, $i, $c, date("Y")));
$day=date("d",mktime(0, 0, 0, $i, $c, date("Y")));
if($w!=0 && $w!=6 && !in_array($dat,$feiertage) && !in_array($day,$tage)){
if($i==date("m")){
if($c<=$today) $urlaub++;
}else{
$urlaub++;
}
}
if($w!=0 && $w!=6 && !in_array($dat,$feiertage)) $hours=$hours+7.7;
$c++;
}
if($month=="May") $urlaub=0;
if($da!=0)
echo "<a href="timer.php?mg=$i">".$month."</a> <b>".$h."</b> Stunden ($durch h/Tag bei $da Arbeitstagen), SollStunden: $hours Stunden, Urlaubstage: $urlaub<br>\n";
}
echo "<p><a href="timer.php?jahr=2001">Jahresansicht</a> anzeigen</p>";
if(isset($mg)){
echo "<img src="bild.php?month=$mg">";
}
if(isset($jahr)){
echo "<img src="bild.php?jahr=$jahr">";
}
?>
lg
Ludwig