add shift create model

This commit is contained in:
Philip Häusler 2014-12-07 17:34:29 +01:00
parent 156db1eadd
commit fa0e38ebff
5 changed files with 63 additions and 28 deletions

View File

@ -1,5 +1,25 @@
<?php
/**
* Create a new shift.
* @return new shift id or false
*/
function Shift_create($shift) {
$result = sql_query("INSERT INTO `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']));
if ($result === false)
return false;
return sql_id();
}
/**
* Return users shifts.
*/
function Shifts_by_user($user) {
return sql_select("
SELECT *

View File

@ -9,6 +9,13 @@ function sql_close() {
return $sql_connection->close();
}
/**
* Return NULL if given value is null.
*/
function sql_null($value = null) {
return $value == null ? 'NULL' : ("'" . sql_escape($value) . "'");
}
/**
* Start new transaction.
*/

View File

@ -1,4 +1,5 @@
<?php
function admin_import_title() {
return _("Frab import");
}
@ -116,8 +117,11 @@ function admin_import() {
sql_query("DELETE FROM `Room` WHERE `Name`='" . sql_escape($room) . "' LIMIT 1");
list($events_new, $events_updated, $events_deleted) = prepare_events($import_file);
foreach ($events_new as $event)
sql_query("INSERT INTO `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']) . "'");
foreach ($events_new as $event) {
$result = Shift_create($event);
if ($result === false)
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");

View File

@ -1,4 +1,5 @@
<?php
function admin_shifts_title() {
return _("Create shifts");
}
@ -229,14 +230,17 @@ function admin_shifts() {
))
));
}
} elseif (isset($_REQUEST['submit'])) {
if (! is_array($_SESSION['admin_shifts_shifts']) || ! is_array($_SESSION['admin_shifts_types']))
redirect(page_link_to('admin_shifts'));
foreach ($_SESSION['admin_shifts_shifts'] as $shift) {
sql_query("INSERT INTO `Shifts` SET `start`=" . sql_escape($shift['start']) . ", `end`=" . sql_escape($shift['end']) . ", `RID`=" . sql_escape($shift['RID']) . ", `name`='" . sql_escape($shift['name']) . "'");
$shift_id = sql_id();
$shift['URL'] = null;
$shift['PSID'] = null;
$shift_id = Shift_create($shift);
if ($shift_id === false)
engelsystem_error('Unable to create shift.');
engelsystem_log("Shift created: " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
$needed_angel_types_info = array();
foreach ($_SESSION['admin_shifts_types'] as $type_id => $count) {