summaryrefslogtreecommitdiffstats
path: root/application/controllers/PersonController.php
blob: 91ced77be931143993793e3a30047219ee673d04 (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
<?php
/*
 * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg
 * This program is free software distributed under the GPL version 2.
 * See http://gpl.openslx.org/
 *
 * If you have any feedback please consult http://feedback.openslx.org/ and
 * send your suggestions, praise, or complaints to feedback@openslx.org
 *
 * General information about OpenSLX can be found at http://openslx.org/
 */

class PersonController extends Zend_Controller_Action
{
	protected $person = null;
	protected $membershipMapper = null;
	protected $currentMembership = null;
	protected $memberships = null;
	protected $userIDsNamespace = null;
	protected $config;
	protected $pbs2host;

	public function init()
	{
		if (Zend_Auth::getInstance()->hasIdentity()) {
			$bootstrap = $this->getInvokeArg('bootstrap');
			$this->config = $bootstrap->getOptions();
			$this->pbs2host = $this->config['pbs2']['host'];
			$this->userIDsNamespace = Zend_Session::namespaceGet('userIDs');
			if(is_array($this->userIDsNamespace)) {
				$membershipID = $this->userIDsNamespace['membershipID'];
				$this->currentMembership = new Application_Model_Membership();
				$this->membershipMapper = new Application_Model_MembershipMapper();
				$this->membershipMapper->find($membershipID, $this->currentMembership);
				$personApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getperson'] . $this->currentMembership->getApikey(), 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', '');
				$personXMLString = $personApiResult['http-body'];
				if(strlen($personXMLString) > 0) {
					$personXML = new SimpleXMLElement($personXMLString);
					$this->person = new Application_Model_Person();
					$this->person->setID(sprintf("%s", $personXML->person->id));
					$this->person->setCity(sprintf("%s", $personXML->person->city));
					$this->person->setEmail(sprintf("%s", $personXML->person->email));
					$this->person->setFirstname(sprintf("%s", $personXML->person->firstname));
					$this->person->setHousenumber(sprintf("%s", $personXML->person->housenumber));
					$this->person->setLogin(sprintf("%s", $personXML->person->login));
					$this->person->setLogindate(sprintf("%s", $personXML->person->logindate));
					$this->person->setName(sprintf("%s", $personXML->person->name));
					$this->person->setPostalcode(sprintf("%s", $personXML->person->postalcode));
					$this->person->setRegisterdate(sprintf("%s", $personXML->person->registerdate));
					$this->person->setStreet(sprintf("%s", $personXML->person->street));
					$this->person->setSuspend(sprintf("%s", $personXML->person->suspend));
					$this->person->setTitle(sprintf("%s", $personXML->person->title));
				}
			}

			$this->memberships = Zend_Session::namespaceGet('memberships');
			$this->view->apikeys = array();

			if(isset($this->memberships)) {
				foreach($this->memberships as $membership) {
					$groupApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getgroup'] . $membership['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', '');
					$groupXMLString = $groupApiResult['http-body'];
					if(strlen($groupXMLString) > 0) {
						$groupXML = new SimpleXMLElement($groupXMLString);
						$group = new Application_Model_Group();
						$group->setID($groupXML->group->id);
						$group->setTitle($groupXML->group->title);
						$group->setDescription($groupXML->group->description);
							
						$this->view->apikeys[$group->getID()] = $membership['apikey'];
						$this->groups[] = array (
                        					'groupID'  => $group->getID(),	
                        					'title' => $group->getTitle(),
                        					'description' => $group->getDescription(),
                        					'membershipID' => $membership['membershipID'],
						);
					}
				}
			}
		} else {
			$this->_helper->redirector('login', 'auth');
			return;
		}
	}

	public function indexAction()
	{
		$this->view->person = $this->person;
		$this->view->userIDsNamespace = Zend_Session::namespaceGet('userIDs');
	}

	public function selectmembershipAction()
	{
		$userIDsNamespace = Zend_Session::namespaceGet('userIDs');
		if(isset($userIDsNamespace['membershipID'])) {
			$this->_redirect('/');
		} else {
			if(count($this->memberships) == 1) {
				$myMembership = $this->memberships[0];
				$userSession = new Zend_Session_Namespace('userIDs');
				$userSession->membershipID = $myMembership['membershipID'];
				$userSession->personID = $myMembership['personID'];
				$userSession->groupID = $myMembership['groupID'];
				$userSession->apikey = $myMembership['apikey'];
				$this->_redirect('/');
			} elseif(count($this->memberships) > 1) {
				if(isset($_POST['selectmembership'])) {
					$userSession = new Zend_Session_Namespace('userIDs');
					$userSession->membershipID = $_POST['membershipID'];
					$userSession->personID = $this->person->getID();
					$membership = $this->membershipMapper->find($_POST['membershipID']);
					$userSession->groupID = $membership->getGroupID();
					$userSession->apikey = $membership->getApikey();
					$this->_redirect('/');
					return;
				} else {
					if(isset($this->memberships)) {
						$suspendlist = array();
						foreach($this->memberships as $membership) {
							$groupApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getgroup'] . $membership['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', '');
							$groupXMLString = $groupApiResult['http-body'];
							if(strlen($groupXMLString) > 0) {
								-$groupXML = new SimpleXMLElement($groupXMLString);
								$group = new Application_Model_Group();
								$group->setID($groupXML->group->id);
								$group->setTitle($groupXML->group->title);
								$group->setDescription($groupXML->group->description);
								if($membership['suspend'] == 0){
									$membershipList[] = array(
                                							'membershipID' => $membership['membershipID'],
                                							'group' => $group->getTitle()
									);
								}
								else{
									$suspendlist[] = array(
                                							'membershipID' => $membership['membershipID'],
                                							'group' => $group->getTitle()
									);
								}

							}
							if(count($suspendlist) >=1){
								$poolNotifier = new Poolctrl_Notifier();
								$this->view->notification = $poolNotifier->notify("Actually ".count($suspendlist)." Memberships are suspended", 'error' );
							}
						}
					}
					$membershipSelectForm = new Application_Form_MembershipSelect(array('membershiplist' => $membershipList));
					$this->view->membershipSelectForm = $membershipSelectForm;
				}
			} else {
				$poolNotifier = new Poolctrl_Notifier();
				$this->view->notification = $poolNotifier->notify("Currently you are not a member of any group", 'error' );
			}
		}
	}

	public function changemembershipAction()
	{
		$this->_helper-> viewRenderer-> setNoRender();
		Zend_Session::namespaceUnset('userIDs');
		$this->_helper->redirector('selectmembership', 'person');
		return;
	}
}