prohibit inline control structures on pages

main
msquare 8 years ago
parent 1ec19b46f3
commit 91dafb19ec

@ -14,8 +14,9 @@ function admin_active() {
$limit = "";
$set_active = "";
if (isset($_REQUEST['search']))
if (isset($_REQUEST['search'])) {
$search = strip_request_item('search');
}
$show_all_shifts = isset($_REQUEST['show_all_shifts']);
@ -33,8 +34,9 @@ function admin_active() {
$msg .= error(_("Please enter a number of angels to be marked as active."), true);
}
if ($ok)
if ($ok) {
$limit = " LIMIT " . $count;
}
if (isset($_REQUEST['ack'])) {
sql_query("UPDATE `User` SET `Aktiv` = 0 WHERE `Tshirt` = 0");
$users = sql_select("
@ -67,8 +69,9 @@ function admin_active() {
sql_query("UPDATE `User` SET `Aktiv`=1 WHERE `UID`='" . sql_escape($id) . "' LIMIT 1");
engelsystem_log("User " . User_Nick_render($user_source) . " is active now.");
$msg = success(_("Angel has been marked as active."), true);
} else
} else {
$msg = error(_("Angel not found."), true);
}
} elseif (isset($_REQUEST['not_active']) && preg_match("/^[0-9]+$/", $_REQUEST['not_active'])) {
$id = $_REQUEST['not_active'];
$user_source = User($id);
@ -76,8 +79,9 @@ function admin_active() {
sql_query("UPDATE `User` SET `Aktiv`=0 WHERE `UID`='" . sql_escape($id) . "' LIMIT 1");
engelsystem_log("User " . User_Nick_render($user_source) . " is NOT active now.");
$msg = success(_("Angel has been marked as not active."), true);
} else
} else {
$msg = error(_("Angel not found."), true);
}
} elseif (isset($_REQUEST['tshirt']) && preg_match("/^[0-9]+$/", $_REQUEST['tshirt'])) {
$id = $_REQUEST['tshirt'];
$user_source = User($id);
@ -85,8 +89,9 @@ function admin_active() {
sql_query("UPDATE `User` SET `Tshirt`=1 WHERE `UID`='" . sql_escape($id) . "' LIMIT 1");
engelsystem_log("User " . User_Nick_render($user_source) . " has tshirt now.");
$msg = success(_("Angel has got a t-shirt."), true);
} else
} else {
$msg = error("Angel not found.", true);
}
} elseif (isset($_REQUEST['not_tshirt']) && preg_match("/^[0-9]+$/", $_REQUEST['not_tshirt'])) {
$id = $_REQUEST['not_tshirt'];
$user_source = User($id);
@ -94,9 +99,10 @@ function admin_active() {
sql_query("UPDATE `User` SET `Tshirt`=0 WHERE `UID`='" . sql_escape($id) . "' LIMIT 1");
engelsystem_log("User " . User_Nick_render($user_source) . " has NO tshirt.");
$msg = success(_("Angel has got no t-shirt."), true);
} else
} else {
$msg = error(_("Angel not found."), true);
}
}
$users = sql_select("
SELECT `User`.*, COUNT(`ShiftEntry`.`id`) as `shift_count`, ${shift_sum_formula} as `shift_length`
@ -107,22 +113,25 @@ function admin_active() {
GROUP BY `User`.`UID`
ORDER BY `force_active` DESC, `shift_length` DESC" . $limit);
$matched_users = array();
if ($search == "")
$tokens = array();
else
$matched_users = [];
if ($search == "") {
$tokens = [];
} else {
$tokens = explode(" ", $search);
}
foreach ($users as &$usr) {
if (count($tokens) > 0) {
$match = false;
foreach ($tokens as $t)
foreach ($tokens as $t) {
if (stristr($usr['Nick'], trim($t))) {
$match = true;
break;
}
if (! $match)
}
if (! $match) {
continue;
}
}
$usr['nick'] = User_Nick_render($usr);
$usr['shirt_size'] = $tshirt_sizes[$usr['Size']];
$usr['work_time'] = round($usr['shift_length'] / 60) . ' min (' . round($usr['shift_length'] / 3600) . ' h)';
@ -131,14 +140,16 @@ function admin_active() {
$usr['tshirt'] = glyph_bool($usr['Tshirt'] == 1);
$actions = array();
if ($usr['Aktiv'] == 0)
if ($usr['Aktiv'] == 0) {
$actions[] = '<a href="' . page_link_to('admin_active') . '&amp;active=' . $usr['UID'] . ($show_all_shifts ? '&amp;show_all_shifts=' : '') . '&amp;search=' . $search . '">' . _("set active") . '</a>';
}
if ($usr['Aktiv'] == 1 && $usr['Tshirt'] == 0) {
$actions[] = '<a href="' . page_link_to('admin_active') . '&amp;not_active=' . $usr['UID'] . ($show_all_shifts ? '&amp;show_all_shifts=' : '') . '&amp;search=' . $search . '">' . _("remove active") . '</a>';
$actions[] = '<a href="' . page_link_to('admin_active') . '&amp;tshirt=' . $usr['UID'] . ($show_all_shifts ? '&amp;show_all_shifts=' : '') . '&amp;search=' . $search . '">' . _("got t-shirt") . '</a>';
}
if ($usr['Tshirt'] == 1)
if ($usr['Tshirt'] == 1) {
$actions[] = '<a href="' . page_link_to('admin_active') . '&amp;not_tshirt=' . $usr['UID'] . ($show_all_shifts ? '&amp;show_all_shifts=' : '') . '&amp;search=' . $search . '">' . _("remove t-shirt") . '</a>';
}
$usr['actions'] = join(' ', $actions);
@ -161,18 +172,18 @@ function admin_active() {
'given' => '<b>' . sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Tshirt`=1") . '</b>'
];
return page_with_title(admin_active_title(), array(
form(array(
return page_with_title(admin_active_title(), [
form([
form_text('search', _("Search angel:"), $search),
form_checkbox('show_all_shifts', _("Show all shifts"), $show_all_shifts),
form_submit('submit', _("Search"))
), page_link_to('admin_active')),
$set_active == "" ? form(array(
], page_link_to('admin_active')),
$set_active == "" ? form([
form_text('count', _("How much angels should be active?"), $count),
form_submit('set_active', _("Preview"))
)) : $set_active,
]) : $set_active,
msg(),
table(array(
table([
'nick' => _("Nickname"),
'shirt_size' => _("Size"),
'shift_count' => _("Shifts"),
@ -181,13 +192,13 @@ function admin_active() {
'force_active' => _("Forced"),
'tshirt' => _("T-shirt?"),
'actions' => ""
), $matched_users),
], $matched_users),
'<h2>' . _("Shirt statistics") . '</h2>',
table(array(
table([
'size' => _("Size"),
'needed' => _("Needed shirts"),
'given' => _("Given shirts")
), $shirt_statistics)
));
], $shirt_statistics)
]);
}
?>

@ -7,8 +7,9 @@ function admin_arrive_title() {
function admin_arrive() {
$msg = "";
$search = "";
if (isset($_REQUEST['search']))
if (isset($_REQUEST['search'])) {
$search = strip_request_item('search');
}
if (isset($_REQUEST['reset']) && preg_match("/^[0-9]*$/", $_REQUEST['reset'])) {
$id = $_REQUEST['reset'];
@ -18,8 +19,9 @@ function admin_arrive() {
engelsystem_log("User set to not arrived: " . User_Nick_render($user_source));
success(_("Reset done. Angel has not arrived."));
redirect(user_link($user_source));
} else
} else {
$msg = error(_("Angel not found."), true);
}
} elseif (isset($_REQUEST['arrived']) && preg_match("/^[0-9]*$/", $_REQUEST['arrived'])) {
$id = $_REQUEST['arrived'];
$user_source = User($id);
@ -28,37 +30,42 @@ function admin_arrive() {
engelsystem_log("User set has arrived: " . User_Nick_render($user_source));
success(_("Angel has been marked as arrived."));
redirect(user_link($user_source));
} else
} else {
$msg = error(_("Angel not found."), true);
}
}
$users = sql_select("SELECT * FROM `User` ORDER BY `Nick`");
$arrival_count_at_day = [];
$planned_arrival_count_at_day = [];
$planned_departure_count_at_day = [];
$users_matched = [];
if ($search == "")
if ($search == "") {
$tokens = [];
else
} else {
$tokens = explode(" ", $search);
}
foreach ($users as $usr) {
if (count($tokens) > 0) {
$match = false;
$index = join(" ", $usr);
foreach ($tokens as $t)
foreach ($tokens as $t) {
if (stristr($index, trim($t))) {
$match = true;
break;
}
if (! $match)
}
if (! $match) {
continue;
}
}
$usr['nick'] = User_Nick_render($usr);
if ($usr['planned_departure_date'] != null)
if ($usr['planned_departure_date'] != null) {
$usr['rendered_planned_departure_date'] = date('Y-m-d', $usr['planned_departure_date']);
else
} else {
$usr['rendered_planned_departure_date'] = '-';
}
$usr['rendered_planned_arrival_date'] = date('Y-m-d', $usr['planned_arrival_date']);
$usr['rendered_arrival_date'] = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : "-";
$usr['arrived'] = $usr['Gekommen'] == 1 ? _("yes") : "";
@ -66,22 +73,25 @@ function admin_arrive() {
if ($usr['arrival_date'] > 0) {
$day = date('Y-m-d', $usr['arrival_date']);
if (! isset($arrival_count_at_day[$day]))
if (! isset($arrival_count_at_day[$day])) {
$arrival_count_at_day[$day] = 0;
}
$arrival_count_at_day[$day] ++;
}
if ($usr['planned_arrival_date'] != null) {
$day = date('Y-m-d', $usr['planned_arrival_date']);
if (! isset($planned_arrival_count_at_day[$day]))
if (! isset($planned_arrival_count_at_day[$day])) {
$planned_arrival_count_at_day[$day] = 0;
}
$planned_arrival_count_at_day[$day] ++;
}
if ($usr['planned_departure_date'] != null && $usr['Gekommen'] == 1) {
$day = date('Y-m-d', $usr['planned_departure_date']);
if (! isset($planned_departure_count_at_day[$day]))
if (! isset($planned_departure_count_at_day[$day])) {
$planned_departure_count_at_day[$day] = 0;
}
$planned_departure_count_at_day[$day] ++;
}
@ -125,20 +135,20 @@ function admin_arrive() {
];
}
return page_with_title(admin_arrive_title(), array(
return page_with_title(admin_arrive_title(), [
msg(),
form(array(
form([
form_text('search', _("Search"), $search),
form_submit('submit', _("Search"))
)),
table(array(
]),
table([
'nick' => _("Nickname"),
'rendered_planned_arrival_date' => _("Planned arrival"),
'arrived' => _("Arrived?"),
'rendered_arrival_date' => _("Arrival date"),
'rendered_planned_departure_date' => _("Planned departure"),
'actions' => ""
), $users_matched),
], $users_matched),
div('row', [
div('col-md-4', [
heading(_("Planned arrival statistics"), 2),
@ -186,6 +196,6 @@ function admin_arrive() {
], $planned_departure_at_day)
])
])
));
]);
}
?>

@ -1,4 +1,5 @@
<?php
function admin_free_title() {
return _("Free angels");
}
@ -7,25 +8,28 @@ function admin_free() {
global $privileges;
$search = "";
if (isset($_REQUEST['search']))
if (isset($_REQUEST['search'])) {
$search = strip_request_item('search');
}
$angeltypesearch = "";
if (empty($_REQUEST['angeltype']))
if (empty($_REQUEST['angeltype'])) {
$_REQUEST['angeltype'] = '';
else {
} else {
$angeltypesearch = " INNER JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id` = '" . sql_escape($_REQUEST['angeltype']) . "' AND `UserAngelTypes`.`user_id` = `User`.`UID`";
if (isset($_REQUEST['confirmed_only']))
if (isset($_REQUEST['confirmed_only'])) {
$angeltypesearch .= " AND `UserAngelTypes`.`confirm_user_id`";
}
$angeltypesearch .= ") ";
}
$angel_types_source = sql_select("SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`");
$angel_types = array(
$angel_types = [
'' => 'alle Typen'
);
foreach ($angel_types_source as $angel_type)
];
foreach ($angel_types_source as $angel_type) {
$angel_types[$angel_type['id']] = $angel_type['name'];
}
$users = sql_select("
SELECT `User`.*
@ -37,58 +41,61 @@ function admin_free() {
GROUP BY `User`.`UID`
ORDER BY `Nick`");
$free_users_table = array();
if ($search == "")
$tokens = array();
else
$free_users_table = [];
if ($search == "") {
$tokens = [];
} else {
$tokens = explode(" ", $search);
}
foreach ($users as $usr) {
if (count($tokens) > 0) {
$match = false;
$index = join("", $usr);
foreach ($tokens as $t)
foreach ($tokens as $t) {
if (stristr($index, trim($t))) {
$match = true;
break;
}
if (! $match)
}
if (! $match) {
continue;
}
}
$free_users_table[] = array(
$free_users_table[] = [
'name' => User_Nick_render($usr),
'shift_state' => User_shift_state_render($usr),
'dect' => $usr['DECT'],
'jabber' => $usr['jabber'],
'email' => $usr['email'],
'actions' => in_array('admin_user', $privileges) ? button(page_link_to('admin_user') . '&amp;id=' . $usr['UID'], _("edit"), 'btn-xs') : ''
);
];
}
return page_with_title(admin_free_title(), array(
form(array(
div('row', array(
div('col-md-4', array(
return page_with_title(admin_free_title(), [
form([
div('row', [
div('col-md-4', [
form_text('search', _("Search"), $search)
)),
div('col-md-4', array(
]),
div('col-md-4', [
form_select('angeltype', _("Angeltype"), $angel_types, $_REQUEST['angeltype'])
)),
div('col-md-2', array(
]),
div('col-md-2', [
form_checkbox('confirmed_only', _("Only confirmed"), isset($_REQUEST['confirmed_only']))
)),
div('col-md-2', array(
]),
div('col-md-2', [
form_submit('submit', _("Search"))
))
))
)),
table(array(
])
])
]),
table([
'name' => _("Nick"),
'shift_state' => '',
'dect' => _("DECT"),
'jabber' => _("Jabber"),
'email' => _("E-Mail"),
'actions' => ''
), $free_users_table)
));
], $free_users_table)
]);
}
?>

@ -1,4 +1,5 @@
<?php
function admin_groups_title() {
return _("Grouprights");
}
@ -12,63 +13,68 @@ function admin_groups() {
$privileges = sql_select("SELECT * FROM `GroupPrivileges` JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`) WHERE `group_id`='" . sql_escape($group['UID']) . "'");
$privileges_html = array();
foreach ($privileges as $priv)
foreach ($privileges as $priv) {
$privileges_html[] = $priv['name'];
}
$groups_table[] = array(
$groups_table[] = [
'name' => $group['Name'],
'privileges' => join(', ', $privileges_html),
'actions' => button(page_link_to('admin_groups') . '&action=edit&id=' . $group['UID'], _("edit"), 'btn-xs')
);
];
}
return page_with_title(admin_groups_title(), array(
table(array(
return page_with_title(admin_groups_title(), [
table([
'name' => _("Name"),
'privileges' => _("Privileges"),
'actions' => ''
), $groups_table)
));
], $groups_table)
]);
} else {
switch ($_REQUEST["action"]) {
case 'edit':
if (isset($_REQUEST['id']) && preg_match("/^-[0-9]{1,11}$/", $_REQUEST['id']))
if (isset($_REQUEST['id']) && preg_match("/^-[0-9]{1,11}$/", $_REQUEST['id'])) {
$id = $_REQUEST['id'];
else
} else {
return error("Incomplete call, missing Groups ID.", true);
}
$room = sql_select("SELECT * FROM `Groups` WHERE `UID`='" . sql_escape($id) . "' LIMIT 1");
if (count($room) > 0) {
list($room) = $room;
$privileges = sql_select("SELECT `Privileges`.*, `GroupPrivileges`.`group_id` FROM `Privileges` LEFT OUTER JOIN `GroupPrivileges` ON (`Privileges`.`id` = `GroupPrivileges`.`privilege_id` AND `GroupPrivileges`.`group_id`='" . sql_escape($id) . "') ORDER BY `Privileges`.`name`");
$privileges_html = "";
$privileges_form = array();
$privileges_form = [];
foreach ($privileges as $priv) {
$privileges_form[] = form_checkbox('privileges[]', $priv['desc'] . ' (' . $priv['name'] . ')', $priv['group_id'] != "", $priv['id']);
$privileges_html .= sprintf('<tr><td><input type="checkbox" ' . 'name="privileges[]" value="%s" %s />' . '</td> <td>%s</td> <td>%s</td></tr>', $priv['id'], ($priv['group_id'] != "" ? 'checked="checked"' : ''), $priv['name'], $priv['desc']);
}
$privileges_form[] = form_submit('submit', _("Save"));
$html .= page_with_title(_("Edit group"), array(
$html .= page_with_title(_("Edit group"), [
form($privileges_form, page_link_to('admin_groups') . '&action=save&id=' . $id)
));
} else
]);
} else {
return error("No Group found.", true);
}
break;
case 'save':
if (isset($_REQUEST['id']) && preg_match("/^-[0-9]{1,11}$/", $_REQUEST['id']))
if (isset($_REQUEST['id']) && preg_match("/^-[0-9]{1,11}$/", $_REQUEST['id'])) {
$id = $_REQUEST['id'];
else
} else {
return error("Incomplete call, missing Groups ID.", true);
}
$room = sql_select("SELECT * FROM `Groups` WHERE `UID`='" . sql_escape($id) . "' LIMIT 1");
if (! is_array($_REQUEST['privileges']))
$_REQUEST['privileges'] = array();
if (! is_array($_REQUEST['privileges'])) {
$_REQUEST['privileges'] = [];
}
if (count($room) > 0) {
list($room) = $room;
sql_query("DELETE FROM `GroupPrivileges` WHERE `group_id`='" . sql_escape($id) . "'");
$privilege_names = array();
$privilege_names = [];
foreach ($_REQUEST['privileges'] as $priv) {
if (preg_match("/^[0-9]{1,}$/", $priv)) {
$group_privileges_source = sql_select("SELECT * FROM `Privileges` WHERE `id`='" . sql_escape($priv) . "' LIMIT 1");
@ -80,8 +86,9 @@ function admin_groups() {
}
engelsystem_log("Group privileges of group " . $room['Name'] . " edited: " . join(", ", $privilege_names));
redirect(page_link_to("admin_groups"));
} else
} else {
return error("No Group found.", true);
}
break;
}
}

@ -14,8 +14,9 @@ function admin_import() {
'input',
'check',
'import'
]))
])) {
$step = $_REQUEST['step'];
}
if ($test_handle = fopen('../import/tmp', 'w')) {
fclose($test_handle);
@ -30,11 +31,13 @@ function admin_import() {
$add_minutes_end = 15;
$shifttypes_source = ShiftTypes();
if ($shifttypes_source === false)
if ($shifttypes_source === false) {
engelsystem_error('Unable to load shifttypes.');
}
$shifttypes = [];
foreach ($shifttypes_source as $shifttype)
foreach ($shifttypes_source as $shifttype) {
$shifttypes[$shifttype['id']] = $shifttype['name'];
}
switch ($step) {
case 'input':
@ -43,23 +46,23 @@ function admin_import() {
if (isset($_REQUEST['submit'])) {
$ok = true;
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']]))
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
$shifttype_id = $_REQUEST['shifttype_id'];
else {
} else {
$ok = false;
error(_('Please select a shift type.'));
}
if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start'])))
if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) {
$add_minutes_start = trim($_REQUEST['add_minutes_start']);
else {
} else {
$ok = false;
error(_("Please enter an amount of minutes to add to a talk's begin."));
}
if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end'])))
if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) {
$add_minutes_end = trim($_REQUEST['add_minutes_end']);
else {
} else {
$ok = false;
error(_("Please enter an amount of minutes to add to a talk's end."));
}
@ -89,14 +92,14 @@ function admin_import() {
_('File Upload') . mute(glyph('arrow-right')) . mute(_('Validation')) . mute(glyph('arrow-right')) . mute(_('Import'))
]) . div('row', [
div('col-md-offset-3 col-md-6', [
form(array(
form([
form_info('', _("This import will create/update/delete rooms and shifts by given FRAB-export file. The needed file format is xcal.")),
form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id),
form_spinner('add_minutes_start', _("Add minutes to start"), $add_minutes_start),
form_spinner('add_minutes_end', _("Add minutes to end"), $add_minutes_end),
form_file('xcal_file', _("xcal-File (.xcal)")),
form_submit('submit', _("Import"))
))
])
])
]);
}
@ -108,23 +111,23 @@ function admin_import() {
redirect(page_link_to('admin_import'));
}
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']]))
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
$shifttype_id = $_REQUEST['shifttype_id'];
else {
} else {
error(_('Please select a shift type.'));
redirect(page_link_to('admin_import'));
}
if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start'])))
if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) {
$add_minutes_start = trim($_REQUEST['add_minutes_start']);
else {
} else {
error(_("Please enter an amount of minutes to add to a talk's begin."));
redirect(page_link_to('admin_import'));
}
if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end'])))
if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) {
$add_minutes_end = trim($_REQUEST['add_minutes_end']);
else {
} else {
error(_("Please enter an amount of minutes to add to a talk's end."));
redirect(page_link_to('admin_import'));
}
@ -146,32 +149,32 @@ function admin_import() {
])
]),
'<h3>' . _("Shifts to create") . '</h3>',
table(array(
table([
'day' => _("Day"),
'start' => _("Start"),
'end' => _("End"),
'shifttype' => _('Shift type'),
'title' => _("Title"),
'room' => _("Room")
), shifts_printable($events_new, $shifttypes)),
], shifts_printable($events_new, $shifttypes)),
'<h3>' . _("Shifts to update") . '</h3>',
table(array(
table([
'day' => _("Day"),
'start' => _("Start"),
'end' => _("End"),
'shifttype' => _('Shift type'),
'title' => _("Title"),
'room' => _("Room")
), shifts_printable($events_updated, $shifttypes)),
], shifts_printable($events_updated, $shifttypes)),
'<h3>' . _("Shifts to delete") . '</h3>',
table(array(
table([
'day' => _("Day"),
'start' => _("Start"),
'end' => _("End"),
'shifttype' => _('Shift type'),
'title' => _("Title"),
'room' => _("Room")
), shifts_printable($events_deleted, $shifttypes)),
], shifts_printable($events_deleted, $shifttypes)),
form_submit('submit', _("Import"))
], page_link_to('admin_import') . '&step=import&shifttype_id=' . $shifttype_id . "&add_minutes_end=" . $add_minutes_end . "&add_minutes_start=" . $add_minutes_start);
break;
@ -182,26 +185,27 @@ function admin_import() {
redirect(page_link_to('admin_import'));
}
if (! file_exists($import_file))
if (! file_exists($import_file)) {
redirect(page_link_to('admin_import'));
}
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']]))
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
$shifttype_id = $_REQUEST['shifttype_id'];
else {
} else {
error(_('Please select a shift type.'));
redirect(page_link_to('admin_import'));
}
if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start'])))
if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) {
$add_minutes_start = trim($_REQUEST['add_minutes_start']);
else {
} else {
error(_("Please enter an amount of minutes to add to a talk's begin."));
redirect(page_link_to('admin_import'));
}
if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end'])))
if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) {
$add_minutes_end = trim($_REQUEST['add_minutes_end']);
else {
} else {
error(_("Please enter an amount of minutes to add to a talk's end."));
redirect(page_link_to('admin_import'));
}
@ -209,33 +213,38 @@ function admin_import() {
list($rooms_new, $rooms_deleted) = prepare_rooms($import_file);
foreach ($rooms_new as $room) {
$result = Room_create($room, true, true);
if ($result === false)
if ($result === false) {
engelsystem_error('Unable to create room.');
}
$rooms_import[trim($room)] = sql_id();
}
foreach ($rooms_deleted as $room)
foreach ($rooms_deleted as $room) {
sql_query("DELETE FROM `Room` WHERE `Name`='" . sql_escape($room) . "' LIMIT 1");
}
list($events_new, $events_updated, $events_deleted) = prepare_events($import_file, $shifttype_id, $add_minutes_start, $add_minutes_end);
foreach ($events_new as $event) {
$result = Shift_create($event);
if ($result === false)
if ($result === false) {
engelsystem_error('Unable to create shift.');
}
}
foreach ($events_updated as $event) {
$result = Shift_update_by_psid($event);
if ($result === false)
if ($result === false) {
engelsystem_error('Unable to update shift.');
}
}
foreach ($events_deleted as $event) {
$result = Shift_delete_by_psid($event['PSID']);
if ($result === false)
if ($result === false) {
engelsystem_error('Unable to delete shift.');
}
}
engelsystem_log("Pentabarf import done");
engelsystem_log("Frab import done");
unlink($import_file);
@ -258,30 +267,31 @@ function prepare_rooms($file) {
$data = read_xml($file);
// Load rooms from db for compare with input
$rooms = sql_select("SELECT * FROM `Room` WHERE `FromPentabarf`='Y'");
$rooms_db = array();
$rooms_import = array();
$rooms = sql_select("SELECT * FROM `Room`");
$rooms_db = [];
$rooms_import = [];
foreach ($rooms as $room) {
$rooms_db[] = (string) $room['Name'];
$rooms_import[$room['Name']] = $room['RID'];
}
$events = $data->vcalendar->vevent;
$rooms_pb = array();
$rooms_pb = [];
foreach ($events as $event) {
$rooms_pb[] = (string) $event->location;
if (! isset($rooms_import[trim($event->location)]))
if (! isset($rooms_import[trim($event->location)])) {
$rooms_import[trim($event->location)] = trim($event->location);
}
}
$rooms_pb = array_unique($rooms_pb);
$rooms_new = array_diff($rooms_pb, $rooms_db);
$rooms_deleted = array_diff($rooms_db, $rooms_pb);
return array(
return [
$rooms_new,
$rooms_deleted
);
];
}
function prepare_events($file, $shifttype_id, $add_minutes_start, $add_minutes_end) {
@ -289,17 +299,18 @@ function prepare_events($file, $shifttype_id, $add_minutes_start, $add_minutes_e
$data = read_xml($file);
$rooms = sql_select("SELECT * FROM `Room`");
$rooms_db = array();
foreach ($rooms as $room)
$rooms_db = [];
foreach ($rooms as $room) {
$rooms_db[$room['Name']] = $room['RID'];
}
$events = $data->vcalendar->vevent;
$shifts_pb = array();
$shifts_pb = [];
foreach ($events as $event) {
$event_pb = $event->children("http://pentabarf.org");
$event_id = trim($event_pb->{
'event-id' });
$shifts_pb[$event_id] = array(
$shifts_pb[$event_id] = [
'shifttype_id' => $shifttype_id,
'start' => DateTime::createFromFormat("Ymd\THis", $event->dtstart)->getTimestamp() - $add_minutes_start * 60,
'end' => DateTime::createFromFormat("Ymd\THis", $event->dtend)->getTimestamp() + $add_minutes_end * 60,
@ -307,41 +318,47 @@ function prepare_events($file, $shifttype_id, $add_minutes_start, $add_minutes_e
'title' => trim($event->summary),
'URL' => trim($event->url),
'PSID' => $event_id
);
];
}
$shifts = sql_select("SELECT * FROM `Shifts` WHERE `PSID` IS NOT NULL ORDER BY `start`");
$shifts_db = array();
foreach ($shifts as $shift)
$shifts_db = [];
foreach ($shifts as $shift) {
$shifts_db[$shift['PSID']] = $shift;
}
$shifts_new = [];
$shifts_updated = [];
foreach ($shifts_pb as $shift)
if (! isset($shifts_db[$shift['PSID']]))
foreach ($shifts_pb as $shift) {
if (! isset($shifts_db[$shift['PSID']])) {
$shifts_new[] = $shift;
else {
} else {
$tmp = $shifts_db[$shift['PSID']];
if ($shift['shifttype_id'] != $tmp['shifttype_id'] || $shift['title'] != $tmp['title'] || $shift['start'] != $tmp['start'] || $shift['end'] != $tmp['end'] || $shift['RID'] != $tmp['RID'] || $shift['URL'] != $tmp['URL'])
if ($shift['shifttype_id'] != $tmp['shifttype_id'] || $shift['title'] != $tmp['title'] || $shift['start'] != $tmp['start'] || $shift['end'] != $tmp['end'] || $shift['RID'] != $tmp['RID'] || $shift['URL'] != $tmp['URL']) {
$shifts_updated[] = $shift;
}
}
}
$shifts_deleted = array();
foreach ($shifts_db as $shift)
if (! isset($shifts_pb[$shift['PSID']]))
$shifts_deleted = [];
foreach ($shifts_db as $shift) {
if (! isset($shifts_pb[$shift['PSID']])) {
$shifts_deleted[] = $shift;
}
}
return array(
return [
$shifts_new,
$shifts_updated,
$shifts_deleted
);
];
}
function read_xml($file) {
global $xml_import;
if (! isset($xml_import))
if (! isset($xml_import)) {
$xml_import = simplexml_load_file($file);
}
return $xml_import;
}
@ -351,9 +368,9 @@ function shifts_printable($shifts, $shifttypes) {
uasort($shifts, 'shift_sort');
$shifts_printable = array();
foreach ($shifts as $shift)
$shifts_printable[] = array(
$shifts_printable = [];
foreach ($shifts as $shift) {
$shifts_printable[] = [
'day' => date("l, Y-m-d", $shift['start']),
'start' => date("H:i", $shift['start']),
'shifttype' => ShiftType_name_render([
@ -363,7 +380,8 @@ function shifts_printable($shifts, $shifttypes) {
'title' => shorten($shift['title']),
'end' => date("H:i", $shift['end']),
'room' => $rooms[$shift['RID']]
);
];
}
return $shifts_printable;
}

@ -1,10 +1,10 @@
<?php
function admin_log_title() {
return _("Log");
}
function admin_log() {
if (isset($_POST['keyword'])) {
$filter = $_POST['keyword'];
$log_entries_source = LogEntries_filter($_POST['keyword']);
@ -13,23 +13,23 @@ function admin_log() {
$log_entries_source = LogEntries();
}
$log_entries = array();
$log_entries = [];
foreach ($log_entries_source as $log_entry) {
$log_entry['date'] = date("d.m.Y H:i", $log_entry['timestamp']);
$log_entries[] = $log_entry;
}
return page_with_title(admin_log_title(), array(
return page_with_title(admin_log_title(), [
msg(),
form(array(
form([
form_text('keyword', _("Search"), $filter),
form_submit(_("Search"), "Go")
)),
table(array(
]),
table([
'date' => "Time",
'nick' => "Angel",
'message' => "Log Entry"
), $log_entries)
));
], $log_entries)
]);
}
?>

@ -1,4 +1,5 @@
<?php
function admin_news() {
global $user;
@ -6,10 +7,11 @@ function admin_news() {
redirect(page_link_to("news"));
} else {
$html = '<div class="col-md-12"><h1>' . _("Edit news entry") . '</h1>' . msg();
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id']))
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
$id = $_REQUEST['id'];
else
} else {
return error("Incomplete call, missing News ID.", true);
}
$news = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($id) . "' LIMIT 1");
if (count($news) > 0) {
@ -20,17 +22,18 @@ function admin_news() {
list($news) = $news;
$user_source = User($news['UID']);
if ($user_source === false)
if ($user_source === false) {
engelsystem_error("Unable to load user.");
}
$html .= form(array(
$html .= form([
form_info(_("Date"), date("Y-m-d H:i", $news['Datum'])),
form_info(_("Author"), User_Nick_render($user_source)),
form_text('eBetreff', _("Subject"), $news['Betreff']),
form_textarea('eText', _("Message"), $news['Text']),
form_checkbox('eTreffen', _("Meeting"), $news['Treffen'] == 1, 1),
form_submit('submit', _("Save"))
), page_link_to('admin_news&action=save&id=' . $id));
], page_link_to('admin_news&action=save&id=' . $id));
$html .= '<a class="btn btn-danger" href="' . page_link_to('admin_news&action=delete&id=' . $id) . '"><span class="glyphicon glyphicon-trash"></span> ' . _("Delete") . '</a>';
break;

@ -1,4 +1,5 @@
<?php
function admin_questions_title() {
return _("Answer questions");
}
@ -9,9 +10,10 @@ function admin_new_questions() {
if (in_array("admin_questions", $privileges)) {
$new_messages = sql_num_query("SELECT * FROM `Questions` WHERE `AID` IS NULL");
if ($new_messages > 0)
if ($new_messages > 0) {
return info('<a href="' . page_link_to("admin_questions") . '">' . _('There are unanswered questions!') . '</a>', true);
}
}
return "";
}
@ -24,63 +26,67 @@ function admin_questions() {
$questions = sql_select("SELECT * FROM `Questions` WHERE `AID` IS NULL");
foreach ($questions as $question) {
$user_source = User($question['UID']);
if ($user_source === false)
if ($user_source === false) {
engelsystem_error("Unable to load user.");
}
$unanswered_questions_table[] = array(
$unanswered_questions_table[] = [
'from' => User_Nick_render($user_source),
'question' => str_replace("\n", "<br />", $question['Question']),
'answer' => form(array(
'answer' => form([
form_textarea('answer', '', ''),
form_submit('submit', _("Save"))
), page_link_to('admin_questions') . '&action=answer&id=' . $question['QID']),
], page_link_to('admin_questions') . '&action=answer&id=' . $question['QID']),
'actions' => button(page_link_to("admin_questions") . '&action=delete&id=' . $question['QID'], _("delete"), 'btn-xs')
);
];
}
$answered_questions_table = array();
$answered_questions_table = [];
$questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL");
foreach ($questions as $question) {
$user_source = User($question['UID']);
if ($user_source === false)
if ($user_source === false) {
engelsystem_error("Unable to load user.");
}
$answer_user_source = User($question['AID']);
if ($answer_user_source === false)
if ($answer_user_source === false) {
engelsystem_error("Unable to load user.");
$answered_questions_table[] = array(
}
$answered_questions_table[] = [
'from' => User_Nick_render($user_source),
'question' => str_replace("\n", "<br />", $question['Question']),
'answered_by' => User_Nick_render($answer_user_source),
'answer' => str_replace("\n", "<br />", $question['Answer']),
'actions' => button(page_link_to("admin_questions") . '&action=delete&id=' . $question['QID'], _("delete"), 'btn-xs')
);
];
}
return page_with_title(admin_questions_title(), array(
return page_with_title(admin_questions_title(), [
'<h2>' . _("Unanswered questions") . '</h2>',
table(array(
table([
'from' => _("From"),
'question' => _("Question"),
'answer' => _("Answer"),
'actions' => ''
), $unanswered_questions_table),
], $unanswered_questions_table),
'<h2>' . _("Answered questions") . '</h2>',
table(array(
table([
'from' => _("From"),
'question' => _("Question"),
'answered_by' => _("Answered by"),
'answer' => _("Answer"),
'actions' => ''
), $answered_questions_table)
));
], $answered_questions_table)
]);
} else {
switch ($_REQUEST['action']) {
case 'answer':
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id']))
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
$id = $_REQUEST['id'];
else
} else {
return error("Incomplete call, missing Question ID.", true);
}
$question = sql_select("SELECT * FROM `Questions` WHERE `QID`='" . sql_escape($id) . "' LIMIT 1");
if (count($question) > 0 && $question[0]['AID'] == null) {
@ -90,24 +96,28 @@ function admin_questions() {
sql_query("UPDATE `Questions` SET `AID`='" . sql_escape($user['UID']) . "', `Answer`='" . sql_escape($answer) . "' WHERE `QID`='" . sql_escape($id) . "' LIMIT 1");
engelsystem_log("Question " . $question[0]['Question'] . " answered: " . $answer);
redirect(page_link_to("admin_questions"));
} else
return error("Gib eine Antwort ein!", true);
} else
} else {
return error("Enter an answer!", true);
}
} else {
return error("No question found.", true);
}
break;
case 'delete':
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id']))
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
$id = $_REQUEST['id'];
else
} else {
return error("Incomplete call, missing Question ID.", true);
}
$question = sql_select("SELECT * FROM `Questions` WHERE `QID`='" . sql_escape($id) . "' LIMIT 1");
if (count($question) > 0) {
sql_query("DELETE FROM `Questions` WHERE `QID`='" . sql_escape($id) . "' LIMIT 1");
engelsystem_log("Question deleted: " . $question[0]['Question']);
redirect(page_link_to("admin_questions"));
} else
} else {
return error("No question found.", true);
}
break;
}
}

@ -6,17 +6,18 @@ function admin_rooms_title() {
function admin_rooms() {
$rooms_source = sql_select("SELECT * FROM `Room` ORDER BY `Name`");
$rooms = array();
foreach ($rooms_source as $room)
$rooms[] = array(
$rooms = [];
foreach ($rooms_source as $room) {
$rooms[] = [
'name' => $room['Name'],
'from_pentabarf' => $room['FromPentabarf'] == 'Y' ? '&#10003;' : '',
'public' => $room['show'] == 'Y' ? '&#10003;' : '',
'actions' => buttons(array(
'actions' => buttons([
button(page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'], _("edit"), 'btn-xs'),
button(page_link_to('admin_rooms') . '&show=delete&id=' . $room['RID'], _("delete"), 'btn-xs')
))
);
])
];
}
$room = null;
if (isset($_REQUEST['show'])) {
@ -27,8 +28,8 @@ function admin_rooms() {
$number = "";
$angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
$angeltypes = array();
$angeltypes_count = array();
$angeltypes = [];
$angeltypes_count = [];
foreach ($angeltypes_source as $angeltype) {
$angeltypes[$angeltype['id']] = $angeltype['name'];
$angeltypes_count[$angeltype['id']] = 0;
@ -43,11 +44,13 @@ function admin_rooms() {
$public = $room[0]['show'];
$number = $room[0]['Number'];
$needed_angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($id) . "'");
foreach ($needed_angeltypes as $needed_angeltype)
foreach ($needed_angeltypes as $needed_angeltype) {
$angeltypes_count[$needed_angeltype['angel_type_id']] = $needed_angeltype['count'];
} else
}
} else {
redirect(page_link_to('admin_rooms'));
}
}
if ($_REQUEST['show'] == 'edit') {
if (isset($_REQUEST['submit'])) {
@ -64,25 +67,28 @@ function admin_rooms() {
$msg .= error(_("Please enter a name."), true);
}
if (isset($_REQUEST['from_pentabarf']))
if (isset($_REQUEST['from_pentabarf'])) {
$from_pentabarf = 'Y';
else
} else {
$from_pentabarf = '';
}
if (isset($_REQUEST['public']))
if (isset($_REQUEST['public'])) {
$public = 'Y';
else
} else {
$public = '';
}
if (isset($_REQUEST['number']))
if (isset($_REQUEST['number'])) {
$number = strip_request_item('number');
else
} else {
$ok = false;
}
foreach ($angeltypes as $angeltype_id => $angeltype) {
if (isset($_REQUEST['angeltype_count_' . $angeltype_id]) && preg_match("/^[0-9]{1,4}$/", $_REQUEST['angeltype_count_' . $angeltype_id]))
if (isset($_REQUEST['angeltype_count_' . $angeltype_id]) && preg_match("/^[0-9]{1,4}$/", $_REQUEST['angeltype_count_' . $angeltype_id])) {
$angeltypes_count[$angeltype_id] = $_REQUEST['angeltype_count_' . $angeltype_id];
else {
} else {
$ok = false;
$msg .= error(sprintf(_("Please enter needed angels for type %s.", $angeltype)), true);
}
@ -94,8 +100,9 @@ function admin_rooms() {
engelsystem_log("Room updated: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number);
} else {
$id = Room_create($name, $from_pentabarf, $public, $number);
if ($id === false)
if ($id === false) {
engelsystem_error("Unable to create room.");
}
engelsystem_log("Room created: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number);
}
@ -103,8 +110,9 @@ function admin_rooms() {
$needed_angeltype_info = array();
foreach ($angeltypes_count as $angeltype_id => $angeltype_count) {
$angeltype = AngelType($angeltype_id);
if ($angeltype === false)
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype != null) {
sql_query("INSERT INTO `NeededAngelTypes` SET `room_id`='" . sql_escape($id) . "', `angel_type_id`='" . sql_escape($angeltype_id) . "', `count`='" . sql_escape($angeltype_count) . "'");
$needed_angeltype_info[] = $angeltype['name'] . ": " . $angeltype_count;
@ -116,70 +124,72 @@ function admin_rooms() {
redirect(page_link_to("admin_rooms"));
}
}
$angeltypes_count_form = array();
foreach ($angeltypes as $angeltype_id => $angeltype)
$angeltypes_count_form[] = div('col-lg-4 col-md-6 col-xs-6', array(
$angeltypes_count_form = [];
foreach ($angeltypes as $angeltype_id => $angeltype) {
$angeltypes_count_form[] = div('col-lg-4 col-md-6 col-xs-6', [
form_spinner('angeltype_count_' . $angeltype_id, $angeltype, $angeltypes_count[$angeltype_id])
));
]);
}
return page_with_title(admin_rooms_title(), array(
buttons(array(
return page_with_title(admin_rooms_title(), [
buttons([
button(page_link_to('admin_rooms'), _("back"), 'back')
)),
]),
$msg,
form(array(
div('row', array(
div('col-md-6', array(
form([
div('row', [
div('col-md-6', [
form_text('name', _("Name"), $name),
form_checkbox('from_pentabarf', _("Frab import"), $from_pentabarf),
form_checkbox('public', _("Public"), $public),
form_text('number', _("Room number"), $number)
)),
div('col-md-6', array(
div('row', array(
div('col-md-12', array(
]),
div('col-md-6', [
div('row', [
div('col-md-12', [
form_info(_("Needed angels:"))
)),
]),
join($angeltypes_count_form)
))
))
)),
])
])
]),
form_submit('submit', _("Save"))
))
));
])
]);
} elseif ($_REQUEST['show'] == 'delete') {
if (isset($_REQUEST['ack'])) {
if (! Room_delete($id))
if (! Room_delete($id)) {
engelsystem_error("Unable to delete room.");
}
engelsystem_log("Room deleted: " . $name);
success(sprintf(_("Room %s deleted."), $name));
redirect(page_link_to('admin_rooms'));
}
return page_with_title(admin_rooms_title(), array(
buttons(array(
return page_with_title(admin_rooms_title(), [
buttons([
button(page_link_to('admin_rooms'), _("back"), 'back')
)),
]),
sprintf(_("Do you want to delete room %s?"), $name),
buttons(array(
buttons([
button(page_link_to('admin_rooms') . '&show=delete&id=' . $id . '&ack', _("Delete"), 'delete')
))
));
])
]);
}
}
return page_with_title(admin_rooms_title(), array(
buttons(array(
return page_with_title(admin_rooms_title(), [
buttons([
button(page_link_to('admin_rooms') . '&show=edit', _("add"))
)),
]),
msg(),
table(array(
table([
'name' => _("Name"),
'from_pentabarf' => _("Frab import"),
'public' => _("Public"),
'actions' => ""
), $rooms)
));
], $rooms)
]);
}
?>

@ -14,40 +14,46 @@ function admin_shifts() {
$mode = 'single';
$angelmode = 'manually';
$length = '';
$change_hours = array();
$change_hours = [];
$title = "";
$shifttype_id = null;
// Locations laden (auch unsichtbare - fuer Erzengel ist das ok)
$rooms = sql_select("SELECT * FROM `Room` ORDER BY `Name`");
$room_array = array();
foreach ($rooms as $room)
$room_array = [];
foreach ($rooms as $room) {
$room_array[$room['RID']] = $room['Name'];
}
// Engeltypen laden
$types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
$needed_angel_types = array();
foreach ($types as $type)
$needed_angel_types = [];
foreach ($types as $type) {
$needed_angel_types[$type['id']] = 0;
}
// Load shift types
$shifttypes_source = ShiftTypes();
if ($shifttypes_source === false)
if ($shifttypes_source === false) {
engelsystem_error('Unable to load shift types.');
}
$shifttypes = [];
foreach ($shifttypes_source as $shifttype)
foreach ($shifttypes_source as $shifttype) {
$shifttypes[$shifttype['id']] = $shifttype['name'];
}
if (isset($_REQUEST['preview']) || isset($_REQUEST['back'])) {
if (isset($_REQUEST['shifttype_id'])) {
$shifttype = ShiftType($_REQUEST['shifttype_id']);
if ($shifttype === false)
if ($shifttype === false) {
engelsystem_error('Unable to load shift type.');
}
if ($shifttype == null) {
$ok = false;
error(_('Please select a shift type.'));
} else
} else {
$shifttype_id = $_REQUEST['shifttype_id'];
}
} else {
$ok = false;
error(_('Please select a shift type.'));
@ -57,24 +63,24 @@ function admin_shifts() {
$title = strip_request_item('title');
// Auswahl der sichtbaren Locations für die Schichten
if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room_array[$_REQUEST['rid']]))
if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room_array[$_REQUEST['rid']])) {
$rid = $_REQUEST['rid'];
else {
} else {
$ok = false;
$rid = $rooms[0]['RID'];
error(_('Please select a location.'));
}
if (isset($_REQUEST['start']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['start'])))
if (isset($_REQUEST['start']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['start']))) {
$start = $tmp->getTimestamp();
else {
} else {
$ok = false;
error(_('Please select a start time.'));
}
if (isset($_REQUEST['end']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['end'])))
if (isset($_REQUEST['end']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['end']))) {
$end = $tmp->getTimestamp();
else {
} else {
$ok = false;
error(_('Please select an end time.'));
}
@ -136,43 +142,47 @@ function admin_shifts() {
}
// Beim Zurück-Knopf das Formular zeigen
if (isset($_REQUEST['back']))
if (isset($_REQUEST['back'])) {
$ok = false;
}
// Alle Eingaben in Ordnung
if ($ok) {
if ($angelmode == 'location') {
$needed_angel_types = array();
$needed_angel_types = [];
$needed_angel_types_location = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($rid) . "'");
foreach ($needed_angel_types_location as $type)
foreach ($needed_angel_types_location as $type) {
$needed_angel_types[$type['angel_type_id']] = $type['count'];
}
$shifts = array();
}
$shifts = [];
if ($mode == 'single') {
$shifts[] = array(
$shifts[] = [
'start' => $start,
'end' => $end,
'RID' => $rid,
'title' => $title,
'shifttype_id' => $shifttype_id
);
];
} elseif ($mode == 'multi') {
$shift_start = $start;
do {
$shift_end = $shift_start + $length * 60;
if ($shift_end > $end)
if ($shift_end > $end) {
$shift_end = $end;
if ($shift_start >= $shift_end)
}
if ($shift_start >= $shift_end) {
break;
}
$shifts[] = array(
$shifts[] = [
'start' => $shift_start,
'end' => $shift_end,
'RID' => $rid,
'title' => $title,
'shifttype_id' => $shifttype_id
);
];
$shift_start = $shift_end;
} while ($shift_end < $end);
@ -182,50 +192,54 @@ function admin_shifts() {
$change_index = 0;
// Ersten/nächsten passenden Schichtwechsel suchen
foreach ($change_hours as $i => $change_hour) {
if ($start < $day + $change_hour * 60 * 60)
if ($start < $day + $change_hour * 60 * 60) {
$change_index = $i;
elseif ($start == $day + $change_hour * 60 * 60) {
} elseif ($start == $day + $change_hour * 60 * 60) {
// Start trifft Schichtwechsel
$change_index = ($i + count($change_hours) - 1) % count($change_hours);
break;
} else
} else {
break;
}
}
$shift_start = $start;
do {
$day = DateTime::createFromFormat("Y-m-d H:i", date("Y-m-d", $shift_start) . " 00:00")->getTimestamp();
$shift_end = $day + $change_hours[$change_index] * 60 * 60;
if ($shift_end > $end)
if ($shift_end > $end) {
$shift_end = $end;
if ($shift_start >= $shift_end)
}
if ($shift_start >= $shift_end) {
$shift_end += 24 * 60 * 60;
}
$shifts[] = array(
$shifts[] = [
'start' => $shift_start,
'end' => $shift_end,
'RID' => $rid,
'title' => $title,
'shifttype_id' => $shifttype_id
);
];
$shift_start = $shift_end;
$change_index = ($change_index + count($change_hours) - 1) % count($change_hours);
} while ($shift_end < $end);
}
$shifts_table = array();
$shifts_table = [];
foreach ($shifts as $shift) {
$shifts_table_entry = [
'timeslot' => '<span class="glyphicon glyphicon-time"></span> ' . date("Y-m-d H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . '<br />' . Room_name_render(Room($shift['RID'])),
'title' => ShiftType_name_render(ShiftType($shifttype_id)) . ($shift['title'] ? '<br />' . $shift['title'] : ''),
'needed_angels' => ''
];
foreach ($types as $type)
if (isset($needed_angel_types[$type['id']]) && $needed_angel_types[$type['id']] > 0)
foreach ($types as $type) {
if (isset($needed_angel_types[$type['id']]) && $needed_angel_types[$type['id']] > 0) {
$shifts_table_entry['needed_angels'] .= '<b>' . AngelType_name_render($type) . ':</b> ' . $needed_angel_types[$type['id']] . '<br />';
}
}
$shifts_table[] = $shifts_table_entry;
}
@ -234,10 +248,11 @@ function admin_shifts() {
$_SESSION['admin_shifts_types'] = $needed_angel_types;
$hidden_types = "";
foreach ($needed_angel_types as $type_id => $count)
foreach ($needed_angel_types as $type_id => $count) {
$hidden_types .= form_hidden('type_' . $type_id, $count);
return page_with_title(_("Preview"), array(
form(array(
}
return page_with_title(_("Preview"), [
form([
$hidden_types,
form_hidden('shifttype_id', $shifttype_id),
form_hidden('title', $title),
@ -249,28 +264,30 @@ function admin_shifts() {
form_hidden('change_hours', implode(', ', $change_hours)),
form_hidden('angelmode', $angelmode),
form_submit('back', _("back")),
table(array(
table([
'timeslot' => _('Time and location'),
'title' => _('Type and title'),
'needed_angels' => _('Needed angels')
), $shifts_table),
], $shifts_table),
form_submit('submit', _("Save"))
))
));
])
]);
}
} elseif (isset($_REQUEST['submit'])) {
if (! is_array($_SESSION['admin_shifts_shifts']) || ! is_array($_SESSION['admin_shifts_types']))
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) {
$shift['URL'] = null;
$shift['PSID'] = null;
$shift_id = Shift_create($shift);
if ($shift_id === false)
if ($shift_id === false) {
engelsystem_error('Unable to create shift.');
}
engelsystem_log("Shift created: " . $shifttypes[$shift['shifttype_id']] . " with title " . $shift['title'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
$needed_angel_types_info = array();
$needed_angel_types_info = [];
foreach ($_SESSION['admin_shifts_types'] as $type_id => $count) {
$angel_type_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($type_id) . "' LIMIT 1");
if (count($angel_type_source) > 0) {
@ -288,20 +305,22 @@ function admin_shifts() {
unset($_SESSION['admin_shifts_types']);
}
if (! isset($_REQUEST['rid']))
if (! isset($_REQUEST['rid'])) {
$_REQUEST['rid'] = null;
}
$angel_types = "";
foreach ($types as $type)
foreach ($types as $type) {
$angel_types .= '<div class="col-md-4">' . form_spinner('type_' . $type['id'], $type['name'], $needed_angel_types[$type['id']]) . '</div>';
}
return page_with_title(admin_shifts_title(), array(
return page_with_title(admin_shifts_title(), [
msg(),
form(array(
form([
form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id),
form_text('title', _("Title"), $title),
form_select('rid', _("Room"), $room_array, $_REQUEST['rid']),
'<div class="row">',
'<div class="col-md-6">',
div('row', [
div('col-md-6', [
form_text('start', _("Start"), date("Y-m-d H:i", $start)),
form_text('end', _("End"), date("Y-m-d H:i", $end)),
form_info(_("Mode"), ''),
@ -309,17 +328,19 @@ function admin_shifts() {
form_radio('mode', _("Create multiple shifts"), $mode == 'multi', 'multi'),
form_text('length', _("Length"), ! empty($_REQUEST['length']) ? $_REQUEST['length'] : '120'),
form_radio('mode', _("Create multiple shifts with variable length"), $mode == 'variable', 'variable'),
form_text('change_hours', _("Shift change hours"), ! empty($_REQUEST['change_hours']) ? $_REQUEST['change_hours'] : '00, 04, 08, 10, 12, 14, 16, 18, 20, 22'),
'</div>',
'<div class="col-md-6">',
form_text('change_hours', _("Shift change hours"), ! empty($_REQUEST['change_hours']) ? $_REQUEST['change_hours'] : '00, 04, 08, 10, 12, 14, 16, 18, 20, 22')
]),
div('col-md-6', [
form_info(_("Needed angels"), ''),
form_radio('angelmode', _("Take needed angels from room settings"), $angelmode == 'location', 'location'),
form_radio('angelmode', _("The following angels are needed"), $angelmode == 'manually', 'manually'),
'<div class="row">'.$angel_types.'</div>',
'</div>',
'</div>',
div('row', [
$angel_types
])
])
]),
form_submit('preview', _("Preview"))
))
));
])
]);
}
?>

@ -9,14 +9,16 @@ function admin_user() {
$html = '';
if (! isset($_REQUEST['id']))
if (! isset($_REQUEST['id'])) {
redirect(users_link());
}
$id = $_REQUEST['id'];
if (! isset($_REQUEST['action'])) {
$user_source = User($id);
if ($user_source === false)
if ($user_source === false) {
engelsystem_error('Unable to load user.');
}
if ($user_source == null) {
error(_('This user does not exist.'));
redirect(users_link());
@ -42,10 +44,10 @@ function admin_user() {
$html .= " <tr><td>jabber</td><td>" . "<input type=\"text\" size=\"40\" name=\"ejabber\" value=\"" . $user_source['jabber'] . "\"></td></tr>\n";
$html .= " <tr><td>Size</td><td>" . html_select_key('size', 'eSize', $tshirt_sizes, $user_source['Size']) . "</td></tr>\n";
$options = array(
'1' => "Yes",
'0' => "No"
);
$options = [
'1' => _("Yes"),
'0' => _("No")
];
// Gekommen?
$html .= " <tr><td>Gekommen</td><td>\n";
@ -90,20 +92,23 @@ function admin_user() {
$html .= "<hr />";
$my_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user['UID']) . "' ORDER BY `group_id` LIMIT 1");
if (count($my_highest_group) > 0)
if (count($my_highest_group) > 0) {
$my_highest_group = $my_highest_group[0]['group_id'];
}
$his_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($id) . "' ORDER BY `group_id` LIMIT 1");
if (count($his_highest_group) > 0)
if (count($his_highest_group) > 0) {
$his_highest_group = $his_highest_group[0]['group_id'];
}
if ($id != $user['UID'] && $my_highest_group <= $his_highest_group) {
$html .= "Hier kannst Du die Benutzergruppen des Engels festlegen:<form action=\"" . page_link_to("admin_user") . "&action=save_groups&id=" . $id . "\" method=\"post\">\n";
$html .= '<table>';
$groups = sql_select("SELECT * FROM `Groups` LEFT OUTER JOIN `UserGroups` ON (`UserGroups`.`group_id` = `Groups`.`UID` AND `UserGroups`.`uid` = '" . sql_escape($id) . "') WHERE `Groups`.`UID` >= '" . sql_escape($my_highest_group) . "' ORDER BY `Groups`.`Name`");
foreach ($groups as $group)
foreach ($groups as $group) {
$html .= '<tr><td><input type="checkbox" name="groups[]" value="' . $group['UID'] . '"' . ($group['group_id'] != "" ? ' checked="checked"' : '') . ' /></td><td>' . $group['Name'] . '</td></tr>';
}
$html .= '</table>';
@ -127,18 +132,19 @@ function admin_user() {
if (count($my_highest_group) > 0 && (count($his_highest_group) == 0 || ($my_highest_group[0]['group_id'] <= $his_highest_group[0]['group_id']))) {
$groups_source = sql_select("SELECT * FROM `Groups` LEFT OUTER JOIN `UserGroups` ON (`UserGroups`.`group_id` = `Groups`.`UID` AND `UserGroups`.`uid` = '" . sql_escape($id) . "') WHERE `Groups`.`UID` >= '" . sql_escape($my_highest_group[0]['group_id']) . "' ORDER BY `Groups`.`Name`");
$groups = array();
$grouplist = array();
$groups = [];
$grouplist = [];
foreach ($groups_source as $group) {
$groups[$group['UID']] = $group;
$grouplist[] = $group['UID'];
}
if (! is_array($_REQUEST['groups']))
$_REQUEST['groups'] = array();
if (! is_array($_REQUEST['groups'])) {
$_REQUEST['groups'] = [];
}
sql_query("DELETE FROM `UserGroups` WHERE `uid`='" . sql_escape($id) . "'");
$user_groups_info = array();
$user_groups_info = [];
foreach ($_REQUEST['groups'] as $group) {
if (in_array($group, $grouplist)) {
sql_query("INSERT INTO `UserGroups` SET `uid`='" . sql_escape($id) . "', `group_id`='" . sql_escape($group) . "'");
@ -158,8 +164,9 @@ function admin_user() {
case 'save':
$force_active = $user['force_active'];
if (in_array('admin_active', $privileges))
if (in_array('admin_active', $privileges)) {
$force_active = $_REQUEST['force_active'];
}
$SQL = "UPDATE `User` SET
`Nick` = '" . sql_escape($_POST["eNick"]) . "',
`Name` = '" . sql_escape($_POST["eName"]) . "',
@ -197,8 +204,8 @@ function admin_user() {
}
}
return page_with_title(_('Edit user'), array(
return page_with_title(_("Edit user"), [
$html
));
]);
}
?>

@ -4,6 +4,6 @@ function credits_title() {
}
function guest_credits() {
return template_render('../templates/guest_credits.html', array());
return template_render('../templates/guest_credits.html', []);
}
?>

@ -17,8 +17,9 @@ function guest_register() {
global $tshirt_sizes, $enable_tshirt_size, $default_theme, $user;
$event_config = EventConfig();
if ($event_config === false)
if ($event_config === false) {
engelsystem_error("Unable to load event config.");
}
$msg = "";
$nick = "";
@ -35,16 +36,17 @@ function guest_register() {
$comment = "";
$tshirt_size = '';
$password_hash = "";
$selected_angel_types = array();
$selected_angel_types = [];
$planned_arrival_date = null;
$angel_types_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
$angel_types = array();
$angel_types = [];
foreach ($angel_types_source as $angel_type) {
$angel_types[$angel_type['id']] = $angel_type['name'] . ($angel_type['restricted'] ? " (restricted)" : "");
if (! $angel_type['restricted'])
if (! $angel_type['restricted']) {
$selected_angel_types[] = $angel_type['id'];
}
}
if (isset($_REQUEST['submit'])) {
$ok = true;
@ -71,8 +73,9 @@ function guest_register() {
$msg .= error(_("Please enter your e-mail."), true);
}
if (isset($_REQUEST['email_shiftinfo']))
if (isset($_REQUEST['email_shiftinfo'])) {
$email_shiftinfo = true;
}
if (isset($_REQUEST['jabber']) && strlen(strip_request_item('jabber')) > 0) {
$jabber = strip_request_item('jabber');
@ -83,9 +86,9 @@ function guest_register() {
}
if ($enable_tshirt_size) {
if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']]) && $_REQUEST['tshirt_size'] != '')
if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']]) && $_REQUEST['tshirt_size'] != '') {
$tshirt_size = $_REQUEST['tshirt_size'];
else {
} else {
$ok = false;
$msg .= error(_("Please select your shirt size."), true);
}
@ -108,28 +111,38 @@ function guest_register() {
$msg .= error(_("Please enter your planned date of arrival."), true);
}
$selected_angel_types = array();
foreach (array_keys($angel_types) as $angel_type_id)
if (isset($_REQUEST['angel_types_' . $angel_type_id]))
$selected_angel_types = [];
foreach (array_keys($angel_types) as $angel_type_id) {
if (isset($_REQUEST['angel_types_' . $angel_type_id])) {
$selected_angel_types[] = $angel_type_id;
}
}
// Trivia
if (isset($_REQUEST['lastname']))
if (isset($_REQUEST['lastname'])) {
$lastname = strip_request_item('lastname');
if (isset($_REQUEST['prename']))
}
if (isset($_REQUEST['prename'])) {
$prename = strip_request_item('prename');
if (isset($_REQUEST['age']) && preg_match("/^[0-9]{0,4}$/", $_REQUEST['age']))
}
if (isset($_REQUEST['age']) && preg_match("/^[0-9]{0,4}$/", $_REQUEST['age'])) {
$age = strip_request_item('age');
if (isset($_REQUEST['tel']))
}
if (isset($_REQUEST['tel'])) {
$tel = strip_request_item('tel');
if (isset($_REQUEST['dect']))
}
if (isset($_REQUEST['dect'])) {
$dect = strip_request_item('dect');
if (isset($_REQUEST['mobile']))
}
if (isset($_REQUEST['mobile'])) {
$mobile = strip_request_item('mobile');
if (isset($_REQUEST['hometown']))
}
if (isset($_REQUEST['hometown'])) {
$hometown = strip_request_item('hometown');
if (isset($_REQUEST['comment']))
}
if (isset($_REQUEST['comment'])) {
$comment = strip_request_item_nl('comment');
}
if ($ok) {
sql_query("
@ -160,7 +173,7 @@ function guest_register() {
set_password($user_id, $_REQUEST['password']);
// Assign angel-types
$user_angel_types_info = array();
$user_angel_types_info = [];
foreach ($selected_angel_types as $selected_angel_type_id) {
sql_query("INSERT INTO `UserAngelTypes` SET `user_id`='" . sql_escape($user_id) . "', `angeltype_id`='" . sql_escape($selected_angel_type_id) . "'");
$user_angel_types_info[] = $angel_types[$selected_angel_type_id];
@ -183,77 +196,77 @@ function guest_register() {
}
}
return page_with_title(register_title(), array(
return page_with_title(register_title(), [
_("By completing this form you're registering as a Chaos-Angel. This script will create you an account in the angel task sheduler."),
$msg,
msg(),
form(array(
div('row', array(
div('col-md-6', array(
div('row', array(
div('col-sm-4', array(
form([
div('row', [
div('col-md-6', [
div('row', [
div('col-sm-4', [
form_text('nick', _("Nick") . ' ' . entry_required(), $nick)
)),
div('col-sm-8', array(
]),
div('col-sm-8', [
form_email('mail', _("E-Mail") . ' ' . entry_required(), $mail),
form_checkbox('email_shiftinfo', _("Please send me an email if my shifts change"), $email_shiftinfo)
))
)),
div('row', array(
div('col-sm-6', array(
])
]),
div('row', [
div('col-sm-6', [
form_date('planned_arrival_date', _("Planned date of arrival") . ' ' . entry_required(), $planned_arrival_date, time())
)),
div('col-sm-6', array(
]),
div('col-sm-6', [
$enable_tshirt_size ? form_select('tshirt_size', _("Shirt size") . ' ' . entry_required(), $tshirt_sizes, $tshirt_size) : ''
))
)),
div('row', array(
div('col-sm-6', array(
])
]),
div('row', [
div('col-sm-6', [
form_password('password', _("Password") . ' ' . entry_required())
)),
div('col-sm-6', array(
]),
div('col-sm-6', [
form_password('password2', _("Confirm password") . ' ' . entry_required())
))
)),
])
]),
form_checkboxes('angel_types', _("What do you want to do?") . sprintf(" (<a href=\"%s\">%s</a>)", page_link_to('angeltypes') . '&action=about', _("Description of job types")), $angel_types, $selected_angel_types),
form_info("", _("Restricted angel types need will be confirmed later by an archangel. You can change your selection in the options section."))
)),
div('col-md-6', array(
div('row', array(
div('col-sm-4', array(
]),
div('col-md-6', [
div('row', [
div('col-sm-4', [
form_text('dect', _("DECT"), $dect)
)),
div('col-sm-4', array(
]),
div('col-sm-4', [
form_text('mobile', _("Mobile"), $mobile)
)),
div('col-sm-4', array(
]),
div('col-sm-4', [
form_text('tel', _("Phone"), $tel)
))
)),
])
]),
form_text('jabber', _("Jabber"), $jabber),
div('row', array(
div('col-sm-6', array(
div('row', [
div('col-sm-6', [
form_text('prename', _("First name"), $prename)
)),
div('col-sm-6', array(
]),
div('col-sm-6', [
form_text('lastname', _("Last name"), $lastname)
))
)),
div('row', array(
div('col-sm-3', array(
])
]),
div('row', [
div('col-sm-3', [
form_text('age', _("Age"), $age)
)),
div('col-sm-9', array(
]),
div('col-sm-9', [
form_text('hometown', _("Hometown"), $hometown)
))
)),
])
]),
form_info(entry_required() . ' = ' . _("Entry required!"))
))
)),
])
]),
// form_textarea('comment', _("Did you help at former CCC events and which tasks have you performed then?"), $comment),
form_submit('submit', _("Register"))
))
));
])
]);
}
function entry_required() {

@ -19,8 +19,9 @@ function user_ical() {
engelsystem_error("Key invalid.");
}
if (! in_array('ical', privileges_for_user($user['UID'])))
if (! in_array('ical', privileges_for_user($user['UID']))) {
engelsystem_error("No privilege for ical.");
}
$ical_shifts = load_ical_shifts();

@ -9,9 +9,10 @@ function user_unread_messages() {
if (isset($user)) {
$new_messages = sql_num_query("SELECT * FROM `Messages` WHERE isRead='N' AND `RUID`='" . sql_escape($user['UID']) . "'");
if ($new_messages > 0)
if ($new_messages > 0) {
return ' <span class="badge danger">' . $new_messages . '</span>';
}
}
return '';
}
@ -21,12 +22,13 @@ function user_messages() {
if (! isset($_REQUEST['action'])) {
$users = sql_select("SELECT * FROM `User` WHERE NOT `UID`='" . sql_escape($user['UID']) . "' ORDER BY `Nick`");
$to_select_data = array(
$to_select_data = [
"" => _("Select recipient...")
);
];
foreach ($users as $u)
foreach ($users as $u) {
$to_select_data[$u['UID']] = $u['Nick'];
}
$to_select = html_select_key('to', 'to', $to_select_data, '');
@ -45,70 +47,78 @@ function user_messages() {
foreach ($messages as $message) {
$sender_user_source = User($message['SUID']);
if ($sender_user_source === false)
if ($sender_user_source === false) {
engelsystem_error(_("Unable to load user."));
}
$receiver_user_source = User($message['RUID']);
if ($receiver_user_source === false)
if ($receiver_user_source === false) {
engelsystem_error(_("Unable to load user."));
}
$messages_table_entry = array(
$messages_table_entry = [
'new' => $message['isRead'] == 'N' ? '<span class="glyphicon glyphicon-envelope"></span>' : '',
'timestamp' => date("Y-m-d H:i", $message['Datum']),
'from' => User_Nick_render($sender_user_source),
'to' => User_Nick_render($receiver_user_source),
'text' => str_replace("\n", '<br />', $message['Text'])
);
];
if ($message['RUID'] == $user['UID']) {
if ($message['isRead'] == 'N')
if ($message['isRead'] == 'N') {
$messages_table_entry['actions'] = button(page_link_to("user_messages") . '&action=read&id=' . $message['id'], _("mark as read"), 'btn-xs');
} else
}
} else {
$messages_table_entry['actions'] = button(page_link_to("user_messages") . '&action=delete&id=' . $message['id'], _("delete message"), 'btn-xs');
}
$messages_table[] = $messages_table_entry;
}
return page_with_title(messages_title(), array(
return page_with_title(messages_title(), [
msg(),
sprintf(_("Hello %s, here can you leave messages for other angels"), User_Nick_render($user)),
form(array(
table(array(
form([
table([
'new' => _("New"),
'timestamp' => _("Date"),
'from' => _("Transmitted"),
'to' => _("Recipient"),
'text' => _("Message"),
'actions' => ''
), $messages_table)
), page_link_to('user_messages') . '&action=send')
));
], $messages_table)
], page_link_to('user_messages') . '&action=send')
]);
} else {
switch ($_REQUEST['action']) {
case "read":
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id']))
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
$id = $_REQUEST['id'];
else
} else {
return error(_("Incomplete call, missing Message ID."), true);
}
$message = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($id) . "' LIMIT 1");
if (count($message) > 0 && $message[0]['RUID'] == $user['UID']) {
sql_query("UPDATE `Messages` SET `isRead`='Y' WHERE `id`='" . sql_escape($id) . "' LIMIT 1");
redirect(page_link_to("user_messages"));
} else
} else {
return error(_("No Message found."), true);
}
break;
case "delete":
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id']))
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
$id = $_REQUEST['id'];
else
} else {
return error(_("Incomplete call, missing Message ID."), true);
}
$message = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($id) . "' LIMIT 1");
if (count($message) > 0 && $message[0]['SUID'] == $user['UID']) {
sql_query("DELETE FROM `Messages` WHERE `id`='" . sql_escape($id) . "' LIMIT 1");
redirect(page_link_to("user_messages"));
} else
} else {
return error(_("No Message found."), true);
}
break;
case "send":

@ -23,10 +23,10 @@ function user_myshifts() {
success(_("Key changed."));
redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']);
}
return page_with_title(_("Reset API key"), array(
return page_with_title(_("Reset API key"), [
error(_("If you reset the key, the url to your iCal- and JSON-export and your atom feed changes! You have to update it in every application using one of these exports."), true),
button(page_link_to('user_myshifts') . '&reset=ack', _("Continue"), 'btn-danger')
));
]);
} elseif (isset($_REQUEST['edit']) && preg_match("/^[0-9]*$/", $_REQUEST['edit'])) {
$id = $_REQUEST['edit'];
$shift = sql_select("SELECT
@ -65,14 +65,15 @@ function user_myshifts() {
$user_source = User($shift['UID']);
if ($ok) {
$result = ShiftEntry_update(array(
$result = ShiftEntry_update([
'id' => $id,
'Comment' => $comment,
'freeloaded' => $freeloaded,
'freeload_comment' => $freeload_comment
));
if ($result === false)
]);
if ($result === false) {
engelsystem_error('Unable to update shift entry.');
}
engelsystem_log("Updated " . User_Nick_render($user_source) . "'s shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']) . " with comment " . $comment . ". Freeloaded: " . ($freeloaded ? "YES Comment: " . $freeload_comment : "NO"));
success(_("Shift saved."));
@ -94,19 +95,22 @@ function user_myshifts() {
$shift = $shift[0];
if (($shift['start'] > time() + $LETZTES_AUSTRAGEN * 3600) || in_array('user_shifts_admin', $privileges)) {
$result = ShiftEntry_delete($id);
if ($result === false)
if ($result === false) {
engelsystem_error('Unable to delete shift entry.');
}
$room = Room($shift['RID']);
$angeltype = AngelType($shift['TID']);
$shifttype = ShiftType($shift['shifttype_id']);
engelsystem_log("Deleted own shift: " . $shifttype['name'] . " at " . $room['Name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']) . " as " . $angeltype['name']);
success(_("Shift canceled."));
} else
} else {
error(_("It's too late to sign yourself off the shift. If neccessary, ask the dispatcher to do so."));
} else
}
} else {
redirect(user_link($shifts_user));
}
}
redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']);
}

@ -1,4 +1,5 @@
<?php
function user_news_comments_title() {
return _("News comments");
}
@ -16,24 +17,27 @@ function user_meetings() {
$html = '<div class="col-md-12"><h1>' . meetings_title() . '</h1>' . msg();
if (isset($_REQUEST['page']) && preg_match("/^[0-9]{1,}$/", $_REQUEST['page']))
if (isset($_REQUEST['page']) && preg_match("/^[0-9]{1,}$/", $_REQUEST['page'])) {
$page = $_REQUEST['page'];
else
} else {
$page = 0;
}
$news = sql_select("SELECT * FROM `News` WHERE `Treffen`=1 ORDER BY `Datum` DESC LIMIT " . sql_escape($page * $DISPLAY_NEWS) . ", " . sql_escape($DISPLAY_NEWS));
foreach ($news as $entry)
foreach ($news as $entry) {
$html .= display_news($entry);
}
$dis_rows = ceil(sql_num_query("SELECT * FROM `News`") / $DISPLAY_NEWS);
$html .= '<div class="text-center">' . '<ul class="pagination">';
for ($i = 0; $i < $dis_rows; $i ++) {
if (isset($_REQUEST['page']) && $i == $_REQUEST['page'])
if (isset($_REQUEST['page']) && $i == $_REQUEST['page']) {
$html .= '<li class="active">';
elseif (! isset($_REQUEST['page']) && $i == 0)
} elseif (! isset($_REQUEST['page']) && $i == 0) {
$html .= '<li class="active">';
else
} else {
$html .= '<li>';
}
$html .= '<a href="' . page_link_to("user_meetings") . '&page=' . $i . '">' . ($i + 1) . '</a></li>';
}
$html .= '</ul></div></div>';
@ -52,18 +56,20 @@ function display_news($news) {
$html .= '<div class="panel-body">' . ReplaceSmilies(nl2br($news['Text'])) . '</div>';
$html .= '<div class="panel-footer text-muted">';
if (in_array("admin_news", $privileges))
if (in_array("admin_news", $privileges)) {
$html .= '<div class="pull-right">' . button_glyph(page_link_to("admin_news") . '&action=edit&id=' . $news['ID'], 'edit', 'btn-xs') . '</div>';
}
$html .= '<span class="glyphicon glyphicon-time"></span> ' . date("Y-m-d H:i", $news['Datum']) . '&emsp;';
$user_source = User($news['UID']);
if ($user_source === false)
if ($user_source === false) {
engelsystem_error(_("Unable to load user."));
}
$html .= User_Nick_render($user_source);
if ($p != "news_comments")
if ($p != "news_comments") {
$html .= '&emsp;<a href="' . page_link_to("news_comments") . '&nid=' . $news['ID'] . '"><span class="glyphicon glyphicon-comment"></span> ' . _("Comments") . ' &raquo;</a> <span class="badge">' . sql_num_query("SELECT * FROM `NewsComments` WHERE `Refid`='" . sql_escape($news['ID']) . "'") . '</span>';
}
$html .= '</div>';
$html .= '</div>';
return $html;
@ -88,8 +94,9 @@ function user_news_comments() {
$comments = sql_select("SELECT * FROM `NewsComments` WHERE `Refid`='" . sql_escape($nid) . "' ORDER BY 'ID'");
foreach ($comments as $comment) {
$user_source = User($comment['UID']);
if ($user_source === false)
if ($user_source === false) {
engelsystem_error(_("Unable to load user."));
}
$html .= '<div class="panel panel-default">';
$html .= '<div class="panel-body">' . nl2br($comment['Text']) . '</div>';
@ -101,11 +108,10 @@ function user_news_comments() {
}
$html .= '<hr /><h2>' . _("New Comment:") . '</h2>';
$html .= form(array(
$html .= form([
form_textarea('text', _("Message"), ''),
form_submit('submit', _("Save"))
), page_link_to('news_comments') . '&nid=' . $news['ID']);
], page_link_to('news_comments') . '&nid=' . $news['ID']);
} else {
$html .= _("Invalid request.");
}
@ -119,32 +125,36 @@ function user_news() {
$html = '<div class="col-md-12"><h1>' . news_title() . '</h1>' . msg();
if (isset($_POST["text"]) && isset($_POST["betreff"]) && in_array("admin_news", $privileges)) {
if (! isset($_POST["treffen"]) || ! in_array("admin_news", $privileges))
if (! isset($_POST["treffen"]) || ! in_array("admin_news", $privileges)) {
$_POST["treffen"] = 0;
}
sql_query("INSERT INTO `News` (`Datum`, `Betreff`, `Text`, `UID`, `Treffen`) " . "VALUES ('" . sql_escape(time()) . "', '" . sql_escape($_POST["betreff"]) . "', '" . sql_escape($_POST["text"]) . "', '" . sql_escape($user['UID']) . "', '" . sql_escape($_POST["treffen"]) . "');");
engelsystem_log("Created news: " . $_POST["betreff"] . ", treffen: " . $_POST["treffen"]);
success(_("Entry saved."));
redirect(page_link_to('news'));
}
if (isset($_REQUEST['page']) && preg_match("/^[0-9]{1,}$/", $_REQUEST['page']))
if (isset($_REQUEST['page']) && preg_match("/^[0-9]{1,}$/", $_REQUEST['page'])) {
$page = $_REQUEST['page'];
else
} else {
$page = 0;
}
$news = sql_select("SELECT * FROM `News` ORDER BY `Datum` DESC LIMIT " . sql_escape($page * $DISPLAY_NEWS) . ", " . sql_escape($DISPLAY_NEWS));
foreach ($news as $entry)
foreach ($news as $entry) {
$html .= display_news($entry);
}
$dis_rows = ceil(sql_num_query("SELECT * FROM `News`") / $DISPLAY_NEWS);
$html .= '<div class="text-center">' . '<ul class="pagination">';
for ($i = 0; $i < $dis_rows; $i ++) {
if (isset($_REQUEST['page']) && $i == $_REQUEST['page'])
if (isset($_REQUEST['page']) && $i == $_REQUEST['page']) {
$html .= '<li class="active">';
elseif (! isset($_REQUEST['page']) && $i == 0)
} elseif (! isset($_REQUEST['page']) && $i == 0) {
$html .= '<li class="active">';
else
} else {
$html .= '<li>';
}
$html .= '<a href="' . page_link_to("news") . '&page=' . $i . '">' . ($i + 1) . '</a></li>';
}
$html .= '</ul></div>';
@ -153,12 +163,12 @@ function user_news() {
$html .= '<hr />';
$html .= '<h2>' . _("Create news:") . '</h2>';
$html .= form(array(
$html .= form([
form_text('betreff', _("Subject"), ''),
form_textarea('text', _("Message"), ''),
form_checkbox('treffen', _("Meeting"), false, 1),
form_submit('submit', _("Save"))
));
]);
}
return $html . '</div>';
}

@ -1,4 +1,5 @@
<?php
function questions_title() {
return _("Ask an archangel");
}
@ -12,8 +13,9 @@ function user_questions() {
$answered_questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL AND `UID`='" . sql_escape($user['UID']) . "'");
foreach ($answered_questions as &$question) {
$answer_user_source = User($question['AID']);
if ($answer_user_source === false)
if ($answer_user_source === false) {
engelsystem_error(_("Unable to load user."));
}
$question['answer_user'] = User_Nick_render($answer_user_source);
}
@ -24,29 +26,33 @@ function user_questions() {
$question = strip_request_item_nl('question');
if ($question != "") {
$result = sql_query("INSERT INTO `Questions` SET `UID`='" . sql_escape($user['UID']) . "', `Question`='" . sql_escape($question) . "'");
if ($result === false)
if ($result === false) {
engelsystem_error(_("Unable to save question."));
}
success(_("You question was saved."));
redirect(page_link_to("user_questions"));
} else
return page_with_title(questions_title(), array(
} else {
return page_with_title(questions_title(), [
error(_("Please enter a question!"), true)
));
]);
}
break;
case 'delete':
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id']))
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
$id = $_REQUEST['id'];
else
} else {
return error(_("Incomplete call, missing Question ID."), true);
}
$question = sql_select("SELECT * FROM `Questions` WHERE `QID`='" . sql_escape($id) . "' LIMIT 1");
if (count($question) > 0 && $question[0]['UID'] == $user['UID']) {
sql_query("DELETE FROM `Questions` WHERE `QID`='" . sql_escape($id) . "' LIMIT 1");
redirect(page_link_to("user_questions"));
} else
return page_with_title(questions_title(), array(
} else {
return page_with_title(questions_title(), [
error(_("No question found."), true)
));
]);
}
break;
}
}

@ -50,9 +50,9 @@ function user_settings() {
}
}
if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']]))
if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']])) {
$tshirt_size = $_REQUEST['tshirt_size'];
elseif ($enable_tshirt_size) {
} elseif ($enable_tshirt_size) {
$ok = false;
}
@ -70,24 +70,32 @@ function user_settings() {
$ok = false;
$msg .= error(_("Please enter your planned date of departure."), true);
}
} else
} else {
$planned_departure_date = null;
}
// Trivia
if (isset($_REQUEST['lastname']))
if (isset($_REQUEST['lastname'])) {
$lastname = strip_request_item('lastname');
if (isset($_REQUEST['prename']))
}
if (isset($_REQUEST['prename'])) {
$prename = strip_request_item('prename');
if (isset($_REQUEST['age']) && preg_match("/^[0-9]{0,4}$/", $_REQUEST['age']))
}
if (isset($_REQUEST['age']) && preg_match("/^[0-9]{0,4}$/", $_REQUEST['age'])) {
$age = strip_request_item('age');
if (isset($_REQUEST['tel']))
}
if (isset($_REQUEST['tel'])) {
$tel = strip_request_item('tel');
if (isset($_REQUEST['dect']))
}
if (isset($_REQUEST['dect'])) {
$dect = strip_request_item('dect');
if (isset($_REQUEST['mobile']))
}
if (isset($_REQUEST['mobile'])) {
$mobile = strip_request_item('mobile');
if (isset($_REQUEST['hometown']))
}
if (isset($_REQUEST['hometown'])) {
$hometown = strip_request_item('hometown');
}
if ($ok) {
sql_query("
@ -114,24 +122,26 @@ function user_settings() {
} elseif (isset($_REQUEST['submit_password'])) {
$ok = true;
if (! isset($_REQUEST['password']) || ! verify_password($_REQUEST['password'], $user['Passwort'], $user['UID']))
if (! isset($_REQUEST['password']) || ! verify_password($_REQUEST['password'], $user['Passwort'], $user['UID'])) {
$msg .= error(_("-> not OK. Please try again."), true);
elseif (strlen($_REQUEST['new_password']) < MIN_PASSWORD_LENGTH)
} elseif (strlen($_REQUEST['new_password']) < MIN_PASSWORD_LENGTH) {
$msg .= error(_("Your password is to short (please use at least 6 characters)."), true);
elseif ($_REQUEST['new_password'] != $_REQUEST['new_password2'])
} elseif ($_REQUEST['new_password'] != $_REQUEST['new_password2']) {
$msg .= error(_("Your passwords don't match."), true);
elseif (set_password($user['UID'], $_REQUEST['new_password']))
} elseif (set_password($user['UID'], $_REQUEST['new_password'])) {
success(_("Password saved."));
else
} else {
error(_("Failed setting password."));
}
redirect(page_link_to('user_settings'));
} elseif (isset($_REQUEST['submit_theme'])) {
$ok = true;
if (isset($_REQUEST['theme']) && isset($themes[$_REQUEST['theme']]))
if (isset($_REQUEST['theme']) && isset($themes[$_REQUEST['theme']])) {
$selected_theme = $_REQUEST['theme'];
else
} else {
$ok = false;
}
if ($ok) {
sql_query("UPDATE `User` SET `color`='" . sql_escape($selected_theme) . "' WHERE `UID`='" . sql_escape($user['UID']) . "'");
@ -142,10 +152,11 @@ function user_settings() {
} elseif (isset($_REQUEST['submit_language'])) {
$ok = true;
if (isset($_REQUEST['language']) && isset($locales[$_REQUEST['language']]))
if (isset($_REQUEST['language']) && isset($locales[$_REQUEST['language']])) {
$selected_language = $_REQUEST['language'];
else
} else {
$ok = false;
}
if ($ok) {
sql_query("UPDATE `User` SET `Sprache`='" . sql_escape($selected_language) . "' WHERE `UID`='" . sql_escape($user['UID']) . "'");
@ -156,12 +167,12 @@ function user_settings() {
}
}
return page_with_title(settings_title(), array(
return page_with_title(settings_title(), [
$msg,
msg(),
div('row', array(
div('col-md-6', array(
form(array(
div('row', [
div('col-md-6', [
form([
form_info('', _("Here you can change your user details.")),
form_info(entry_required() . ' = ' . _("Entry required!")),
form_text('nick', _("Nick"), $nick, true),
@ -180,28 +191,28 @@ function user_settings() {
$enable_tshirt_size ? form_select('tshirt_size', _("Shirt size"), $tshirt_sizes, $tshirt_size) : '',
form_info('', _('Please visit the angeltypes page to manage your angeltypes.')),
form_submit('submit', _("Save"))
))
)),
div('col-md-6', array(
form(array(
])
]),
div('col-md-6', [
form([
form_info(_("Here you can change your password.")),
form_password('password', _("Old password:")),
form_password('new_password', _("New password:")),
form_password('new_password2', _("Password confirmation:")),
form_submit('submit_password', _("Save"))
)),
form(array(
]),
form([
form_info(_("Here you can choose your color settings:")),
form_select('theme', _("Color settings:"), $themes, $selected_theme),
form_submit('submit_theme', _("Save"))
)),
form(array(
]),
form([
form_info(_("Here you can choose your language:")),
form_select('language', _("Language:"), $locales, $selected_language),
form_submit('submit_language', _("Save"))
))
))
))
));
])
])
])
]);
}
?>

@ -7,21 +7,24 @@ function shifts_title() {
function user_shifts() {
global $user, $privileges;
if (User_is_freeloader($user))
if (User_is_freeloader($user)) {
redirect(page_link_to('user_myshifts'));
}
// Locations laden
$rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
$room_array = array();
foreach ($rooms as $room)
$room_array = [];
foreach ($rooms as $room) {
$room_array[$room['RID']] = $room['Name'];
}
// Löschen einzelner Schicht-Einträge (Also Belegung einer Schicht von Engeln) durch Admins
if (isset($_REQUEST['entry_id']) && in_array('user_shifts_admin', $privileges)) {
if (isset($_REQUEST['entry_id']) && test_request_int('entry_id'))
if (isset($_REQUEST['entry_id']) && test_request_int('entry_id')) {
$entry_id = $_REQUEST['entry_id'];
else
} else {
redirect(page_link_to('user_shifts'));
}
$shift_entry_source = sql_select("
SELECT `User`.`Nick`, `ShiftEntry`.`Comment`, `ShiftEntry`.`UID`, `ShiftTypes`.`name`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`name` as `angel_type`
@ -36,37 +39,41 @@ function user_shifts() {
$shift_entry_source = $shift_entry_source[0];
$result = ShiftEntry_delete($entry_id);
if ($result === false)
if ($result === false) {
engelsystem_error('Unable to delete shift entry.');
}
engelsystem_log("Deleted " . User_Nick_render($shift_entry_source) . "'s shift: " . $shift_entry_source['name'] . " at " . $shift_entry_source['Name'] . " from " . date("Y-m-d H:i", $shift_entry_source['start']) . " to " . date("Y-m-d H:i", $shift_entry_source['end']) . " as " . $shift_entry_source['angel_type']);
success(_("Shift entry deleted."));
} else
} else {
error(_("Entry not found."));
}
redirect(page_link_to('user_shifts'));
} // Schicht bearbeiten
elseif (isset($_REQUEST['edit_shift']) && in_array('admin_shifts', $privileges)) {
} elseif (isset($_REQUEST['edit_shift']) && in_array('admin_shifts', $privileges)) {
// Schicht bearbeiten
$msg = "";
$ok = true;
if (isset($_REQUEST['edit_shift']) && test_request_int('edit_shift'))
if (isset($_REQUEST['edit_shift']) && test_request_int('edit_shift')) {
$shift_id = $_REQUEST['edit_shift'];
else
} else {
redirect(page_link_to('user_shifts'));
}
$shift = sql_select("
SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.* FROM `Shifts`
JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
WHERE `SID`='" . sql_escape($shift_id) . "'");
if (count($shift) == 0)
if (count($shift) == 0) {
redirect(page_link_to('user_shifts'));
}
$shift = $shift[0];
// Engeltypen laden
$types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
$angel_types = array();
$needed_angel_types = array();
$angel_types = [];
$needed_angel_types = [];
foreach ($types as $type) {
$angel_types[$type['id']] = $type;
$needed_angel_types[$type['id']] = 0;
@ -74,22 +81,25 @@ function user_shifts() {
$shifttypes_source = ShiftTypes();
$shifttypes = [];
foreach ($shifttypes_source as $shifttype)
foreach ($shifttypes_source as $shifttype) {
$shifttypes[$shifttype['id']] = $shifttype['name'];
}
// Benötigte Engeltypen vom Raum
$needed_angel_types_source = sql_select("SELECT `AngelTypes`.*, `NeededAngelTypes`.`count` FROM `AngelTypes` LEFT JOIN `NeededAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id` AND `NeededAngelTypes`.`room_id`='" . sql_escape($shift['RID']) . "') ORDER BY `AngelTypes`.`name`");
foreach ($needed_angel_types_source as $type) {
if ($type['count'] != "")
if ($type['count'] != "") {
$needed_angel_types[$type['id']] = $type['count'];
}
}
// Benötigte Engeltypen von der Schicht
$needed_angel_types_source = sql_select("SELECT `AngelTypes`.*, `NeededAngelTypes`.`count` FROM `AngelTypes` LEFT JOIN `NeededAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id` AND `NeededAngelTypes`.`shift_id`='" . sql_escape($shift_id) . "') ORDER BY `AngelTypes`.`name`");
foreach ($needed_angel_types_source as $type) {
if ($type['count'] != "")
if ($type['count'] != "") {
$needed_angel_types[$type['id']] = $type['count'];
}
}
$shifttype_id = $shift['shifttype_id'];
$title = $shift['title'];
@ -102,31 +112,31 @@ function user_shifts() {
$title = strip_request_item('title');
// Auswahl der sichtbaren Locations für die Schichten
if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room_array[$_REQUEST['rid']]))
if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room_array[$_REQUEST['rid']])) {
$rid = $_REQUEST['rid'];
else {
} else {
$ok = false;
$rid = $rooms[0]['RID'];
$msg .= error(_("Please select a room."), true);
}
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']]))
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
$shifttype_id = $_REQUEST['shifttype_id'];
else {
} else {
$ok = false;
$msg .= error(_('Please select a shifttype.'), true);
}
if (isset($_REQUEST['start']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['start'])))
if (isset($_REQUEST['start']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['start']))) {
$start = $tmp->getTimestamp();
else {
} else {
$ok = false;
$msg .= error(_("Please enter a valid starting time for the shifts."), true);
}
if (isset($_REQUEST['end']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['end'])))
if (isset($_REQUEST['end']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['end']))) {
$end = $tmp->getTimestamp();
else {
} else {
$ok = false;
$msg .= error(_("Please enter a valid ending time for the shifts."), true);
}
@ -153,10 +163,11 @@ function user_shifts() {
$shift['end'] = $end;
$result = Shift_update($shift);
if ($result === false)
if ($result === false) {
engelsystem_error('Unable to update shift.');
}
sql_query("DELETE FROM `NeededAngelTypes` WHERE `shift_id`='" . sql_escape($shift_id) . "'");
$needed_angel_types_info = array();
$needed_angel_types_info = [];
foreach ($needed_angel_types as $type_id => $count) {
sql_query("INSERT INTO `NeededAngelTypes` SET `shift_id`='" . sql_escape($shift_id) . "', `angel_type_id`='" . sql_escape($type_id) . "', `count`='" . sql_escape($count) . "'");
$needed_angel_types_info[] = $angel_types[$type_id]['name'] . ": " . $count;
@ -172,13 +183,14 @@ function user_shifts() {
}
$angel_types = "";
foreach ($types as $type)
foreach ($types as $type) {
$angel_types .= form_spinner('type_' . $type['id'], $type['name'], $needed_angel_types[$type['id']]);
}
return page_with_title(shifts_title(), array(
return page_with_title(shifts_title(), [
msg(),
'<noscript>' . info(_("This page is much more comfortable with javascript."), true) . '</noscript>',
form(array(
form([
form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id),
form_text('title', _("Title"), $title),
form_select('rid', _("Room:"), $room_array, $rid),
@ -187,62 +199,72 @@ function user_shifts() {
'<h2>' . _("Needed angels") . '</h2>',
$angel_types,
form_submit('submit', _("Save"))
))
));
} // Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg)
elseif (isset($_REQUEST['delete_shift']) && in_array('user_shifts_admin', $privileges)) {
if (isset($_REQUEST['delete_shift']) && preg_match("/^[0-9]*$/", $_REQUEST['delete_shift']))
])
]);
} elseif (isset($_REQUEST['delete_shift']) && in_array('user_shifts_admin', $privileges)) {
// Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg)
if (isset($_REQUEST['delete_shift']) && preg_match("/^[0-9]*$/", $_REQUEST['delete_shift'])) {
$shift_id = $_REQUEST['delete_shift'];
else
} else {
redirect(page_link_to('user_shifts'));
}
$shift = Shift($shift_id);
if ($shift === false)
if ($shift === false) {
engelsystem_error('Unable to load shift.');
if ($shift == null)
}
if ($shift == null) {
redirect(page_link_to('user_shifts'));
}
// Schicht löschen bestätigt
if (isset($_REQUEST['delete'])) {
$result = Shift_delete($shift_id);
if ($result === false)
if ($result === false) {
engelsystem_error('Unable to delete shift.');
}
engelsystem_log("Deleted shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
success(_("Shift deleted."));
redirect(page_link_to('user_shifts'));
}
return page_with_title(shifts_title(), array(
return page_with_title(shifts_title(), [
error(sprintf(_("Do you want to delete the shift %s from %s to %s?"), $shift['name'], date("Y-m-d H:i", $shift['start']), date("H:i", $shift['end'])), true),
'<a class="button" href="?p=user_shifts&delete_shift=' . $shift_id . '&delete">' . _("delete") . '</a>'
));
]);
} elseif (isset($_REQUEST['shift_id'])) {
if (isset($_REQUEST['shift_id']) && preg_match("/^[0-9]*$/", $_REQUEST['shift_id']))
if (isset($_REQUEST['shift_id']) && preg_match("/^[0-9]*$/", $_REQUEST['shift_id'])) {
$shift_id = $_REQUEST['shift_id'];
else
} else {
redirect(page_link_to('user_shifts'));
}
$shift = Shift($shift_id);
$room;
$shift['Name'] = $room_array[$shift['RID']];
if ($shift === false)
if ($shift === false) {
engelsystem_error('Unable to load shift.');
if ($shift == null)
}
if ($shift == null) {
redirect(page_link_to('user_shifts'));
}
if (isset($_REQUEST['type_id']) && preg_match("/^[0-9]*$/", $_REQUEST['type_id']))
if (isset($_REQUEST['type_id']) && preg_match("/^[0-9]*$/", $_REQUEST['type_id'])) {
$type_id = $_REQUEST['type_id'];
else
} else {
redirect(page_link_to('user_shifts'));
}
if (in_array('user_shifts_admin', $privileges))
if (in_array('user_shifts_admin', $privileges)) {
$type = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($type_id) . "' LIMIT 1");
else
} else {
$type = sql_select("SELECT * FROM `UserAngelTypes` JOIN `AngelTypes` ON (`UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`) WHERE `AngelTypes`.`id` = '" . sql_escape($type_id) . "' AND (`AngelTypes`.`restricted` = 0 OR (`UserAngelTypes`.`user_id` = '" . sql_escape($user['UID']) . "' AND NOT `UserAngelTypes`.`confirm_user_id` IS NULL)) LIMIT 1");
}
if (count($type) == 0)
if (count($type) == 0) {
redirect(page_link_to('user_shifts'));
}
$type = $type[0];
if (! Shift_signup_allowed($shift, $type)) {
@ -253,21 +275,26 @@ function user_shifts() {
if (isset($_REQUEST['submit'])) {
$selected_type_id = $type_id;
if (in_array('user_shifts_admin', $privileges)) {
if (isset($_REQUEST['user_id']) && preg_match("/^[0-9]*$/", $_REQUEST['user_id']))
if (isset($_REQUEST['user_id']) && preg_match("/^[0-9]*$/", $_REQUEST['user_id'])) {
$user_id = $_REQUEST['user_id'];
else
} else {
$user_id = $user['UID'];
}
if (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1") == 0)
if (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1") == 0) {
redirect(page_link_to('user_shifts'));
}
if (isset($_REQUEST['angeltype_id']) && test_request_int('angeltype_id') && sql_num_query("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($_REQUEST['angeltype_id']) . "' LIMIT 1") > 0)
if (isset($_REQUEST['angeltype_id']) && test_request_int('angeltype_id') && sql_num_query("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($_REQUEST['angeltype_id']) . "' LIMIT 1") > 0) {
$selected_type_id = $_REQUEST['angeltype_id'];
} else
}
} else {
$user_id = $user['UID'];
}
if (sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `UID` = '" . sql_escape($user_id) . "'"))
if (sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `UID` = '" . sql_escape($user_id) . "'")) {
return error("This angel does already have an entry for this shift.", true);
}
$freeloaded = $shift['freeloaded'];
$freeload_comment = $shift['freeload_comment'];
@ -277,19 +304,21 @@ function user_shifts() {
}
$comment = strip_request_item_nl('comment');
$result = ShiftEntry_create(array(
$result = ShiftEntry_create([
'SID' => $shift_id,
'TID' => $selected_type_id,
'UID' => $user_id,
'Comment' => $comment,
'freeloaded' => $freeloaded,
'freeload_comment' => $freeload_comment
));
if ($result === false)
]);
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) . "')");
}
$user_source = User($user_id);
engelsystem_log("User " . User_Nick_render($user_source) . " signed up for shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
@ -299,16 +328,18 @@ function user_shifts() {
if (in_array('user_shifts_admin', $privileges)) {
$users = sql_select("SELECT *, (SELECT count(*) FROM `ShiftEntry` WHERE `freeloaded`=1 AND `ShiftEntry`.`UID`=`User`.`UID`) AS `freeloaded` FROM `User` ORDER BY `Nick`");
$users_select = array();
$users_select = [];
foreach ($users as $usr)
foreach ($users as $usr) {
$users_select[$usr['UID']] = $usr['Nick'] . ($usr['freeloaded'] == 0 ? "" : " (" . _("Freeloader") . ")");
}
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
$angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
$angeltypes = array();
foreach ($angeltypes_source as $angeltype)
$angeltypes = [];
foreach ($angeltypes_source as $angeltype) {
$angeltypes[$angeltype['id']] = $angeltype['name'];
}
$angeltyppe_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
} else {
$user_text = User_Nick_render($user);
@ -325,7 +356,7 @@ function view_user_shifts() {
global $user, $privileges;
global $ical_shifts;
$ical_shifts = array();
$ical_shifts = [];
$days = sql_select_single_col("
SELECT DISTINCT DATE(FROM_UNIXTIME(`start`)) AS `id`, DATE(FROM_UNIXTIME(`start`)) AS `name`
FROM `Shifts`
@ -343,30 +374,33 @@ function view_user_shifts() {
redirect('?');
}
if (in_array('user_shifts_admin', $privileges))
if (in_array('user_shifts_admin', $privileges)) {
$types = sql_select("SELECT `id`, `name` FROM `AngelTypes` ORDER BY `AngelTypes`.`name`");
else
} else {
$types = sql_select("SELECT `AngelTypes`.`id`, `AngelTypes`.`name`, (`AngelTypes`.`restricted`=0 OR (NOT `UserAngelTypes`.`confirm_user_id` IS NULL OR `UserAngelTypes`.`id` IS NULL)) as `enabled` FROM `AngelTypes` LEFT JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id` AND `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "') ORDER BY `AngelTypes`.`name`");
if (empty($types))
}
if (empty($types)) {
$types = sql_select("SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0");
$filled = array(
array(
}
$filled = [
[
'id' => '1',
'name' => _('occupied')
),
array(
'name' => _("occupied")
],
[
'id' => '0',
'name' => _('free')
)
);
'name' => _("free")
]
];
if (count($types) == 0) {
error(_("The administration has not configured any angeltypes yet - or you are not subscribed to any angeltype."));
redirect('?');
}
if (! isset($_SESSION['user_shifts']))
$_SESSION['user_shifts'] = array();
if (! isset($_SESSION['user_shifts'])) {
$_SESSION['user_shifts'] = [];
}
if (! isset($_SESSION['user_shifts']['filled'])) {
// User shift admins see free and occupied shifts by default
@ -378,65 +412,77 @@ function view_user_shifts() {
];
}
foreach (array(
foreach ([
'rooms',
'types',
'filled'
) as $key) {
] as $key) {
if (isset($_REQUEST[$key])) {
$filtered = array_filter($_REQUEST[$key], 'is_numeric');
if (! empty($filtered))
if (! empty($filtered)) {
$_SESSION['user_shifts'][$key] = $filtered;
}
unset($filtered);
}
if (! isset($_SESSION['user_shifts'][$key]))
if (! isset($_SESSION['user_shifts'][$key])) {
$_SESSION['user_shifts'][$key] = array_map('get_ids_from_array', $$key);
}
}
if (isset($_REQUEST['rooms'])) {
if (isset($_REQUEST['new_style']))
if (isset($_REQUEST['new_style'])) {
$_SESSION['user_shifts']['new_style'] = true;
else
} else {
$_SESSION['user_shifts']['new_style'] = false;
}
if (! isset($_SESSION['user_shifts']['new_style']))
}
if (! isset($_SESSION['user_shifts']['new_style'])) {
$_SESSION['user_shifts']['new_style'] = true;
foreach (array(
}
foreach ([
'start',
'end'
) as $key) {
if (isset($_REQUEST[$key . '_day']) && in_array($_REQUEST[$key . '_day'], $days))
] as $key) {
if (isset($_REQUEST[$key . '_day']) && in_array($_REQUEST[$key . '_day'], $days)) {
$_SESSION['user_shifts'][$key . '_day'] = $_REQUEST[$key . '_day'];
if (isset($_REQUEST[$key . '_time']) && preg_match('#^\d{1,2}:\d\d$#', $_REQUEST[$key . '_time']))
}
if (isset($_REQUEST[$key . '_time']) && preg_match('#^\d{1,2}:\d\d$#', $_REQUEST[$key . '_time'])) {
$_SESSION['user_shifts'][$key . '_time'] = $_REQUEST[$key . '_time'];
}
if (! isset($_SESSION['user_shifts'][$key . '_day'])) {
$time = date('Y-m-d', time() + ($key == 'end' ? 24 * 60 * 60 : 0));
$_SESSION['user_shifts'][$key . '_day'] = in_array($time, $days) ? $time : ($key == 'end' ? max($days) : min($days));
}
if (! isset($_SESSION['user_shifts'][$key . '_time']))
if (! isset($_SESSION['user_shifts'][$key . '_time'])) {
$_SESSION['user_shifts'][$key . '_time'] = date('H:i');
}
if ($_SESSION['user_shifts']['start_day'] > $_SESSION['user_shifts']['end_day'])
}
if ($_SESSION['user_shifts']['start_day'] > $_SESSION['user_shifts']['end_day']) {
$_SESSION['user_shifts']['end_day'] = $_SESSION['user_shifts']['start_day'];
if ($_SESSION['user_shifts']['start_day'] == $_SESSION['user_shifts']['end_day'] && $_SESSION['user_shifts']['start_time'] >= $_SESSION['user_shifts']['end_time'])
}
if ($_SESSION['user_shifts']['start_day'] == $_SESSION['user_shifts']['end_day'] && $_SESSION['user_shifts']['start_time'] >= $_SESSION['user_shifts']['end_time']) {
$_SESSION['user_shifts']['end_time'] = '23:59';
}
if (isset($_SESSION['user_shifts']['start_day'])) {
$starttime = DateTime::createFromFormat("Y-m-d H:i", $_SESSION['user_shifts']['start_day'] . $_SESSION['user_shifts']['start_time']);
$starttime = $starttime->getTimestamp();
} else
} else {
$starttime = now();
}
if (isset($_SESSION['user_shifts']['end_day'])) {
$endtime = DateTime::createFromFormat("Y-m-d H:i", $_SESSION['user_shifts']['end_day'] . $_SESSION['user_shifts']['end_time']);
$endtime = $endtime->getTimestamp();
} else
} else {
$endtime = now() + 24 * 60 * 60;
}
if (! isset($_SESSION['user_shifts']['rooms']) || count($_SESSION['user_shifts']['rooms']) == 0)
$_SESSION['user_shifts']['rooms'] = array(
if (! isset($_SESSION['user_shifts']['rooms']) || count($_SESSION['user_shifts']['rooms']) == 0) {
$_SESSION['user_shifts']['rooms'] = [
0
);
];
}
$SQL = "SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`, nat2.`special_needs` > 0 AS 'has_special_needs'
FROM `Shifts`
@ -449,13 +495,14 @@ function view_user_shifts() {
AND `start` BETWEEN " . $starttime . " AND " . $endtime;
if (count($_SESSION['user_shifts']['filled']) == 1) {
if ($_SESSION['user_shifts']['filled'][0] == 0)
if ($_SESSION['user_shifts']['filled'][0] == 0) {
$SQL .= "
AND (nat.`count` > entries.`count` OR entries.`count` IS NULL OR EXISTS (SELECT `SID` FROM `ShiftEntry` WHERE `UID` = '" . sql_escape($user['UID']) . "' AND `ShiftEntry`.`SID` = `Shifts`.`SID`))";
elseif ($_SESSION['user_shifts']['filled'][0] == 1)
} elseif ($_SESSION['user_shifts']['filled'][0] == 1) {
$SQL .= "
AND (nat.`count` <= entries.`count` OR EXISTS (SELECT `SID` FROM `ShiftEntry` WHERE `UID` = '" . sql_escape($user['UID']) . "' AND `ShiftEntry`.`SID` = `Shifts`.`SID`))";
}
}
$SQL .= "
ORDER BY `start`";
@ -468,27 +515,28 @@ function view_user_shifts() {
INNER JOIN `ShiftEntry` ON (`Shifts`.`SID` = `ShiftEntry`.`SID` AND `ShiftEntry`.`UID` = '" . sql_escape($user['UID']) . "')
WHERE `Shifts`.`RID` IN (" . implode(',', $_SESSION['user_shifts']['rooms']) . ")
AND `start` BETWEEN " . $starttime . " AND " . $endtime);
$ownshifts = array();
foreach ($ownshifts_source as $ownshift)
$ownshifts = [];
foreach ($ownshifts_source as $ownshift) {
$ownshifts[$ownshift['SID']] = $ownshift;
}
unset($ownshifts_source);
$shifts_table = "";
// qqqq
/*
* [0] => Array ( [SID] => 1 [start] => 1355958000 [end] => 1355961600 [RID] => 1 [name] => [URL] => [PSID] => [room_name] => test1 [has_special_needs] => 1 [is_full] => 0 )
*/
if ($_SESSION['user_shifts']['new_style']) {
$first = 15 * 60 * floor($starttime / (15 * 60));
$maxshow = ceil(($endtime - $first) / (60 * 15));
$block = array();
$todo = array();
$block = [];
$todo = [];
$myrooms = $rooms;
// delete un-selected rooms from array
foreach ($myrooms as $k => $v) {
if (array_search($v["id"], $_SESSION['user_shifts']['rooms']) === FALSE)
if (array_search($v["id"], $_SESSION['user_shifts']['rooms']) === false) {
unset($myrooms[$k]);
}
// initialize $block array
$block[$v["id"]] = array_fill(0, $maxshow, 0);
}
@ -498,8 +546,9 @@ function view_user_shifts() {
$rid = $shift["RID"];
$blocks = ($shift["end"] - $shift["start"]) / (15 * 60);
$firstblock = floor(($shift["start"] - $first) / (15 * 60));
for ($i = $firstblock; $i < $blocks + $firstblock && $i < $maxshow; $i ++)
for ($i = $firstblock; $i < $blocks + $firstblock && $i < $maxshow; $i ++) {
$block[$rid][$i] ++;
}
$shifts[$k]['own'] = in_array($shift['SID'], array_keys($ownshifts));
}
@ -513,8 +562,9 @@ function view_user_shifts() {
continue;
}
$colspan = call_user_func_array('max', $block[$rid]);
if ($colspan == 0)
if ($colspan == 0) {
$colspan = 1;
}
$todo[$rid] = array_fill(0, $maxshow, $colspan);
$shifts_table .= "<th" . (($colspan > 1) ? ' colspan="' . $colspan . '"' : '') . ">" . Room_name_render([
'RID' => $room['id'],
@ -542,26 +592,28 @@ function view_user_shifts() {
if ($shift["RID"] == $rid) {
if (floor($shift["start"] / (15 * 60)) == $thistime / (15 * 60)) {
$blocks = ($shift["end"] - $shift["start"]) / (15 * 60);
if ($blocks < 1)
if ($blocks < 1) {
$blocks = 1;
}
$collides = in_array($shift['SID'], array_keys($ownshifts));
if (! $collides)
if (! $collides) {
foreach ($ownshifts as $ownshift) {
if ($ownshift['start'] >= $shift['start'] && $ownshift['start'] < $shift['end'] || $ownshift['end'] > $shift['start'] && $ownshift['end'] <= $shift['end'] || $ownshift['start'] < $shift['start'] && $ownshift['end'] > $shift['end']) {
$collides = true;
break;
}
}
}
// qqqqqq
$is_free = false;
$shifts_row = '';
if (in_array('admin_shifts', $privileges))
$shifts_row .= '<div class="pull-right">' . table_buttons(array(
if (in_array('admin_shifts', $privileges)) {
$shifts_row .= '<div class="pull-right">' . table_buttons([
button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'),
button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs')
)) . '</div>';
]) . '</div>';
}
$shifts_row .= Room_name_render([
'RID' => $room['id'],
'Name' => $room['name']
@ -585,19 +637,21 @@ function view_user_shifts() {
WHERE
`count` > 0
AND ";
if ($shift['has_special_needs'])
if ($shift['has_special_needs']) {
$query .= "`shift_id` = '" . sql_escape($shift['SID']) . "'";
else
} else {
$query .= "`room_id` = '" . sql_escape($shift['RID']) . "'";
if (! empty($_SESSION['user_shifts']['types']))
}
if (! empty($_SESSION['user_shifts']['types'])) {
$query .= " AND `angel_type_id` IN (" . implode(',', $_SESSION['user_shifts']['types']) . ") ";
}
$query .= " ORDER BY `AngelTypes`.`name`";
$angeltypes = sql_select($query);
if (count($angeltypes) > 0) {
foreach ($angeltypes as $angeltype) {
$entries = sql_select("SELECT * FROM `ShiftEntry` JOIN `User` ON (`ShiftEntry`.`UID` = `User`.`UID`) WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `TID`='" . sql_escape($angeltype['id']) . "' ORDER BY `Nick`");
$entry_list = array();
$entry_list = [];
$freeloader = 0;
foreach ($entries as $entry) {
$style = '';
@ -605,13 +659,14 @@ function view_user_shifts() {
$freeloader ++;
$style = " text-decoration: line-through;";
}
if (in_array('user_shifts_admin', $privileges))
if (in_array('user_shifts_admin', $privileges)) {
$entry_list[] = "<span style=\"$style\">" . User_Nick_render($entry) . ' ' . table_buttons(array(
button(page_link_to('user_shifts') . '&entry_id=' . $entry['id'], glyph('trash'), 'btn-xs')
)) . '</span>';
else
} else {
$entry_list[] = "<span style=\"$style\">" . User_Nick_render($entry) . "</span>";
}
}
if ($angeltype['count'] - count($entries) - $freeloader > 0) {
$inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($entries)), $angeltype['count'] - count($entries));
// is the shift still running or alternatively is the user shift admin?
@ -632,20 +687,21 @@ function view_user_shifts() {
// User shift admins may join anybody in every shift
$user_may_join_shift |= in_array('user_shifts_admin', $privileges);
if ($user_may_join_shift)
if ($user_may_join_shift) {
$entry_list[] = '<a href="' . page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'] . '">' . $inner_text . '</a> ' . button(page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'], _('Sign up'), 'btn-xs');
else {
if (time() > $shift['start'])
} else {
if (time() > $shift['start']) {
$entry_list[] = $inner_text . ' (' . _('ended') . ')';
elseif ($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && ! isset($angeltype['confirm_user_id']))
} elseif ($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && ! isset($angeltype['confirm_user_id'])) {
$entry_list[] = $inner_text . glyph('lock');
elseif ($angeltype['restricted'] == 1)
} elseif ($angeltype['restricted'] == 1) {
$entry_list[] = $inner_text;
elseif ($collides)
} elseif ($collides) {
$entry_list[] = $inner_text;
else
} else {
$entry_list[] = $inner_text . '<br />' . button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']), 'btn-xs');
}
}
unset($inner_text);
$is_free = true;
@ -655,17 +711,19 @@ function view_user_shifts() {
$shifts_row .= join(", ", $entry_list);
$shifts_row .= '<br />';
}
if (in_array('user_shifts_admin', $privileges))
if (in_array('user_shifts_admin', $privileges)) {
$shifts_row .= ' ' . button(page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs');
}
if ($shift['own'] && ! in_array('user_shifts_admin', $privileges))
}
if ($shift['own'] && ! in_array('user_shifts_admin', $privileges)) {
$class = 'own';
elseif ($collides && ! in_array('user_shifts_admin', $privileges))
} elseif ($collides && ! in_array('user_shifts_admin', $privileges)) {
$class = 'collides';
elseif ($is_free)
} elseif ($is_free) {
$class = 'free';
else
} else {
$class = 'occupied';
}
$shifts_table .= '<td rowspan="' . $blocks . '" class="' . $class . '">';
$shifts_table .= $shifts_row;
$shifts_table .= "</td>";
@ -676,36 +734,39 @@ function view_user_shifts() {
}
}
// fill up row with empty <td>
while ($todo[$rid][$i] -- > 0)
while ($todo[$rid][$i] -- > 0) {
$shifts_table .= '<td class="empty"></td>';
}
}
$shifts_table .= "</tr>\n";
}
$shifts_table .= '</tbody></table></div>';
// qqq
} else {
$shifts_table = array();
$shifts_table = [];
foreach ($shifts as $shift) {
$info = array();
if ($_SESSION['user_shifts']['start_day'] != $_SESSION['user_shifts']['end_day'])
$info = [];
if ($_SESSION['user_shifts']['start_day'] != $_SESSION['user_shifts']['end_day']) {
$info[] = date("Y-m-d", $shift['start']);
}
$info[] = date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']);
if (count($_SESSION['user_shifts']['rooms']) > 1)
if (count($_SESSION['user_shifts']['rooms']) > 1) {
$info[] = Room_name_render([
'Name' => $shift['room_name'],
'RID' => $shift['RID']
]);
}
$shift_row = array(
$shift_row = [
'info' => join('<br />', $info),
'entries' => '<a href="' . shift_link($shift) . '">' . $shift['name'] . '</a>' . ($shift['title'] ? '<br />' . $shift['title'] : '')
);
];
if (in_array('admin_shifts', $privileges))
$shift_row['info'] .= ' ' . table_buttons(array(
if (in_array('admin_shifts', $privileges)) {
$shift_row['info'] .= ' ' . table_buttons([
button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'),
button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs')
));
]);
}
$shift_row['entries'] .= '<br />';
$is_free = false;
$shift_has_special_needs = 0 < sql_num_query("SELECT `id` FROM `NeededAngelTypes` WHERE `shift_id` = " . $shift['SID']);
@ -714,13 +775,15 @@ function view_user_shifts() {
JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`)
LEFT JOIN `UserAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `UserAngelTypes`.`angeltype_id`AND `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "')
WHERE ";
if ($shift_has_special_needs)
if ($shift_has_special_needs) {
$query .= "`shift_id` = '" . sql_escape($shift['SID']) . "'";
else
} else {
$query .= "`room_id` = '" . sql_escape($shift['RID']) . "'";
}
$query .= " AND `count` > 0 ";
if (! empty($_SESSION['user_shifts']['types']))
if (! empty($_SESSION['user_shifts']['types'])) {
$query .= "AND `angel_type_id` IN (" . implode(',', $_SESSION['user_shifts']['types']) . ") ";
}
$query .= "ORDER BY `AngelTypes`.`name`";
$angeltypes = sql_select($query);
if (count($angeltypes) > 0) {
@ -728,16 +791,17 @@ function view_user_shifts() {
foreach ($angeltypes as &$angeltype) {
$entries = sql_select("SELECT * FROM `ShiftEntry` JOIN `User` ON (`ShiftEntry`.`UID` = `User`.`UID`) WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `TID`='" . sql_escape($angeltype['id']) . "' ORDER BY `Nick`");
$entry_list = array();
$entry_list = [];
$entry_nicks = [];
$freeloader = 0;
foreach ($entries as $entry) {
if (in_array('user_shifts_admin', $privileges))
if (in_array('user_shifts_admin', $privileges)) {
$member = User_Nick_render($entry) . ' ' . table_buttons(array(
button(page_link_to('user_shifts') . '&entry_id=' . $entry['id'], glyph('trash'), 'btn-xs')
));
else
} else {
$member = User_Nick_render($entry);
}
if ($entry['freeloaded']) {
$member = '<strike>' . $member . '</strike>';
$freeloader ++;
@ -761,17 +825,18 @@ function view_user_shifts() {
$user_may_join_shift &= isset($angeltype['user_id']);
// you cannot join if you are not confirmed
if ($angeltype['restricted'] == 1 && isset($angeltype['user_id']))
if ($angeltype['restricted'] == 1 && isset($angeltype['user_id'])) {
$user_may_join_shift &= isset($angeltype['confirm_user_id']);
}
// you can only join if the shift is in future or running
$user_may_join_shift &= time() < $shift['start'];
// User shift admins may join anybody in every shift
$user_may_join_shift |= in_array('user_shifts_admin', $privileges);
if ($user_may_join_shift)
if ($user_may_join_shift) {
$entry_list[] = '<a href="' . page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'] . '">' . $inner_text . ' &raquo;</a>';
else {
} else {
if (time() > $shift['end']) {
$entry_list[] = $inner_text . ' (vorbei)';
} elseif ($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && ! isset($angeltype['confirm_user_id'])) {
@ -797,19 +862,20 @@ function view_user_shifts() {
$ical_shifts[] = $shift;
}
}
$shifts_table = table(array(
$shifts_table = table([
'info' => _("Time") . "/" . _("Room"),
'entries' => _("Entries")
), $shifts_table);
], $shifts_table);
}
if ($user['api_key'] == "")
if ($user['api_key'] == "") {
User_reset_api_key($user, false);
}
return page(array(
'<div class="col-md-12">',
return page([
div('col-md-12', [
msg(),
template_render('../templates/user_shifts.html', array(
template_render('../templates/user_shifts.html', [
'title' => shifts_title(),
'room_select' => make_select($rooms, $_SESSION['user_shifts']['rooms'], "rooms", _("Rooms")),
'start_select' => html_select_key("start_day", "start_day", array_combine($days, $days), $_SESSION['user_shifts']['start_day']),
@ -823,9 +889,9 @@ function view_user_shifts() {
'shifts_table' => msg() . $shifts_table,
'ical_text' => '<h2>' . _("iCal export") . '</h2><p>' . sprintf(_("Export of shown shifts. <a href=\"%s\">iCal format</a> or <a href=\"%s\">JSON format</a> available (please keep secret, otherwise <a href=\"%s\">reset the api key</a>)."), page_link_to_absolute('ical') . '&key=' . $user['api_key'], page_link_to_absolute('shifts_json_export') . '&key=' . $user['api_key'], page_link_to('user_myshifts') . '&reset') . '</p>',
'filter' => _("Filter")
)),
'</div>'
));
])
])
]);
}
function make_user_shifts_export_link($page, $key) {
@ -833,12 +899,15 @@ function make_user_shifts_export_link($page, $key) {
$link = "&start_time=" . $_SESSION['user_shifts']['start_time'];
$link = "&end_day=" . $_SESSION['user_shifts']['end_day'];
$link = "&end_time=" . $_SESSION['user_shifts']['end_time'];
foreach ($_SESSION['user_shifts']['rooms'] as $room)
foreach ($_SESSION['user_shifts']['rooms'] as $room) {
$link .= '&rooms[]=' . $room;
foreach ($_SESSION['user_shifts']['types'] as $type)
}
foreach ($_SESSION['user_shifts']['types'] as $type) {
$link .= '&types[]=' . $type;
foreach ($_SESSION['user_shifts']['filled'] as $filled)
}
foreach ($_SESSION['user_shifts']['filled'] as $filled) {
$link .= '&filled[]=' . $filled;
}
return page_link_to_absolute($page) . $link . '&export=user_shifts&key=' . $key;
}
@ -847,18 +916,20 @@ function get_ids_from_array($array) {
}
function make_select($items, $selected, $name, $title = null) {
$html_items = array();
if (isset($title))
$html_items = [];
if (isset($title)) {
$html_items[] = '<h4>' . $title . '</h4>' . "\n";
}
foreach ($items as $i)
foreach ($items as $i) {
$html_items[] = '<div class="checkbox"><label><input type="checkbox" name="' . $name . '[]" value="' . $i['id'] . '"' . (in_array($i['id'], $selected) ? ' checked="checked"' : '') . '> ' . $i['name'] . '</label>' . (! isset($i['enabled']) || $i['enabled'] ? '' : glyph("lock")) . '</div><br />';
}
$html = '<div id="selection_' . $name . '" class="selection ' . $name . '">' . "\n";
$html .= implode("\n", $html_items);
$html .= buttons(array(
$html .= buttons([
button("javascript: checkAll('selection_" . $name . "', true)", _("All"), ""),
button("javascript: checkAll('selection_" . $name . "', false)", _("None"), "")
));
]);
$html .= '</div>' . "\n";
return $html;
}

Loading…
Cancel
Save