141 lines
3.4 KiB
PHP
141 lines
3.4 KiB
PHP
<?php
|
|
|
|
class SystemController {
|
|
public static function status() {
|
|
$status = [
|
|
"B" => "Blacklisted",
|
|
"N" => "Pending",
|
|
"F" => "Failed",
|
|
"D" => "Done",
|
|
"Y" => "Done",
|
|
"W" => "Postponed",
|
|
"P" => "Processing",
|
|
"X" => "Deleted",
|
|
"O" => "Off-site",
|
|
"Q" => "Postponed",
|
|
"R" => "Redirect",
|
|
];
|
|
|
|
$q = DB::getInstance()->query("select count(id) as c, status from pages group by status order by status");
|
|
$spider = [];
|
|
while ($r = DB::getInstance()->nextRecord($q)) {
|
|
$spider[@$status[$r->status]] = $r->c;
|
|
}
|
|
|
|
$q = DB::getInstance()->query("select count(id) as c, status from spider group by status order by status");
|
|
$pdf = [];
|
|
while ($r = DB::getInstance()->nextRecord($q)) {
|
|
$pdf[@$status[$r->status]] = $r->c;
|
|
}
|
|
|
|
$q = DB::getInstance()->query("select count(id) as c, ocr from revision group by ocr order by ocr");
|
|
$ocr = [];
|
|
while ($r = DB::getInstance()->nextRecord($q)) {
|
|
$ocr[@$status[$r->ocr]] = $r->c;
|
|
}
|
|
|
|
$q = DB::getInstance()->query("select count(id) as c, idx from revision group by idx order by idx");
|
|
$idx = [];
|
|
while ($r = DB::getInstance()->nextRecord($q)) {
|
|
$idx[@$status[$r->idx]] = $r->c;
|
|
}
|
|
|
|
return blade("status", ["spider" => $spider, "pdf" => $pdf, "ocr" => $ocr, "idx" => $idx]);
|
|
}
|
|
|
|
|
|
public static function api_get_idmatches() {
|
|
return IDMatch::find([["id", ">=", 0]])->orderBy("weight")->all();
|
|
}
|
|
|
|
public static function api_add_idmatch($_request) {
|
|
$i = new IDMatch;
|
|
$i->example = $_request->put('example');
|
|
$i->regex = $_request->put('regex');
|
|
$i->weight = $_request->put('weight');
|
|
$i->save();
|
|
return SystemController::api_get_idmatches();
|
|
}
|
|
|
|
public static function api_set_idmatch($id) {
|
|
$i = new IDMatch($id);
|
|
if ($i) {
|
|
$i->example = $_POST['example'];
|
|
$i->regex = $_POST['regex'];
|
|
$i->weight = $_POST['weight'];
|
|
$i->save();
|
|
}
|
|
return SystemController::api_get_idmatches();
|
|
}
|
|
|
|
public static function api_del_idmatch($id) {
|
|
$i = new IDMatch($id);
|
|
if ($i) {
|
|
$i->delete();
|
|
}
|
|
return SystemController::api_get_idmatches();
|
|
}
|
|
|
|
|
|
|
|
public static function systems() {
|
|
$u = get_user();
|
|
$sys = System::find([["owner", "=", $u->id]])->all();
|
|
return blade("systems", ["systems" => $sys]);
|
|
}
|
|
|
|
public static function system($id) {
|
|
$sys = new System($id);
|
|
$sys->load("documents");
|
|
return blade("system", ["sys" => $sys]);
|
|
}
|
|
|
|
public static function systems_add() {
|
|
return blade("systems_add");
|
|
}
|
|
|
|
public static function systems_do_add($_request) {
|
|
$sys = new System;
|
|
$sys->name = $_request->post("name");
|
|
$sys->model = $_request->post("model");
|
|
$sys->notes = $_request->post("notes");
|
|
$sys->owner = get_user()->id;
|
|
$sys->save();
|
|
return redirect("/system/" . $sys->id);
|
|
}
|
|
|
|
public static function system_add_doc($id, $doc) {
|
|
$sys = new System($id);
|
|
if ($sys->owner == get_user()->id) {
|
|
$exist = SystemDoc::find([
|
|
["system", "=", $sys->id],
|
|
["document", "=", $doc]
|
|
])->first();
|
|
if (!$exist) {
|
|
$sd = new SystemDoc;
|
|
$sd->system = $sys->id;
|
|
$sd->document = $doc;
|
|
$sd->save();
|
|
}
|
|
return redirect("/system/" . $id);
|
|
}
|
|
return [403, "Forbidden"];
|
|
}
|
|
|
|
public static function system_del_doc($id, $doc) {
|
|
$sys = new System($id);
|
|
if ($sys->owner == get_user()->id) {
|
|
$sd = SystemDoc::find([
|
|
["system", "=", $sys->id],
|
|
["document", "=", $doc]
|
|
])->first();
|
|
if ($sd) {
|
|
$sd->delete();
|
|
}
|
|
return redirect("/system/" . $id);
|
|
}
|
|
return [403, "Forbidden"];
|
|
}
|
|
}
|
|
|