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": $rack_id = $this->request->id; $side = $this->request->side ?? 'front'; $rackDataArray = PoprackModel::getAllbyRack($rack_id); $rackData = $rackDataArray[0] ?? null; if ($rackData) { $modules_to_render = $rackData['modules'][$side] ?? []; $rack_he = $rackData['rack']['he']; $plugs[1] = "LC/APC"; $plugs[2] = "SC/APC"; $plugs[3] = "E2000/APC"; include(dirname(__FILE__) . "/../../Layout/default/Pop/_rack_body.php"); } exit; 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; $side=$this->request->side; $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 ' He' . $i . ''; foreach ($poprack[0][$side]['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 = ""; $title=$slots['modulname']; if ($slots['type'] == '0') { $color = '#9fff6e'; $colorclass = "rack-color-lwl"; if ($slots['plug']) { $extText = " (" . $plugs[$slots['plug']] . "/" . $slots['ports'] . "P)"; $extTextspan = "".$extText.""; } } else if ($slots['type'] == '1') { $slots['modulname']=' $slots['device_id']]).'">'.$slots['modulname'].''; $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 'frei'; $position++; $calcwidth = $calcwidth + $slots['width']; } if ($slots['width'] < 12 && $position != $slots['position']) { echo 'frei'; $position++; $calcwidth = $calcwidth + $slots['width']; } if ($slots['width'] < 12 && $position != $slots['position']) { echo 'frei'; $position++; $calcwidth = $calcwidth + $slots['width']; } echo ' ' . $slots['modulname'] . $extTextspan . ''; $position++; $calcwidth = $calcwidth + $slots['width']; } if ($calcwidth != 12) { echo 'frei'; $calcwidth = $calcwidth + $slots['width']; } if ($calcwidth != 12) { echo 'frei'; $calcwidth = $calcwidth + $slots['width']; } if ($calcwidth != 12) { echo 'frei'; $calcwidth = $calcwidth + $slots['width']; } $blocktd = $modulelenght + $i; } } if ($i >= $blocktd) { echo ' frei'; } echo ''; endfor; die(); } }