summaryrefslogtreecommitdiffstats
path: root/application/modules/user/controllers/ConfigController.php
blob: 83ff804bf5e2680b7008b0a4412f26071719514e (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php

class user_ConfigController extends Zend_Controller_Action
{

	protected $configMapper;
	protected $membershipMapper;
	protected $membership;
	protected $page;
	
    public function init()
    {
        if (Zend_Auth::getInstance()->hasIdentity()) {
			$userIDsNamespace = Zend_Session::namespaceGet('userIDs');
			if($userIDsNamespace['membershipID'] ==''){
				$this->_redirect('/user/index');
			}
			
			$this->configMapper = new Application_Model_ConfigMapper();
			
			$this->membershipMapper = new Application_Model_MembershipMapper();
			$this->membership = new Application_Model_Membership();
			$this->membershipMapper->find($userIDsNamespace['membershipID'],$this->membership);

			$this->db = Zend_Db_Table::getDefaultAdapter();
		} else {
			$this->_helper->redirector('login', 'auth');
		}
		$this->page = $this->_request->getParam('page');   	}

    public function indexAction()
    {
        $result = $this->_request->getParam('addresult');
		if($result != ""){
			$pbsNotifier = new Pbs_Notifier();
			$this->view->notification = $pbsNotifier->notify('create',$result);
		}
		$result = $this->_request->getParam('deleteresult');
		if($result != ""){
			$pbsNotifier = new Pbs_Notifier();
			$this->view->notification = $pbsNotifier->notify('delete',$result);
		}
		$result = $this->_request->getParam('modifyresult');
		if($result != ""){
			$pbsNotifier = new Pbs_Notifier();
			$this->view->notification = $pbsNotifier->notify('modify',$result);
		}
		
		$groupID = $this->membership->getGroupID();  
		
		//TODO ACL Darf er Configs sehen?
    	if(false)
    		$this->_redirect('/user/index');
		
    	$this->configMapper = new Application_Model_ConfigMapper();	
    	$groupMapper = new Application_Model_GroupMapper();    	
    	
    	if(true){    		
	    	//TODO nur Configs von Admins
	    	$this->view->configlist = $this->configMapper->findBy(array('groupID' => $this->membership->getGroupID()));
	    }else{	
	    	$this->view->configlist = $this->configMapper->findBy(array('membershipID' => $this->membership->getID()));
	    }	
	    
        foreach ($this->view->configlist as $config){
    		$config->setGroupID("[".$config->getGroupID()."] ".$groupMapper->find($config->getGroupID())->getTitle());
    	}
    	
    	// Pagination
	    $pagination = new Pbs_Pagination();	
		$pagination->setPerPage(2);		
		$pagination->setElement($this->view->configlist);
		$pagination->setRequestPage($this->_request->getParam('page'));		
		$pagination->setPageUrl('/user/config/index'.((isset($this->view->search))?'/search/'.$this->view->search:''));
		$this->view->configlist = $pagination->getElements();		
		
		$this->view->pagination = $pagination->pagination($pageurl);
		$this->view->page 		= $pagination->getRequestPage();
		$this->view->configlist = $this->view->configlist;    	 	    	
    		     	
    }

    public function createconfigAction()
    {
    	//TODO ACL Darf er Configs erstellen?
    	if(false)
    		$this->_redirect('/user/config/index/page/'.$this->page.'/addresult/forbidden');
    		
        if (!isset($_POST["createconfig"])){
    	        $configForm = new user_Form_Config(array('action' => 'createconfig','rights' => null,'page'=>$this->page));
    		} else {
    	        $configForm = new user_Form_Config(array('action' => 'createconfig','rights' => null,'page'=>$this->page),$_POST);
    			    			
    		    if ($configForm->isValid($_POST)) {

    		    	$config = new Application_Model_Config($_POST);
    		    	$config->setCreated(time());
    		    	$config->setMembershipID($this->membership->getID());
    		    	$config->setGroupID($this->membership->getGroupID());    	
    		    	    		        
    		    	try {  
    		            $this->configMapper->save($config);
     		        }catch(Zend_Exception $e)
    		        {
    		            echo "Caught exception: " . get_class($e) . "<br/>";
    					echo "Message: " . $e->getMessage() . "<br/>";
    					$this->_redirect('/user/config/index/page/'.$this->page.'/addresult/error');    					
    		        }    		        
					$this->_redirect('/user/config/index/page/'.$this->page.'/addresult/ok');
    		     }
    		}
    
            $this->view->configForm = $configForm;
    }

    public function editconfigAction()
    {
    	//TODO ACL Darf er Configs editieren?
    	if(false)
    		$this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/forbidden');
    	
    	$configID = $this->_request->getParam('configID'); 
    	if (!is_numeric($configID))
   			$this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/error');
   			
    	$groupID = $this->membership->getGroupID();
    	
    	$config = new Application_Model_Config();
    	$this->configMapper->find($configID, $config);
    	
    	if($config->getMembershipID() != null){
    		if($this->membership->getID() != $config->getMembershipID())
    			$this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/forbidden');
    	}else{
    		if($this->membership->getGroupID() != $config->getGroupID())
    			$this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/forbidden');
    	}
    	        
    	if (!isset($_POST["editconfig"])){

    		$configForm = new user_Form_Config(array('action' => 'editconfig','rights' => 'meta','page'=>$this->page));
    		$configForm->populate($config->toArray()); 
    	
    	}else{
    		$configForm = new user_Form_Config(array('action' => 'editconfig','rights' => 'meta','page'=>$this->page),$_POST);
    			    			
    		if ($configForm->isValid($_POST)) {

    			$configold = $config;
    			
    			$config = new Application_Model_Config($_POST); 	
    		    $config->setCreated(time());
    		    $config->setMembershipID($this->membership->getID());
    		    $config->setGroupID($this->membership->getGroupID());
    		    $config->setID($configID);
    		    
    		    if($configold->getShellscript() != $config->getShellscript()){
    		    	//TODO ACL Is he allowed to edit other than Metadata?
	    			if(false)
	    				$this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/forbidden');
    		    }
	    
    		    
    		   	try {  
    		       	$this->configMapper->save($config);
    		    }catch(Zend_Exception $e)
    		    {
    		    	echo "Caught exception: " . get_class($e) . "<br/>";
    				echo "Message: " . $e->getMessage() . "<br/>";	
    				$this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/error');
    		    }
    		    
				$this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/ok');	
    		}
    			
    	}
    	
    	$this->view->configForm = $configForm;
    }

    public function deleteconfigAction()
    {
    	//TODO ACL Darf er Configs löschen?
    	if(false)
    		$this->_redirect('/user/config/index/page/'.$this->page.'/deleteresult/forbidden');
    		
    	try{
    		$configID = $this->_request->getParam('configID');
	     	if (!is_numeric($configID))
	   			$this->_redirect('/user/config/index/page/'.$this->page.'/deleteresult/error');
		   		
	    	$config = new Application_Model_Config();
	    	$this->configMapper->find($configID,$config);
	    	
	    	if($config->getMembershipID() != null){
	    		if($this->membership->getID() != $config->getMembershipID())
		   			$this->_redirect('/user/config/index/page/'.$this->page.'/deleteresult/forbidden');
	    	}else{
	   			if($this->membership->getGroupID() != $config->getGroupID())
		   			$this->_redirect('/user/config/index/page/'.$this->page.'/deleteresult/forbidden');
	    	}
	    	
	    	$this->configMapper->delete($config);
    	
    	}catch(Zend_Exception $e){
    		echo "Caught exception: " . get_class($e) . "<br/>";
    		echo "Message: " . $e->getMessage() . "<br/>";
    		$this->_redirect('/user/config/index/page/'.$this->page.'/deleteresult/error');	
    	}
	   		$this->_redirect('/user/config/index/page/'.$this->page.'/deleteresult/ok');
    }


}