69 lines
1.6 KiB
PHP
69 lines
1.6 KiB
PHP
<?php
|
|
|
|
class TerminationController extends mfBaseController {
|
|
|
|
protected function init() {
|
|
$this->needlogin=true;
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->me = $me;
|
|
$this->layout()->set("me",$me);
|
|
|
|
if(!$me->isAdmin() && !$me->is("netowner") && !$me->is("lineplanner") && !$me->is("lineworker")) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
}
|
|
|
|
|
|
protected function apiAction() {
|
|
$do = $this->request->do;
|
|
$data = [];
|
|
|
|
switch($do) {
|
|
case "setValue":
|
|
$return = $this->setValueApi();
|
|
break;
|
|
default:
|
|
$return = false;
|
|
}
|
|
|
|
if(!is_array($return) || !count($return)) {
|
|
$data = ["status" => "error"];
|
|
$this->returnJson($data);
|
|
}
|
|
$data['status'] = "OK";
|
|
$data['result'] = $return;
|
|
$this->returnJson($data);
|
|
}
|
|
|
|
private function setValueApi() {
|
|
$term_id = $this->request->id;
|
|
$field = $this->request->type;
|
|
$value = $this->db->escape($this->request->value);
|
|
|
|
if(!is_numeric($term_id) || $term_id < 1) {
|
|
$this->log->debug(__FILE__.": id not a number");
|
|
return false;
|
|
}
|
|
|
|
if(!in_array($field, ["name","contact","phone","email"])) {
|
|
$this->log->debug(__FILE__.": invalid field");
|
|
return false;
|
|
}
|
|
|
|
$term = new Termination($term_id);
|
|
if(!$term->id) {
|
|
$this->log->debug(__FILE__.": no termination");
|
|
return false;
|
|
}
|
|
|
|
$term->$field = $value;
|
|
|
|
if(!$term->save()) {
|
|
$this->log->debug(__FILE__.": error saving");
|
|
return false;
|
|
}
|
|
|
|
return ["msg" => "Saved successfully"];
|
|
}
|
|
} |