summaryrefslogtreecommitdiffstats
path: root/application/modules/user/controllers/ClientController.php
blob: bd111cf2a1e2defc233a8d451f0a60f9a77bc72d (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
<?php

class User_ClientController extends Zend_Controller_Action
{
	private $membership;
    public function init()
    {
        /* Initialize action controller here */
           	$membershipMapper = new Application_Model_MembershipMapper();
        	$this->membership = new Application_Model_Membership();
        	$membershipMapper->find($_SESSION['membershipID'],$this->membership);
    }

    public function indexAction()
    {
        // TODO: ACL: is he athorized to see this ?
		
		// Get the Clients which booted with a bootiso of this group		
		$result = $this->_request->getParam('result');
		switch($result){
			case "forbidden":
				echo "<div class='errorbox'>Not allowed to delete this</div>";
				break;
			case "ok":
				echo "<div class='checkbox'>Delete sucessful</div>";
				break;
			case "error":
				echo "<div class='warningbox'>There was an error deleting</div>";
				break;
		}
		$clientMapper = new Application_Model_ClientMapper();
		$clientsInGroup = $clientMapper->findBy('groupID',$this->membership->getGroupID());
		# print_a($clientsInGroup);
				
        $this->view->clients = $clientsInGroup;
        
    }

    public function addclientAction()
    {
        // action body
    }

    public function removeclientAction()
    {
    	 $clientID = $this->_request->getParam('clientID');
		// TODO: ACL: is he authorized to delete clients?
		$clientMapper = new Application_Model_ClientMapper();
		if(is_numeric($clientID)){
			$client = new Application_Model_Client();
			$clientMapper->find($clientID,$client);
			// TODO: ACL: Is He authorized to delete
			if($client->getGroupID() == $this->membership->getGroupID()){
				$clientMapper = new Application_Model_ClientMapper();
				$clientMapper->delete($client);
				$this->_redirect('/user/client/index/result/ok');
			}
			else{
				$this->_redirect('/user/client/index/result/forbidden');
			}
		}
		$this->_redirect('/user/client/index/result/error');
        // action body
    }

    public function editclientAction()
    {
        // action body
    }


}