diff options
-rw-r--r-- | .zfproject.xml | 5 | ||||
-rw-r--r-- | application/controllers/ClientController.php | 89 | ||||
-rw-r--r-- | application/controllers/FilterController.php | 17 | ||||
-rw-r--r-- | application/forms/Client.php | 37 | ||||
-rw-r--r-- | application/views/scripts/client/addclient.phtml | 4 | ||||
-rw-r--r-- | application/views/scripts/client/editclient.phtml | 3 | ||||
-rw-r--r-- | application/views/scripts/client/index.phtml | 16 |
7 files changed, 145 insertions, 26 deletions
diff --git a/.zfproject.xml b/.zfproject.xml index 417a947..8cdb2e0 100644 --- a/.zfproject.xml +++ b/.zfproject.xml @@ -58,6 +58,7 @@ <actionMethod actionName="index"/> <actionMethod actionName="addclient"/> <actionMethod actionName="removeclient"/> + <actionMethod actionName="editclient"/> </controllerFile> <controllerFile controllerName="Pool"> <actionMethod actionName="index"/> @@ -92,6 +93,7 @@ <formFile formName="BootisoEdit"/> <formFile formName="Pool"/> <formFile formName="PoolClient"/> + <formFile formName="Client"/> </formsDirectory> <layoutsDirectory enabled="false"/> <modelsDirectory> @@ -281,6 +283,9 @@ <viewControllerScriptsDirectory forControllerName="Pool"> <viewScriptFile forActionName="unlinkclient"/> </viewControllerScriptsDirectory> + <viewControllerScriptsDirectory forControllerName="Client"> + <viewScriptFile forActionName="editclient"/> + </viewControllerScriptsDirectory> </viewScriptsDirectory> <viewHelpersDirectory/> <viewFiltersDirectory enabled="false"/> diff --git a/application/controllers/ClientController.php b/application/controllers/ClientController.php index 336bf9e..ff663ba 100644 --- a/application/controllers/ClientController.php +++ b/application/controllers/ClientController.php @@ -10,39 +10,78 @@ class ClientController extends Zend_Controller_Action public function indexAction() { - $clientMapper = new Application_Model_ClientMapper(); - $this->view->clients = $clientMapper->fetchAll(); + $clientMapper = new Application_Model_ClientMapper(); + $this->view->clients = $clientMapper->fetchAll(); } public function addclientAction() - { - $mac = $this->_request->getParam('mac'); - $hh = $this->_request->getParam('hh'); - - if($mac != '' && $hh != ''){ - $client = new Application_Model_Client(); - $client->setMacadress($mac); - $client->setHardwarehash($hh); - $clientmapper = new Application_Model_ClientMapper(); - $clientmapper->save($client); - print_a('inserted'); - } - else{ - print_a('no insert'); - } + { + $mac = $this->_request->getParam('mac'); + $hh = $this->_request->getParam('hh'); + + if (!isset($_POST["add"])){ + $addclient = new Application_Form_Client(); + $this->view->addclient = $addclient; + } + else{ + $addfilterform = new Application_Form_Client($_POST); + print_a($_POST,$addfilterform->isValid($_POST)); + if ($addfilterform->isValid($_POST) || ($mac != '' && $hh != '') ) { + $client = new Application_Model_Client(); + $mac = ($mac!='')?$mac:$_POST['macadress']; + $hh = ($hh!='')?$hh:$_POST['hardwarehash']; + $client->setMacadress($mac); + $client->setHardwarehash($hh); + $clientmapper = new Application_Model_ClientMapper(); + $clientmapper->save($client); + print_a('inserted'); + $this->_redirect('/client'); + } + else{ + print_a('no insert'); + } + } } public function removeclientAction() { $clientID = $this->_request->getParam('clientID'); - // TODO: ACL implementieren ob er den filter löschen darf - if(is_numeric($clientID)){ - $removeClient = new Application_Model_Client(); - $removeClient->setID($clientID); - $clientMapper = new Application_Model_ClientMapper(); - $clientMapper->delete($removeClient); + // TODO: ACL implementieren ob er den filter löschen darf + if(is_numeric($clientID)){ + $removeClient = new Application_Model_Client(); + $removeClient->setID($clientID); + $clientMapper = new Application_Model_ClientMapper(); + $clientMapper->delete($removeClient); + } + $this->_redirect('/client'); + } + + public function editclientAction() + { + if (!isset($_POST["add"])){ + $clientID = $this->_request->getParam('clientID'); + $data = new Application_Model_Client(); + $mapper = new Application_Model_ClientMapper(); + $mapper->find($clientID,$data); + + $editclient = new Application_Form_Client(); + $editclient->populate($data->toArray()); + $this->view->editclient = $editclient; + } + else{ + $addfilterform = new Application_Form_Client($_POST); + if ($addfilterform->isValid($_POST) || ($mac != '' && $hh != '') ) { + $client = new Application_Model_Client($_POST); + $client->setID($this->_request->getParam('clientID')); + $clientmapper = new Application_Model_ClientMapper(); + $clientmapper->save($client); + print_a('updated'); + $this->_redirect('/client'); + } + else{ + print_a('no update'); + } } - $this->_redirect('/client'); } @@ -52,3 +91,5 @@ class ClientController extends Zend_Controller_Action + + diff --git a/application/controllers/FilterController.php b/application/controllers/FilterController.php index 3f9a49d..df8db07 100644 --- a/application/controllers/FilterController.php +++ b/application/controllers/FilterController.php @@ -265,6 +265,7 @@ class FilterController extends Zend_Controller_Action ######################################################### // IP Adress $filtertypID = 1; + // get it from session_table with session_id from the session $ipAdress = "111.10.10.10"; $ipAdress = str_replace(".","",$this->fillIP($ipAdress)); $select = $db->select() @@ -285,6 +286,7 @@ class FilterController extends Zend_Controller_Action ######################################################### // Mac range $filtertypID = 2; + // get it from session_table with session_id from the session $macAdress = "00:1e:0b:27:f4:99"; $macAdress = str_replace(":","",$this->fillMac($ipAdress)); $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE @@ -300,30 +302,45 @@ class FilterController extends Zend_Controller_Action ######################################################### // PoolID $filtertypID = 3; + // get PoolID from client_ID from session_id from the session + $poolid = 1; + $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE + filtertypeID = ".$filtertypID." AND + filtervalue = '.$poolid.' "); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + if($showPartResults) + print_a('poolID',$result,$set[$filtertypID]); /* If client comes from a specific pool */ ######################################################### // ClientID $filtertypID = 8; + // get client_ID from session_id from the session /* If client is a specific client */ ######################################################### // BootIsoID $filtertypID = 4; + // get BootIsoID from client_ID from session_id from the session /* WHERE bootiso = bootiso */ ######################################################### // MembershipID $filtertypID = 5; + // get membership from the session /* user is in a defined membership */ ######################################################### // GroupID $filtertypID = 6; + // get membership from the session /* user is in a defined groupID */ diff --git a/application/forms/Client.php b/application/forms/Client.php new file mode 100644 index 0000000..1378349 --- /dev/null +++ b/application/forms/Client.php @@ -0,0 +1,37 @@ +<?php + +class Application_Form_Client extends Zend_Form +{ + + public function init() + { + $this->setName("pool"); + $this->setMethod('post'); + + $this->addElement('text', 'macadress', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'label' => 'MacAdress:', + )); + $this->addElement('text', 'hardwarehash', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'label' => 'Hardwarehash:', + )); + + $this->addElement('submit', 'add', array( + 'required' => false, + 'ignore' => true, + 'label' => 'Save', + )); + } + + +} + diff --git a/application/views/scripts/client/addclient.phtml b/application/views/scripts/client/addclient.phtml index 9d1c04e..e5b0bcf 100644 --- a/application/views/scripts/client/addclient.phtml +++ b/application/views/scripts/client/addclient.phtml @@ -1 +1,3 @@ -<br /><br /><center>View script for controller <b>Client</b> and script/action name <b>addclient</b></center>
\ No newline at end of file +<?php + +echo $this->addclient; diff --git a/application/views/scripts/client/editclient.phtml b/application/views/scripts/client/editclient.phtml new file mode 100644 index 0000000..94d6b34 --- /dev/null +++ b/application/views/scripts/client/editclient.phtml @@ -0,0 +1,3 @@ +<?php + +echo $this->editclient; diff --git a/application/views/scripts/client/index.phtml b/application/views/scripts/client/index.phtml index 4095a5f..0eb28b8 100644 --- a/application/views/scripts/client/index.phtml +++ b/application/views/scripts/client/index.phtml @@ -1,7 +1,13 @@ <h1>Clients</h1> <?php if ($this->clients): ?> - + <a href="<?php echo $this->url( + array( + 'controller' => 'client', + 'action' => 'addclient' + ), + 'default', + true) ?>">add client</a> <!-- A table of filters. --> <table border=1> <tr> @@ -17,6 +23,14 @@ <td><a href="<?php echo $this->url( array( 'controller' => 'client', + 'action' => 'editclient', + 'clientID' => $client->getID() + ), + 'default', + true) ?>">edit client</a></td> + <td><a href="<?php echo $this->url( + array( + 'controller' => 'client', 'action' => 'removeclient', 'clientID' => $client->getID() ), |