diff options
| author | Simon | 2011-03-16 14:42:40 +0100 |
|---|---|---|
| committer | Simon | 2011-03-16 14:42:40 +0100 |
| commit | 29224a1ccc162e457589210168c38529e81a572d (patch) | |
| tree | f049b58ed09cd4bd9de2e3fe882593b75b16cae4 /application/modules | |
| parent | Merge branch 'master' of openslx.org:lsfks/master-teamprojekt/pbs2 (diff) | |
| download | pbs2-29224a1ccc162e457589210168c38529e81a572d.tar.gz pbs2-29224a1ccc162e457589210168c38529e81a572d.tar.xz pbs2-29224a1ccc162e457589210168c38529e81a572d.zip | |
Helper initialisiert, ClientController geadded
Diffstat (limited to 'application/modules')
6 files changed, 112 insertions, 22 deletions
diff --git a/application/modules/dev/controllers/ClientController.php b/application/modules/dev/controllers/ClientController.php index d73379c..27b8a08 100644 --- a/application/modules/dev/controllers/ClientController.php +++ b/application/modules/dev/controllers/ClientController.php @@ -18,15 +18,19 @@ class dev_ClientController extends Zend_Controller_Action { $mac = $this->_request->getParam('mac'); $hh = $this->_request->getParam('hh'); + + $groupMapper = new Application_Model_GroupMapper(); + $groups = $groupMapper->fetchAll(); + #print_a($groups);die(); if (!isset($_POST["add"])){ - $addclient = new dev_Form_Client(array('buttontext' => 'Create Client')); + $addclient = new dev_Form_Client(array('buttontext' => 'Create Client','groups'=>$groups)); $this->view->addclient = $addclient; } else{ - $addfilterform = new dev_Form_Client(array('buttontext' => 'Create Client'),$_POST); + $addfilterform = new dev_Form_Client(array('buttontext' => 'Create Client','groups'=>$groups),$_POST); if ($addfilterform->isValid($_POST) || ($mac != '' && $hh != '') ) { - $client = new Application_Model_Client(); + $client = new Application_Model_Client($_POST); $mac = ($mac!='')?$mac:$_POST['macadress']; $hh = ($hh!='')?$hh:$_POST['hardwarehash']; $client->setMacadress($mac); @@ -55,18 +59,22 @@ class dev_ClientController extends Zend_Controller_Action public function editclientAction() { + $groupMapper = new Application_Model_GroupMapper(); + $groups = $groupMapper->fetchAll(); + # print_a($groups);die(); + if (!isset($_POST["add"])){ $clientID = $this->_request->getParam('clientID'); $data = new Application_Model_Client(); $mapper = new Application_Model_ClientMapper(); $mapper->find($clientID,$data); - $editclient = new dev_Form_Client(array('buttontext' => 'Edit Client')); + $editclient = new dev_Form_Client(array('buttontext' => 'Edit Client', 'groups'=>$groups)); $editclient->populate($data->toArray()); $this->view->editclient = $editclient; } else{ - $editclient = new dev_Form_Client(array('buttontext' => 'Edit Client'),$_POST); + $editclient = new dev_Form_Client(array('buttontext' => 'Edit Client','groups'=>$groups),$_POST); if ($editclient->isValid($_POST) || ($mac != '' && $hh != '') ) { $client = new Application_Model_Client($_POST); $client->setID($this->_request->getParam('clientID')); diff --git a/application/modules/dev/forms/Client.php b/application/modules/dev/forms/Client.php index f09f720..1e62877 100644 --- a/application/modules/dev/forms/Client.php +++ b/application/modules/dev/forms/Client.php @@ -7,7 +7,16 @@ class dev_Form_Client extends Zend_Form { $this->setName("pool"); $this->setMethod('post'); - + + $groupfield = $this->createElement('select','groupID'); + $groupfield ->setLabel('Group:'); + + foreach($this->groups as $c){ + $groupfield->addMultiOption($c->getID(),$c->getTitle()); + } + $this->addElement($groupfield); + + $this->addElement('text', 'macadress', array( 'filters' => array('StringTrim'), 'validators' => array( @@ -32,13 +41,18 @@ class dev_Form_Client extends Zend_Form )); $this->addElement('button', 'Cancel', array( - 'onclick' => 'self.location="/client"' + 'onclick' => 'self.location="/dev/client"' )); } private $buttontext = 'Save'; + private $groups; function setButtontext($v){ $this->buttontext = $v; } + public function setGroups($groups){ + $this->groups = $groups; + return $this; + } } diff --git a/application/modules/dev/views/scripts/client/index.phtml b/application/modules/dev/views/scripts/client/index.phtml index fa12ed7..612e23b 100644 --- a/application/modules/dev/views/scripts/client/index.phtml +++ b/application/modules/dev/views/scripts/client/index.phtml @@ -7,6 +7,7 @@ <table> <tr> <th>ID</th> + <th>GroupID</th> <th>MAC</th> <th>Hardwarehash</th> <th colspan=2>Actions</th> @@ -14,6 +15,7 @@ <?php foreach ($this->clients as $client): ?> <tr class=entry> <td><?php echo $this->escape($client->getID()) ?></td> + <td><?php echo $this->escape($client->getGroupID()) ?></td> <td class='monospace'><?php echo $this->escape($client->getMacadress()) ?></td> <td class='monospace'><?php echo $this->escape($client->getHardwarehash()) ?></td> <td class='action'><a href="<?php echo $this->url( diff --git a/application/modules/user/controllers/ClientController.php b/application/modules/user/controllers/ClientController.php index a8d0d3d..bd111cf 100644 --- a/application/modules/user/controllers/ClientController.php +++ b/application/modules/user/controllers/ClientController.php @@ -2,7 +2,7 @@ class User_ClientController extends Zend_Controller_Action { - private $this->membership; + private $membership; public function init() { /* Initialize action controller here */ @@ -15,15 +15,24 @@ class User_ClientController extends Zend_Controller_Action { // TODO: ACL: is he athorized to see this ? - // Get the Clients which booted with a bootiso of this group - $groupID = $this->membership->getGroupID(); - $bootisoMapper = new Application_Model_BootIsoMapper(); - $bootisos = $bootisoMapper->findby('groupID',$groupID); - - $sessions - - - + // Get the Clients which booted with a bootiso of this group + $result = $this->_request->getParam('result'); + switch($result){ + case "forbidden": + echo "<div class='errorbox'>Not allowed to delete this</div>"; + break; + case "ok": + echo "<div class='checkbox'>Delete sucessful</div>"; + break; + case "error": + echo "<div class='warningbox'>There was an error deleting</div>"; + break; + } + $clientMapper = new Application_Model_ClientMapper(); + $clientsInGroup = $clientMapper->findBy('groupID',$this->membership->getGroupID()); + # print_a($clientsInGroup); + + $this->view->clients = $clientsInGroup; } @@ -34,6 +43,23 @@ class User_ClientController extends Zend_Controller_Action public function removeclientAction() { + $clientID = $this->_request->getParam('clientID'); + // TODO: ACL: is he authorized to delete clients? + $clientMapper = new Application_Model_ClientMapper(); + if(is_numeric($clientID)){ + $client = new Application_Model_Client(); + $clientMapper->find($clientID,$client); + // TODO: ACL: Is He authorized to delete + if($client->getGroupID() == $this->membership->getGroupID()){ + $clientMapper = new Application_Model_ClientMapper(); + $clientMapper->delete($client); + $this->_redirect('/user/client/index/result/ok'); + } + else{ + $this->_redirect('/user/client/index/result/forbidden'); + } + } + $this->_redirect('/user/client/index/result/error'); // action body } diff --git a/application/modules/user/views/scripts/client/index.phtml b/application/modules/user/views/scripts/client/index.phtml index 4f0e6ec..e79b208 100644 --- a/application/modules/user/views/scripts/client/index.phtml +++ b/application/modules/user/views/scripts/client/index.phtml @@ -1 +1,41 @@ -<br /><br /><center>View script for controller <b>Client</b> and script/action name <b>index</b></center>
\ No newline at end of file +<h1>Clients</h1> +<?php echo $this->formButton('createbootos', 'Create Client', array( + 'onclick' => 'self.location="/user/client/addclient"', + 'class' => 'addbutton'))?> + +<?php if ($this->clients): ?> + <table> + <tr> + <th>MAC</th> + <th>Hardwarehash</th> + <th colspan=2>Actions</th> + </tr> + <?php foreach ($this->clients as $client): ?> + <tr class=entry> + <td class='monospace'><?php echo $this->escape($client['macadress']) ?></td> + <td class='monospace'><?php echo $this->escape($client['hardwarehash']) ?></td> + <td class='action'><a href="<?php echo $this->url( + array( + 'module' => 'user', + 'controller' => 'client', + 'action' => 'editclient', + 'clientID' => $client['clientID'] + ), + 'default', + true) ?>"><img src='/media/img/edit.png' alt='Edit Client'/></a></td> + <td class='action'><a href="<?php echo $this->url( + array( + 'module' => 'user', + 'controller' => 'client', + 'action' => 'removeclient', + 'clientID' => $client['clientID'] + ), + 'default', + true) ?>"><img src='/media/img/delete.png' alt='Delete Client'/></a></td> + </tr> + <?php endforeach ?> + </table> + +<?php else: ?> + <p>There are no clients to display.</p> +<?php endif;?> diff --git a/application/modules/user/views/scripts/index/index.phtml b/application/modules/user/views/scripts/index/index.phtml index 77e0720..a6e84a7 100644 --- a/application/modules/user/views/scripts/index/index.phtml +++ b/application/modules/user/views/scripts/index/index.phtml @@ -1,9 +1,9 @@ <h1>Welcome</h1> -<div class='infobox'><?php echo $this->text;?></div> -<div class='checkbox'><?php echo $this->text;?></div> -<div class='warningbox'><?php echo $this->text;?></div> -<div class='errorbox'><?php echo $this->text;?></div> +<div class='infobox'>infobox: <?php echo $this->text;?></div> +<div class='okbox'>okbox: <?php echo $this->text;?></div> +<div class='warningbox'>warningbox: <?php echo $this->text;?></div> +<div class='errorbox'>errorbox: <?php echo $this->text;?></div> <?php print_a($this->links);?> <?php if(count($this->links)>0 && is_array($this->links)): ?> |
