/** * read subnets */ public function readSubnets() { //init subnet class $subnet = new Subnet(); //set IP address format $subnet->format = $this->_params['format']; //get all subnets if ($this->_params['all']) { $subnet->all = true; } elseif ($this->_params['sectionId']) { $subnet->sectionId = $this->_params['sectionId']; } else { $subnet->id = $this->_params['id']; } //fetch results $res = $subnet->readSubnet(); //return subnet(s) in array format return $res; }
/** * delete Section * id must be provided * * we must also delete all subnets and all IP addresses! */ public function deleteSection() { //check input $this->Common->check_var("int", $this->id, null); //verify that it exists try { $this->readSection(); } catch (Exception $e) { throw new Exception($e->getMessage()); } //do we need to delete also subnets? if ($this->subnets) { $Subnet = new Subnet(); # get all belonging subnets $Subnet->sectionId = $this->id; $Subnet->addresses = $this->addresses; //flag to delete also IPs try { $allsubnets = $Subnet->readSubnet(); } catch (Exception $e) { # empty? if (substr($e->getMessage(), 0, 32) == "Invalid section Id or no subnets") { } else { throw new Exception($e->getMessage()); } } # loop if (sizeof($allsubnets) > 0) { foreach ($allsubnets as $s) { # provide id and parameters $Subnet->id = $s['id']; $Subnet->deleteSubnet(); } } } //set query and execute $this->query = "delete from `sections` where `id` = " . $this->id . ";"; $this->executeQuery(); //set result $result['result'] = "success"; $result['response'] = "section " . $this->id . " deleted successfully!"; //return result return $result; }