summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.zfproject.xml1
-rw-r--r--application/models/Pool.php10
-rw-r--r--application/models/PoolMapper.php8
-rw-r--r--application/modules/user/controllers/PoolController.php135
-rw-r--r--application/modules/user/forms/Pool.php54
-rw-r--r--application/modules/user/views/scripts/pool/createpool.phtml3
-rw-r--r--application/modules/user/views/scripts/pool/deletepool.phtml1
-rw-r--r--application/modules/user/views/scripts/pool/editpool.phtml3
-rw-r--r--application/modules/user/views/scripts/pool/index.phtml132
-rw-r--r--pbs-newdata.sql11
-rw-r--r--pbs.sql3
11 files changed, 341 insertions, 20 deletions
diff --git a/.zfproject.xml b/.zfproject.xml
index c0eba40..4a6e73f 100644
--- a/.zfproject.xml
+++ b/.zfproject.xml
@@ -265,6 +265,7 @@
<formsDirectory>
<formFile formName="Login"/>
<formFile formName="Client"/>
+ <formFile formName="Pool"/>
</formsDirectory>
<layoutsDirectory enabled="false"/>
<modelsDirectory>
diff --git a/application/models/Pool.php b/application/models/Pool.php
index 11d5a03..f312b19 100644
--- a/application/models/Pool.php
+++ b/application/models/Pool.php
@@ -3,6 +3,7 @@
class Application_Model_Pool
{
protected $_poolID;
+ protected $_groupID;
protected $_title;
protected $_description;
protected $_location;
@@ -54,6 +55,15 @@ class Application_Model_Pool
$this->_poolID = $_poolID;
return $this;
}
+ public function getGroupID()
+ {
+ return $this->_groupID;
+ }
+ public function setGroupID($_groupID)
+ {
+ $this->_groupID = $_groupID;
+ return $this;
+ }
public function getTitle()
{
return $this->_title;
diff --git a/application/models/PoolMapper.php b/application/models/PoolMapper.php
index 994a3fd..9b875ca 100644
--- a/application/models/PoolMapper.php
+++ b/application/models/PoolMapper.php
@@ -48,6 +48,7 @@ class Application_Model_PoolMapper
{
print_a($pol);
$data = array('poolID'=> $pol->getID() ,
+ 'groupID'=> $pol->getGroupID() ,
'title'=> $pol->getTitle() ,
'description'=> $pol->getDescription() ,
'location'=> $pol->getLocation() );
@@ -79,6 +80,7 @@ class Application_Model_PoolMapper
$row = $result->current();
$pol->setID($row->poolID)
+ ->setGroupID($row->groupID)
->setTitle($row->title)
->setDescription($row->description)
->setLocation($row->location);
@@ -91,7 +93,11 @@ class Application_Model_PoolMapper
foreach ($resultSet as $row) {
$entry = new Application_Model_Pool();
- $entry->setID($row->poolID)->setTitle($row->title)->setDescription($row->description)->setLocation($row->location);
+ $entry->setID($row->poolID)
+ ->setGroupID($row->groupID)
+ ->setTitle($row->title)
+ ->setDescription($row->description)
+ ->setLocation($row->location);
$entries[] = $entry;
}
diff --git a/application/modules/user/controllers/PoolController.php b/application/modules/user/controllers/PoolController.php
index cf4dfe7..01b5a2a 100644
--- a/application/modules/user/controllers/PoolController.php
+++ b/application/modules/user/controllers/PoolController.php
@@ -2,30 +2,133 @@
class User_PoolController extends Zend_Controller_Action
{
-
+ private $membership;
public function init()
{
- /* Initialize action controller here */
+ $membershipMapper = new Application_Model_MembershipMapper();
+ $this->membership = new Application_Model_Membership();
+ $membershipMapper->find($_SESSION['membershipID'],$this->membership);
}
public function indexAction()
- {
- // action body
+ {
+ // TODO: ACL: is he allowed to see the pools of a group
+
+ $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);
+ }
+ $result = $this->_request->getParam('addresult');
+ if($result != ""){
+ $pbsNotifier = new Pbs_Notifier();
+ $this->view->notification = $pbsNotifier->notify('create',$result);
+ }
+
+
+ $poolMapper = new Application_Model_PoolMapper();
+ $this->view->pools = $poolMapper->fetchAll();
+
+ $clientmapper = new Application_Model_ClientMapper();
+ $clients = $clientmapper->fetchAll();
+ foreach($clients as $c){
+ #$client = new Application_Model_Client($c);
+ $clientsArray[] = $c->toArray();
+ }
+ $assignedclientmapper = new Application_Model_PoolEntriesMapper();
+ $assignedclients = $assignedclientmapper->fetchAll();
+ foreach($assignedclients as $c){
+ $assignedclientsArray[] = $c->toArray();
+ }
+ $freeclients = $this->arrayDiff($clientsArray,$assignedclientsArray);
+
+ $this->view->freeclients = $freeclients;
}
- public function createpoolAction()
+ public function createpoolAction()
{
- // action body
+ // TODO: ACL: is he allowed to create a pool?
+ if (!isset($_POST["add"])){
+ $addfilterform = new user_Form_Pool(array('buttontext' => 'Create Pool'));
+ $this->view->addpool = $addfilterform;
+ }else {
+ $addpoolform = new user_Form_Pool(array('buttontext' => 'Create Pool'),$_POST);
+ if ($addpoolform->isValid($_POST)) {
+ try{
+ $pool = new Application_Model_Pool($_POST);
+ $pool->setGroupID($this->membership->getGroupID());
+ $poolmapper = new Application_Model_PoolMapper();
+ $poolmapper->save($pool);
+ $this->_redirect('/dev/pool/index/addresult/ok');
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
+ $this->_redirect('/dev/pool/index/addresult/error');
+ }
+ }
+ $this->view->addpool = $addfilterform;
+ }
}
public function deletepoolAction()
{
- // action body
+ $poolID = $this->_request->getParam('poolID');
+ // TODO: ACL: is he allowed to delete a pool?
+ #if( he is allowed){
+ if(is_numeric($poolID)){
+ $poolmapper = new Application_Model_PoolMapper();
+ $pool = new Application_Model_Pool();
+ $poolmapper->find($poolID,$pool);
+ if($this->membership->getGroupID() == $pool->getGroupID()){
+ $deletepool = new Application_Model_Pool();
+ $deletepool->setID($poolID);
+ $poolmapper->delete($deletepool);
+ $this->_redirect('/user/pool/index/deleteresult/ok');
+ }
+ else{
+ $this->_redirect('/user/pool/index/deleteresult/forbidden');
+ }
+ }
+ $this->_redirect('/user/pool/index/deleteresult/error');
+ #}else{
+ # $this->_redirect('/user/pool/index/deleteresult/forbidden');
+ #}
}
public function editpoolAction()
{
- // action body
+ // TODO: ACL: is he allowed to edit a pool?
+ // TODO: is he allowed to edit this pool?
+ if (!isset($_POST["add"])){
+ $poolID = $this->_request->getParam('poolID');
+ $pool = new Application_Model_Pool();
+ $poolmapper = new Application_Model_PoolMapper();
+ $poolmapper->find($poolID,$pool);
+ $poolArray = $pool->toArray();
+ $editpool = new user_Form_Pool(array('buttontext' => 'Edit Pool'));
+ $editpool->populate($poolArray);
+ $this->view->editpool = $editpool;
+
+ }else {
+ $editpoolform = new user_Form_Pool(array('buttontext' => 'Edit Pool'),$_POST);
+ if ($editpoolform->isValid($_POST)) {
+ try{
+ $pool = new Application_Model_Pool($_POST);
+ $pool->setID($this->_request->getParam('poolID'));
+ $poolmapper = new Application_Model_PoolMapper();
+ $poolmapper->save($pool);
+ $this->_redirect('/dev/pool/index/modifyresult/ok');
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
+ $this->_redirect('/dev/pool/index/modifyresult/error');
+ }
+ }
+ $this->view->editpool = $editpoolform;
+ }
}
public function linkclientAction()
@@ -37,7 +140,21 @@ class User_PoolController extends Zend_Controller_Action
{
// action body
}
-
+
+ // creates an array of two arrays
+ // first parameter is the list of all clients
+ // second parameter is the list of clients which are already in a group
+ // return value is a list of all clients, which are in no group
+ private function arrayDiff($a, $b){
+ foreach($a as $k1 => $i1){
+ foreach($b as $k2 => $i2){
+ if($i1['clientID'] == $i2['clientID']){
+ unset($a[$k1]);
+ }
+ }
+ }
+ return $a;
+ }
}
diff --git a/application/modules/user/forms/Pool.php b/application/modules/user/forms/Pool.php
new file mode 100644
index 0000000..909bdd6
--- /dev/null
+++ b/application/modules/user/forms/Pool.php
@@ -0,0 +1,54 @@
+<?php
+
+class user_Form_Pool extends Zend_Form
+{
+
+ public function init()
+ {
+ $this->setName("pool");
+ $this->setMethod('post');
+
+ $this->addElement('text', 'title', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 30)),
+ ),
+ 'required' => true,
+ 'label' => 'Title:',
+ ));
+ $this->addElement('textarea', 'description', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 140)),
+ ),
+ 'required' => false,
+ 'label' => 'Description:',
+ ));
+ // TODO: Add target of Filter
+
+ $this->addElement('text', 'location', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 30)),
+ ),
+ 'required' => true,
+ 'label' => 'Location:',
+ ));
+
+ $this->addElement('submit', 'add', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => $this->buttontext,
+ ));
+
+ $this->addElement('button', 'Cancel', array(
+ 'onclick' => 'self.location="/user/pool"'
+ ));
+ }
+ private $buttontext = 'Save';
+ function setButtontext($v){
+ $this->buttontext = $v;
+ }
+
+}
+
diff --git a/application/modules/user/views/scripts/pool/createpool.phtml b/application/modules/user/views/scripts/pool/createpool.phtml
index 3d7f8ca..305b36e 100644
--- a/application/modules/user/views/scripts/pool/createpool.phtml
+++ b/application/modules/user/views/scripts/pool/createpool.phtml
@@ -1 +1,2 @@
-<br /><br /><center>View script for controller <b>Pool</b> and script/action name <b>createpool</b></center> \ No newline at end of file
+<?php
+echo $this->addpool;
diff --git a/application/modules/user/views/scripts/pool/deletepool.phtml b/application/modules/user/views/scripts/pool/deletepool.phtml
deleted file mode 100644
index 622e663..0000000
--- a/application/modules/user/views/scripts/pool/deletepool.phtml
+++ /dev/null
@@ -1 +0,0 @@
-<br /><br /><center>View script for controller <b>Pool</b> and script/action name <b>deletepool</b></center> \ No newline at end of file
diff --git a/application/modules/user/views/scripts/pool/editpool.phtml b/application/modules/user/views/scripts/pool/editpool.phtml
index c70464e..6304037 100644
--- a/application/modules/user/views/scripts/pool/editpool.phtml
+++ b/application/modules/user/views/scripts/pool/editpool.phtml
@@ -1 +1,2 @@
-<br /><br /><center>View script for controller <b>Pool</b> and script/action name <b>editpool</b></center> \ No newline at end of file
+<?php
+echo $this->editpool;
diff --git a/application/modules/user/views/scripts/pool/index.phtml b/application/modules/user/views/scripts/pool/index.phtml
index 5266a4e..05b880a 100644
--- a/application/modules/user/views/scripts/pool/index.phtml
+++ b/application/modules/user/views/scripts/pool/index.phtml
@@ -1 +1,131 @@
-<br /><br /><center>View script for controller <b>Pool</b> and script/action name <b>index</b></center> \ No newline at end of file
+<h1>Pools</h1>
+<?php echo $this->formButton('createconfig', 'Create Pool', array(
+ 'onclick' => 'self.location="/user/pool/createpool"',
+ 'class' => 'addbutton'))?>
+
+<?php if ($this->pools): ?>
+ <table >
+ <tr>
+ <th>ID</th>
+ <th>Title</th>
+ <th>Description</th>
+ <th>Location</th>
+ <th colspan=3>Actions</th>
+ </tr>
+ <?php foreach ($this->pools as $pool): ?>
+ <tr class=entry>
+ <td><?php echo $this->escape($pool->getID()) ?></td>
+ <td><?php echo $this->escape($pool->getTitle()) ?></td>
+ <td><?php echo $this->escape($pool->getDescription()) ?></td>
+ <td><?php echo $this->escape($pool->getLocation()) ?></td>
+ <td class='action'><a href="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'pool',
+ 'action' => 'editpool',
+ 'poolID' => $pool->getID()
+ ),
+ 'default',
+ true) ?>"><img src='/media/img/edit.png' alt='Edit Pool'/></a></td>
+ <td class='action'><a href="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'pool',
+ 'action' => 'deletepool',
+ 'poolID' => $pool->getID()
+ ),
+ 'default',
+ true) ?>"><img src='/media/img/delete.png' alt='Delete Pool'/></a></td>
+ <td class='action'><a href="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'pool',
+ 'action' => 'linkclient',
+ 'poolID' => $pool->getID()
+ ),
+ 'default',
+ true) ?>"><img src='/media/img/add.png' alt='Link Client'/></a></td>
+ </tr>
+ <?php
+ $poolentriesMapper = new Application_Model_PoolEntriesMapper();
+ $clients = $poolentriesMapper->findBy('poolID',$pool->getID());
+ ?>
+ <?php if (count($clients)>0): ?>
+ <tr class=detail>
+ <td class=arrowtop>↳</td>
+ <td colspan=6>
+ <table>
+ <tr>
+ <th>ClientID</th>
+ <th>Mac</th>
+ <th>Hardwarehash</th>
+ <th>Actions</th>
+ </tr>
+ <?php
+ foreach ($clients as $client): ?>
+ <tr>
+ <td><?php echo $client['clientID'];?></td>
+ <?php
+ $cli = new Application_Model_Client();
+ $clientMapper = new Application_Model_ClientMapper();
+ $clientMapper->find($client['clientID'],$cli);
+ ?>
+ <td><?php echo ($cli->macAdress); ?></td>
+ <td><?php echo ($cli->hardwarehash); ?></td>
+ <td class='action'><a href="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'pool',
+ 'action' => 'unlinkclient',
+ 'poolentriesID' => $client['poolentriesID']
+ ),
+ 'default',
+ true) ?>"><img src='/media/img/delete.png' alt='Unlink Client'/></a></td>
+ </tr>
+ <?php endforeach ?>
+ </table>
+ </td>
+ </tr>
+ <?php endif;?>
+ <?php endforeach ?>
+ </table>
+<h2>Free clients</h2>
+<table >
+<tr>
+<th>ClientID</th>
+<th>MacAdress</th>
+<th>Hardwarehash</th>
+<th>Actions</th>
+</tr>
+<?php
+foreach ($this->freeclients as $client): ?>
+ <tr>
+ <td><?php echo $client['clientID']; ?></td>
+ <td><?php echo $client['macadress']; ?></td>
+ <td><?php echo $client['hardwarehash']; ?></td>
+ <td><select onChange="location.href=this.options[this.selectedIndex].value">
+ <option></option>
+ <?php foreach ($this->pools as $pool): ?>
+ <option value="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'pool',
+ 'action' => 'linkclient',
+ 'clientID' => $client['clientID'],
+ 'poolID' => $pool->getID(),
+ ),
+ 'default',
+ true) ?>"><?php echo $pool->getTitle(); ?></option>
+ <?php //<img src='/media/img/add.png' alt='Link to Pool'/></a></td> ?>
+ <?php endforeach ?>
+ </select>
+ </td>
+ </tr>
+<?php endforeach ?>
+</table>
+<?php else: ?>
+
+
+ <p>There are no pools to display.</p>
+
+<?php endif;?>
diff --git a/pbs-newdata.sql b/pbs-newdata.sql
index 1abb07c..a412195 100644
--- a/pbs-newdata.sql
+++ b/pbs-newdata.sql
@@ -60,12 +60,11 @@ INSERT INTO `pbs_bootiso` (`bootisoID`, `title`, `membershipID`, `groupID`, `pat
(3, 'BootIso 3', 1, 1, 'Path 3', 2147483647, '1299693899', '2012-03-09', 0);
-- Adding Pools
-INSERT INTO `pbs_pool` (`poolID`, `title`, `description`, `location`) VALUES
-(1, 'Pool 1', 'Description 1', 'Keller'),
-(2, 'Pool 2', 'Description 2', 'EG'),
-(3, 'Pool 3', 'Description 3', '1 OG'),
-(4, 'Pool 4', 'Description', '2 OG');
-
+INSERT INTO `pbs_pool` (`poolID`, `groupID`, `title`, `description`, `location`) VALUES
+(1, 1, 'Pool 1', 'Description 1', 'Keller'),
+(2, 1, 'Pool 2', 'Description 2', 'EG'),
+(3, 1, 'Pool 3', 'Description 3', '1 OG');
+(4, 1, 'Pool 4', 'Description 4', '2 OG');
-- Adding Bootmenus
INSERT INTO `pbs_bootmenu` (`bootmenuID`, `membershipID`, `groupID`, `title`, `created`) VALUES
diff --git a/pbs.sql b/pbs.sql
index 2b3a198..58c21b2 100644
--- a/pbs.sql
+++ b/pbs.sql
@@ -242,6 +242,9 @@ CREATE TABLE IF NOT EXISTS `pbs_pool` (
`location` varchar(30),
PRIMARY KEY (`poolID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
+ALTER TABLE `pbs_pool` ADD `groupID` INT NOT NULL AFTER `poolID`;
+ALTER TABLE `pbs_pool`
+ ADD CONSTRAINT `pbs_pool_ibfk_1` FOREIGN KEY (`groupID`) REFERENCES `pbs_group` (`groupID`) ON DELETE CASCADE;
CREATE TABLE IF NOT EXISTS `pbs_poolentries` (
`poolID` int(11) NOT NULL,