summaryrefslogblamecommitdiffstats
path: root/application/controllers/PersonController.php
blob: 75bec622cc6314be6575bff4ac2a74853ac68bfa (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 $currentMembership = null;
	protected $memberships = null;
	protected $groups = null;
	protected $userIDsNamespace = null;
	protected $config;
	protected $pbs2host;
	protected $acl;

	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(isset($this->userIDsNamespace['apikey'])) {
				$this->acl = new Poolctrl_Acl($this->pbs2host, $this->config['pbs2']['checkright'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
			}
			foreach(Zend_Session::namespaceGet('persons') as $person) {
				if($person->getID() == $this->userIDsNamespace['personID']) {
					$this->person = $person;
					break;
				}
			}
			foreach(Zend_Session::namespaceGet('memberships') as $membership) {
				$this->memberships[$membership->getID()] = $membership;
			}
			if(count($this->memberships) > 0) {
				if(isset($this->userIDsNamespace['membershipID'])) {
					$membershipID = $this->userIDsNamespace['membershipID'];
					$personNamesapce = Zend_Session::namespaceGet('memberships');
					if($membershipID) {
						$this->currentMembership = $this->memberships[$membershipID];
					}
				}
				if(count(Zend_Session::namespaceGet('groups')) > 0) {
					$useGroupnamespace = true;
					foreach(Zend_Session::namespaceGet('groups') as $group) {
						$groups[$group->getID()] = $group;
					}
				} else {
					$groupSession = new Zend_Session_Namespace('groups');
					$useGroupnamespace = false;
				}
				if(count(Zend_Session::namespaceGet('roles')) > 0) {
					$useRolenamespace = true;
					foreach(Zend_Session::namespaceGet('roles') as $role) {
						$roles[$role->getID()] = $role;
					}
				} else {
					$useRolenamespace = false;
					$roleSession = new Zend_Session_Namespace('roles');
				}
				foreach($this->memberships as $membership) {
					$groupID = $membership->getGroupID();
					if($useGroupnamespace) {
						$group = $groups[$groupID];
					} else {
						$grouprequest = "groupid=" . $groupID;
						$groupApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getgroup'] . $membership->getApikey(), '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));

							$groupSession->$groupID = $group;
						}
					}
					$roleID = $membership->getRoleID();
					if($useRolenamespace) {
						$role = $roles[$roleID];
					} else {
						$roleApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getrole'] . $membership->getApikey(), 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', '');
						$roleXMLString = $roleApiResult['http-body'];
						if(strlen($roleXMLString) > 0) {
							$roleXML = new SimpleXMLElement($roleXMLString);
							$role = new Application_Model_Role();
							$role->setID(sprintf("%s", $roleXML->role->id));
							$role->setGroupID(sprintf("%s", $roleXML->role->groupid));
							$role->setTitle(sprintf("%s", $roleXML->role->title));
							$role->setDescription(sprintf("%s", $roleXML->role->description));
							$role->setInheritance(sprintf("%s", $roleXML->role->inheritance));

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

	public function indexAction()
	{
		$pagination = new Poolctrl_Pagination();
		$pagination->setPerPage(5);
		$pagination->setElement($this->groups);
		$pagination->setRequestPage($this->_request->getParam('page'));
		$pagination->setPageUrl('/person/index');
		$this->view->groups = $pagination->getElements();
		$this->view->pagination = $pagination->pagination();
		$this->view->page 		= $pagination->getRequestPage();
		$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) {
				$membership = $this->memberships[0];
				$userSession = new Zend_Session_Namespace('userIDs');
				$userSession->membershipID = $membership->getID();
				$userSession->groupID = $membership->getGroupID();
				$userSession->roleID = $membership->getRoleID();
				$userSession->apikey = $membership->getApikey();
				$this->_redirect('/');
				return;
			} elseif(count($this->memberships) > 1) {
				if(isset($_POST['selectmembership'])) {
					$membership = $this->memberships[$_POST['membershipID']];
					$userSession = new Zend_Session_Namespace('userIDs');
					$userSession->membershipID = $membership->getID();
					$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) {
							$groupData = $this->groups[$membership->getGroupID()];
							$group = new Application_Model_Group($groupData);
							$group->setID($groupData['groupID']);
							$roleTitle = $groupData['role'];
							$suspend = $membership->getSuspend();
							if($suspend == 0){
								$membershipList[] = array(
                                							'membershipID' => $membership->getID(),
                                							'group' => $group->getTitle(),
															'role' => $roleTitle,
								);
							}
							else{
								$suspendlist[] = array(
                                							'membershipID' => $membership->getID(),
                                							'group' => $group->getTitle(),
															'role' => $roleTitle,
								);
							}

							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');
		$userSession = new Zend_Session_Namespace('userIDs');
		$userSession->personID = $this->person->getID();
		$this->_helper->redirector('selectmembership', 'person');
		return;
	}
}