Devices:
• Übersicht Pop/Adressen/Koordinaten Verlinkungen Pop: • Fontsize in Übersicht auf 13px geändert für bessere Übersicht • Neue Features: o Poprackverwaltung v1 CRUD o Poprackmodulverwaltung V1 CRUD
This commit is contained in:
@@ -43,6 +43,7 @@ class PopController extends mfBaseController
|
||||
|
||||
$this->layout()->setTemplate("Pop/Detail");
|
||||
$filter['pop_id'] = $id;
|
||||
$this->layout()->set("popracks", PoprackModel::getAllbyPop($id));
|
||||
$this->layout()->set("devices", DeviceModel::search($filter));
|
||||
$pops = PopModel::getOne($id);
|
||||
$this->layout()->set("pops", $pops);
|
||||
@@ -151,7 +152,6 @@ class PopController extends mfBaseController
|
||||
$returnAction = "";
|
||||
$returnVariables['id'] = $id;
|
||||
$this->returUrl = $returnUrl;
|
||||
var_dump($returnUrl);
|
||||
} else {
|
||||
$this->returUrl = ucfirst($this->request->returnto);
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
class Poprack extends mfBaseModel
|
||||
{
|
||||
|
||||
private $pop;
|
||||
|
||||
public function getProperty($name)
|
||||
{
|
||||
if ($this->$name == 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
|
||||
class PoprackController extends mfBaseController
|
||||
{
|
||||
protected function apiAction()
|
||||
{
|
||||
$do = $this->request->do;
|
||||
|
||||
$data = [];
|
||||
|
||||
switch ($do) {
|
||||
case "addRack":
|
||||
$return = $this->addRack();
|
||||
break;
|
||||
case "editRack":
|
||||
$return = $this->editRack();
|
||||
break;
|
||||
case "removeRack":
|
||||
$return = $this->removeRack();
|
||||
break;
|
||||
case "sortRack":
|
||||
$return = $this->sortRack();
|
||||
break;
|
||||
case "generateRack";
|
||||
$return = $this->generateRack();
|
||||
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 addRack()
|
||||
{
|
||||
$r = $this->request;
|
||||
$pop_id = $r->pop_id;
|
||||
$data = [];
|
||||
$data['name'] = trim($r->name);
|
||||
$data['he'] = trim($r->he);
|
||||
$data['pop_id'] = trim($pop_id);
|
||||
$poprack = PoprackModel::create($data);
|
||||
|
||||
$new_id = $poprack->save();
|
||||
// var_dump($r);die();
|
||||
if (!$new_id) {
|
||||
$response['success'] = false;
|
||||
} else {
|
||||
$response['success'] = true;
|
||||
}
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
private function editRack()
|
||||
{
|
||||
$r = $this->request;
|
||||
$id = $r->poprack_id;
|
||||
$poprack = new Poprack($id);
|
||||
$response['success'] = false;
|
||||
if ($poprack->id) {
|
||||
$data = [];
|
||||
$data['name'] = $r->name;
|
||||
$data['he'] = $r->he;
|
||||
$poprack->update($data);
|
||||
if ($poprack->save()) {
|
||||
$response['success'] = true;
|
||||
}
|
||||
}
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
private function sortRack()
|
||||
{
|
||||
$r = $this->request;
|
||||
$racksortids = $r->racksortids;
|
||||
// var_dump($racksortids);
|
||||
// die();
|
||||
|
||||
foreach ($racksortids as $sort => $id) {
|
||||
$poprack = new Poprack($id);
|
||||
$response['success'] = false;
|
||||
if ($poprack->id) {
|
||||
$data = [];
|
||||
$data['sort'] = $sort;
|
||||
$poprack->update($data);
|
||||
if ($poprack->save()) {
|
||||
$response['success'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
private function removeRack()
|
||||
{
|
||||
$id = $this->request->id;
|
||||
$poprack = new Poprack($id);
|
||||
if (!$poprack->id || $poprack->id != $id) {
|
||||
$response['success'] = false;
|
||||
} else {
|
||||
$poprack->delete();
|
||||
$response['success'] = true;
|
||||
}
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
private function generateRack()
|
||||
{
|
||||
$id = $this->request->id;
|
||||
$cellwidth = 227;
|
||||
$blocktd = 0;
|
||||
$poprack = PoprackModel::getAllbyRack($id);
|
||||
$plugs[1] = "LC";
|
||||
$plugs[2] = "SC";
|
||||
$plugs[3] = "E2000";
|
||||
for ($i = 1; $i <= $poprack[0]['rack']['he']; $i++) :
|
||||
echo '<tr>
|
||||
<td class="border-right w-15 p-0 pl-1 pr-1 border-bottom font-13 rack-he user-select-none"
|
||||
data-toggle="modal" data-target="#rackModuleModal"
|
||||
style="cursor: pointer" data-he="' . $i . '">He' . $i . '</td>';
|
||||
foreach ($poprack[0]['modules'] as $module) {
|
||||
|
||||
if ($module['start_he'] == $i) {
|
||||
$modulestart = 1;
|
||||
|
||||
$modulelenght = $module['end_he'] - $module['start_he'] + 1;
|
||||
$position = 1;
|
||||
$slotcounter = 0;
|
||||
$calcwidth = 0;
|
||||
$extText = "";
|
||||
$extTextspan="";
|
||||
foreach ($module['slots'] as $slots) {
|
||||
$extText = "";
|
||||
if ($slots['type'] == '0') {
|
||||
$color = '#9fff6e';
|
||||
$colorclass = "rack-color-lwl";
|
||||
if ($slots['plug']) {
|
||||
|
||||
$extText = " (" . $plugs[$slots['plug']] . "/" . $slots['ports'] . "P)";
|
||||
$extTextspan = "<span style='font-size: 12px;font-weight: 400'>".$extText."</span>";
|
||||
}
|
||||
} else if ($slots['type'] == '1') {
|
||||
|
||||
$color = '#b6c6ff';
|
||||
$colorclass = "rack-color-device";
|
||||
} else if ($slots['type'] == '2') {
|
||||
|
||||
$color = '#ff8100';
|
||||
$colorclass = "rack-color-rpanel";
|
||||
} else if ($slots['type'] == '3') {
|
||||
$color = '#ffad59';
|
||||
$colorclass = "rack-color-infra";
|
||||
} else if ($slots['type'] == '4') {
|
||||
$color = '#96f3de';
|
||||
$colorclass = "rack-color-panel";
|
||||
} else if ($slots['type'] == '5') {
|
||||
$color = '#96f3de';
|
||||
$colorclass = "rack-color-blocked";
|
||||
}
|
||||
if ($slots['width'] == "12") {
|
||||
$width = "85%";
|
||||
$maxwidth = $cellwidth;
|
||||
} else if ($slots['width'] == "6") {
|
||||
$width = "42%";
|
||||
$maxwidth = intval($cellwidth / 2);
|
||||
} else if ($slots['width'] == "4") {
|
||||
$width = "28%";
|
||||
$maxwidth = intval($cellwidth / 3);
|
||||
} else if ($slots['width'] == "3") {
|
||||
$width = "21%";
|
||||
$maxwidth = intval($cellwidth / 4);
|
||||
}
|
||||
if ($slots['width'] < 12 && $position != $slots['position']) {
|
||||
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right text-nowrap text-truncate pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
|
||||
$position++;
|
||||
$calcwidth = $calcwidth + $slots['width'];
|
||||
|
||||
}
|
||||
if ($slots['width'] < 12 && $position != $slots['position']) {
|
||||
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-righttext-nowrap text-truncate pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
|
||||
$position++;
|
||||
$calcwidth = $calcwidth + $slots['width'];
|
||||
}
|
||||
if ($slots['width'] < 12 && $position != $slots['position']) {
|
||||
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right text-nowrap text-truncate pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
|
||||
$position++;
|
||||
$calcwidth = $calcwidth + $slots['width'];
|
||||
}
|
||||
echo '<td title="' . $slots['modulname'] . $extText . '" colspan="' . $slots['width'] . '" class="text-center border-top border-bottom border-right text-nowrap text-truncate pl-1 pr-1 ' . $colorclass . '" data-id="' . $slots['moduleid'] . '" data-type="' . $slots['type'] . '" data-name="' . $slots['modulname'] . '" data-starthe="' . $module['start_he'] . '" data-ports="' . $slots['ports'] . '" data-plug="' . $slots['plug'] . '" rowspan="' . $modulelenght . '" style="width: ' . $width . '; background-color: ' . $color . ';border-color: #797979 !important; white-space: nowrap; text-overflow: ellipsis;max-width: ' . $maxwidth . 'px;"><span></span> ' . $slots['modulname'] . $extTextspan . '</td>';
|
||||
$position++;
|
||||
$calcwidth = $calcwidth + $slots['width'];
|
||||
}
|
||||
if ($calcwidth != 12) {
|
||||
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right text-nowrap text-truncate pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
|
||||
$calcwidth = $calcwidth + $slots['width'];
|
||||
}
|
||||
if ($calcwidth != 12) {
|
||||
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right text-nowrap text-truncate pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
|
||||
$calcwidth = $calcwidth + $slots['width'];
|
||||
}
|
||||
if ($calcwidth != 12) {
|
||||
echo '<td colspan="' . $slots['width'] . '" style="width: ' . $width . ';" class="text-center border-top border-bottom border-right text-nowrap text-truncate pl-1 pr-1" rowspan="' . $modulelenght . '">frei</td>';
|
||||
$calcwidth = $calcwidth + $slots['width'];
|
||||
}
|
||||
|
||||
$blocktd = $modulelenght + $i;
|
||||
|
||||
}
|
||||
}
|
||||
if ($i >= $blocktd) {
|
||||
echo '<td colspan="12" style="background-color: #fff;" class="text-center he-free" ><span></span> frei</td>';
|
||||
}
|
||||
echo '</tr>';
|
||||
endfor;
|
||||
die();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
class PoprackModel
|
||||
{
|
||||
public $pop_id = null;
|
||||
public $name = null;
|
||||
public $he = null;
|
||||
public $sort = null;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
public static function create(array $data)
|
||||
{
|
||||
$model = new Poprack();
|
||||
|
||||
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 getAllbyPop($pop_id)
|
||||
{
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
$sql = "(SELECT `Poprackmodule`.`type`,`Poprack`.`id`,`Poprack`.`sort`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Poprackmodule`.`name` as `modulname`,device_id ,`Poprackmodule`.`id` as moduleid,`Poprackmodule`.`width` as modulewidth,`Poprackmodule`.`position` as moduleposition,`Poprackmodule`.`ports` as moduleports,`Poprackmodule`.`plug` as moduleplug FROM `Poprack`
|
||||
LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id` AND `Poprackmodule`.`type`!=1)
|
||||
WHERE `Poprack`.`pop_id`='" . $pop_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.start_he,`Poprackmodule`.position)
|
||||
UNION
|
||||
(SELECT `Poprackmodule`.`type`,`Poprack`.`id`,`Poprack`.`sort`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Device`.`name` as `modulname`,device_id,`Poprackmodule`.`id` as moduleid,`Poprackmodule`.`width` as modulewidth,`Poprackmodule`.`position` as moduleposition,`Poprackmodule`.`ports` as moduleports,`Poprackmodule`.`plug` as moduleplug FROM `Poprack`
|
||||
LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id` AND `Poprackmodule`.`type`=1)
|
||||
LEFT JOIN `Device` ON (`Device`.`id`=`Poprackmodule`.`device_id`)
|
||||
WHERE `Poprack`.`pop_id`='" . $pop_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.start_he,`Poprackmodule`.position)
|
||||
ORDER BY sort,name,start_he,moduleposition
|
||||
";
|
||||
|
||||
//
|
||||
// $sql = "SELECT `Poprack`.`id`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Poprackmodule`.`name` as `modulname` FROM `Poprack`
|
||||
// LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id`)
|
||||
// WHERE `Poprack`.`pop_id`='" . $pop_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.`start_he`";
|
||||
$res = $db->query($sql);
|
||||
if ($db->num_rows($res)) {
|
||||
$oldrackid = "";
|
||||
$counter = -1;
|
||||
while ($data = $db->fetch_array($res)) {
|
||||
|
||||
if ($oldrackid != $data['id']) {
|
||||
$counter++;
|
||||
$items[$counter]['rack']['id'] = $data['id'];
|
||||
$items[$counter]['rack']['name'] = $data['name'];
|
||||
$items[$counter]['rack']['he'] = $data['he'];
|
||||
$modulecounter = 0;
|
||||
}
|
||||
if ($data['modulname']) {
|
||||
if ($data['device_id']) {
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['device_id'] = $data['device_id'];
|
||||
}
|
||||
$items[$counter]['modules'][$data['start_he']]['start_he'] = $data['start_he'];
|
||||
$items[$counter]['modules'][$data['start_he']]['end_he'] = $data['end_he'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['modulname'] = $data['modulname'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['moduleid'] = $data['moduleid'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['type'] = $data['type'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['width'] = $data['modulewidth'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['position'] = $data['moduleposition'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['ports'] = $data['moduleports'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['plug'] = $data['moduleplug'];
|
||||
$modulecounter++;
|
||||
}
|
||||
$oldrackid = $data['id'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getAllbyRack($rack_id)
|
||||
{
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
$sql = "(SELECT `Poprackmodule`.`type`,`Poprack`.`id`,`Poprack`.`sort`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Poprackmodule`.`name` as `modulname`,device_id ,`Poprackmodule`.`id` as moduleid,`Poprackmodule`.`width` as modulewidth,`Poprackmodule`.`position` as moduleposition,`Poprackmodule`.`ports` as moduleports,`Poprackmodule`.`plug` as moduleplug FROM `Poprack`
|
||||
LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id` AND `Poprackmodule`.`type`!=1)
|
||||
WHERE `Poprack`.`id`='" . $rack_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.start_he,`Poprackmodule`.position)
|
||||
UNION
|
||||
(SELECT `Poprackmodule`.`type`,`Poprack`.`id`,`Poprack`.`sort`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Device`.`name` as `modulname`,device_id,`Poprackmodule`.`id` as moduleid,`Poprackmodule`.`width` as modulewidth,`Poprackmodule`.`position` as moduleposition,`Poprackmodule`.`ports` as moduleports,`Poprackmodule`.`plug` as moduleplug FROM `Poprack`
|
||||
LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id` AND `Poprackmodule`.`type`=1)
|
||||
LEFT JOIN `Device` ON (`Device`.`id`=`Poprackmodule`.`device_id`)
|
||||
WHERE `Poprack`.`id`='" . $rack_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.start_he,`Poprackmodule`.position)
|
||||
ORDER BY sort,name,start_he,moduleposition
|
||||
";
|
||||
|
||||
//
|
||||
// $sql = "SELECT `Poprack`.`id`, `Poprack`.`name`, `Poprack`.`he`,`Poprackmodule`.start_he,`Poprackmodule`.end_he,`Poprackmodule`.`name` as `modulname` FROM `Poprack`
|
||||
// LEFT JOIN `Poprackmodule` ON (`Poprackmodule`.`poprack_id`=`Poprack`.`id`)
|
||||
// WHERE `Poprack`.`pop_id`='" . $pop_id . "' ORDER by `Poprack`.`sort`,`Poprack`.`name`,`Poprackmodule`.`start_he`";
|
||||
$res = $db->query($sql);
|
||||
if ($db->num_rows($res)) {
|
||||
$oldrackid = "";
|
||||
$counter = -1;
|
||||
while ($data = $db->fetch_array($res)) {
|
||||
|
||||
if ($oldrackid != $data['id']) {
|
||||
$counter++;
|
||||
$items[$counter]['rack']['id'] = $data['id'];
|
||||
$items[$counter]['rack']['name'] = $data['name'];
|
||||
$items[$counter]['rack']['he'] = $data['he'];
|
||||
$modulecounter = 0;
|
||||
}
|
||||
if ($data['modulname']) {
|
||||
if ($data['device_id']) {
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['device_id'] = $data['device_id'];
|
||||
}
|
||||
$items[$counter]['modules'][$data['start_he']]['start_he'] = $data['start_he'];
|
||||
$items[$counter]['modules'][$data['start_he']]['end_he'] = $data['end_he'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['modulname'] = $data['modulname'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['moduleid'] = $data['moduleid'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['type'] = $data['type'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['width'] = $data['modulewidth'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['position'] = $data['moduleposition'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['ports'] = $data['moduleports'];
|
||||
$items[$counter]['modules'][$data['start_he']]['slots'][$data['moduleid']]['plug'] = $data['moduleplug'];
|
||||
$modulecounter++;
|
||||
}
|
||||
$oldrackid = $data['id'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getpoprack($pop_id)
|
||||
{
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
$sql = "SELECT `id`, `name`, `he` FROM `Poprack` WHERE pop_id='" . $pop_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;
|
||||
}
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
class Poprackmodule extends mfBaseModel
|
||||
{
|
||||
private $poprack;
|
||||
|
||||
public function getProperty($name)
|
||||
{
|
||||
if ($this->$name == 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
class PoprackmoduleController extends mfBaseController
|
||||
{
|
||||
protected function apiAction()
|
||||
{
|
||||
$do = $this->request->do;
|
||||
|
||||
$data = [];
|
||||
|
||||
switch ($do) {
|
||||
case "addModule":
|
||||
$return = $this->addModule();
|
||||
break;
|
||||
case "removeModule":
|
||||
$return = $this->removeModule();
|
||||
break;
|
||||
case "updateModule":
|
||||
$return = $this->updateModule();
|
||||
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 addModule()
|
||||
{
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
$data = [];
|
||||
$data['poprack_id'] = $r->poprack_id;
|
||||
$data['type'] = $r->type;
|
||||
if ($data['type'] == 0) {
|
||||
$data['ports'] = ($r->ports) ? $r->ports : null;
|
||||
$data['plug'] = ($r->plug) ? $r->plug : null;
|
||||
}
|
||||
if ($data['type'] == 1) {
|
||||
$data['device_id'] = ($r->device_id) ? $r->device_id : null;
|
||||
}
|
||||
$data['name'] = ($r->name) ? $r->name : null;
|
||||
$data['start_he'] = $r->start_he;
|
||||
$data['end_he'] = $r->end_he;
|
||||
$data['width'] = $r->width;
|
||||
$data['position'] = ($r->position) ? $r->position : null;
|
||||
|
||||
$poprackmodule = PoprackmoduleModel::create($data);
|
||||
|
||||
$new_id = $poprackmodule->save();
|
||||
// var_dump($r);die();
|
||||
if (!$new_id) {
|
||||
$response['success'] = false;
|
||||
} else {
|
||||
$response['success'] = true;
|
||||
}
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
private function updateModule()
|
||||
{
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
if (is_numeric($id) && $id > 0) {
|
||||
$poprackmodule = new Poprackmodule($id);
|
||||
if (!$poprackmodule->id) {
|
||||
$response['success'] = false;
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
die();
|
||||
}
|
||||
}
|
||||
$data = [];
|
||||
|
||||
if ($r->type == 0) {
|
||||
$data['ports'] = ($r->ports) ? $r->ports : null;
|
||||
$data['plug'] = ($r->plug) ? $r->plug : null;
|
||||
}
|
||||
$data['name'] = ($r->name);
|
||||
$poprackmodule->update($data);
|
||||
|
||||
$new_id = $poprackmodule->save();
|
||||
// var_dump($r);die();
|
||||
if (!$new_id) {
|
||||
$response['success'] = false;
|
||||
} else {
|
||||
$response['success'] = true;
|
||||
}
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
private function removeModule()
|
||||
{
|
||||
$id = $this->request->id;
|
||||
$poprackmodule = new Poprackmodule($id);
|
||||
if (!$poprackmodule->id || $poprackmodule->id != $id) {
|
||||
$response['success'] = false;
|
||||
} else {
|
||||
$poprackmodule->delete();
|
||||
$response['success'] = true;
|
||||
}
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
class PoprackmoduleModel
|
||||
{
|
||||
|
||||
public $poprack_id = null;
|
||||
public $type = null;
|
||||
public $device_id = null;
|
||||
public $name = null;
|
||||
public $start_he = null;
|
||||
public $end_he = null;
|
||||
public $width = null;
|
||||
public $ports = null;
|
||||
public $plug = null;
|
||||
public $position = null;
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
public static function create(array $data)
|
||||
{
|
||||
$model = new Poprackmodule();
|
||||
|
||||
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 getpoprackmodule($poprack_id)
|
||||
{
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
$sql = "SELECT `id`, `name`, `start_he`,`end_he` FROM `Poprackmodule` WHERE `poprack_id`='" . $poprack_id . "' AND type ='0' ORDER by name";
|
||||
|
||||
$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;
|
||||
}
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user