diff options
author | Philip Häusler <msquare@notrademark.de> | 2014-12-07 17:41:40 +0100 |
---|---|---|
committer | Philip Häusler <msquare@notrademark.de> | 2014-12-07 17:41:40 +0100 |
commit | d26f8aa12cd71cd5301e6747fbedf6bfbe2ac37f (patch) | |
tree | 8e3d783bb6433a1ead0864ae87551d1ed697ce84 | |
parent | fa0e38ebff81a02f89bd4493627c49bbc48bc93b (diff) |
add shift update model
-rw-r--r-- | includes/model/Shifts_model.php | 28 | ||||
-rw-r--r-- | includes/pages/admin_import.php | 7 | ||||
-rw-r--r-- | includes/pages/user_shifts.php | 8 |
3 files changed, 40 insertions, 3 deletions
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index a9a9244e..a1d7967f 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -1,7 +1,35 @@ <?php /** + * Update a shift. + */ +function Shift_update($shift) { + return sql_query("UPDATE `Shifts` SET + `start`=" . sql_escape($shift['start']) . ", + `end`=" . sql_escape($shift['end']) . ", + `RID`=" . sql_escape($shift['RID']) . ", + `name`=" . sql_null($shift['name']) . ", + `URL`=" . sql_null($shift['URL']) . ", + `PSID`=" . sql_null($shift['PSID']) . " + WHERE `SID`=" . sql_escape($shift['SID'])); +} + +/** + * Update a shift by its external id. + */ +function Shift_update_by_psid($shift) { + return sql_query("UPDATE `Shifts` SET + `start`=" . sql_escape($shift['start']) . ", + `end`=" . sql_escape($shift['end']) . ", + `RID`=" . sql_escape($shift['RID']) . ", + `name`=" . sql_null($shift['name']) . ", + `URL`=" . sql_null($shift['URL']) . " + WHERE `PSID`=" . sql_escape($shift['PSID'])); +} + +/** * Create a new shift. + * * @return new shift id or false */ function Shift_create($shift) { diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php index 31b73992..f4c2b252 100644 --- a/includes/pages/admin_import.php +++ b/includes/pages/admin_import.php @@ -123,8 +123,11 @@ function admin_import() { engelsystem_error('Unable to create shift.'); } - foreach ($events_updated as $event) - sql_query("UPDATE `Shifts` SET `name`='" . sql_escape($event['name']) . "', `start`=" . sql_escape($event['start']) . ", `end`=" . sql_escape($event['end']) . ", `RID`=" . sql_escape($event['RID']) . ", `PSID`=" . sql_escape($event['PSID']) . ", `URL`='" . sql_escape($event['URL']) . "' WHERE `PSID`=" . sql_escape($event['PSID']) . " LIMIT 1"); + foreach ($events_updated as $event) { + $result = Shift_update_by_psid($event); + if ($result === false) + engelsystem_error('Unable to update shift.'); + } foreach ($events_deleted as $event) sql_query("DELETE FROM `Shifts` WHERE `PSID`=" . sql_escape($event['PSID']) . " LIMIT 1"); diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 07f10ea2..2f0bee6e 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -125,7 +125,13 @@ function user_shifts() { } if ($ok) { - sql_query("UPDATE `Shifts` SET `start`=" . sql_escape($start) . ", `end`=" . sql_escape($end) . ", `RID`=" . sql_escape($rid) . ", `name`='" . sql_escape($name) . "' WHERE `SID`=" . sql_escape($shift_id) . " LIMIT 1"); + $shift['name'] = $name; + $shift['RID'] = $rid; + $shift['start'] = $start; + $shift['end'] = $end; + $result = Shift_update($shift); + if ($result === false) + engelsystem_error('Unable to update shift.'); sql_query("DELETE FROM `NeededAngelTypes` WHERE `shift_id`=" . sql_escape($shift_id)); $needed_angel_types_info = array(); foreach ($needed_angel_types as $type_id => $count) { |