Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
timerec3public/details.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
502 lines (467 sloc)
19.9 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php session_start(); ?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>timerec | Details</title> | |
<link rel="stylesheet" type="text/css" href="style.css"> | |
<link rel="stylesheet" href="timepickerW.css"> | |
<script src="timepickerW.js"></script> | |
<link rel="shortcut icon" href="favicon.ico"> | |
<script type="text/javascript"> | |
//Diese Funktion fügt eine neue Zeile zum Forumlar hinzu, um neue Zeiten eintragen zu können | |
function add(){ | |
var form = document.getElementById("neu"); | |
var time = document.createElement("input"); | |
var status = document.createElement("select"); | |
var kommt = document.createElement("option"); | |
var geht = document.createElement("option"); | |
var dienst = document.createElement("option"); | |
var leer = document.createTextNode(" "); | |
var note = document.createElement("input"); | |
time.type = "time"; | |
time.pattern = "(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9])"; | |
time.title = "HH:MM"; | |
time.name = "newtime[]"; | |
status.name = "newstatus[]" | |
kommt.value = "kommt"; | |
kommt.innerHTML = "kommt"; | |
geht.value = "geht"; | |
geht.innerHTML = "geht"; | |
dienst.value = "Dienst"; | |
dienst.innerHTML = "Dienst"; | |
note.name = "newnote[]"; | |
note.type = "text"; | |
form.appendChild(time); | |
form.appendChild(leer); | |
form.appendChild(status); | |
status.appendChild(kommt); | |
status.appendChild(geht); | |
status.appendChild(dienst); | |
form.appendChild(leer.cloneNode(true)); | |
form.appendChild(note); | |
form.appendChild(document.createElement("br")); | |
inittimepicker(); | |
} | |
//Diese Funktion ermöglicht das Auf- und Zuklappen der Details | |
function showhide(elementid){ | |
var offen = 'inherit'; | |
var geschlossen = '0px'; | |
if(elementid.style.height==offen){ | |
elementid.style.height=geschlossen; | |
elementid.style.visibility='hidden'; | |
elementid.previousElementSibling.firstElementChild.innerHTML='>'; | |
}else{ | |
elementid.style.height=offen; | |
elementid.style.visibility='visible'; | |
elementid.previousElementSibling.firstElementChild.innerHTML='v'; | |
} | |
} | |
//Diese Funktion verhindert, dass die Details aufgeklappt werden, wenn man in ein Textfeld o.ä. klickt | |
function nix(element){ | |
element.addEventListener('click', function (e){ | |
e.stopPropagation(); | |
}); | |
} | |
document.addEventListener("DOMContentLoaded", function(event) { | |
inittimepicker(); | |
}); | |
</script> | |
</head> | |
<body> | |
<?php | |
//argumente: date | |
//session_start(); //1. zeile | |
if(!$_SESSION['userid']){ | |
session_destroy(); | |
include('login.php'); | |
exit; | |
} | |
if(!$_SESSION['userarray']['admin']){ | |
echo "<h3>keine Rechte, diese Seite einzusehen!</h3>"; | |
exit; | |
} | |
include('dbconnect.php'); | |
$infoarray = $_SESSION['infoarray']; | |
$maID = $infoarray['maID']; | |
$name = $infoarray['nachname'].", ".$infoarray['vorname']; | |
if(!isset($_GET['date'])){ | |
echo "Datum nicht übergeben!"; | |
exit; | |
} | |
$date = $_GET['date']; | |
$year = substr($date, 0, 4); | |
$month = substr($date, 5, 2); | |
//---------------------- | |
//zurück | |
$datum = new DateTime($date); | |
$tagdavor = $datum->modify('-1 day'); | |
$tagdavor = $tagdavor->format('Y-m-d'); | |
$tagdanach = $datum->modify('+2 days'); | |
$tagdanach = $tagdanach->format('Y-m-d'); | |
$datum->modify('-1 day'); //zurücksetzen auf urspünglichen Wert | |
echo "<div id='headline'> | |
<div id='home'> | |
<a href='month.php?y=$year&m=$month'><button><< Tableau</button></a> | |
<a href='index.php?ma=".$infoarray['maID']."'><button><< Menü</button></a> | |
</div> | |
<div id='back'><a href='details.php?date=$tagdavor'><button><<<</button></a></div> | |
Detailansicht am <b>".$datum->format('d.m.Y')."</b> für $name | |
<div id='forward'><a href='details.php?date=$tagdanach'><button>>>></button></a></div> | |
</div>"; | |
//---------------------- | |
//abgeschicktes formular behandeln | |
if (isset($_POST['time']) || isset($_POST['newtime'])){ | |
$erfolg = false; | |
foreach($_POST['time'] as $index=>$row){ | |
//start | |
$dbc->query("start transaction;"); | |
//history insert der alten Daten | |
$query = "insert into zeit_history (zeit_ID, maID, datumzeit, status, note, timestamp, userid) | |
select * from zeit where zeit_ID = $index;"; | |
$dbc->query($query); | |
if($dbc->error){ | |
echo $dbc->error; | |
$dbc->query("rollback;"); | |
exit; | |
} | |
//update ohne userid um zu sehen ob überhaupt Daten geändert wurden | |
$query = "update zeit set datumzeit = concat(date(datumzeit), ' $row:00'), | |
note = '".$_POST['note'][$index]."', | |
status = '".$_POST['status'][$index]."' | |
where zeit_ID = $index;"; | |
$dbc->query($query); | |
if($dbc->error){ | |
echo $dbc->error; | |
$dbc->query("rollback;"); | |
exit; | |
} | |
//delete handle | |
if(in_array($index, $_POST['del'])){ | |
$query = "delete from zeit where zeit_ID = $index;"; | |
$dbc->query($query); | |
if($dbc->error){ | |
echo $dbc->error; | |
$dbc->query("rollback;"); | |
exit; | |
} | |
$query = "update zeit_history set del_by = '".$_SESSION['userid']."' where zeit_ID = $index;"; | |
$dbc->query($query); | |
if($dbc->error){ | |
echo $dbc->error; | |
$dbc->query("rollback;"); | |
exit; | |
} | |
} | |
//check ob daten geändert wurden | |
if($dbc->affected_rows > 0){ | |
//ja: userid nachreichen | |
$query = "update zeit set userid = '".$_SESSION['userid']."' where zeit_ID = $index;"; | |
$dbc->query($query); | |
if($dbc->error){ | |
echo $dbc->error; | |
$dbc->query("rollback;"); | |
exit; | |
} | |
$dbc->query("commit;"); | |
$erfolg = true; | |
}else{ | |
//nein: insert in die history verhindern | |
$dbc->query("rollback;"); | |
} | |
} | |
//neue Zeiten hinterlegen | |
if(isset($_POST['newtime'])){ | |
$newtime = $_POST['newtime']; | |
$newstatus = $_POST['newstatus']; | |
$newnote = $_POST['newnote']; | |
$size = sizeof($newtime); | |
$query = "insert into zeit (maID, datumzeit, status, note, userid) values "; | |
for($i = 0; $i < $size; $i++){ | |
$query .= "($maID, '$date $newtime[$i]', '$newstatus[$i]', '$newnote[$i]', '".$_SESSION['userid']."'), "; | |
} | |
$query = substr($query, 0, -2); | |
$query .= ";"; | |
$dbc->query($query); | |
if($dbc->error){ | |
echo $dbc->error; | |
exit; | |
} | |
$erfolg = true; | |
} | |
if($erfolg){ | |
header("Location: details.php?date=$date&success=true"); | |
exit; | |
}else{ | |
header("Location: details.php?date=$date&success=false"); | |
exit; | |
} | |
} | |
//---------------------- | |
$query = "select * from zeit where date(datumzeit) = '$date' and maID = $maID order by datumzeit asc;"; | |
$result = $dbc->query($query); | |
$getazd = $dbc->query("select * from az_data_copy where maID = '$maID' order by azdID desc, datum_ab desc limit 1;"); | |
$azd = $getazd->fetch_assoc(); | |
$getazt = $dbc->query("select * from az_time where azdID = $azd[azdID];"); | |
foreach($getazt as $aztime){ | |
$azt[$aztime['tag']] = $aztime; | |
} | |
$wochentag = $datum->format('N'); | |
//Handler für special std | |
if($_POST['specialsaldo']){ | |
if($_POST['removespecial']){ | |
$delete = "delete from saldo where sid = $_POST[specialsaldo];"; | |
$dbc->query($delete); | |
if($dbc->error){ | |
echo $dbc->error; | |
exit; | |
} | |
header("Location: details.php?date=$date&delete=true"); | |
exit; | |
} | |
if(!empty($_POST['special']) && !empty($_POST['saldo'])){ | |
$vz = substr($_POST['saldo'],0, 1); | |
$saldomin = substr($_POST['saldo'], 1, (strpos($_POST['saldo'], ':')-1))*60; | |
if($vz == "+"){ | |
$saldomin += substr($_POST['saldo'], -2); | |
}else{ | |
$saldomin = $vz . $saldomin; | |
$saldomin -= substr($_POST['saldo'], -2); | |
} | |
if($_POST['specialsaldo'] <= 1){ | |
$insertsaldo = "insert into saldo values (NULL, '$maID', '$date', '$_POST[special]', '$saldomin');"; | |
}else{ | |
$insertsaldo = "update saldo set special = '$_POST[special]', saldomin = '$saldomin' where sid = '$_POST[specialsaldo]';"; | |
} | |
$dbc->query($insertsaldo); | |
if($dbc->error){ | |
echo $dbc->error; | |
exit; | |
} | |
header("Location: details.php?date=$date&success=true"); | |
exit; | |
} | |
if($_POST['krank']){ | |
$fulldiff = new DateTime("00:00:00 $date"); | |
$pausefulldiff = new DateTime("00:00:00 $date"); | |
foreach($result as $zeit){ | |
if($zeit['status'] == 'kommt'){ | |
$anzahlkommt++; | |
$kommt = new DateTime($zeit['datumzeit']); | |
if($kommt->format('H:i:s') < $azt[$wochentag]['azstart']){ | |
$kommt = new DateTime($azt[$wochentag]['azstart']); | |
} | |
if($anzahlgeht){ | |
$pausediff = $geht->diff($kommt); | |
$pausefulldiff->add($pausediff); | |
} | |
}elseif($zeit['status'] == 'geht'){ | |
$anzahlgeht++; | |
$geht = new DateTime($zeit['datumzeit']); | |
$diff = $kommt->diff($geht); | |
$fulldiff->add($diff); | |
} | |
} | |
if($anzahlkommt == $anzahlgeht){ | |
$gearbeitet = $fulldiff->format('H')*60 + $fulldiff->format('i') + round($fulldiff->format('s')/60); | |
$tagessoll = $azd['wochenarbeit']/count($azt); | |
if($gearbeitet < $tagessoll){ | |
$pauseab = new DateTime($azd['pauseab']); | |
$pauseab = $pauseab->format('H')*60 + $pauseab->format('i'); | |
$azpause = new DateTime($azd['pause']); | |
$azpause = $azpause->format('H')*60 + $azpause->format('i'); | |
$realpause = $pausefulldiff->format('H')*60 + $pausefulldiff->format('i'); | |
$rest = $tagessoll - $gearbeitet; | |
if($gearbeitet >= $pauseab && ($realpause <= 0)){ | |
$rest += $azpause; | |
}elseif($gearbeitet >= $pauseab && ($realpause < $azpause && $realpause > 0)){ | |
$pauserest = $azpause - $realpause; | |
$rest += $pauserest; | |
} | |
$insert = "insert into saldo values (NULL, '$maID', '$date', 'krank nach Hause', $rest);"; | |
$dbc->query($insert); | |
if($dbc->error){ | |
echo $dbc->error; | |
exit; | |
} | |
} | |
}else{ | |
header("Location: details.php?date=$date&success=false&fail=kein Gehen vorhanden!"); | |
exit; | |
} | |
header("Location: details.php?date=$date&success=true"); | |
exit; | |
} | |
if($_POST['startsaldo']){ | |
$dbc->query("delete from saldo where special in('new', 'tozero') and datum = '$date' and maID = '$maID';"); | |
if($dbc->error){ | |
header("Location: details.php?date=$date&success=false&fail=alter Ausgleich konnte nicht entfernt werden"); | |
exit; | |
} | |
if($_POST['removestartsaldo']){ | |
header("Location: details.php?date=$date&delete=true"); | |
exit; | |
} | |
$getsaldo = $dbc->query("select sum(saldomin) from saldo where maID = '$maID' and datum <= '$date'"); | |
$oldsaldo = $getsaldo->fetch_array()[0]; | |
$ausgleich = $oldsaldo < 0 ? abs($oldsaldo) : -1*$oldsaldo; | |
$dbc->query("insert into saldo (maID, datum, special, saldomin) values ('$maID', '$date', 'tozero', '$ausgleich');"); | |
if($dbc->error){ | |
header("Location: details.php?date=$date&success=false&fail=Ausgleich konnte nicht gesetzt werden!"); | |
exit; | |
} | |
$vz = substr($_POST['startsaldo'], 0, 1); | |
$saldoneu = substr($_POST['startsaldo'], 1, (strpos($_POST['startsaldo'], ':')-1))*60; | |
if($vz == '+'){ | |
$saldoneu += substr($_POST['startsaldo'], -2); | |
}else{ | |
$saldoneu = $vz . $saldoneu; | |
$saldoneu -= substr($_POST['startsaldo'], -2); | |
} | |
$dbc->query("insert into saldo (maID, datum, special, saldomin) values ('$maID', '$date', 'new', '$saldoneu');"); | |
if($dbc->error){ | |
header("Location: details.php?date=$date&success=false&fail=neuer Startsaldo konnte nicht eingetragen werden!"); | |
exit; | |
} | |
header("Location: details.php?date=$date&success=true"); | |
exit; | |
} | |
} | |
//---------------------- | |
//SQL Query nach oben verschoben, damit für krank nach Hause Zeiten zur Verarbeitung bereitstehen | |
echo "<div id='korrekturcontainer'>"; | |
if($_GET['success'] === "true"){ | |
echo "<h3 class='light-green'>neue Daten erfolgreich hinterlegt!</h3>"; | |
}elseif($_GET['success'] === "false"){ | |
echo "<h3 class='red'>keine Daten geändert</h3>"; | |
if($_GET['fail']){ | |
echo "<h3 class='red'>$_GET[fail]</h3>"; | |
} | |
} | |
if($_GET['delete'] === "true"){ | |
echo "<h3 class='light-green'>+/- Std. erfolgreich entfernt.</h3>"; | |
} | |
echo "<form action='#' method='post' id='korrektur'>"; | |
foreach($result as $row){ //aufklappbare Zeilen generieren, für jeden Eintrag des Tages eine | |
$hours = substr($row['datumzeit'], 11, 2); | |
$minutes = substr($row['datumzeit'], 14, 2); | |
$seconds = substr($row['datumzeit'], 17, 2); | |
if ($seconds >= 30){ | |
//Sekunden aufrunden | |
$minutes++; | |
if($minutes < 10) $minutes = "0" . $minutes; | |
if($minutes >= 60){ | |
$minutes = "00"; | |
$hours++; | |
if($hours < 10) $hours = "0" . $hours; | |
} | |
} | |
$zeit = $hours . ":" . $minutes; | |
$id = $row['zeit_ID']; | |
$note = $row['note']; | |
echo "<div class='infobox' onclick='showhide(this.nextElementSibling)'> | |
<span>></span>   <div onmouseover='nix(this)'> | |
<input type='time' pattern='(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9])' title='HH:MM' name='time[$id]' value='$zeit'> "; | |
//Pattern ist hier notwendig für Firefox, der kein input type=time oder date kennt | |
if ($row['status'] == 'kommt'){ | |
$kommt = 'selected'; | |
$geht = $dienst = ''; | |
}elseif($row['status'] == 'geht'){ | |
$geht = 'selected'; | |
$kommt = $dienst = ''; | |
}else{ | |
$dienst = 'selected'; | |
$kommt = $geht = ''; | |
} | |
echo "<select name='status[$id]'> | |
<option value='kommt' $kommt>kommt</option> | |
<option value='geht' $geht>geht</option> | |
<option value='dienst' $dienst>Dienst</option> | |
</select> "; | |
echo "<input type='text' name='note[$id]' value='$note'> | |
<label> | |
<input id='delbox$id' class='hackbox' type='checkbox' name='del[]' value='$id'> | |
Löschen?<label for='delbox$id'></label> | |
</label> | |
</div><br> | |
</div> | |
<div> | |
<table> | |
<tr> | |
<th>Aktuelle Metainformation:</th> | |
<th>Verlauf:</th> | |
</tr> | |
<tr> | |
<td>"; | |
$timestamp = new DateTime($row['timestamp']); | |
$textdatum = $timestamp->format("d.m.Y H:i:s"); | |
//letzte Änderung und History einbinden | |
echo "$textdatum<br> | |
".$row['userid']."<br><br> | |
</td> | |
<td> | |
<iframe src='history.php?id=".$row['zeit_ID']."'></iframe> | |
</td> | |
</tr> | |
</table> | |
</div>"; | |
} | |
$getspecialsaldo = $dbc->query("select * from saldo where maID = '$maID' and datum = '$date' and special is not NULL and special not in('new', 'tozero');"); | |
$specialsaldo = $getspecialsaldo->fetch_assoc(); | |
//geholten Saldo in Stunden:Minuten Format wandeln zur Anzeige | |
$vz = $specialsaldo['saldomin'] < 0 ? "-" : "+"; | |
$saldostd = intval(abs($specialsaldo['saldomin']/60)); | |
$saldostd = $saldostd < 10 && $saldostd >= 0 ? "0".$saldostd : $saldostd; | |
$saldomin = abs($specialsaldo['saldomin']%60); | |
$saldomin = $saldomin < 10 && $saldomin >= 0 ? "0".$saldomin : $saldomin; | |
$specialmin = $vz.$saldostd.":".$saldomin; | |
$sid = $specialsaldo['sid'] ? $specialsaldo['sid'] : 1; | |
$getstartsaldo = $dbc->query("select * from saldo where maID = '$maID' and datum = '$date' and special = 'new';"); | |
$startsaldo = $getstartsaldo->fetch_array(); | |
$startsaldovz = $startsaldo['saldomin'] < 0 ? "-" : "+"; | |
$startsaldostd = intval(abs($startsaldo['saldomin']/60)); | |
$startsaldostd = $startsaldostd < 10 && $startsaldostd >= 0 ? "0".$startsaldostd : $startsaldostd; | |
$startsaldomin = abs($startsaldo['saldomin']%60); | |
$startsaldomin = $startsaldomin < 10 && $startsaldomin >= 0 ? "0".$startsaldomin : $startsaldomin; | |
$startsaldotime = $startsaldovz . $startsaldostd . ":" . $startsaldomin; | |
echo "<div id='neu'></div> | |
</form> | |
<br> | |
<button onclick='add()'>Hinzufügen</button> | |
<a href='history.php?del=$date' target='popup' | |
onclick='window.open(\"history.php?del=$date\",\"popup\",\"width=800,height=600\")'><button>Gelöschte Einträge ansehen</button></a> | |
<br> | |
<br> | |
<button form='korrektur' type='submit' onclick='return confirm(\"Sicher?\")'>OK</button> | |
<button onclick='window.location.reload()'>Abbrechen</button> | |
<div id='plusminus'> | |
<h3 class='trenner'>Ausgleichen: +/- Std.</h3> | |
<form id='specialsaldo' action='#' method='post'> | |
<table class='tabelle'> | |
<tr> | |
<td class='rechts'>+/- Std.</td> | |
<input type='hidden' name='specialsaldo' value='$sid'> | |
<td class='links'> ⟶ <input id='special' type='text' name='special' placeholder='Bemerkung' value='$specialsaldo[special]'> <input class='small centered' type='text' name='saldo' title='+HH:MM bzw. -HH:MM' pattern='^[+-]([0-9]{1,3})(:[0-5][0-9])' value='$specialmin'> Std. | |
⟶ <button onclick='return confirm(\"Sicher?\")'>OK</button> oder <button name='removespecial' value='1' onclick='return confirm(\"Wirklich entfernen?\")'>Entfernen</button></td> | |
</tr> | |
<tr> | |
<td class='rechts'>krank nach Hause</td><td class='links'> ⟶ <button name='krank' value='1' id='krank' onclick='return confirm(\"Sicher?\")'>automatisch setzen</button></td> | |
</tr> | |
<tr class='topline'><td colspan='2'></td></tr> | |
< | |
<tr> | |
<td class='rechts'>neuen Gesamt-Saldo setzen</td><td class='links'> ⟶ <input class='small centered' type='text' name='startsaldo' pattern='^[+-]([0-9]{1,3})(:[0-5][0-9])' title='+HH:MM bzw. -HH:MM' value='$startsaldotime'> Std. ⟶ | |
<button onclick='return confirm(\"Sicher?\")'>OK</button> oder | |
<button name='removestartsaldo' value='1' onclick='return confirm(\"Sicher?\")'>entfernen</button> | |
</td> | |
</tr> | |
</table> | |
</form> | |
</div>"; | |
/* echo "<div id='debug'>"; | |
print_r($_POST); | |
echo "</div>"; */ | |
echo "</div>"; | |
?> | |
</body> | |
</html> |