engelsystem/admin/schichtplan.php_old

381 lines
12 KiB
Plaintext
Executable File
Raw Blame History

<?php
$title = "Schichtplan";
$header = "Neue Schichten erfassen";
$submenus = 1;
include ("./inc/header.php");
include ("./inc/funktion_user.php");
if (!IsSet($action)) {
echo "Hallo ".$_SESSION['Nick'].",<br>\n";
echo "hier kannst du Schichten anlegen, &auml;ndern oder l&ouml;schen.<br><br>";
echo "<a href=\"./schichtplan.php?action=new\">Neue Schicht einplanen</a><br><br>\n\n";
?>
<table width="100%" class="border" cellpadding="2" cellspacing="1">
<tr class="contenttopic">
<td>Datum</td>
<td>Raum</td>
<td>Dauer</td>
<td>Beschreibung</td>
<td>&Auml;ndern</td>
</tr>
<?
$sql = "Select * from Schichtplan ORDER BY RID, Date";
$Erg = mysql_query($sql, $con);
$rowcount = mysql_num_rows($Erg);
for ($i=0; $i<$rowcount; $i++){
echo "\t<tr class=\"content\">\n";
echo "\t\t<td>".mysql_result($Erg, $i, "Date")."</td>\n";
$sql2= "Select * from Raeume where RID=\"".mysql_result($Erg, $i, "RID")."\"";
$Erg2 = mysql_query($sql2, $con);
echo "\t\t<td>".mysql_result($Erg2, 0, "Name")."</td>\n";
echo "\t\t<td>".mysql_result($Erg, $i, "Dauer")." Std. </td>\n";
echo "\t\t<td>".mysql_result($Erg, $i, "Name")."</td>\n";
echo "\t\t<td><a href=\"./schichtplan.php?action=change&SID=".mysql_result($Erg, $i, "SID")."\">XXX</a></td>\n";
echo "\t</tr>\n";
}
echo "</table>";
} else {
switch ($action){
case 'new':
?>
Hier kannst du neue Schichten eintragen. Dazu musst du den Anfang und das Ende der Schichten eintragen.
&Uuml;ber die L&auml;nge der Schichten errechnet sich dadurch die Anzahl dieser. Dadurch k&ouml;nnen gleich
mehrere Schichten auf einmal erfasst werden:
<? /* <form action="<? echo basename (getenv ("PATH_INFO")) ; ?>" method="post"> */ ?>
<form action="<? echo $_SERVER['SCRIPT_NAME']; ?>" >
<table>
<tr>
<td align="right">Name:</td>
<td><input type="text" name="SchichtName" size="50" value="Engel Schicht X"></td>
</tr>
<tr>
<td align="right">Month.Jahr:</td>
<td><input type="ext" name="MonthJahr" size="7" value="2003-12"></td>
</tr>
<tr>
<td align="right">Beginn:</td>
<td>Date<input type="text" name="SDatum" size="5" value="27">
Time<input type="text" name="STime" size="5" value="10"></td>
</tr>
<tr>
<td align="right">More then One</td>
<td><input type="checkbox" name="MoreThenOne" value="ON" checked></td>
</tr>
<tr>
<td align="right">End:</td>
<td>Date<input type="text" name="EDatum" size="5" value="29">
Time<input type="text" name="ETime" size="5" value="12"></td>
</tr>
<tr>
<td align="right">L&auml;nge in h:</td>
<td><input type="text" name="len" size="5" value="2"></td>
</tr>
<tr>
<td align="right">Ort:</td>
<td>
<select name="RID">
<?
$sql = "select * from Raeume";
$Erg = mysql_query($sql, $con);
$rowcount = mysql_num_rows($Erg);
for ($i=0; $i<$rowcount; $i++) {
echo " <option value=\"".mysql_result($Erg, $i, "RID")."\">";
echo mysql_result($Erg, $i, "Name")."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right">Nacht-Sonderschichten ein:</td>
<td><input type="checkbox" name="NachtON" value="ON"></td>
</tr>
<tr>
<td align="right">L&auml;nge bei Nacht in h (Time;Time):</td>
<td><input type="text" name="len_night" size="50" value="0;4;8;10;12;14;16;18;20;22;24"></td>
</tr>
</table>
<br>
<input type="hidden" name="OnlyShow" value="ON">
<input type="hidden" name="action" value="newsave">
<input type="submit" value="zeig mal Gabriel!">
</form>
<?
break; // Ende new
case 'newsave':
if (isset($SDatum) && ($len > 0)) {
$lenOrg = $len;
if( $NachtON == "ON" )
{
$lenPos = 0;
$lenArrayDummy = explode( ";", $len_night);
$i = -1;
foreach ( $lenArrayDummy as $Temp )
{
$i++;
if( $i == 0 )
$lenArray[$i] = $Temp;
else
$lenArray[$i] = $Temp- $lenArrayDummy[$i-1];
if( $Temp==$STime )
$lenPos = $i;
}//foreach
$lenPosMax = $i;
}//IF( $NachtON == "ON" )
echo "<table border=\"1\">\n";
echo "<tr>\n";
echo "\t<td valign=\"top\" align=\"center\">Start</td>\n";
echo "\t<td valign=\"top\" align=\"center\">End</td>\n";
echo "\t<td valign=\"top\" align=\"center\">RID</td>\n";
echo "\t<td valign=\"top\" align=\"center\">len</td>\n";
echo "\t<td valign=\"top\" align=\"center\">Beschreibung</td>\n";
echo "\t<td valign=\"top\" align=\"center\">OK?</td>\n";
echo "</tr>\n";
$DateEnd = $SDatum;
$TimeEnd = $STime;
do {
// define Start time
$Date = $DateEnd;
$Time = $TimeEnd;
$_DateS = $MonthJahr. "-". $Date. " ". $Time. ":00:00";
// define End time
if( $NachtON == "ON" )
{
$len = $lenArray[$lenPos++];
if( $lenPos == $lenPosMax )
$lenPos = 0;
}
$TimeEnd = $Time+ $len;
//Tages<65>berschreitung
while( $TimeEnd >= 24 )
{
$TimeEnd -= 24;
$DateEnd += 1;
}
//ist schischt zu lang dan verk<72>rzen
if( $DateEnd > $EDatum || ($DateEnd == $EDatum && $TimeEnd >= $ETime) )
{
$len -= ($DateEnd- $EDatum)*24;
$len -= ($TimeEnd- $ETime); // -(-) ->> +
$DateEnd = $EDatum;
$TimeEnd = $ETime;
}
$_DateE = $MonthJahr. "-". $DateEnd. " ". $TimeEnd. ":00:00";
if( $_DateS != $_DateE )
CreateNewEntry();
if( $MoreThenOne!="ON" ) break;
if( $DateEnd == $EDatum && $TimeEnd >= $ETime ) break;
} while( true );
echo "</table>";
if( $OnlyShow!="" )
{
echo "<form action=\"". $_SERVER['SCRIPT_NAME']. "\">";
echo "\n\t<Input type=\"hidden\" name=\"SchichtName\" value=\"$SchichtName\">";
echo "\n\t<input type=\"hidden\" name=\"MonthJahr\" value=\"$MonthJahr\">";
echo "\n\t<input type=\"hidden\" name=\"SDatum\" value=\"$SDatum\">";
echo "\n\t<input type=\"hidden\" name=\"STime\" value=\"$STime\">";
echo "\n\t<input type=\"hidden\" name=\"MoreThenOne\" value=\"$MoreThenOne\">";
echo "\n\t<input type=\"hidden\" name=\"EDatum\" value=\"$EDatum\">";
echo "\n\t<input type=\"hidden\" name=\"ETime\" value=\"$ETime\">";
echo "\n\t<input type=\"hidden\" name=\"len\" value=\"$lenOrg\">";
echo "\n\t<input type=\"hidden\" name=\"RID\" value=\"$RID\">";
echo "\n\t<input type=\"hidden\" name=\"NachtON\" value=\"$NachtON\">";
echo "\n\t<input type=\"hidden\" name=\"len_night\" value=\"$len_night\">";
echo "\n\t<input type=\"hidden\" name=\"OnlyShow\" value=\"\">";
echo "\n\t<input type=\"hidden\" name=\"action\" value=\"newsave\">";
echo "\n\t<input type=\"submit\" value=\"mach mal Gabriel!\">";
echo "\n</form>";
} //if
} //IF
break;
case 'change':
if (! IsSet($SID)){
echo "Fehlerhafter Aufruf!";
} else {
$sql = "select * from Schichtplan where (SID = $SID)";
$Erg = mysql_query($sql, $con);
echo "Schicht ab&auml;ndern: <br>\n";
echo "<form action=\"".$_SERVER['SCRIPT_NAME']."\" method=\"POST\" >";
//echo "<form action=\"./schichtplan.php\" method=\"POST\">\n";
echo "<table>\n";
echo " <tr><td>Schichtbeginn</td><td><input value=\"".mysql_result($Erg, 0, "Date")."\" type=\"text\" size=\"40\" name=\"eDate\"></td></tr>\n";
echo " <tr><td>Raum</td><td>\n";
echo " <select name=\"eRID\">\n";
$sql2 = "select * from Raeume";
$Erg2 = mysql_query($sql2, $con);
$rowcount = mysql_num_rows($Erg2);
for ($i=0; $i<$rowcount; $i++){
$RID=mysql_result($Erg2, $i, "RID");
echo " <option value=\"".$RID."\"";
if ($RID == mysql_result($Erg, 0, "RID")) {
echo " selected";
}
echo ">".mysql_result($Erg2, $i, "Name")."</option>\n";
}
echo " </select>\n";
// <input value=\"".mysql_result($Erg, 0, "RID")."\" type=\"text\" size=\"40\" name=\"eRID\">
echo " </td></tr>\n";
echo " <tr><td>Dauer in h</td><td><input value=\"".mysql_result($Erg, 0, "Dauer")."\" type=\"text\" size=\"40\" name=\"eDauer\"></td></tr>\n";
echo " <tr><td>Beschreibung</td><td><input value=\"".mysql_result($Erg, 0, "Name")."\" type=\"text\" size=\"40\" name=\"eName\"></td></tr>\n";
echo "</table>\n";
echo "<input type=\"hidden\" name=\"SID\" value=\"$SID\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"changesave\">\n";
echo "<input type=\"submit\" value=\"sichern...\">\n";
echo "</form>";
echo "<form action=\"".$_SERVER['SCRIPT_NAME']."\" method=\"POST\" >\n";
//echo "<form action=\"./schichtplan.php\" method=\"POST\">\n";
echo "<input type=\"hidden\" name=\"SID\" value=\"$SID\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"delete\">\n";
echo "<input type=\"submit\" value=\"L&ouml;schen...\">";
echo "</form>";
$sql3 = "select * from Schichtbelegung where SID=$SID";
$Erg3 = mysql_query($sql3, $con);
$rowcount = mysql_num_rows($Erg3);
if ($rowcount > 0) {
echo "<b>ACHTUNG:</b> Es haben sich bereits Engel f&uuml;r diese Schicht eingetragen!<br>\n";
echo "Beim L&ouml;schen werden die bisher eingetragenen Engel f&uuml;r diese Schicht mitgel&ouml;scht.<br>\n";
}
if ($rowcount > 0) {
echo "<hr>";
echo "Ausserdem kannst du hier Engel aus der Schicht austragen, wenn diese nicht zu Schicht erschienen sind:<br>";
for ($j=0; $j < $rowcount; $j++) {
$userUID=mysql_result($Erg3, $j, "UID");
echo "<a href=\"./schichtplan.php?action=engeldel&SID=$SID&eUID=$userUID\">".UID2Nick($userUID)." austragen</a><br>";
}
}
echo "<hr>";
echo "Hat ein anderer Engel die Schicht &uuml;bernommen, trage ihn hier bitte ein:";
echo "<form action=\"".$_SERVER['SCRIPT_NAME']."\" method=\"POST\" >\n";
echo "<input type=\"hidden\" name=\"SID\" value=\"$SID\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"engeladd\">\n";
echo "<select name=\"eUID\">\n";
$usql="select * from User order by Nick";
$uErg = mysql_query($usql, $con);
$urowcount = mysql_num_rows($uErg);
for ($k=0; $k<$urowcount; $k++){
echo "\t<option value=\"".mysql_result($uErg, $k, "UID")."\">".mysql_result($uErg, $k, "Nick")."</option>\n";
}
echo "</select>\n";
echo " als \n";
echo "<select name=\"Art\">\n";
$SQL2 = "SELECT * FROM `Raeume` WHERE ";
$SQL2.= "(RID = '".mysql_result($Erg,0,"RID")."')";
$Erg2 = mysql_query($SQL2, $con);
for ($l = 2; $l < mysql_num_fields($Erg2); $l++) {
if (mysql_result($Erg2, 0, $l) > 0)
echo "<option value=$l>".mysql_field_name($Erg2,$l)."engel".
"</option>\n";
}
echo "</select>\n";
echo "<input type=\"submit\" value=\"eintragen...\">\n";
echo "</form>";
}
break;
case 'engeladd':
$chSQL="insert into Schichtbelegung values ('$SID', '$eUID', 'Schicht eingetragen durch Erzengel ".$_SESSION['Nick']."', '$Art')";
echo "Es wird folgende Schicht zus&auml;tzlich eingetragen:<br>\n";
echo "Engel: ".UID2Nick($eUID)."<br>\n";
echo "Bemerkung: Schicht eingetragen durch Erzengel ".$_SESSION['Nick']."<br>\n";
break;
case 'engeldel':
$chSQL="delete from Schichtbelegung where SID='$SID' and UID='$eUID' LIMIT 1";
break;
case 'changesave':
$chSQL="update Schichtplan set Date = '$eDate', RID = '$eRID', Dauer='$eDauer', Name='$eName', ";
$query = mysql_query("SELECT DATE_ADD('".$eDate."', INTERVAL '+0 ".$eDauer."' DAY_HOUR)", $con);
$enddate = mysql_fetch_row($query);
$chSQL .= " EndDate = '".$enddate[0]."' where SID=$SID";
break;
case 'delete':
$chSQL="delete from Schichtplan where SID=$SID limit 1";
$ch2SQL="delete from Schichtbelegung where SID=$SID";
break;
} // end switch
// Update ???
if (IsSet($chSQL)){
// echo $chSQL;
// hier muesste das SQL ausgefuehrt werden...
$Erg = mysql_query($chSQL, $con);
if ($Erg == 1) {
echo "&Auml;nderung wurde gesichert...";
if (IsSet($ch2SQL)){
$Erg = mysql_query($ch2SQL, $con);
}
} else {
echo "Fehler beim speichern... bitte noch ein mal probieren :)";
}
} // Ende Update
}
function CreateNewEntry() {
global $con, $_DateS, $_DateE, $RID, $len, $SchichtName, $OnlyShow, $DEBUG;
echo "<tr>\n";
echo "\t<td>$_DateS</td>\n";
echo "\t<td>$_DateE</td>\n";
echo "\t<td>$RID</td>\n";
echo "\t<td>$len</td\n>";
echo "\t<td>$SchichtName</td>\n";
if( $OnlyShow == "" )
{
$SQL = "INSERT INTO `Schichtplan` (`Date`, `EndDate`, `RID`, `Dauer`, `Name`) VALUES (";
$SQL .= "'". $_DateS. "', '". $_DateE. "', ";
$SQL .= "'". $RID. "', '". $len. "', ";
$SQL .= "'". $SchichtName. "');";
$Erg = mysql_query($SQL, $con);
if( $DEBUG ) $SQLFail = "\n\t<br>[".$SQL. "]";
if ($Erg == 1) echo "\t<td>pass</td>\n";
else echo "\t<td>fail <br>\n<u>". mysql_error($con). "</u>$SQLFail</td>\n";
} else
echo "\t<td>only show</td>\n";
echo "</tr>\n";
}
include ("./inc/footer.php");
?>