Add machine editing APIs
This commit is contained in:
parent
6c2ef83ec6
commit
d156725bf7
@ -97,9 +97,8 @@ switch ($VARS['action']) {
|
||||
returnToSender("invalid_parameters");
|
||||
}
|
||||
|
||||
$machine = new Machine($VARS['machine']);
|
||||
|
||||
$machine->addEvent(
|
||||
$evt = Event::create(
|
||||
$VARS['machine'],
|
||||
date(
|
||||
"Y-m-d H:i:s",
|
||||
strtotime($VARS['date'] . " " . $VARS['time'])
|
||||
@ -110,7 +109,7 @@ switch ($VARS['action']) {
|
||||
$VARS['privatenotes']
|
||||
);
|
||||
|
||||
returnToSender("event_added", $machine->getID());
|
||||
returnToSender("event_added", $VARS['machine']);
|
||||
case "editclient":
|
||||
$user = new User($_SESSION['uid']);
|
||||
if (!$user->hasPermission("MACHINEMANAGER_EDIT")) {
|
||||
|
@ -1,4 +1,3 @@
|
||||
# Rewrite for Nextcloud Notes API
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine on
|
||||
RewriteRule ([a-zA-Z0-9]+) index.php?action=$1 [PT]
|
||||
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2020 Netsyms Technologies.
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
if (empty($VARS["id"]) || (!Machine::exists($VARS["id"]) && !Machine::serialExists($VARS["id"]))) {
|
||||
sendJsonResp("Requested ID does not exist.", "ERROR");
|
||||
}
|
||||
|
||||
if (Machine::exists($VARS["id"])) {
|
||||
$machine = new Machine($VARS['id']);
|
||||
} else {
|
||||
$machine = new Machine(Machine::getIDFromSerial($VARS['id']));
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
exit(json_encode($machine));
|
69
api/actions/machine.php
Normal file
69
api/actions/machine.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2020 Netsyms Technologies.
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
if (!empty($VARS["id"])) {
|
||||
if (Machine::exists($VARS["id"])) {
|
||||
$machine = new Machine($VARS['id']);
|
||||
} else if (Machine::serialExists($VARS["id"])) {
|
||||
$machine = new Machine(Machine::getIDFromSerial($VARS['id']));
|
||||
} else {
|
||||
http_response_code(404);
|
||||
sendJsonResp("Requested ID does not exist.", "ERROR");
|
||||
}
|
||||
} else {
|
||||
$machine = Machine::create();
|
||||
}
|
||||
|
||||
$user = getRequestUser();
|
||||
|
||||
|
||||
if ($VARS["action"] != "lookup") {
|
||||
|
||||
if (!$user->hasPermission("MACHINEMANAGER_EDIT")) {
|
||||
http_response_code(403);
|
||||
sendJsonResp("You don't have permission to edit.", "ERROR");
|
||||
}
|
||||
|
||||
if (!empty($VARS["model"])) {
|
||||
$machine->setModel($VARS['model']);
|
||||
}
|
||||
if (!empty($VARS["client"])) {
|
||||
$machine->setClientID($VARS['client']);
|
||||
}
|
||||
if (!empty($VARS["os"])) {
|
||||
$machine->setOS($VARS['os']);
|
||||
}
|
||||
if (!empty($VARS["serial"])) {
|
||||
$machine->setSerial($VARS['serial']);
|
||||
}
|
||||
if (!empty($VARS["manufacturer"])) {
|
||||
$machine->setManufacturer($VARS['manufacturer']);
|
||||
}
|
||||
if (!empty($VARS["condition"])) {
|
||||
$machine->setCondition($VARS['condition']);
|
||||
}
|
||||
if (!empty($VARS["price"])) {
|
||||
$machine->setPrice($VARS['price']);
|
||||
}
|
||||
if (!empty($VARS["privatenotes"])) {
|
||||
$machine->setPrivateNotes($VARS['privatenotes']);
|
||||
}
|
||||
if (!empty($VARS["publicnotes"])) {
|
||||
$machine->setPublicNotes($VARS['publicnotes']);
|
||||
}
|
||||
|
||||
$machine->save();
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
$output = $machine->toArray();
|
||||
$output["editable"] = $user->hasPermission("MACHINEMANAGER_EDIT");
|
||||
|
||||
exit(json_encode($output));
|
@ -13,9 +13,38 @@ $APIS = [
|
||||
]
|
||||
],
|
||||
"lookup" => [
|
||||
"load" => "lookup.php",
|
||||
"load" => "machine.php",
|
||||
"vars" => [
|
||||
"id" => "/^[0-9a-z]+$/"
|
||||
]
|
||||
],
|
||||
"editmachine" => [
|
||||
"load" => "machine.php",
|
||||
"vars" => [
|
||||
"id" => "/^[0-9a-z]+$/",
|
||||
"model (optional)" => "string",
|
||||
"client (optional)" => "string",
|
||||
"os (optional)" => "string",
|
||||
"serial (optional)" => "string",
|
||||
"manufacturer (optional)" => "string",
|
||||
"condition (optional)" => "numeric",
|
||||
"price (optional)" => "numeric",
|
||||
"privatenotes (optional)" => "string",
|
||||
"publicnotes (optional)" => "string"
|
||||
]
|
||||
],
|
||||
"addmachine" => [
|
||||
"load" => "machine.php",
|
||||
"vars" => [
|
||||
"model (optional)" => "string",
|
||||
"client (optional)" => "string",
|
||||
"os (optional)" => "string",
|
||||
"serial (optional)" => "string",
|
||||
"manufacturer (optional)" => "string",
|
||||
"condition (optional)" => "numeric",
|
||||
"price (optional)" => "numeric",
|
||||
"privatenotes (optional)" => "string",
|
||||
"publicnotes (optional)" => "string"
|
||||
]
|
||||
]
|
||||
];
|
||||
|
148
api/login/index.php
Normal file
148
api/login/index.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
require __DIR__ . "/../../required.php";
|
||||
|
||||
session_start();
|
||||
|
||||
header("Content-Security-Policy: default-src '*';");
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
|
||||
$redirecttologin = false;
|
||||
|
||||
$thisurl = "https://track.netsyms.com/api/login/index.php";
|
||||
$iconurl = "https://static.netsyms.net/images/products/machinemanager/logo.svg";
|
||||
|
||||
/**
|
||||
* Show a simple HTML page with a line of text and a button. Matches the UI of
|
||||
* the AccountHub login flow.
|
||||
*
|
||||
* @global type $SETTINGS
|
||||
* @global type $SECURE_NONCE
|
||||
* @global type $Strings
|
||||
* @param string $title Text to show, passed through i18n
|
||||
* @param string $button Button text, passed through i18n
|
||||
* @param string $url URL for the button
|
||||
*/
|
||||
function showHTML(string $title, string $button = "", string $url = "", string $message = "") {
|
||||
global $SETTINGS, $iconurl;
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title><?php echo $SETTINGS['app_name']; ?></title>
|
||||
|
||||
<link rel="icon" href="<?php echo $iconurl; ?>">
|
||||
|
||||
<link href="https://static.netsyms.net/bootstrap/4/bootstrap.materia.min.css" rel="stylesheet">
|
||||
<style>
|
||||
.display-5 {
|
||||
font-size: 2.5rem;
|
||||
font-weight: 300;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.banner-image {
|
||||
max-height: 100px;
|
||||
margin: 2em auto;
|
||||
border: 1px solid grey;
|
||||
border-radius: 15%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="container mt-4">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-12 text-center">
|
||||
<img class="banner-image" src="<?php echo $iconurl; ?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-12 text-center">
|
||||
<h1 class="display-5 mb-4"><?php echo $title; ?></h1>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($message)) { ?>
|
||||
<div class="col-12 col-sm-8 col-lg-6">
|
||||
<div class="card mt-4">
|
||||
<div class="card-body">
|
||||
<p>
|
||||
<?php echo $message; ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (!empty($button)) { ?>
|
||||
<div class="col-12 col-sm-8 col-lg-6">
|
||||
<div class="card mt-4">
|
||||
<div class="card-body">
|
||||
<a href="<?php echo $url; ?>" class="btn btn-primary btn-block"><?php echo $button; ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if (empty($_SESSION["login_code"])) {
|
||||
$redirecttologin = true;
|
||||
} else {
|
||||
try {
|
||||
$uidinfo = AccountHubApi::get("checkloginkey", ["code" => $_SESSION["login_code"]]);
|
||||
|
||||
if ($uidinfo["status"] == "ERROR") {
|
||||
throw new Exception();
|
||||
}
|
||||
if (is_numeric($uidinfo['uid'])) {
|
||||
$user = new User($uidinfo['uid'] * 1);
|
||||
|
||||
$addpassresp = AccountHubApi::get(
|
||||
"addapppassword",
|
||||
[
|
||||
"desc" => $SETTINGS["app_name"],
|
||||
"username" => $user->getUsername()
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
$_SESSION["login_code"] = null;
|
||||
|
||||
$redirecturl = "https://apploginhelper.netsyms.net/?user:" . htmlentities($user->getUsername()) . "&password:" . htmlentities($addpassresp["pass"]);
|
||||
|
||||
header("Location: $redirecturl");
|
||||
showHTML("Continue", "Click Here", $redirecturl);
|
||||
} else {
|
||||
throw new Exception();
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
$redirecttologin = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($redirecttologin) {
|
||||
try {
|
||||
$codedata = AccountHubApi::get("getloginkey", ["appname" => $SETTINGS["app_name"], "appicon" => $iconurl], true);
|
||||
|
||||
if ($codedata['status'] != "OK") {
|
||||
throw new Exception("There was a problem. Try again later.");
|
||||
}
|
||||
|
||||
$_SESSION["login_code"] = $codedata["code"];
|
||||
|
||||
$locationurl = $codedata["loginurl"] . "?code=" . htmlentities($codedata["code"]) . "&redirect=" . htmlentities($thisurl);
|
||||
|
||||
header("Location: $locationurl");
|
||||
showHTML("Continue", "Continue", $locationurl);
|
||||
die();
|
||||
} catch (Exception $ex) {
|
||||
showHTML("Error", "", "", $ex->getMessage());
|
||||
}
|
||||
}
|
4
langs/en/components.json
Normal file
4
langs/en/components.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"Type": "Type",
|
||||
"Tested": "Tested"
|
||||
}
|
4
langs/en/events.json
Normal file
4
langs/en/events.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"Date": "Date",
|
||||
"Technician": "Technician"
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
use InvoiceNinja\Config as NinjaConfig;
|
||||
use InvoiceNinja\Models\Client as NinjaClient;
|
||||
|
||||
class Client {
|
||||
class Client implements JsonSerializable {
|
||||
|
||||
private $local = true;
|
||||
private $exists = false;
|
||||
@ -54,6 +54,13 @@ class Client {
|
||||
}
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"name" => $this->name
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in all the client data from the InvoiceNinja API.
|
||||
*/
|
||||
|
@ -41,6 +41,15 @@ if (!empty($SETTINGS["apis"]["invoiceninja"]["token"])) {
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function getAllAsIDNameArray(): array {
|
||||
$clients = Clients::getAll();
|
||||
$arr = [];
|
||||
foreach ($clients as $c) {
|
||||
$arr[$c->getID()] = $c->getName();
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public static function getClient($id): Client {
|
||||
return new Client($id, false);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
class Component {
|
||||
class Component implements JsonSerializable {
|
||||
|
||||
private $componentid = "";
|
||||
private $component = [];
|
||||
@ -39,6 +39,60 @@ class Component {
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
global $Strings;
|
||||
if ($this->exists) {
|
||||
return [
|
||||
"info" => [
|
||||
"id" => $this->getID(),
|
||||
"machineid" => $this->getMachineID(),
|
||||
"serial" => $this->getSerial(),
|
||||
"type" => $this->getTypeID(),
|
||||
"tested" => $this->getTestedDate(),
|
||||
"capacity" => $this->getCapacity(),
|
||||
"model" => $this->getModel(),
|
||||
"price" => $this->getPrice(),
|
||||
"manufacturer" => $this->getManufacturer(),
|
||||
"publicnotes" => $this->getPublicNotes(),
|
||||
"privatenotes" => $this->getPrivateNotes()
|
||||
],
|
||||
"formdata" => [
|
||||
"types" => $this->getTypes(),
|
||||
"inputtypes" => [
|
||||
"machineid" => "text",
|
||||
"serial" => "text",
|
||||
"type" => "number",
|
||||
"tested" => "datetime",
|
||||
"capacity" => "text",
|
||||
"model" => "text",
|
||||
"price" => "number",
|
||||
"manufacturer" => "text",
|
||||
"privatenotes" => "textarea",
|
||||
"publicnotes" => "textarea"
|
||||
],
|
||||
"labels" => [
|
||||
"machineid" => $Strings->get("Machine ID", false),
|
||||
"serial" => $Strings->get("Serial", false),
|
||||
"type" => $Strings->get("Type", false),
|
||||
"tested" => $Strings->get("Tested", false),
|
||||
"capacity" => $Strings->get("Capacity", false),
|
||||
"model" => $Strings->get("Model", false),
|
||||
"price" => $Strings->get("Price", false),
|
||||
"manufacturer" => $Strings->get("Manufacturer", false),
|
||||
"privatenotes" => $Strings->get("Private Notes", false),
|
||||
"publicnotes" => $Strings->get("Public Notes", false)
|
||||
],
|
||||
"icons" => []
|
||||
]
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
public function save() {
|
||||
global $database;
|
||||
if ($this->exists) {
|
||||
|
195
lib/Event.lib.php
Normal file
195
lib/Event.lib.php
Normal file
@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
class Event implements JsonSerializable {
|
||||
|
||||
private $id = "";
|
||||
private $event = [];
|
||||
private $exists = false;
|
||||
|
||||
public function __construct($eventid) {
|
||||
global $database;
|
||||
$this->id = $eventid;
|
||||
if (\Event::exists($eventid)) {
|
||||
$this->exists = true;
|
||||
$this->event = $database->get('events', ['machineid', 'eventid', 'techuid', 'date', 'privatenotes', 'publicnotes'], ['historyid' => $eventid]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function create(string $machineid = "", string $date = "", int $event = 0, string $techuid = "", string $publicnotes = "", string $privatenotes = ""): Event {
|
||||
if ($machineid == "" || $date == "" || $event == 0) {
|
||||
return new Event("");
|
||||
} else {
|
||||
if (!Machine::exists($machineid)) {
|
||||
throw new Exception("Invalid machine ID $machineid");
|
||||
}
|
||||
if (strtotime($date) === false) {
|
||||
throw new Exception("Invalid date.");
|
||||
}
|
||||
$date = date("Y-m-d H:i:s", strtotime($date));
|
||||
if (!array_key_exists($event, \Event::getTypes())) {
|
||||
throw new Exception("Invalid event type.");
|
||||
}
|
||||
$evt = new Event("");
|
||||
|
||||
$evt->setMachineID($machineid);
|
||||
$evt->setTypeID($event);
|
||||
$evt->setDate($date);
|
||||
$evt->setTechUID($techuid);
|
||||
$evt->setPrivateNotes($privatenotes);
|
||||
$evt->setPublicNotes($publicnotes);
|
||||
$evt->save();
|
||||
|
||||
return $evt;
|
||||
}
|
||||
}
|
||||
|
||||
public static function exists($id): bool {
|
||||
global $database;
|
||||
return $database->has('events', ['historyid' => $id]);
|
||||
}
|
||||
|
||||
public static function getTypes() {
|
||||
global $database;
|
||||
$types = $database->select("event_types", ["eventid (id)", "eventname (name)"]);
|
||||
|
||||
$list = [];
|
||||
foreach ($types as $t) {
|
||||
$list[$t['id']] = $t['name'];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
global $Strings;
|
||||
if ($this->exists) {
|
||||
return [
|
||||
"info" => [
|
||||
"id" => $this->getID(),
|
||||
"machineid" => $this->getMachineID(),
|
||||
"type" => $this->getTypeID(),
|
||||
"date" => $this->getDate(),
|
||||
"techuid" => $this->getTechUID(),
|
||||
"publicnotes" => $this->getPublicNotes(),
|
||||
"privatenotes" => $this->getPrivateNotes()
|
||||
],
|
||||
"formdata" => [
|
||||
"types" => $this->getTypes(),
|
||||
"inputtypes" => [
|
||||
"machineid" => "text",
|
||||
"type" => "number",
|
||||
"date" => "datetime",
|
||||
"techuid" => "text",
|
||||
"privatenotes" => "textarea",
|
||||
"publicnotes" => "textarea"
|
||||
],
|
||||
"labels" => [
|
||||
"machineid" => $Strings->get("Machine ID", false),
|
||||
"type" => $Strings->get("Type", false),
|
||||
"date" => $Strings->get("Date", false),
|
||||
"techuid" => $Strings->get("Technician", false),
|
||||
"privatenotes" => $Strings->get("Private Notes", false),
|
||||
"publicnotes" => $Strings->get("Public Notes", false)
|
||||
],
|
||||
"icons" => []
|
||||
]
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
public function save() {
|
||||
global $database;
|
||||
if ($this->exists) {
|
||||
$database->update("events", $this->event, ["historyid" => $this->id]);
|
||||
} else {
|
||||
$database->insert("events", $this->event);
|
||||
$this->id = $database->id();
|
||||
$this->exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function getID(): string {
|
||||
return $this->id . "";
|
||||
}
|
||||
|
||||
public function getMachineID(): string {
|
||||
if (!empty($this->event["machineid"])) {
|
||||
return $this->event["machineid"];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public function getTypeID(): int {
|
||||
if (!empty($this->event["eventid"])) {
|
||||
return $this->event["eventid"] * 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return $this->getTypes()[$this->getTypeID()] ?? "";
|
||||
}
|
||||
|
||||
public function getDate(): string {
|
||||
if (!empty($this->event["date"])) {
|
||||
return $this->event["date"];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public function getTechUID(): string {
|
||||
if (!empty($this->event["techuid"])) {
|
||||
return $this->event["techuid"];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public function getPublicNotes(): string {
|
||||
if (!empty($this->event["publicnotes"])) {
|
||||
return $this->event["publicnotes"];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public function getPrivateNotes(): string {
|
||||
if (!empty($this->event["privatenotes"])) {
|
||||
return $this->event["privatenotes"];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public function setMachineID($id) {
|
||||
$this->event["machineid"] = $id;
|
||||
}
|
||||
|
||||
public function setTypeID(int $id) {
|
||||
if (!empty($this->getTypes()[$id])) {
|
||||
$this->event["eventid"] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
public function setTechUID($uid) {
|
||||
$this->event["techuid"] = $uid;
|
||||
}
|
||||
|
||||
public function setDate(string $date) {
|
||||
$this->event["date"] = date("Y-m-d H:i:s", strtotime($date));
|
||||
}
|
||||
|
||||
public function setPrivateNotes(string $notes) {
|
||||
$this->event["privatenotes"] = $notes;
|
||||
}
|
||||
|
||||
public function setPublicNotes(string $notes) {
|
||||
$this->event["publicnotes"] = $notes;
|
||||
}
|
||||
|
||||
}
|
@ -18,7 +18,10 @@ class Machine implements JsonSerializable {
|
||||
if (Machine::exists($machineid)) {
|
||||
$this->exists = true;
|
||||
$this->machine = $database->get('machines', ['model', 'condition', 'price', 'os', 'serial', 'manufacturer', 'clientid', 'privatenotes', 'publicnotes'], ['machineid' => $machineid]);
|
||||
$this->events = $database->select('events', ['[>]event_types' => 'eventid'], ['historyid', 'date', 'event_types.eventname', 'techuid', 'privatenotes', 'publicnotes'], ['machineid' => $machineid, "ORDER" => ["date" => "DESC"]]);
|
||||
$events = $database->select('events', 'historyid', ['machineid' => $machineid, "ORDER" => ["date" => "DESC"]]);
|
||||
foreach ($events as $e) {
|
||||
$this->events[] = new Event($e);
|
||||
}
|
||||
$components = $database->select("components", "compid", ["machineid" => $machineid]);
|
||||
foreach ($components as $c) {
|
||||
$this->components[] = new Component($c);
|
||||
@ -26,19 +29,52 @@ class Machine implements JsonSerializable {
|
||||
}
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
public function toArray() {
|
||||
global $Strings;
|
||||
if ($this->exists) {
|
||||
return [
|
||||
"status" => "OK",
|
||||
"id" => $this->machineid,
|
||||
"info" => $this->machine,
|
||||
"events" => $this->events,
|
||||
"components" => $this->components
|
||||
"components" => $this->components,
|
||||
"formdata" => [
|
||||
"options" => [
|
||||
"clientid" => Clients::getAllAsIDNameArray()
|
||||
],
|
||||
"inputtypes" => [
|
||||
"model" => "text",
|
||||
"condition" => "number",
|
||||
"price" => "number",
|
||||
"os" => "text",
|
||||
"serial" => "text",
|
||||
"manufacturer" => "text",
|
||||
"clientid" => "select",
|
||||
"privatenotes" => "textarea",
|
||||
"publicnotes" => "textarea"
|
||||
],
|
||||
"labels" => [
|
||||
"model" => $Strings->get("Model", false),
|
||||
"condition" => $Strings->get("Condition", false),
|
||||
"price" => $Strings->get("Price", false),
|
||||
"os" => $Strings->get("OS/Software", false),
|
||||
"serial" => $Strings->get("Serial", false),
|
||||
"manufacturer" => $Strings->get("Manufacturer", false),
|
||||
"clientid" => $Strings->get("Client", false),
|
||||
"privatenotes" => $Strings->get("Private Notes", false),
|
||||
"publicnotes" => $Strings->get("Public Notes", false)
|
||||
],
|
||||
"icons" => []
|
||||
]
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
public static function create(): Machine {
|
||||
return new Machine(Machine::generateId());
|
||||
}
|
||||
@ -204,22 +240,9 @@ class Machine implements JsonSerializable {
|
||||
}
|
||||
|
||||
public function addEvent(string $date, int $event, string $techuid = "", string $publicnotes = "", string $privatenotes = "") {
|
||||
global $database;
|
||||
if (strtotime($date) === false) {
|
||||
throw new Exception("Invalid date.");
|
||||
}
|
||||
$date = date("Y-m-d H:i:s", strtotime($date));
|
||||
if (!$database->has('event_types', ['eventid' => $event])) {
|
||||
throw new Exception("Invalid event type.");
|
||||
}
|
||||
$event = (int) $event;
|
||||
if (empty($publicnotes)) {
|
||||
$publicnotes = "";
|
||||
}
|
||||
if (empty($privatenotes)) {
|
||||
$privatenotes = "";
|
||||
}
|
||||
$database->insert('events', ['date' => $date, 'eventid' => $event, 'techuid' => $techuid, 'machineid' => $this->machineid, 'publicnotes' => $publicnotes, 'privatenotes' => $privatenotes]);
|
||||
$evt = Event::create($this->machineid, $date, $event, $techuid, $publicnotes, $privatenotes);
|
||||
|
||||
$this->events[] = $evt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,13 +96,13 @@ $machine = new Machine($machineid);
|
||||
<?php
|
||||
foreach ($history as $h) {
|
||||
echo "<div class=\"list-group-item\">\n";
|
||||
echo "<b>$h[eventname]</b> on " . date($SETTINGS["datetime_format"], strtotime($h['date'])) . "<br />\n";
|
||||
echo "<b>Technician:</b> " . htmlspecialchars((new User($h['techuid']))->getName()) . "<br />\n";
|
||||
if (!empty($h['publicnotes'])) {
|
||||
echo "<div><b>Public Notes:</b><br /><div class=\"ml-3\">" . htmlspecialchars($h['publicnotes']) . "</div></div>";
|
||||
echo "<b>" . $h->getName() . "</b> on " . date($SETTINGS["datetime_format"], strtotime($h->getDate())) . "<br />\n";
|
||||
echo "<b>Technician:</b> " . htmlspecialchars((new User($h->getTechUID()))->getName()) . "<br />\n";
|
||||
if (!empty($h->getPublicNotes())) {
|
||||
echo "<div><b>Public Notes:</b><br /><div class=\"ml-3\">" . htmlspecialchars($h->getPublicNotes()) . "</div></div>";
|
||||
}
|
||||
if (!empty($h['privatenotes'])) {
|
||||
echo "<div><b>Private Notes:</b><br /><div class=\"ml-3\">" . htmlspecialchars($h['privatenotes']) . "</div></div>";
|
||||
if (!empty($h->getPrivateNotes())) {
|
||||
echo "<div><b>Private Notes:</b><br /><div class=\"ml-3\">" . htmlspecialchars($h->getPrivateNotes()) . "</div></div>";
|
||||
}
|
||||
echo "\n</div>\n";
|
||||
}
|
||||
|
@ -321,9 +321,9 @@ if (isset($_GET["backgroundcolor"]) && !empty($_GET["backgroundcolor"]) && preg_
|
||||
<?php
|
||||
foreach ($history as $h) {
|
||||
echo "<div class=\"list-group-item\">\n";
|
||||
echo "<b>$h[eventname]</b> on " . date($SETTINGS["datetime_format"], strtotime($h['date'])) . "<br />\n";
|
||||
if (!empty($h['publicnotes'])) {
|
||||
echo "<div><b>Notes:</b><br /><div class=\"ml-3\">" . htmlspecialchars($h['publicnotes']) . "</div></div>";
|
||||
echo "<b>" . $h->getName() . "</b> on " . date($SETTINGS["datetime_format"], strtotime($h->getDate())) . "<br />\n";
|
||||
if (!empty($h->getPublicNotes())) {
|
||||
echo "<div><b>Notes:</b><br /><div class=\"ml-3\">" . htmlspecialchars($h->getPublicNotes()) . "</div></div>";
|
||||
}
|
||||
echo "\n</div>\n";
|
||||
}
|
||||
|
@ -106,7 +106,10 @@ try {
|
||||
'server' => $SETTINGS['database']['server'],
|
||||
'username' => $SETTINGS['database']['user'],
|
||||
'password' => $SETTINGS['database']['password'],
|
||||
'charset' => $SETTINGS['database']['charset']
|
||||
'charset' => $SETTINGS['database']['charset'],
|
||||
'option' => [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
]
|
||||
]);
|
||||
} catch (Exception $ex) {
|
||||
//header('HTTP/1.1 500 Internal Server Error');
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 8.0 KiB |
@ -14,11 +14,11 @@
|
||||
viewBox="0 0 512.00001 512.00001"
|
||||
id="svg2"
|
||||
version="1.1"
|
||||
inkscape:version="0.91 r13725"
|
||||
inkscape:version="0.92.3 (2405546, 2018-03-11)"
|
||||
sodipodi:docname="logo.svg"
|
||||
inkscape:export-filename="/home/skylar/Documents/Projects/Sources/WebAppTemplate/static/img/logo.png"
|
||||
inkscape:export-xdpi="90"
|
||||
inkscape:export-ydpi="90">
|
||||
inkscape:export-filename="/home/skylar/Documents/Projects/Sources/Apps/Native/MachineManager/resources/icon.png"
|
||||
inkscape:export-xdpi="384"
|
||||
inkscape:export-ydpi="384">
|
||||
<defs
|
||||
id="defs4">
|
||||
<inkscape:perspective
|
||||
@ -36,13 +36,18 @@
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.49497475"
|
||||
inkscape:cx="-135.9681"
|
||||
inkscape:cy="352.66131"
|
||||
inkscape:zoom="0.9899495"
|
||||
inkscape:cx="130.19097"
|
||||
inkscape:cy="153.91657"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
units="px" />
|
||||
units="px"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1013"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
@ -51,7 +56,7 @@
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
@ -69,10 +74,20 @@
|
||||
y="540.36218"
|
||||
rx="50"
|
||||
ry="50" />
|
||||
<g
|
||||
id="g985"
|
||||
transform="matrix(1.3341636,0,0,1.3341636,-85.545882,-266.11525)">
|
||||
<path
|
||||
id="path4348"
|
||||
style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:9.87128067;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 132.93564,682.51771 213.96788,-43.14304 0,313.97496 -213.96788,-37.9643 z m 213.96788,-43.14304 0,313.97496 32.16084,-45.18373 0,-217.44396 z m -213.96788,43.14304 213.96788,-43.14304 32.16084,51.34727 -167.21823,22.47784 z m 78.91049,30.68207 167.21823,-22.47784 0,217.44396 -167.21823,-19.77968 z m -78.91049,-30.68207 0,232.86762 78.91049,-26.99911 0,-175.18644 z m 0,232.86762 213.96788,37.9643 32.16084,-45.18373 -167.21823,-19.77968 z"
|
||||
inkscape:connector-curvature="0" />
|
||||
style="fill:#03a9f4;stroke-width:0.47823665"
|
||||
inkscape:connector-curvature="0"
|
||||
d="M 321.04019,819.31756 H 252.1741 a 3.8258933,3.8258933 0 0 0 -3.82589,3.8259 v 7.6518 a 3.8258933,3.8258933 0 0 0 3.82589,3.8259 h 68.86609 a 3.8258933,3.8258933 0 0 0 3.82589,-3.8259 v -7.6518 a 3.8258933,3.8258933 0 0 0 -3.82589,-3.8259 z m -126.25449,17.2165 a 9.5647334,9.5647334 0 1 0 -9.56473,-9.5647 9.5647334,9.5647334 0 0 0 9.56473,9.5647 z m 7.65179,-40.1719 h 107.12502 a 15.303573,15.303573 0 0 0 15.30357,-15.3036 v -53.5625 a 15.303573,15.303573 0 0 0 -15.30357,-15.3036 H 202.43749 a 15.303573,15.303573 0 0 0 -15.30357,15.3036 v 53.5625 a 15.303573,15.303573 0 0 0 15.30357,15.3036 z M 347.82144,673.93356 H 164.17856 a 15.303573,15.303573 0 0 0 -15.30357,15.3036 v 168.3393 a 15.303573,15.303573 0 0 0 15.30357,15.3036 v 30.6071 a 15.303573,15.303573 0 0 0 15.30357,15.3036 h 153.03574 a 15.303573,15.303573 0 0 0 15.30357,-15.3036 v -30.6071 a 15.303573,15.303573 0 0 0 15.30357,-15.3036 v -168.3393 a 15.303573,15.303573 0 0 0 -15.30357,-15.3036 z m -22.95536,221.9018 H 187.13392 v -22.9553 h 137.73216 z m 15.30357,-45.9107 h -168.3393 v -153.0357 h 168.3393 z"
|
||||
id="path942" />
|
||||
<path
|
||||
sodipodi:nodetypes="ssccssccsssssssccccssccccscccccccccc"
|
||||
id="path953"
|
||||
d="M 321.04019,819.31756 H 252.1741 c -2.11298,0 -3.82589,1.71292 -3.82589,3.8259 v 7.6518 c 0,2.11298 1.71291,3.8259 3.82589,3.8259 h 68.86609 c 2.11298,0 3.82589,-1.71292 3.82589,-3.8259 v -7.6518 c 0,-2.11298 -1.71291,-3.8259 -3.82589,-3.8259 z m -126.25449,17.2165 c 8.52187,0 12.78809,-10.30256 6.76294,-16.32769 -6.02515,-6.02513 -16.3277,-1.75888 -16.32767,6.76299 2e-5,5.28244 4.28229,9.5647 9.56473,9.5647 z M 347.82144,673.93356 H 164.17856 c -8.45194,0 -15.30358,6.85166 -15.30357,15.3036 v 168.3393 c -1e-5,8.45194 6.85163,15.3036 15.30357,15.3036 v 30.6071 c -1e-5,8.45194 6.85163,15.3036 15.30357,15.3036 h 153.03574 c 8.45194,0 15.30358,-6.85166 15.30357,-15.3036 v -30.6071 c 8.45194,0 15.30358,-6.85166 15.30357,-15.3036 v -168.3393 c 1e-5,-8.45194 -6.85163,-15.3036 -15.30357,-15.3036 z m -22.95536,221.9018 H 187.13392 v -22.9553 h 137.73216 z m 15.30357,-45.9107 h -168.3393 v -153.0357 h 168.3393 z"
|
||||
inkscape:connector-curvature="0"
|
||||
style="stroke-width:0.47823665" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 4.7 KiB |
Loading…
x
Reference in New Issue
Block a user