You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
8.1 KiB
PHTML

14 years ago
<?php
/**
* @return string
*/
8 years ago
function admin_rooms_title()
{
return __('Rooms');
}
/**
* @return string
*/
8 years ago
function admin_rooms()
{
$rooms_source = Rooms();
8 years ago
$rooms = [];
$request = request();
8 years ago
foreach ($rooms_source as $room) {
$rooms[] = [
'name' => Room_name_render($room),
'from_frab' => glyph_bool($room['from_frab']),
'map_url' => glyph_bool(!empty($room['map_url'])),
'actions' => table_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'
)
8 years ago
])
];
8 years ago
}
8 years ago
$room = null;
if ($request->has('show')) {
$msg = '';
$name = '';
$from_frab = false;
$map_url = null;
$description = null;
$room_id = 0;
8 years ago
$angeltypes_source = AngelTypes();
8 years ago
$angeltypes = [];
$angeltypes_count = [];
foreach ($angeltypes_source as $angeltype) {
$angeltypes[$angeltype['id']] = $angeltype['name'];
$angeltypes_count[$angeltype['id']] = 0;
}
8 years ago
8 years ago
if (test_request_int('id')) {
$room = Room($request->input('id'));
if (empty($room)) {
8 years ago
redirect(page_link_to('admin_rooms'));
}
8 years ago
$room_id = $request->input('id');
8 years ago
$name = $room['Name'];
$from_frab = $room['from_frab'];
$map_url = $room['map_url'];
$description = $room['description'];
8 years ago
$needed_angeltypes = NeededAngelTypes_by_room($room_id);
8 years ago
foreach ($needed_angeltypes as $needed_angeltype) {
$angeltypes_count[$needed_angeltype['angel_type_id']] = $needed_angeltype['count'];
}
}
8 years ago
if ($request->input('show') == 'edit') {
if ($request->hasPostData('submit')) {
8 years ago
$valid = true;
8 years ago
if ($request->has('name') && strlen(strip_request_item('name')) > 0) {
$result = Room_validate_name(strip_request_item('name'), $room_id);
if (!$result->isValid()) {
8 years ago
$valid = false;
$msg .= error(__('This name is already in use.'), true);
} else {
$name = $result->getValue();
8 years ago
}
} else {
$valid = false;
$msg .= error(__('Please enter a name.'), true);
8 years ago
}
8 years ago
$from_frab = $request->has('from_frab');
8 years ago
if ($request->has('map_url')) {
$map_url = strip_request_item('map_url');
8 years ago
}
8 years ago
if ($request->has('description')) {
$description = strip_request_item_nl('description');
8 years ago
}
8 years ago
8 years ago
foreach ($angeltypes as $angeltype_id => $angeltype) {
$angeltypes_count[$angeltype_id] = 0;
$queryKey = 'angeltype_count_' . $angeltype_id;
if (!$request->has($queryKey)) {
continue;
}
if (preg_match('/^\d{1,4}$/', $request->input($queryKey))) {
$angeltypes_count[$angeltype_id] = $request->input($queryKey);
8 years ago
} else {
$valid = false;
$msg .= error(sprintf(
__('Please enter needed angels for type %s.'),
$angeltype
), true);
8 years ago
}
}
8 years ago
8 years ago
if ($valid) {
if (empty($room_id)) {
$room_id = Room_create($name, $from_frab, $map_url, $description);
} else {
Room_update($room_id, $name, $from_frab, $map_url, $description);
8 years ago
}
8 years ago
8 years ago
NeededAngelTypes_delete_by_room($room_id);
$needed_angeltype_info = [];
foreach ($angeltypes_count as $angeltype_id => $angeltype_count) {
$angeltype = AngelType($angeltype_id);
if (!empty($angeltype)) {
8 years ago
NeededAngelType_add(null, $angeltype_id, $room_id, $angeltype_count);
if ($angeltype_count > 0) {
$needed_angeltype_info[] = $angeltype['name'] . ': ' . $angeltype_count;
}
8 years ago
}
}
8 years ago
engelsystem_log(
'Set needed angeltypes of room ' . $name
. ' to: ' . join(', ', $needed_angeltype_info)
8 years ago
);
success(__('Room saved.'));
redirect(page_link_to('admin_rooms'));
8 years ago
}
}
$angeltypes_count_form = [];
foreach ($angeltypes as $angeltype_id => $angeltype) {
$angeltypes_count_form[] = div('col-lg-4 col-md-6 col-xs-6', [
8 years ago
form_spinner('angeltype_count_' . $angeltype_id, $angeltype, $angeltypes_count[$angeltype_id])
]);
8 years ago
}
8 years ago
8 years ago
return page_with_title(admin_rooms_title(), [
8 years ago
buttons([
button(page_link_to('admin_rooms'), __('back'), 'back')
8 years ago
]),
$msg,
form([
div('row', [
div('col-md-6', [
form_text('name', __('Name'), $name, false, 35),
form_checkbox('from_frab', __('Frab import'), $from_frab),
form_text('map_url', __('Map URL'), $map_url),
form_info('', __('The map url is used to display an iframe on the room page.')),
form_textarea('description', __('Description'), $description),
form_info('', __('Please use markdown for the description.')),
8 years ago
]),
div('col-md-6', [
div('row', [
div('col-md-12', [
form_info(__('Needed angels:'))
8 years ago
]),
join($angeltypes_count_form)
])
])
]),
form_submit('submit', __('Save'))
8 years ago
])
]);
} elseif ($request->input('show') == 'delete') {
if ($request->hasPostData('ack')) {
$shifts = Shifts_by_room($room_id);
foreach ($shifts as $shift) {
$shift = Shift($shift['SID']);
UserWorkLog_from_shift($shift);
mail_shift_delete($shift);
}
Room_delete($room_id);
8 years ago
success(sprintf(__('Room %s deleted.'), $name));
8 years ago
redirect(page_link_to('admin_rooms'));
}
8 years ago
8 years ago
return page_with_title(admin_rooms_title(), [
8 years ago
buttons([
button(page_link_to('admin_rooms'), __('back'), 'back')
8 years ago
]),
sprintf(__('Do you want to delete room %s?'), $name),
form([
form_submit('ack', __('Delete'), 'delete btn-danger'),
], page_link_to('admin_rooms', ['show' => 'delete', 'id' => $room_id])),
8 years ago
]);
8 years ago
}
}
8 years ago
8 years ago
return page_with_title(admin_rooms_title(), [
8 years ago
buttons([
button(page_link_to('admin_rooms', ['show' => 'edit']), __('add'))
8 years ago
]),
msg(),
table([
'name' => __('Name'),
'from_frab' => __('Frab import'),
'map_url' => __('Map'),
'actions' => ''
8 years ago
], $rooms)
]);
14 years ago
}