<?php if (array_key_exists("action", $_POST) && $_POST["action"] === "search") { $db = DB::getInstance(); $where = $db->quote($_POST["field"], DB::PARAM_IDENT) . " LIKE " . $db->quote(str_replace(array("%", "*"), array("\\%", "%"), $_POST["value"]), DB::PARAM_STR); $temp->content .= '<h1>Search results</h1>'; $temp->content .= DBItem::getByConditionCLASS($class, $where)->view(false, false); } else { $temp->content = '<h1>Search ' . $class . '</h1>' . '<form method="POST">Search in <select name="field">'; foreach (DBItemField::parseClass($class) as $item) { /* @var $item DBItemField */ if ($item->searchable) { $temp->content .= '<option>' . $item->name . '</option>'; } } $temp->content .= '</select> for <input name="value"><br><button type="submit" name="action" value="search">search</button></form>'; }
<?php /* @var $this Shelf */ ?> <article class="DBItem <?php echo $this->specifier->getClassName(); ?> "> <h1><?php $this->view("singleLine", true); ?> </h1> <table> <?php $this->emit(new Event("view.fields.start", $this)); foreach (DBItemField::parseClass(get_class($this)) as $item) { /* @var $item DBItemField */ if ($item->displayable) { echo "<tr><td>" . $this->html($item->displayName) . "</td><td>"; $item->view(false, true, $this); echo "</td></tr>"; if ($item->name === "storage") { if ($this->storage && $this->storage->room) { echo "<tr><td>location</td><td>"; $this->storage->room->view("map", true, array("storage" => $this->storage)); echo "</td></tr>"; } } $this->emit(new Event("view.field." . $item->name, $this)); } }
<?php if (include "login.php") { if (array_key_exists("id", $_POST) && array_key_exists("action", $_POST)) { switch ($_POST["action"]) { case "save": $item = DBItem::getCLASS($class, $_POST["id"]); $data = DBItemField::parseClass($class)->translateRequestData($_POST[$class][$item->DBid]); foreach ($data as $name => $value) { $item->{$name} = $value; } $temp->content .= $item->view("edit", false); break; case "delete": $item = DBItem::getCLASS($class, $_POST["id"]); $line = $item->view("singleLine"); $item->delete(); $temp->content = '<h1>' . $line . ' deleted</h1>'; break; } } else { if (array_key_exists("id", $_GET)) { $item = DBItem::getCLASS($class, $_GET["id"]); $temp->content = '<h1>Edit ' . $item->view("singleLine") . '</h1><form method="POST" enctype="multipart/form-data">'; $temp->content .= $item->view("edit", false); $temp->content .= '<button type="submit" name="action" value="save">save</button>' . '<button type="submit" name="action" value="delete">delete</button>' . '</form>'; } else { $temp->content = '<h1>Choose ' . $class . '</h1><ul>'; foreach (DBItem::getByConditionCLASS($class, false) as $item) { $temp->content .= '<li>' . $item->view("link.edit", false) . '</li>'; }
<?php if (include "login.php") { $temp->content .= '<h1>Enter data for new ' . $class . '</h1><form method="POST" enctype="multipart/form-data">'; $item = DBItem::getCLASS($class, 0); $temp->content .= $item->view("edit", false); $temp->content .= '<button type="submit" name="action" value="save">save</button></form>'; $temp->content .= '<script type="text/javascript">(function(){ var forms = document.getElementsByTagName("form"); forms[forms.length - 1].elements[2].select(); })()</script>'; if (array_key_exists("id", $_POST) && array_key_exists("action", $_POST) && $_POST["action"] === "save") { $item = DBItem::createCLASS($class, DBItemField::parseClass($class)->translateRequestData($_POST[$class][0])); if ($item->hasField("creator")) { $item->creator = $_SESSION["userID"]; } $temp->content .= '<h1>Entry saved.</h1>'; $temp->content .= $item->view(false, false); } }