summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Geiger2011-03-27 16:44:55 +0200
committerBjörn Geiger2011-03-27 16:44:55 +0200
commitaaf8275e5ff92504357c5f3167a3f256d0d393ad (patch)
tree1b6faae50f95f7a3bc2c51c452fc33c8f867caa4
parentCompare Methode bei allen Mappern ergänzt (diff)
downloadpbs2-aaf8275e5ff92504357c5f3167a3f256d0d393ad.tar.gz
pbs2-aaf8275e5ff92504357c5f3167a3f256d0d393ad.tar.xz
pbs2-aaf8275e5ff92504357c5f3167a3f256d0d393ad.zip
Rollenverwaltung User Module
-rw-r--r--.zfproject.xml21
-rw-r--r--application/models/Acl.php71
-rw-r--r--application/modules/user/controllers/BootisoController.php6
-rw-r--r--application/modules/user/controllers/BootmenuController.php6
-rw-r--r--application/modules/user/controllers/BootosController.php6
-rw-r--r--application/modules/user/controllers/ClientController.php207
-rw-r--r--application/modules/user/controllers/ConfigController.php20
-rw-r--r--application/modules/user/controllers/FilterController.php358
-rw-r--r--application/modules/user/controllers/GroupController.php20
-rw-r--r--application/modules/user/controllers/PoolController.php35
-rw-r--r--application/modules/user/controllers/RoleController.php241
-rw-r--r--application/modules/user/forms/LinkRight.php48
-rw-r--r--application/modules/user/forms/RoleAdd.php50
-rw-r--r--application/modules/user/forms/RoleEdit.php65
-rw-r--r--application/modules/user/views/scripts/role/add.phtml4
-rw-r--r--application/modules/user/views/scripts/role/edit.phtml10
-rw-r--r--application/modules/user/views/scripts/role/index.phtml59
-rw-r--r--application/modules/user/views/scripts/role/linkright.phtml4
-rw-r--r--application/modules/user/views/scripts/role/show.phtml67
19 files changed, 977 insertions, 321 deletions
diff --git a/.zfproject.xml b/.zfproject.xml
index 70ccd1c..3845e14 100644
--- a/.zfproject.xml
+++ b/.zfproject.xml
@@ -126,6 +126,12 @@
</controllerFile>
<controllerFile controllerName="Role">
<actionMethod actionName="index"/>
+ <actionMethod actionName="add"/>
+ <actionMethod actionName="edit"/>
+ <actionMethod actionName="show"/>
+ <actionMethod actionName="delete"/>
+ <actionMethod actionName="linkright"/>
+ <actionMethod actionName="unlinkright"/>
</controllerFile>
<controllerFile controllerName="Bootiso">
<actionMethod actionName="index"/>
@@ -175,6 +181,9 @@
<formFile formName="RecoverPassword"/>
<formFile formName="NewPassword"/>
<formFile formName="MembershipSelect"/>
+ <formFile formName="RoleAdd"/>
+ <formFile formName="RoleEdit"/>
+ <formFile formName="LinkRight"/>
</formsDirectory>
<layoutsDirectory enabled="false"/>
<modelsDirectory>
@@ -278,6 +287,18 @@
<viewControllerScriptsDirectory forControllerName="Person">
<viewScriptFile forActionName="selectmembership"/>
</viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Role">
+ <viewScriptFile forActionName="add"/>
+ </viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Role">
+ <viewScriptFile forActionName="edit"/>
+ </viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Role">
+ <viewScriptFile forActionName="show"/>
+ </viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Role">
+ <viewScriptFile forActionName="linkright"/>
+ </viewControllerScriptsDirectory>
</viewScriptsDirectory>
<viewHelpersDirectory/>
<viewFiltersDirectory/>
diff --git a/application/models/Acl.php b/application/models/Acl.php
new file mode 100644
index 0000000..3de2ec9
--- /dev/null
+++ b/application/models/Acl.php
@@ -0,0 +1,71 @@
+<?php
+
+class Application_Model_Acl
+{
+ private static $roleID;
+
+ public static function setRoleID($roleID) {
+ Application_Model_Acl::$roleID = $roleID;
+ }
+
+ public static function getRoleID() {
+ return Application_Model_Acl::$roleID;
+ }
+
+ public static function checkRight($rightID) {
+ $rightRolesMapper = new Application_Model_RightRolesMapper();
+ $rightroles = $rightRolesMapper->findBy('roleID', Application_Model_Acl::$roleID);
+ $rightMapper = new Application_Model_RightMapper();
+ foreach($rightroles as $rightrole) {
+ $right = $rightMapper->find($rightrole['rightID']);
+ if($right->getID() == $rightID) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static function checkRightByMembershipID($membershipID, $rightID) {
+ $membershipMapper = new Application_Model_MembershipMapper();
+ $membership = $membershipMapper->find($membershipID);
+ $rightRolesMapper = new Application_Model_RightRolesMapper();
+ $rightroles = $rightRolesMapper->findBy('roleID', $membership->getRoleID());
+ $rightMapper = new Application_Model_RightMapper();
+ foreach($rightroles as $rightrole) {
+ $right = $rightMapper->find($rightrole['rightID']);
+ if($right->getID() == $rightID) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static function checkRightTitle($rightTitle) {
+ $rightRolesMapper = new Application_Model_RightRolesMapper();
+ $rightroles = $rightRolesMapper->findBy('roleID', Application_Model_Acl::$roleID);
+ $rightMapper = new Application_Model_RightMapper();
+ foreach($rightroles as $rightrole) {
+ $right = $rightMapper->find($rightrole['rightID']);
+ if($right->getTitle() == $rightTitle) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static function checkRightTitleByMembershipID($membershipID, $rightTitle) {
+ $membershipMapper = new Application_Model_MembershipMapper();
+ $membership = $membershipMapper->find($membershipID);
+ $rightRolesMapper = new Application_Model_RightRolesMapper();
+ $rightroles = $rightRolesMapper->findBy('roleID', $membership->getRoleID());
+ $rightMapper = new Application_Model_RightMapper();
+ foreach($rightroles as $rightrole) {
+ $right = $rightMapper->find($rightrole['rightID']);
+ if($right->getTitle() == $rightTitle) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
+
diff --git a/application/modules/user/controllers/BootisoController.php b/application/modules/user/controllers/BootisoController.php
index 492e035..5f9dcdb 100644
--- a/application/modules/user/controllers/BootisoController.php
+++ b/application/modules/user/controllers/BootisoController.php
@@ -5,7 +5,11 @@ class User_BootisoController extends Zend_Controller_Action
public function init()
{
- /* Initialize action controller here */
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+
+ } else {
+ $this->_helper->redirector('login', 'auth');
+ }
}
public function indexAction()
diff --git a/application/modules/user/controllers/BootmenuController.php b/application/modules/user/controllers/BootmenuController.php
index 2ecab8d..7b0f4f5 100644
--- a/application/modules/user/controllers/BootmenuController.php
+++ b/application/modules/user/controllers/BootmenuController.php
@@ -5,7 +5,11 @@ class User_BootmenuController extends Zend_Controller_Action
public function init()
{
- /* Initialize action controller here */
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+
+ } else {
+ $this->_helper->redirector('login', 'auth');
+ }
}
public function indexAction()
diff --git a/application/modules/user/controllers/BootosController.php b/application/modules/user/controllers/BootosController.php
index 7fc72d1..56a6ae3 100644
--- a/application/modules/user/controllers/BootosController.php
+++ b/application/modules/user/controllers/BootosController.php
@@ -5,7 +5,11 @@ class User_BootosController extends Zend_Controller_Action
public function init()
{
- /* Initialize action controller here */
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+
+ } else {
+ $this->_helper->redirector('login', 'auth');
+ }
}
public function indexAction()
diff --git a/application/modules/user/controllers/ClientController.php b/application/modules/user/controllers/ClientController.php
index 30ac2f7..7846d94 100644
--- a/application/modules/user/controllers/ClientController.php
+++ b/application/modules/user/controllers/ClientController.php
@@ -3,24 +3,29 @@
class User_ClientController extends Zend_Controller_Action
{
private $membership;
- public function init()
- {
- $userIDsNamespace = Zend_Session::namespaceGet('userIDs');
- if($userIDsNamespace['membershipID'] ==''){
- $pbsNotifier = new Pbs_Notifier();
- echo $pbsNotifier->notify('No membershipID set','forbidden');
+
+ public function init()
+ {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+ $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($userIDsNamespace['membershipID'],$this->membership);
+ } else {
+ $this->_helper->redirector('login', 'auth');
}
- /* Initialize action controller here */
- $membershipMapper = new Application_Model_MembershipMapper();
- $this->membership = new Application_Model_Membership();
- $membershipMapper->find($userIDsNamespace['membershipID'],$this->membership);
- }
-
- public function indexAction()
- {
- // TODO: ACL: is he authorized to see this ?
-
- // Get the Clients which booted with a bootiso of this group
+ }
+
+ public function indexAction()
+ {
+ // TODO: ACL: is he authorized to see this ?
+
+ // Get the Clients which booted with a bootiso of this group
$result = $this->_request->getParam('deleteresult');
if($result != ""){
$pbsNotifier = new Pbs_Notifier();
@@ -36,115 +41,115 @@ class User_ClientController extends Zend_Controller_Action
$pbsNotifier = new Pbs_Notifier();
$this->view->notification = $pbsNotifier->notify('create',$result);
}
-
+
$clientMapper = new Application_Model_ClientMapper();
$clientsInGroup = $clientMapper->findBy('groupID',$this->membership->getGroupID());
#print_a($clientsInGroup);
-
- $this->view->clients = $clientsInGroup;
-
- }
- public function addclientAction()
- {
- $mac = $this->_request->getParam('mac');
+ $this->view->clients = $clientsInGroup;
+
+ }
+
+ public function addclientAction()
+ {
+ $mac = $this->_request->getParam('mac');
$hh = $this->_request->getParam('hh');
-
+
// TODO: ACL: is he authorized to create new clients?
#if( he is allowed){
- if (!isset($_POST["add"])){
- $addclient = new user_Form_Client(array('buttontext' => 'Create Client'));
- $this->view->addclient = $addclient;
- }
- else{
- $addclient = new user_Form_Client(array('buttontext' => 'Create Client'),$_POST);
- print_a($_POST);
- if ($addclient->isValid($_POST) || ($mac != '' && $hh != '') ) {
- $client = new Application_Model_Client($_POST);
- $mac = ($mac!='')?$mac:$_POST['macadress'];
- $hh = ($hh!='')?$hh:$_POST['hardwarehash'];
- $client->setMacadress($mac);
- $client->setHardwarehash($hh);
- $client->setGroupID($this->membership->getGroupID());
- $clientmapper = new Application_Model_ClientMapper();
- $clientmapper->save($client);
- $this->_redirect('/user/client/index/addresult/ok');
- }
- $this->view->addclient = $addclient;
+ if (!isset($_POST["add"])){
+ $addclient = new user_Form_Client(array('buttontext' => 'Create Client'));
+ $this->view->addclient = $addclient;
+ }
+ else{
+ $addclient = new user_Form_Client(array('buttontext' => 'Create Client'),$_POST);
+ print_a($_POST);
+ if ($addclient->isValid($_POST) || ($mac != '' && $hh != '') ) {
+ $client = new Application_Model_Client($_POST);
+ $mac = ($mac!='')?$mac:$_POST['macadress'];
+ $hh = ($hh!='')?$hh:$_POST['hardwarehash'];
+ $client->setMacadress($mac);
+ $client->setHardwarehash($hh);
+ $client->setGroupID($this->membership->getGroupID());
+ $clientmapper = new Application_Model_ClientMapper();
+ $clientmapper->save($client);
+ $this->_redirect('/user/client/index/addresult/ok');
}
+ $this->view->addclient = $addclient;
+ }
#}else{
# $this->_redirect('/user/');
#}
- }
+ }
- public function removeclientAction()
- {
- $clientID = $this->_request->getParam('clientID');
+ public function removeclientAction()
+ {
+ $clientID = $this->_request->getParam('clientID');
// TODO: ACL: is he authorized to delete clients?
#if( he is allowed){
- $clientMapper = new Application_Model_ClientMapper();
- if(is_numeric($clientID)){
- $client = new Application_Model_Client();
- $clientMapper->find($clientID,$client);
- if($client->getGroupID() == $this->membership->getGroupID()){
- $clientMapper = new Application_Model_ClientMapper();
- $clientMapper->delete($client);
- $this->_redirect('/user/client/index/deleteresult/ok');
- }
- else{
- $this->_redirect('/user/client/index/deleteresult/forbidden');
- }
+ $clientMapper = new Application_Model_ClientMapper();
+ if(is_numeric($clientID)){
+ $client = new Application_Model_Client();
+ $clientMapper->find($clientID,$client);
+ if($client->getGroupID() == $this->membership->getGroupID()){
+ $clientMapper = new Application_Model_ClientMapper();
+ $clientMapper->delete($client);
+ $this->_redirect('/user/client/index/deleteresult/ok');
}
- $this->_redirect('/user/client/index/deleteresult/error');
+ else{
+ $this->_redirect('/user/client/index/deleteresult/forbidden');
+ }
+ }
+ $this->_redirect('/user/client/index/deleteresult/error');
#}else{
# $this->_redirect('/user/');
#}
- }
-
- public function editclientAction(){
- // TODO: ACL: Is he authorized to edit clients ?
- #if( he is allowed){
- if (!isset($_POST["add"])){
- $clientID = $this->_request->getParam('clientID');
- $client = new Application_Model_Client();
- $mapper = new Application_Model_ClientMapper();
- $mapper->find($clientID,$client);
-
- if($client->getGroupID() == $this->membership->getGroupID()){
- $editclient = new user_Form_Client(array('buttontext' => 'Edit Client'));
- $editclient->populate($client->toArray());
- $this->view->editclient = $editclient;
- }
- else{
- $this->_redirect('/user/client/index/modifyresult/error');
- }
+ }
+
+ public function editclientAction(){
+ // TODO: ACL: Is he authorized to edit clients ?
+ #if( he is allowed){
+ if (!isset($_POST["add"])){
+ $clientID = $this->_request->getParam('clientID');
+ $client = new Application_Model_Client();
+ $mapper = new Application_Model_ClientMapper();
+ $mapper->find($clientID,$client);
+
+ if($client->getGroupID() == $this->membership->getGroupID()){
+ $editclient = new user_Form_Client(array('buttontext' => 'Edit Client'));
+ $editclient->populate($client->toArray());
+ $this->view->editclient = $editclient;
}
else{
- $editclient = new user_Form_Client(array('buttontext' => 'Edit Client'),$_POST);
- if ($editclient->isValid($_POST) || ($mac != '' && $hh != '') ) {
- $client = new Application_Model_Client($_POST);
- $client->setID($this->_request->getParam('clientID'));
-
- $dbclient = new Application_Model_Client();
- $clientMapper = new Application_Model_ClientMapper();
- $clientMapper->find($this->_request->getParam('clientID'),$dbclient);
-
- if($dbclient->getGroupID() == $this->membership->getGroupID()){
- $client->setGroupID($this->membership->getGroupID());
- $clientmapper = new Application_Model_ClientMapper();
- $clientmapper->save($client);
- $this->_redirect('/user/client/index/modifyresult/ok');
- }
- else{
- $this->_redirect('/user/client/index/modifyresult/error');
- }
+ $this->_redirect('/user/client/index/modifyresult/error');
+ }
+ }
+ else{
+ $editclient = new user_Form_Client(array('buttontext' => 'Edit Client'),$_POST);
+ if ($editclient->isValid($_POST) || ($mac != '' && $hh != '') ) {
+ $client = new Application_Model_Client($_POST);
+ $client->setID($this->_request->getParam('clientID'));
+
+ $dbclient = new Application_Model_Client();
+ $clientMapper = new Application_Model_ClientMapper();
+ $clientMapper->find($this->_request->getParam('clientID'),$dbclient);
+
+ if($dbclient->getGroupID() == $this->membership->getGroupID()){
+ $client->setGroupID($this->membership->getGroupID());
+ $clientmapper = new Application_Model_ClientMapper();
+ $clientmapper->save($client);
+ $this->_redirect('/user/client/index/modifyresult/ok');
+ }
+ else{
+ $this->_redirect('/user/client/index/modifyresult/error');
}
- $this->view->editclient = $editclient;
}
+ $this->view->editclient = $editclient;
+ }
#}else{
# $this->_redirect('/user/');
#}
- }
+ }
}
diff --git a/application/modules/user/controllers/ConfigController.php b/application/modules/user/controllers/ConfigController.php
index ffc5387..2b5f095 100644
--- a/application/modules/user/controllers/ConfigController.php
+++ b/application/modules/user/controllers/ConfigController.php
@@ -3,15 +3,19 @@
class User_ConfigController extends Zend_Controller_Action
{
- public function init()
- {
- /* Initialize action controller here */
- }
+ public function init()
+ {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
- public function indexAction()
- {
- // action body
- }
+ } else {
+ $this->_helper->redirector('login', 'auth');
+ }
+ }
+
+ public function indexAction()
+ {
+ // action body
+ }
}
diff --git a/application/modules/user/controllers/FilterController.php b/application/modules/user/controllers/FilterController.php
index 642c543..efa6c75 100644
--- a/application/modules/user/controllers/FilterController.php
+++ b/application/modules/user/controllers/FilterController.php
@@ -4,27 +4,31 @@ class User_FilterController extends Zend_Controller_Action
{
protected $filterMapper;
protected $membershipMapper;
- public function init()
- {
- $userIDsNamespace = Zend_Session::namespaceGet('userIDs');
- if($userIDsNamespace['membershipID'] ==''){
- $pbsNotifier = new Pbs_Notifier();
- echo $pbsNotifier->notify('No membershipID set','forbidden');
+ public function init()
+ {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+ $userIDsNamespace = Zend_Session::namespaceGet('userIDs');
+ if($userIDsNamespace['membershipID'] ==''){
+ $pbsNotifier = new Pbs_Notifier();
+ echo $pbsNotifier->notify('No membershipID set','forbidden');
+ }
+ $this->filterMapper = new Application_Model_FilterMapper();
+
+ $membershipMapper = new Application_Model_MembershipMapper();
+ $this->membership = new Application_Model_Membership();
+ $membershipMapper->find($userIDsNamespace['membershipID'],$this->membership);
+
+ $this->db = Zend_Db_Table::getDefaultAdapter();
+ } else {
+ $this->_helper->redirector('login', 'auth');
}
- $this->filterMapper = new Application_Model_FilterMapper();
-
- $membershipMapper = new Application_Model_MembershipMapper();
- $this->membership = new Application_Model_Membership();
- $membershipMapper->find($userIDsNamespace['membershipID'],$this->membership);
-
- $this->db = Zend_Db_Table::getDefaultAdapter();
- }
-
- public function indexAction()
- {
- // TODO: ACL: is he authorized to see this?
-
- $result = $this->_request->getParam('addresult');
+ }
+
+ public function indexAction()
+ {
+ // TODO: ACL: is he authorized to see this?
+
+ $result = $this->_request->getParam('addresult');
if($result != ""){
$pbsNotifier = new Pbs_Notifier();
$this->view->notification = $pbsNotifier->notify('create',$result);
@@ -39,8 +43,8 @@ class User_FilterController extends Zend_Controller_Action
$pbsNotifier = new Pbs_Notifier();
$this->view->notification = $pbsNotifier->notify('modify',$result);
}
-
- $filters = $this->filterMapper->findBy('groupID',$this->membership->getGroupID());
+
+ $filters = $this->filterMapper->findBy('groupID',$this->membership->getGroupID());
foreach($filters as $filter){
$ff = new Application_Model_Filter();
$ff->setOptions($filter);
@@ -48,12 +52,12 @@ class User_FilterController extends Zend_Controller_Action
$allFilter[] = $ff;
}
$this->view->filters = $allFilter;
- }
+ }
- public function addfilterAction()
- {
- // TODO: ACL: is he authorized to add a filter?
- $bmmapper = new Application_Model_BootMenuMapper();
+ public function addfilterAction()
+ {
+ // TODO: ACL: is he authorized to add a filter?
+ $bmmapper = new Application_Model_BootMenuMapper();
$result = $bmmapper->findBy('groupID',$this->membership->getGroupID());
foreach($result as $rr){
$bm = new Application_Model_BootMenu();
@@ -62,65 +66,65 @@ class User_FilterController extends Zend_Controller_Action
$bootmenus[] = $bm;
}
$this->view->bootmenus = $bootmenus;
-
- if (!isset($_POST["add"])){
- $addfilterform = new user_Form_Filter(array('buttontext' => 'Create Filter','bootmenus'=>$bootmenus));
- $this->view->addfilterform = $addfilterform;
+
+ if (!isset($_POST["add"])){
+ $addfilterform = new user_Form_Filter(array('buttontext' => 'Create Filter','bootmenus'=>$bootmenus));
+ $this->view->addfilterform = $addfilterform;
}else {
$addfilterform = new user_Form_Filter(array('buttontext' => 'Create Filter','bootmenus'=>$bootmenus),$_POST);
- if ($addfilterform->isValid($_POST)) {
+ if ($addfilterform->isValid($_POST)) {
try{
$newfilter = new Application_Model_Filter($_POST);
- $newfilter->setCreated(time());
+ $newfilter->setCreated(time());
$newfilter->setGroupID($this->membership->getGroupID());
- $newfilter->setMembershipID($this->membership->getID());
+ $newfilter->setMembershipID($this->membership->getID());
$newfilter2 = new Application_Model_FilterMapper();
$id = $newfilter2->save($newfilter);
-
+
$filterentriesMapper = new Application_Model_FilterEntriesMapper();
$filterentry = new Application_Model_FilterEntries();
$filterentry->setFilterID($id);
$filterentry->setFiltertypeID(6);
$filterentry->setFiltervalue($this->membership->getGroupID());
$filterentriesMapper->save($filterentry);
-
+
$this->_redirect('/user/filter/index/addresult/ok');
- }catch (Zend_Exception $e) {
- echo "Error message 2: " . $e->getMessage() . "\n";
- $this->_redirect('/user/filter/index/addresult/error');
- }
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
+ $this->_redirect('/user/filter/index/addresult/error');
+ }
}
$this->view->addfilterform = $addfilterform;
}
- }
+ }
- public function removefilterAction()
- {
- $filterID = $this->_request->getParam('filterID');
- $filtermapper = new Application_Model_FilterMapper();
+ public function removefilterAction()
+ {
+ $filterID = $this->_request->getParam('filterID');
+ $filtermapper = new Application_Model_FilterMapper();
// TODO: ACL implementieren ob er den filter löschen darf
-
+
if(is_numeric($filterID)){
$filter = new Application_Model_Filter();
$filtermapper->find($filterID,$filter);
- if($filter->getGroupID() == $this->membership->getGroupID()){
+ if($filter->getGroupID() == $this->membership->getGroupID()){
$deletefilter = new Application_Model_Filter();
- $deletefilter->setID($filterID);
+ $deletefilter->setID($filterID);
$filtermapper->delete($deletefilter);
- $this->_redirect('/user/filter/index/deleteresult/ok');
+ $this->_redirect('/user/filter/index/deleteresult/ok');
}
else{
- $this->_redirect('/user/filter/index/deleteresult/forbidden');
+ $this->_redirect('/user/filter/index/deleteresult/forbidden');
}
}
else{
- $this->_redirect('/user/filter/index/deleteresult/error');
+ $this->_redirect('/user/filter/index/deleteresult/error');
}
- }
+ }
- public function editfilterAction()
- {
- $bmmapper = new Application_Model_BootMenuMapper();
+ public function editfilterAction()
+ {
+ $bmmapper = new Application_Model_BootMenuMapper();
$result = $bmmapper->findBy('groupID',$this->membership->getGroupID());
foreach($result as $rr){
$bm = new Application_Model_BootMenu();
@@ -128,112 +132,112 @@ class User_FilterController extends Zend_Controller_Action
$bm->setID($rr['bootmenuID']);
$bootmenus[] = $bm;
}
-
+
if (!isset($_POST["add"])){
- // TODO: ACL implementieren ob er editieren darf
+ // TODO: ACL implementieren ob er editieren darf
$filterID = $this->_request->getParam('filterID');
- $filter = new Application_Model_Filter();
+ $filter = new Application_Model_Filter();
$filtermapper = new Application_Model_FilterMapper();
- $filtermapper->find($filterID,$filter);
+ $filtermapper->find($filterID,$filter);
if($filter->getGroupID() == $this->membership->getGroupID()){
$filter2 = $filter->toArray();
- $editfilterform = new user_Form_Filter(array('buttontext' => 'Edit Filter','bootmenus'=>$bootmenus));
+ $editfilterform = new user_Form_Filter(array('buttontext' => 'Edit Filter','bootmenus'=>$bootmenus));
$editfilterform->populate($filter2);
$this->view->editfilterform = $editfilterform;
}
else{
- $this->_redirect('/user/filter/index/modifyresult/forbidden');
+ $this->_redirect('/user/filter/index/modifyresult/forbidden');
}
-
+
} else{
try{
- $filterID = $this->_request->getParam('filterID');
+ $filterID = $this->_request->getParam('filterID');
$filter = new Application_Model_Filter();
$filtermapper = new Application_Model_FilterMapper();
- $filtermapper->find($filterID,$filter);
- if($filter->getGroupID() == $this->membership->getGroupID()){
+ $filtermapper->find($filterID,$filter);
+ if($filter->getGroupID() == $this->membership->getGroupID()){
$editfilterform = new user_Form_Filter(array('buttontext' => 'Edit Filter','bootmenus'=>$bootmenus),$_POST);
- if ($editfilterform->isValid($_POST)) {
+ if ($editfilterform->isValid($_POST)) {
$newfilterentry = new Application_Model_Filter($_POST);
$newfilterentry->setID($this->_request->getParam('filterID'));
$newfilterentry->setGroupID($this->membership->getGroupID());
$newfilterentry->setMembershipID($this->membership->getID());
$newfilterentry->setCreated($_POST['created']);
- $newfilter2 = new Application_Model_FilterMapper();
+ $newfilter2 = new Application_Model_FilterMapper();
$newfilter2->save($newfilterentry);
- $this->_redirect('/user/filter/index/modifyresult/ok');
- }
+ $this->_redirect('/user/filter/index/modifyresult/ok');
+ }
$this->view->editfilterform = $editfilterform;
}
else{
- $this->_redirect('/user/filter/index/modifyresult/forbidden');
+ $this->_redirect('/user/filter/index/modifyresult/forbidden');
}
- }catch (Zend_Exception $e) {
- echo "Error message 2: " . $e->getMessage() . "\n";
- $this->_redirect('/user/filter/index/modifyresult/error');
- }
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
+ $this->_redirect('/user/filter/index/modifyresult/error');
+ }
}
- }
-
- private function prepareFormData(){
- $poolMapper = new Application_Model_PoolMapper();
- $pools = $poolMapper->findBY('groupID',$this->membership->getGroupID());
-
- $bootisoMapper = new Application_Model_BootIsoMapper();
- $bootisos = $bootisoMapper->findBY('groupID',$this->membership->getGroupID());
-
- $membershipMapper = new Application_Model_MembershipMapper();
- $memberships = $membershipMapper->findBY('groupID',$this->membership->getGroupID());
-
- // TODO: get all child groups
+ }
+
+ private function prepareFormData(){
+ $poolMapper = new Application_Model_PoolMapper();
+ $pools = $poolMapper->findBY('groupID',$this->membership->getGroupID());
+
+ $bootisoMapper = new Application_Model_BootIsoMapper();
+ $bootisos = $bootisoMapper->findBY('groupID',$this->membership->getGroupID());
+
+ $membershipMapper = new Application_Model_MembershipMapper();
+ $memberships = $membershipMapper->findBY('groupID',$this->membership->getGroupID());
+
+ // TODO: get all child groups
$grouppMapper = new Application_Model_GroupMapper();
$group = new Application_Model_Group();
$grouppMapper->find($this->membership->getGroupID(),$group);
- $groups[] = $group->toArray();
-
+ $groups[] = $group->toArray();
+
$clientMapper = new Application_Model_ClientMapper();
- $clients = $clientMapper->findBY('groupID',$this->membership->getGroupID());
-
- return array ( 'clients' => $clients,
+ $clients = $clientMapper->findBY('groupID',$this->membership->getGroupID());
+
+ return array ( 'clients' => $clients,
'memberships' => $memberships,
'groups' => $groups,
'bootisos' => $bootisos,
'pools' => $pools);
-
- }
-
- public function addfilterentryAction()
- {
- // TODO: ACL: is he allowed to create a new filterentry?
- $filterID = $this->_request->getParam('filterID');
- $filterMapper = new Application_Model_FilterMapper();
- $filter = new Application_Model_Filter();
- $filterMapper->find($filterID,$filter);
-
- $selectData = $this->prepareFormData();
-
- if($filter->getGroupID() == $this->membership->getGroupID()){
- if (!isset($_POST["add"])){
+
+ }
+
+ public function addfilterentryAction()
+ {
+ // TODO: ACL: is he allowed to create a new filterentry?
+ $filterID = $this->_request->getParam('filterID');
+ $filterMapper = new Application_Model_FilterMapper();
+ $filter = new Application_Model_Filter();
+ $filterMapper->find($filterID,$filter);
+
+ $selectData = $this->prepareFormData();
+
+ if($filter->getGroupID() == $this->membership->getGroupID()){
+ if (!isset($_POST["add"])){
try{
$addform = new user_Form_FilterEntry(array( 'buttontext' => 'Add Filterentry',
'filterID' => $filterID,
'selectData' => $selectData,
'data' => $_POST
- ));
+ ));
$addform->populate($_POST);
$this->view->addform = $addform;
- }catch (Zend_Exception $e) {
+ }catch (Zend_Exception $e) {
echo "Error message 2: " . $e->getMessage() . "\n";
- $this->_redirect('/user/filter/index/addresult/error');
+ $this->_redirect('/user/filter/index/addresult/error');
}
} else{
- $addform = new user_Form_FilterEntry(array('buttontext' => 'Add Filterentry',
+ $addform = new user_Form_FilterEntry(array('buttontext' => 'Add Filterentry',
'selectData' => $selectData,
'data'=>$_POST
- ));
+ ));
if ($addform->isValid($_POST)) {
- print_a('valid');
+ print_a('valid');
$newfilterenty = new Application_Model_FilterEntries();
$newfilterenty->setFilterID($filterID);
$newfilterenty->setFiltertypeID($_POST['filtertypeID']);
@@ -246,40 +250,40 @@ class User_FilterController extends Zend_Controller_Action
$newfilterenty->setFiltervalue($this->fillup($_POST['filtervalue'],2,':'));
$newfilterenty->setFiltervalue2($this->fillup($_POST['filtervalue2'],2,':'));
}
- else{
+ else{
$newfilterenty->setFiltervalue($_POST['filtervalue']);
if(isset($_POST['filtervalue2'])){
$newfilterenty->setFiltervalue2($_POST['filtervalue2']);
}
}
-
+
$newfilter2 = new Application_Model_FilterEntriesMapper();
- $newfilter2->save($newfilterenty);
+ $newfilter2->save($newfilterenty);
$this->_redirect('/user/filter/index/addresult/ok');
}
$this->view->addform = $addform;
}
}
else{
- $this->_redirect('/user/filter/index/addresult/forbidden');
+ $this->_redirect('/user/filter/index/addresult/forbidden');
}
- }
+ }
- public function editfilterentryAction()
- {
- //TODO: ACL: is he allowed to edit filterentrys ?
- $selectData = $this->prepareFormData();
- if (!isset($_POST["add"])){
+ public function editfilterentryAction()
+ {
+ //TODO: ACL: is he allowed to edit filterentrys ?
+ $selectData = $this->prepareFormData();
+ if (!isset($_POST["add"])){
try{
$filterentriesID = $this->_request->getParam('filterentriesID');
$filterentry = new Application_Model_FilterEntries();
$filterentriesmapper = new Application_Model_FilterEntriesMapper();
- $filterentriesmapper->find($filterentriesID,$filterentry);
-
+ $filterentriesmapper->find($filterentriesID,$filterentry);
+
$filterMapper = new Application_Model_FilterMapper();
$filter = new Application_Model_Filter();
$filterMapper->find($filterentry->getFilterID(),$filter);
-
+
if($filter->getGroupID() == $this->membership->getGroupID()){
if(isset($_POST['filtertypeID']) && $_POST['filtertypeID'] != $filterentry->getFiltertypeID()){
$filterentry->setFiltertypeID($_POST['filtertypeID']) ;
@@ -288,51 +292,51 @@ class User_FilterController extends Zend_Controller_Action
$editfilterform = new user_Form_FilterEntry(array('buttontext' => 'Edit Filterentry',
'selectData' => $selectData,
'data' => $data
- ));
-
+ ));
+
$editfilterform->populate($filterentry->toArray());
$this->view->editfilterform = $editfilterform;
}
else{
$this->_redirect('/user/filter/index/moodifyresult/forbidden');
}
- }catch (Zend_Exception $e) {
- echo "Error message 2: " . $e->getMessage() . "\n";
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
$this->_redirect('/user/filter/index/moodifyresult/error');
}
} else{
try{
- $filterentriesID = $this->_request->getParam('filterentriesID');
+ $filterentriesID = $this->_request->getParam('filterentriesID');
$editfilterform = new user_Form_FilterEntry(array('buttontext' => 'Edit Filterentry',
'selectData' => $selectData,
'data' => $_POST
- ));
- if ($editfilterform->isValid($_POST)) {
+ ));
+ if ($editfilterform->isValid($_POST)) {
$filterentry = new Application_Model_FilterEntries();
$filterentriesmapper = new Application_Model_FilterEntriesMapper();
- $filterentriesmapper->find($filterentriesID,$filterentry);
-
+ $filterentriesmapper->find($filterentriesID,$filterentry);
+
$filterMapper = new Application_Model_FilterMapper();
$filter = new Application_Model_Filter();
$filterMapper->find($filterentry->getFilterID(),$filter);
-
+
if($filter->getGroupID() == $this->membership->getGroupID()){
if($_POST['filterID'] == '')
- unset($_POST['filterID']);
-
- $newfilterenty = new Application_Model_FilterEntries($_POST);
- $newfilterenty->setID($filterentriesID);
- if($_POST['filtertypeID'] == 1){
+ unset($_POST['filterID']);
+
+ $newfilterenty = new Application_Model_FilterEntries($_POST);
+ $newfilterenty->setID($filterentriesID);
+ if($_POST['filtertypeID'] == 1){
$newfilterenty->setFiltervalue($this->fillup($_POST['filtervalue'],3,'.'));
$newfilterenty->setFiltervalue2($this->fillup($_POST['filtervalue2'],3,'.'));
}
- elseif($_POST['filtertypeID'] == 2){
+ elseif($_POST['filtertypeID'] == 2){
$newfilterenty->setFiltervalue($this->fillup($_POST['filtervalue'],2,';'));
$newfilterenty->setFiltervalue2($this->fillup($_POST['filtervalue2'],2,':'));
}
- else{
+ else{
$newfilterenty->setFiltervalue($_POST['filtervalue']);
- $newfilterenty->setFiltervalue2($_POST['filtervalue2']);
+ $newfilterenty->setFiltervalue2($_POST['filtervalue2']);
}
// check if it's the last groupID filterentry
@@ -353,42 +357,42 @@ class User_FilterController extends Zend_Controller_Action
echo $pbsNotifier->notify('You cannot modify the last GroupFilter','forbidden');
}
else{
- $newfilter2 = new Application_Model_FilterEntriesMapper();
+ $newfilter2 = new Application_Model_FilterEntriesMapper();
$newfilter2->save($newfilterenty);
$this->_redirect('/user/filter/index/modifyresult/ok');
}
}
else{
$this->_redirect('/user/filter/index/modifyresult/forbidden');
- }
+ }
}
$this->view->editfilterform = $editfilterform;
- }catch (Zend_Exception $e) {
- echo "Error message 2: " . $e->getMessage() . "\n";
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
$this->_redirect('/user/filter/index/modifyresult/error');
}
}
- }
-
- public function removefilterentryAction()
- {
- //TODO: ACL: is he autohorized to delete a filterentry?
- $filterentriesID = $this->_request->getParam('filterentriesID');
- if(is_numeric($filterentriesID)){
- $filterentriesmapper = new Application_Model_FilterEntriesMapper();
- $filterentry = new Application_Model_FilterEntries();
- $filterentriesmapper->find($filterentriesID, $filterentry);
- $filterID = $filterentry->getFilterID();
-
- $filterMapper = new Application_Model_FilterMapper();
+ }
+
+ public function removefilterentryAction()
+ {
+ //TODO: ACL: is he autohorized to delete a filterentry?
+ $filterentriesID = $this->_request->getParam('filterentriesID');
+ if(is_numeric($filterentriesID)){
+ $filterentriesmapper = new Application_Model_FilterEntriesMapper();
+ $filterentry = new Application_Model_FilterEntries();
+ $filterentriesmapper->find($filterentriesID, $filterentry);
+ $filterID = $filterentry->getFilterID();
+
+ $filterMapper = new Application_Model_FilterMapper();
$filter = new Application_Model_Filter();
$filterMapper->find($filterID,$filter);
-
+
if($filter->getGroupID() == $this->membership->getGroupID()){
try{
$deletefilterentry = new Application_Model_FilterEntries();
- $deletefilterentry->setID($filterentriesID);
-
+ $deletefilterentry->setID($filterentriesID);
+
// check if it's the last groupID filterentry
$allFilters = $filterentriesmapper->findBy('filterID',$filterID);
$lastfilter = true;
@@ -403,34 +407,34 @@ class User_FilterController extends Zend_Controller_Action
}
}
if($lastfilter){
- $this->_redirect('/user/filter/index/deleteresult/forbidden');
+ $this->_redirect('/user/filter/index/deleteresult/forbidden');
}
- else{
+ else{
$filterentriesmapper = new Application_Model_FilterEntriesMapper();
$filterentriesmapper->delete($deletefilterentry);
- $this->_redirect('/user/filter/index/deleteresult/ok');
- }
- }catch (Zend_Exception $e) {
+ $this->_redirect('/user/filter/index/deleteresult/ok');
+ }
+ }catch (Zend_Exception $e) {
echo "Error message 2: " . $e->getMessage() . "\n";
- $this->_redirect('/user/filter/index/deleteresult/error');
+ $this->_redirect('/user/filter/index/deleteresult/error');
}
}
else{
- $this->_redirect('/user/filter/index/deleteresult/forbidden');
+ $this->_redirect('/user/filter/index/deleteresult/forbidden');
}
}
else{
- $this->_redirect('/user/filter/index/deleteresult/error');
- }
- }
- private function fillup($string, $length, $seperator=':',$sign='0'){
- $ar = explode($seperator,$string);
+ $this->_redirect('/user/filter/index/deleteresult/error');
+ }
+ }
+ private function fillup($string, $length, $seperator=':',$sign='0'){
+ $ar = explode($seperator,$string);
$representation = array();
foreach($ar as $part){
$representation[] = sprintf("%".$sign.$length."s",$part);
}
return implode($seperator,$representation);
- }
+ }
}
diff --git a/application/modules/user/controllers/GroupController.php b/application/modules/user/controllers/GroupController.php
index 21944d3..52136af 100644
--- a/application/modules/user/controllers/GroupController.php
+++ b/application/modules/user/controllers/GroupController.php
@@ -3,15 +3,19 @@
class User_GroupController extends Zend_Controller_Action
{
- public function init()
- {
- /* Initialize action controller here */
- }
+ public function init()
+ {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
- public function indexAction()
- {
- // action body
- }
+ } else {
+ $this->_helper->redirector('login', 'auth');
+ }
+ }
+
+ public function indexAction()
+ {
+ // action body
+ }
}
diff --git a/application/modules/user/controllers/PoolController.php b/application/modules/user/controllers/PoolController.php
index 6ec8aa7..07dfec5 100644
--- a/application/modules/user/controllers/PoolController.php
+++ b/application/modules/user/controllers/PoolController.php
@@ -5,21 +5,26 @@ class User_PoolController extends Zend_Controller_Action
private $membership;
public function init()
{
- $userIDsNamespace = Zend_Session::namespaceGet('userIDs');
- if($userIDsNamespace['membershipID'] ==''){
- $pbsNotifier = new Pbs_Notifier();
- echo $pbsNotifier->notify('No membershipID set','forbidden');
- }
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+ $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($userIDsNamespace['membershipID'],$this->membership);
+ $membershipMapper = new Application_Model_MembershipMapper();
+ $this->membership = new Application_Model_Membership();
+ $membershipMapper->find($userIDsNamespace['membershipID'],$this->membership);
+ ;
+ } else {
+ $this->_helper->redirector('login', 'auth');
+ }
}
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();
@@ -184,7 +189,7 @@ class User_PoolController extends Zend_Controller_Action
$assignedclientsArray[] = $c->toArray();
}
$freeclients = $this->arrayDiff($clients,$assignedclientsArray);
-
+
$poolclient = new user_Form_PoolClient(array('buttontext' => 'Link Client','clients'=> $freeclients));
$this->view->poolclient = $poolclient;
}else {
@@ -222,7 +227,7 @@ class User_PoolController extends Zend_Controller_Action
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();
@@ -230,14 +235,14 @@ class User_PoolController extends Zend_Controller_Action
$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);
diff --git a/application/modules/user/controllers/RoleController.php b/application/modules/user/controllers/RoleController.php
index d7abc62..da65507 100644
--- a/application/modules/user/controllers/RoleController.php
+++ b/application/modules/user/controllers/RoleController.php
@@ -2,17 +2,242 @@
class User_RoleController extends Zend_Controller_Action
{
+ private $userIDsNamespace;
- public function init()
- {
- /* Initialize action controller here */
- }
+ public function init()
+ {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+ $this->userIDsNamespace = Zend_Session::namespaceGet('userIDs');
+ if($this->userIDsNamespace['groupID'] ==''){
+ $pbsNotifier = new Pbs_Notifier();
+ echo $pbsNotifier->notify('No groupID set','forbidden');
+ }
+ $this->roleMapper = new Application_Model_RoleMapper();
+ $this->rightMapper = new Application_Model_RightMapper();
+ $this->rightRolesMapper = new Application_Model_RightRolesMapper();
+ } else {
+ $this->_helper->redirector('login', 'auth');
+ }
+ }
- public function indexAction()
- {
- // action body
- }
+ public function indexAction()
+ {
+ if(isset($this->userIDsNamespace['groupID'])) {
+ $roleList = $this->roleMapper->findBy('groupID', $this->userIDsNamespace['groupID']);
+ $this->view->groupID = $this->userIDsNamespace['groupID'];
+ $this->view->roleList = $roleList;
+ } else {
+ $this->_helper->redirector('groupselect', 'role');
+ return;
+ }
+ }
+
+ public function addAction()
+ {
+ if(isset($this->userIDsNamespace['groupID'])) {
+ if (!isset($_POST["add"])){
+ $addForm = new user_Form_RoleAdd(array('rightlist' => $rightList));
+ } else {
+ $addForm = new user_Form_RoleAdd(array('rightlist' => $rightList),$_POST);
+ if ($addForm->isValid($_POST)) {
+
+ $_POST['groupID'] = $this->userIDsNamespace['groupID'];
+ $role = new Application_Model_Role($_POST);
+ try {
+ $this->roleMapper->save($role);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $this->_helper->redirector('', 'role');
+ return;
+ }
+ }
+
+ $this->view->addForm = $addForm;
+ } else {
+ $this->_helper->redirector('groupselect', 'role');
+ return;
+ }
+ }
+
+ public function editAction()
+ {
+ $roleID = $this->_request->getParam('roleID');
+ if(!isset($roleID)) {
+ $addForm = new user_Form_RoleAdd();
+ $this->view->addForm = $addForm;
+ return;
+ }
+ if (!isset($_POST["save"])){
+ $role = $this->roleMapper->find($roleID);
+ $_POST['title'] = $role->getTitle();
+ $_POST['description'] = $role->getDescription();
+ $_POST['groupID'] = $role->getGroupID();
+ $editForm = new user_Form_RoleEdit(array('roleID' => $roleID));
+ } else {
+ $editForm = new user_Form_RoleEdit(array('roleID' => $roleID), $_POST);
+ if ($editForm->isValid($_POST)) {
+ $role = new Application_Model_Role($_POST);
+ $role->setID($this->_request->getParam('roleID'));
+ try {
+ $this->roleMapper->save($role);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $this->_helper->redirector('', 'role');
+ return;
+ }
+ }
+ $this->view->editForm = $editForm;
+ }
+
+ public function showAction()
+ {
+ $roleID = $this->_request->getParam('roleID');
+ if($roleID) {
+ $rightroles = $this->rightRolesMapper->findBy('roleID', $roleID);
+ if(count($rightroles) > 0) {
+ foreach($rightroles as $rightrole) {
+ $right = $this->rightMapper->find($rightrole['rightID']);
+ $rightsList[] = $right;
+ }
+ if(is_array($rightsList)) {
+ $this->view->rightsList = $rightsList;
+ }
+ }
+ $this->view->role = $this->roleMapper->find($roleID);
+ $this->view->roleID = $roleID;
+ } else {
+ $this->_helper->redirector('', 'role');
+ return;
+ }
+ }
+
+ public function deleteAction()
+ {
+ $this->_helper->viewRenderer->setNoRender();
+ $roleID = $this->_request->getParam('roleID');
+ if (isset($roleID)){
+ $role = $this->roleMapper->find($roleID);
+ try {
+ $this->roleMapper->delete($role);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $this->_helper->redirector('', 'role');
+ return;
+ } else {
+ $this->_helper->redirector('', 'role');
+ return;
+ }
+ }
+
+ public function linkrightAction()
+ {
+ $roleID = $this->_request->getParam('roleID');
+ if(isset($roleID)) {
+ $rightroles = $this->rightRolesMapper->findBy('roleID', $roleID);
+ $rights = $this->rightMapper->fetchAll();
+ if(count($rightroles) > 0) {
+ if(count($rights) > 0) {
+ foreach($rights as $right) {
+ foreach($rightroles as $rightrole) {
+ if($right->getID() == $rightrole['rightID']) {
+ $found = true;
+ break;
+ }
+ }
+ if(!$found) {
+ $rightlist[] = $right;
+ }
+ $found = false;
+ }
+ }
+ } else {
+ $rightlist = $rights;
+ }
+ if(count($rightlist) > 0) {
+ if (!isset($_POST["link"])){
+ $linkForm = new user_Form_LinkRight(array('rightlist' => $rightlist, 'roleID' => $roleID));
+ } else {
+ $linkForm = new user_Form_LinkRight(array('rightlist' => $rightlist, 'roleID' => $roleID), $_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) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $this->_redirect('/user/role/show/roleID/' . $roleID);
+ return;
+ }
+ }
+ $this->view->linkForm = $linkForm;
+ } else {
+ $this->_redirect('/user/role/show/roleID/' . $roleID);
+ return;
+ }
+ } else {
+ $this->_helper->redirector('', 'role');
+ return;
+ }
+ }
+
+ public function unlinkrightAction()
+ {
+ $this->_helper-> viewRenderer-> setNoRender();
+ $rightRolesID = $this->_request->getParam('rightrolesID');
+ if(isset($rightRolesID)) {
+ $rightRolesID = explode('-',$rightRolesID);
+ $roleID = $rightRolesID[0];
+ $rightID = $rightRolesID[1];
+ if (isset($roleID) && isset($rightID)){
+ $rightroles = new Application_Model_RightRoles();
+ $rightroles->setRoleID($roleID);
+ $rightroles->setRightID($rightID);
+ try {
+ $this->rightRolesMapper->delete($rightroles);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $this->_redirect('/user/role/show/roleID/' . $roleID);
+ return;
+ }
+ } else {
+ $this->_helper->redirector('', 'role');
+ return;
+ }
+ }
}
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/application/modules/user/forms/LinkRight.php b/application/modules/user/forms/LinkRight.php
new file mode 100644
index 0000000..139aee4
--- /dev/null
+++ b/application/modules/user/forms/LinkRight.php
@@ -0,0 +1,48 @@
+<?php
+
+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->setMethod('post');
+
+ $rightfield = $this->createElement('select','rightID');
+ $rightfield ->setLabel('Right:');
+
+ if(count($this->rightlist)>0){
+ foreach($this->rightlist as $right => $r){
+ $rightfield->addMultiOption($r->getID(), $r->getTitle());
+ }
+ }
+ $rightfield->setRegisterInArrayValidator(false);
+ $this->addElement($rightfield);
+
+ $this->addElement('submit', 'link', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Add Right',
+ ));
+
+ $this->addElement('button', 'cancel', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Cancel',
+ 'onclick' => 'location.href="/user/role/show/roleID/' . $this->roleID . '"',
+ ));
+ }
+
+
+}
+
diff --git a/application/modules/user/forms/RoleAdd.php b/application/modules/user/forms/RoleAdd.php
new file mode 100644
index 0000000..3b5200b
--- /dev/null
+++ b/application/modules/user/forms/RoleAdd.php
@@ -0,0 +1,50 @@
+<?php
+
+class user_Form_RoleAdd extends Zend_Form
+{
+ private $rightlist;
+
+ public function setRightlist($rightlist){
+ $this->rightlist = $rightlist;
+ }
+
+ public function init()
+ {
+ $this->setName("RoleAdd");
+ $this->setMethod('post');
+
+ $this->addElement('text', 'title', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Title:',
+ ));
+
+ $this->addElement('text', 'description', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 140)),
+ ),
+ 'required' => false,
+ 'label' => 'Description:',
+ ));
+
+ $this->addElement('submit', 'add', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Add',
+ ));
+
+ $this->addElement('button', 'cancel', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Cancel',
+ 'onclick' => 'location.href="/user/role/"',
+ ));
+ }
+
+
+}
+
diff --git a/application/modules/user/forms/RoleEdit.php b/application/modules/user/forms/RoleEdit.php
new file mode 100644
index 0000000..170a2f9
--- /dev/null
+++ b/application/modules/user/forms/RoleEdit.php
@@ -0,0 +1,65 @@
+<?php
+
+class user_Form_RoleEdit extends Zend_Form
+{
+ private $roleID;
+
+ public function setRoleID($roleID){
+ $this->roleID = $roleID;
+ }
+
+ public function init()
+ {
+ $this->setName("RoleEdit");
+ $this->setMethod('post');
+
+ $this->addElement('text', 'title', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Title:',
+ 'value' => $_POST['title'],
+ ));
+
+ $this->addElement('text', 'description', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 140)),
+ ),
+ 'required' => false,
+ 'label' => 'Description:',
+ 'value' => $_POST['description'],
+ ));
+
+ $this->addElement('hidden', 'groupID', array(
+ 'value' => $_POST['groupID'],
+ ));
+
+ $this->addElement('submit', 'save', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Save',
+ ));
+
+ if(strpos($_SERVER['HTTP_REFERER'], '/user/role/show/roleID')) {
+ $this->addElement('button', 'cancel', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Cancel',
+ 'onclick' => 'location.href="/user/role/show/roleID/' . $this->roleID . '"',
+ ));
+ } else {
+ $this->addElement('button', 'cancel', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Cancel',
+ 'onclick' => 'location.href="/user/role/"',
+ ));
+ }
+ }
+
+
+}
+
diff --git a/application/modules/user/views/scripts/role/add.phtml b/application/modules/user/views/scripts/role/add.phtml
new file mode 100644
index 0000000..4f96cf0
--- /dev/null
+++ b/application/modules/user/views/scripts/role/add.phtml
@@ -0,0 +1,4 @@
+<?php
+$this->addForm->setAction($this->url());
+echo $this->addForm;
+?> \ No newline at end of file
diff --git a/application/modules/user/views/scripts/role/edit.phtml b/application/modules/user/views/scripts/role/edit.phtml
new file mode 100644
index 0000000..c976a90
--- /dev/null
+++ b/application/modules/user/views/scripts/role/edit.phtml
@@ -0,0 +1,10 @@
+<?php
+if(isset($this->addForm)) {
+ $this->addForm->setAction('/etc/role/add');
+ echo $this->addForm;
+}
+else {
+ $this->editForm->setAction($this->url());
+ echo $this->editForm;
+}
+?>
diff --git a/application/modules/user/views/scripts/role/index.phtml b/application/modules/user/views/scripts/role/index.phtml
index d30131e..7255db6 100644
--- a/application/modules/user/views/scripts/role/index.phtml
+++ b/application/modules/user/views/scripts/role/index.phtml
@@ -1 +1,58 @@
-<br /><br /><center>View script for controller <b>Role</b> and script/action name <b>index</b></center> \ No newline at end of file
+<?php
+if($this->groupID) {
+ ?>
+<h1>Roles</h1>
+ <?php echo $this->formButton('addrole', 'Add Role', array(
+ 'onclick' => 'self.location="/user/role/add"',
+ 'class' => 'addbutton'))?>
+<table>
+ <tr>
+ <th>Title</th>
+ <th colspan=3>Actions</th>
+ </tr>
+ <?php
+ $count = 0;
+ foreach($this->roleList as $role) {
+ ?>
+ <tr class="entry">
+ <td><?php echo $role['title'] ?></td>
+ <td class='action'><a
+ href="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'role',
+ 'action' => 'show',
+ 'roleID' => $role['roleID']
+ ),
+ 'default',
+ true) ?>"> <img src='/media/img/show.png' alt='Show Group' /></a></td>
+ <td class='action'><a
+ href="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'role',
+ 'action' => 'edit',
+ 'roleID' => $role['roleID']
+ ),
+ 'default',
+ true) ?>"> <img src='/media/img/edit.png' alt='Edit Group' /></a></td>
+ <td class='action'><a
+ href="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'role',
+ 'action' => 'delete',
+ 'roleID' => $role['roleID']
+ ),
+ 'default',
+ true) ?>"> <img src='/media/img/delete.png' alt='Delete Group' /></a>
+ </td>
+ </tr>
+ <?php
+ $count++;
+ }
+ ?>
+</table>
+ <?php
+}
+?> \ No newline at end of file
diff --git a/application/modules/user/views/scripts/role/linkright.phtml b/application/modules/user/views/scripts/role/linkright.phtml
new file mode 100644
index 0000000..94ad343
--- /dev/null
+++ b/application/modules/user/views/scripts/role/linkright.phtml
@@ -0,0 +1,4 @@
+<?php
+$this->linkForm->setAction($this->url());
+echo $this->linkForm;
+?> \ No newline at end of file
diff --git a/application/modules/user/views/scripts/role/show.phtml b/application/modules/user/views/scripts/role/show.phtml
new file mode 100644
index 0000000..9abab1a
--- /dev/null
+++ b/application/modules/user/views/scripts/role/show.phtml
@@ -0,0 +1,67 @@
+<h1>Role Details</h1>
+<?php
+if($this->roleID) {
+ ?>
+ <?php echo $this->formButton('deleterole', 'Delete', array(
+ 'onclick' => 'self.location="/user/role/delete/roleID/' . $this->role->getID() .'"',
+ 'class' => 'rightbutton'))?>
+ <?php echo $this->formButton('editrole', 'Edit', array(
+ 'onclick' => 'self.location="/user/role/edit/roleID/' . $this->role->getID() .'"',
+ 'class' => 'rightbutton'))?>
+<span class="clear"></span>
+<table>
+ <tr>
+ <th>Title</th>
+ <th>Description</th>
+ </tr>
+ <tr class="entry">
+ <td><?php echo $this->role->getTitle(); ?></td>
+ <td><?php echo $this->role->getDescription(); ?></td>
+ </tr>
+</table>
+<br />
+<h2>Rights:</h2>
+ <?php echo $this->formButton('linkright', 'Add Right', array(
+ 'onclick' => 'self.location="/user/role/linkright/roleID/' . $this->role->getID() .'"',
+ 'class' => 'addbutton'))?>
+ <?php if(isset($this->rightsList)) {
+ ?>
+<table>
+ <tr>
+ <th>Title</th>
+ <th>Description</th>
+ <th>Remove</th>
+ </tr>
+
+ <?php
+ foreach($this->rightsList as $right) {
+ ?>
+ <tr class="entry">
+ <td><?php echo $right->getTitle(); ?></td>
+ <td><?php echo $right->getDescription(); ?></td>
+ <td class='action'><a
+ href="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'role',
+ 'action' => 'unlinkright',
+ 'rightrolesID' => $this->roleID . '-' . $right->getID(),
+ ),
+ 'default',
+ true) ?>"> <img src='/media/img/delete.png' alt='Remove Right' /></a>
+ </td>
+ </tr>
+ <?php
+ }
+ ?>
+</table>
+ <?php
+ } else {
+ ?>
+<br />
+<center>
+<h3>No Rights have been added!</h3>
+</center>
+ <?php
+ }
+} \ No newline at end of file