diff --git a/includes/funktion_xml_schudle.php b/includes/funktion_xml_schudle.php index 8103ea10..1fd708bb 100755 --- a/includes/funktion_xml_schudle.php +++ b/includes/funktion_xml_schudle.php @@ -63,43 +63,89 @@ function SaveSchedule() if( $Erg ) { echo "Aenderung, am Schedule '". $_GET["PSIDXML"]. "', war erfogreich
\n"; - if( mysql_num_rows($Erg1)==0) + + //SID auslesen + $SQL1 = "Select `SID` FROM `Shifts` WHERE `PSID`='". $_GET["PSIDXML"]. "';"; + $Erg1 = mysql_query($SQL1, $con); + $newSID = mysql_result($Erg1, 0, 0); + + // erstellt ein Array der Reume + $sql2 = "SELECT * FROM `Room` ". + "WHERE `RID`='".$_GET["RIDXML"]. "' ". + "ORDER BY `Number`, `Name`;"; + $Erg2 = mysql_query( $sql2, $con); + for( $j=0; $jCreate Shifts:
\n"; - - //SID auslesen - $SQL1 = "Select `SID` FROM `Shifts` WHERE `PSID`='". $_GET["PSIDXML"]. "';"; - $Erg1 = mysql_query($SQL1, $con); - - // erstellt ein Array der Reume - $sql2 = "SELECT * FROM `Room` ". - "WHERE `RID`='".$_GET["RIDXML"]. "' ". - "ORDER BY `Number`, `Name`;"; - $Erg2 = mysql_query( $sql2, $con); - for( $j=0; $j 0 ) + if( substr( mysql_field_name($Erg2, $j), 0, 12)=="DEFAULT_EID_" ) + { + // extract db values + $EngelNeeded = mysql_result($Erg2, 0, $j); + $EngelTypeID = substr( mysql_field_name($Erg2, $j), 12); + + + // chech exist shifts + $sqlShifts = "SELECT * FROM `ShiftEntry` ". + "WHERE `SID`='". $newSID. "' AND ". + "`TID` = '". $EngelTypeID. "';"; + $ErgShifts = mysql_query( $sqlShifts, $con); + $EngelNeeded -= mysql_num_rows( $ErgShifts); + + // check for not empty shifts + $sqlShiftsNotEmpty = "SELECT * FROM `ShiftEntry` ". + "WHERE `SID`='". $newSID. "' AND ". + "`TID` = '". $EngelTypeID. "' AND ". + "`UID` != 0 ;"; + $ErgShiftsNotEmpty = mysql_query( $sqlShiftsNotEmpty, $con); + if( (mysql_num_rows( $ErgShiftsNotEmpty) > 0) && ($EngelNeeded < 0) ) + { + echo "---> WARING ". mysql_num_rows( $ErgShiftsNotEmpty). " shift is used, can't deleting all shifts
\n"; + $EngelNeeded += mysql_num_rows( $ErgShiftsNotEmpty); + } + + + // Angel create/delte? + if( $EngelNeeded > 0) { - echo "---->Create engeltype: ". substr( mysql_field_name($Erg2, $j), 12). - " ". mysql_result($Erg2, 0, $j). "x
\n"; - for( $i=0; $i < mysql_result($Erg2, 0, $j); $i++ ) + echo "---->Create Shifts for engeltype: ". $EngelTypeID. " ". $EngelNeeded. "x
\n------>\n"; + for( $i=0; $i < $EngelNeeded; $i++ ) { $SQL3 = "INSERT INTO `ShiftEntry` (`SID`, `TID`) VALUES (". - "'". mysql_result($Erg1, 0, 0). "', ". - "'". substr( mysql_field_name($Erg2, $j), 12). "');"; - + "'". $newSID. "', ". + "'". $EngelTypeID. "');"; + $Erg3 = mysql_query($SQL3, $con); + if ($Erg3 == 1) + echo "pass "; + else + echo "fail ". mysql_error($con). + "($SQL3)
\n"; + } + } + else if ($EngelNeeded < 0) + { + echo "---->Delete empty Shifts for engeltype: ". $EngelTypeID. " ". $EngelNeeded. "x
\n------>\n"; + for( ; $EngelNeeded < 0; $EngelNeeded++ ) + { + $SQL3 = "DELETE FROM `ShiftEntry` ". + "WHERE `SID` = ". $newSID. " AND ". + "`TID` = ". $EngelTypeID. " AND ". + "`UID` = 0 ". + "LIMIT 1;"; $Erg3 = mysql_query($SQL3, $con); if ($Erg3 == 1) - echo "------>pass
\n"; + echo "pass "; else - echo "------>fail ". - mysql_error($con). + echo "fail ". mysql_error($con). "($SQL3)
\n"; } - + echo "
\n"; } - echo "
\n"; + else + { +// echo "---->Nothing to do, for engeltype: ". $EngelTypeID. "
\n"; + } + } } + } else echo "Aenderung, am Schedule '". $_GET["PSIDXML"]. "', war nicht erfogreich.(".