diff options
author | michael pereira | 2011-04-04 03:47:22 +0200 |
---|---|---|
committer | michael pereira | 2011-04-04 03:47:22 +0200 |
commit | d26f46ed221f9e833e558747033657e8a58abdbc (patch) | |
tree | cf7dc4e3e0b601938b4dc937f7dd9c281ba6336d /application | |
parent | Bootmenu im User Controller fertig (diff) | |
download | pbs2-d26f46ed221f9e833e558747033657e8a58abdbc.tar.gz pbs2-d26f46ed221f9e833e558747033657e8a58abdbc.tar.xz pbs2-d26f46ed221f9e833e558747033657e8a58abdbc.zip |
Config in User fertig mit pagination
Diffstat (limited to 'application')
5 files changed, 346 insertions, 10 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'); + } } + + + + + + diff --git a/application/modules/user/forms/Config.php b/application/modules/user/forms/Config.php new file mode 100644 index 0000000..bf25fe2 --- /dev/null +++ b/application/modules/user/forms/Config.php @@ -0,0 +1,71 @@ +<?php + +class user_Form_Config extends Zend_Form +{ + + private $action; + private $rights; + private $page; + + public function setRights($rights){ + $this->rights = $rights; + } + public function setAction($action){ + $this->action = $action; + } + public function setPage($p){ + $this->page = $p; + } + + public function init() + { + $this->setName($this->action); + $this->setMethod('post'); + + if ($this->rights == 'meta') + $meta = true; + else + $meta = null; + + $this->addElement('text', 'title', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'label' => 'Title:', + )); + + + $this->addElement('textarea', 'shellscript', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'rows' => 10, + 'cols' => 70, + 'readOnly' => $meta, + 'label' => 'Shellscript:', + )); + + if($this->action == "createconfig") + $label = "Create Config"; + else + $label = "Edit Config"; + + $this->addElement('submit', $this->action, array( + 'required' => false, + 'ignore' => true, + 'label' => $label + )); + + $this->addElement('button', 'Cancel', array( + 'onclick' => 'self.location="/user/config/index/page/'.$this->page.'"' + )); + + } + +} +?> + diff --git a/application/modules/user/views/scripts/config/createconfig.phtml b/application/modules/user/views/scripts/config/createconfig.phtml new file mode 100644 index 0000000..e3939f5 --- /dev/null +++ b/application/modules/user/views/scripts/config/createconfig.phtml @@ -0,0 +1,4 @@ +<?php +$this->configForm; +echo $this->configForm; +?> diff --git a/application/modules/user/views/scripts/config/editconfig.phtml b/application/modules/user/views/scripts/config/editconfig.phtml new file mode 100644 index 0000000..e3939f5 --- /dev/null +++ b/application/modules/user/views/scripts/config/editconfig.phtml @@ -0,0 +1,4 @@ +<?php +$this->configForm; +echo $this->configForm; +?> diff --git a/application/modules/user/views/scripts/config/index.phtml b/application/modules/user/views/scripts/config/index.phtml index 4d9a1fb..478a12d 100644 --- a/application/modules/user/views/scripts/config/index.phtml +++ b/application/modules/user/views/scripts/config/index.phtml @@ -1 +1,54 @@ -<br /><br /><center>View script for controller <b>Config</b> and script/action name <b>index</b></center>
\ No newline at end of file +<h1>Config</h1> +<?php if($this->notification != ''){echo $this->notification;} ?> +<?php echo $this->formButton('createconfig', 'Create Config', array( + 'onclick' => 'self.location="/user/config/createconfig/page/'.$this->page.'"', + 'class' => 'addbutton'))?> + +<table> + <tr> + <th>ID</th> + <th>Title</th> + <th>GroupID</th> + <th>Shellscript</th> + <th>Changed</th> + <th colspan=2>Actions</th> + </tr> + <?php if(count($this->configlist)==0) + echo "</table> There are no Config's to display." ?> + <?php foreach ($this->configlist as $config): ?> + <tr class=entry> + <td><?php echo $this->escape($config->getID()); ?></td> + <td><?php echo $this->escape($config->getTitle()); ?></td> + <td><?php echo $this->escape($config->getGroupID()); ?></td> + <td><?php echo $this->escape($config->getShellscript()); ?></td> + <td><?php echo $this->escape(date('Y-m-d H:i:s', $config->getCreated())); ?></td> + <td class='action'><a href="<?php echo $this->url( + array( + 'module' => 'user', + 'controller' => 'config', + 'action' => 'editconfig', + 'configID' => $config->getID(), + 'page' => $this->page + ), + 'default', + true, false) ?>"><img src='/media/img/edit.png' alt='Edit Config'/></a></td> + <td class='action'><a href="<?php echo $this->url( + array( + 'module' => 'user', + 'controller' => 'config', + 'action' => 'deleteconfig', + 'configID' => $config->getID(), + 'page' => $this->page + ), + 'default', + true) ?>"><img src='/media/img/delete.png' alt='Delete Config'/></a></td> + </tr> + <?php endforeach; ?> +</table> +<?php echo $this->pagination; ?> + + + + + + |