101 lines
2.2 KiB
PHP
101 lines
2.2 KiB
PHP
<?php
|
|
|
|
class mfConfig {
|
|
private $db;
|
|
private $id;
|
|
private $name;
|
|
private $value;
|
|
private $active;
|
|
private $type;
|
|
public $create_by;
|
|
public $edit_by;
|
|
public $create;
|
|
public $edit;
|
|
private $me;
|
|
|
|
public function __construct($name) {
|
|
$this->db = FronkDB::singleton();
|
|
|
|
$name = $this->db->escape($name);
|
|
$this->name = $name;
|
|
|
|
|
|
if(defined("INTERNAL_USER_ID")) {
|
|
$me = new User(INTERNAL_USER_ID);
|
|
} else {
|
|
$me = new User();
|
|
$me->loadMe();
|
|
}
|
|
$this->me = $me;
|
|
|
|
$res = $this->db->select("System", "*", "name='$name' LIMIT 1");
|
|
if($this->db->num_rows($res)) {
|
|
$data = $this->db->fetch_object($res);
|
|
$this->id = $data->id;
|
|
$this->value = $data->value;
|
|
$this->active = $data->active;
|
|
$this->type = $data->type;
|
|
$this->create_by = $data->create_by;
|
|
$this->edit_by = $data->edit_by;
|
|
$this->create = $data->create;
|
|
$this->edit = $data->edit;
|
|
} else {
|
|
$this->active = 1;
|
|
$this->type = "string";
|
|
}
|
|
}
|
|
|
|
public function value($value = null) {
|
|
if($value !== null) {
|
|
$this->value = $value;
|
|
}
|
|
$return_value = $this->value;
|
|
|
|
if($this->type == "int") {
|
|
$return_value = (int)$return_value;
|
|
}
|
|
if($this->type == "float") {
|
|
$return_value = (float)$return_value;
|
|
}
|
|
|
|
return $return_value;
|
|
}
|
|
|
|
public function type($type = null) {
|
|
if($type !== null) {
|
|
$this->type = $type;
|
|
}
|
|
return $this->type;
|
|
}
|
|
|
|
public function active($active = null) {
|
|
return $this->active;
|
|
}
|
|
|
|
public function save() {
|
|
$id = $this->id;
|
|
|
|
$values['name'] = $this->name;
|
|
$values['value'] = $this->value;
|
|
$values['active'] = ($this->active === true || $this->active === 1 || $this->active === (string) 1) ? 1 : 0;
|
|
$values['type'] = $this->type;
|
|
$values['edit_by'] = $this->me->id;
|
|
$values['edit'] = date('U');
|
|
|
|
if($id) {
|
|
// update
|
|
$this->db->update("System", $values, "id=$id");
|
|
} else {
|
|
// insert
|
|
$values['create_by'] = $this->me->id;
|
|
$values['create'] = date('U');
|
|
$id = $this->db->insert("System", $values);
|
|
$this->id = $id;
|
|
}
|
|
|
|
}
|
|
|
|
public function __toString() {
|
|
return (string) $this->value;
|
|
}
|
|
} |