2013-12-09 17:10:07 +01:00
|
|
|
<?php
|
|
|
|
|
2014-09-28 15:01:02 +02:00
|
|
|
/**
|
|
|
|
* Counts all freeloaded shifts.
|
|
|
|
*/
|
|
|
|
function ShiftEntries_freeleaded_count() {
|
|
|
|
return sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1");
|
|
|
|
}
|
|
|
|
|
2014-12-07 16:54:00 +01:00
|
|
|
function ShiftEntries_by_shift($shift_id) {
|
|
|
|
return sql_select("
|
|
|
|
SELECT `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `AngelTypes`.`name` as `angel_type_name`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded`
|
|
|
|
FROM `ShiftEntry`
|
|
|
|
JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
|
|
|
|
JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id`
|
|
|
|
WHERE `ShiftEntry`.`SID`=" . sql_escape($shift_id));
|
|
|
|
}
|
|
|
|
|
2014-12-07 16:45:09 +01:00
|
|
|
/**
|
|
|
|
* Create a new shift entry.
|
2014-12-07 16:54:00 +01:00
|
|
|
*
|
2014-12-07 16:45:09 +01:00
|
|
|
* @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'));
|
|
|
|
}
|
|
|
|
|
2014-08-23 01:55:18 +02:00
|
|
|
/**
|
|
|
|
* Returns next (or current) shifts of given user.
|
2014-12-07 16:45:09 +01:00
|
|
|
*
|
|
|
|
* @param User $user
|
2014-08-23 01:55:18 +02:00
|
|
|
*/
|
|
|
|
function ShiftEntries_upcoming_for_user($user) {
|
|
|
|
return sql_select("
|
|
|
|
SELECT *
|
|
|
|
FROM `ShiftEntry`
|
|
|
|
JOIN `Shifts` ON `Shifts`.`SID`=`ShiftEntry`.`SID`
|
|
|
|
WHERE `ShiftEntry`.`UID`=" . sql_escape($user['UID']) . "
|
|
|
|
AND `Shifts`.`end` > " . sql_escape(time()) . "
|
|
|
|
ORDER BY `Shifts`.`end`
|
|
|
|
");
|
|
|
|
}
|
|
|
|
|
2013-12-09 17:10:07 +01:00
|
|
|
/**
|
|
|
|
* Returns all shift entries in given shift for given angeltype.
|
2014-08-23 01:55:18 +02:00
|
|
|
*
|
|
|
|
* @param int $shift_id
|
|
|
|
* @param int $angeltype_id
|
2013-12-09 17:10:07 +01:00
|
|
|
*/
|
|
|
|
function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id) {
|
|
|
|
return sql_select("
|
|
|
|
SELECT *
|
2013-12-09 17:17:23 +01:00
|
|
|
FROM `ShiftEntry`
|
2013-12-09 17:10:07 +01:00
|
|
|
WHERE `SID`=" . sql_escape($shift_id) . "
|
|
|
|
AND `TID`=" . sql_escape($angeltype_id) . "
|
|
|
|
");
|
|
|
|
}
|
|
|
|
|
2013-12-27 18:45:27 +01:00
|
|
|
/**
|
|
|
|
* Returns all freeloaded shifts for given user.
|
|
|
|
*/
|
|
|
|
function ShiftEntries_freeloaded_by_user($user) {
|
|
|
|
return sql_select("SELECT *
|
|
|
|
FROM `ShiftEntry`
|
|
|
|
WHERE `freeloaded` = 1
|
|
|
|
AND `UID`=" . sql_escape($user['UID']));
|
|
|
|
}
|
|
|
|
|
2013-12-09 17:10:07 +01:00
|
|
|
?>
|