From 5e5443fad6bcd49ee57fda70855dc1e63a52f255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20H=C3=A4usler?= Date: Wed, 21 Dec 2011 22:20:06 +0100 Subject: [PATCH] #44 angeltypes recreated --- db/update.sql | 8 +- includes/pages/admin_angel_types.php | 189 ++++++++++++++------------- includes/pages/admin_rooms.php | 4 +- includes/pages/admin_shifts.php | 2 +- includes/pages/guest_login.php | 2 +- includes/pages/user_myshifts.php | 2 +- includes/pages/user_shifts.php | 8 +- includes/sys_page.php | 99 ++++++++++++-- includes/sys_template.php | 124 ++++++++++++++++++ public/css/base.css | 85 +++++++++++- 10 files changed, 407 insertions(+), 116 deletions(-) diff --git a/db/update.sql b/db/update.sql index 994e285d..7da5f3e6 100644 --- a/db/update.sql +++ b/db/update.sql @@ -12,4 +12,10 @@ NULL , 'ical', 'iCal shift export' ); /* DECT Nummern können für GSM auch 5-stellig sein. */ -ALTER TABLE `User` CHANGE `DECT` `DECT` VARCHAR( 5 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL; \ No newline at end of file +ALTER TABLE `User` CHANGE `DECT` `DECT` VARCHAR( 5 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL; + +/* Neues Engeltypen-System */ +ALTER TABLE `AngelTypes` DROP `Man`; +ALTER TABLE `AngelTypes` CHANGE `TID` `id` INT( 11 ) NOT NULL AUTO_INCREMENT; +ALTER TABLE `AngelTypes` CHANGE `Name` `name` VARCHAR( 25 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT ''; +ALTER TABLE `AngelTypes` ADD `restricted` INT( 1 ) NOT NULL; diff --git a/includes/pages/admin_angel_types.php b/includes/pages/admin_angel_types.php index 0a7a721c..f9c39ebf 100644 --- a/includes/pages/admin_angel_types.php +++ b/includes/pages/admin_angel_types.php @@ -1,96 +1,105 @@ %s%s' - . 'Edit', - $angel_type['Name'], $angel_type['Man'], - page_link_to("admin_angel_types"), - $angel_type['TID'] - ); - - $html .= template_render('../templates/admin_angel_types.html', array ( - 'link' => page_link_to("admin_angel_types"), - 'table' => $table - )); - - } else { - - switch ($_REQUEST['action']) { - - case 'create' : - $name = strip_request_item("name"); - $man = strip_request_item("man"); - - sql_query("INSERT INTO `AngelTypes` SET `Name`='" . sql_escape($name) . "', `Man`='" . sql_escape($man) . "'"); - - header("Location: " . page_link_to("admin_angel_types")); - break; - - case 'edit' : - if (isset ($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) - $id = $_REQUEST['id']; - else - return error("Incomplete call, missing AngelType ID."); - - $angel_type = sql_select("SELECT * FROM `AngelTypes` WHERE `TID`=" . sql_escape($id) . " LIMIT 1"); - if (count($angel_type) > 0) { - list ($angel_type) = $angel_type; - - $html .= template_render( - '../templates/admin_angel_types_edit_form.html', array ( - 'link' => page_link_to("admin_angel_types"), - 'id' => $id, - 'name' => $angel_type['Name'], - 'man' => $angel_type['Man'] - )); - } else - return error("No Angel Type found."); - break; - - case 'save' : - if (isset ($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) - $id = $_REQUEST['id']; - else - return error("Incomplete call, missing AngelType ID."); - - $angel_type = sql_select("SELECT * FROM `AngelTypes` WHERE `TID`=" . sql_escape($id) . " LIMIT 1"); - if (count($angel_type) > 0) { - list ($angel_type) = $angel_type; - - $name = strip_request_item("name"); - $man = strip_request_item("man"); - - sql_query("UPDATE `AngelTypes` SET `Name`='" . sql_escape($name) . "', `Man`='" . sql_escape($man) . "' WHERE `TID`=" . sql_escape($id) . " LIMIT 1"); - header("Location: " . page_link_to("admin_angel_types")); - } else - return error("No Angel Type found."); - break; - - case 'delete' : - if (isset ($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) - $id = $_REQUEST['id']; - else - return error("Incomplete call, missing AngelType ID."); - - $angel_type = sql_select("SELECT * FROM `AngelTypes` WHERE `TID`=" . sql_escape($id) . " LIMIT 1"); - if (count($angel_type) > 0) { - sql_query("DELETE FROM `AngelTypes` WHERE `TID`=" . sql_escape($id) . " LIMIT 1"); - sql_query("DELETE FROM `NeededAngelTypes` WHERE `angel_type_id`=" . sql_escape($id) . " LIMIT 1"); - header("Location: " . page_link_to("admin_angel_types")); - } else - return error("No Angel Type found."); - break; - } + $angel_types_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`"); + $angel_types = array (); + foreach ($angel_types_source as $angel_type) { + $angel_types[] = array ( + 'id' => $angel_type['id'], + 'name' => $angel_type['name'], + 'restricted' => $angel_type['restricted'] == 1 ? '✓' : '', + 'actions' => 'edit delete' + ); } - return $html; + if (isset ($_REQUEST['show'])) { + if (test_request_int('id')) { + $angel_type = sql_select("SELECT * FROM `AngelTypes` WHERE `id`=" . sql_escape($_REQUEST['id'])); + if (count($angel_type) > 0) { + $id = $_REQUEST['id']; + $name = $angel_type[0]['name']; + $restricted = $angel_type[0]['restricted']; + } else + redirect(page_link_to('admin_angel_types')); + } + + if ($_REQUEST['show'] == 'edit') { + $msg = ""; + $name = ""; + $restricted = 0; + + if (isset ($_REQUEST['submit'])) { + $ok = true; + + if (isset ($_REQUEST['name']) && strlen(strip_request_item('name')) > 0) { + $name = strip_request_item('name'); + if (sql_num_query("SELECT * FROM `AngelTypes` WHERE NOT `id`=" . sql_escape(isset ($id) ? $id : 0) . " AND `name`='" . sql_escape(strip_request_item('name')) . "' LIMIT 1") > 0) { + $ok = false; + $msg .= error("This angel type name is already given.", true); + } + } else { + $ok = false; + $msg .= error("Please enter a name.", true); + } + + if (isset ($_REQUEST['restricted'])) + $restricted = 1; + + if ($ok) { + if (isset ($id)) + sql_query("UPDATE `AngelTypes` SET `name`='" . sql_escape($name) . "', `restricted`=" . sql_escape($restricted) . " WHERE `id`=" . sql_escape($id) . " LIMIT 1"); + else + sql_query("INSERT INTO `AngelTypes` SET `name`='" . sql_escape($name) . "', `restricted`=" . sql_escape($restricted)); + + success("Angel type saved."); + redirect(page_link_to('admin_angel_types')); + } + } + + return page(array ( + buttons(array ( + button(page_link_to('admin_angel_types'), "Back", 'back') + )), + $msg, + form(array ( + form_text('name', 'Name', $name), + form_checkbox('restricted', 'Restricted', $restricted), + form_info("", "Restricted angel types can only be used by an angel if enabled by an archangel (double opt-in)."), + form_submit('submit', 'Save') + )) + )); + } + elseif ($_REQUEST['show'] == 'delete') { + if (isset ($_REQUEST['ack'])) { + sql_query("DELETE FROM `NeededAngelTypes` WHERE `angel_type_id`=" . sql_escape($id) . " LIMIT 1"); + sql_query("DELETE FROM `ShiftEntry` WHERE `TID`=" . sql_escape($id) . " LIMIT 1"); + sql_query("DELETE FROM `AngelTypes` WHERE `id`=" . sql_escape($id) . " LIMIT 1"); + success(sprintf("Angel type %s deleted.", $name)); + redirect(page_link_to('admin_angel_types')); + } + + return page(array ( + buttons(array ( + button(page_link_to('admin_angel_types'), "Back", 'back') + )), + sprintf("Do you want to delete angel type %s?", $name), + buttons(array ( + button(page_link_to('admin_angel_types') . '&show=delete&id=' . $id . '&ack', "Delete", 'delete') + )) + )); + } else + redirect(page_link_to('admin_angel_types')); + } + + return page(array ( + buttons(array ( + button(page_link_to('admin_angel_types') . '&show=edit', "Add", 'add') + )), + msg(), + table(array ( + 'name' => "Name", + 'restricted' => "Restricted", + 'actions' => "" + ), $angel_types) + )); } ?> diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php index c4e8ba46..e04e3697 100644 --- a/includes/pages/admin_rooms.php +++ b/includes/pages/admin_rooms.php @@ -63,7 +63,7 @@ function admin_rooms() { $room = sql_select("SELECT * FROM `Room` WHERE `RID`=" . sql_escape($rid) . " LIMIT 1"); if (count($room) > 0) { list ($room) = $room; - $room_angel_types = sql_select("SELECT * FROM `AngelTypes` LEFT OUTER JOIN `NeededAngelTypes` ON (`AngelTypes`.`TID` = `NeededAngelTypes`.`angel_type_id` AND `NeededAngelTypes`.`room_id`=" . sql_escape($rid) . ") ORDER BY `AngelTypes`.`Name`"); + $room_angel_types = sql_select("SELECT * FROM `AngelTypes` LEFT OUTER JOIN `NeededAngelTypes` ON (`AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id` AND `NeededAngelTypes`.`room_id`=" . sql_escape($rid) . ") ORDER BY `AngelTypes`.`name`"); $angel_types = ""; foreach ($room_angel_types as $room_angel_type) { @@ -101,7 +101,7 @@ function admin_rooms() { $room = sql_select("SELECT * FROM `Room` WHERE `RID`=" . sql_escape($rid) . " LIMIT 1"); if (count($room) > 0) { list ($room) = $room; - $room_angel_types = sql_select("SELECT * FROM `AngelTypes` LEFT OUTER JOIN `NeededAngelTypes` ON (`AngelTypes`.`TID` = `NeededAngelTypes`.`angel_type_id` AND `NeededAngelTypes`.`room_id`=" . sql_escape($rid) . ") ORDER BY `AngelTypes`.`Name`"); + $room_angel_types = sql_select("SELECT * FROM `AngelTypes` LEFT OUTER JOIN `NeededAngelTypes` ON (`AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id` AND `NeededAngelTypes`.`room_id`=" . sql_escape($rid) . ") ORDER BY `AngelTypes`.`name`"); $name = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}]{1,})/ui", '', strip_tags($_REQUEST['Name'])); $man = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}]{1,})/ui", '', strip_tags($_REQUEST['Man'])); diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index 94c6f38a..ebc503f1 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -21,7 +21,7 @@ function admin_shifts() { $room_array[$room['RID']] = $room['Name']; // Engeltypen laden - $types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `Name`"); + $types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`"); $needed_angel_types = array (); foreach ($types as $type) $needed_angel_types[$type['TID']] = 0; diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 51afd9c5..47c1c0a7 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -168,7 +168,7 @@ function guest_register() { $html .= "" . Get_Text("makeuser_Engelart") . "\n"; $html .= "'; + } + $html .= ""; + return form_element($label, $html); +} + +/** + * Rendert eine Checkbox + */ +function form_checkbox($name, $label, $selected, $value = 'checked') { + return form_element("", ''); +} + +/** + * Rendert einen Infotext in das Formular + */ +function form_info($label, $text) { + return form_element($label, $text, ""); +} + +/** + * Rendert den Absenden-Button eines Formulars + */ +function form_submit($name, $label) { + return form_element('', ""); +} + +/** + * Rendert ein Formular-Textfeld + */ +function form_text($name, $label, $value, $disabled = false) { + $disabled = $disabled ? ' disabled="disabled"' : ''; + return form_element($label, '', 'form_' . $name); +} + +/** + * Rendert ein Formular-Textfeld + */ +function form_textarea($name, $label, $value, $disabled = false) { + $disabled = $disabled ? ' disabled="disabled"' : ''; + return form_element($label, '', 'form_' . $name); +} + +/** + * Rendert ein Formular-Auswahlfeld + */ +function form_select($name, $label, $values, $selected) { + return form_element($label, html_select_key('form_' . $name, $name, $values, $selected), 'form_' . $name); +} + +/** + * Rendert ein Formular-Element + */ +function form_element($label, $input, $for = "") { + return '
' . '
' . $input . '
'; +} + +/** + * Rendert ein Formular + */ +function form($elements, $action = "") { + return '
' . join($elements) . '
'; +} + +/** + * Generiert HTML Code für eine "Seite". Fügt dazu die übergebenen Elemente zusammen. + */ +function page($elements) { + return join($elements); +} + +/** + * Rendert eine Datentabelle + */ +function table($columns, $rows, $data = true) { + if (count($rows) == 0) + return info("No data available.", true); + $html = ""; + $html .= ''; + $html .= ''; + foreach ($columns as $key => $column) + $html .= '' . $column . ''; + $html .= ''; + $html .= ''; + foreach ($rows as $row) { + $html .= ''; + foreach ($columns as $key => $column) + if (isset ($row[$key])) + $html .= '' . $row[$key] . ''; + else + $html .= ' '; + $html .= ''; + } + $html .= ''; + $html .= ''; + return $html; +} + +/** + * Rendert einen Knopf + */ +function button($href, $label, $class = "") { + return '' . $label . ''; +} + +/** + * Rendert eine Toolbar mit Knöpfen + */ +function buttons($buttons = array ()) { + return '
' . join($buttons) . '
'; +} + // Load and render template function template_render($file, $data) { if (file_exists($file)) { diff --git a/public/css/base.css b/public/css/base.css index 55af610f..d8940de3 100644 --- a/public/css/base.css +++ b/public/css/base.css @@ -106,6 +106,7 @@ a.sprache img { table { border-collapse: collapse; + margin-top: 5px; } fieldset hr { @@ -194,12 +195,22 @@ tr:hover .hidden { background: #fff; } +.error, .info, .success { + background: #f0f0f0; + border: 1px solid #888; + border-radius: 2px; + color: #000; + padding: 5px; +} + .error { - color: #f00; + background: #f99; + border-color: #900; } .success { - color: #090; + background: #9f9; + border-color: #090; } .notice { @@ -262,3 +273,73 @@ tr:hover .hidden { text-align: right; width: 42px; } + +.toolbar { + margin: 5px 0 10px 0; +} + +.button { + background: #f0f0f0; + border: 1px solid #888; + border-radius: 4px; + margin-right: 5px; + padding: 2px 5px; + text-decoration: none; +} + +.button:hover { + background: #fff; +} + + +.form { + border: 1px solid #888; + border-radius: 2px; + margin: 10px 0; + padding: 10px 10px 0 10px; +} + +.form_element { + /* clear: left; */ + min-height: 32px; + margin-bottom: 10px; +} + +.form_label { + display: block; + float: left; + width: 250px; +} + +.form_input { + margin-left: 250px; +} + +.form input[type="text"], .form textarea { + background: #fff; + border: 1px solid #888; + color: inherit; + font-family: inherit; + font-size: inherit; + padding: 2px; + width: 350px; +} + +.form input[disabled="disabled"] { + background: #f0f0f0; + color: #999; +} + +.form input[type="submit"] { + cursor: pointer; + font-family: inherit; + font-size: inherit; +} + +.form input[type="checkbox"] { + margin-right: 10px; +} + +.form ul { + list-style: none; +}