From bae3ede662426d362a3b9d33d9124253af7e847b Mon Sep 17 00:00:00 2001 From: msquare Date: Fri, 25 Nov 2016 13:38:16 +0100 Subject: fixes #279 fix exporting freeload comment in json export --- includes/model/Shifts_model.php | 4 +++- includes/model/User_model.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'includes/model') diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 2db0a3d3..67580eee 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -263,7 +263,9 @@ function Shift_create($shift) { */ function Shifts_by_user($user) { $result = sql_select(" - SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`, `ShiftEntry`.*, `Shifts`.*, `Room`.* + SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`, + `ShiftEntry`.`id`, `ShiftEntry`.`SID`, `ShiftEntry`.`TID`, `ShiftEntry`.`UID`, `ShiftEntry`.`freeloaded`, `ShiftEntry`.`Comment`, + `Shifts`.*, `Room`.* FROM `ShiftEntry` JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`) diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 344a3886..3ebd3bf9 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -284,7 +284,7 @@ function User($user_id) { function User_by_api_key($api_key) { $user = sql_select("SELECT * FROM `User` WHERE `api_key`='" . sql_escape($api_key) . "' LIMIT 1"); if ($user === false) { - return false; + engelsystem_error("Unable to find user by api key."); } if (count($user) == 0) { return null; -- cgit v1.2.3-70-g09d2 From 476d1daeb76306faf3ecd70f2afc8e29e98b9553 Mon Sep 17 00:00:00 2001 From: msquare Date: Fri, 25 Nov 2016 13:58:43 +0100 Subject: fixes #280 shift entries finished by user returns no freeloaded shifts --- includes/model/ShiftEntry_model.php | 1 + 1 file changed, 1 insertion(+) (limited to 'includes/model') diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index 99f67028..dca7e1c1 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -115,6 +115,7 @@ function ShiftEntries_finished_by_user($user) { JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id` WHERE `ShiftEntry`.`UID`=" . sql_escape($user['UID']) . " AND `Shifts`.`end` < " . sql_escape(time()) . " + AND `ShiftEntry`.`freeloaded` = 0 ORDER BY `Shifts`.`end` "); } -- cgit v1.2.3-70-g09d2 From 34248bb20cb3102fbcff76fcd7e059c12d87a6c3 Mon Sep 17 00:00:00 2001 From: msquare Date: Fri, 25 Nov 2016 14:27:47 +0100 Subject: show freeload comments to supporters (user shift admin) --- includes/controller/users_controller.php | 2 +- includes/model/Shifts_model.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'includes/model') diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 33abe764..26ca8d00 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -151,7 +151,7 @@ function user_controller() { } } - $shifts = Shifts_by_user($user_source); + $shifts = Shifts_by_user($user_source, in_array("user_shifts_admin", $privileges)); foreach ($shifts as &$shift) { // TODO: Move queries to model $shift['needed_angeltypes'] = sql_select("SELECT DISTINCT `AngelTypes`.* FROM `ShiftEntry` JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id` WHERE `ShiftEntry`.`SID`='" . sql_escape($shift['SID']) . "' ORDER BY `AngelTypes`.`name`"); diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 67580eee..b1d4ca5e 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -261,10 +261,11 @@ function Shift_create($shift) { /** * Return users shifts. */ -function Shifts_by_user($user) { +function Shifts_by_user($user, $include_freeload_comments = false) { $result = sql_select(" SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`, `ShiftEntry`.`id`, `ShiftEntry`.`SID`, `ShiftEntry`.`TID`, `ShiftEntry`.`UID`, `ShiftEntry`.`freeloaded`, `ShiftEntry`.`Comment`, + " . ($include_freeload_comments ? "`ShiftEntry`.`freeload_comment`, " : "") . " `Shifts`.*, `Room`.* FROM `ShiftEntry` JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) -- cgit v1.2.3-70-g09d2