summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon2011-03-08 16:40:30 +0100
committerSimon2011-03-08 16:40:30 +0100
commit90daca1a5ec239dfb7f44e54f1c22cf299181143 (patch)
treea8e91fd36e90e8a5dcedfcaeaa92099b5ca962f8
parentsession hinzugefügt (diff)
downloadpbs2-90daca1a5ec239dfb7f44e54f1c22cf299181143.tar.gz
pbs2-90daca1a5ec239dfb7f44e54f1c22cf299181143.tar.xz
pbs2-90daca1a5ec239dfb7f44e54f1c22cf299181143.zip
create, edit, delete session - fehlt noch mit selectboxen && sql-data abgeändert
-rw-r--r--.zfproject.xml1
-rw-r--r--application/controllers/SessionController.php74
-rw-r--r--application/forms/Session.php70
-rw-r--r--application/models/Session.php10
-rw-r--r--application/models/SessionMapper.php24
-rw-r--r--application/views/scripts/session/createsession.phtml6
-rw-r--r--application/views/scripts/session/editsession.phtml6
-rw-r--r--application/views/scripts/session/index.phtml49
-rw-r--r--pbs-data.sql8
-rw-r--r--pbs.sql2
10 files changed, 233 insertions, 17 deletions
diff --git a/.zfproject.xml b/.zfproject.xml
index 373017a..844ba10 100644
--- a/.zfproject.xml
+++ b/.zfproject.xml
@@ -100,6 +100,7 @@
<formFile formName="Pool"/>
<formFile formName="PoolClient"/>
<formFile formName="Client"/>
+ <formFile formName="Session"/>
</formsDirectory>
<layoutsDirectory enabled="false"/>
<modelsDirectory>
diff --git a/application/controllers/SessionController.php b/application/controllers/SessionController.php
index 382e68e..fc3b962 100644
--- a/application/controllers/SessionController.php
+++ b/application/controllers/SessionController.php
@@ -10,22 +10,88 @@ class SessionController extends Zend_Controller_Action
public function indexAction()
{
- // action body
+ $mapper = new Application_Model_SessionMapper();
+ $this->view->sessions = $mapper->fetchAll();
}
public function createsessionAction()
{
- // action body
+ if (!isset($_POST["add"])){
+ $createsession = new Application_Form_Session();
+ $this->view->createsession = $createsession;
+ }else {
+ $createsession = new Application_Form_Session($_POST);
+ print_a($_POST);
+ if ($createsession->isValid($_POST)) {
+ try{
+ $session = new Application_Model_Session($_POST);
+ $sessionmapper = new Application_Model_SessionMapper();
+ $sessionmapper->save($session);
+
+ $this->_redirect('/session');
+
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
+ }
+ print_a('saved');
+ $this->_redirect('/session');
+ }
+ else{
+ print_a('not saved');
+ }
+ }
}
public function editsessionAction()
{
- // action body
+ if (!isset($_POST["add"])){
+ // TODO: ACL implementieren ob er editieren darf
+ $sessionID = $this->_request->getParam('sessionID');
+ $session = new Application_Model_Session();
+
+
+ $sessionmapper = new Application_Model_SessionMapper();
+ $sessionmapper->find($sessionID,$session);
+ $session2 = $session->toArray();
+
+ $editsession = new Application_Form_Session();
+ $editsession->populate($session2);
+ $this->view->editsession = $editsession;
+
+ } else{
+ try{
+ $sessionID = $this->_request->getParam('sessionID');
+
+ $editsession = new Application_Form_Session($_POST);
+
+ if ($editsession->isValid($_POST)) {
+ $session = new Application_Model_Session($_POST);
+ $session->setID($this->_request->getParam('sessionID'));
+ $sessionmapper = new Application_Model_SessionMapper();
+ $sessionmapper->save($session);
+ echo 'valid';
+ }
+ else
+ {
+ echo 'not valid';
+ }
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
+ }
+ $this->_redirect('/session');
+ }
}
public function deletesessionAction()
{
- // action body
+ $sessionID = $this->_request->getParam('sessionID');
+ if(is_numeric($sessionID)){
+ $deletesession = new Application_Model_Session();
+ $deletesession->setID($sessionID);
+ $sessionmapper = new Application_Model_SessionMapper();
+ $sessionmapper->delete($deletesession);
+ }
+ $this->_redirect('/session');
}
diff --git a/application/forms/Session.php b/application/forms/Session.php
new file mode 100644
index 0000000..f094676
--- /dev/null
+++ b/application/forms/Session.php
@@ -0,0 +1,70 @@
+<?php
+
+class Application_Form_Session extends Zend_Form
+{
+
+ public function init()
+ {
+ $this->setName("session");
+ $this->setMethod('post');
+
+ $this->addElement('text', 'clientID', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'clientID:',
+ ));
+
+ $this->addElement('text', 'bootosID', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'bootosID:',
+ ));
+$this->addElement('text', 'bootisoID', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'bootisoID:',
+ ));
+$this->addElement('text', 'time', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'time:',
+ ));
+$this->addElement('text', 'ip', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => false,
+ 'label' => 'ip:',
+ ));
+$this->addElement('text', 'ip6', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => false,
+ 'label' => 'ip6:',
+ ));
+
+ $this->addElement('submit', 'add', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Save',
+ ));
+ }
+
+
+}
+
diff --git a/application/models/Session.php b/application/models/Session.php
index b042c17..ca07ccb 100644
--- a/application/models/Session.php
+++ b/application/models/Session.php
@@ -5,6 +5,7 @@ class Application_Model_Session
protected $_sessionID;
protected $_clientID;
protected $_bootosID;
+ protected $_bootisoID;
protected $_time;
protected $_ip;
protected $_ip6;
@@ -74,6 +75,15 @@ class Application_Model_Session
$this->_bootosID = $_bootosID;
return $this;
}
+ public function getBootisoID()
+ {
+ return $this->_bootisoID;
+ }
+ public function setBootisoID($_bootisoID)
+ {
+ $this->_bootisoID = $_bootisoID;
+ return $this;
+ }
public function getTime()
{
return $this->_time;
diff --git a/application/models/SessionMapper.php b/application/models/SessionMapper.php
index 57b2fdf..f836643 100644
--- a/application/models/SessionMapper.php
+++ b/application/models/SessionMapper.php
@@ -44,16 +44,22 @@ class Application_Model_SessionMapper
return $this->_dbTable;
}
- public function save(Application_Model_Session $sesion)
+ public function save(Application_Model_Session $session)
{
- $data = array('sessionID'=> $sesion->getSessionID() ,'clientID'=> $sesion->getClientID() ,'bootosID'=> $sesion->getBootosID() ,'time'=> $sesion->getTime() ,'ip'=> $sesion->getIp() ,'ip6'=> $sesion->getIp6() );
-
- if (null === ($id = $sesion->getID()) ) {
- unset($data['sesionID']);
+ $data = array( 'sessionID'=> $session->getID() ,
+ 'clientID'=> $session->getClientID() ,
+ 'bootosID'=> $session->getBootosID() ,
+ 'bootisoID'=> $session->getBootisoID() ,
+ 'time'=> $session->getTime() ,
+ 'ip'=> $session->getIp() ,
+ 'ip6'=> $session->getIp6() );
+ print_a($data);
+ if (null === ($id = $session->getID()) ) {
+ unset($data['sessionID']);
$this->getDbTable()->insert($data);
} else {
- $this->getDbTable()->update($data, array('sesionID = ?' => $id));
+ $this->getDbTable()->update($data, array('sessionID = ?' => $id));
}
}
@@ -62,7 +68,7 @@ class Application_Model_SessionMapper
if (null === ($id = $sesion->getID()) ) {
return;
} else {
- $this->getDbTable()->delete(array('sesionID = ?' => $id));
+ $this->getDbTable()->delete(array('sessionID = ?' => $id));
}
}
@@ -75,7 +81,7 @@ class Application_Model_SessionMapper
$row = $result->current();
- $sesion->setSessionID($row->sessionID)->setClientID($row->clientID)->setBootosID($row->bootosID)->setTime($row->time)->setIp($row->ip)->setIp6($row->ip6);
+ $sesion->setID($row->sessionID)->setClientID($row->clientID)->setBootosID($row->bootosID)->setBootisoID($row->bootisoID)->setTime($row->time)->setIp($row->ip)->setIp6($row->ip6);
}
public function fetchAll()
@@ -85,7 +91,7 @@ class Application_Model_SessionMapper
foreach ($resultSet as $row) {
$entry = new Application_Model_Session();
- $entry->setSessionID($row->sessionID)->setClientID($row->clientID)->setBootosID($row->bootosID)->setTime($row->time)->setIp($row->ip)->setIp6($row->ip6);
+ $entry->setID($row->sessionID)->setClientID($row->clientID)->setBootosID($row->bootosID)->setBootisoID($row->bootisoID)->setTime($row->time)->setIp($row->ip)->setIp6($row->ip6);
$entries[] = $entry;
}
diff --git a/application/views/scripts/session/createsession.phtml b/application/views/scripts/session/createsession.phtml
index 81c476e..11fe7ce 100644
--- a/application/views/scripts/session/createsession.phtml
+++ b/application/views/scripts/session/createsession.phtml
@@ -1 +1,5 @@
-<br /><br /><center>View script for controller <b>Session</b> and script/action name <b>createsession</b></center> \ No newline at end of file
+<h1>create session</h1>
+
+<?php
+echo $this->createsession;
+?>
diff --git a/application/views/scripts/session/editsession.phtml b/application/views/scripts/session/editsession.phtml
index 987a332..88fb273 100644
--- a/application/views/scripts/session/editsession.phtml
+++ b/application/views/scripts/session/editsession.phtml
@@ -1 +1,5 @@
-<br /><br /><center>View script for controller <b>Session</b> and script/action name <b>editsession</b></center> \ No newline at end of file
+<h1>edit session</h1>
+
+<?php
+echo $this->editsession;
+?>
diff --git a/application/views/scripts/session/index.phtml b/application/views/scripts/session/index.phtml
index fe3c2d4..d26e818 100644
--- a/application/views/scripts/session/index.phtml
+++ b/application/views/scripts/session/index.phtml
@@ -1 +1,48 @@
-<br /><br /><center>View script for controller <b>Session</b> and script/action name <b>index</b></center> \ No newline at end of file
+<h1>Session</h1>
+
+<p><a href="<?php echo $this->url(
+ array(
+ 'controller' => 'session',
+ 'action' => 'createsession'
+ ),
+ 'default',
+ true) ?>">create new session</a></p>
+
+<table border=1>
+<tr>
+ <th>SessionID</th>
+ <th>ClientID</th>
+ <th>BootosID</th>
+ <th>BootIsoID</th>
+ <th>Time</th>
+ <th>IP</th>
+ <th>IPv6</th>
+</tr>
+<?php foreach ($this->sessions as $session): ?>
+ <tr>
+ <td><?php echo $this->escape($session->getID()) ?></td>
+ <td><?php echo $this->escape($session->getClientID()) ?></td>
+ <td><?php echo $this->escape($session->getBootosID()) ?></td>
+ <td><?php echo $this->escape($session->getBootisoID()) ?></td>
+ <td><?php echo $this->escape($session->getTime()) ?></td>
+ <td><?php echo $this->escape($session->getIp()) ?></td>
+ <td><?php echo $this->escape($session->getIp6()) ?></td>
+ <td><a href="<?php echo $this->url(
+ array(
+ 'controller' => 'session',
+ 'action' => 'editsession',
+ 'sessionID' => $session->getID()
+ ),
+ 'default',
+ true) ?>">edit filter</a></td>
+ <td><a href="<?php echo $this->url(
+ array(
+ 'controller' => 'session',
+ 'action' => 'deletesession',
+ 'sessionID' => $session->getID()
+ ),
+ 'default',
+ true) ?>">delete filter</a></td>
+ </tr>
+<?php endforeach ?>
+</table>
diff --git a/pbs-data.sql b/pbs-data.sql
index ec7dd03..52a174a 100644
--- a/pbs-data.sql
+++ b/pbs-data.sql
@@ -63,3 +63,11 @@ INSERT INTO `pbs_poolentries` (`poolentriesID`, `poolID`, `clientID`) VALUES
(9, 3, 9),
(10, 3, 10);
+-- Insert Data for Sessions
+INSERT INTO `pbs`.`pbs_bootos` (`bootosID`, `configID`, `groupID`, `membershipID`, `title`, `description`, `path_init`, `path_kernel`, `defaultkcl`, `created`, `expires`, `public`) VALUES
+(1, NULL, 1, 1, 'BootOS 1', 'Description', '', '', '', '', NULL, 0);
+
+INSERT INTO `pbs_bootiso` (`bootisoID`, `title`, `membershipID`, `groupID`, `path`, `serialnumber`, `created`, `expires`, `public`) VALUES
+(1, 'BootISO 1', 1, 1, '', 1337, '', NULL, 1),
+(2, 'BootISO 2', 1, 1, '', 1337, '', NULL, 1);
+
diff --git a/pbs.sql b/pbs.sql
index 099ea65..bc38d7c 100644
--- a/pbs.sql
+++ b/pbs.sql
@@ -214,7 +214,7 @@ CREATE TABLE IF NOT EXISTS `pbs_session` (
KEY `clientID` (`clientID`),
KEY `bootosID` (`bootosID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
-ALTER TABLE `pbs_session` ADD `bootisoID` INT NOT NULL AFTER `bootosID`
+ALTER TABLE `pbs_session` ADD `bootisoID` INT NOT NULL AFTER `bootosID`;
ALTER TABLE `pbs_session`
ADD CONSTRAINT `pbs_session_ibfk_1` FOREIGN KEY (`clientID`) REFERENCES `pbs_client` (`clientID`),