From b5cbdd6b400aa1ec77c9846e9cc8d4257f437e3c Mon Sep 17 00:00:00 2001
From: Simon
Date: Mon, 14 Mar 2011 16:09:03 +0100
Subject: Application in 3 Modules gesplittet, Dev = unsere
entwicklungsumgebung, user = die weboberfläche fr anwender mit acl etc, fbgui
= für die fbgui truppe - links in dev müssen noch angepasst werden
---
.../modules/dev/controllers/AuthController.php | 169 +++++
.../modules/dev/controllers/BootisoController.php | 125 ++++
.../modules/dev/controllers/BootmenuController.php | 328 ++++++++++
.../modules/dev/controllers/BootosController.php | 147 +++++
.../modules/dev/controllers/ClientController.php | 90 +++
.../modules/dev/controllers/ConfigController.php | 126 ++++
.../modules/dev/controllers/ErrorController.php | 51 ++
.../modules/dev/controllers/FilterController.php | 680 +++++++++++++++++++++
.../modules/dev/controllers/GroupController.php | 242 ++++++++
.../modules/dev/controllers/IndexController.php | 22 +
.../modules/dev/controllers/PersonController.php | 154 +++++
.../modules/dev/controllers/PoolController.php | 176 ++++++
.../modules/dev/controllers/ResourceController.php | 192 ++++++
.../modules/dev/controllers/RoleController.php | 64 ++
.../modules/dev/controllers/SessionController.php | 182 ++++++
15 files changed, 2748 insertions(+)
create mode 100644 application/modules/dev/controllers/AuthController.php
create mode 100644 application/modules/dev/controllers/BootisoController.php
create mode 100644 application/modules/dev/controllers/BootmenuController.php
create mode 100644 application/modules/dev/controllers/BootosController.php
create mode 100644 application/modules/dev/controllers/ClientController.php
create mode 100644 application/modules/dev/controllers/ConfigController.php
create mode 100644 application/modules/dev/controllers/ErrorController.php
create mode 100644 application/modules/dev/controllers/FilterController.php
create mode 100644 application/modules/dev/controllers/GroupController.php
create mode 100644 application/modules/dev/controllers/IndexController.php
create mode 100644 application/modules/dev/controllers/PersonController.php
create mode 100644 application/modules/dev/controllers/PoolController.php
create mode 100644 application/modules/dev/controllers/ResourceController.php
create mode 100644 application/modules/dev/controllers/RoleController.php
create mode 100644 application/modules/dev/controllers/SessionController.php
(limited to 'application/modules/dev/controllers')
diff --git a/application/modules/dev/controllers/AuthController.php b/application/modules/dev/controllers/AuthController.php
new file mode 100644
index 0000000..097417b
--- /dev/null
+++ b/application/modules/dev/controllers/AuthController.php
@@ -0,0 +1,169 @@
+db = Zend_Db_Table::getDefaultAdapter();
+ $this->personmapper = new Application_Model_PersonMapper();
+ }
+
+ public function indexAction()
+ {
+ $this->_helper->redirector('login', 'auth');
+ }
+
+ public function loginAction()
+ {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+ print_a('Already logged in.');
+ } else {
+ 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(
+ $this->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->personmapper = new Application_Model_PersonMapper();
+ $result = $this->personmapper->findBy('email', Zend_Auth::getInstance()->getIdentity());
+ $person = new Application_Model_Person($result[0]);
+ $person->setID($result[0]['personID']);
+ $date = new DateTime();
+ $person->setLogindate($date->getTimestamp());
+ $this->personmapper->save($person);
+ $this->_redirect('/');
+ return;
+ } else {
+ echo "Wrong Email or Password.";
+ }
+ }
+ }
+
+ $this->view->loginForm = $loginForm;
+ }
+ }
+
+ public function registerAction()
+ {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+ print_a('Already logged in.');
+ } else {
+ 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);
+ $this->personmapper = new Application_Model_PersonMapper();
+
+ $date = new DateTime();
+ $person->setRegisterdate($date->getTimestamp());
+ $person->setPasswordSalt(MD5($date->getTimestamp()));
+ $person->setPassword(MD5($person->getPassword() . $person->getPasswordSalt()));
+ print_a($person);
+ try {
+ $this->personmapper->save($person);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+ echo "Email Address already existing..";
+ return;
+ }
+ echo "Successfully registered.
";
+ echo "Continue to Login: Login";
+ $this->_helper->redirector('login', 'auth');
+ return;
+ }
+ }
+
+ $this->view->registerForm = $registerForm;
+ }
+ }
+
+ public function logoutAction()
+ {
+ $auth = Zend_Auth::getInstance();
+ $auth->clearIdentity();
+ $this->_helper->redirector('login', 'auth');
+ }
+
+ public function recoverpasswordAction()
+ {
+ if (!isset($_POST["recoverPassword"])){
+ $recoverPasswordForm = new Application_Form_AuthRecoverPassword();
+ } else {
+ $recoverPasswordForm = new Application_Form_AuthRecoverPassword($_POST);
+ # Wiederherstellung funktioniert noch nicht!!!
+ /*if ($recoverPasswordForm->isValid($_POST)) {
+ $recoverPasswordForm->getView()->url();
+ $person = new Application_Model_Person($_POST);
+ $this->personmapper = new Application_Model_PersonMapper();
+
+ $result = $this->personmapper->findBy('email', $_POST['email']);
+ $email = $result[0]['email'];
+ $name = $result[0]['firstname'] . ' ' . $result[0]['name'];
+ $url = $this->getRequest()->getScheme() . '://' . $this->getRequest()->getHttpHost() . $this->view->url();
+ $recoverid = $this->random(100);
+ $mailbody = 'Um das Passwort zu ändern klicken Sie auf folgenden Link
Passwort ändern';
+ $mail = new Zend_Mail();
+ $mail->setBodyHtml($mailbody, 'utf8');
+ $mail->getBodyHtml()->getContent();
+ $mail->setFrom('admin@local', 'Admin');
+ $mail->addTo($email, $name);
+ $mail->setSubject('Password Wiederherstellung Preboot Server');
+ $mail->send();
+ }
+ */
+ }
+
+ $this->view->recoverPasswordForm = $recoverPasswordForm;
+ }
+
+ public function deleteAction()
+ {
+ $result = $this->personmapper->findBy('email', Zend_Auth::getInstance()->getIdentity());
+ $person = $result[0];
+ $personID = $person["personID"];
+ if (isset($personID)){
+ $this->personmapper = new Application_Model_PersonMapper();
+ $person = $this->personmapper->find($personID);
+ try {
+ $this->personmapper->delete($person);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+ return;
+ }
+ $auth = Zend_Auth::getInstance();
+ $auth->clearIdentity();
+ $this->_helper->redirector('login', 'auth');
+ }
+ }
+}
\ No newline at end of file
diff --git a/application/modules/dev/controllers/BootisoController.php b/application/modules/dev/controllers/BootisoController.php
new file mode 100644
index 0000000..078c962
--- /dev/null
+++ b/application/modules/dev/controllers/BootisoController.php
@@ -0,0 +1,125 @@
+view->bootisolist = $bootisomapper->fetchAll();
+
+ foreach ($this->view->bootisolist as $bootiso){
+ $bootiso->setGroupID("[".$bootiso->getGroupID()."] ".$groupmapper->find($bootiso->getGroupID())->getTitle());
+ $bootiso->setMembershipID("[".$bootiso->getMembershipID()."] ".$personmapper->find($membershipmapper->find($bootiso->getMembershipID())->getPersonID())->getFirstname());
+ }
+
+ }
+
+ public function createbootisoAction()
+ {
+ $groupmapper = new Application_Model_GroupMapper();
+
+ if (!isset($_POST["createbootiso"])){
+ $createbootisoForm = new Application_Form_BootisoCreate(array('grouplist' => $groupmapper->fetchAll()));
+ } else {
+
+ $createbootisoForm = new Application_Form_BootisoCreate(array('grouplist' => $groupmapper->fetchAll()),$_POST);
+
+ if ($createbootisoForm->isValid($_POST)) {
+
+ $bootiso = new Application_Model_BootIso($_POST);
+ $bootiso->setMembershipID('1');
+ $bootisomapper = new Application_Model_BootIsoMapper();
+ $bootiso->setCreated(time());
+
+ try {
+ $bootisomapper->save($bootiso);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+
+ }
+ $this->_redirect('/bootiso');
+ }
+ }
+
+ $this->view->createbootisoForm = $createbootisoForm;
+ }
+
+ public function editbootisoAction()
+ {
+ $bootisoID = $this->_request->getParam('bootisoID');
+ $groupmapper = new Application_Model_GroupMapper();
+
+ if (!isset($_POST["editbootiso"])){
+ $bootisoID = $this->_request->getParam('bootisoID');
+ if (!isset($bootisoID) || !is_numeric($bootisoID)){
+ $this->_redirect('/bootiso');
+ } else {
+ $bootiso = new Application_Model_BootIso();
+ $bootisomapper = new Application_Model_BootIsoMapper();
+ $bootisomapper->find($bootisoID, $bootiso);
+
+ $editbootisoForm = new Application_Form_BootisoEdit(array('grouplist' => $groupmapper->fetchAll()));
+ $editbootisoForm->populate($bootiso->toArray());
+ }
+ }else{
+ $editbootisoForm = new Application_Form_BootisoEdit(array('grouplist' => $groupmapper->fetchAll()),$_POST);
+
+ if ($editbootisoForm->isValid($_POST)) {
+
+ $bootiso = new Application_Model_BootIso($_POST);
+ $bootiso->setMembershipID('1');
+ $bootisomapper = new Application_Model_BootIsoMapper();
+ $bootiso->setCreated(time());
+ $bootiso->setID($bootisoID);
+
+ try {
+ $bootisomapper->save($bootiso);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+ }
+
+ $this->_redirect('/bootiso');
+ }
+
+ }
+
+ $this->view->editbootisoForm = $editbootisoForm;
+ }
+
+ public function deletebootisoAction()
+ {
+ $bootisoID = $this->_request->getParam('bootisoID');
+ if (!isset($bootisoID)){
+ $this->_redirect('/bootiso');
+ } else {
+ $bootiso = new Application_Model_BootIso();
+ $bootiso->setID($bootisoID);
+ $bootisomapper = new Application_Model_BootIsoMapper();
+ $bootisomapper->delete($bootiso);
+ }
+ $this->_redirect('/bootiso');
+ }
+
+
+}
+
+
+
+
+
+
+
diff --git a/application/modules/dev/controllers/BootmenuController.php b/application/modules/dev/controllers/BootmenuController.php
new file mode 100644
index 0000000..641b547
--- /dev/null
+++ b/application/modules/dev/controllers/BootmenuController.php
@@ -0,0 +1,328 @@
+view->bootosmapper = $bootosmapper;
+ $this->view->configmapper = $configmapper;
+
+ $bootmenuID = $this->_request->getParam('bootmenuid');
+ $preboot = $this->_request->getParam('preboot');
+
+ if($preboot=="")
+ {
+ if($bootmenuID == "")
+ {
+ $this->view->bootmenulist = $bootmenumapper->fetchAll();
+ $bootmenuentries = array();
+ foreach ($this->view->bootmenulist as $bootmenu){
+ $bootmenuentries[$bootmenu->getID()] = $bootmenuentriesmapper->findBy('bootmenuID',$bootmenu->getID());
+ $bootmenu->setGroupID("[".$bootmenu->getGroupID()."] ".$groupmapper->find($bootmenu->getGroupID())->getTitle());
+ $bootmenu->setMembershipID("[".$bootmenu->getMembershipID()."] ".$personmapper->find($membershipmapper->find($bootmenu->getMembershipID())->getPersonID())->getFirstname());
+ }
+ }else{
+ $bootmenu = new Application_Model_BootMenu();
+ $bootmenumapper->find($bootmenuID, $bootmenu);
+
+ $bootmenuentries = array();
+ $bootmenuentries[$bootmenuID] = $bootmenuentriesmapper->findBy('bootmenuID',$bootmenuID);
+ $bootmenu->setGroupID("[".$bootmenu->getGroupID()."] ".$groupmapper->find($bootmenu->getGroupID())->getTitle());
+ $bootmenu->setMembershipID("[".$bootmenu->getMembershipID()."] ".$personmapper->find($membershipmapper->find($bootmenu->getMembershipID())->getPersonID())->getFirstname());
+
+ $this->view->bootmenulist = array($bootmenu);
+
+ }
+
+ $this->view->bootmenuentrylist = $bootmenuentries;
+
+ }else{
+ $this->_helper->layout->disableLayout();
+ $this->_helper->viewRenderer->setNoRender();
+
+ if($bootmenuID == "")
+ {
+ $this->view->bootmenulist = $bootmenumapper->fetchAll();
+ $bootmenuentries = array();
+ foreach ($this->view->bootmenulist as $bootmenu){
+ $bootmenuentries[$bootmenu->getID()] = $bootmenuentriesmapper->findBy('bootmenuID',$bootmenu->getID());
+ $bootmenu->setGroupID("[".$bootmenu->getGroupID()."] ".$groupmapper->find($bootmenu->getGroupID())->getTitle());
+ $bootmenu->setMembershipID("[".$bootmenu->getMembershipID()."] ".$personmapper->find($membershipmapper->find($bootmenu->getMembershipID())->getPersonID())->getFirstname());
+ }
+ }else{
+ $bootmenu = new Application_Model_BootMenu();
+ $bootmenumapper->find($bootmenuID, $bootmenu);
+
+ $cc['title'] = $bootmenu->getTitle();
+
+ $bootmenuentries = array();
+ $bootmenuentries = $bootmenuentriesmapper->findBy('bootmenuID',$bootmenuID);
+
+ foreach($bootmenuentries as $bootmenuentry){
+ $ar = array();
+ $ar['title'] = $bootmenuentry->getTitle();
+ $ar['id'] = $bootmenuentry->getID();
+ $cc['data'][] = $ar;
+ }
+
+ echo json_encode($cc);
+
+ //print_a($cc);
+
+ }
+
+ }
+ }
+
+ public function addbootmenuentryAction()
+ {
+ $bootmenuID = $this->_request->getParam('bootmenuID');
+ $bootosmapper = new Application_Model_BootOsMapper();
+ $configmapper = new Application_Model_ConfigMapper();
+
+ if (!isset($_POST["addbootmenuentry"])){
+ $addbootmenuentryForm = new Application_Form_BootmenuEntriesAdd(array('bootoslist'=>$bootosmapper->fetchAll(), 'maxorder'=> $this->_request->getParam('maxorder'), 'configlist'=>$configmapper->fetchAll()));
+ $addbootmenuentryForm->populate(array('order' => $this->_request->getParam('maxorder')));
+ unset($_POST['kcl']);
+ unset($_POST['configID']);
+ $addbootmenuentryForm->populate($_POST);
+ } else {
+
+ $addbootmenuentryForm = new Application_Form_BootmenuEntriesAdd(array('bootoslist'=>$bootosmapper->fetchAll(), 'maxorder'=> $this->_request->getParam('maxorder'), 'configlist'=>$configmapper->fetchAll()),$_POST);
+
+ if ($addbootmenuentryForm->isValid($_POST)) {
+
+ $bootmenuentry = new Application_Model_BootMenuEntries($_POST);
+ $bootmenuentry->setBootmenuID($bootmenuID);
+
+ $bootmenuentrymapper = new Application_Model_BootMenuEntriesMapper();
+
+ try {
+ if($bootmenuentry->getOrder() < $this->_request->getParam('maxorder')){
+ $bootmenuentry->setOrder($bootmenuentry->getOrder());
+ $bootmenuentrymapper->order($bootmenuentry);
+ }
+ $bootmenuentrymapper->save($bootmenuentry);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+
+ }
+ $this->_redirect('/bootmenu');
+ }
+ }
+
+ $this->view->addbootmenuentryForm = $addbootmenuentryForm;
+
+ }
+
+ public function createbootmenuAction()
+ {
+ $groupmapper = new Application_Model_GroupMapper();
+
+ if (!isset($_POST["createbootmenu"])){
+ $createbootmenuForm = new Application_Form_BootmenuCreate(array('grouplist' => $groupmapper->fetchAll()));
+ } else {
+
+ $createbootmenuForm = new Application_Form_BootmenuCreate(array('grouplist' => $groupmapper->fetchAll()),$_POST);
+
+ if ($createbootmenuForm->isValid($_POST)) {
+
+ $bootmenu = new Application_Model_BootMenu($_POST);
+ $bootmenu->setMembershipID('1');
+ $bootmenu->setCreated(time());
+ $bootmenumapper = new Application_Model_BootMenuMapper();
+
+ try {
+ $bootmenumapper->save($bootmenu);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+
+ }
+ $this->_redirect('/bootmenu');
+ }
+ }
+
+ $this->view->createbootmenuForm = $createbootmenuForm;
+ }
+
+ public function editbootmenuAction()
+ {
+ $bootmenuID = $this->_request->getParam('bootmenuID');
+ $groupmapper = new Application_Model_GroupMapper();
+
+ if (!isset($_POST["editbootmenu"])){
+ $bootmenuID = $this->_request->getParam('bootmenuID');
+ if (!isset($bootmenuID) || !is_numeric($bootmenuID)){
+ $this->_redirect('/bootmenu');
+ } else {
+ $bootmenu = new Application_Model_BootMenu();
+ $bootmenumapper = new Application_Model_BootMenuMapper();
+ $bootmenumapper->find($bootmenuID, $bootmenu);
+
+ $editbootmenuForm = new Application_Form_BootmenuEdit(array('grouplist' => $groupmapper->fetchAll()));
+ $editbootmenuForm->populate($bootmenu->toArray());
+ }
+ }else{
+ $editbootmenuForm = new Application_Form_BootmenuEdit(array('grouplist' => $groupmapper->fetchAll()),$_POST);
+
+ if ($editbootmenuForm->isValid($_POST)) {
+
+ $bootmenu = new Application_Model_BootMenu($_POST);
+ $bootmenu->setMembershipID('1');
+ $bootmenu->setCreated(time());
+ $bootmenumapper = new Application_Model_BootMenuMapper();
+
+ $bootmenu->setID($bootmenuID);
+
+ try {
+
+ $bootmenumapper->save($bootmenu);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+ }
+
+ $this->_redirect('/bootmenu');
+ }
+
+ }
+
+ $this->view->editbootmenuForm = $editbootmenuForm;
+ }
+
+ public function editbootmenuentryAction()
+ {
+ $bootmenuentryID = $this->_request->getParam('bootmenuentryID');
+ $bootmenuID = $this->_request->getParam('bootmenuID');
+ $bootosmapper = new Application_Model_BootOsMapper();
+ $configmapper = new Application_Model_ConfigMapper();
+ $bootmenuentry = new Application_Model_BootMenuEntries();
+ $bootmenuentrymapper = new Application_Model_BootMenuEntriesMapper();
+
+ if (!isset($_POST["editbootmenuentry"])){
+ $bootmenuentryID = $this->_request->getParam('bootmenuentryID');
+ if (!isset($bootmenuentryID) || !is_numeric($bootmenuentryID)){
+ $this->_redirect('/bootmenu');
+ } else {
+
+ $bootmenuentrymapper->find($bootmenuentryID, $bootmenuentry);
+
+ $editbootmenuentryForm = new Application_Form_BootmenuEntriesEdit(array('bootoslist'=>$bootosmapper->fetchAll(), 'maxorder' => $this->_request->getParam('maxorder'), 'configlist'=>$configmapper->fetchAll()));
+ if(!isset($_POST['kcl'])){
+ $editbootmenuentryForm->populate($bootmenuentry->toArray());
+ }
+ else{
+ unset($_POST['kcl']);
+ unset($_POST['configID']);
+ $editbootmenuentryForm->populate($_POST);
+ }
+ }
+ }else{
+ $editbootmenuentryForm = new Application_Form_BootmenuEntriesEdit(array('bootoslist'=>$bootosmapper->fetchAll(), 'maxorder'=> $this->_request->getParam('maxorder'), 'configlist'=>$configmapper->fetchAll()),$_POST);
+
+ if ($editbootmenuentryForm->isValid($_POST)) {
+
+ $bootmenuentry = new Application_Model_BootMenuEntries($_POST);
+
+ $bootmenuentry->setBootmenuID($bootmenuID);
+ $bootmenuentry->setID($bootmenuentryID);
+
+ $bootmenuentrymapper = new Application_Model_BootMenuEntriesMapper();
+
+ try {
+ if($bootmenuentry->getOrder() < $this->_request->getParam('oldorder'))
+ $bootmenuentrymapper->orderbefore($bootmenuentry, $this->_request->getParam('oldorder'));
+ else
+ $bootmenuentrymapper->orderafter($bootmenuentry, $this->_request->getParam('oldorder'));
+
+ $bootmenuentrymapper->save($bootmenuentry);
+
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+ }
+
+ $this->_redirect('/bootmenu');
+ }
+
+ }
+
+ $this->view->editbootmenuentryForm = $editbootmenuentryForm;
+
+ }
+
+ public function removebootmenuentryAction()
+ {
+ $bootmenuentryID = $this->_request->getParam('bootmenuentryID');
+ if (!isset($bootmenuentryID) || !is_numeric($bootmenuentryID)){
+ $this->_redirect('/bootmenu');
+ } else {
+ $bootmenuentry = new Application_Model_BootMenuEntries();
+ $bootmenuentrymapper = new Application_Model_BootMenuEntriesMapper();
+ $bootmenuentrymapper->find($bootmenuentryID, $bootmenuentry);
+ $bootmenuentrymapper->delete($bootmenuentry);
+ $bootmenuentrymapper->orderremove($bootmenuentry);
+ }
+ $this->_redirect('/bootmenu');
+ }
+
+ public function deletebootmenuAction()
+ {
+ $bootmenuID = $this->_request->getParam('bootmenuID');
+ if (!isset($bootmenuID) || !is_numeric($bootmenuID)){
+ $this->_redirect('/bootmenu');
+ } else {
+ $bootmenu = new Application_Model_BootMenu();
+ $bootmenu->setID($bootmenuID);
+ $bootmenumapper = new Application_Model_BootMenuMapper();
+ $bootmenumapper->delete($bootmenu);
+ }
+ $this->_redirect('/bootmenu');
+ }
+
+ private function arrayDiff($a, $b){
+ foreach($a as $k1 => $i1){
+ foreach($b as $k2 => $i2){
+ if($i1->getID() == $i2->getBootosID()){
+ unset($a[$k1]);
+ }
+ }
+ }
+ return $a;
+ }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/application/modules/dev/controllers/BootosController.php b/application/modules/dev/controllers/BootosController.php
new file mode 100644
index 0000000..3a7ab90
--- /dev/null
+++ b/application/modules/dev/controllers/BootosController.php
@@ -0,0 +1,147 @@
+view->bootoslist = $bootosmapper->fetchAll();
+ if(count($this->view->bootoslist)>0){
+ foreach ($this->view->bootoslist as $bootos){
+ $bootos->setGroupID("[".$bootos->getGroupID()."] ".$groupmapper->find($bootos->getGroupID())->getTitle());
+ $bootos->setMembershipID("[".$bootos->getMembershipID()."] ".$personmapper->find($membershipmapper->find($bootos->getMembershipID())->getPersonID())->getFirstname());
+ $bootos->setConfigID("[".$bootos->getConfigID()."] ".$configmapper->find($bootos->getConfigID())->getTitle());
+
+ }
+ }
+
+ }
+
+ public function createbootosAction()
+ {
+ $groupmapper = new Application_Model_GroupMapper();
+ $configmapper = new Application_Model_ConfigMapper();
+
+ if (!isset($_POST["createbootos"])){
+ $createbootosForm = new Application_Form_BootosCreate(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()));
+ } else {
+
+ $createbootosForm = new Application_Form_BootosCreate(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()),$_POST);
+
+ if ($createbootosForm->isValid($_POST)) {
+
+ $bootos = new Application_Model_BootOs($_POST);
+ $bootos->setMembershipID('1');
+ if($bootos->getConfigID() == '')
+ $bootos->setConfigID(NULL);
+ $bootosmapper = new Application_Model_BootOsMapper();
+ $bootos->setCreated(time());
+
+ try {
+ $bootosID = $bootosmapper->save($bootos);
+
+ $initpath = "../resources/bootos/".$bootosID."/initramfs/";
+ $kernelpath = "../resources/bootos/".$bootosID."/kernel/";
+
+ exec("wget -P ".$kernelpath." ".$bootos->getPath_kernel());
+ exec("wget -P ".$initpath." ".$bootos->getPath_init());
+
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+
+ }
+
+ $this->_redirect('/bootos');
+ }
+ }
+
+ $this->view->createbootosForm = $createbootosForm;
+ }
+
+ public function editbootosAction()
+ {
+ $bootosID = $this->_request->getParam('bootosID');
+ $groupmapper = new Application_Model_GroupMapper();
+ $configmapper = new Application_Model_ConfigMapper();
+
+ if (!isset($_POST["editbootos"])){
+ $bootosID = $this->_request->getParam('bootosID');
+ if (!isset($bootosID) || !is_numeric($bootosID)){
+ $this->_redirect('/bootos');
+ } else {
+ $bootos = new Application_Model_BootOs();
+ $bootosmapper = new Application_Model_BootOsMapper();
+ $bootos = $bootosmapper->find($bootosID);
+
+ $editbootosForm = new Application_Form_BootosEdit(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()));
+ $editbootosForm->populate($bootos->toArray());
+ }
+ }else{
+ $editbootosForm = new Application_Form_BootosEdit(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()),$_POST);
+
+ if ($editbootosForm->isValid($_POST)) {
+
+ $bootos = new Application_Model_BootOs($_POST);
+ $bootos->setMembershipID('1');
+ if($bootos->getConfigID() == '')
+ $bootos->setConfigID(NULL);
+ $bootosmapper = new Application_Model_BootOsMapper();
+ $bootos->setCreated(time());
+ $bootos->setID($bootosID);
+
+ try {
+ $bootosmapper->save($bootos);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+ }
+
+ $this->_redirect('/bootos');
+ }
+
+ }
+
+ $this->view->editbootosForm = $editbootosForm;
+
+ }
+
+ public function deletebootosAction()
+ {
+ $bootosID = $this->_request->getParam('bootosID');
+ if (!isset($bootosID)){
+ $this->_redirect('/bootos');
+ } else {
+ $bootos = new Application_Model_BootOs();
+ $bootos->setID($bootosID);
+ $bootosmapper = new Application_Model_BootOsMapper();
+ $bootosmapper->delete($bootos);
+ }
+ $this->_redirect('/bootos');
+
+ }
+
+
+}
+
+
+
+
+
+
+
diff --git a/application/modules/dev/controllers/ClientController.php b/application/modules/dev/controllers/ClientController.php
new file mode 100644
index 0000000..affa780
--- /dev/null
+++ b/application/modules/dev/controllers/ClientController.php
@@ -0,0 +1,90 @@
+view->clients = $clientMapper->fetchAll();
+ }
+
+ public function addclientAction()
+ {
+ $mac = $this->_request->getParam('mac');
+ $hh = $this->_request->getParam('hh');
+
+ if (!isset($_POST["add"])){
+ $addclient = new Application_Form_Client(array('buttontext' => 'Create Client'));
+ $this->view->addclient = $addclient;
+ }
+ else{
+ $addfilterform = new Application_Form_Client(array('buttontext' => 'Create Client'),$_POST);
+ if ($addfilterform->isValid($_POST) || ($mac != '' && $hh != '') ) {
+ $client = new Application_Model_Client();
+ $mac = ($mac!='')?$mac:$_POST['macadress'];
+ $hh = ($hh!='')?$hh:$_POST['hardwarehash'];
+ $client->setMacadress($mac);
+ $client->setHardwarehash($hh);
+ $clientmapper = new Application_Model_ClientMapper();
+ $clientmapper->save($client);
+ print_a('inserted');
+ $this->_redirect('/client');
+ }
+ $this->view->addclient = $addclient;
+ }
+ }
+
+ public function removeclientAction()
+ {
+ $clientID = $this->_request->getParam('clientID');
+ // TODO: ACL implementieren ob er den filter löschen darf
+ if(is_numeric($clientID)){
+ $removeClient = new Application_Model_Client();
+ $removeClient->setID($clientID);
+ $clientMapper = new Application_Model_ClientMapper();
+ $clientMapper->delete($removeClient);
+ }
+ $this->_redirect('/client');
+ }
+
+ public function editclientAction()
+ {
+ 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 Application_Form_Client(array('buttontext' => 'Edit Client'));
+ $editclient->populate($data->toArray());
+ $this->view->editclient = $editclient;
+ }
+ else{
+ $editclient = new Application_Form_Client(array('buttontext' => 'Edit Client'),$_POST);
+ if ($editclient->isValid($_POST) || ($mac != '' && $hh != '') ) {
+ $client = new Application_Model_Client($_POST);
+ $client->setID($this->_request->getParam('clientID'));
+ $clientmapper = new Application_Model_ClientMapper();
+ $clientmapper->save($client);
+ print_a('updated');
+ $this->_redirect('/client');
+ }
+ $this->view->editclient = $editclient;
+ }
+ }
+
+
+}
+
+
+
+
+
+
+
diff --git a/application/modules/dev/controllers/ConfigController.php b/application/modules/dev/controllers/ConfigController.php
new file mode 100644
index 0000000..3eff0cc
--- /dev/null
+++ b/application/modules/dev/controllers/ConfigController.php
@@ -0,0 +1,126 @@
+view->configlist = $configmapper->fetchAll();
+
+ foreach ($this->view->configlist as $config){
+ $config->setGroupID("[".$config->getGroupID()."] ".$groupmapper->find($config->getGroupID())->getTitle());
+ $config->setMembershipID("[".$config->getMembershipID()."] ".$personmapper->find($membershipmapper->find($config->getMembershipID())->getPersonID())->getFirstname());
+ }
+
+ }
+
+ public function createconfigAction()
+ {
+ $groupmapper = new Application_Model_GroupMapper();
+ if (!isset($_POST["createconfig"])){
+ $createconfigForm = new Application_Form_ConfigCreate(array('grouplist' => $groupmapper->fetchAll()));
+ } else {
+
+ $createconfigForm = new Application_Form_ConfigCreate(array('grouplist' => $groupmapper->fetchAll()),$_POST);
+
+ if ($createconfigForm->isValid($_POST)) {
+
+ $config = new Application_Model_Config($_POST);
+ $config->setCreated(time());
+ $config->setMembershipID('1');
+
+ $configmapper = new Application_Model_ConfigMapper();
+
+ try {
+ $configmapper->save($config);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+
+ }
+ $this->_redirect('/config');
+ }
+ }
+
+ $this->view->createconfigForm = $createconfigForm;
+ }
+
+ public function editconfigAction()
+ {
+ $configID = $this->_request->getParam('configID');
+ $groupmapper = new Application_Model_GroupMapper();
+
+ if (!isset($_POST["editconfig"])){
+ $configID = $this->_request->getParam('configID');
+ if (!isset($configID) || !is_numeric($configID)){
+ $this->_redirect('/config');
+ } else {
+ $config = new Application_Model_Config();
+ $configmapper = new Application_Model_ConfigMapper();
+ $config = $configmapper->find($configID);
+
+ $editconfigForm = new Application_Form_ConfigEdit(array('grouplist' => $groupmapper->fetchAll()));
+ $editconfigForm->populate($config->toArray());
+ }
+ }else{
+ $editconfigForm = new Application_Form_ConfigEdit(array('grouplist' => $groupmapper->fetchAll()),$_POST);
+
+ if ($editconfigForm->isValid($_POST)) {
+
+ $config = new Application_Model_Config($_POST);
+ $configmapper = new Application_Model_ConfigMapper();
+ $config->setCreated(time());
+ $config->setMembershipID('1');
+ $config->setID($configID);
+
+ try {
+ $configmapper->save($config);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+ }
+
+ $this->_redirect('/config');
+ }
+
+ }
+
+ $this->view->editconfigForm = $editconfigForm;
+ }
+
+ public function deleteconfigAction()
+ {
+ $configID = $this->_request->getParam('configID');
+ if (!isset($configID)){
+ $this->_redirect('/config');
+ } else {
+ $config = new Application_Model_Config();
+ $config->setID($configID);
+ $configmapper = new Application_Model_ConfigMapper();
+ $configmapper->delete($config);
+ }
+ $this->_redirect('/config');
+ }
+
+
+}
+
+
+
+
+
+
+
diff --git a/application/modules/dev/controllers/ErrorController.php b/application/modules/dev/controllers/ErrorController.php
new file mode 100644
index 0000000..5bb2749
--- /dev/null
+++ b/application/modules/dev/controllers/ErrorController.php
@@ -0,0 +1,51 @@
+_getParam('error_handler');
+
+ switch ($errors->type) {
+ case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
+ case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
+ case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
+
+ // 404 error -- controller or action not found
+ $this->getResponse()->setHttpResponseCode(404);
+ $this->view->message = 'Page not found';
+ break;
+ default:
+ // application error
+ $this->getResponse()->setHttpResponseCode(500);
+ $this->view->message = 'Application error';
+ break;
+ }
+
+ // Log exception, if logger available
+ if ($log = $this->getLog()) {
+ $log->crit($this->view->message, $errors->exception);
+ }
+
+ // conditionally display exceptions
+ if ($this->getInvokeArg('displayExceptions') == true) {
+ $this->view->exception = $errors->exception;
+ }
+
+ $this->view->request = $errors->request;
+ }
+
+ public function getLog()
+ {
+ $bootstrap = $this->getInvokeArg('bootstrap');
+ if (!$bootstrap->hasPluginResource('Log')) {
+ return false;
+ }
+ $log = $bootstrap->getResource('Log');
+ return $log;
+ }
+
+
+}
+
diff --git a/application/modules/dev/controllers/FilterController.php b/application/modules/dev/controllers/FilterController.php
new file mode 100644
index 0000000..da52c34
--- /dev/null
+++ b/application/modules/dev/controllers/FilterController.php
@@ -0,0 +1,680 @@
+_filtermapper = new Application_Model_FilterMapper();
+ }catch (Zend_Exception $e) {
+ echo "Error message 1: " . $e->getMessage() . "\n";
+ }
+ $this->db = Zend_Db_Table::getDefaultAdapter();
+ }
+
+ public function indexAction()
+ {
+ try{
+ $this->_filtermapper = new Application_Model_FilterMapper();
+ $this->view->filters = $this->_filtermapper->fetchAll();
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
+ }
+ }
+
+ public function addfilterAction()
+ {
+ $bmmapper = new Application_Model_BootMenuMapper();
+ //TODO get bootmenu by group
+ $bootmenus = $bmmapper->fetchAll();
+ if (!isset($_POST["add"])){
+ $addfilterform = new Application_Form_FilterAdd(array('buttontext' => 'Create Filter','bootmenus'=>$bootmenus));
+ $this->view->addfilterform = $addfilterform;
+ }else {
+ $addfilterform = new Application_Form_FilterAdd(array('buttontext' => 'Create Filter','bootmenus'=>$bootmenus),$_POST);
+ if ($addfilterform->isValid($_POST)) {
+ try{
+ $newfilter = new Application_Model_Filter($_POST);
+ $newfilter->setCreated(time());
+
+ // TODO: Ändere mit ACL
+ $newfilter->setGroupID('1');
+ $newfilter->setMembershipID('1');
+
+ $newfilter2 = new Application_Model_FilterMapper();
+ $newfilter2->save($newfilter);
+
+ $this->_redirect('/filter');
+ return;
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
+ }
+ }
+ $this->view->addfilterform = $addfilterform;
+ }
+ }
+
+ public function removefilterAction()
+ {
+ $filterID = $this->_request->getParam('filterID');
+ // TODO: ACL implementieren ob er den filter löschen darf
+ if(is_numeric($filterID)){
+ $deletefilter = new Application_Model_Filter();
+ $deletefilter->setID($filterID);
+ $filtermapper = new Application_Model_FilterMapper();
+ $filtermapper->delete($deletefilter);
+ }
+ $this->_redirect('/filter');
+ }
+
+ public function editfilterAction()
+ {
+ $bmmapper = new Application_Model_BootMenuMapper();
+ //TODO get bootmenu by group
+ $bootmenus = $bmmapper->fetchAll();
+ if (!isset($_POST["add"])){
+ // TODO: ACL implementieren ob er editieren darf
+ $filterID = $this->_request->getParam('filterID');
+ $filter = new Application_Model_Filter();
+
+
+ $filtermapper = new Application_Model_FilterMapper();
+ $filtermapper->find($filterID,$filter);
+ $filter2 = $filter->toArray();
+
+ $editfilterform = new Application_Form_FilterAdd(array('buttontext' => 'Edit Filter','bootmenus'=>$bootmenus));
+ $editfilterform->populate($filter2);
+ $this->view->editfilterform = $editfilterform;
+
+ } else{
+ try{
+ $filterID = $this->_request->getParam('filterID');
+
+ $editfilterform = new Application_Form_FilterAdd(array('buttontext' => 'Edit Filter','bootmenus'=>$bootmenus),$_POST);
+ //TODO: ACL integrieren
+ $_POST['groupID'] = 1;
+ $_POST['membershipID'] = 1;
+ $_POST['created'] = time();
+
+ if ($editfilterform->isValid($_POST)) {
+ $newfilterenty = new Application_Model_Filter($_POST);
+ $newfilterenty->setID($this->_request->getParam('filterID'));
+ $newfilter2 = new Application_Model_FilterMapper();
+ $newfilter2->save($newfilterenty);
+ echo 'valid';
+ $this->_redirect('/filter');
+ }
+ $this->view->editfilterform = $editfilterform;
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
+ }
+ }
+ }
+
+ public function addfilterentryAction()
+ {
+ // TODO: ACL implementieren ob er editieren darf
+ if (!isset($_POST["add"])){
+ try{
+ $editfilterform = new Application_Form_FilterEntriesAdd(
+ array( 'buttontext' => 'Add Filterentry',
+ 'filterID' => $this->_request->getParam('filterID'),
+ 'data' => $_POST
+ ));
+ $editfilterform->populate($_POST);
+ $this->view->editfilterform = $editfilterform;
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
+ }
+ } else{
+ $editfilterform = new Application_Form_FilterEntriesAdd(array('buttontext' => 'Add Filterentry'),$_POST);
+ if ($editfilterform->isValid($_POST)) {
+ $newfilterenty = new Application_Model_FilterEntries();
+ $newfilterenty->setFilterID($_POST['filterID']);
+ $newfilterenty->setFiltertypeID($_POST['filtertypeID']);
+
+ if($_POST['filtertypeID'] == 1){
+ $newfilterenty->setFiltervalue($this->fillIP($_POST['filtervalue']));
+ $newfilterenty->setFiltervalue2($this->fillIP($_POST['filtervalue2']));
+ }
+ else{
+ $newfilterenty->setFiltervalue($_POST['filtervalue']);
+ $newfilterenty->setFiltervalue2($_POST['filtervalue2']);
+ }
+
+ $newfilter2 = new Application_Model_FilterEntriesMapper();
+ $newfilter2->save($newfilterenty);
+ #print_a($newfilterenty);
+ $this->_redirect('/filter');
+ }
+ $this->view->editfilterform = $editfilterform;
+ }
+ }
+
+ public function editfilterentryAction()
+ {
+ if (!isset($_POST["add"])){
+ try{
+ $filterentriesID = $this->_request->getParam('filterentriesID');
+
+ $filterentry = new Application_Model_FilterEntries();
+
+ $filterentriesmapper = new Application_Model_FilterEntriesMapper();
+ $filterentriesmapper->find($filterentriesID,$filterentry);
+
+
+
+ #$editfilterform->setFilterID($filterID);
+ if(isset($_POST['filtertypeID']) && $_POST['filtertypeID'] != $filterentry->getFiltertypeID()){
+ $filterentry->setFiltertypeID($_POST['filtertypeID']) ;
+ }
+ $data = $filterentry->toArray();
+ print_a($data);
+ $editfilterform = new Application_Form_FilterEntriesAdd(
+ array('buttontext' => 'Edit Filterentry',
+ 'data' => $data));
+
+ $editfilterform->populate($filterentry->toArray());
+ $this->view->editfilterform = $editfilterform;
+
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
+ }
+ } else{
+ try{
+ $filterentriesID = $this->_request->getParam('filterentriesID');
+ $editfilterform = new Application_Form_FilterEntriesAdd(array('buttontext' => 'Edit Filterentry'),$_POST);
+ if ($editfilterform->isValid($_POST)) {
+ if($_POST['filterID'] == '')
+ unset($_POST['filterID']);
+ $newfilterenty = new Application_Model_FilterEntries($_POST);
+ $newfilterenty->setID($filterentriesID);
+ if($_POST['filtertypeID'] == 1){
+ $newfilterenty->setFiltervalue($this->fillIP($_POST['filtervalue']));
+ $newfilterenty->setFiltervalue2($this->fillIP($_POST['filtervalue2']));
+ }
+ else{
+ $newfilterenty->setFiltervalue($_POST['filtervalue']);
+ $newfilterenty->setFiltervalue2($_POST['filtervalue2']);
+ }
+ $newfilter2 = new Application_Model_FilterEntriesMapper();
+ $newfilter2->save($newfilterenty);
+ #print_a($newfilterenty);
+ $this->_redirect('/filter');
+
+ }
+ $this->view->editfilterform = $editfilterform;
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
+ }
+ }
+ }
+
+ public function removefilterentryAction()
+ {
+ try{
+ $filterentriesID = $this->_request->getParam('filterentriesID');
+
+ // TODO: ACL implementieren ob er den filter löschen darf
+ if(is_numeric($filterentriesID)){
+ $deletefilterentry = new Application_Model_FilterEntries();
+ $deletefilterentry->setID($filterentriesID);
+ echo "
"; + print_r($deletefilterentry); + echo ""; + + $filterentriesmapper = new Application_Model_FilterEntriesMapper(); + $filterentriesmapper->delete($deletefilterentry); + echo "ok"; + } + $this->_redirect('/filter'); + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + } + + private function fillIP($ip) + { + $ar = explode(".",$ip); + $representation = array(); + foreach($ar as $part){ + $representation[] = sprintf("%03s",$part); + } + return implode(".",$representation); + } + + private function fillMac($ip) + { + $ar = explode(":",$ip); + $representation = array(); + foreach($ar as $part){ + $representation[] = sprintf("%02s",$part); + } + return implode(":",$representation); + } + + public function evaluateAction() + { + $db = $this->db; + $showPartResults = false; + // For Testing Filters + + + $testFilter = (isset($_POST['submit']))?true:false; + + if($testFilter){ + $ipAdress = $_POST['ip']; + $macAdress = $_POST['mac']; + $poolID = $_POST['poolID']; + $bootisoID = $_POST['bootisoID']; + $membershipID = $_POST['membershipID']; + $groupID = $_POST['groupID']; + $time = ($_POST['time']); + $clientID = $_POST['clientID']; + $weekday = $_POST['weekday']; + $date = $_POST['date']; + print_a('Input', + array('ipAdress'=>$ipAdress, + 'macAdress'=>$macAdress, + 'poolID' => $poolID, + 'bootisoID' => $bootisoID, + 'membershipID'=>$membershipID, + 'groupID'=>$groupID, + 'time'=> $time." - ".date('d.m.Y H:i:s',$time), + 'clientID' => $clientID, + 'hardwarehash' => $hardwarehash, + 'weekday' => $weekday, + 'date' => $date)); + } + + + try{ + $mysession = '1'; + $set = array(); + + + $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 + if(!$testFilter){ + $ipAdress = $session->getIp(); + } + $ipAdress = str_replace(".","",$this->fillIP($ipAdress)); + + $select = $db->select() + ->from(array('pbs_filterentries') + ) + ->where('filtertypeID = ?',$filtertypID) + ->where('REPLACE(filtervalue,".","") <= ?',$ipAdress) + ->where('? <= REPLACE(filtervalue2,".","")',$ipAdress); + + $stmt = $select->query(); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + + if($showPartResults) + print_a('ipAdress',$result,$set[$filtertypID]); + + ######################################################### + // Mac range + $filtertypID = 2; + // get it from session_table with session_id from the session + if(!$testFilter){ + $client = new Application_Model_Client(); + $clientmapper = new Application_Model_ClientMapper(); + $clientmapper->find($session->getClientID(),$client); + $macAdress = $client->getMacadress(); + } + try{ + $macAdress = $this->fillMac($macAdress); + $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE + filtertypeID = ".$filtertypID." AND + filtervalue <= '".$macAdress."' AND + '".$macAdress."' <= filtervalue2"); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + } + catch(Exception $e){} + if($showPartResults) + print_a('macAdress',$result,$set[$filtertypID]); + + ######################################################### + // PoolID + $filtertypID = 3; + // get PoolID from client_ID from session_id from the session + if(!$testFilter){ + $poolentry = new Application_Model_PoolEntries(); + $poolentrymapper = new Application_Model_PoolEntriesMapper(); + $poolentry = $poolentrymapper->findby('clientID',$client->getID()); + $poolentry = $poolentry[0]; + + $poolID = $poolentry['poolID']; + } + + try{ + $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE + filtertypeID = ".$filtertypID." AND + filtervalue = ".$poolID." "); + $result = $stmt->fetchAll(); + if(count($result)>0){ + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + } + } + catch(Exception $e){} + + if($showPartResults) + print_a('poolID',$result,$set[$filtertypID]); + ######################################################### + // ClientID + $filtertypID = 8; + // get client_ID from session_id from the session + + if(!$testFilter){ + $clientID = $session->getClientID(); + } + try{ + $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE + filtertypeID = ".$filtertypID." AND + filtervalue = ".$clientID." "); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + } + catch(Exception $e){} + + if($showPartResults) + print_a('clientID',$result,$set[$filtertypID]); + ######################################################### + // BootIsoID + $filtertypID = 4; + // get BootIsoID from client_ID from session_id from the session + if(!$testFilter){ + $bootisoID = $session->getBootisoID(); + } + try{ + $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE + filtertypeID = ".$filtertypID." AND + filtervalue = ".$bootisoID." "); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + } + catch(Exception $e){} + + if($showPartResults) + print_a('bootisoID',$result,$set[$filtertypID]); + ######################################################### + // MembershipID + $filtertypID = 5; + + if(!$testFilter){ + // get membership from the session + //TODO: GET MEMBERSHIP from SESSION + $membershipID = 1; + } + try{ + $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE + filtertypeID = ".$filtertypID." AND + filtervalue = ".$membershipID." "); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + } + catch(Exception $e){} + + if($showPartResults) + print_a('membership',$result,$set[$filtertypID]); + ######################################################### + // GroupID + $filtertypID = 6; + + if(!$testFilter){ + // get membership from the session + //TODO: GET GROUP from SESSION + $groupID = 1; + } + try{ + $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE + filtertypeID = ".$filtertypID." AND + filtervalue = ".$groupID." "); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + } + catch(Exception $e){} + + if($showPartResults) + print_a('membership',$result,$set[$filtertypID]); + ######################################################### + // Time + $filtertypID = 7; + if(!$testFilter){ + $time = time("H:i"); + } + + $nowShort = $time; + + $nowShort = str_replace(":","",$nowShort); + try{ + $select = $db->select() + ->from(array('pbs_filterentries') + ) + ->where('filtertypeID = ?',$filtertypID) + ->where('REPLACE(filtervalue,":","") <= ? AND ? <= REPLACE(filtervalue2,":","")',$nowShort); + + $stmt = $select->query(); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + } + catch(Exception $e){} + + if($showPartResults) + print_a('time',$result,$set[$filtertypID]); + ######################################################### + // Hardwarehash + $filtertypID = 9; + if(!$testFilter){ + // get hardwarehash from session + $hardwarehash = 'aaaa'; + } + + try{ + $select = $db->select() + ->from(array('pbs_filterentries') + ) + ->where('filtertypeID = ?',$filtertypID) + ->where('`filtervalue` = ?',$hardwarehash); + $stmt = $select->query(); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + } + catch(Exception $e){} + + if($showPartResults) + print_a('hardwarehash',$result,$set[$filtertypID]); + ######################################################### + // weekday + $filtertypID = 10; + if(!$testFilter){ + $weekday = date('N'); + } + + try{ + $select = $db->select() + ->from(array('pbs_filterentries') + ) + ->where('filtertypeID = ?',$filtertypID) + ->where('filtervalue = ? ',$weekday); + + $stmt = $select->query(); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + } + catch(Exception $e){} + + if($showPartResults) + print_a('weekday',$result,$set[$filtertypID]); + ######################################################### + // weekday + $filtertypID = 11; + if(!$testFilter){ + $date = date('d.m.Y'); + } + + try{ + $select = $db->select() + ->from(array('pbs_filterentries') + ) + ->where('filtertypeID = ?',$filtertypID) + ->where('REPLACE(filtervalue,".","") <= ? AND ? <= REPLACE(filtervalue2,".","")',$date); + + $stmt = $select->query(); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + } + catch(Exception $e){} + + if($showPartResults) + print_a('weekday',$result,$set[$filtertypID]); + ######################################## + // ErgebnisSet auswerten + print_a('the result sets of the filtertypes',$set); + + // Merging of the resultsets of the filter + $kk = array(); + foreach($set as $myset){ + $kk = array_merge($kk,$myset); + } + $set = $kk; + // counting how often a filter is evaluated at database + $a = array(); + foreach($set as $k=> $s){ + $a[$s] += 1; + } + print_a('Übereinstimmungen pro Filter',$a); + // Get the number of filtertypes every filter has + $stmt = $db->query('SELECT filterID, COUNT(filtertypeID) as num FROM pbs_filterentries GROUP BY filterID'); + $resultset = $stmt->fetchAll(); + foreach($resultset as $d){ + $database[$d['filterID']] = $d['num']; + } + print_a('Anzahl Filterentries in Datenbank',$database); + + // remove all filters from resultset, which to few filtertypes satisfied + $result = array(); + foreach($a as $i=>$b){ + if($a[$i] < $database[$i]){ + unset($a[$i]); + } + else{ + $result[] = $i; + } + } + + print_a('True Filters',$result); + // now selecting the filter with the highest priority + $query = 'SELECT filterID, bootmenuID, priority + FROM pbs_filter WHERE '; + foreach($result as $e){ + $queryTmp[] = "filterID = '$e'"; + } + $query .= implode(" OR ", $queryTmp); + $query .= 'ORDER BY priority DESC LIMIT 0,1'; + $bootmenuID = 'null'; + try{ + $stmt = $db->query($query); + $resultset = $stmt->fetchAll(); + $bootmenuID = $resultset[0]['bootmenuID']; + } + catch(Exception $e){ + } + if($bootmenuID != 'null'){ + $bm = new Application_Model_BootMenu(); + $bmmapper = new Application_Model_BootMenuMapper(); + $bmmapper->find($bootmenuID,$bm); + echo "