fixes #279 fix exporting freeload comment in json export

This commit is contained in:
msquare 2016-11-25 13:38:16 +01:00
parent a8bcb19eaa
commit bae3ede662
6 changed files with 11 additions and 25 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
use Engelsystem\ShiftSignupState; use Engelsystem\ShiftSignupState;
function shift_link($shift) { function shift_link($shift) {
return page_link_to('shifts') . '&action=view&shift_id=' . $shift['SID']; return page_link_to('shifts') . '&action=view&shift_id=' . $shift['SID'];
} }
@ -286,7 +286,7 @@ function shifts_json_export_all_controller() {
* (Like iCal Export or shifts view) * (Like iCal Export or shifts view)
*/ */
function shifts_json_export_controller() { function shifts_json_export_controller() {
global $ical_shifts, $user; global $user;
if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) { if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
engelsystem_error("Missing key."); engelsystem_error("Missing key.");
@ -295,9 +295,6 @@ function shifts_json_export_controller() {
$key = $_REQUEST['key']; $key = $_REQUEST['key'];
$user = User_by_api_key($key); $user = User_by_api_key($key);
if ($user === false) {
engelsystem_error("Unable to find user.");
}
if ($user == null) { if ($user == null) {
engelsystem_error("Key invalid."); engelsystem_error("Key invalid.");
} }
@ -305,25 +302,17 @@ function shifts_json_export_controller() {
engelsystem_error("No privilege for shifts_json_export."); engelsystem_error("No privilege for shifts_json_export.");
} }
$ical_shifts = load_ical_shifts(); $shifts = load_ical_shifts();
header("Content-Type: application/json; charset=utf-8"); header("Content-Type: application/json; charset=utf-8");
raw_output(json_encode($ical_shifts)); raw_output(json_encode($shifts));
} }
/** /**
* Returns shifts to export. * Returns users shifts to export.
* Users shifts or user_shifts filter based shifts if export=user_shifts is given as param.
*/ */
function load_ical_shifts() { function load_ical_shifts() {
global $user, $ical_shifts; global $user;
if (isset($_REQUEST['export']) && $_REQUEST['export'] == 'user_shifts') {
require_once realpath(__DIR__ . '/user_shifts.php');
view_user_shifts();
return $ical_shifts;
}
return Shifts_by_user($user); return Shifts_by_user($user);
} }

View File

@ -263,7 +263,9 @@ function Shift_create($shift) {
*/ */
function Shifts_by_user($user) { function Shifts_by_user($user) {
$result = sql_select(" $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` FROM `ShiftEntry`
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`) JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)

View File

@ -284,7 +284,7 @@ function User($user_id) {
function User_by_api_key($api_key) { function User_by_api_key($api_key) {
$user = sql_select("SELECT * FROM `User` WHERE `api_key`='" . sql_escape($api_key) . "' LIMIT 1"); $user = sql_select("SELECT * FROM `User` WHERE `api_key`='" . sql_escape($api_key) . "' LIMIT 1");
if ($user === false) { if ($user === false) {
return false; engelsystem_error("Unable to find user by api key.");
} }
if (count($user) == 0) { if (count($user) == 0) {
return null; return null;

View File

@ -10,9 +10,6 @@ function user_atom() {
$key = $_REQUEST['key']; $key = $_REQUEST['key'];
$user = User_by_api_key($key); $user = User_by_api_key($key);
if ($user === false) {
engelsystem_error("Unable to find user.");
}
if ($user == null) { if ($user == null) {
engelsystem_error("Key invalid."); engelsystem_error("Key invalid.");
} }

View File

@ -12,9 +12,6 @@ function user_ical() {
$key = $_REQUEST['key']; $key = $_REQUEST['key'];
$user = User_by_api_key($key); $user = User_by_api_key($key);
if ($user === false) {
engelsystem_error("Unable to find user.");
}
if ($user == null) { if ($user == null) {
engelsystem_error("Key invalid."); engelsystem_error("Key invalid.");
} }

View File

@ -55,6 +55,7 @@ function ShiftType_view($shifttype, $angeltype) {
button(page_link_to('shifttypes') . '&action=edit&shifttype_id=' . $shifttype['id'], _('edit'), 'edit'), button(page_link_to('shifttypes') . '&action=edit&shifttype_id=' . $shifttype['id'], _('edit'), 'edit'),
button(page_link_to('shifttypes') . '&action=delete&shifttype_id=' . $shifttype['id'], _('delete'), 'delete') button(page_link_to('shifttypes') . '&action=delete&shifttype_id=' . $shifttype['id'], _('delete'), 'delete')
]), ]),
heading(_("Description"), 2),
$parsedown->parse($shifttype['description']) $parsedown->parse($shifttype['description'])
]); ]);
} }