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,13 +63,11 @@ function SaveSchedule()
if( $Erg )
{
echo "Aenderung, am Schedule '". $_GET["PSIDXML"]. "', war erfogreich<br>\n";
if( mysql_num_rows($Erg1)==0)
{
echo "-->Create Shifts:<br>\n";
//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` ".
@ -77,29 +75,77 @@ function SaveSchedule()
"ORDER BY `Number`, `Name`;";
$Erg2 = mysql_query( $sql2, $con);
for( $j=0; $j<mysql_num_fields( $Erg2); $j++)
if( substr( mysql_field_name($Erg2, $j), 0, 12)=="DEFAULT_EID_" &&
mysql_result($Erg2, 0, $j) > 0 )
{
echo "---->Create engeltype: ". substr( mysql_field_name($Erg2, $j), 12).
" ". mysql_result($Erg2, 0, $j). "x<br>\n";
for( $i=0; $i < mysql_result($Erg2, 0, $j); $i++ )
if( substr( mysql_field_name($Erg2, $j), 0, 12)=="DEFAULT_EID_" )
{
$SQL3 = "INSERT INTO `ShiftEntry` (`SID`, `TID`) VALUES (".
"'". mysql_result($Erg1, 0, 0). "', ".
"'". substr( mysql_field_name($Erg2, $j), 12). "');";
// extract db values
$EngelNeeded = mysql_result($Erg2, 0, $j);
$EngelTypeID = substr( mysql_field_name($Erg2, $j), 12);
$Erg3 = mysql_query($SQL3, $con);
if ($Erg3 == 1)
echo "------>pass<br>\n";
else
echo "------>fail <u>".
mysql_error($con).
"</u>($SQL3)<br>\n";
// 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<br>\n";
$EngelNeeded += mysql_num_rows( $ErgShiftsNotEmpty);
}
// 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 (".
"'". $newSID. "', ".
"'". $EngelTypeID. "');";
$Erg3 = mysql_query($SQL3, $con);
if ($Erg3 == 1)
echo "pass ";
else
echo "fail <u>". mysql_error($con).
"</u>($SQL3)<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
echo "Aenderung, am Schedule '". $_GET["PSIDXML"]. "', war <u>nicht</u> erfogreich.(".