#44 angeltypes recreated
parent
23d82fecb4
commit
5e5443fad6
@ -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']
|
||||
$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' => '<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>'
|
||||
);
|
||||
}
|
||||
|
||||
$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 (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) {
|
||||
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']
|
||||
));
|
||||
$id = $_REQUEST['id'];
|
||||
$name = $angel_type[0]['name'];
|
||||
$restricted = $angel_type[0]['restricted'];
|
||||
} else
|
||||
return error("No Angel Type found.");
|
||||
break;
|
||||
redirect(page_link_to('admin_angel_types'));
|
||||
}
|
||||
|
||||
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.");
|
||||
if ($_REQUEST['show'] == 'edit') {
|
||||
$msg = "";
|
||||
$name = "";
|
||||
$restricted = 0;
|
||||
|
||||
$angel_type = sql_select("SELECT * FROM `AngelTypes` WHERE `TID`=" . sql_escape($id) . " LIMIT 1");
|
||||
if (count($angel_type) > 0) {
|
||||
list ($angel_type) = $angel_type;
|
||||
if (isset ($_REQUEST['submit'])) {
|
||||
$ok = true;
|
||||
|
||||
$name = strip_request_item("name");
|
||||
$man = strip_request_item("man");
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
if (isset ($_REQUEST['restricted']))
|
||||
$restricted = 1;
|
||||
|
||||
case 'delete' :
|
||||
if (isset ($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id']))
|
||||
$id = $_REQUEST['id'];
|
||||
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
|
||||
return error("Incomplete call, missing AngelType ID.");
|
||||
sql_query("INSERT INTO `AngelTypes` SET `name`='" . sql_escape($name) . "', `restricted`=" . sql_escape($restricted));
|
||||
|
||||
$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");
|
||||
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");
|
||||
header("Location: " . page_link_to("admin_angel_types"));
|
||||
} else
|
||||
return error("No Angel Type found.");
|
||||
break;
|
||||
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)
|
||||
));
|
||||
}
|
||||
?>
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
function error($msg) {
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue