summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2011-12-21 22:20:06 +0100
committerPhilip Häusler <msquare@notrademark.de>2011-12-21 22:20:06 +0100
commit5e5443fad6bcd49ee57fda70855dc1e63a52f255 (patch)
treec1b7475495ca7775dd2f975ff010b67255e34076 /includes
parent23d82fecb4d1e40f2ef8fe1ebc16455fa7221f0f (diff)
#44 angeltypes recreated
Diffstat (limited to 'includes')
-rw-r--r--includes/pages/admin_angel_types.php183
-rw-r--r--includes/pages/admin_rooms.php4
-rw-r--r--includes/pages/admin_shifts.php2
-rw-r--r--includes/pages/guest_login.php2
-rw-r--r--includes/pages/user_myshifts.php2
-rw-r--r--includes/pages/user_shifts.php8
-rw-r--r--includes/sys_page.php99
-rw-r--r--includes/sys_template.php124
8 files changed, 314 insertions, 110 deletions
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 @@
<?php
-
function admin_angel_types() {
- $html = "";
- if (!isset ($_REQUEST['action'])) {
-
- $table = "";
- $angel_types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `Name`");
-
- foreach ($angel_types as $angel_type)
- $table .= sprintf(
- '<tr><td>%s</td><td>%s</td><td>'
- . '<a href="%s&action=edit&id=%s">Edit</a></td></tr>',
- $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;
+ $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 ? '&#10003;' : '',
+ 'actions' => '<a class="action edit" href="' . page_link_to('admin_angel_types') . '&show=edit&id=' . $angel_type['id'] . '">edit</a> <a class="action delete" href="' . page_link_to('admin_angel_types') . '&show=delete&id=' . $angel_type['id'] . '">delete</a>'
+ );
+ }
- 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.");
+ 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'));
+ }
- $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;
+ 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 $html;
+ 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 .= "<tr><td>" . Get_Text("makeuser_Engelart") . "</td><td align=\"left\">\n";
$html .= "<select name=\"Art\">\n";
- $engel_types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `NAME`");
+ $engel_types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
foreach ($engel_types as $engel_type) {
$Name = $engel_type['Name'] . Get_Text("inc_schicht_engel");
$html .= "<option value=\"" . $Name . "\"";
diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php
index dd53d134..48c3b176 100644
--- a/includes/pages/user_myshifts.php
+++ b/includes/pages/user_myshifts.php
@@ -27,7 +27,7 @@ function user_myshifts() {
}
elseif (isset ($_REQUEST['edit']) && preg_match("/^[0-9]*$/", $_REQUEST['edit'])) {
$id = $_REQUEST['edit'];
- $shift = sql_select("SELECT `ShiftEntry`.`Comment`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`Name` as `angel_type` FROM `ShiftEntry` JOIN `AngelTypes` ON (`ShiftEntry`.`TID` = `AngelTypes`.`TID`) JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `id`=" . sql_escape($id) . " AND `UID`=" . sql_escape($shifts_user['UID']) . " LIMIT 1");
+ $shift = sql_select("SELECT `ShiftEntry`.`Comment`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`name` as `angel_type` FROM `ShiftEntry` JOIN `AngelTypes` ON (`ShiftEntry`.`TID` = `AngelTypes`.`id`) JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `id`=" . sql_escape($id) . " AND `UID`=" . sql_escape($shifts_user['UID']) . " LIMIT 1");
if (count($shift) > 0) {
$shift = $shift[0];
diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php
index 668fe8b7..10a96278 100644
--- a/includes/pages/user_shifts.php
+++ b/includes/pages/user_shifts.php
@@ -36,7 +36,7 @@ function user_shifts() {
$room_array[$room['RID']] = $room['Name'];
// Engeltypen laden
- $types = sql_select("SELECT * FROM `NeededAngelTypes` JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`TID`) WHERE `shift_id`=" . sql_escape($shift_id) . " ORDER BY `AngelTypes`.`Name`");
+ $types = sql_select("SELECT * FROM `NeededAngelTypes` JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`) WHERE `shift_id`=" . sql_escape($shift_id) . " ORDER BY `AngelTypes`.`name`");
$needed_angel_types = array ();
foreach ($types as $type)
$needed_angel_types[$type['TID']] = $type['count'];
@@ -162,7 +162,7 @@ function user_shifts() {
else
header("Location: " . page_link_to('user_shifts'));
- $type = sql_select("SELECT * FROM `AngelTypes` WHERE `TID`=" . sql_escape($type_id) . " LIMIT 1");
+ $type = sql_select("SELECT * FROM `AngelTypes` WHERE `id`=" . sql_escape($type_id) . " LIMIT 1");
if (count($type) == 0)
header("Location: " . page_link_to('user_shifts'));
$type = $type[0];
@@ -240,9 +240,9 @@ function user_shifts() {
$shift_row .= ' <a href="?p=user_shifts&edit_shift=' . $shift['SID'] . '">[edit]</a> <a href="?p=user_shifts&delete_shift=' . $shift['SID'] . '">[x]</a>';
$shift_row .= '<br />';
$show_shift = false;
- $angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`TID`) WHERE `shift_id`=" . sql_escape($shift['SID']) . " AND `count` > 0 ORDER BY `AngelTypes`.`Name`");
+ $angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`) WHERE `shift_id`=" . sql_escape($shift['SID']) . " AND `count` > 0 ORDER BY `AngelTypes`.`name`");
if (count($angeltypes) == 0)
- $angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`TID`) WHERE `room_id`=" . sql_escape($shift['RID']) . " AND `count` > 0 ORDER BY `AngelTypes`.`Name`");
+ $angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`) WHERE `room_id`=" . sql_escape($shift['RID']) . " AND `count` > 0 ORDER BY `AngelTypes`.`name`");
if (count($angeltypes) > 0) {
$my_shift = sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`=" . sql_escape($shift['SID']) . " AND `UID`=" . sql_escape($user['UID']) . " LIMIT 1") > 0;
diff --git a/includes/sys_page.php b/includes/sys_page.php
index e499cd57..54bbd953 100644
--- a/includes/sys_page.php
+++ b/includes/sys_page.php
@@ -1,26 +1,97 @@
<?php
+
+/**
+ * Leitet den Browser an die übergebene URL weiter und hält das Script an.
+ */
+function redirect($to) {
+ header("Location: " . $to, true, 302);
+ die();
+}
+
+/**
+ * Gibt den gefilterten REQUEST Wert ohne Zeilenumbrüche zurück
+ */
function strip_request_item($name) {
- return preg_replace(
- "/([^\p{L}\p{P}\p{Z}\p{N}]{1,})/ui",
- '',
- strip_tags($_REQUEST[$name])
- );
+ return strip_item($_REQUEST[$name]);
}
+/**
+ * Testet, ob der angegebene REQUEST Wert ein Integer ist, bzw. eine ID sein könnte.
+ */
+function test_request_int($name) {
+ if (isset ($_REQUEST[$name]))
+ return preg_match("/^[0-9]*$/", $_REQUEST[$name]);
+ return false;
+}
+
+/**
+ * Gibt den gefilterten REQUEST Wert mit Zeilenumbrüchen zurück
+ */
function strip_request_item_nl($name) {
- return preg_replace(
- "/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui",
- '',
- strip_tags($_REQUEST[$name])
- );
+ return preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}+\n]{1,})/ui", '', strip_tags($_REQUEST[$name]));
+}
+
+/**
+ * Entfernt unerwünschte Zeichen
+ */
+function strip_item($item) {
+ return preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}+]{1,})/ui", '', strip_tags($item));
+}
+
+/**
+ * Gibt zwischengespeicherte Fehlermeldungen zurück und löscht den Zwischenspeicher
+ */
+function msg() {
+ if (!isset ($_SESSION['msg']))
+ return "";
+ $msg = $_SESSION['msg'];
+ $_SESSION['msg'] = "";
+ return $msg;
+}
+
+/**
+ * Rendert eine Information
+ */
+function info($msg, $immediatly = false) {
+ if ($immediatly) {
+ if ($msg == "")
+ return "";
+ return '<p class="info">' . $msg . '</p>';
+ } else {
+ if (!isset ($_SESSION['msg']))
+ $_SESSION['msg'] = "";
+ $_SESSION['msg'] .= info($msg, true);
+ }
}
-function error($msg) {
- return '<p class="error">' . $msg . '</p>';
+/**
+ * Rendert eine Fehlermeldung
+ */
+function error($msg, $immediatly = false) {
+ if ($immediatly) {
+ if ($msg == "")
+ return "";
+ return '<p class="error">' . $msg . '</p>';
+ } else {
+ if (!isset ($_SESSION['msg']))
+ $_SESSION['msg'] = "";
+ $_SESSION['msg'] .= error($msg, true);
+ }
}
-function success($msg) {
- return '<p class="success">' . $msg . '</p>';
+/**
+ * Rendert eine Erfolgsmeldung
+ */
+function success($msg, $immediatly = false) {
+ if ($immediatly) {
+ if ($msg == "")
+ return "";
+ return '<p class="success">' . $msg . '</p>';
+ } else {
+ if (!isset ($_SESSION['msg']))
+ $_SESSION['msg'] = "";
+ $_SESSION['msg'] .= success($msg, true);
+ }
}
?>
diff --git a/includes/sys_template.php b/includes/sys_template.php
index 92e6e674..4af22500 100644
--- a/includes/sys_template.php
+++ b/includes/sys_template.php
@@ -1,6 +1,130 @@
<?php
+/**
+ * Rendert eine Liste von Checkboxen für ein Formular
+ * @param name Die Namen der Checkboxen werden aus name_key gebildet
+ * @param label Die Beschriftung der Liste
+ * @param items Array mit den einzelnen Checkboxen
+ * @param selected Array mit den Keys, die ausgewählt sind
+ */
+function form_checkboxes($name, $label, $items, $selected) {
+ $html = "<ul>";
+ foreach ($items as $key => $item) {
+ $id = $name . '_' . $key;
+ $sel = array_search($key, $selected) !== false ? ' checked="checked"' : "";
+ $html .= '<li><input type="checkbox" id="' . $id . '" name="' . $id . '" value="checked"' . $sel . ' /><label for="' . $id . '">' . $item . '</label></li>';
+ }
+ $html .= "</ul>";
+ return form_element($label, $html);
+}
+
+/**
+ * Rendert eine Checkbox
+ */
+function form_checkbox($name, $label, $selected, $value = 'checked') {
+ return form_element("", '<input type="checkbox" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /><label for="' . $name . '">' . $label . '</label>');
+}
+
+/**
+ * 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('<input class="button save ' . $name . '" type="submit" name="' . $name . '" value="' . $label . '" />', "");
+}
+
+/**
+ * Rendert ein Formular-Textfeld
+ */
+function form_text($name, $label, $value, $disabled = false) {
+ $disabled = $disabled ? ' disabled="disabled"' : '';
+ return form_element($label, '<input id="form_' . $name . '" type="text" name="' . $name . '" value="' . $value . '" ' . $disabled . '/>', 'form_' . $name);
+}
+
+/**
+ * Rendert ein Formular-Textfeld
+ */
+function form_textarea($name, $label, $value, $disabled = false) {
+ $disabled = $disabled ? ' disabled="disabled"' : '';
+ return form_element($label, '<textarea id="form_' . $name . '" type="text" name="' . $name . '" ' . $disabled . '>' . $value . '</textarea>', '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 '<div class="form_element">' . '<label for="' . $for . '" class="form_label">' . $label . '</label><div class="form_input">' . $input . '</div></div>';
+}
+
+/**
+ * Rendert ein Formular
+ */
+function form($elements, $action = "") {
+ return '<form action="' . $action . '" enctype="multipart/form-data" method="post"><div class="form">' . join($elements) . '</div></form>';
+}
+
+/**
+ * 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 .= '<table' . ($data ? ' class="data"' : '') . '>';
+ $html .= '<thead><tr>';
+ foreach ($columns as $key => $column)
+ $html .= '<th>' . $column . '</th>';
+ $html .= '</tr></thead>';
+ $html .= '<tbody>';
+ foreach ($rows as $row) {
+ $html .= '<tr>';
+ foreach ($columns as $key => $column)
+ if (isset ($row[$key]))
+ $html .= '<td class="' . $key . '">' . $row[$key] . '</td>';
+ else
+ $html .= '<td class="' . $key . '">&nbsp;</td>';
+ $html .= '</tr>';
+ }
+ $html .= '</tbody>';
+ $html .= '</table>';
+ return $html;
+}
+
+/**
+ * Rendert einen Knopf
+ */
+function button($href, $label, $class = "") {
+ return '<a href="' . $href . '" class="button ' . $class . '">' . $label . '</a>';
+}
+
+/**
+ * Rendert eine Toolbar mit Knöpfen
+ */
+function buttons($buttons = array ()) {
+ return '<div class="toolbar">' . join($buttons) . '</div>';
+}
+
// Load and render template
function template_render($file, $data) {
if (file_exists($file)) {