From fb9e5f028899f8205541fe86d7eb9c5e12c4a5ad Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Fri, 8 Apr 2011 13:20:06 +0200 Subject: Auch beim hinzufügen von weiteren Rechten nun Checkboxliste --- .../modules/user/controllers/RoleController.php | 28 +++--- application/modules/user/forms/LinkRight.php | 45 +++++++-- application/modules/user/forms/RoleAdd.php | 16 ++++ application/modules/user/layouts/user.phtml | 101 ++++++++++----------- .../modules/user/views/scripts/role/show.phtml | 2 +- 5 files changed, 114 insertions(+), 78 deletions(-) (limited to 'application/modules') diff --git a/application/modules/user/controllers/RoleController.php b/application/modules/user/controllers/RoleController.php index 4e0aa52..88e2eeb 100644 --- a/application/modules/user/controllers/RoleController.php +++ b/application/modules/user/controllers/RoleController.php @@ -303,20 +303,24 @@ class User_RoleController extends Zend_Controller_Action } if(count($rightlist) > 0) { if (!isset($_POST["link"])){ - $linkForm = new user_Form_LinkRight(array('rightlist' => $rightlist, 'roleID' => $roleID)); + $linkForm = new user_Form_LinkRight(array('rightlist' => $rightlist)); } else { - $linkForm = new user_Form_LinkRight(array('rightlist' => $rightlist, 'roleID' => $roleID), $_POST); + $linkForm = new user_Form_LinkRight(array('rightlist' => $rightlist, $_POST)); if ($linkForm->isValid($_POST)) { - $rightroles = new Application_Model_RightRoles(); - $rightroles->setRightID($_POST['rightID']); - $rightroles->setRoleID($roleID); - try { - $this->rightRolesMapper->save($rightroles); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "
"; - echo "Message: " . $e->getMessage() . "
"; - return; + foreach($_POST['rights'] as $rightID => $bool) { + if($bool == 1) { + $rightroles = new Application_Model_RightRoles(); + $rightroles->setRightID($rightID); + $rightroles->setRoleID($roleID); + try { + $this->rightRolesMapper->save($rightroles); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + return; + } + } } $this->_redirect('/user/role/show/roleID/' . $roleID); return; diff --git a/application/modules/user/forms/LinkRight.php b/application/modules/user/forms/LinkRight.php index 54aacd6..80cfb1d 100644 --- a/application/modules/user/forms/LinkRight.php +++ b/application/modules/user/forms/LinkRight.php @@ -3,29 +3,54 @@ class user_Form_LinkRight extends Zend_Form { private $rightlist; - private $roleID; public function setRightlist($rightlist){ $this->rightlist = $rightlist; } - public function setRoleID($roleID){ - $this->roleID = $roleID; - } - public function init() { - $this->setName("LinkRight"); + $this->setName("LinkRights"); $this->setMethod('post'); - $rightfield = $this->createElement('select','rightID',array('label'=> 'Right: ','required' => true,'multioptions'=> $this->rightlist)); - $rightfield->setRegisterInArrayValidator(false); - $this->addElement($rightfield); + $sform = new Zend_Form_SubForm(array('legend' => 'Rights:')); + + $sform->addElement('button', 'checkAll', array( + 'required' => false, + 'ignore' => true, + 'label' => 'Check All', + 'class' => 'leftbutton', + 'onclick' => "checkAllCheckBoxes();", + )); + + $sform->addElement('button', 'uncheckAll', array( + 'required' => false, + 'ignore' => true, + 'label' => 'Uncheck All', + 'onclick' => "uncheckAllCheckBoxes();", + )); + + if(count($this->rightlist) > 0) { + foreach($this->rightlist as $rightcategory => $rights) { + foreach($rights as $rightID => $rightTitle) { + $element = $this->createElement('checkbox', "$rightID", array( + 'label' => $rightTitle . ':', + 'belongsTo' => 'rights', + )); + $elements[] = $rightID; + $sform->addElement($element); + } + $sform->addDisplayGroup($elements, "$rightcategory", array("legend" => $rightcategory . ":")); + unset($elements); + } + } + + $this->addSubForm($sform, 'rights'); $this->addElement('submit', 'link', array( 'required' => false, 'ignore' => true, - 'label' => 'Add', + 'label' => 'Add Rights', )); $this->addElement('button', 'cancel', array( diff --git a/application/modules/user/forms/RoleAdd.php b/application/modules/user/forms/RoleAdd.php index 5968b47..d165701 100644 --- a/application/modules/user/forms/RoleAdd.php +++ b/application/modules/user/forms/RoleAdd.php @@ -32,6 +32,21 @@ class user_Form_RoleAdd extends Zend_Form )); $sform = new Zend_Form_SubForm(array('legend' => 'Rights:')); + + $sform->addElement('button', 'checkAll', array( + 'required' => false, + 'ignore' => true, + 'label' => 'Check All', + 'class' => 'leftbutton', + 'onclick' => "checkAllCheckBoxes(new Array('inheritance'));", + )); + + $sform->addElement('button', 'uncheckAll', array( + 'required' => false, + 'ignore' => true, + 'label' => 'Uncheck All', + 'onclick' => "uncheckAllCheckBoxes(new Array('inheritance'));", + )); if(count($this->rightlist) > 0) { foreach($this->rightlist as $rightcategory => $rights) { foreach($rights as $rightID => $rightTitle) { @@ -46,6 +61,7 @@ class user_Form_RoleAdd extends Zend_Form unset($elements); } } + $this->addSubForm($sform, 'rights'); $this->addElement('checkbox', 'inheritance', array( diff --git a/application/modules/user/layouts/user.phtml b/application/modules/user/layouts/user.phtml index edbe209..b27b747 100644 --- a/application/modules/user/layouts/user.phtml +++ b/application/modules/user/layouts/user.phtml @@ -29,60 +29,52 @@ echo $this->headScript()."\n";
  • @@ -97,11 +89,11 @@ echo $this->headScript()."\n";
    -
    hasIdentity()){ echo 'Angemeldet als '; $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); - + if(isset($userIDsNamespace['membershipID'])){ $membershipMapper = new Application_Model_MembershipMapper(); $membership = new Application_Model_Membership(); @@ -122,8 +114,7 @@ if(Zend_Auth::getInstance()->hasIdentity()){ echo "".$role->getTitle().""; } } -?> -
    +?>
    getControllerName()) . " > " . ucwords($request->getActionName()); ?> diff --git a/application/modules/user/views/scripts/role/show.phtml b/application/modules/user/views/scripts/role/show.phtml index 6769336..8194353 100644 --- a/application/modules/user/views/scripts/role/show.phtml +++ b/application/modules/user/views/scripts/role/show.phtml @@ -33,7 +33,7 @@ if($this->roleID) {

    Rights:

    rightsAvailable === true) { - echo $this->formButton('linkright', 'Add Right', array( + echo $this->formButton('linkright', 'Add Rights', array( 'onclick' => 'self.location="/user/role/linkright/roleID/' . $this->role->getID() .'"', 'class' => 'addbutton'))?>
    -- cgit v1.2.3-55-g7522