Row_Updated Server Event - no record with new date
Hi,
I am using the below code to update a record.
When I update the recod it is removing the recored "Code" from table protokoll but it is not entering the "Code" for the new date in the table protokoll.
In this case I am only changing the field date.
Why is this not doing?
// Row_Updated event
function Row_Updated($rsold, &$rsnew)
{
// Get the old and new values
$codeOld = $rsold["Code"];
$eventOld = $rsold["Event"];
$dateOld = $rsold["Date"];
$codeNew = $rsnew["Code"];
$eventNew = $rsnew["Event"];
$dateNew = $rsnew["Date"];
// Remove the old code from the old event and date
if (!empty($eventOld) && !empty($dateOld)) {
$sqlOld =
"SELECT `Id`, `Entschuldigt` FROM `protokoll` WHERE `Titel` = '" .
AdjustSql($eventOld) .
"' AND `Datum` = '" .
AdjustSql($dateOld) .
"'";
$rsOld = Conn()->executeQuery($sqlOld);
while ($rowOld = $rsOld->fetch()) {
$idOld = $rowOld["Id"];
$entschuldigtOld = $rowOld["Entschuldigt"];
$entschuldigtArrayOld = explode(",", $entschuldigtOld);
$index = array_search($codeOld, $entschuldigtArrayOld);
if ($index !== false) {
// Remove the old code
unset($entschuldigtArrayOld[$index]);
$newEntschuldigtOld = implode(",", $entschuldigtArrayOld);
// Update the protokoll record
$updateSqlOld =
"UPDATE `protokoll` SET `Entschuldigt` = '" .
AdjustSql($newEntschuldigtOld) .
"' WHERE `Id` = " .
AdjustSql($idOld);
Conn()->executeUpdate($updateSqlOld);
}
}
}
// Add the new code to the new event and date
if (!empty($eventNew) && !empty($dateNew)) {
$sqlNew =
"SELECT `Id`, `Entschuldigt` FROM `protokoll` WHERE `Titel` = '" .
AdjustSql($eventNew) .
"' AND `Datum` = '" .
AdjustSql($dateNew) .
"'";
$rsNew = Conn()->executeQuery($sqlNew);
while ($rowNew = $rsNew->fetch()) {
$idNew = $rowNew["Id"];
$entschuldigtNew = $rowNew["Entschuldigt"];
$entschuldigtArrayNew = explode(",", $entschuldigtNew);
if (!in_array($codeNew, $entschuldigtArrayNew)) {
// Add the new code
$entschuldigtArrayNew[] = $codeNew;
$newEntschuldigtNew = implode(",", $entschuldigtArrayNew);
// Update the protokoll record
$updateSqlNew =
"UPDATE `protokoll` SET `Entschuldigt` = '" .
AdjustSql($newEntschuldigtNew) .
"' WHERE `Id` = " .
AdjustSql($idNew);
Conn()->executeUpdate($updateSqlNew);
}
}
}
}
mpol_ch