responsify create room form

main
Felix Favre 10 years ago
parent 1cc84a967a
commit bc6aa9a209

@ -5,7 +5,7 @@ function admin_rooms_title() {
function admin_rooms() { function admin_rooms() {
global $user; global $user;
$rooms_source = sql_select("SELECT * FROM `Room` ORDER BY `Name`"); $rooms_source = sql_select("SELECT * FROM `Room` ORDER BY `Name`");
$rooms = array(); $rooms = array();
foreach ($rooms_source as $room) foreach ($rooms_source as $room)
@ -15,17 +15,17 @@ function admin_rooms() {
'public' => $room['show'] == 'Y' ? '✓' : '', 'public' => $room['show'] == 'Y' ? '✓' : '',
'actions' => buttons(array( 'actions' => buttons(array(
button(page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'], _("edit"), 'btn-xs'), 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') button(page_link_to('admin_rooms') . '&show=delete&id=' . $room['RID'], _("delete"), 'btn-xs')
)) ))
); );
if (isset($_REQUEST['show'])) { if (isset($_REQUEST['show'])) {
$msg = ""; $msg = "";
$name = ""; $name = "";
$from_pentabarf = ""; $from_pentabarf = "";
$public = 'Y'; $public = 'Y';
$number = ""; $number = "";
$angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`"); $angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
$angeltypes = array(); $angeltypes = array();
$angeltypes_count = array(); $angeltypes_count = array();
@ -33,7 +33,7 @@ function admin_rooms() {
$angeltypes[$angeltype['id']] = $angeltype['name']; $angeltypes[$angeltype['id']] = $angeltype['name'];
$angeltypes_count[$angeltype['id']] = 0; $angeltypes_count[$angeltype['id']] = 0;
} }
if (test_request_int('id')) { if (test_request_int('id')) {
$room = sql_select("SELECT * FROM `Room` WHERE `RID`=" . sql_escape($_REQUEST['id'])); $room = sql_select("SELECT * FROM `Room` WHERE `RID`=" . sql_escape($_REQUEST['id']));
if (count($room) > 0) { if (count($room) > 0) {
@ -47,33 +47,33 @@ function admin_rooms() {
} else } else
redirect(page_link_to('admin_rooms')); redirect(page_link_to('admin_rooms'));
} }
if ($_REQUEST['show'] == 'edit') { if ($_REQUEST['show'] == 'edit') {
if (isset($_REQUEST['submit'])) { if (isset($_REQUEST['submit'])) {
$ok = true; $ok = true;
if (isset($_REQUEST['name']) && strlen(strip_request_item('name')) > 0) if (isset($_REQUEST['name']) && strlen(strip_request_item('name')) > 0)
$name = strip_request_item('name'); $name = strip_request_item('name');
else { else {
$ok = false; $ok = false;
$msg .= error(_("Please enter a name."), true); $msg .= error(_("Please enter a name."), true);
} }
if (isset($_REQUEST['from_pentabarf'])) if (isset($_REQUEST['from_pentabarf']))
$from_pentabarf = 'Y'; $from_pentabarf = 'Y';
else else
$from_pentabarf = ''; $from_pentabarf = '';
if (isset($_REQUEST['public'])) if (isset($_REQUEST['public']))
$public = 'Y'; $public = 'Y';
else else
$public = ''; $public = '';
if (isset($_REQUEST['number'])) if (isset($_REQUEST['number']))
$number = strip_request_item('number'); $number = strip_request_item('number');
else else
$ok = false; $ok = false;
foreach ($angeltypes as $angeltype_id => $angeltype) { 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]; $angeltypes_count[$angeltype_id] = $_REQUEST['angeltype_count_' . $angeltype_id];
@ -82,7 +82,7 @@ function admin_rooms() {
$msg .= error(sprintf(_("Please enter needed angels for type %s.", $angeltype)), true); $msg .= error(sprintf(_("Please enter needed angels for type %s.", $angeltype)), true);
} }
} }
if ($ok) { if ($ok) {
if (isset($id)) { if (isset($id)) {
sql_query("UPDATE `Room` SET `Name`='" . sql_escape($name) . "', `FromPentabarf`='" . sql_escape($from_pentabarf) . "', `show`='" . sql_escape($public) . "', `Number`='" . sql_escape($number) . "' WHERE `RID`=" . sql_escape($id) . " LIMIT 1"); sql_query("UPDATE `Room` SET `Name`='" . sql_escape($name) . "', `FromPentabarf`='" . sql_escape($from_pentabarf) . "', `show`='" . sql_escape($public) . "', `Number`='" . sql_escape($number) . "' WHERE `RID`=" . sql_escape($id) . " LIMIT 1");
@ -92,7 +92,7 @@ function admin_rooms() {
$id = sql_id(); $id = sql_id();
engelsystem_log("Room created: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number); engelsystem_log("Room created: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number);
} }
sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`=" . sql_escape($id)); sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`=" . sql_escape($id));
$needed_angeltype_info = array(); $needed_angeltype_info = array();
foreach ($angeltypes_count as $angeltype_id => $angeltype_count) { foreach ($angeltypes_count as $angeltype_id => $angeltype_count) {
@ -102,7 +102,7 @@ function admin_rooms() {
$needed_angeltype_info[] = $angeltypes_source[0]['name'] . ": " . $angeltype_count; $needed_angeltype_info[] = $angeltypes_source[0]['name'] . ": " . $angeltype_count;
} }
} }
engelsystem_log("Set needed angeltypes of room " . $name . " to: " . join(", ", $needed_angeltype_info)); engelsystem_log("Set needed angeltypes of room " . $name . " to: " . join(", ", $needed_angeltype_info));
success(_("Room saved.")); success(_("Room saved."));
redirect(page_link_to("admin_rooms")); redirect(page_link_to("admin_rooms"));
@ -110,56 +110,66 @@ function admin_rooms() {
} }
$angeltypes_count_form = array(); $angeltypes_count_form = array();
foreach ($angeltypes as $angeltype_id => $angeltype) foreach ($angeltypes as $angeltype_id => $angeltype)
$angeltypes_count_form[] = form_spinner('angeltype_count_' . $angeltype_id, $angeltype, $angeltypes_count[$angeltype_id]); $angeltypes_count_form[] = div('col-lg-4 col-md-6 col-xs-6', array(form_spinner('angeltype_count_' . $angeltype_id, $angeltype, $angeltypes_count[$angeltype_id])));
return page_with_title(admin_rooms_title(), array( return page_with_title(admin_rooms_title(), array(
buttons(array( buttons(array(
button(page_link_to('admin_rooms'), _("back"), 'back') button(page_link_to('admin_rooms'), _("back"), 'back')
)), )),
$msg, $msg,
form(array( form(array(
form_text('name', _("Name"), $name), div('row', array(
form_checkbox('from_pentabarf', _("Frab import"), $from_pentabarf), div('col-md-6', array(
form_checkbox('public', _("Public"), $public), form_text('name', _("Name"), $name),
form_text('number', _("Room number"), $number), form_checkbox('from_pentabarf', _("Frab import"), $from_pentabarf),
form_info(_("Needed angels:")), form_checkbox('public', _("Public"), $public),
join($angeltypes_count_form), form_text('number', _("Room number"), $number)
form_submit('submit', _("Save")) )),
)) div('col-md-6', array(
div('row', array(
div('col-md-12', array(
form_info(_("Needed angels:")),
)),
join($angeltypes_count_form)
))
))
)),
form_submit('submit', _("Save"))
))
)); ));
} elseif ($_REQUEST['show'] == 'delete') { } elseif ($_REQUEST['show'] == 'delete') {
if (isset($_REQUEST['ack'])) { if (isset($_REQUEST['ack'])) {
sql_query("DELETE FROM `Room` WHERE `RID`=" . sql_escape($id) . " LIMIT 1"); sql_query("DELETE FROM `Room` WHERE `RID`=" . sql_escape($id) . " LIMIT 1");
sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`=" . sql_escape($id) . " LIMIT 1"); sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`=" . sql_escape($id) . " LIMIT 1");
engelsystem_log("Room deleted: " . $name); engelsystem_log("Room deleted: " . $name);
success(sprintf(_("Room %s deleted."), $name)); success(sprintf(_("Room %s deleted."), $name));
redirect(page_link_to('admin_rooms')); redirect(page_link_to('admin_rooms'));
} }
return page_with_title(admin_rooms_title(), array( return page_with_title(admin_rooms_title(), array(
buttons(array( buttons(array(
button(page_link_to('admin_rooms'), _("back"), 'back') button(page_link_to('admin_rooms'), _("back"), 'back')
)), )),
sprintf(_("Do you want to delete room %s?"), $name), sprintf(_("Do you want to delete room %s?"), $name),
buttons(array( buttons(array(
button(page_link_to('admin_rooms') . '&show=delete&id=' . $id . '&ack', _("Delete"), 'delete') button(page_link_to('admin_rooms') . '&show=delete&id=' . $id . '&ack', _("Delete"), 'delete')
)) ))
)); ));
} }
} }
return page_with_title(admin_rooms_title(), array( return page_with_title(admin_rooms_title(), array(
buttons(array( buttons(array(
button(page_link_to('admin_rooms') . '&show=edit', _("add")) button(page_link_to('admin_rooms') . '&show=edit', _("add"))
)), )),
msg(), msg(),
table(array( table(array(
'name' => _("Name"), 'name' => _("Name"),
'from_pentabarf' => _("Frab import"), 'from_pentabarf' => _("Frab import"),
'public' => _("Public"), 'public' => _("Public"),
'actions' => "" 'actions' => ""
), $rooms) ), $rooms)
)); ));
} }
?> ?>

Loading…
Cancel
Save