machineid = $machineid;
if (Machine::exists($machineid)) {
$this->exists = true;
$this->machine = $database->get('machines', ['type [Int]', 'model', 'condition [Number]', 'price [Number]', 'os', 'serial', 'manufacturer', 'clientid [Int]', 'privatenotes', 'publicnotes', 'deleted [Bool]'], ['machineid' => $machineid]);
$typeinfo = $database->get("machine_types", ["machinetypeid (id) [Int]", "typename (label)", "icon"], ["machinetypeid" => $this->machine["type"]]);
$this->icon = $typeinfo["icon"];
$this->typeid = $typeinfo["id"];
$this->typelabel = $typeinfo["label"];
$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);
}
}
}
/**
* Get a shorter array without editing data, events, or components.
* @return type
*/
public function toArrayLite() {
global $Strings;
if ($this->exists) {
$info = $this->machine;
// only show deleted if true
if (!$this->isDeleted()) {
unset($info["deleted"]);
}
return [
"status" => "OK",
"id" => $this->machineid,
"icon" => $this->icon,
"type" => [
"id" => $this->typeid,
"label" => $this->typelabel
],
"info" => $info,
"formdata" => [
"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),
"type" => $Strings->get("Type", false)
]
]
];
}
return [];
}
public function toArray() {
global $Strings;
if ($this->exists) {
$info = $this->machine;
// only show deleted if true
if (!$this->isDeleted()) {
unset($info["deleted"]);
}
$clientinfo = [];
if (!empty($this->getClientID())) {
$client = Clients::getClient($this->getClientID());
$clientinfo = [
"name" => $client->getName(),
"phone" => $client->getPhone(),
"billingaddress" => $client->getBillingAddress(),
"mailingaddress" => $client->getMailingAddress()
];
}
return [
"status" => "OK",
"id" => $this->machineid,
"icon" => $this->icon,
"type" => [
"id" => $this->typeid,
"label" => $this->typelabel
],
"clientinfo" => $clientinfo,
"info" => $info,
"events" => $this->events,
"components" => $this->components,
"formdata" => [
"options" => [
"clientid" => ["" => ""] + Clients::getAllAsIDNameArray(),
"type" => Machine::getTypeList()
],
"inputtypes" => [
"model" => "text",
"condition" => "number",
"price" => "number",
"os" => "text",
"serial" => "text",
"manufacturer" => "text",
"clientid" => "select",
"privatenotes" => "textarea",
"publicnotes" => "textarea",
"type" => "select"
],
"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),
"type" => $Strings->get("Type", false)
],
"icons" => [
"model" => "fas fa-hashtag",
"condition" => "fas fa-star-half-alt",
"price" => "fas fa-money-bill-wave",
"os" => "fas fa-hdd",
"serial" => "fas fa-barcode",
"manufacturer" => "fas fa-industry",
"privatenotes" => "fas fa-comment-dots",
"publicnotes" => "far fa-comment-dots"
]
]
];
}
return [
"status" => "OK",
"id" => "",
"icon" => "",
"type" => [
"id" => "",
"label" => ""
],
"clientinfo" => [],
"info" => [],
"events" => [],
"components" => [],
"formdata" => [
"options" => [
"clientid" => ["" => ""] + Clients::getAllAsIDNameArray(),
"type" => Machine::getTypeList()
],
"inputtypes" => [
"model" => "text",
"condition" => "number",
"price" => "number",
"os" => "text",
"serial" => "text",
"manufacturer" => "text",
"clientid" => "select",
"privatenotes" => "textarea",
"publicnotes" => "textarea",
"type" => "select"
],
"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),
"type" => $Strings->get("Type", false)
],
"icons" => [
"model" => "fas fa-hashtag",
"condition" => "fas fa-star-half-alt",
"price" => "fas fa-money-bill-wave",
"os" => "fas fa-hdd",
"serial" => "fas fa-barcode",
"manufacturer" => "fas fa-industry",
"privatenotes" => "fas fa-comment-dots",
"publicnotes" => "far fa-comment-dots"
]
]
];
}
public function toHTMLListGroup(bool $public = true): string {
global $Strings;
$func = function($param) {
return $param;
};
$line = function($type) use ($public): string {
global $Strings, $SETTINGS;
$publicsettings = json_decode(file_get_contents(__DIR__ . "/../custom/public.json"), true);
if ($type == "Client") {
if (!empty($this->getClientID()) && $public == false) {
$client = Clients::getClient($this->getClientID());
$rtn = "" . $Strings->get("Client", false) . ": " . htmlspecialchars($client->getName()) . "
";
$rtn .= "