add create shift type
This commit is contained in:
parent
c8cc46886b
commit
526167ed11
|
@ -3,26 +3,70 @@
|
||||||
function shifttype_delete_controller() {
|
function shifttype_delete_controller() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit or create shift type.
|
||||||
|
*/
|
||||||
function shifttype_edit_controller() {
|
function shifttype_edit_controller() {
|
||||||
|
$shifttype_id = null;
|
||||||
|
$name = "";
|
||||||
|
$angeltype_id = null;
|
||||||
|
$description = "";
|
||||||
|
|
||||||
|
$angeltypes = AngelTypes();
|
||||||
|
if ($angeltypes === false)
|
||||||
|
engelsystem_error("Unable to load angel types.");
|
||||||
|
|
||||||
|
if (isset($_REQUEST['submit'])) {
|
||||||
|
$ok = true;
|
||||||
|
|
||||||
|
if (isset($_REQUEST['name']) && $_REQUEST['name'] != '')
|
||||||
|
$name = strip_request_item('name');
|
||||||
|
else {
|
||||||
|
$ok = false;
|
||||||
|
error(_('Please enter a name.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_REQUEST['angeltype_id']) && preg_match("/^[0-9]+$/", $_REQUEST['angeltype_id']))
|
||||||
|
$angeltype_id = $_REQUEST['angeltype_id'];
|
||||||
|
else
|
||||||
|
$angeltype_id = null;
|
||||||
|
|
||||||
|
if (isset($_REQUEST['description']))
|
||||||
|
$description = strip_request_item_nl('description');
|
||||||
|
|
||||||
|
if ($ok) {
|
||||||
|
if ($shifttype_id) {} else {
|
||||||
|
$shifttype_id = ShiftType_create($name, $angeltype_id, $description);
|
||||||
|
if ($shifttype_id === false)
|
||||||
|
engelsystem_error('Unable to create shift type.');
|
||||||
|
engelsystem_log('Created shifttype ' . $name);
|
||||||
|
success(_('Created shifttype.'));
|
||||||
|
}
|
||||||
|
redirect(page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
shifttypes_title(),
|
||||||
|
ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id)
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
function shifttype_controller() {
|
function shifttype_controller() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all shift types.
|
||||||
|
*/
|
||||||
function shifttypes_list_controller() {
|
function shifttypes_list_controller() {
|
||||||
global $privileges, $user;
|
|
||||||
|
|
||||||
if (! in_array('shifttypes', $privileges))
|
|
||||||
redirect('?');
|
|
||||||
|
|
||||||
$shifttypes = ShiftTypes();
|
$shifttypes = ShiftTypes();
|
||||||
if ($shifttypes === false)
|
if ($shifttypes === false)
|
||||||
engelsystem_error("Unable to load shifttypes.");
|
engelsystem_error("Unable to load shifttypes.");
|
||||||
|
|
||||||
return array(
|
return [
|
||||||
shifttypes_title(),
|
shifttypes_title(),
|
||||||
ShiftTypes_list_view($shifttypes)
|
ShiftTypes_list_view($shifttypes)
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,6 +76,9 @@ function shifttypes_title() {
|
||||||
return _("Shifttypes");
|
return _("Shifttypes");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Route shift type actions
|
||||||
|
*/
|
||||||
function shifttypes_controller() {
|
function shifttypes_controller() {
|
||||||
if (! isset($_REQUEST['action']))
|
if (! isset($_REQUEST['action']))
|
||||||
$_REQUEST['action'] = 'list';
|
$_REQUEST['action'] = 'list';
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
$themes = array(
|
$themes = array(
|
||||||
"0" => "Engelsystem light",
|
"0" => "Engelsystem light",
|
||||||
"1" => "Engelsystem dark",
|
"1" => "Engelsystem dark",
|
||||||
"2" => "Engelsystem 31c3"
|
"2" => "Engelsystem 31c3"
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render glyphicon
|
* Render glyphicon
|
||||||
*
|
*
|
||||||
* @param string $glyph_name
|
* @param string $glyph_name
|
||||||
*/
|
*/
|
||||||
function glyph($glyph_name) {
|
function glyph($glyph_name) {
|
||||||
return ' <span class="glyphicon glyphicon-' . $glyph_name . '"></span> ';
|
return ' <span class="glyphicon glyphicon-' . $glyph_name . '"></span> ';
|
||||||
|
@ -21,7 +21,7 @@ function glyph($glyph_name) {
|
||||||
/**
|
/**
|
||||||
* Renders a tick or a cross by given boolean
|
* Renders a tick or a cross by given boolean
|
||||||
*
|
*
|
||||||
* @param boolean $boolean
|
* @param boolean $boolean
|
||||||
*/
|
*/
|
||||||
function glyph_bool($boolean) {
|
function glyph_bool($boolean) {
|
||||||
return '<span class="text-' . ($boolean ? 'success' : 'danger') . '">' . glyph($boolean ? 'ok' : 'remove') . '</span>';
|
return '<span class="text-' . ($boolean ? 'success' : 'danger') . '">' . glyph($boolean ? 'ok' : 'remove') . '</span>';
|
||||||
|
@ -39,7 +39,7 @@ function heading($content, $number = 1) {
|
||||||
/**
|
/**
|
||||||
* Render a toolbar.
|
* Render a toolbar.
|
||||||
*
|
*
|
||||||
* @param array $items
|
* @param array $items
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function toolbar($items = array(), $right = false) {
|
function toolbar($items = array(), $right = false) {
|
||||||
|
@ -49,10 +49,10 @@ function toolbar($items = array(), $right = false) {
|
||||||
/**
|
/**
|
||||||
* Render a link for a toolbar.
|
* Render a link for a toolbar.
|
||||||
*
|
*
|
||||||
* @param string $href
|
* @param string $href
|
||||||
* @param string $glyphicon
|
* @param string $glyphicon
|
||||||
* @param string $label
|
* @param string $label
|
||||||
* @param bool $selected
|
* @param bool $selected
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function toolbar_item_link($href, $glyphicon, $label, $selected = false) {
|
function toolbar_item_link($href, $glyphicon, $label, $selected = false) {
|
||||||
|
@ -125,9 +125,9 @@ function form_checkboxes($name, $label, $items, $selected) {
|
||||||
$html = form_element($label, '');
|
$html = form_element($label, '');
|
||||||
foreach ($items as $key => $item)
|
foreach ($items as $key => $item)
|
||||||
$html .= form_checkbox($name . '_' . $key, $item, array_search($key, $selected) !== false);
|
$html .= form_checkbox($name . '_' . $key, $item, array_search($key, $selected) !== false);
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
|
|
||||||
$html = "<ul>";
|
$html = "<ul>";
|
||||||
foreach ($items as $key => $item) {
|
foreach ($items as $key => $item) {
|
||||||
$id = $name . '_' . $key;
|
$id = $name . '_' . $key;
|
||||||
|
@ -283,17 +283,17 @@ function table($columns, $rows_raw, $data = true) {
|
||||||
// If only one column is given
|
// If only one column is given
|
||||||
if (! is_array($columns)) {
|
if (! is_array($columns)) {
|
||||||
$columns = array(
|
$columns = array(
|
||||||
'col' => $columns
|
'col' => $columns
|
||||||
);
|
);
|
||||||
|
|
||||||
$rows = array();
|
$rows = array();
|
||||||
foreach ($rows_raw as $row)
|
foreach ($rows_raw as $row)
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
'col' => $row
|
'col' => $row
|
||||||
);
|
);
|
||||||
} else
|
} else
|
||||||
$rows = $rows_raw;
|
$rows = $rows_raw;
|
||||||
|
|
||||||
if (count($rows) == 0)
|
if (count($rows) == 0)
|
||||||
return info(_("No data found."), true);
|
return info(_("No data found."), true);
|
||||||
$html = "";
|
$html = "";
|
||||||
|
@ -381,7 +381,7 @@ function html_options($name, $options, $selected = "") {
|
||||||
$html = "";
|
$html = "";
|
||||||
foreach ($options as $value => $label)
|
foreach ($options as $value => $label)
|
||||||
$html .= '<input type="radio"' . ($value == $selected ? ' checked="checked"' : '') . ' name="' . $name . '" value="' . $value . '"> ' . $label;
|
$html .= '<input type="radio"' . ($value == $selected ? ' checked="checked"' : '') . ' name="' . $name . '" value="' . $value . '"> ' . $label;
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,7 +419,7 @@ function ReplaceSmilies($neueckig) {
|
||||||
$neueckig = str_replace(";P", "<img src=\"pic/smiles/icon_mad.gif\">", $neueckig);
|
$neueckig = str_replace(";P", "<img src=\"pic/smiles/icon_mad.gif\">", $neueckig);
|
||||||
$neueckig = str_replace(";oP", "<img src=\"pic/smiles/icon_mad.gif\">", $neueckig);
|
$neueckig = str_replace(";oP", "<img src=\"pic/smiles/icon_mad.gif\">", $neueckig);
|
||||||
$neueckig = str_replace("?)", "<img src=\"pic/smiles/icon_question.gif\">", $neueckig);
|
$neueckig = str_replace("?)", "<img src=\"pic/smiles/icon_question.gif\">", $neueckig);
|
||||||
|
|
||||||
return $neueckig;
|
return $neueckig;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -4,6 +4,25 @@ function ShiftType_delete_view($shifttype) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) {
|
function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) {
|
||||||
|
$angeltypes_select = [
|
||||||
|
'' => _('All')
|
||||||
|
];
|
||||||
|
foreach ($angeltypes as $angeltype)
|
||||||
|
$angeltypes_select[$angeltype['id']] = $angeltype['name'];
|
||||||
|
|
||||||
|
return page_with_title($shifttype_id ? _('Edit shifttype') : _('Create shifttype'), [
|
||||||
|
msg(),
|
||||||
|
buttons([
|
||||||
|
button(page_link_to('shifttypes'), shifttypes_title(), 'back')
|
||||||
|
]),
|
||||||
|
form([
|
||||||
|
form_text('name', _('Name'), $name),
|
||||||
|
form_select('angeltype_id', _('Angeltype'), $angeltypes_select, $angeltype_id),
|
||||||
|
form_textarea('description', _('Description'), $description),
|
||||||
|
form_info('', _('Please use markdown for the description.')),
|
||||||
|
form_submit('submit', _('Save'))
|
||||||
|
])
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ShiftType_view($shifttype) {
|
function ShiftType_view($shifttype) {
|
||||||
|
@ -12,21 +31,21 @@ function ShiftType_view($shifttype) {
|
||||||
function ShiftTypes_list_view($shifttypes) {
|
function ShiftTypes_list_view($shifttypes) {
|
||||||
foreach ($shifttypes as &$shifttype) {
|
foreach ($shifttypes as &$shifttype) {
|
||||||
$shifttype['actions'] = table_buttons([
|
$shifttype['actions'] = table_buttons([
|
||||||
button(page_link_to('shifttypes') . '&action=edit&shifttype_id=' . $shifttype['id'], _("edit"), "btn-xs"),
|
button(page_link_to('shifttypes') . '&action=edit&shifttype_id=' . $shifttype['id'], _('edit'), 'btn-xs'),
|
||||||
button(page_link_to('shifttypes') . '&action=delete&shifttype_id=' . $shifttypes['id'], _("delete"), "btn-xs")
|
button(page_link_to('shifttypes') . '&action=delete&shifttype_id=' . $shifttype['id'], _('delete'), 'btn-xs')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return page_with_title(shifttypes_title(), array(
|
return page_with_title(shifttypes_title(), [
|
||||||
msg(),
|
msg(),
|
||||||
buttons(array(
|
buttons([
|
||||||
button(page_link_to('shifttypes') . '&action=edit', _("New shifttype"), 'add')
|
button(page_link_to('shifttypes') . '&action=edit', _('New shifttype'), 'add')
|
||||||
)),
|
]),
|
||||||
table(array(
|
table([
|
||||||
'name' => _("Name"),
|
'name' => _('Name'),
|
||||||
'actions' => ""
|
'actions' => ''
|
||||||
), $shifttypes)
|
], $shifttypes)
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue