summaryrefslogtreecommitdiffstats
path: root/application/controllers/PoolController.php
blob: 27e81a341870bc43214b82508f89b842b7770d71 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php

class PoolController extends Zend_Controller_Action
{

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

    public function indexAction()
    {
        $poolMapper = new Application_Model_PoolMapper();
        $this->view->pools = $poolMapper->fetchAll();
    }

    public function createpoolAction()
    {
		if (!isset($_POST["add"])){
    		$addfilterform = new Application_Form_Pool();    		
			$this->view->addpool = $addfilterform;		
		}else {
			$addpoolform = new Application_Form_Pool($_POST);
			if ($addpoolform->isValid($_POST)) {			
				try{
					$pool = new Application_Model_Pool($_POST);
					$poolmapper = new Application_Model_PoolMapper();
					$poolmapper->save($pool);
					$this->_redirect('/pool');
			    	return;
				}catch (Zend_Exception $e) {  
        			echo "Error message 2: " . $e->getMessage() . "\n";  
        		}
			}
		}
    }

    public function deletepoolAction()
    {
       $poolID = $this->_request->getParam('poolID');
		// TODO: ACL implementieren ob er den pool löschen darf
		if(is_numeric($poolID)){
			$deletepool = new Application_Model_Pool();
			$deletepool->setID($poolID);
			$poolmapper = new Application_Model_PoolMapper();
			$poolmapper->delete($deletepool);
		}
		$this->_redirect('/pool');
    }

    public function editpoolAction()
    {
       	if (!isset($_POST["add"])){
			$poolID = $this->_request->getParam('poolID');

			$pool = new Application_Model_Pool();
			$poolmapper = new Application_Model_PoolMapper();
			$poolmapper->find($poolID,$pool);		
			$poolArray = $pool->toArray();

			$editpool = new Application_Form_Pool();  
			$editpool->populate($poolArray);
			$this->view->editpoolform = $editpool;
		
		}else {
			$addpoolform = new Application_Form_Pool($_POST);
			if ($addpoolform->isValid($_POST)) {			
				try{
					$pool = new Application_Model_Pool($_POST);
					$pool->setID($this->_request->getParam('poolID'));
					$poolmapper = new Application_Model_PoolMapper();
					$poolmapper->save($pool);
					$this->_redirect('/pool');			    	
				}catch (Zend_Exception $e) {  
        			echo "Error message 2: " . $e->getMessage() . "\n";  
        		}
			}
		}
    }

    public function linkclientAction()
    {
        // action body
    }

    public function unlinkclientAction()
    {
        $poolentriesID = $this->_request->getParam('poolentriesID');

			// TODO: ACL implementieren ob er den filter löschen darf
			if(is_numeric($poolentriesID)){
				$deletepoolentries = new Application_Model_PoolEntries();
				$deletepoolentries->setID($poolentriesID);
				echo "<pre style='border:1px solid black;background-color:#F5B800'>";
				print_r($deletepoolentries);
				echo "</pre>";

				$deletepoolentriesmapper = new Application_Model_PoolEntriesMapper();
				$deletepoolentriesmapper->delete($deletepoolentries);
				echo "ok";
			}
#			echo "ready";
			$this->_redirect('/pool');
    }


}