diff options
9 files changed, 243 insertions, 152 deletions
diff --git a/.zfproject.xml b/.zfproject.xml index da3638e..7b8e6d9 100644 --- a/.zfproject.xml +++ b/.zfproject.xml @@ -112,6 +112,7 @@ <actionMethod actionName="edit"/> <actionMethod actionName="request"/> <actionMethod actionName="leave"/> + <actionMethod actionName="selectMembership"/> </controllerFile> <controllerFile controllerName="Group"> <actionMethod actionName="index"/> @@ -166,6 +167,7 @@ <formFile formName="Register"/> <formFile formName="RecoverPassword"/> <formFile formName="NewPassword"/> + <formFile formName="MembershipSelect"/> </formsDirectory> <layoutsDirectory enabled="false"/> <modelsDirectory> @@ -269,6 +271,8 @@ <viewControllerScriptsDirectory forControllerName="Person"> <viewScriptFile forActionName="request"/> </viewControllerScriptsDirectory> + <viewControllerScriptsDirectory forControllerName="Group"> + <viewScriptFile forActionName="select"/> </viewScriptsDirectory> <viewHelpersDirectory/> <viewFiltersDirectory/> diff --git a/application/modules/user/controllers/AuthController.php b/application/modules/user/controllers/AuthController.php index 4bfc093..df45b90 100644 --- a/application/modules/user/controllers/AuthController.php +++ b/application/modules/user/controllers/AuthController.php @@ -15,15 +15,7 @@ class User_AuthController extends Zend_Controller_Action public function indexAction() { - $membershipID = $this->_request->getParam('membershipID'); - if($membershipID == ''){ - $_SESSION['membershipID'] = 1; - } - else{ - $_SESSION['membershipID'] = $membershipID; - } - $pbsNotifier = new Pbs_Notifier(); - echo $pbsNotifier->notify("membershipID is set to ".$_SESSION['membershipID'],'ok'); + } public function loginAction() @@ -64,7 +56,7 @@ class User_AuthController extends Zend_Controller_Action $date = new DateTime(); $person->setLogindate($date->getTimestamp()); $this->personmapper->save($person); - $this->_redirect('/user/'); + $this->_helper->redirector('selectmembership', 'person'); return; } else { echo "Wrong Email or Password."; diff --git a/application/modules/user/controllers/ClientController.php b/application/modules/user/controllers/ClientController.php index d3d7573..30ac2f7 100644 --- a/application/modules/user/controllers/ClientController.php +++ b/application/modules/user/controllers/ClientController.php @@ -5,14 +5,15 @@ class User_ClientController extends Zend_Controller_Action private $membership; public function init() { - if($_SESSION['membershipID'] ==''){ + $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); + if($userIDsNamespace['membershipID'] ==''){ $pbsNotifier = new Pbs_Notifier(); echo $pbsNotifier->notify('No membershipID set','forbidden'); } /* Initialize action controller here */ $membershipMapper = new Application_Model_MembershipMapper(); $this->membership = new Application_Model_Membership(); - $membershipMapper->find($_SESSION['membershipID'],$this->membership); + $membershipMapper->find($userIDsNamespace['membershipID'],$this->membership); } public function indexAction() diff --git a/application/modules/user/controllers/FilterController.php b/application/modules/user/controllers/FilterController.php index d604aba..642c543 100644 --- a/application/modules/user/controllers/FilterController.php +++ b/application/modules/user/controllers/FilterController.php @@ -6,7 +6,8 @@ class User_FilterController extends Zend_Controller_Action protected $membershipMapper; public function init() { - if($_SESSION['membershipID'] ==''){ + $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); + if($userIDsNamespace['membershipID'] ==''){ $pbsNotifier = new Pbs_Notifier(); echo $pbsNotifier->notify('No membershipID set','forbidden'); } @@ -14,7 +15,7 @@ class User_FilterController extends Zend_Controller_Action $membershipMapper = new Application_Model_MembershipMapper(); $this->membership = new Application_Model_Membership(); - $membershipMapper->find($_SESSION['membershipID'],$this->membership); + $membershipMapper->find($userIDsNamespace['membershipID'],$this->membership); $this->db = Zend_Db_Table::getDefaultAdapter(); } diff --git a/application/modules/user/controllers/IndexController.php b/application/modules/user/controllers/IndexController.php index 74e1da7..e61f012 100644 --- a/application/modules/user/controllers/IndexController.php +++ b/application/modules/user/controllers/IndexController.php @@ -23,9 +23,10 @@ class User_IndexController extends Zend_Controller_Action } $this->view->links = $links; - $ggMapper = new Application_Model_GroupGroupsMapper(); - print_a('Your Parent Groups', $ggMapper->getParentGroups($_SESSION['membershipID'])); - print_a('Your Child Groups',$ggMapper->getChildGroups($_SESSION['membershipID'])); + $ggMapper = new Application_Model_GroupGroupsMapper(); + $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); + print_a('Your Parent Groups', $ggMapper->getParentGroups($userIDsNamespace['membershipID'])); + print_a('Your Child Groups',$ggMapper->getChildGroups($userIDsNamespace['membershipID'])); } } diff --git a/application/modules/user/controllers/PersonController.php b/application/modules/user/controllers/PersonController.php index 59ce707..87e492c 100644 --- a/application/modules/user/controllers/PersonController.php +++ b/application/modules/user/controllers/PersonController.php @@ -2,15 +2,23 @@ class user_PersonController extends Zend_Controller_Action { - protected $person; - protected $personmapper; - protected $membershipMapper; - protected $memberships; - protected $groupMapper; - protected $groups; - protected $groupRequestMapper; - - public function init() { + + protected $person = null; + + protected $personmapper = null; + + protected $membershipMapper = null; + + protected $memberships = null; + + protected $groupMapper = null; + + protected $groups = null; + + protected $groupRequestMapper = null; + + public function init() + { if (Zend_Auth::getInstance()->hasIdentity()) { $this->personmapper = new Application_Model_PersonMapper(); $result = $this->personmapper->findBy('email', Zend_Auth::getInstance()->getIdentity()); @@ -24,10 +32,10 @@ class user_PersonController extends Zend_Controller_Action foreach($this->memberships as $membership) { $group = $this->groupMapper->find($membership['groupID']); $this->groups[] = array ( - 'groupID' => $group->getID(), - 'title' => $group->getTitle(), - 'description' => $group->getDescription(), - 'membershipID' => $membership['membershipID'] + 'groupID' => $group->getID(), + 'title' => $group->getTitle(), + 'description' => $group->getDescription(), + 'membershipID' => $membership['membershipID'] ); } } @@ -154,6 +162,42 @@ class user_PersonController extends Zend_Controller_Action return; } } + + public function selectmembershipAction() + { + $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); + if(isset($userIDsNamespace['membershipID'])) { + $this->_redirect('/user/'); + } else { + if(isset($_POST['selectmembership'])) { + $roleSession = new Zend_Session_Namespace('userIDs'); + $roleSession->membershipID = $_POST['membershipID']; + $roleSession->personID = $this->person->getID(); + $membership = $this->membershipMapper->find($_POST['membershipID']); + $roleSession->groupID = $membership->getGroupID(); + $roleSession->roleID = $membership->getRoleID(); + $this->_redirect('/user/'); + return; + } else { + $groupMapper = new Application_Model_GroupMapper(); + $roleMapper = new Application_Model_RoleMapper(); + if(isset($this->memberships)) { + foreach($this->memberships as $membership) { + $group = $groupMapper->find($membership['groupID']); + $role = $roleMapper->find($membership['roleID']); + $membershipList[] = array( + 'membershipID' => $membership['membershipID'], + 'group' => $group->getTitle(), + 'role' => $role->getTitle() + ); + } + } + $membershipSelectForm = new user_Form_MembershipSelect(array('membershiplist' => $membershipList)); + $this->view->membershipSelectForm = $membershipSelectForm; + } + } + } + } @@ -167,3 +211,4 @@ class user_PersonController extends Zend_Controller_Action + diff --git a/application/modules/user/controllers/PoolController.php b/application/modules/user/controllers/PoolController.php index f2829ff..6ec8aa7 100644 --- a/application/modules/user/controllers/PoolController.php +++ b/application/modules/user/controllers/PoolController.php @@ -3,23 +3,24 @@ class User_PoolController extends Zend_Controller_Action { private $membership; - public function init() - { - if($_SESSION['membershipID'] ==''){ + public function init() + { + $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); + if($userIDsNamespace['membershipID'] ==''){ $pbsNotifier = new Pbs_Notifier(); echo $pbsNotifier->notify('No membershipID set','forbidden'); } - + $membershipMapper = new Application_Model_MembershipMapper(); $this->membership = new Application_Model_Membership(); - $membershipMapper->find($_SESSION['membershipID'],$this->membership); - } + $membershipMapper->find($userIDsNamespace['membershipID'],$this->membership); + } - public function indexAction() - { - // TODO: ACL: is he allowed to see the pools of a group - - $result = $this->_request->getParam('deleteresult'); + public function indexAction() + { + // TODO: ACL: is he allowed to see the pools of a group + + $result = $this->_request->getParam('deleteresult'); if($result != ""){ $pbsNotifier = new Pbs_Notifier(); $this->view->notification = $pbsNotifier->notify('delete',$result); @@ -44,90 +45,90 @@ class User_PoolController extends Zend_Controller_Action $pbsNotifier = new Pbs_Notifier(); $this->view->notification = $pbsNotifier->notify('unlink',$result); } - + // get all pools from this group - $poolMapper = new Application_Model_PoolMapper(); - $pools = $poolMapper->findBy('groupID',$this->membership->getGroupID()); - foreach($pools as $pool){ + $poolMapper = new Application_Model_PoolMapper(); + $pools = $poolMapper->findBy('groupID',$this->membership->getGroupID()); + foreach($pools as $pool){ $ff = new Application_Model_Pool(); $ff->setOptions($pool); $ff->setID($pool['poolID']); $yourpools[] = $ff; } - $this->view->pools = $yourpools; - + $this->view->pools = $yourpools; + // Get all Clients from this group $clientmapper = new Application_Model_ClientMapper(); $clientsArray = $clientmapper->findBy('groupID',$this->membership->getGroupID()); - + // Get all assigned Clients $assignedclientmapper = new Application_Model_PoolEntriesMapper(); $assignedclients = $assignedclientmapper->fetchAll(); foreach($assignedclients as $c){ $assignedclientsArray[] = $c->toArray(); } - + // extract the un-assigned clients from the clientlist of the group $freeclients = $this->arrayDiff($clientsArray,$assignedclientsArray); - - - $this->view->freeclients = $freeclients; - } - public function createpoolAction() - { - // TODO: ACL: is he allowed to create a pool? - if (!isset($_POST["add"])){ - $addfilterform = new user_Form_Pool(array('buttontext' => 'Create Pool')); - $this->view->addpool = $addfilterform; + + $this->view->freeclients = $freeclients; + } + + public function createpoolAction() + { + // TODO: ACL: is he allowed to create a pool? + if (!isset($_POST["add"])){ + $addfilterform = new user_Form_Pool(array('buttontext' => 'Create Pool')); + $this->view->addpool = $addfilterform; }else { $addpoolform = new user_Form_Pool(array('buttontext' => 'Create Pool'),$_POST); - if ($addpoolform->isValid($_POST)) { + if ($addpoolform->isValid($_POST)) { try{ $pool = new Application_Model_Pool($_POST); $pool->setGroupID($this->membership->getGroupID()); $poolmapper = new Application_Model_PoolMapper(); $poolmapper->save($pool); $this->_redirect('/dev/pool/index/addresult/ok'); - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - $this->_redirect('/dev/pool/index/addresult/error'); - } + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + $this->_redirect('/dev/pool/index/addresult/error'); + } } - $this->view->addpool = $addpoolform; + $this->view->addpool = $addpoolform; } - } + } - public function deletepoolAction() - { - $poolID = $this->_request->getParam('poolID'); + public function deletepoolAction() + { + $poolID = $this->_request->getParam('poolID'); // TODO: ACL: is he allowed to delete a pool? #if( he is allowed){ - if(is_numeric($poolID)){ - $poolmapper = new Application_Model_PoolMapper(); - $pool = new Application_Model_Pool(); - $poolmapper->find($poolID,$pool); - if($this->membership->getGroupID() == $pool->getGroupID()){ - $deletepool = new Application_Model_Pool(); - $deletepool->setID($poolID); - $poolmapper->delete($deletepool); - $this->_redirect('/user/pool/index/deleteresult/ok'); - } - else{ - $this->_redirect('/user/pool/index/deleteresult/forbidden'); - } - } - $this->_redirect('/user/pool/index/deleteresult/error'); + if(is_numeric($poolID)){ + $poolmapper = new Application_Model_PoolMapper(); + $pool = new Application_Model_Pool(); + $poolmapper->find($poolID,$pool); + if($this->membership->getGroupID() == $pool->getGroupID()){ + $deletepool = new Application_Model_Pool(); + $deletepool->setID($poolID); + $poolmapper->delete($deletepool); + $this->_redirect('/user/pool/index/deleteresult/ok'); + } + else{ + $this->_redirect('/user/pool/index/deleteresult/forbidden'); + } + } + $this->_redirect('/user/pool/index/deleteresult/error'); #}else{ # $this->_redirect('/user/'); #} - } + } - public function editpoolAction() - { - // TODO: ACL: is he allowed to edit a pool? - if (!isset($_POST["add"])){ - $poolID = $this->_request->getParam('poolID'); + public function editpoolAction() + { + // TODO: ACL: is he allowed to edit a pool? + if (!isset($_POST["add"])){ + $poolID = $this->_request->getParam('poolID'); $pool = new Application_Model_Pool(); $poolmapper = new Application_Model_PoolMapper(); $poolmapper->find($poolID,$pool); @@ -139,55 +140,55 @@ class User_PoolController extends Zend_Controller_Action } else{ $this->_redirect('/user/pool/index/modifyresult/forbidden'); - } + } }else { $editpoolform = new user_Form_Pool(array('buttontext' => 'Edit Pool'),$_POST); - if ($editpoolform->isValid($_POST)) { + if ($editpoolform->isValid($_POST)) { try{ $poolmapper = new Application_Model_PoolMapper(); $poolID = $this->_request->getParam('poolID'); $pooldb = new Application_Model_Pool(); $poolmapper->find($poolID,$pooldb); print_a($pooldb->getGroupID(), $this->membership->getGroupID()); - if($pooldb->getGroupID() == $this->membership->getGroupID()){ + if($pooldb->getGroupID() == $this->membership->getGroupID()){ $pool = new Application_Model_Pool($_POST); - $pool->setID($poolID); - $pool->setGroupID($this->membership->getGroupID()); + $pool->setID($poolID); + $pool->setGroupID($this->membership->getGroupID()); $poolmapper->save($pool); - $this->_redirect('/user/pool/index/modifyresult/ok'); - } + $this->_redirect('/user/pool/index/modifyresult/ok'); + } else{ $this->_redirect('/user/pool/index/modifyresult/forbidden'); - } - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - $this->_redirect('/user/pool/index/modifyresult/error'); - } + } + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + $this->_redirect('/user/pool/index/modifyresult/error'); + } } $this->view->editpool = $editpoolform; } - } + } - public function linkclientAction() - { - $clientID = $this->_request->getParam('clientID'); + public function linkclientAction() + { + $clientID = $this->_request->getParam('clientID'); $poolID = $this->_request->getParam('poolID'); - + // TODO: ACL: Is he allowed to link clients to pools? if(!isset($_POST['clientID']) && ($clientID == '')){ $clientmapper = new Application_Model_ClientMapper(); - $clients = $clientmapper->findBy('groupID',$this->membership->getGroupID()); + $clients = $clientmapper->findBy('groupID',$this->membership->getGroupID()); $assignedclientmapper = new Application_Model_PoolEntriesMapper(); $assignedclients = $assignedclientmapper->fetchAll(); foreach($assignedclients as $c){ $assignedclientsArray[] = $c->toArray(); - } + } $freeclients = $this->arrayDiff($clients,$assignedclientsArray); - - $poolclient = new user_Form_PoolClient(array('buttontext' => 'Link Client','clients'=> $freeclients)); + + $poolclient = new user_Form_PoolClient(array('buttontext' => 'Link Client','clients'=> $freeclients)); $this->view->poolclient = $poolclient; - }else { - $poolclient = new dev_Form_PoolClient(array('buttontext' => 'Link Client'),$_POST); + }else { + $poolclient = new dev_Form_PoolClient(array('buttontext' => 'Link Client'),$_POST); try{ $poolID = $this->_request->getParam('poolID'); $poolmapper = new Application_Model_PoolMapper(); @@ -195,49 +196,49 @@ class User_PoolController extends Zend_Controller_Action $poolmapper->find($poolID,$pooldb); $clientmapper = new Application_Model_ClientMapper(); $clientdb = new Application_Model_Client(); - $clientmapper->find($clientID,$clientdb); - + $clientmapper->find($clientID,$clientdb); + if($pooldb->getGroupID() == $this->membership->getGroupID() && $clientdb->getGroupID() == $this->membership->getGroupID()){ - $poolentriesmapper = new Application_Model_PoolEntriesMapper(); + $poolentriesmapper = new Application_Model_PoolEntriesMapper(); $poolentry = new Application_Model_PoolEntries($_POST); $poolentry->setPoolID($poolID); if($poolentry->getClientID() == ''){ $poolentry->setClientID($clientID); - } + } $poolentriesmapper->save($poolentry); - $this->_redirect('/user/pool/index/linkresult/ok'); + $this->_redirect('/user/pool/index/linkresult/ok'); } else{ - $this->_redirect('/user/pool/index/linkresult/forbidden'); - } - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - $this->_redirect('/user/pool/index/linkresult/error'); - } - $this->view->poolclient = $poolclient; + $this->_redirect('/user/pool/index/linkresult/forbidden'); + } + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + $this->_redirect('/user/pool/index/linkresult/error'); + } + $this->view->poolclient = $poolclient; } - } + } - public function unlinkclientAction() - { - $poolentriesID = $this->_request->getParam('poolentriesID'); - - // TODO: ACL: Is he allowed to unlink clients from pools? - if(is_numeric($poolentriesID)){ - $poolentriesMapper = new Application_Model_PoolEntriesMapper(); - $poolentry = new Application_Model_PoolEntries(); - $poolentriesMapper->find($poolentriesID,$poolentry); - $clientMapper = new Application_Model_ClientMapper(); - $client = new Application_Model_Client(); - - $poolMapper = new Application_Model_PoolMapper(); - $pool = new Application_Model_Pool(); - - $clientMapper->find($poolentry->getClientID(),$client); - $poolMapper->find($poolentry->getPoolID(),$pool); - - - if($pool->getGroupID() == $this->membership->getGroupID() && $client->getGroupID() == $this->membership->getGroupID()){ + public function unlinkclientAction() + { + $poolentriesID = $this->_request->getParam('poolentriesID'); + + // TODO: ACL: Is he allowed to unlink clients from pools? + if(is_numeric($poolentriesID)){ + $poolentriesMapper = new Application_Model_PoolEntriesMapper(); + $poolentry = new Application_Model_PoolEntries(); + $poolentriesMapper->find($poolentriesID,$poolentry); + $clientMapper = new Application_Model_ClientMapper(); + $client = new Application_Model_Client(); + + $poolMapper = new Application_Model_PoolMapper(); + $pool = new Application_Model_Pool(); + + $clientMapper->find($poolentry->getClientID(),$client); + $poolMapper->find($poolentry->getPoolID(),$pool); + + + if($pool->getGroupID() == $this->membership->getGroupID() && $client->getGroupID() == $this->membership->getGroupID()){ $deletepoolentries = new Application_Model_PoolEntries(); $deletepoolentries->setID($poolentriesID); $deletepoolentriesmapper = new Application_Model_PoolEntriesMapper(); @@ -251,12 +252,12 @@ class User_PoolController extends Zend_Controller_Action else{ $this->_redirect('/user/pool/index/unlinkresult/error'); } - } - - // creates an array of two arrays - // first parameter is the list of all clients - // second parameter is the list of clients which are already in a group - // return value is a list of all clients, which are in no group + } + + // creates an array of two arrays + // first parameter is the list of all clients + // second parameter is the list of clients which are already in a group + // return value is a list of all clients, which are in no group private function arrayDiff($a, $b){ foreach($a as $k1 => $i1){ foreach($b as $k2 => $i2){ diff --git a/application/modules/user/forms/MembershipSelect.php b/application/modules/user/forms/MembershipSelect.php new file mode 100644 index 0000000..fbf8b8a --- /dev/null +++ b/application/modules/user/forms/MembershipSelect.php @@ -0,0 +1,42 @@ +<?php + +class user_Form_MembershipSelect extends Zend_Form +{ + private $membershiplist; + + public function setMembershiplist($membershiplist){ + $this->membershiplist = $membershiplist; + + } + + public function getMembershiplist(){ + return $this->membershiplist; + } + + public function init() + { + $this->setName("MembershipSelect"); + $this->setMethod('post'); + + $membershipfield = $this->createElement('select','membershipID'); + $membershipfield ->setLabel('Membership:'); + + if(count($this->membershiplist)>0){ + foreach($this->membershiplist as $membership => $m){ + $membershipfield->addMultiOption($m['membershipID'], $m['group'] . ' - ' . $m['role']); + } + } + + $membershipfield->setRegisterInArrayValidator(false); + $this->addElement($membershipfield); + + $this->addElement('submit', 'selectmembership', array( + 'required' => false, + 'ignore' => true, + 'label' => 'Select Group', + )); + } + + +} + diff --git a/application/modules/user/views/scripts/person/selectmembership.phtml b/application/modules/user/views/scripts/person/selectmembership.phtml new file mode 100644 index 0000000..2bfe4d6 --- /dev/null +++ b/application/modules/user/views/scripts/person/selectmembership.phtml @@ -0,0 +1,4 @@ +<?php +$this->membershipSelectForm->setAction($this->url()); +echo $this->membershipSelectForm; +?>
\ No newline at end of file |