summaryrefslogtreecommitdiffstats
path: root/application/modules/user/controllers/ConfigController.php
diff options
context:
space:
mode:
authormichael pereira2011-04-04 03:47:22 +0200
committermichael pereira2011-04-04 03:47:22 +0200
commitd26f46ed221f9e833e558747033657e8a58abdbc (patch)
treecf7dc4e3e0b601938b4dc937f7dd9c281ba6336d /application/modules/user/controllers/ConfigController.php
parentBootmenu im User Controller fertig (diff)
downloadpbs2-d26f46ed221f9e833e558747033657e8a58abdbc.tar.gz
pbs2-d26f46ed221f9e833e558747033657e8a58abdbc.tar.xz
pbs2-d26f46ed221f9e833e558747033657e8a58abdbc.zip
Config in User fertig mit pagination
Diffstat (limited to 'application/modules/user/controllers/ConfigController.php')
-rw-r--r--application/modules/user/controllers/ConfigController.php222
1 files changed, 213 insertions, 9 deletions
diff --git a/application/modules/user/controllers/ConfigController.php b/application/modules/user/controllers/ConfigController.php
index 2b5f095..3618901 100644
--- a/application/modules/user/controllers/ConfigController.php
+++ b/application/modules/user/controllers/ConfigController.php
@@ -1,22 +1,226 @@
<?php
-class User_ConfigController extends Zend_Controller_Action
+class user_ConfigController extends Zend_Controller_Action
{
- public function init()
- {
- if (Zend_Auth::getInstance()->hasIdentity()) {
+ protected $configMapper;
+ protected $membershipMapper;
+ protected $membership;
+ protected $page;
+
+ public function init()
+ {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+ $userIDsNamespace = Zend_Session::namespaceGet('userIDs');
+ if($userIDsNamespace['membershipID'] ==''){
+ $this->_redirect('/user/index');
+ }
+
+ $this->configMapper = new Application_Model_ConfigMapper();
+
+ $this->membershipMapper = new Application_Model_MembershipMapper();
+ $this->membership = new Application_Model_Membership();
+ $this->membershipMapper->find($userIDsNamespace['membershipID'],$this->membership);
+ $this->db = Zend_Db_Table::getDefaultAdapter();
} else {
$this->_helper->redirector('login', 'auth');
}
- }
+ $this->page = $this->_request->getParam('page'); }
- public function indexAction()
- {
- // action body
- }
+ public function indexAction()
+ {
+ $result = $this->_request->getParam('addresult');
+ if($result != ""){
+ $pbsNotifier = new Pbs_Notifier();
+ $this->view->notification = $pbsNotifier->notify('create',$result);
+ }
+ $result = $this->_request->getParam('deleteresult');
+ if($result != ""){
+ $pbsNotifier = new Pbs_Notifier();
+ $this->view->notification = $pbsNotifier->notify('delete',$result);
+ }
+ $result = $this->_request->getParam('modifyresult');
+ if($result != ""){
+ $pbsNotifier = new Pbs_Notifier();
+ $this->view->notification = $pbsNotifier->notify('modify',$result);
+ }
+
+ $groupID = $this->membership->getGroupID();
+
+ //TODO ACL Darf er Configs sehen?
+ if(false)
+ $this->_redirect('/user/index');
+
+ $this->configMapper = new Application_Model_ConfigMapper();
+ $groupMapper = new Application_Model_GroupMapper();
+
+ if(true){
+ //TODO nur Configs von Admins
+ $this->view->configlist = $this->configMapper->findBy('groupID', $this->membership->getGroupID());
+ }else{
+ $this->view->configlist = $this->configMapper->findBy('membershipID', $this->membership->getID());
+ }
+
+ foreach ($this->view->configlist as $config){
+ $config->setGroupID("[".$config->getGroupID()."] ".$groupMapper->find($config->getGroupID())->getTitle());
+ }
+
+
+ // Pagination
+ $perpage = 5;
+ $req_page = $this->_request->getParam('page');
+ $all = count($this->view->configlist);
+ $numpages = ceil($all/$perpage);
+ if($req_page < 0 || !is_numeric($req_page) )
+ $req_page = 0;
+ if($req_page >= $numpages)
+ $req_page = $numpages-1;
+ $startitem = $req_page * $perpage;
+
+ $pagination = new Pbs_Pagination();
+ $this->view->pagination = $pagination->pagination('/user/config/index',$req_page,$numpages);
+ $this->view->page = $req_page;
+ $this->view->configlist = array_slice($this->view->configlist,$startitem,$perpage);
+
+ }
+
+ public function createconfigAction()
+ {
+ //TODO ACL Darf er Configs erstellen?
+ if(false)
+ $this->_redirect('/user/config/index/page/'.$this->page.'/addresult/forbidden');
+
+ if (!isset($_POST["createconfig"])){
+ $configForm = new user_Form_Config(array('action' => 'createconfig','rights' => null,'page'=>$this->page));
+ } else {
+ $configForm = new user_Form_Config(array('action' => 'createconfig','rights' => null,'page'=>$this->page),$_POST);
+
+ if ($configForm->isValid($_POST)) {
+
+ $config = new Application_Model_Config($_POST);
+ $config->setCreated(time());
+ $config->setMembershipID($this->membership->getID());
+ $config->setGroupID($this->membership->getGroupID());
+
+ try {
+ $this->configMapper->save($config);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ $this->_redirect('/user/config/index/page/'.$this->page.'/addresult/error');
+ }
+ $this->_redirect('/user/config/index/page/'.$this->page.'/addresult/ok');
+ }
+ }
+
+ $this->view->configForm = $configForm;
+ }
+
+ public function editconfigAction()
+ {
+ //TODO ACL Darf er Configs editieren?
+ if(false)
+ $this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/forbidden');
+
+ $configID = $this->_request->getParam('configID');
+ if (!is_numeric($configID))
+ $this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/error');
+
+ $groupID = $this->membership->getGroupID();
+
+ $config = new Application_Model_Config();
+ $this->configMapper->find($configID, $config);
+
+ if($config->getMembershipID() != null){
+ if($this->membership->getID() != $config->getMembershipID())
+ $this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/forbidden');
+ }else{
+ if($this->membership->getGroupID() != $config->getGroupID())
+ $this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/forbidden');
+ }
+
+ if (!isset($_POST["editconfig"])){
+
+ $configForm = new user_Form_Config(array('action' => 'editconfig','rights' => 'meta','page'=>$this->page));
+ $configForm->populate($config->toArray());
+
+ }else{
+ $configForm = new user_Form_Config(array('action' => 'editconfig','rights' => 'meta','page'=>$this->page),$_POST);
+
+ if ($configForm->isValid($_POST)) {
+
+ $configold = $config;
+
+ $config = new Application_Model_Config($_POST);
+ $config->setCreated(time());
+ $config->setMembershipID($this->membership->getID());
+ $config->setGroupID($this->membership->getGroupID());
+ $config->setID($configID);
+
+ if($configold->getShellscript() != $config->getShellscript()){
+ //TODO ACL Is he allowed to edit other than Metadata?
+ if(false)
+ $this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/forbidden');
+ }
+
+
+ try {
+ $this->configMapper->save($config);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ $this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/error');
+ }
+
+ $this->_redirect('/user/config/index/page/'.$this->page.'/modifyresult/ok');
+ }
+
+ }
+
+ $this->view->configForm = $configForm;
+ }
+
+ public function deleteconfigAction()
+ {
+ //TODO ACL Darf er Configs löschen?
+ if(false)
+ $this->_redirect('/user/config/index/page/'.$this->page.'/deleteresult/forbidden');
+
+ try{
+ $configID = $this->_request->getParam('configID');
+ if (!is_numeric($configID))
+ $this->_redirect('/user/config/index/page/'.$this->page.'/deleteresult/error');
+
+ $config = new Application_Model_Config();
+ $this->configMapper->find($configID,$config);
+
+ if($config->getMembershipID() != null){
+ if($this->membership->getID() != $config->getMembershipID())
+ $this->_redirect('/user/config/index/page/'.$this->page.'/deleteresult/forbidden');
+ }else{
+ if($this->membership->getGroupID() != $config->getGroupID())
+ $this->_redirect('/user/config/index/page/'.$this->page.'/deleteresult/forbidden');
+ }
+
+ $this->configMapper->delete($config);
+
+ }catch(Zend_Exception $e){
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ $this->_redirect('/user/config/index/page/'.$this->page.'/deleteresult/error');
+ }
+ $this->_redirect('/user/config/index/page/'.$this->page.'/deleteresult/ok');
+ }
}
+
+
+
+
+
+