expant the dbUpadte funktion, now will update the number of engel shifts

git-svn-id: svn://svn.cccv.de/engel-system@321 29ba0400-6e00-0410-a75a-ca02368028f8
This commit is contained in:
cookie 2008-12-21 21:56:21 +00:00
parent fad6bf645e
commit 0e31515334
1 changed files with 72 additions and 26 deletions

View File

@ -63,43 +63,89 @@ function SaveSchedule()
if( $Erg ) if( $Erg )
{ {
echo "Aenderung, am Schedule '". $_GET["PSIDXML"]. "', war erfogreich<br>\n"; echo "Aenderung, am Schedule '". $_GET["PSIDXML"]. "', war erfogreich<br>\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; $j<mysql_num_fields( $Erg2); $j++)
{ {
echo "-->Create Shifts:<br>\n"; 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);
//SID auslesen
$SQL1 = "Select `SID` FROM `Shifts` WHERE `PSID`='". $_GET["PSIDXML"]. "';";
$Erg1 = mysql_query($SQL1, $con);
// erstellt ein Array der Reume // chech exist shifts
$sql2 = "SELECT * FROM `Room` ". $sqlShifts = "SELECT * FROM `ShiftEntry` ".
"WHERE `RID`='".$_GET["RIDXML"]. "' ". "WHERE `SID`='". $newSID. "' AND ".
"ORDER BY `Number`, `Name`;"; "`TID` = '". $EngelTypeID. "';";
$Erg2 = mysql_query( $sql2, $con); $ErgShifts = mysql_query( $sqlShifts, $con);
for( $j=0; $j<mysql_num_fields( $Erg2); $j++) $EngelNeeded -= mysql_num_rows( $ErgShifts);
if( substr( mysql_field_name($Erg2, $j), 0, 12)=="DEFAULT_EID_" &&
mysql_result($Erg2, 0, $j) > 0 ) // 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 "---->Create engeltype: ". substr( mysql_field_name($Erg2, $j), 12). echo "---> WARING ". mysql_num_rows( $ErgShiftsNotEmpty). " shift is used, can't deleting all shifts<br>\n";
" ". mysql_result($Erg2, 0, $j). "x<br>\n"; $EngelNeeded += mysql_num_rows( $ErgShiftsNotEmpty);
for( $i=0; $i < mysql_result($Erg2, 0, $j); $i++ ) }
// Angel create/delte?
if( $EngelNeeded > 0)
{
echo "---->Create Shifts for engeltype: ". $EngelTypeID. " ". $EngelNeeded. "x<br>\n------>\n";
for( $i=0; $i < $EngelNeeded; $i++ )
{ {
$SQL3 = "INSERT INTO `ShiftEntry` (`SID`, `TID`) VALUES (". $SQL3 = "INSERT INTO `ShiftEntry` (`SID`, `TID`) VALUES (".
"'". mysql_result($Erg1, 0, 0). "', ". "'". $newSID. "', ".
"'". substr( mysql_field_name($Erg2, $j), 12). "');"; "'". $EngelTypeID. "');";
$Erg3 = mysql_query($SQL3, $con); $Erg3 = mysql_query($SQL3, $con);
if ($Erg3 == 1) if ($Erg3 == 1)
echo "------>pass<br>\n"; echo "pass ";
else else
echo "------>fail <u>". echo "fail <u>". mysql_error($con).
mysql_error($con).
"</u>($SQL3)<br>\n"; "</u>($SQL3)<br>\n";
} }
} }
echo "<br>\n"; else if ($EngelNeeded < 0)
{
echo "---->Delete empty Shifts for engeltype: ". $EngelTypeID. " ". $EngelNeeded. "x<br>\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 ";
else
echo "fail <u>". mysql_error($con).
"</u>($SQL3)<br>\n";
}
echo "<br>\n";
}
else
{
// echo "---->Nothing to do, for engeltype: ". $EngelTypeID. "<br>\n";
}
}
} }
} }
else else
echo "Aenderung, am Schedule '". $_GET["PSIDXML"]. "', war <u>nicht</u> erfogreich.(". echo "Aenderung, am Schedule '". $_GET["PSIDXML"]. "', war <u>nicht</u> erfogreich.(".