summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/models/Client.php10
-rw-r--r--application/models/ClientMapper.php10
-rw-r--r--application/modules/dev/controllers/ClientController.php18
-rw-r--r--application/modules/dev/forms/Client.php18
-rw-r--r--application/modules/dev/views/scripts/client/index.phtml2
-rw-r--r--application/modules/user/controllers/ClientController.php46
-rw-r--r--application/modules/user/views/scripts/client/index.phtml42
-rw-r--r--application/modules/user/views/scripts/index/index.phtml8
-rw-r--r--library/Pbs/PbsNotifier.php27
-rw-r--r--pbs-newdata.sql22
-rw-r--r--pbs.sql4
-rw-r--r--public/media/css/style.css4
12 files changed, 173 insertions, 38 deletions
diff --git a/application/models/Client.php b/application/models/Client.php
index a27c3b3..3c2b050 100644
--- a/application/models/Client.php
+++ b/application/models/Client.php
@@ -3,6 +3,7 @@
class Application_Model_Client
{
protected $_clientID;
+ protected $_groupID;
protected $_macadress;
protected $_hardwarehash;
@@ -53,6 +54,15 @@ class Application_Model_Client
$this->_clientID = $_clientID;
return $this;
}
+ public function getGroupID()
+ {
+ return $this->_groupID;
+ }
+ public function setGroupID($_groupID)
+ {
+ $this->_groupID = $_groupID;
+ return $this;
+ }
public function getMacadress()
{
return $this->_macadress;
diff --git a/application/models/ClientMapper.php b/application/models/ClientMapper.php
index 7016ae7..2c530d9 100644
--- a/application/models/ClientMapper.php
+++ b/application/models/ClientMapper.php
@@ -47,7 +47,11 @@ class Application_Model_ClientMapper
public function save(Application_Model_Client $client)
{
- $data = array('clientID'=> $client->getID() ,'macadress'=> $client->getMacadress() ,'hardwarehash'=> $client->getHardwarehash() );
+ $data = array('clientID'=> $client->getID() ,
+ 'groupID' => $client->getGroupID(),
+ 'macadress'=> $client->getMacadress() ,
+ 'hardwarehash'=> $client->getHardwarehash()
+ );
if (null === ($id = $client->getID()) ) {
unset($data['clientID']);
@@ -75,7 +79,7 @@ class Application_Model_ClientMapper
$row = $result->current();
- $client->setID($row->clientID)->setMacadress($row->macadress)->setHardwarehash($row->hardwarehash);
+ $client->setID($row->clientID)->setGroupID($row->groupID)->setMacadress($row->macadress)->setHardwarehash($row->hardwarehash);
}
public function fetchAll()
@@ -85,7 +89,7 @@ class Application_Model_ClientMapper
foreach ($resultSet as $row) {
$entry = new Application_Model_Client();
- $entry->setID($row->clientID)->setMacadress($row->macadress)->setHardwarehash($row->hardwarehash);
+ $entry->setID($row->clientID)->setGroupID($row->groupID)->setMacadress($row->macadress)->setHardwarehash($row->hardwarehash);
$entries[] = $entry;
}
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)): ?>
diff --git a/library/Pbs/PbsNotifier.php b/library/Pbs/PbsNotifier.php
new file mode 100644
index 0000000..b079f2d
--- /dev/null
+++ b/library/Pbs/PbsNotifier.php
@@ -0,0 +1,27 @@
+<?php
+
+class Pbs_PbsNotifier{
+
+
+ public function notify($boxstyle, $action, $result){
+ switch($boxstyle){
+ default:
+ case "info":
+ $boxstyle = 'infobox';
+ break;
+ case "warning":
+ $boxstyle = 'warning';
+ break;
+ case "ok":
+ $boxstyle = 'okbox';
+ break;
+ case "error":
+ $boxstyle = 'errorbox';
+ break;
+ }
+
+
+ }
+}
+
+?>
diff --git a/pbs-newdata.sql b/pbs-newdata.sql
index 7f4b958..c309a54 100644
--- a/pbs-newdata.sql
+++ b/pbs-newdata.sql
@@ -20,17 +20,17 @@ INSERT INTO `pbs`.`pbs_membership` (`membershipID`, `groupID`, `roleID`, `person
INSERT INTO `pbs`.`pbs_membership` (`membershipID`, `groupID`, `roleID`, `personID`) VALUES (2, '1', '2', '2');
-- Adding clients
-INSERT INTO `pbs_client` (`clientID`, `macadress`, `hardwarehash`) VALUES
-(1, '00:00:00:00:00:10', 'ea9b82d9de911bc2d3cd23f53a6cab48'),
-(2, '00:00:00:00:10:00', '1e2b1599710fbbef0dc789e8cfe12455'),
-(3, '00:00:00:10:10:00', '8f6209ca3d6b35e223a11c249d1b69fc'),
-(4, '00:00:10:00:00:00', 'e17ab09f3586464f19629e2e8b1e9a9d'),
-(5, '00:10:00:00:00:00', '9bf70279d283b85440c2031c19bb6812'),
-(6, '10:00:00:00:00:00', 'ad3bce4464a6267441ec144744439c7e'),
-(7, '00:55:00:55:00:55', 'e8d7e80d79f224771b7a3a0af4e02748'),
-(8, '66:00:66:00:66:00', 'ded66ce272f384e9e386c1b57ded3e4d'),
-(9, '00:ff:ff:ff:ff:ff', '695610ee509c060b1fca9c8011529af4'),
-(10, '00:22:00:22:00:22', 'a3562c8cad2a4fa4fc11656025dc911b');
+INSERT INTO `pbs_client` (`clientID`, `groupID`,`macadress`, `hardwarehash`) VALUES
+(1, 1, '00:00:00:00:00:10', 'ea9b82d9de911bc2d3cd23f53a6cab48'),
+(2, 1, '00:00:00:00:10:00', '1e2b1599710fbbef0dc789e8cfe12455'),
+(3, 1, '00:00:00:10:10:00', '8f6209ca3d6b35e223a11c249d1b69fc'),
+(4, 1, '00:00:10:00:00:00', 'e17ab09f3586464f19629e2e8b1e9a9d'),
+(5, 1, '00:10:00:00:00:00', '9bf70279d283b85440c2031c19bb6812'),
+(6, 1, '10:00:00:00:00:00', 'ad3bce4464a6267441ec144744439c7e'),
+(7, 1, '00:55:00:55:00:55', 'e8d7e80d79f224771b7a3a0af4e02748'),
+(8, 1, '66:00:66:00:66:00', 'ded66ce272f384e9e386c1b57ded3e4d'),
+(9, 1, '00:ff:ff:ff:ff:ff', '695610ee509c060b1fca9c8011529af4'),
+(10, 1, '00:22:00:22:00:22', 'a3562c8cad2a4fa4fc11656025dc911b');
-- Adding config
INSERT INTO `pbs_config` (`configID`, `title`, `groupID`, `membershipID`, `shellscript`, `created`) VALUES
diff --git a/pbs.sql b/pbs.sql
index 4373267..12e00f6 100644
--- a/pbs.sql
+++ b/pbs.sql
@@ -208,6 +208,9 @@ CREATE TABLE IF NOT EXISTS `pbs_client` (
`hardwarehash` varchar(32),
PRIMARY KEY (`clientID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
+ALTER TABLE `pbs_client` ADD `groupID` INT NOT NULL AFTER `clientID` ;
+ALTER TABLE `pbs_client`
+ ADD CONSTRAINT `pbs_client_ibfk_1` FOREIGN KEY (`groupID`) REFERENCES `pbs_group` (`groupID`) ON DELETE CASCADE;
CREATE TABLE IF NOT EXISTS `pbs_session` (
`sessionID` int(11) NOT NULL AUTO_INCREMENT,
@@ -225,6 +228,7 @@ ALTER TABLE `pbs_session` ADD `alphasessionID` VARCHAR( 16 ) NOT NULL AFTER `ses
ALTER TABLE `pbs_session` ADD `bootmenuentryID` INT AFTER `clientID` ;
ALTER TABLE `pbs_session` ADD `membershipID` INT NULL AFTER `bootisoID` ;
+
ALTER TABLE `pbs_session`
ADD CONSTRAINT `pbs_session_ibfk_1` FOREIGN KEY (`clientID`) REFERENCES `pbs_client` (`clientID`) ON DELETE CASCADE,
ADD CONSTRAINT `pbs_session_ibfk_2` FOREIGN KEY (`bootosID`) REFERENCES `pbs_bootos` (`bootosID`) ON DELETE CASCADE,
diff --git a/public/media/css/style.css b/public/media/css/style.css
index 57b3552..8390fb2 100644
--- a/public/media/css/style.css
+++ b/public/media/css/style.css
@@ -237,7 +237,7 @@ td.action img{border:none;}
.footer{text-align:right;font-size:10px;font-family:Verdana, Arial;padding:10px 0px 10px 0px;}
/* boxes */
-.checkbox, .warningbox, .errorbox, .infobox {
+.okbox, .warningbox, .errorbox, .infobox {
margin:10px 0px;
padding:10px 10px 10px 40px;
border-width:1px;
@@ -259,7 +259,7 @@ td.action img{border:none;}
background: #FF9999 url('/media/img/box_error.png') no-repeat;
background-position:10px center;
}
-.checkbox{
+.okbox{
border:1px solid #339933;
background: #BBFFBB url('/media/img/box_check.png') no-repeat;
background-position:10px center;