summaryrefslogtreecommitdiffstats
path: root/application/controllers
diff options
context:
space:
mode:
authormichael pereira2011-03-08 19:41:07 +0100
committermichael pereira2011-03-08 19:41:07 +0100
commit6a917fa16d4aabd8e69e1db08867899c860424e1 (patch)
tree5aee03f6bf1810ec340110df55fd1edacf44f592 /application/controllers
parentBootOs Name anzeigen & Reihenfolge im BootMenu (diff)
parentansehnlichere oberfläche && Controller auflistung (diff)
downloadpbs2-6a917fa16d4aabd8e69e1db08867899c860424e1.tar.gz
pbs2-6a917fa16d4aabd8e69e1db08867899c860424e1.tar.xz
pbs2-6a917fa16d4aabd8e69e1db08867899c860424e1.zip
Merge branch 'master' of openslx.org:lsfks/master-teamprojekt/pbs2
Diffstat (limited to 'application/controllers')
-rw-r--r--application/controllers/AuthController.php180
-rw-r--r--application/controllers/FilterController.php98
-rw-r--r--application/controllers/IndexController.php5
-rw-r--r--application/controllers/PoolController.php28
-rw-r--r--application/controllers/SessionController.php105
5 files changed, 294 insertions, 122 deletions
diff --git a/application/controllers/AuthController.php b/application/controllers/AuthController.php
index fd30d82..c43e5a9 100644
--- a/application/controllers/AuthController.php
+++ b/application/controllers/AuthController.php
@@ -5,82 +5,86 @@ class AuthController extends Zend_Controller_Action
public function init()
{
- $db = Zend_Db_Table::getDefaultAdapter();
-
+ $db = Zend_Db_Table::getDefaultAdapter();
}
-
+
+ public function indexAction()
+ {
+ $this->_redirect('/auth/login');
+ }
+
public function loginAction()
- {
- if (!isset($_POST["login"])){
- $loginForm = new Application_Form_AuthLogin();
- } else {
- $loginForm = new Application_Form_AuthLogin($_POST);
-
- if ($loginForm->isValid($_POST)) {
-
- $auth = Zend_Auth::getInstance();
-
- $adapter = new Zend_Auth_Adapter_DbTable(
- $db,
- 'pbs_person',
- 'email',
- 'password',
- 'MD5(CONCAT(?, password_salt))'
- );
-
-
- $adapter->setIdentity($loginForm->getValue('email'));
- $adapter->setCredential($loginForm->getValue('password'));
-
- $result = $auth->authenticate($adapter);
-
- // TODO: erweiterte fehlerbeschreibung des Users
-
- if ($result->isValid()) {
- $this->_redirect('/');
- return;
- } else {
- echo "Falsche Email oder Passwort";
- }
- }
- }
-
- $this->view->loginForm = $loginForm;
+ {
+ if (!isset($_POST["login"])){
+ $loginForm = new Application_Form_AuthLogin();
+ } else {
+ $loginForm = new Application_Form_AuthLogin($_POST);
+
+ if ($loginForm->isValid($_POST)) {
+
+ $auth = Zend_Auth::getInstance();
+
+ $adapter = new Zend_Auth_Adapter_DbTable(
+ $db,
+ 'pbs_person',
+ 'email',
+ 'password',
+ 'MD5(CONCAT(?, password_salt))'
+ );
+
+
+ $adapter->setIdentity($loginForm->getValue('email'));
+ $adapter->setCredential($loginForm->getValue('password'));
+
+ $result = $auth->authenticate($adapter);
+
+ // TODO: erweiterte fehlerbeschreibung des Users
+
+ if ($result->isValid()) {
+ $this->_redirect('/');
+ return;
+ } else {
+ echo "Falsche Email oder Passwort";
+ }
+ }
+ }
+
+ $this->view->loginForm = $loginForm;
}
public function registerAction()
- {
- if (!isset($_POST["register"])){
- $registerForm = new Application_Form_AuthRegister();
- } else {
- $registerForm = new Application_Form_AuthRegister($_POST);
-
- if ($registerForm->isValid($_POST)) {
-
- $person = new Application_Model_Person($_POST);
- $personmapper = new Application_Model_PersonMapper();
-
- $date = new DateTime();
- $person->setRegisterdate($date->getTimestamp());
- $person->setPasswordSalt(MD5($date->getTimestamp()));
- $person->setPassword(MD5($person->getPassword() . $person->getPasswordSalt()));
-
- try {
- $personmapper->save($person);
- }catch(Zend_Exception $e)
- {
- echo "Caught exception: " . get_class($e) . "<br/>";
- echo "Message: " . $e->getMessage() . "<br/>";
- echo "Email Adresse bereits vorhanden.";
- return;
- }
- echo "Erfolgreich registriert. <br/>";
- echo "Weiter zum Login: <a href=\""."/auth/login"."\">Login</a>";
- return;
- }
- }
-
- $this->view->registerForm = $registerForm;
+ {
+ if (!isset($_POST["register"])){
+ $registerForm = new Application_Form_AuthRegister();
+ } else {
+ $registerForm = new Application_Form_AuthRegister($_POST);
+
+ if ($registerForm->isValid($_POST)) {
+
+ $person = new Application_Model_Person($_POST);
+ $personmapper = new Application_Model_PersonMapper();
+
+ $date = new DateTime();
+ $person->setRegisterdate($date->getTimestamp());
+ $person->setPasswordSalt(MD5($date->getTimestamp()));
+ $person->setPassword(MD5($person->getPassword() . $person->getPasswordSalt()));
+
+ try {
+ $personmapper->save($person);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ echo "Email Adresse bereits vorhanden.";
+ return;
+ }
+ echo "Erfolgreich registriert. <br/>";
+ echo "Weiter zum Login: <a href=\""."/auth/login"."\">Login</a>";
+ return;
+ }
+ }
+
+ $this->view->registerForm = $registerForm;
}
public function logoutAction()
@@ -96,23 +100,23 @@ class AuthController extends Zend_Controller_Action
public function deleteAction()
{
if (!isset($_POST["delete"])){
- $deleteForm = new Application_Form_AuthDelete();
- } else {
- $deleteForm = new Application_Form_AuthDelete($_POST);
-
- if ($deleteForm->isValid($_POST)) {
-
- $person = new Application_Model_Person($_POST);
- $personmapper = new Application_Model_PersonMapper();
-
-
- $personmapper->delete($person);
- }
- }
-
- $this->view->deleteForm = $deleteForm;
-
+ $deleteForm = new Application_Form_AuthDelete();
+ } else {
+ $deleteForm = new Application_Form_AuthDelete($_POST);
+
+ if ($deleteForm->isValid($_POST)) {
+
+ $person = new Application_Model_Person($_POST);
+ $personmapper = new Application_Model_PersonMapper();
+
+
+ $personmapper->delete($person);
+ }
+ }
+
+ $this->view->deleteForm = $deleteForm;
}
+
}
@@ -122,3 +126,5 @@ class AuthController extends Zend_Controller_Action
+
+
diff --git a/application/controllers/FilterController.php b/application/controllers/FilterController.php
index df8db07..1ebb35e 100644
--- a/application/controllers/FilterController.php
+++ b/application/controllers/FilterController.php
@@ -42,8 +42,7 @@ class FilterController extends Zend_Controller_Action
// TODO: Ändere mit ACL
$newfilter->setGroupID('1');
- $newfilter->setMembershipID('1');
- $newfilter->setBootmenuID('1');
+ $newfilter->setMembershipID('1');
$newfilter2 = new Application_Model_FilterMapper();
$newfilter2->save($newfilter);
@@ -95,7 +94,6 @@ class FilterController extends Zend_Controller_Action
//TODO: ACL integrieren
$_POST['groupID'] = 1;
$_POST['membershipID'] = 1;
- $_POST['bootmenuID'] = 1;
$_POST['created'] = time();
if ($editfilterform->isValid($_POST)) {
@@ -262,11 +260,18 @@ class FilterController extends Zend_Controller_Action
$db = $this->db;
$showPartResults = false;
try{
+
+ $mysession = '1';
+
+ $filtertypID = 8;
+ $session = new Application_Model_Session();
+ $sessionmapper = new Application_Model_SessionMapper();
+ $sessionmapper->find($mysession,$session);
#########################################################
// IP Adress
$filtertypID = 1;
// get it from session_table with session_id from the session
- $ipAdress = "111.10.10.10";
+ $ipAdress = $session->getIp();
$ipAdress = str_replace(".","",$this->fillIP($ipAdress));
$select = $db->select()
->from(array('pbs_filterentries')
@@ -281,13 +286,16 @@ class FilterController extends Zend_Controller_Action
$set[$filtertypID][] = $r['filterID'];
}
if($showPartResults)
- print_a('ipAdress',$result,$set[$filtertypID]);
-
+ print_a('ipAdress',$result,$set[$filtertypID]);
#########################################################
// Mac range
$filtertypID = 2;
// get it from session_table with session_id from the session
- $macAdress = "00:1e:0b:27:f4:99";
+ $client = new Application_Model_Client();
+ $clientmapper = new Application_Model_ClientMapper();
+ $clientmapper->find($session->getClientID(),$client);
+
+ $macAdress = $client->getMacadress();
$macAdress = str_replace(":","",$this->fillMac($ipAdress));
$stmt = $db->query("SELECT * FROM pbs_filterentries WHERE
filtertypeID = ".$filtertypID." AND
@@ -303,47 +311,81 @@ class FilterController extends Zend_Controller_Action
// PoolID
$filtertypID = 3;
// get PoolID from client_ID from session_id from the session
- $poolid = 1;
+ $poolentry = new Application_Model_PoolEntries();
+ $poolentrymapper = new Application_Model_PoolEntriesMapper();
+ $poolentry = $poolentrymapper->findby('clientID',$client->getID());
+ $poolentry = $poolentry[0];
+
+ $poolID = $poolentry['poolID'];
+ print_a($poolentry);
$stmt = $db->query("SELECT * FROM pbs_filterentries WHERE
filtertypeID = ".$filtertypID." AND
- filtervalue = '.$poolid.' ");
+ filtervalue = ".$poolID." ");
$result = $stmt->fetchAll();
foreach($result as $r){
$set[$filtertypID][] = $r['filterID'];
}
if($showPartResults)
print_a('poolID',$result,$set[$filtertypID]);
- /*
- If client comes from a specific pool
- */
#########################################################
- // ClientID
- $filtertypID = 8;
- // get client_ID from session_id from the session
- /*
- If client is a specific client
- */
+ // ClientID
+ $filtertypID = 8;
+ // get client_ID from session_id from the session
+ $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE
+ filtertypeID = ".$filtertypID." AND
+ filtervalue = ".$session->getClientID()." ");
+ $result = $stmt->fetchAll();
+ foreach($result as $r){
+ $set[$filtertypID][] = $r['filterID'];
+ }
+ if($showPartResults)
+ print_a('clientID',$result,$set[$filtertypID]);
#########################################################
// BootIsoID
$filtertypID = 4;
- // get BootIsoID from client_ID from session_id from the session
- /*
- WHERE bootiso = bootiso
- */
+ // get BootIsoID from client_ID from session_id from the session
+ $bootisoID = $session->getBootisoID();
+ $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE
+ filtertypeID = ".$filtertypID." AND
+ filtervalue = ".$bootisoID." ");
+ $result = $stmt->fetchAll();
+ foreach($result as $r){
+ $set[$filtertypID][] = $r['filterID'];
+ }
+ if($showPartResults)
+ print_a('bootisoID',$result,$set[$filtertypID]);
#########################################################
// MembershipID
$filtertypID = 5;
// get membership from the session
- /*
- user is in a defined membership
- */
+ //TODO: GET MEMBERSHIP from SESSION
+ $membershipID = 1;
+
+ $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE
+ filtertypeID = ".$filtertypID." AND
+ filtervalue = ".$membershipID." ");
+ $result = $stmt->fetchAll();
+ foreach($result as $r){
+ $set[$filtertypID][] = $r['filterID'];
+ }
+ if($showPartResults)
+ print_a('membership',$result,$set[$filtertypID]);
#########################################################
// GroupID
$filtertypID = 6;
// get membership from the session
- /*
- user is in a defined groupID
- */
+ //TODO: GET GROUP from SESSION
+ $groupID = 1;
+
+ $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE
+ filtertypeID = ".$filtertypID." AND
+ filtervalue = ".$groupID." ");
+ $result = $stmt->fetchAll();
+ foreach($result as $r){
+ $set[$filtertypID][] = $r['filterID'];
+ }
+ if($showPartResults)
+ print_a('membership',$result,$set[$filtertypID]);
#########################################################
// Time
$filtertypID = 7;
diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php
index 1ff6319..df2f91c 100644
--- a/application/controllers/IndexController.php
+++ b/application/controllers/IndexController.php
@@ -11,11 +11,12 @@ class IndexController extends Zend_Controller_Action
public function indexAction()
{
// action body
- }
-
+ }
}
+
+
diff --git a/application/controllers/PoolController.php b/application/controllers/PoolController.php
index 28bde8e..cb38a80 100644
--- a/application/controllers/PoolController.php
+++ b/application/controllers/PoolController.php
@@ -13,8 +13,21 @@ class PoolController extends Zend_Controller_Action
$poolMapper = new Application_Model_PoolMapper();
$this->view->pools = $poolMapper->fetchAll();
- $poolentriesMapper = new Application_Model_PoolEntriesMapper();
- #print_a($poolentriesMapper->findBy('poolID',1));
+ $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);
+ #print_a($freeclients);
+
+ $this->view->freeclients = $freeclients;
}
@@ -84,12 +97,15 @@ class PoolController extends Zend_Controller_Action
public function linkclientAction()
{
- if(!isset($_POST['clientID'])){
+ $clientID = $this->_request->getParam('clientID');
+ $poolID = $this->_request->getParam('poolID');
+ print_a($clientID,$poolID);
+
+ if(!isset($_POST['clientID']) && ($clientID == '' && $poolID == '')){
print_a($_POST);
$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();
@@ -108,7 +124,9 @@ class PoolController extends Zend_Controller_Action
try{
$pool = new Application_Model_PoolEntries($_POST);
$pool->setPoolID($this->_request->getParam('poolID'));
-
+ if($pool->getClientID() == ''){
+ $pool->setClientID($this->_request->getParam('clientID'));
+ }
$poolmapper = new Application_Model_PoolEntriesMapper();
$poolmapper->save($pool);
$this->_redirect('/pool');
diff --git a/application/controllers/SessionController.php b/application/controllers/SessionController.php
new file mode 100644
index 0000000..fc3b962
--- /dev/null
+++ b/application/controllers/SessionController.php
@@ -0,0 +1,105 @@
+<?php
+
+class SessionController extends Zend_Controller_Action
+{
+
+ public function init()
+ {
+ /* Initialize action controller here */
+ }
+
+ public function indexAction()
+ {
+ $mapper = new Application_Model_SessionMapper();
+ $this->view->sessions = $mapper->fetchAll();
+ }
+
+ public function createsessionAction()
+ {
+ 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()
+ {
+ 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()
+ {
+ $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');
+ }
+
+
+}
+
+
+
+
+
+
+