Merge branch 'master' into fronkdev

This commit is contained in:
Frank Schubert
2024-01-09 17:27:57 +01:00
57 changed files with 76755 additions and 45594 deletions

View File

@@ -15,25 +15,42 @@ class Device extends mfBaseModel
return null;
}
if ($name == "creator") {
$this->creator = new User($this->create_by);
if($name == "creator") {
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($this->creator === null) {
$this->creator = new User($this->create_by);
if($this->creator->id) {
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
}
}
return $this->creator;
}
if ($name == "editor") {
$this->editor = new User($this->edit_by);
if($name == "editor") {
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
if($this->editor === null) {
$this->editor = new User($this->edit_by);
if($this->editor->id) {
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
}
}
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name . "_id";
$this->$name = new $classname($this->$idfield);
$idfield = $name."_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
if(!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if ($this->$name->id) {
if($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
}
return $this->$name;

View File

@@ -15,24 +15,41 @@ class Devicetype extends mfBaseModel
}
if ($name == "creator") {
$this->creator = new User($this->create_by);
$this->creator = mfValuecache::singleton()->get("Worker-id-" . $this->create_by);
if ($this->creator === null) {
$this->creator = new User($this->create_by);
if ($this->creator->id) {
mfValuecache::singleton()->set("Worker-id-" . $this->create_by, $this->creator);
}
}
return $this->creator;
}
if ($name == "editor") {
$this->editor = new User($this->edit_by);
$this->editor = mfValuecache::singleton()->get("Worker-id-" . $this->edit_by);
if ($this->editor === null) {
$this->editor = new User($this->edit_by);
if ($this->editor->id) {
mfValuecache::singleton()->set("Worker-id-" . $this->edit_by, $this->editor);
}
}
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name . "_id";
$this->$name = new $classname($this->$idfield);
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield);
if (!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if ($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-" . $this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
}
return $this->$name;

View File

@@ -114,7 +114,7 @@ class Network extends mfBaseModel {
}
if($name == "pops") {
$pops = PopModel::search(['network_id' => $this->id]);
$pops = PopNetworkModel::search(['network_id' => $this->id]);
$this->pops = $pops;
return $this->pops;
}

View File

@@ -5,18 +5,49 @@ class Pop extends mfBaseModel {
private $network;
public function getProperty($name) {
if($this->$name == null) {
if ($this->$name == null) {
if (!$this->id) {
return null;
}
if($name == "creator") {
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($this->creator === null) {
$this->creator = new User($this->create_by);
if($this->creator->id) {
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
}
}
return $this->creator;
}
if($name == "editor") {
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
if($this->editor === null) {
$this->editor = new User($this->edit_by);
if($this->editor->id) {
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
}
}
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
if(!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}

View File

@@ -21,7 +21,8 @@ class PopController extends mfBaseController
{
$this->layout()->setTemplate("Pop/Index");
$pops = PopModel::getAll();
$pops = PopModel::getAlladv();
$this->layout()->set("pops", $pops);
}
@@ -40,7 +41,8 @@ class PopController extends mfBaseController
$this->layout()->setFlash("Pop nicht gefunden", "error");
$this->redirect("Pop");
}
$popnetwork = PopNetworkModel::getbyPopid($id);
$this->layout()->set("popnetwork", implode(', ' , $popnetwork['name']));
$this->layout()->setTemplate("Pop/Detail");
$filter['pop_id'] = $id;
$this->layout()->set("popracks", PoprackModel::getAllbyPop($id));
@@ -76,6 +78,8 @@ class PopController extends mfBaseController
$this->redirect("Network");
}
$popnetwork = PopNetworkModel::getbyPopid($id);
$this->layout()->set("popnetwork", $popnetwork['network_id']);
$this->layout()->set("pop", $pop);
return $this->addAction();
}
@@ -106,7 +110,8 @@ class PopController extends mfBaseController
}
$data = [];
$data['network_id'] = $r->network_id;
$data['name'] = $r->name;
$data['gps_lat'] = ($r->gps_lat) ? $r->gps_lat : null;
$data['gps_long'] = ($r->gps_long) ? $r->gps_long : null;
@@ -127,11 +132,32 @@ class PopController extends mfBaseController
$new_id = $pop->save();
if (!$new_id) {
$this->layout()->setFlash("Fehler beim Speichern", "error");
$this->layout()->set("network", $network);
return $this->addAction();
}
if ($r->network_id) {
$oldPopnetworks = json_encode(PopNetworkModel::getbyPopid($new_id));
if ($oldPopnetworks != json_encode($r->network_id)) {
PopNetworkModel::deletebyPopid($new_id);
unset($data);
$data = [];
foreach ($r->network_id as $networkid) {
$data['network_id'] = $networkid;
$data['pop_id'] = $new_id;
$popNetwork = PopNetworkModel::create($data);
$popNetwork->save();
}
}
}
if ($this->request->returnto) {
$returnAction = "Index";
$returnVariables = array();

View File

@@ -1,130 +1,178 @@
<?php
class PopModel {
public $name = null;
public $network_id = null;
public $gps_lat = null;
public $gps_long = null;
public $location = null;
public $vlan_public = null;
public $vlan_nat = null;
public $vlan_ipv6 = null;
public $note = null;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function find($data) {
}
public static function create(Array $data) {
$model = new Pop();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
if(substr($field, 0, 5) == "vlan_" && !$value) {
$model->$field = null;
continue;
class PopModel
{
public $name = null;
public $network_id = null;
public $gps_lat = null;
public $gps_long = null;
public $location = null;
public $vlan_public = null;
public $vlan_nat = null;
public $vlan_ipv6 = null;
public $note = null;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new Pop();
foreach ($data as $field => $value) {
if (property_exists(get_called_class(), $field)) {
if (substr($field, 0, 5) == "vlan_" && !$value) {
$model->$field = null;
continue;
}
$model->$field = $value;
}
}
$model->$field = $value;
}
}
$me = mfValuecache::singleton()->get("me");
if(!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
$me = mfValuecache::singleton()->get("me");
if (!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
}
if ($model->create_by === null) {
$model->create_by = $me->id;
}
if ($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
if($model->create_by === null) {
$model->create_by = $me->id;
}
if($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getOne($id) {
if(!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("Pop", "*", "id=$id LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Pop($data);
}
return $item;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("Pop", "*","1=1 ORDER by name");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Pop($data);
}
}
return $items;
}
public static function getFirst() {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Pop", "*", "$where ORDER BY name, network_id");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Pop($data);
if($item->id) {
public static function getOne($id)
{
if (!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("Pop", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Pop($data);
}
return $item;
} else {
return null;
}
}
return null;
}
public static function search($filter) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Pop", "*", "$where ORDER BY name, network_id");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Pop($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
//var_dump($filter);exit;
if(array_key_exists("network_id", $filter)) {
$networkid = $filter['network_id'];
if(is_numeric($networkid)) {
$where .= " AND network_id=$networkid";
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("Pop", "*", "1=1 ORDER by name");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new Pop($data);
}
}
return $items;
}
//var_dump($filter, $where);exit;
return $where;
}
public static function getAlladv()
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `Pop`.`id`, `Pop`.`network_id`, `Pop`.`name`, `Pop`.`gps_lat`, `Pop`.`gps_long`, `Pop`.`location`, `Pop`.`vlan_public`, `Pop`.`vlan_nat`, `Pop`.`vlan_ipv6`, `Pop`.`note`,`Network`.`name` as Networkname FROM `Pop`
INNER JOIN `PopNetwork` ON (`Pop`.`id`=`PopNetwork`.`pop_id`)
INNER JOIN `Network` ON (`Network`.`id`=`PopNetwork`.`network_id`)";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_array($res)) {
$Pops[$data['id']]['data'] = $data;
$Pops[$data['id']]['networks'][] = $data['Networkname'];
}
}
foreach ($Pops as $key => $Pop) {
$Pop['data']['networks'] = implode(', ', $Pop['networks']);
$items[] = new Pop((object)$Pop['data']);
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
//$res = $db->select("Pop", "*", "$where ORDER BY name, network_id");
$sql = "SELECT Pop.* FROM Pop
LEFT JOIN PopNetwork ON (PopNetwork.pop_id = Pop.id)
WHERE $where
ORDER BY name, PopNetwork.network_id LIMIT 1
";
$res = $db->query($sql);
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Pop($data);
if ($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function search($filter)
{
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT Pop.* FROM Pop
LEFT JOIN PopNetwork ON (PopNetwork.pop_id = Pop.id)
WHERE $where
ORDER BY name, PopNetwork.network_id";
$res = $db->query($sql);
//$res = $db->select("Pop", "*", "$where ORDER BY name, network_id");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new Pop($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("network_id", $filter)) {
$networkid = $filter['network_id'];
if (is_numeric($networkid)) {
$where .= " AND PopNetwork.network_id=$networkid";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,44 @@
<?php
class PopNetwork extends mfBaseModel
{
private $editor;
private $creator;
private $pop;
private $network;
public function getProperty($name)
{
if ($this->$name == null) {
if (!$this->id) {
return null;
}
if ($name == "creator") {
$this->creator = new User($this->create_by);
return $this->creator;
}
if ($name == "editor") {
$this->editor = new User($this->edit_by);
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name . "_id";
$this->$name = new $classname($this->$idfield);
if ($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}

View File

@@ -0,0 +1,154 @@
<?php
class PopNetworkModel
{
private $pop_id;
private $network_id;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new PopNetwork();
foreach ($data as $field => $value) {
if (property_exists(get_called_class(), $field)) {
if (substr($field, 0, 5) == "vlan_" && !$value) {
$model->$field = null;
continue;
}
$model->$field = $value;
}
}
$me = mfValuecache::singleton()->get("me");
if (!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
}
if ($model->create_by === null) {
$model->create_by = $me->id;
}
if ($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getOne($id)
{
if (!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("PopNetwork", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new PopNetwork($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("PopNetwork", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new PopNetwork($data);
}
}
return $items;
}
public static function getbyPopid($pop_id)
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `PopNetwork`.`id`,`PopNetwork`.`network_id`,`Network`.`name` FROM `PopNetwork`
INNER JOIN `Network` ON (`Network`.`id`=`PopNetwork`.`network_id`)
WHERE `PopNetwork`.`pop_id`='" . $pop_id . "'";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_array($res)) {
$items['network_id'][] = $data['network_id'];
$items['name'][] = $data['name'];
}
}
return $items;
}
public static function deletebyPopid($pop_id)
{
$db = FronkDB::singleton();
$sql = "DELETE FROM `PopNetwork` WHERE `pop_id`='" . $pop_id . "'";
$db->query($sql);
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("PopNetwork", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new PopNetwork($data);
if ($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function search($filter)
{
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("PopNetwork", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new PopNetwork($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("network_id", $filter)) {
$networkid = $filter['network_id'];
if (is_numeric($networkid)) {
$where .= " AND network_id=$networkid";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -173,6 +173,28 @@ class PoprackModel
$response['success'] = true;
} else {
$response['success'] = false;
}
echo json_encode($response);
exit;
}
public static function getdispatchersleeve($dispatcher_id)
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `id`, `name` FROM `FiberPlanDispatchersleeve` WHERE fiberPlanDispatcher_id='" . $dispatcher_id . "' ";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_array($res)) {
$items[] = $data;
}
$response['data'] = $items;
$response['success'] = true;
} else {
$response['success'] = false;
}

View File

@@ -33,6 +33,7 @@ class PoprackmoduleController extends mfBaseController
private function addModule()
{
$ports = 0;
$r = $this->request;
$id = $r->id;
$data = [];
@@ -40,7 +41,9 @@ class PoprackmoduleController extends mfBaseController
$data['type'] = $r->type;
if ($data['type'] == 0) {
$data['ports'] = ($r->ports) ? $r->ports : null;
$ports = $data['ports'];
$data['plug'] = ($r->plug) ? $r->plug : null;
}
if ($data['type'] == 1) {
$data['device_id'] = ($r->device_id) ? $r->device_id : null;
@@ -59,6 +62,16 @@ class PoprackmoduleController extends mfBaseController
$response['success'] = false;
} else {
$response['success'] = true;
if ($data['type'] == 0) {
unset($data);
$data = [];
$data['poprackmodule_id'] = $new_id;
for ($i = 1; $i <= $ports; $i++) {
$data['port'] = $i;
$poprackmodulepatch = PoprackmodulepatchModel::create($data);
$poprackmodulepatch->save();
}
}
}
echo json_encode($response);
exit;
@@ -82,12 +95,26 @@ class PoprackmoduleController extends mfBaseController
if ($r->type == 0) {
$data['ports'] = ($r->ports) ? $r->ports : null;
$data['plug'] = ($r->plug) ? $r->plug : null;
$poprackmodulepatchcounter = PoprackmodulepatchModel::countAllModule($id);
if ($poprackmodulepatchcounter > $data['ports']) {
for ($i = $poprackmodulepatchcounter; $i > $data['ports']; $i--) {
PoprackmodulepatchModel::deletebyPort($id, $i);
}
} else if ($poprackmodulepatchcounter < $data['ports']) {
$datapatchModel=[];
for ($i = $poprackmodulepatchcounter + 1; $i <= $data['ports']; $i++) {
$datapatchModel['poprackmodule_id'] = $id;
$datapatchModel['port'] = $i;
$poprackmodulepatch = PoprackmodulepatchModel::create($datapatchModel);
$poprackmodulepatch->save();
}
}
}
$data['name'] = ($r->name);
$poprackmodule->update($data);
$new_id = $poprackmodule->save();
// var_dump($r);die();
if (!$new_id) {
$response['success'] = false;
} else {

View File

@@ -0,0 +1,44 @@
<?php
class Poprackmodulepatch extends mfBaseModel
{
private $editor;
private $creator;
private $poprackmodule;
private $fiberPlanCable;
public function getProperty($name)
{
if ($this->$name == null) {
if (!$this->id) {
return null;
}
if ($name == "creator") {
$this->creator = new User($this->create_by);
return $this->creator;
}
if ($name == "editor") {
$this->editor = new User($this->edit_by);
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name . "_id";
$this->$name = new $classname($this->$idfield);
if ($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}

View File

@@ -0,0 +1,108 @@
<?php
class PoprackmodulepatchModel
{
private $poprackmodule_id;
private $port;
private $fiberPlanCable_id;
private $destination;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new Poprackmodulepatch();
foreach ($data as $field => $value) {
if (property_exists(get_called_class(), $field)) {
if (substr($field, 0, 5) == "vlan_" && !$value) {
$model->$field = null;
continue;
}
$model->$field = $value;
}
}
$me = mfValuecache::singleton()->get("me");
if (!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
}
if ($model->create_by === null) {
$model->create_by = $me->id;
}
if ($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getOne($id)
{
if (!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("Poprackmodulepatch", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Poprackmodulepatch($data);
}
return $item;
}
public static function countAllModule($moduleId)
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `id` FROM `Poprackmodulepatch` WHERE `poprackmodule_id`='" . $moduleId . "'";
$res = $db->query($sql);
$countrows = $db->num_rows($res);
return $countrows;
}
public static function deletebyPort($moduleId, $port)
{
$db = FronkDB::singleton();
$sql = "DELETE FROM `Poprackmodulepatch` WHERE `port`='" . $port . "' AND `poprackmodule_id`='" . $moduleId . "'";
$res = $db->query($sql);
}
public static function updatebyPort($moduleId, $port, $fiberPlanCable_id)
{
$db = FronkDB::singleton();
$sql = "UPDATE `Poprackmodulepatch` SET fiberPlanCable_id='" . $fiberPlanCable_id . "' WHERE `port`='" . $port . "' AND `poprackmodule_id`='" . $moduleId . "'";
echo $sql . "\n";
$db->query($sql);
}
public static function updatebyPortRange($moduleId, $startport, $endport, $fiberPlanCable_id)
{
$db = FronkDB::singleton();
$sql = "UPDATE `Poprackmodulepatch` SET fiberPlanCable_id='" . $fiberPlanCable_id . "' WHERE `port`>='" . $startport . "' AND `port`<='" . $endport . "' AND `poprackmodule_id`='" . $moduleId . "'";
echo $sql . "\n";
$db->query($sql);
}
public static function clearPort($fiberPlanCable_id)
{
$db = FronkDB::singleton();
$sql = "UPDATE `Poprackmodulepatch` SET fiberPlanCable_id=NULL WHERE `fiberPlanCable_id`='" . $fiberPlanCable_id . "'";
$db->query($sql);
}
}

View File

@@ -0,0 +1,61 @@
<?php
class Timerecording extends mfBaseModel
{
private $editor;
private $creator;
private $user;
private $timerecordingCategory;
public function getProperty($name)
{
if ($this->$name == null) {
if (!$this->id) {
return null;
}
if($name == "creator") {
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($this->creator === null) {
$this->creator = new User($this->create_by);
if($this->creator->id) {
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
}
}
return $this->creator;
}
if($name == "editor") {
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
if($this->editor === null) {
$this->editor = new User($this->edit_by);
if($this->editor->id) {
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
}
}
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
if(!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}

View File

@@ -0,0 +1,145 @@
<?php
class TimerecordingController extends mfBaseController
{
protected function init()
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->is(["employee"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction()
{
$this->layout()->setTemplate("Timerecording/Index");
$timerecordingCategoriess = TimerecordingCategoryModel::getAll();
$this->layout()->set("timerecordingCategoriess", $timerecordingCategoriess);
$timerecordings = TimerecordingModel::search(['user_id' => $this->me->id]);
$this->layout()->set("timerecordings", $timerecordings);
}
protected function addAction()
{
$timerecordingCategoriess = TimerecordingCategoryModel::getAll();
$this->layout()->set("timerecordingCategoriess", $timerecordingCategoriess);
$this->layout()->setTemplate("Timerecording/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Buchung nicht gefunden", "error");
$this->redirect("Timerecording");
}
$timerecordings = new Timerecording($id);
if ($timerecordings->id != $id) {
$this->layout()->setFlash("Buchung nicht gefunden", "error");
$this->redirect("Timerecording");
}
$this->layout()->set("timerecordings", $timerecordings);
return $this->addAction();
}
protected function saveAction()
{
$r = $this->request;
$id = $r->id;
$enddate = $r->enddate;
if (!$enddate && $r->start && $r->end) {
$starttime = strtotime($r->date . " " . $r->start . ":00");
$endtime = strtotime($r->date . " " . $r->end . ":00");
} elseif ($enddate) {
$starttime = strtotime($r->date . " 00:00:00");
$endtime = strtotime($enddate . " 23:59:00");
} else if (!$enddate && !$r->start && !$r->end) {
$starttime = strtotime($r->date . " 00:00:00");
$endtime = NULL;
}
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$timerecordings = new Timerecording($id);
if (!$timerecordings->id) {
$this->layout()->setFlash("Buchungen nicht gefunden", "error");
$this->redirect("Timerecording");
}
} else {
$mode = "add";
}
$data = [];
$data['user_id'] = $this->me->id;
$data['start'] = $starttime;
$data['end'] = $endtime;
$data['timerecordingCategory_id'] = trim($r->timerecordingCategory_id);
$data['commend'] = trim($r->commend);
if (!$data['user_id']) {
$this->layout()->setFlash("Benutzer darf nicht leer sein", "error");
$this->redirect("Timerecording");
}
if ($data['start'] < 1577833200) {
$this->layout()->setFlash("Ungültige Startzeit", "error");
$this->redirect("Timerecording");
}
if ($data['end'] && $data['end'] < 1577833200) {
$this->layout()->setFlash("Ungültige Endzeit", "error");
$this->redirect("Timerecording");
}
if (!$data['timerecordingCategory_id']) {
$data['timerecordingCategory_id'] = NULL;
}
if (!$data['commend']) {
$data['commend'] = NULL;
}
if ($mode == "edit") {
$timerecordings->update($data);
} else {
$timerecordings = TimerecordingModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $timerecordings->save();
if (!$id) {
$this->layout()->setFlash("Buchung konnte nicht angelegt werden", "error");
$this->redirect("Timerecording");
}
if ($mode == "edit") {
$this->layout()->setFlash("Buchung erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("Buchung erfolgreich angelegt", "success");
}
$this->redirect("Timerecording");
}
protected function deleteAction()
{
$id = $this->request->id;
$timerecordings = new Timerecording($id);
if (!$timerecordings->id || $timerecordings->id != $id) {
$this->layout()->setFlash("Buchung nicht gefunden.", "error");
$this->redirect("Timerecording");
}
$timerecordings->delete();
$this->redirect("Timerecording");
}
}

View File

@@ -0,0 +1,148 @@
<?php
class TimerecordingModel
{
private $user_id;
private $start;
private $end;
private $timerecordingCategory_id;
private $commend;
private $approved;
private $completed;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new Timerecording();
foreach ($data as $field => $value) {
if (property_exists(get_called_class(), $field)) {
if (substr($field, 0, 5) == "vlan_" && !$value) {
$model->$field = null;
continue;
}
$model->$field = $value;
}
}
$me = mfValuecache::singleton()->get("me");
if (!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
}
if ($model->create_by === null) {
$model->create_by = $me->id;
}
if ($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getOne($id)
{
if (!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("Timerecording", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Timerecording($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("Timerecording", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new Timerecording($data);
}
}
return $items;
}
public static function getAllPermits()
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT Timerecording.* FROM `Timerecording`
INNER JOIN `TimerecordingCategory` ON (`Timerecording`.`timerecordingCategory_id` = `TimerecordingCategory`.`id`)
WHERE `TimerecordingCategory`.`approval`='1'";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new Timerecording($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Timerecording", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Timerecording($data);
if ($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function search($filter)
{
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Timerecording", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new Timerecording($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
if (array_key_exists("user_id", $filter)) {
$userid = $filter['user_id'];
if (is_numeric($userid)) {
$where .= " AND user_id=$userid";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,41 @@
<?php
class TimerecordingCategory extends mfBaseModel
{
private $editor;
private $creator;
public function getProperty($name)
{
if ($this->$name == null) {
if (!$this->id) {
return null;
}
if ($name == "creator") {
$this->creator = new User($this->create_by);
return $this->creator;
}
if ($name == "editor") {
$this->editor = new User($this->edit_by);
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name . "_id";
$this->$name = new $classname($this->$idfield);
if ($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}

View File

@@ -0,0 +1,141 @@
<?php
class TimerecordingCategoryController extends mfBaseController
{
protected function init()
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->can(["Fibu"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction()
{
$this->layout()->setTemplate("TimerecordingCategories/Index");
$timerecordingcategoriesapproval = TimerecordingCategoryModel::$approval_definition;
$timerecordingcategorieshourday = TimerecordingCategoryModel::$hourday_definition;
$timerecordingcategoriesrequire_comment = TimerecordingCategoryModel::$require_comment_definition;
$timerecordingcategoriess = TimerecordingCategoryModel::getAll();
$this->layout()->set("timerecordingcategoriesrequire_comment", $timerecordingcategoriesrequire_comment);
$this->layout()->set("timerecordingcategorieshourday", $timerecordingcategorieshourday);
$this->layout()->set("timerecordingcategoriesapproval", $timerecordingcategoriesapproval);
$this->layout()->set("timerecordingcategoriess", $timerecordingcategoriess);
}
protected function addAction()
{
$timerecordingcategorieshourday = TimerecordingCategoryModel::$hourday_definition;
$this->layout()->set("timerecordingcategorieshourday", $timerecordingcategorieshourday);
$this->layout()->setTemplate("TimerecordingCategories/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Zeiterfassung Kategorie nicht gefunden", "error");
$this->redirect("TimerecordingCategory");
}
$timerecordingcategoriess = new TimerecordingCategory($id);
if ($timerecordingcategoriess->id != $id) {
$this->layout()->setFlash("Zeiterfassung Kategorie nicht gefunden", "error");
$this->redirect("TimerecordingCategory");
}
$timerecordingcategorieshourday = TimerecordingCategoryModel::$hourday_definition;
$this->layout()->set("timerecordingcategorieshourday", $timerecordingcategorieshourday);
$this->layout()->set("timerecordingcategoriess", $timerecordingcategoriess);
return $this->addAction();
}
protected function saveAction()
{
$r = $this->request;
$id = $r->id;
//var_dump($r->get());exit;
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$timerecordingcategoriess = new TimerecordingCategory($id);
if (!$timerecordingcategoriess->id) {
$this->layout()->setFlash("Zeiterfassung Kategorien nicht gefunden", "error");
$this->redirect("TimerecordingCategory");
}
} else {
$mode = "add";
}
$data = [];
$data['name'] = trim($r->name);
$data['short'] = trim($r->short);
$data['hourday'] = trim($r->hourday);
$data['approval'] = trim($r->approval);
$data['require_comment'] = trim($r->require_comment);
if (!$data['name']) {
$data['name'] = NULL;
}
if (!$data['short']) {
$data['short'] = NULL;
}
if (!$data['approval']) {
$data['approval'] = 0;
}
if (!$data['require_comment']) {
$data['require_comment'] = 0;
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$timerecordingcategoriess->update($data);
} else {
$timerecordingcategoriess = TimerecordingCategoryModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $timerecordingcategoriess->save();
if (!$id) {
$this->layout()->setFlash("Zeiterfassung Kategorie konnte nicht angelegt werden", "error");
$this->redirect("TimerecordingCategory");
}
if ($mode == "edit") {
$this->layout()->setFlash("Zeiterfassung Kategorie erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("Zeiterfassung Kategorie erfolgreich angelegt", "success");
}
$this->redirect("TimerecordingCategory");
}
protected function deleteAction()
{
$id = $this->request->id;
$timerecordingcategoriess = new TimerecordingCategory($id);
if (!$timerecordingcategoriess->id || $timerecordingcategoriess->id != $id) {
$this->layout()->setFlash("Zeiterfassung Kategorie nicht gefunden.", "error");
$this->redirect("TimerecordingCategory");
}
$timerecordingcategoriess->delete();
$this->redirect("TimerecordingCategory");
}
}

View File

@@ -0,0 +1,132 @@
<?php
class TimerecordingCategoryModel
{
private $name;
private $short;
private $hourday;
private $approval;
private $require_comment;
public static $hourday_definition = array(1 => "Uhrzeit (von/bis)", 2 => "Tage (von/bis)", 3 => "Startdatum", 4 => "Enddatum");
public static $approval_definition = array(0 => "Nein", 1 => "Ja");
public static $require_comment_definition = array(0 => "Nein", 1 => "Ja");
public static function find($data)
{
}
public static function create(array $data)
{
$model = new TimerecordingCategory();
foreach ($data as $field => $value) {
if (property_exists(get_called_class(), $field)) {
if (substr($field, 0, 5) == "vlan_" && !$value) {
$model->$field = null;
continue;
}
$model->$field = $value;
}
}
$me = mfValuecache::singleton()->get("me");
if (!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
}
if ($model->create_by === null) {
$model->create_by = $me->id;
}
if ($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getOne($id)
{
if (!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("timerecordingCategory", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new TimerecordingCategory($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("TimerecordingCategory", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new TimerecordingCategory($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("TimerecordingCategory", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new TimerecordingCategory($data);
if ($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function search($filter)
{
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("TimerecordingCategory", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new TimerecordingCategory($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("network_id", $filter)) {
$networkid = $filter['network_id'];
if (is_numeric($networkid)) {
$where .= " AND network_id=$networkid";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,62 @@
<?php
class TimerecordingPermitController extends mfBaseController
{
protected function init()
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->can(["Fibu"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction()
{
$this->layout()->setTemplate("TimerecordingPermit/Index");
$timerecordingCategoriess = TimerecordingCategoryModel::getAll();
$this->layout()->set("timerecordingCategoriess", $timerecordingCategoriess);
$timerecordings = TimerecordingModel::getAllPermits();
$this->layout()->set("timerecordings", $timerecordings);
}
protected function addAction()
{
}
protected function editAction()
{
}
protected function saveAction()
{
}
protected function approveAction()
{
$id = $this->request->id;
$timerecordings = new Timerecording($id);
if (!$timerecordings->id || $timerecordings->id != $id) {
$this->layout()->setFlash("Buchung nicht gefunden.", "error");
$this->redirect("TimerecordingPermit");
}
$data = [];
$data['approved'] = 1;
$timerecordings->update($data);
$timerecordings->save();
$this->redirect("TimerecordingPermit");
}
}

View File

@@ -0,0 +1,51 @@
<?php
class TimerecordingReportController extends mfBaseController
{
protected function init()
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->can(["Fibu"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction()
{
$this->layout()->setTemplate("TimerecordingReport/Index");
$timerecordingCategoriess = TimerecordingCategoryModel::getAll();
$this->layout()->set("timerecordingCategoriess", $timerecordingCategoriess);
$timerecordings = TimerecordingModel::getAll();
$this->layout()->set("timerecordings", $timerecordings);
}
protected function addAction()
{
}
protected function editAction()
{
}
protected function saveAction()
{
}
protected function deleteAction()
{
}
}