add update, delete and view for shift type

main
Philip Häusler 10 years ago
parent 526167ed11
commit 3f8e5e47c0

@ -6,6 +6,8 @@ CREATE TABLE IF NOT EXISTS `ShiftTypes` (
`description` text NOT NULL, `description` text NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
ALTER TABLE `ShiftTypes` ADD INDEX ( `angeltype_id` );
ALTER TABLE `ShiftTypes` ADD FOREIGN KEY ( `angeltype_id` ) REFERENCES `engelsystem`.`AngelTypes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
INSERT INTO `engelsystem`.`Privileges` (`id`, `name`, `desc`) VALUES (NULL , 'shifttypes', 'Administrate shift types'); INSERT INTO `engelsystem`.`Privileges` (`id`, `name`, `desc`) VALUES (NULL , 'shifttypes', 'Administrate shift types');
INSERT INTO `GroupPrivileges` SET `group_id`=-5, `privilege_id`=(SELECT `id` FROM `Privileges` WHERE `name`='shifttypes'); INSERT INTO `GroupPrivileges` SET `group_id`=-5, `privilege_id`=(SELECT `id` FROM `Privileges` WHERE `name`='shifttypes');

@ -1,6 +1,31 @@
<?php <?php
/**
* Delete a shifttype.
*/
function shifttype_delete_controller() { function shifttype_delete_controller() {
if (! isset($_REQUEST['shifttype_id']))
redirect(page_link_to('shifttypes'));
$shifttype = ShiftType($_REQUEST['shifttype_id']);
if ($shifttype === false)
engelsystem_error('Unable to load shifttype.');
if ($shifttype == null)
redirect(page_link_to('shifttypes'));
if (isset($_REQUEST['confirmed'])) {
$result = ShiftType_delete($shifttype['id']);
if ($result === false)
engelsystem_error('Unable to delete shifttype.');
engelsystem_log('Deleted shifttype ' . $shifttype['name']);
success(sprintf(_('Shifttype %s deleted.'), $shifttype['name']));
redirect(page_link_to('shifttypes'));
}
return array(
sprintf(_("Delete shifttype %s"), $shifttype['name']),
ShiftType_delete_view($shifttype)
);
} }
/** /**
@ -16,6 +41,20 @@ function shifttype_edit_controller() {
if ($angeltypes === false) if ($angeltypes === false)
engelsystem_error("Unable to load angel types."); engelsystem_error("Unable to load angel types.");
if (isset($_REQUEST['shifttype_id'])) {
$shifttype = ShiftType($_REQUEST['shifttype_id']);
if ($shifttype === false)
engelsystem_error('Unable to load shifttype.');
if ($shifttype == null) {
error(_('Shifttype not found.'));
redirect(page_link_to('shifttypes'));
}
$shifttype_id = $shifttype['id'];
$name = $shifttype['name'];
$angeltype_id = $shifttype['angeltype_id'];
$description = $shifttype['description'];
}
if (isset($_REQUEST['submit'])) { if (isset($_REQUEST['submit'])) {
$ok = true; $ok = true;
@ -35,7 +74,13 @@ function shifttype_edit_controller() {
$description = strip_request_item_nl('description'); $description = strip_request_item_nl('description');
if ($ok) { if ($ok) {
if ($shifttype_id) {} else { if ($shifttype_id) {
$result = ShiftType_update($shifttype_id, $name, $angeltype_id, $description);
if ($result === false)
engelsystem_error('Unable to update shifttype.');
engelsystem_log('Updated shifttype ' . $name);
success(_('Updated shifttype.'));
} else {
$shifttype_id = ShiftType_create($name, $angeltype_id, $description); $shifttype_id = ShiftType_create($name, $angeltype_id, $description);
if ($shifttype_id === false) if ($shifttype_id === false)
engelsystem_error('Unable to create shifttype.'); engelsystem_error('Unable to create shifttype.');
@ -53,6 +98,25 @@ function shifttype_edit_controller() {
} }
function shifttype_controller() { function shifttype_controller() {
if (! isset($_REQUEST['shifttype_id']))
redirect(page_link_to('shifttypes'));
$shifttype = ShiftType($_REQUEST['shifttype_id']);
if ($shifttype === false)
engelsystem_error('Unable to load shifttype.');
if ($shifttype == null)
redirect(page_link_to('shifttypes'));
$angeltype = null;
if ($shifttype['angeltype_id'] != null) {
$angeltype = AngelType($shifttype['angeltype_id']);
if ($angeltype === false)
engelsystem_error('Unable to load angeltype.');
}
return [
$shifttype['name'],
ShiftType_view($shifttype, $angeltype)
];
} }
/** /**

@ -1,6 +1,13 @@
<?php <?php
function ShiftType_delete_view($shifttype) { function ShiftType_delete_view($shifttype) {
return page_with_title(sprintf(_("Delete shifttype %s"), $shifttype['name']), array(
info(sprintf(_("Do you want to delete shifttype %s?"), $shifttype['name']), true),
buttons(array(
button(page_link_to('shifttypes'), _("cancel"), 'cancel'),
button(page_link_to('shifttypes') . '&action=delete&shifttype_id=' . $shifttype['id'] . '&confirmed', _("delete"), 'ok')
))
));
} }
function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) { function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) {
@ -25,7 +32,21 @@ function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $s
]); ]);
} }
function ShiftType_view($shifttype) { function ShiftType_view($shifttype, $angeltype) {
$parsedown = new Parsedown();
$title = $shifttype['name'];
if ($angeltype)
$title .= ' <small>' . sprintf(_('for team %s'), $angeltype['name']) . '</small>';
return page_with_title($title, [
msg(),
buttons([
button(page_link_to('shifttypes'), shifttypes_title(), 'back'),
$angeltype ? button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], $angeltype['name']) : '',
button(page_link_to('shifttypes'), _('edit'), 'edit'),
button(page_link_to('shifttypes'), _('delete'), 'delete')
]),
$parsedown->parse($shifttype['description'])
]);
} }
function ShiftTypes_list_view($shifttypes) { function ShiftTypes_list_view($shifttypes) {

Loading…
Cancel
Save