summaryrefslogblamecommitdiffstats
path: root/application/controllers/PersonController.php
blob: 981a2003fa207c9a8339849a5ff24bd010c4f886 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14













                                                                           
                                 
                                           
                                            
                                      
                                           

                            



                                                              
                                                                      

                                                                        
                                                                                        



                                                                                           
                                                            
                                                                                        




                                                                                                                                                                                                                                        













                                                                                                                        
                         
 

                                                                            
                                                                                            
                                                                                                                                                                                                                                         



                                                                                                  




                                                                                                                     
                                                                         



                                                                                                              

                                                  
                                                                        










                                                                    
                                                        








                                                                                      
                                                            
                                                                      



                                                                                           
                                                                               
                                                                               


                                                                       
                                                                                             
                                                                                                            
                                                                                            
                                                                                            
                                                                                          
                                                                                        
                                                                                        


                                                              
                                                                       

                                                                                            

                                                                                                                                                                                                                                                         

                                                                                                       
                                                                                                                  
                                                                                                       


                                                                                                                                     

                                                                                                  

                                                                                                                                      



                                                                                               

                                                                                                                                      

                                                                          
 




                                                                                                                                                                                          





                                                                                                                                                  
                                                                        
                                                                                                                                           












                                                                         
<?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');
			$this->membershipMapper = new Application_Model_MembershipMapper();
			$this->currentMembership = new Application_Model_Membership();
			$this->person = new Application_Model_Person();
			$this->memberships = Zend_Session::namespaceGet('memberships');
			if(count($this->userIDsNamespace)) {
				$membershipID = $this->userIDsNamespace['membershipID'];
				$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->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));
				}
			}

			if(isset($this->memberships)) {
				foreach($this->memberships as $membership) {
					$grouprequest = "groupid=" . $membership['groupID'];
					$groupApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getgroup'] . $membership['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $grouprequest);
					$groupXMLString = $groupApiResult['http-body'];
					if(strlen($groupXMLString) > 0) {
						$groupXML = new SimpleXMLElement($groupXMLString);
						$group = new Application_Model_Group();
						$group->setID(sprintf("%s", $groupXML->group->id));
						$group->setTitle(sprintf("%s", $groupXML->group->title));
						$group->setDescription(sprintf("%s", $groupXML->group->description));

						$apikeys[$group->getID()] = $membership['apikey'];
						$this->groups[] = array (
                        					'groupID'  => $group->getID(),	
                        					'title' => $group->getTitle(),
                        					'description' => $group->getDescription(),
                        					'membershipID' => $membership['membershipID'],
						);
					}
					$this->view->apikeys = $apikeys;
				}
			}
		} else {
			$this->_helper->redirector('login', 'auth');
			return;
		}
	}

	public function indexAction()
	{
		$this->view->person = $this->person;
		$this->view->pbs2host = $this->pbs2host;
		$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->roleID = $myMembership['roleID'];
				$userSession->apikey = $myMembership['apikey'];
				$this->_redirect('/');
			} elseif(count($this->memberships) > 1) {
				if(isset($_POST['selectmembership'])) {
					$userSession = new Zend_Session_Namespace('userIDs');
					$membership = $this->membershipMapper->find($_POST['membershipID']);
					$userSession->membershipID = $_POST['membershipID'];
					$userSession->personID = $membership->getPersonID();
					$userSession->groupID = $membership->getGroupID();
					$userSession->roleID = $membership->getRoleID();
					$userSession->apikey = $membership->getApikey();
					$this->_redirect('/');
					return;
				} else {
					if(isset($this->memberships)) {
						$suspendlist = array();
						foreach($this->memberships as $membership) {
							$grouprequest = "groupid=" . $membership['groupID'];
							$groupApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getgroup'] . $membership['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $grouprequest);
							$groupXMLString = $groupApiResult['http-body'];
							if(strlen($groupXMLString) > 0) {
								$groupXML = new SimpleXMLElement($groupXMLString);
								$group = new Application_Model_Group();
								$group->setID(sprintf("%s", $groupXML->group->id));
								$group->setTitle(sprintf("%s", $groupXML->group->title));
								$group->setDescription(sprintf("%s", $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;
	}
}