diff options
Diffstat (limited to 'application/controllers/ClientController.php')
| -rw-r--r-- | application/controllers/ClientController.php | 89 |
1 files changed, 65 insertions, 24 deletions
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 + + |
