add shift entry create model

main
Philip Häusler 10 years ago
parent 09e65d1a84
commit 9176261762

@ -7,8 +7,24 @@ function ShiftEntries_freeleaded_count() {
return sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1"); return sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1");
} }
/**
* Create a new shift entry.
*
* @param ShiftEntry $shift_entry
*/
function ShiftEntry_create($shift_entry) {
return sql_query("INSERT INTO `ShiftEntry` SET
`SID`=" . sql_escape($shift_entry['SID']) . ",
`TID`=" . sql_escape($shift_entry['TID']) . ",
`UID`=" . sql_escape($shift_entry['UID']) . ",
`Comment`='" . sql_escape($shift_entry['Comment']) . "',
`freeload_comment`='" . sql_escape($shift_entry['freeload_comment']) . "',
`freeloaded`=" . sql_escape($shift_entry['freeloaded'] ? 'TRUE' : 'FALSE'));
}
/** /**
* Returns next (or current) shifts of given user. * Returns next (or current) shifts of given user.
*
* @param User $user * @param User $user
*/ */
function ShiftEntries_upcoming_for_user($user) { function ShiftEntries_upcoming_for_user($user) {

@ -246,13 +246,17 @@ function user_shifts() {
} }
$comment = strip_request_item_nl('comment'); $comment = strip_request_item_nl('comment');
sql_query("INSERT INTO `ShiftEntry` SET $result = ShiftEntry_create(array(
`Comment`='" . sql_escape($comment) . "', 'SID' => $shift_id,
`freeloaded`=" . sql_escape($freeloaded ? 1 : 0) . ", 'TID' => $selected_type_id,
`freeload_comment`='" . sql_escape($freeload_comment) . "', 'UID' => $user_id,
`UID`=" . sql_escape($user_id) . ", 'Comment' => $comment,
`TID`=" . sql_escape($selected_type_id) . ", 'freeloaded' => $freeloaded,
`SID`=" . sql_escape($shift_id)); 'freeload_comment' => $freeload_comment
));
if ($result === false)
engelsystem_error('Unable to create shift entry.');
if ($type['restricted'] == 0 && sql_num_query("SELECT * FROM `UserAngelTypes` INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id` WHERE `angeltype_id` = '" . sql_escape($selected_type_id) . "' AND `user_id` = '" . sql_escape($user_id) . "' ") == 0) if ($type['restricted'] == 0 && sql_num_query("SELECT * FROM `UserAngelTypes` INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id` WHERE `angeltype_id` = '" . sql_escape($selected_type_id) . "' AND `user_id` = '" . sql_escape($user_id) . "' ") == 0)
sql_query("INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`) VALUES ('" . sql_escape($user_id) . "', '" . sql_escape($selected_type_id) . "')"); sql_query("INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`) VALUES ('" . sql_escape($user_id) . "', '" . sql_escape($selected_type_id) . "')");

Loading…
Cancel
Save