summaryrefslogtreecommitdiffstats
path: root/application/controllers/ClientController.php
blob: ff663ba53103dc3fecc6a43734878c4f35e4b989 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php

class ClientController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $clientMapper = new Application_Model_ClientMapper();
        $this->view->clients = $clientMapper->fetchAll();
    }

    public function addclientAction()
    {	
			$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);
        		}
        		$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');
			}
		}
    }


}