diff options
Diffstat (limited to 'application/modules/dev/controllers')
16 files changed, 3107 insertions, 3276 deletions
diff --git a/application/modules/dev/controllers/AuthController.php b/application/modules/dev/controllers/AuthController.php index bb59037..2e99cd7 100644 --- a/application/modules/dev/controllers/AuthController.php +++ b/application/modules/dev/controllers/AuthController.php @@ -1,247 +1,234 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_AuthController extends Zend_Controller_Action -{ - protected $personmapper; - private $db = null; - - public function init() - { - $this->db = Zend_Db_Table::getDefaultAdapter(); - $this->personmapper = new Application_Model_PersonMapper(); - } - - public function indexAction() - { - $this->_helper-> viewRenderer-> setNoRender(); - $this->_helper->redirector('login', 'auth'); - } - - public function loginAction() - { - if (Zend_Auth::getInstance()->hasIdentity()) { - $this->_redirect('/dev/'); - } else { - if (!isset($_POST["login"])){ - $loginForm = new dev_Form_AuthLogin(); - } else { - $loginForm = new dev_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(array('email' => Zend_Auth::getInstance()->getIdentity()),true); - $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('/dev/'); - 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 dev_Form_AuthRegister(); - } else { - $registerForm = new dev_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) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - echo "Email Address already existing.."; - return; - } - echo "Successfully registered. <br/>"; - echo "Continue to Login: <a href=\""."/dev/auth/login"."\">Login</a>"; - $this->_helper->redirector('login', 'auth'); - return; - } - } - $this->view->registerForm = $registerForm; - } - } - - public function logoutAction() - { - $this->_helper-> viewRenderer-> setNoRender(); - $auth = Zend_Auth::getInstance(); - $auth->clearIdentity(); - Zend_Session::namespaceUnset('userIDs'); - Zend_Session::forgetMe(); - $this->_helper->redirector('login', 'auth'); - return; - } - - public function recoverpasswordAction() - { - if (isset($_POST["savePassword"])){ - $personID = $_POST['personID']; - $recoverPasswordForm = new dev_Form_NewPassword(array("personID" => $personID, $_POST)); - if ($recoverPasswordForm->isValid($_POST)) { - $this->personmapper = new Application_Model_PersonMapper(); - $person = $this->personmapper->find($personID); - $date = new DateTime(); - $person->setPassword($_POST['password']); - $person->setPasswordSalt(MD5($date->getTimestamp())); - $person->setPassword(MD5($person->getPassword() . $person->getPasswordSalt())); - try { - $this->personmapper->save($person); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - echo "Email Address already existing."; - return; - } - $this->_helper->redirector('login', 'auth'); - return; - } - } else if(isset($_GET['recoveryid'])) { - $recoveryid = $_GET['recoveryid']; - $passwordRecoveryMapper = new Application_Model_PasswordRecoveryMapper(); - $passwordRecovery = $passwordRecoveryMapper->findBy(array("recoveryID" => $recoveryid),true); - if(count($passwordRecovery) > 0) { - $passwordRecoveryObject = new Application_Model_PasswordRecovery(); - $passwordRecoveryObject->setID($passwordRecovery[0]['personID']); - $passwordRecoveryObject->setRecoveryID($passwordRecovery[0]['recoveryID']); - $personID = $passwordRecoveryObject->getID(); - $recoverPasswordForm = new dev_Form_NewPassword(array("personID" => $personID)); - try { - $passwordRecoveryMapper->delete($passwordRecoveryObject); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - } else { - $this->_helper->redirector('login', 'auth'); - return; - } - } else { - if (!isset($_POST["recoverPassword"])){ - $recoverPasswordForm = new dev_Form_AuthRecoverPassword(); - } else { - $recoverPasswordForm = new dev_Form_AuthRecoverPassword($_POST); - if ($recoverPasswordForm->isValid($_POST)) { - $recoverPasswordForm->getView()->url(); - $this->personmapper = new Application_Model_PersonMapper(); - $result = $this->personmapper->findBy('email', $_POST['email']); - $person = new Application_Model_Person($result[0]); - $person->setID($result[0]['personID']); - $email = $person->getEmail(); - $name = $person->getFirstname() . ' ' . $person->getName(); - $url = $this->getRequest()->getScheme() . '://' . $this->getRequest()->getHttpHost() . $this->view->url(); - $recoveryid = randomString(100); - $mailbody = 'Um das Passwort zu ändern klicken Sie auf folgenden Link<br /><br /><a href="'. $url . '/auth/recoverpassword/?recoveryid='. $recoveryid . '">Passwort ändern</a>'; - $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'); - $passwordRecoveryMapper = new Application_Model_PasswordRecoveryMapper(); - $passwordRecoveryObject = new Application_Model_PasswordRecovery(); - $passwordRecoveryObject->setID($person->getID()); - $passwordRecoveryObject->setRecoveryID($recoveryid); - try { - $passwordRecoveryMapper->save($passwordRecoveryObject); - $mail->send(); - }catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_helper->redirector('login', 'auth'); - return; - } - } - } - $this->view->recoverPasswordForm = $recoverPasswordForm; - } - - public function deleteAction() - { - if($_POST['confirmdelete']) { - $auth = Zend_Auth::getInstance(); - $result = $this->personmapper->findBy(array('email' => $auth->getIdentity()), true); - $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) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $auth->clearIdentity(); - Zend_Session::namespaceUnset('userIDs'); - Zend_Session::forgetMe(); - $this->_helper->redirector('login', 'auth'); - return; - } - } else { - $deleteconfirmform = new dev_Form_ConfirmDeleteAccount(); - $this->view->deleteconfirmform = $deleteconfirmform; - } - } +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_AuthController extends Zend_Controller_Action { + protected $personmapper; + private $db = null; + + public function init() { + $this->db = Zend_Db_Table::getDefaultAdapter(); + $this->personmapper = new Application_Model_PersonMapper(); + } + + public function indexAction() { + $this->_helper-> viewRenderer-> setNoRender(); + $this->_helper->redirector('login', 'auth'); + } + + public function loginAction() { + if (Zend_Auth::getInstance()->hasIdentity()) { + $this->_redirect('/dev/'); + } else { + if (!isset($_POST["login"])) { + $loginForm = new dev_Form_AuthLogin(); + } else { + $loginForm = new dev_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(array('email' => Zend_Auth::getInstance()->getIdentity()), true); + $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('/dev/'); + 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 dev_Form_AuthRegister(); + } else { + $registerForm = new dev_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) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + echo "Email Address already existing.."; + return; + } + echo "Successfully registered. <br/>"; + echo "Continue to Login: <a href=\""."/dev/auth/login"."\">Login</a>"; + $this->_helper->redirector('login', 'auth'); + return; + } + } + $this->view->registerForm = $registerForm; + } + } + + public function logoutAction() { + $this->_helper-> viewRenderer-> setNoRender(); + $auth = Zend_Auth::getInstance(); + $auth->clearIdentity(); + Zend_Session::namespaceUnset('userIDs'); + Zend_Session::forgetMe(); + $this->_helper->redirector('login', 'auth'); + return; + } + + public function recoverpasswordAction() { + if (isset($_POST["savePassword"])) { + $personID = $_POST['personID']; + $recoverPasswordForm = new dev_Form_NewPassword(array("personID" => $personID, $_POST)); + if ($recoverPasswordForm->isValid($_POST)) { + $this->personmapper = new Application_Model_PersonMapper(); + $person = $this->personmapper->find($personID); + $date = new DateTime(); + $person->setPassword($_POST['password']); + $person->setPasswordSalt(MD5($date->getTimestamp())); + $person->setPassword(MD5($person->getPassword() . $person->getPasswordSalt())); + try { + $this->personmapper->save($person); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + echo "Email Address already existing."; + return; + } + $this->_helper->redirector('login', 'auth'); + return; + } + } else if(isset($_GET['recoveryid'])) { + $recoveryid = $_GET['recoveryid']; + $passwordRecoveryMapper = new Application_Model_PasswordRecoveryMapper(); + $passwordRecovery = $passwordRecoveryMapper->findBy(array("recoveryID" => $recoveryid), true); + if(count($passwordRecovery) > 0) { + $passwordRecoveryObject = new Application_Model_PasswordRecovery(); + $passwordRecoveryObject->setID($passwordRecovery[0]['personID']); + $passwordRecoveryObject->setRecoveryID($passwordRecovery[0]['recoveryID']); + $personID = $passwordRecoveryObject->getID(); + $recoverPasswordForm = new dev_Form_NewPassword(array("personID" => $personID)); + try { + $passwordRecoveryMapper->delete($passwordRecoveryObject); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + } else { + $this->_helper->redirector('login', 'auth'); + return; + } + } else { + if (!isset($_POST["recoverPassword"])) { + $recoverPasswordForm = new dev_Form_AuthRecoverPassword(); + } else { + $recoverPasswordForm = new dev_Form_AuthRecoverPassword($_POST); + if ($recoverPasswordForm->isValid($_POST)) { + $recoverPasswordForm->getView()->url(); + $this->personmapper = new Application_Model_PersonMapper(); + $result = $this->personmapper->findBy('email', $_POST['email']); + $person = new Application_Model_Person($result[0]); + $person->setID($result[0]['personID']); + $email = $person->getEmail(); + $name = $person->getFirstname() . ' ' . $person->getName(); + $url = $this->getRequest()->getScheme() . '://' . $this->getRequest()->getHttpHost() . $this->view->url(); + $recoveryid = randomString(100); + $mailbody = 'Um das Passwort zu ändern klicken Sie auf folgenden Link<br /><br /><a href="'. $url . '/auth/recoverpassword/?recoveryid='. $recoveryid . '">Passwort ändern</a>'; + $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'); + $passwordRecoveryMapper = new Application_Model_PasswordRecoveryMapper(); + $passwordRecoveryObject = new Application_Model_PasswordRecovery(); + $passwordRecoveryObject->setID($person->getID()); + $passwordRecoveryObject->setRecoveryID($recoveryid); + try { + $passwordRecoveryMapper->save($passwordRecoveryObject); + $mail->send(); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_helper->redirector('login', 'auth'); + return; + } + } + } + $this->view->recoverPasswordForm = $recoverPasswordForm; + } + + public function deleteAction() { + if($_POST['confirmdelete']) { + $auth = Zend_Auth::getInstance(); + $result = $this->personmapper->findBy(array('email' => $auth->getIdentity()), true); + $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) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $auth->clearIdentity(); + Zend_Session::namespaceUnset('userIDs'); + Zend_Session::forgetMe(); + $this->_helper->redirector('login', 'auth'); + return; + } + } else { + $deleteconfirmform = new dev_Form_ConfirmDeleteAccount(); + $this->view->deleteconfirmform = $deleteconfirmform; + } + } } diff --git a/application/modules/dev/controllers/BootisoController.php b/application/modules/dev/controllers/BootisoController.php index 5c250cc..d9a2b15 100644 --- a/application/modules/dev/controllers/BootisoController.php +++ b/application/modules/dev/controllers/BootisoController.php @@ -1,194 +1,185 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_BootisoController extends Zend_Controller_Action -{ - - public function init() - { - $db = Zend_Db_Table::getDefaultAdapter(); +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_BootisoController extends Zend_Controller_Action { + + public function init() { + $db = Zend_Db_Table::getDefaultAdapter(); + } + + public function indexAction() { + $bootisomapper = new Application_Model_BootIsoMapper(); + $groupmapper = new Application_Model_GroupMapper(); + $membershipmapper = new Application_Model_MembershipMapper(); + $personmapper = new Application_Model_PersonMapper(); + $prebootmapper = new Application_Model_PreBootMapper(); + + $this->view->bootisolist = $bootisomapper->fetchAll(); + $this->view->prebootlist = array(); + + + foreach ($this->view->bootisolist as $bootiso) { + $this->view->prebootlist[$bootiso->getID()] = $prebootmapper->find($bootiso->getPrebootID())->getTitle(); + $bootiso->setGroupID("[".$bootiso->getGroupID()."] ".$groupmapper->find($bootiso->getGroupID())->getTitle()); + $bootiso->setMembershipID("[".$bootiso->getMembershipID()."] ".$personmapper->find($membershipmapper->find($bootiso->getMembershipID())->getPersonID())->getFirstname()); } - public function indexAction() - { - $bootisomapper = new Application_Model_BootIsoMapper(); - $groupmapper = new Application_Model_GroupMapper(); - $membershipmapper = new Application_Model_MembershipMapper(); - $personmapper = new Application_Model_PersonMapper(); - $prebootmapper = new Application_Model_PreBootMapper(); - - $this->view->bootisolist = $bootisomapper->fetchAll(); - $this->view->prebootlist = array(); - - - foreach ($this->view->bootisolist as $bootiso){ - $this->view->prebootlist[$bootiso->getID()] = $prebootmapper->find($bootiso->getPrebootID())->getTitle(); - $bootiso->setGroupID("[".$bootiso->getGroupID()."] ".$groupmapper->find($bootiso->getGroupID())->getTitle()); - $bootiso->setMembershipID("[".$bootiso->getMembershipID()."] ".$personmapper->find($membershipmapper->find($bootiso->getMembershipID())->getPersonID())->getFirstname()); - } - - } - - public function downloadbootisoAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(true); - - $prebootID = $this->_request->getParam('prebootID'); - $bootisoID = $this->_request->getParam('bootisoID'); - - if(is_dir("../resources/bootmedium/$prebootID/") && is_numeric($prebootID) && is_numeric($bootisoID)){ - - chdir("../resources/bootmedium/$prebootID/"); - - header("X-Sendfile: $bootisoID".".zip"); - header('Content-Type: application/x-gzip'); - $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; - header('Content-Disposition: ' . $content_disp . '; filename="preboot.zip"'); - header('Pragma: no-cache'); - header('Expires: 0'); - - - $handle = fopen($bootisoID.".zip", 'r'); - $chunk_size = 8192; - while ($chunk = fread($handle, $chunk_size)) { - echo $chunk; - ob_flush(); - } - - } - - - - + } + + public function downloadbootisoAction() { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + $prebootID = $this->_request->getParam('prebootID'); + $bootisoID = $this->_request->getParam('bootisoID'); + + if(is_dir("../resources/bootmedium/$prebootID/") && is_numeric($prebootID) && is_numeric($bootisoID)) { + + chdir("../resources/bootmedium/$prebootID/"); + + header("X-Sendfile: $bootisoID".".zip"); + header('Content-Type: application/x-gzip'); + $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; + header('Content-Disposition: ' . $content_disp . '; filename="preboot.zip"'); + header('Pragma: no-cache'); + header('Expires: 0'); + + + $handle = fopen($bootisoID.".zip", 'r'); + $chunk_size = 8192; + while ($chunk = fread($handle, $chunk_size)) { + echo $chunk; + ob_flush(); + } + } - public function createbootisoAction() - { - $groupmapper = new Application_Model_GroupMapper(); - $prebootmapper = new Application_Model_PreBootMapper(); - - if (!isset($_POST["createbootiso"])){ - $createbootisoForm = new dev_Form_BootisoCreate(array('grouplist' => $groupmapper->fetchAll(),'prebootlist' => $prebootmapper->fetchAll())); - } else { - - $createbootisoForm = new dev_Form_BootisoCreate(array('grouplist' => $groupmapper->fetchAll(),'prebootlist' => $prebootmapper->fetchAll()),$_POST); - - if ($createbootisoForm->isValid($_POST)) { - - $bootiso = new Application_Model_BootIso($_POST); - $bootiso->setMembershipID('1'); - $bootisomapper = new Application_Model_BootIsoMapper(); - $bootiso->setCreated(time()); - - $prebootID = $bootiso->getPrebootID(); - - try { - - $bootisoID = $bootisomapper->save($bootiso); - - copy("../resources/bootmedium/$prebootID/preboot.zip", "../resources/bootmedium/$prebootID/$bootisoID".".zip"); - $zip = new ZipArchive(); - $res = $zip->open("../resources/bootmedium/$prebootID/$bootisoID".".zip"); - if($res === true){ - $rootdir = $zip->getNameIndex(0); - $zip->addFromString($rootdir."build/rootfs/tmp/serial", $bootiso->getSerialnumber()); - $zip->close(); - } - - }catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - - } - $this->_redirect('/dev/bootiso'); - } - } - - $this->view->createbootisoForm = $createbootisoForm; + + + + } + + public function createbootisoAction() { + $groupmapper = new Application_Model_GroupMapper(); + $prebootmapper = new Application_Model_PreBootMapper(); + + if (!isset($_POST["createbootiso"])) { + $createbootisoForm = new dev_Form_BootisoCreate(array('grouplist' => $groupmapper->fetchAll(), 'prebootlist' => $prebootmapper->fetchAll())); + } else { + + $createbootisoForm = new dev_Form_BootisoCreate(array('grouplist' => $groupmapper->fetchAll(), 'prebootlist' => $prebootmapper->fetchAll()), $_POST); + + if ($createbootisoForm->isValid($_POST)) { + + $bootiso = new Application_Model_BootIso($_POST); + $bootiso->setMembershipID('1'); + $bootisomapper = new Application_Model_BootIsoMapper(); + $bootiso->setCreated(time()); + + $prebootID = $bootiso->getPrebootID(); + + try { + + $bootisoID = $bootisomapper->save($bootiso); + + copy("../resources/bootmedium/$prebootID/preboot.zip", "../resources/bootmedium/$prebootID/$bootisoID".".zip"); + $zip = new ZipArchive(); + $res = $zip->open("../resources/bootmedium/$prebootID/$bootisoID".".zip"); + if($res == = true) { + $rootdir = $zip->getNameIndex(0); + $zip->addFromString($rootdir."build/rootfs/tmp/serial", $bootiso->getSerialnumber()); + $zip->close(); + } + + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + + } + $this->_redirect('/dev/bootiso'); + } } - public function editbootisoAction() - { - $bootisoID = $this->_request->getParam('bootisoID'); - $groupmapper = new Application_Model_GroupMapper(); - $prebootmapper = new Application_Model_PreBootMapper(); - - - if (!isset($_POST["editbootiso"])){ - $bootisoID = $this->_request->getParam('bootisoID'); - if (!isset($bootisoID) || !is_numeric($bootisoID)){ - $this->_redirect('/dev/bootiso'); - } else { - $bootiso = new Application_Model_BootIso(); - $bootisomapper = new Application_Model_BootIsoMapper(); - $bootisomapper->find($bootisoID, $bootiso); - - $editbootisoForm = new dev_Form_BootisoEdit(array('grouplist' => $groupmapper->fetchAll(),'prebootlist' => $prebootmapper->fetchAll())); - $editbootisoForm->populate($bootiso->toArray()); - } - }else{ - $editbootisoForm = new dev_Form_BootisoEdit(array('grouplist' => $groupmapper->fetchAll(),'prebootlist' => $prebootmapper->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); - $prebootID = $bootiso->getPrebootID(); - - try { - - - $zip = new ZipArchive(); - $res = $zip->open("../resources/bootmedium/$prebootID/$bootisoID".".zip"); - if($res === true){ - $rootdir = $zip->getNameIndex(0); - $zip->addFromString($rootdir."build/rootfs/serial", $bootiso->getSerialnumber()); - $zip->close(); - } - - $bootisomapper->save($bootiso); - - }catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - } - - $this->_redirect('/dev/bootiso'); - } - - } - - $this->view->editbootisoForm = $editbootisoForm; + $this->view->createbootisoForm = $createbootisoForm; + } + + public function editbootisoAction() { + $bootisoID = $this->_request->getParam('bootisoID'); + $groupmapper = new Application_Model_GroupMapper(); + $prebootmapper = new Application_Model_PreBootMapper(); + + + if (!isset($_POST["editbootiso"])) { + $bootisoID = $this->_request->getParam('bootisoID'); + if (!isset($bootisoID) || !is_numeric($bootisoID)) { + $this->_redirect('/dev/bootiso'); + } else { + $bootiso = new Application_Model_BootIso(); + $bootisomapper = new Application_Model_BootIsoMapper(); + $bootisomapper->find($bootisoID, $bootiso); + + $editbootisoForm = new dev_Form_BootisoEdit(array('grouplist' => $groupmapper->fetchAll(), 'prebootlist' => $prebootmapper->fetchAll())); + $editbootisoForm->populate($bootiso->toArray()); + } + } else { + $editbootisoForm = new dev_Form_BootisoEdit(array('grouplist' => $groupmapper->fetchAll(), 'prebootlist' => $prebootmapper->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); + $prebootID = $bootiso->getPrebootID(); + + try { + + + $zip = new ZipArchive(); + $res = $zip->open("../resources/bootmedium/$prebootID/$bootisoID".".zip"); + if($res == = true) { + $rootdir = $zip->getNameIndex(0); + $zip->addFromString($rootdir."build/rootfs/serial", $bootiso->getSerialnumber()); + $zip->close(); + } + + $bootisomapper->save($bootiso); + + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + } + + $this->_redirect('/dev/bootiso'); + } + } - public function deletebootisoAction() - { - $bootisoID = $this->_request->getParam('bootisoID'); - if (!isset($bootisoID)){ - $this->_redirect('/dev/bootiso'); - } else { - $bootiso = new Application_Model_BootIso(); - $bootiso->setID($bootisoID); - $bootisomapper = new Application_Model_BootIsoMapper(); - $bootisomapper->delete($bootiso); - } - $this->_redirect('/dev/bootiso'); + $this->view->editbootisoForm = $editbootisoForm; + } + + public function deletebootisoAction() { + $bootisoID = $this->_request->getParam('bootisoID'); + if (!isset($bootisoID)) { + $this->_redirect('/dev/bootiso'); + } else { + $bootiso = new Application_Model_BootIso(); + $bootiso->setID($bootisoID); + $bootisomapper = new Application_Model_BootIsoMapper(); + $bootisomapper->delete($bootiso); } + $this->_redirect('/dev/bootiso'); + } } diff --git a/application/modules/dev/controllers/BootmenuController.php b/application/modules/dev/controllers/BootmenuController.php index cada566..d05f42c 100644 --- a/application/modules/dev/controllers/BootmenuController.php +++ b/application/modules/dev/controllers/BootmenuController.php @@ -1,330 +1,313 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_BootmenuController extends Zend_Controller_Action -{ - - public function init() - { - $db = Zend_Db_Table::getDefaultAdapter(); - } - - public function indexAction() - { - $bootmenumapper = new Application_Model_BootMenuMapper(); - $bootmenuentriesmapper = new Application_Model_BootMenuEntriesMapper(); - $bootosmapper = new Application_Model_BootOsMapper(); - $configmapper = new Application_Model_ConfigMapper(); - $membershipmapper = new Application_Model_MembershipMapper(); - $groupmapper = new Application_Model_GroupMapper(); - $personmapper = new Application_Model_PersonMapper(); - - $this->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(array('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); - - } - - } +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_BootmenuController extends Zend_Controller_Action { + + public function init() { + $db = Zend_Db_Table::getDefaultAdapter(); + } + + public function indexAction() { + $bootmenumapper = new Application_Model_BootMenuMapper(); + $bootmenuentriesmapper = new Application_Model_BootMenuEntriesMapper(); + $bootosmapper = new Application_Model_BootOsMapper(); + $configmapper = new Application_Model_ConfigMapper(); + $membershipmapper = new Application_Model_MembershipMapper(); + $groupmapper = new Application_Model_GroupMapper(); + $personmapper = new Application_Model_PersonMapper(); + + $this->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(array('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 dev_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 dev_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); + } + + //print_a($bootmenuentry); + + $bootmenuentrymapper->save($bootmenuentry); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + + } + $this->_redirect('/dev/bootmenu'); + } } - public function addbootmenuentryAction() - { - $bootmenuID = $this->_request->getParam('bootmenuID'); - $bootosmapper = new Application_Model_BootOsMapper(); - $configmapper = new Application_Model_ConfigMapper(); - - if (!isset($_POST["addbootmenuentry"])){ - $addbootmenuentryForm = new dev_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 dev_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); - } - - //print_a($bootmenuentry); - - $bootmenuentrymapper->save($bootmenuentry); - }catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - - } - $this->_redirect('/dev/bootmenu'); - } - } - - $this->view->addbootmenuentryForm = $addbootmenuentryForm; - + $this->view->addbootmenuentryForm = $addbootmenuentryForm; + + } + + public function createbootmenuAction() { + $groupmapper = new Application_Model_GroupMapper(); + + if (!isset($_POST["createbootmenu"])) { + $createbootmenuForm = new dev_Form_BootmenuCreate(array('grouplist' => $groupmapper->fetchAll())); + } else { + + $createbootmenuForm = new dev_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) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + + } + $this->_redirect('/dev/bootmenu'); + } } - public function createbootmenuAction() - { - $groupmapper = new Application_Model_GroupMapper(); - - if (!isset($_POST["createbootmenu"])){ - $createbootmenuForm = new dev_Form_BootmenuCreate(array('grouplist' => $groupmapper->fetchAll())); - } else { - - $createbootmenuForm = new dev_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) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - - } - $this->_redirect('/dev/bootmenu'); - } - } - - $this->view->createbootmenuForm = $createbootmenuForm; + $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 dev_Form_BootmenuEdit(array('grouplist' => $groupmapper->fetchAll())); + $editbootmenuForm->populate($bootmenu->toArray()); + } + } else { + $editbootmenuForm = new dev_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) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + } + + $this->_redirect('/dev/bootmenu'); + } + } - 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 dev_Form_BootmenuEdit(array('grouplist' => $groupmapper->fetchAll())); - $editbootmenuForm->populate($bootmenu->toArray()); - } - }else{ - $editbootmenuForm = new dev_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) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - } - - $this->_redirect('/dev/bootmenu'); - } - - } - - $this->view->editbootmenuForm = $editbootmenuForm; + $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('/dev/bootmenu'); + } else { + + $bootmenuentrymapper->find($bootmenuentryID, $bootmenuentry); + + $editbootmenuentryForm = new dev_Form_BootmenuEntriesEdit(array('bootoslist' => $bootosmapper->fetchAll(), 'maxorder' => $this->_request->getParam('maxorder'), 'configlist' => $configmapper->fetchAll(), 'kcl' => $bootmenuentry->getKcl())); + + if(!isset($_POST['configID'])) { + $editbootmenuentryForm->populate($bootmenuentry->toArray()); + } else { + unset($_POST['kcl']); + unset($_POST['configID']); + $editbootmenuentryForm->populate($_POST); + } + } + } else { + $editbootmenuentryForm = new dev_Form_BootmenuEntriesEdit(array('bootoslist' => $bootosmapper->fetchAll(), 'maxorder' => $this->_request->getParam('maxorder'), 'configlist' => $configmapper->fetchAll(), 'kcl' => $bootmenuentry->getKcl()), $_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) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + } + + $this->_redirect('/dev/bootmenu'); + } + } - 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('/dev/bootmenu'); - } else { - - $bootmenuentrymapper->find($bootmenuentryID, $bootmenuentry); - - $editbootmenuentryForm = new dev_Form_BootmenuEntriesEdit(array('bootoslist'=>$bootosmapper->fetchAll(), 'maxorder' => $this->_request->getParam('maxorder'), 'configlist'=>$configmapper->fetchAll(), 'kcl' => $bootmenuentry->getKcl())); - - if(!isset($_POST['configID'])){ - $editbootmenuentryForm->populate($bootmenuentry->toArray()); - } - else{ - unset($_POST['kcl']); - unset($_POST['configID']); - $editbootmenuentryForm->populate($_POST); - } - } - }else{ - $editbootmenuentryForm = new dev_Form_BootmenuEntriesEdit(array('bootoslist'=>$bootosmapper->fetchAll(), 'maxorder'=> $this->_request->getParam('maxorder'), 'configlist'=>$configmapper->fetchAll(), 'kcl' => $bootmenuentry->getKcl()),$_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) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - } - - $this->_redirect('/dev/bootmenu'); - } - - } - - $this->view->editbootmenuentryForm = $editbootmenuentryForm; - + $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('/dev/bootmenu'); + } - 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('/dev/bootmenu'); + public function deletebootmenuAction() { + $bootmenuID = $this->_request->getParam('bootmenuID'); + if (!isset($bootmenuID) || !is_numeric($bootmenuID)) { + $this->_redirect('/dev/bootmenu'); + } else { + $bootmenu = new Application_Model_BootMenu(); + $bootmenu->setID($bootmenuID); + $bootmenumapper = new Application_Model_BootMenuMapper(); + $bootmenumapper->delete($bootmenu); } + $this->_redirect('/dev/bootmenu'); + } - public function deletebootmenuAction() - { - $bootmenuID = $this->_request->getParam('bootmenuID'); - if (!isset($bootmenuID) || !is_numeric($bootmenuID)){ - $this->_redirect('/dev/bootmenu'); - } else { - $bootmenu = new Application_Model_BootMenu(); - $bootmenu->setID($bootmenuID); - $bootmenumapper = new Application_Model_BootMenuMapper(); - $bootmenumapper->delete($bootmenu); - } - $this->_redirect('/dev/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; + } - 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 index 55537a9..dfe2765 100644 --- a/application/modules/dev/controllers/BootosController.php +++ b/application/modules/dev/controllers/BootosController.php @@ -1,218 +1,208 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_BootosController extends Zend_Controller_Action -{ - - public function init() - { - $db = Zend_Db_Table::getDefaultAdapter(); - } +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_BootosController extends Zend_Controller_Action { + + public function init() { + $db = Zend_Db_Table::getDefaultAdapter(); + } + + public function indexAction() { + + $bootosmapper = new Application_Model_BootOsMapper(); + + $groupmapper = new Application_Model_GroupMapper(); + $membershipmapper = new Application_Model_MembershipMapper(); + $personmapper = new Application_Model_PersonMapper(); + $configmapper = new Application_Model_ConfigMapper(); + + $this->view->bootoslist = $bootosmapper->fetchAll(); + $this->view->update = array(); - public function indexAction() - { - - $bootosmapper = new Application_Model_BootOsMapper(); - - $groupmapper = new Application_Model_GroupMapper(); - $membershipmapper = new Application_Model_MembershipMapper(); - $personmapper = new Application_Model_PersonMapper(); - $configmapper = new Application_Model_ConfigMapper(); - - $this->view->bootoslist = $bootosmapper->fetchAll(); - $this->view->update = array(); - - if(count($this->view->bootoslist)>0){ - foreach ($this->view->bootoslist as $bootos){ - $this->view->update[$bootos->getID()] = $this->checkupdateAction($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()); - - } - } - + if(count($this->view->bootoslist) > 0) { + foreach ($this->view->bootoslist as $bootos) { + $this->view->update[$bootos->getID()] = $this->checkupdateAction($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"])){ - try{ - $createbootosForm = new dev_Form_BootosCreate(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll())); - }catch(Zend_Exception $e){ - print_a($e); - } - } else { - - $createbootosForm = new dev_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 { - exec("wget --spider ".$bootos->getPath_kernel()." 2>&1 | grep 'Remote file exists.'", $exists_kernel); - exec("wget --spider ".$bootos->getPath_init()." 2>&1 | grep 'Remote file exists.'" , $exists_init); - - if(!array_pop($exists_init) || !array_pop($exists_kernel)){ - $this->view->createbootosForm = $createbootosForm; - return; - } - - $bootosID = $bootosmapper->save($bootos); - - $initpath = "../resources/bootos/".$bootosID."/initramfs/"; - $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; - - mkdir($initpath ,0777, true); - mkdir($kernelpath ,0777, true); - - exec("wget -O '".$kernelpath."kernel' ".$bootos->getPath_kernel()); - exec("wget -O '".$initpath."initramfs' ".$bootos->getPath_init()); - - - - }catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - - } - - $this->_redirect('/dev/bootos'); - } - } - + } + + public function createbootosAction() { + $groupmapper = new Application_Model_GroupMapper(); + $configmapper = new Application_Model_ConfigMapper(); + + if (!isset($_POST["createbootos"])) { + try { + $createbootosForm = new dev_Form_BootosCreate(array('grouplist' => $groupmapper->fetchAll() , 'configlist' => $configmapper->fetchAll())); + } catch(Zend_Exception $e) { + print_a($e); + } + } else { + + $createbootosForm = new dev_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 { + exec("wget --spider ".$bootos->getPath_kernel()." 2>&1 | grep 'Remote file exists.'", $exists_kernel); + exec("wget --spider ".$bootos->getPath_init()." 2>&1 | grep 'Remote file exists.'" , $exists_init); + + if(!array_pop($exists_init) || !array_pop($exists_kernel)) { $this->view->createbootosForm = $createbootosForm; + return; + } + + $bootosID = $bootosmapper->save($bootos); + + $initpath = "../resources/bootos/".$bootosID."/initramfs/"; + $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; + + mkdir($initpath , 0777, true); + mkdir($kernelpath , 0777, true); + + exec("wget -O '".$kernelpath."kernel' ".$bootos->getPath_kernel()); + exec("wget -O '".$initpath."initramfs' ".$bootos->getPath_init()); + + + + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + + } + + $this->_redirect('/dev/bootos'); + } } - - public function checkupdateAction($bootos) - { - exec("wget --server-response --spider '".escapeshellcmd($bootos->getPath_kernel())."' 2>&1 | grep 'Last-Modified:'", $kerneldate); - exec("wget --server-response --spider '".escapeshellcmd($bootos->getPath_init())."' 2>&1 | grep 'Last-Modified:'", $initdate); - - $kerneldate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($kerneldate)))); - $kernelname = array_pop(scandir("../resources/bootos/".$bootos->getID()."/kernel/")); - - if($kernelname != "." && $kernelname != "..") - $kernelolddate = filemtime("../resources/bootos/".$bootos->getID()."/kernel/".$kernelname); - else - $kernelolddate = false; - - $initdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($initdate)))); - $initname = array_pop(scandir("../resources/bootos/".$bootos->getID()."/initramfs/")); - - if($initname != "." && $initname != "..") - $initolddate = filemtime("../resources/bootos/".$bootos->getID()."/initramfs/".$initname); - else - $initolddate = false; - - //print_a($kernelname,$kerneldate,$kernelolddate,$initname,$initdate,$initolddate); - - - if($kerneldate > $kernelolddate || $initdate > $initolddate) - return true; - else - return false; - - } - - public function updatebootosAction() - { - $bootosID = $this->_request->getParam('bootosID'); - $bootosmapper = new Application_Model_BootOsMapper(); - $bootos = $bootosmapper->find($bootosID); - - $initpath = "../resources/bootos/".$bootosID."/initramfs/"; - $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; - - exec("wget -P ".$kernelpath." -N ".$bootos->getPath_kernel()); - exec("wget -P ".$initpath." -N ".$bootos->getPath_init()); - - $this->_redirect('/dev/bootos'); - } - 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('/dev/bootos'); - } else { - $bootos = new Application_Model_BootOs(); - $bootosmapper = new Application_Model_BootOsMapper(); - $bootos = $bootosmapper->find($bootosID); - - $editbootosForm = new dev_Form_BootosEdit(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll())); - $editbootosForm->populate($bootos->toArray()); - } - }else{ - $editbootosForm = new dev_Form_BootosEdit(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()),$_POST); - - if ($editbootosForm->isValid($_POST)) { - - //TODO: Check for new URL and download new files. - $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) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - } - - $this->_redirect('/dev/bootos'); - } - - } - - $this->view->editbootosForm = $editbootosForm; - + $this->view->createbootosForm = $createbootosForm; + } + + public function checkupdateAction($bootos) { + exec("wget --server-response --spider '".escapeshellcmd($bootos->getPath_kernel())."' 2>&1 | grep 'Last-Modified:'", $kerneldate); + exec("wget --server-response --spider '".escapeshellcmd($bootos->getPath_init())."' 2>&1 | grep 'Last-Modified:'", $initdate); + + $kerneldate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($kerneldate)))); + $kernelname = array_pop(scandir("../resources/bootos/".$bootos->getID()."/kernel/")); + + if($kernelname != "." && $kernelname != "..") + { $kernelolddate = filemtime("../resources/bootos/".$bootos->getID()."/kernel/".$kernelname); } + else + { $kernelolddate = false; } + + $initdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($initdate)))); + $initname = array_pop(scandir("../resources/bootos/".$bootos->getID()."/initramfs/")); + + if($initname != "." && $initname != "..") + { $initolddate = filemtime("../resources/bootos/".$bootos->getID()."/initramfs/".$initname); } + else + { $initolddate = false; } + + //print_a($kernelname,$kerneldate,$kernelolddate,$initname,$initdate,$initolddate); + + + if($kerneldate > $kernelolddate || $initdate > $initolddate) + { return true; } + else + { return false; } + + } + + public function updatebootosAction() { + $bootosID = $this->_request->getParam('bootosID'); + $bootosmapper = new Application_Model_BootOsMapper(); + $bootos = $bootosmapper->find($bootosID); + + $initpath = "../resources/bootos/".$bootosID."/initramfs/"; + $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; + + exec("wget -P ".$kernelpath." -N ".$bootos->getPath_kernel()); + exec("wget -P ".$initpath." -N ".$bootos->getPath_init()); + + $this->_redirect('/dev/bootos'); + } + + 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('/dev/bootos'); + } else { + $bootos = new Application_Model_BootOs(); + $bootosmapper = new Application_Model_BootOsMapper(); + $bootos = $bootosmapper->find($bootosID); + + $editbootosForm = new dev_Form_BootosEdit(array('grouplist' => $groupmapper->fetchAll() , 'configlist' => $configmapper->fetchAll())); + $editbootosForm->populate($bootos->toArray()); + } + } else { + $editbootosForm = new dev_Form_BootosEdit(array('grouplist' => $groupmapper->fetchAll() , 'configlist' => $configmapper->fetchAll()), $_POST); + + if ($editbootosForm->isValid($_POST)) { + + //TODO: Check for new URL and download new files. + $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) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + } + + $this->_redirect('/dev/bootos'); + } + } - public function deletebootosAction() - { - $bootosID = $this->_request->getParam('bootosID'); - if (!isset($bootosID)){ - $this->_redirect('/dev/bootos'); - } else { - $bootos = new Application_Model_BootOs(); - $bootos->setID($bootosID); - $bootosmapper = new Application_Model_BootOsMapper(); - $bootosmapper->delete($bootos); - } - $this->_redirect('/dev/bootos'); - + $this->view->editbootosForm = $editbootosForm; + + } + + public function deletebootosAction() { + $bootosID = $this->_request->getParam('bootosID'); + if (!isset($bootosID)) { + $this->_redirect('/dev/bootos'); + } else { + $bootos = new Application_Model_BootOs(); + $bootos->setID($bootosID); + $bootosmapper = new Application_Model_BootOsMapper(); + $bootosmapper->delete($bootos); } + $this->_redirect('/dev/bootos'); + + } } diff --git a/application/modules/dev/controllers/ClientController.php b/application/modules/dev/controllers/ClientController.php index b6c202c..d70db4a 100644 --- a/application/modules/dev/controllers/ClientController.php +++ b/application/modules/dev/controllers/ClientController.php @@ -1,101 +1,93 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_ClientController extends Zend_Controller_Action -{ - - public function init() - { - /* Initialize action controller here */ +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_ClientController extends Zend_Controller_Action { + + public function init() { + /* Initialize action controller here */ + } + + public function indexAction() { + $clientMapper = new Application_Model_ClientMapper(); + $this->view->clients = $clientMapper->fetchAll(); + } + + public function addclientAction() { + $mac = $this->_request->getParam('mac'); + $hh = $this->_request->getParam('hh'); + + $groupMapper = new Application_Model_GroupMapper(); + $groups = $groupMapper->fetchAll(); +#print_a($groups);die(); + + if (!isset($_POST["add"])) { + $addclient = new dev_Form_Client(array('buttontext' => 'Create Client', 'groups' => $groups)); + $this->view->addclient = $addclient; + } else { + $addfilterform = new dev_Form_Client(array('buttontext' => 'Create Client', 'groups' => $groups), $_POST); + if ($addfilterform->isValid($_POST) || ($mac != '' && $hh != '') ) { + $client = new Application_Model_Client($_POST); + $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('/dev/client'); + } + $this->view->addclient = $addclient; } - - public function indexAction() - { - $clientMapper = new Application_Model_ClientMapper(); - $this->view->clients = $clientMapper->fetchAll(); - } - - public function addclientAction() - { - $mac = $this->_request->getParam('mac'); - $hh = $this->_request->getParam('hh'); - - $groupMapper = new Application_Model_GroupMapper(); - $groups = $groupMapper->fetchAll(); - #print_a($groups);die(); - - if (!isset($_POST["add"])){ - $addclient = new dev_Form_Client(array('buttontext' => 'Create Client','groups'=>$groups)); - $this->view->addclient = $addclient; - } - else{ - $addfilterform = new dev_Form_Client(array('buttontext' => 'Create Client','groups'=>$groups),$_POST); - if ($addfilterform->isValid($_POST) || ($mac != '' && $hh != '') ) { - $client = new Application_Model_Client($_POST); - $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('/dev/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); } - - 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('/dev/client'); - } - - public function editclientAction() - { - $groupMapper = new Application_Model_GroupMapper(); - $groups = $groupMapper->fetchAll(); - # print_a($this);die(); - - if (!isset($_POST["add"])){ - $clientID = $this->_request->getParam('clientID'); - $data = new Application_Model_Client(); - $mapper = new Application_Model_ClientMapper(); - $mapper->find($clientID,$data); - - $editclient = new dev_Form_Client(array('buttontext' => 'Edit Client', 'groups'=>$groups)); - $editclient->populate($data->toArray()); - $this->view->editclient = $editclient; - } - else{ - $editclient = new dev_Form_Client(array('buttontext' => 'Edit Client','groups'=>$groups),$_POST); - if ($editclient->isValid($_POST) || ($mac != '' && $hh != '') ) { - $client = new Application_Model_Client($_POST); - $client->setID($this->_request->getParam('clientID')); - $clientmapper = new Application_Model_ClientMapper(); - $clientmapper->save($client); - print_a('updated'); - $this->_redirect('/dev/client'); - } - $this->view->editclient = $editclient; - } + $this->_redirect('/dev/client'); + } + + public function editclientAction() { + $groupMapper = new Application_Model_GroupMapper(); + $groups = $groupMapper->fetchAll(); +# print_a($this);die(); + + if (!isset($_POST["add"])) { + $clientID = $this->_request->getParam('clientID'); + $data = new Application_Model_Client(); + $mapper = new Application_Model_ClientMapper(); + $mapper->find($clientID, $data); + + $editclient = new dev_Form_Client(array('buttontext' => 'Edit Client', 'groups' => $groups)); + $editclient->populate($data->toArray()); + $this->view->editclient = $editclient; + } else { + $editclient = new dev_Form_Client(array('buttontext' => 'Edit Client', 'groups' => $groups), $_POST); + if ($editclient->isValid($_POST) || ($mac != '' && $hh != '') ) { + $client = new Application_Model_Client($_POST); + $client->setID($this->_request->getParam('clientID')); + $clientmapper = new Application_Model_ClientMapper(); + $clientmapper->save($client); + print_a('updated'); + $this->_redirect('/dev/client'); + } + $this->view->editclient = $editclient; } + } } diff --git a/application/modules/dev/controllers/ConfigController.php b/application/modules/dev/controllers/ConfigController.php index d89b6e1..2b0b857 100644 --- a/application/modules/dev/controllers/ConfigController.php +++ b/application/modules/dev/controllers/ConfigController.php @@ -1,129 +1,121 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_ConfigController extends Zend_Controller_Action -{ - - public function init() - { - $db = Zend_Db_Table::getDefaultAdapter(); - } - - public function indexAction() - { - $configmapper = new Application_Model_ConfigMapper(); - - $groupmapper = new Application_Model_GroupMapper(); - $membershipmapper = new Application_Model_MembershipMapper(); - $personmapper = new Application_Model_PersonMapper(); - - $this->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()); - } - +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_ConfigController extends Zend_Controller_Action { + + public function init() { + $db = Zend_Db_Table::getDefaultAdapter(); + } + + public function indexAction() { + $configmapper = new Application_Model_ConfigMapper(); + + $groupmapper = new Application_Model_GroupMapper(); + $membershipmapper = new Application_Model_MembershipMapper(); + $personmapper = new Application_Model_PersonMapper(); + + $this->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 dev_Form_ConfigCreate(array('grouplist' => $groupmapper->fetchAll())); - } else { - - $createconfigForm = new dev_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) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - - } - $this->_redirect('/dev/config'); - } - } - - $this->view->createconfigForm = $createconfigForm; + } + + public function createconfigAction() { + $groupmapper = new Application_Model_GroupMapper(); + if (!isset($_POST["createconfig"])) { + $createconfigForm = new dev_Form_ConfigCreate(array('grouplist' => $groupmapper->fetchAll())); + } else { + + $createconfigForm = new dev_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) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + + } + $this->_redirect('/dev/config'); + } } - 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('/dev/config'); - } else { - $config = new Application_Model_Config(); - $configmapper = new Application_Model_ConfigMapper(); - $config = $configmapper->find($configID); - - $editconfigForm = new dev_Form_ConfigEdit(array('grouplist' => $groupmapper->fetchAll())); - $editconfigForm->populate($config->toArray()); - } - }else{ - $editconfigForm = new dev_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) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - } - - $this->_redirect('/dev/config'); - } - - } - - $this->view->editconfigForm = $editconfigForm; + $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('/dev/config'); + } else { + $config = new Application_Model_Config(); + $configmapper = new Application_Model_ConfigMapper(); + $config = $configmapper->find($configID); + + $editconfigForm = new dev_Form_ConfigEdit(array('grouplist' => $groupmapper->fetchAll())); + $editconfigForm->populate($config->toArray()); + } + } else { + $editconfigForm = new dev_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) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + } + + $this->_redirect('/dev/config'); + } + } - public function deleteconfigAction() - { - $configID = $this->_request->getParam('configID'); - if (!isset($configID)){ - $this->_redirect('/dev/config'); - } else { - $config = new Application_Model_Config(); - $config->setID($configID); - $configmapper = new Application_Model_ConfigMapper(); - $configmapper->delete($config); - } - $this->_redirect('/dev/config'); + $this->view->editconfigForm = $editconfigForm; + } + + public function deleteconfigAction() { + $configID = $this->_request->getParam('configID'); + if (!isset($configID)) { + $this->_redirect('/dev/config'); + } else { + $config = new Application_Model_Config(); + $config->setID($configID); + $configmapper = new Application_Model_ConfigMapper(); + $configmapper->delete($config); } + $this->_redirect('/dev/config'); + } } diff --git a/application/modules/dev/controllers/ErrorController.php b/application/modules/dev/controllers/ErrorController.php index 6d63b1b..02f4c2f 100644 --- a/application/modules/dev/controllers/ErrorController.php +++ b/application/modules/dev/controllers/ErrorController.php @@ -1,61 +1,58 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_ErrorController extends Zend_Controller_Action -{ - - public function errorAction() - { - $errors = $this->_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'; - print_a($errors); - break; - default: - // application error - $this->getResponse()->setHttpResponseCode(500); - $this->view->message = 'Application error'; - print_a($errors); - 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; +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_ErrorController extends Zend_Controller_Action { + + public function errorAction() { + $errors = $this->_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'; + print_a($errors); + break; + default: + // application error + $this->getResponse()->setHttpResponseCode(500); + $this->view->message = 'Application error'; + print_a($errors); + 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; } - public function getLog() - { - $bootstrap = $this->getInvokeArg('bootstrap'); - if (!$bootstrap->hasPluginResource('Log')) { - return false; - } - $log = $bootstrap->getResource('Log'); - return $log; + $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 index d68f033..b8aecfd 100644 --- a/application/modules/dev/controllers/FilterController.php +++ b/application/modules/dev/controllers/FilterController.php @@ -1,674 +1,656 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_FilterController extends Zend_Controller_Action -{ - - private $_filtermapper = null; - - private $db = null; - - public function init() - { - try{ - $this->_filtermapper = new Application_Model_FilterMapper(); - }catch (Zend_Exception $e) { - echo "Error message 1: " . $e->getMessage() . "\n"; - } - $this->db = Zend_Db_Table::getDefaultAdapter(); +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_FilterController extends Zend_Controller_Action { + + private $_filtermapper = null; + + private $db = null; + + public function init() { + try { + $this->_filtermapper = new Application_Model_FilterMapper(); + } catch (Zend_Exception $e) { + echo "Error message 1: " . $e->getMessage() . "\n"; } - - 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 dev_Form_FilterAdd(array('buttontext' => 'Create Filter','bootmenus'=>$bootmenus)); - $this->view->addfilterform = $addfilterform; - }else { - $addfilterform = new dev_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('/dev/filter'); - return; - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - } - } - $this->view->addfilterform = $addfilterform; - } + $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 dev_Form_FilterAdd(array('buttontext' => 'Create Filter', 'bootmenus' => $bootmenus)); + $this->view->addfilterform = $addfilterform; + } else { + $addfilterform = new dev_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('/dev/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('/dev/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(); - public function removefilterAction() - { + + $filtermapper = new Application_Model_FilterMapper(); + $filtermapper->find($filterID, $filter); + $filter2 = $filter->toArray(); + + $editfilterform = new dev_Form_FilterAdd(array('buttontext' => 'Edit Filter', 'bootmenus' => $bootmenus)); + $editfilterform->populate($filter2); + $this->view->editfilterform = $editfilterform; + + } else { + try { $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('/dev/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 dev_Form_FilterAdd(array('buttontext' => 'Edit Filter','bootmenus'=>$bootmenus)); - $editfilterform->populate($filter2); - $this->view->editfilterform = $editfilterform; - - } else{ - try{ - $filterID = $this->_request->getParam('filterID'); - - $editfilterform = new dev_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('/dev/filter'); - } - $this->view->editfilterform = $editfilterform; - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - } - } + $editfilterform = new dev_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('/dev/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 dev_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 dev_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('/dev/filter'); - } - $this->view->editfilterform = $editfilterform; - } + } + + public function addfilterentryAction() { + // TODO: ACL implementieren ob er editieren darf + if (!isset($_POST["add"])) { + try { + $editfilterform = new dev_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 dev_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('/dev/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 dev_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 dev_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('/dev/filter'); - - } - $this->view->editfilterform = $editfilterform; - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - } - } + } + + 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 dev_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 dev_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('/dev/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); - - $filterentriesmapper = new Application_Model_FilterEntriesMapper(); - $filterentriesmapper->delete($deletefilterentry); - echo "ok"; - } - $this->_redirect('/dev/filter'); - }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); + + $filterentriesmapper = new Application_Model_FilterEntriesMapper(); + $filterentriesmapper->delete($deletefilterentry); + echo "ok"; + } + $this->_redirect('/dev/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 fillIP($ip) { + $ar = explode(".", $ip); + $representation = array(); + foreach($ar as $part) { + $representation[] = sprintf("%03s", $part); } - - private function fillMac($ip) - { - $ar = explode(":",$ip); - $representation = array(); - foreach($ar as $part){ - $representation[] = sprintf("%02s",$part); - } - return implode(":",$representation); + return implode(".", $representation); + } + + private function fillMac($ip) { + $ar = explode(":", $ip); + $representation = array(); + foreach($ar as $part) { + $representation[] = sprintf("%02s", $part); } - - 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(array('clientID' => $client->getID()),true); - $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 "<h1><a href='/bootmenu/index/bootmenuid/".$bootmenuID."'>Goto BootmenuID: ".$bootmenuID."</a></h1>"; - } - else{ - echo "<h1>No Result :-(</h1>"; - } - - }catch (Zend_Exception $e) { - echo "class: ".get_class($e)."<br>\n"; - echo "Error message 2: " . $e->getMessage() . "\n"; - } + 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)); } - public function testevaluateAction() - { - $pm = new Application_Model_PoolMapper(); - $pools = $pm->fetchAll(); - - $bim = new Application_Model_BootIsoMapper(); - $bootisos = $bim->fetchAll(); - - $mm = new Application_Model_MembershipMapper(); - $memberships = $mm->fetchAll(); - - $gm = new Application_Model_GroupMapper(); - $groups = $gm->fetchAll(); - - $cm = new Application_Model_ClientMapper(); - $clients = $cm->fetchAll(); - - $filterevaluate = new dev_Form_FilterEvaluate( - array( 'pools' => $pools, - 'bootisos' => $bootisos, - 'memberships' => $memberships, - 'groups' => $groups, - 'clients' => $clients, - - )); - $filterevaluate->populate(array( - 'ip' => '132.230.5.6', - 'mac' => '08:00:20:ae:fd:7e', - 'time'=>date('d.m.Y H:i')) - ); - $this->view->filterevaluate = $filterevaluate; + + 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(array('clientID' => $client->getID()), true); + $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 "<h1><a href='/bootmenu/index/bootmenuid/".$bootmenuID."'>Goto BootmenuID: ".$bootmenuID."</a></h1>"; + } else { + echo "<h1>No Result :-(</h1>"; + } + + } catch (Zend_Exception $e) { + echo "class: ".get_class($e)."<br>\n"; + echo "Error message 2: " . $e->getMessage() . "\n"; } + } + + public function testevaluateAction() { + $pm = new Application_Model_PoolMapper(); + $pools = $pm->fetchAll(); + + $bim = new Application_Model_BootIsoMapper(); + $bootisos = $bim->fetchAll(); + + $mm = new Application_Model_MembershipMapper(); + $memberships = $mm->fetchAll(); + + $gm = new Application_Model_GroupMapper(); + $groups = $gm->fetchAll(); + + $cm = new Application_Model_ClientMapper(); + $clients = $cm->fetchAll(); + + $filterevaluate = new dev_Form_FilterEvaluate( + array( 'pools' => $pools, + 'bootisos' => $bootisos, + 'memberships' => $memberships, + 'groups' => $groups, + 'clients' => $clients, + + )); + $filterevaluate->populate(array( + 'ip' => '132.230.5.6', + 'mac' => '08:00:20:ae:fd:7e', + 'time' => date('d.m.Y H:i')) + ); + $this->view->filterevaluate = $filterevaluate; + } } diff --git a/application/modules/dev/controllers/GroupController.php b/application/modules/dev/controllers/GroupController.php index 4188a1d..08bbe45 100644 --- a/application/modules/dev/controllers/GroupController.php +++ b/application/modules/dev/controllers/GroupController.php @@ -1,258 +1,240 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_GroupController extends Zend_Controller_Action -{ - protected $groupMapper; - protected $groupGroupsMapper; - protected $membershipMapper; - protected $groupRequestMapper; - protected $personmapper; - protected $rolemapper; - protected $groupList; - - public function init() - { - if (Zend_Auth::getInstance()->hasIdentity()) { - $this->groupMapper = new Application_Model_GroupMapper(); - $this->groupGroupsMapper = new Application_Model_GroupGroupsMapper(); - $this->membershipMapper = new Application_Model_MembershipMapper(); - $this->groupRequestMapper = new Application_Model_GroupRequestMapper(); - $this->personmapper = new Application_Model_PersonMapper(); - $this->rolemapper = new Application_Model_RoleMapper(); - $this->groupList = $this->groupMapper->fetchAll(); - } else { - $this->_helper->redirector('login', 'auth'); - return; - } - } - - public function indexAction() - { - $this->view->groupList = $this->groupList; - } - - public function addAction() - { - if (!isset($_POST["add"])){ - $addForm = new dev_Form_GroupAdd(array('grouplist' => $this->groupList)); - } else { - $addForm = new dev_Form_GroupAdd(array('grouplist' => $this->groupList),$_POST); - - if ($addForm->isValid($_POST)) { - $group = new Application_Model_Group($_POST); - try { - $this->groupMapper->save($group); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - if($_POST['superordinatedGroupID'] != -1) { - $lastID = $this->groupMapper->getDbTable()->getDefaultAdapter()->lastInsertId(); - $groupgroups = new Application_Model_GroupGroups(); - $groupgroups->setParentID($_POST['superordinatedGroupID']); - $groupgroups->setGroupID($lastID); - try { - $this->groupGroupsMapper->save($groupgroups); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - - } - $this->_helper->redirector('', 'group'); - return; - } - } - - $this->view->addForm = $addForm; - } - - public function editAction() - { - $groupID = $this->_request->getParam('groupID'); - if(!isset($groupID)) { - $addForm = new dev_Form_GroupAdd(array('grouplist' => $this->groupList)); - $this->view->addForm = $addForm; - return; - } - if (!isset($_POST["save"])){ - $group = $this->groupMapper->find($groupID); - $_POST['title'] = $group->getTitle(); - $_POST['description'] = $group->getDescription(); - $editForm = new dev_Form_GroupEdit(); - } else { - $editForm = new dev_Form_GroupEdit($_POST); - if ($editForm->isValid($_POST)) { - $group = new Application_Model_Group($_POST); - $group->setID($this->_request->getParam('groupID')); - try { - $this->groupMapper->save($group); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_helper->redirector('', 'group'); - return; - } - } - - $this->view->editForm = $editForm; - - } - - public function showAction() - { - $groupID = $this->_request->getParam('groupID'); - if($groupID) { - $groupRequests = $this->groupRequestMapper->findBy(array('groupID' => $groupID),true); - if(isset($groupRequests)) { - foreach($groupRequests as $groupRequest) { - $person = $this->personmapper->find($groupRequest['personID']); - $groupRequestList[] = array( - 'grouprequestID' => $groupRequest['grouprequestID'], - 'person' => $person - ); - } - if(is_array($groupRequestList)) { - $this->view->groupRequestList = $groupRequestList; - } - $this->view->roleList = $this->rolemapper->findBy('groupID', $groupID); - } - $members = $this->membershipMapper->findBy('groupID', $groupID); - if(isset($members)) { - foreach($members as $member) { - $person = $this->personmapper->find($member['personID']); - $membersList[] = array( - 'membershipID' => $member['membershipID'], - 'person' => $person - ); - } - if(is_array($membersList)) { - $this->view->membersList = $membersList; - } - } - $groupgroups = $this->groupGroupsMapper->findBy('groupID', $groupID); - if(is_object($groupgroups)) { - $parentGroup = $this->groupMapper->find($groupgroups->getParentID()); - $this->view->$parentGroup = $parentGroup; - } - $group = $this->groupMapper->find($groupID); - $this->view->group = $group; - $this->view->groupID = $groupID; - } - } - - public function linkAction() - { - if (!isset($_POST["link"])){ - $linkForm = new dev_Form_GroupLink(array('grouplist' => $this->groupList)); - } else { - $linkForm = new dev_Form_GroupLink(array('grouplist' => $this->groupList),$_POST); - - if ($linkForm->isValid($_POST)) { - $groupgroups = new Application_Model_GroupGroups(); - $groupgroups->setParentID($_POST['superordinatedGroupID']); - $groupgroups->setGroupID($_POST['groupID']); - try { - $this->groupGroupsMapper->save($groupgroups); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_helper->redirector('', 'group'); - return; - } - } - - $this->view->linkForm = $linkForm; - } - - public function deleteAction() - { - $this->_helper->viewRenderer->setNoRender(); - $groupID = $this->_request->getParam('groupID'); - if (isset($groupID)){ - $group = $this->groupMapper->find($groupID); - try { - $this->groupMapper->delete($group); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_helper->redirector('', 'group'); - return; - } - } - - public function grantpersonAction() - { - $this->_helper->viewRenderer->setNoRender(); - if(isset($_POST['grouprequestID']) && isset($_POST['roleID'])) { - $groupRequest = $this->groupRequestMapper->find($_POST['grouprequestID']); - try { - $this->groupRequestMapper->delete($groupRequest); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $membership = new Application_Model_Membership(); - $membership->setGroupID($groupRequest->getGroupID()); - $membership->setPersonID($groupRequest->getPersonID()); - $membership->setRoleID($_POST['roleID']); - try { - $this->membershipMapper->save($membership); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_redirect("/dev/group/show/groupID/" . $groupRequest->getGroupID()); - } - } - - public function revokepersonAction() - { - $this->_helper->viewRenderer->setNoRender(); - $membershipID = $this->_request->getParam('membershipID'); - if(isset($membershipID)) { - $membership = $this->membershipMapper->find($membershipID); - if(isset($membership)) { - try { - $this->membershipMapper->delete($membership); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_redirect("/dev/group/edit/groupID/" . $membership->getGroupID()); - } - - } - } +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_GroupController extends Zend_Controller_Action { + protected $groupMapper; + protected $groupGroupsMapper; + protected $membershipMapper; + protected $groupRequestMapper; + protected $personmapper; + protected $rolemapper; + protected $groupList; + + public function init() { + if (Zend_Auth::getInstance()->hasIdentity()) { + $this->groupMapper = new Application_Model_GroupMapper(); + $this->groupGroupsMapper = new Application_Model_GroupGroupsMapper(); + $this->membershipMapper = new Application_Model_MembershipMapper(); + $this->groupRequestMapper = new Application_Model_GroupRequestMapper(); + $this->personmapper = new Application_Model_PersonMapper(); + $this->rolemapper = new Application_Model_RoleMapper(); + $this->groupList = $this->groupMapper->fetchAll(); + } else { + $this->_helper->redirector('login', 'auth'); + return; + } + } + + public function indexAction() { + $this->view->groupList = $this->groupList; + } + + public function addAction() { + if (!isset($_POST["add"])) { + $addForm = new dev_Form_GroupAdd(array('grouplist' => $this->groupList)); + } else { + $addForm = new dev_Form_GroupAdd(array('grouplist' => $this->groupList), $_POST); + + if ($addForm->isValid($_POST)) { + $group = new Application_Model_Group($_POST); + try { + $this->groupMapper->save($group); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + if($_POST['superordinatedGroupID'] != -1) { + $lastID = $this->groupMapper->getDbTable()->getDefaultAdapter()->lastInsertId(); + $groupgroups = new Application_Model_GroupGroups(); + $groupgroups->setParentID($_POST['superordinatedGroupID']); + $groupgroups->setGroupID($lastID); + try { + $this->groupGroupsMapper->save($groupgroups); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + + } + $this->_helper->redirector('', 'group'); + return; + } + } + + $this->view->addForm = $addForm; + } + + public function editAction() { + $groupID = $this->_request->getParam('groupID'); + if(!isset($groupID)) { + $addForm = new dev_Form_GroupAdd(array('grouplist' => $this->groupList)); + $this->view->addForm = $addForm; + return; + } + if (!isset($_POST["save"])) { + $group = $this->groupMapper->find($groupID); + $_POST['title'] = $group->getTitle(); + $_POST['description'] = $group->getDescription(); + $editForm = new dev_Form_GroupEdit(); + } else { + $editForm = new dev_Form_GroupEdit($_POST); + if ($editForm->isValid($_POST)) { + $group = new Application_Model_Group($_POST); + $group->setID($this->_request->getParam('groupID')); + try { + $this->groupMapper->save($group); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_helper->redirector('', 'group'); + return; + } + } + + $this->view->editForm = $editForm; + + } + + public function showAction() { + $groupID = $this->_request->getParam('groupID'); + if($groupID) { + $groupRequests = $this->groupRequestMapper->findBy(array('groupID' => $groupID), true); + if(isset($groupRequests)) { + foreach($groupRequests as $groupRequest) { + $person = $this->personmapper->find($groupRequest['personID']); + $groupRequestList[] = array( + 'grouprequestID' => $groupRequest['grouprequestID'], + 'person' => $person + ); + } + if(is_array($groupRequestList)) { + $this->view->groupRequestList = $groupRequestList; + } + $this->view->roleList = $this->rolemapper->findBy('groupID', $groupID); + } + $members = $this->membershipMapper->findBy('groupID', $groupID); + if(isset($members)) { + foreach($members as $member) { + $person = $this->personmapper->find($member['personID']); + $membersList[] = array( + 'membershipID' => $member['membershipID'], + 'person' => $person + ); + } + if(is_array($membersList)) { + $this->view->membersList = $membersList; + } + } + $groupgroups = $this->groupGroupsMapper->findBy('groupID', $groupID); + if(is_object($groupgroups)) { + $parentGroup = $this->groupMapper->find($groupgroups->getParentID()); + $this->view->$parentGroup = $parentGroup; + } + $group = $this->groupMapper->find($groupID); + $this->view->group = $group; + $this->view->groupID = $groupID; + } + } + + public function linkAction() { + if (!isset($_POST["link"])) { + $linkForm = new dev_Form_GroupLink(array('grouplist' => $this->groupList)); + } else { + $linkForm = new dev_Form_GroupLink(array('grouplist' => $this->groupList), $_POST); + + if ($linkForm->isValid($_POST)) { + $groupgroups = new Application_Model_GroupGroups(); + $groupgroups->setParentID($_POST['superordinatedGroupID']); + $groupgroups->setGroupID($_POST['groupID']); + try { + $this->groupGroupsMapper->save($groupgroups); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_helper->redirector('', 'group'); + return; + } + } + + $this->view->linkForm = $linkForm; + } + + public function deleteAction() { + $this->_helper->viewRenderer->setNoRender(); + $groupID = $this->_request->getParam('groupID'); + if (isset($groupID)) { + $group = $this->groupMapper->find($groupID); + try { + $this->groupMapper->delete($group); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_helper->redirector('', 'group'); + return; + } + } + + public function grantpersonAction() { + $this->_helper->viewRenderer->setNoRender(); + if(isset($_POST['grouprequestID']) && isset($_POST['roleID'])) { + $groupRequest = $this->groupRequestMapper->find($_POST['grouprequestID']); + try { + $this->groupRequestMapper->delete($groupRequest); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $membership = new Application_Model_Membership(); + $membership->setGroupID($groupRequest->getGroupID()); + $membership->setPersonID($groupRequest->getPersonID()); + $membership->setRoleID($_POST['roleID']); + try { + $this->membershipMapper->save($membership); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_redirect("/dev/group/show/groupID/" . $groupRequest->getGroupID()); + } + } + + public function revokepersonAction() { + $this->_helper->viewRenderer->setNoRender(); + $membershipID = $this->_request->getParam('membershipID'); + if(isset($membershipID)) { + $membership = $this->membershipMapper->find($membershipID); + if(isset($membership)) { + try { + $this->membershipMapper->delete($membership); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_redirect("/dev/group/edit/groupID/" . $membership->getGroupID()); + } + + } + } } diff --git a/application/modules/dev/controllers/IndexController.php b/application/modules/dev/controllers/IndexController.php index 2b8873d..cbf4e77 100644 --- a/application/modules/dev/controllers/IndexController.php +++ b/application/modules/dev/controllers/IndexController.php @@ -1,28 +1,25 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_IndexController extends Zend_Controller_Action -{ - - public function init() - { - /* Initialize action controller here */ - } - - public function indexAction() - { - // action body - - } +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_IndexController extends Zend_Controller_Action { + + public function init() { + /* Initialize action controller here */ + } + + public function indexAction() { + // action body + + } } diff --git a/application/modules/dev/controllers/PersonController.php b/application/modules/dev/controllers/PersonController.php index 25c415a..3119ab9 100644 --- a/application/modules/dev/controllers/PersonController.php +++ b/application/modules/dev/controllers/PersonController.php @@ -1,176 +1,167 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_PersonController extends Zend_Controller_Action -{ - protected $person; - protected $personmapper; - protected $membershipMapper; - protected $memberships; - protected $groupMapper; - protected $groups; - protected $groupRequestMapper; - - public function init() { - if (Zend_Auth::getInstance()->hasIdentity()) { - $this->personmapper = new Application_Model_PersonMapper(); - $result = $this->personmapper->findBy(array('email' => Zend_Auth::getInstance()->getIdentity()),true); - $this->person = new Application_Model_Person($result[0]); - $this->person->setID($result[0]['personID']); - $this->groupMapper = new Application_Model_GroupMapper(); - $this->groupRequestMapper = new Application_Model_GroupRequestMapper(); - $this->membershipMapper = new Application_Model_MembershipMapper(); - $this->memberships = $this->membershipMapper->findBy("personID",$this->person->getID()); - if(isset($this->memberships)) { - foreach($this->memberships as $membership) { - $group = $this->groupMapper->find($membership['groupID']); - $this->groups[] = array ( - 'groupID' => $group->getID(), - 'title' => $group->getTitle(), - 'description' => $group->getDescription(), - 'membershipID' => $membership['membershipID'] - ); - } - } - } else { - $this->_helper->redirector('login', 'auth'); - return; - } - } - - public function indexAction() - { - $this->_helper-> viewRenderer-> setNoRender(); - $this->_helper->redirector('show', 'person'); - return; - } - - public function showAction() - { - $this->view->person = $this->person; - $this->view->groups = $this->groups; - } - - public function editAction() - { - $this->view->person = $this->person; - if (!isset($_POST["save"])){ - $editForm = new dev_Form_PersonEdit(); - } else { - $editForm = new dev_Form_PersonEdit($_POST); - if ($editForm->isValid($_POST)) { - if(isset($_POST['newpassword'])) { - $date = new DateTime(); - $this->person->setPassword($_POST['newpassword']); - $this->person->setPasswordSalt(MD5($date->getTimestamp())); - $this->person->setPassword(MD5($this->person->getPassword() . $this->person->getPasswordSalt())); - } - $this->person->setOptions($_POST); - try { - $this->personmapper->save($this->person); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - echo "Email Address already existing."; - return; - } - $this->_helper->redirector('show', 'person'); - return; - } - } - $this->view->editForm = $editForm; - } - - public function requestAction() - { - $this->view->person = $this->person; - $allgroups = $this->groupMapper->fetchAll(); - $groupRequests = $this->groupRequestMapper->findBy(array('personID' => $this->person->getID()),true); - $count = 0; - foreach($allgroups as $group) { - foreach($groupRequests as $groupRequest) { - if($groupRequest['groupID'] == $group->getID()) { - $groupsFound[$count] = true; - } else { - $groupsFound[$count] = false; - } - } - foreach($this->memberships as $membership) { - if($membership['groupID'] == $group->getID()) { - $groupsFound[$count] = true; - } else { - if($groupsFound[$count] != true) { - $groupsFound[$count] = false; - } - } - } - $count++; - } - if(count($groupsFound) > 0) { - foreach($groupsFound as $k => $v) { - if($v == true) { - unset($allgroups[$k]); - } - } - } - if (!isset($_POST["request"])){ - if(count($allgroups) <= 0) { - echo "No Groups to choose."; - } - $requestForm = new dev_Form_GroupRequest(array('grouplist' => $allgroups)); - } else { - $requestForm = new dev_Form_GroupRequest(array('grouplist' => $allgroups), $_POST); - if ($requestForm->isValid($_POST)) { - $groupRequestMapper = new Application_Model_GroupRequestMapper(); - $groupRequest = new Application_Model_GroupRequest(); - $groupRequest->setGroupID($_POST['groupID']); - $date = new DateTime(); - $groupRequest->setTime($date->getTimestamp()); - $groupRequest->setPersonID($this->person->getID()); - try { - $groupRequestMapper->save($groupRequest); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_helper->redirector('show', 'person'); - return; - } - } - $this->view->requestForm = $requestForm; - } - - public function leaveAction() - { - $this->_helper-> viewRenderer-> setNoRender(); - $this->view->person = $this->person; - $membershipID = $this->_request->getParam('membershipID'); - if(isset($membershipID)) { - $membership = $this->membershipMapper->find($membershipID); - try { - $this->membershipMapper->delete($membership); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_helper->redirector('show', 'person'); - return; - } - } +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_PersonController extends Zend_Controller_Action { + protected $person; + protected $personmapper; + protected $membershipMapper; + protected $memberships; + protected $groupMapper; + protected $groups; + protected $groupRequestMapper; + + public function init() { + if (Zend_Auth::getInstance()->hasIdentity()) { + $this->personmapper = new Application_Model_PersonMapper(); + $result = $this->personmapper->findBy(array('email' => Zend_Auth::getInstance()->getIdentity()), true); + $this->person = new Application_Model_Person($result[0]); + $this->person->setID($result[0]['personID']); + $this->groupMapper = new Application_Model_GroupMapper(); + $this->groupRequestMapper = new Application_Model_GroupRequestMapper(); + $this->membershipMapper = new Application_Model_MembershipMapper(); + $this->memberships = $this->membershipMapper->findBy("personID", $this->person->getID()); + if(isset($this->memberships)) { + foreach($this->memberships as $membership) { + $group = $this->groupMapper->find($membership['groupID']); + $this->groups[] = array ( + 'groupID' => $group->getID(), + 'title' => $group->getTitle(), + 'description' => $group->getDescription(), + 'membershipID' => $membership['membershipID'] + ); + } + } + } else { + $this->_helper->redirector('login', 'auth'); + return; + } + } + + public function indexAction() { + $this->_helper-> viewRenderer-> setNoRender(); + $this->_helper->redirector('show', 'person'); + return; + } + + public function showAction() { + $this->view->person = $this->person; + $this->view->groups = $this->groups; + } + + public function editAction() { + $this->view->person = $this->person; + if (!isset($_POST["save"])) { + $editForm = new dev_Form_PersonEdit(); + } else { + $editForm = new dev_Form_PersonEdit($_POST); + if ($editForm->isValid($_POST)) { + if(isset($_POST['newpassword'])) { + $date = new DateTime(); + $this->person->setPassword($_POST['newpassword']); + $this->person->setPasswordSalt(MD5($date->getTimestamp())); + $this->person->setPassword(MD5($this->person->getPassword() . $this->person->getPasswordSalt())); + } + $this->person->setOptions($_POST); + try { + $this->personmapper->save($this->person); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + echo "Email Address already existing."; + return; + } + $this->_helper->redirector('show', 'person'); + return; + } + } + $this->view->editForm = $editForm; + } + + public function requestAction() { + $this->view->person = $this->person; + $allgroups = $this->groupMapper->fetchAll(); + $groupRequests = $this->groupRequestMapper->findBy(array('personID' => $this->person->getID()), true); + $count = 0; + foreach($allgroups as $group) { + foreach($groupRequests as $groupRequest) { + if($groupRequest['groupID'] == $group->getID()) { + $groupsFound[$count] = true; + } else { + $groupsFound[$count] = false; + } + } + foreach($this->memberships as $membership) { + if($membership['groupID'] == $group->getID()) { + $groupsFound[$count] = true; + } else { + if($groupsFound[$count] != true) { + $groupsFound[$count] = false; + } + } + } + $count++; + } + if(count($groupsFound) > 0) { + foreach($groupsFound as $k => $v) { + if($v == true) { + unset($allgroups[$k]); + } + } + } + if (!isset($_POST["request"])) { + if(count($allgroups) <= 0) { + echo "No Groups to choose."; + } + $requestForm = new dev_Form_GroupRequest(array('grouplist' => $allgroups)); + } else { + $requestForm = new dev_Form_GroupRequest(array('grouplist' => $allgroups), $_POST); + if ($requestForm->isValid($_POST)) { + $groupRequestMapper = new Application_Model_GroupRequestMapper(); + $groupRequest = new Application_Model_GroupRequest(); + $groupRequest->setGroupID($_POST['groupID']); + $date = new DateTime(); + $groupRequest->setTime($date->getTimestamp()); + $groupRequest->setPersonID($this->person->getID()); + try { + $groupRequestMapper->save($groupRequest); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_helper->redirector('show', 'person'); + return; + } + } + $this->view->requestForm = $requestForm; + } + + public function leaveAction() { + $this->_helper-> viewRenderer-> setNoRender(); + $this->view->person = $this->person; + $membershipID = $this->_request->getParam('membershipID'); + if(isset($membershipID)) { + $membership = $this->membershipMapper->find($membershipID); + try { + $this->membershipMapper->delete($membership); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_helper->redirector('show', 'person'); + return; + } + } } diff --git a/application/modules/dev/controllers/PoolController.php b/application/modules/dev/controllers/PoolController.php index 6f80468..6e31161 100644 --- a/application/modules/dev/controllers/PoolController.php +++ b/application/modules/dev/controllers/PoolController.php @@ -1,175 +1,167 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_PoolController extends Zend_Controller_Action -{ - - public function init() - { - /* Initialize action controller here */ +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_PoolController extends Zend_Controller_Action { + + public function init() { + /* Initialize action controller here */ + } + + public function indexAction() { + $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(); } - - public function indexAction() - { - $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; - + $assignedclientmapper = new Application_Model_PoolEntriesMapper(); + $assignedclients = $assignedclientmapper->fetchAll(); + foreach($assignedclients as $c) { + $assignedclientsArray[] = $c->toArray(); } - - public function createpoolAction() - { - if (!isset($_POST["add"])){ - $addfilterform = new dev_Form_Pool(array('buttontext' => 'Create Pool')); - $this->view->addpool = $addfilterform; - }else { - $addpoolform = new dev_Form_Pool(array('buttontext' => 'Create Pool'),$_POST); - if ($addpoolform->isValid($_POST)) { - try{ - $pool = new Application_Model_Pool($_POST); - $poolmapper = new Application_Model_PoolMapper(); - $poolmapper->save($pool); - $this->_redirect('/dev/pool'); - return; - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - } - } - $this->view->addpool = $addfilterform; - } + $freeclients = $this->arrayDiff($clientsArray, $assignedclientsArray); + + $this->view->freeclients = $freeclients; + + } + + public function createpoolAction() { + if (!isset($_POST["add"])) { + $addfilterform = new dev_Form_Pool(array('buttontext' => 'Create Pool')); + $this->view->addpool = $addfilterform; + } else { + $addpoolform = new dev_Form_Pool(array('buttontext' => 'Create Pool'), $_POST); + if ($addpoolform->isValid($_POST)) { + try { + $pool = new Application_Model_Pool($_POST); + $poolmapper = new Application_Model_PoolMapper(); + $poolmapper->save($pool); + $this->_redirect('/dev/pool'); + return; + } catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + } + $this->view->addpool = $addfilterform; } - - public function deletepoolAction() - { - $poolID = $this->_request->getParam('poolID'); - // TODO: ACL implementieren ob er den pool löschen darf - if(is_numeric($poolID)){ - $deletepool = new Application_Model_Pool(); - $deletepool->setID($poolID); - $poolmapper = new Application_Model_PoolMapper(); - $poolmapper->delete($deletepool); - } - $this->_redirect('/dev/pool'); + } + + public function deletepoolAction() { + $poolID = $this->_request->getParam('poolID'); + // TODO: ACL implementieren ob er den pool löschen darf + if(is_numeric($poolID)) { + $deletepool = new Application_Model_Pool(); + $deletepool->setID($poolID); + $poolmapper = new Application_Model_PoolMapper(); + $poolmapper->delete($deletepool); } - - public function editpoolAction() - { - 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 dev_Form_Pool(array('buttontext' => 'Edit Pool')); - $editpool->populate($poolArray); - $this->view->editpoolform = $editpool; - - }else { - $editpoolform = new dev_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'); - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - } - } - $this->view->editpoolform = $editpoolform; - } + $this->_redirect('/dev/pool'); + } + + public function editpoolAction() { + 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 dev_Form_Pool(array('buttontext' => 'Edit Pool')); + $editpool->populate($poolArray); + $this->view->editpoolform = $editpool; + + } else { + $editpoolform = new dev_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'); + } catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + } + $this->view->editpoolform = $editpoolform; } + } + + public function linkclientAction() { + $clientID = $this->_request->getParam('clientID'); + $poolID = $this->_request->getParam('poolID'); + if(!isset($_POST['clientID']) && ($clientID == '')) { + $clientmapper = new Application_Model_ClientMapper(); + $clients = $clientmapper->fetchAll(); + foreach($clients as $c) { + $clientsArray[] = $c->toArray(); + } + $assignedclientmapper = new Application_Model_PoolEntriesMapper(); + $assignedclients = $assignedclientmapper->fetchAll(); + foreach($assignedclients as $c) { + $assignedclientsArray[] = $c->toArray(); + } + $freeclients = $this->arrayDiff($clientsArray, $assignedclientsArray); + + $poolclient = new dev_Form_PoolClient(array('buttontext' => 'Link Client', 'clients' => $freeclients)); + $this->view->poolclient = $poolclient; + } else { + $poolclient = new dev_Form_PoolClient(array('buttontext' => 'Link Client'), $_POST); + 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('/dev/pool'); + } catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + $this->view->poolclient = $poolclient; - public function linkclientAction() - { - $clientID = $this->_request->getParam('clientID'); - $poolID = $this->_request->getParam('poolID'); - if(!isset($_POST['clientID']) && ($clientID == '')){ - $clientmapper = new Application_Model_ClientMapper(); - $clients = $clientmapper->fetchAll(); - foreach($clients as $c){ - $clientsArray[] = $c->toArray(); - } - $assignedclientmapper = new Application_Model_PoolEntriesMapper(); - $assignedclients = $assignedclientmapper->fetchAll(); - foreach($assignedclients as $c){ - $assignedclientsArray[] = $c->toArray(); - } - $freeclients = $this->arrayDiff($clientsArray,$assignedclientsArray); - - $poolclient = new dev_Form_PoolClient(array('buttontext' => 'Link Client','clients'=> $freeclients)); - $this->view->poolclient = $poolclient; - }else { - $poolclient = new dev_Form_PoolClient(array('buttontext' => 'Link Client'),$_POST); - 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('/dev/pool'); - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - } - $this->view->poolclient = $poolclient; - - } } - 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; - } - - - public function unlinkclientAction() - { - $poolentriesID = $this->_request->getParam('poolentriesID'); - - // TODO: ACL implementieren ob er den filter löschen darf - if(is_numeric($poolentriesID)){ - $deletepoolentries = new Application_Model_PoolEntries(); - $deletepoolentries->setID($poolentriesID); - - $deletepoolentriesmapper = new Application_Model_PoolEntriesMapper(); - $deletepoolentriesmapper->delete($deletepoolentries); - echo "ok"; - } - $this->_redirect('/dev/pool'); + } + 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; + } + + + public function unlinkclientAction() { + $poolentriesID = $this->_request->getParam('poolentriesID'); + + // TODO: ACL implementieren ob er den filter löschen darf + if(is_numeric($poolentriesID)) { + $deletepoolentries = new Application_Model_PoolEntries(); + $deletepoolentries->setID($poolentriesID); + + $deletepoolentriesmapper = new Application_Model_PoolEntriesMapper(); + $deletepoolentriesmapper->delete($deletepoolentries); + echo "ok"; } + $this->_redirect('/dev/pool'); + } } diff --git a/application/modules/dev/controllers/PrebootController.php b/application/modules/dev/controllers/PrebootController.php index c3933c6..4936d2c 100644 --- a/application/modules/dev/controllers/PrebootController.php +++ b/application/modules/dev/controllers/PrebootController.php @@ -1,206 +1,195 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_PrebootController extends Zend_Controller_Action -{ - - public function init() - { - $db = Zend_Db_Table::getDefaultAdapter(); - } +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_PrebootController extends Zend_Controller_Action { + + public function init() { + $db = Zend_Db_Table::getDefaultAdapter(); + } - public function indexAction() - { - $prebootmapper = new Application_Model_PreBootMapper(); - $groupmapper = new Application_Model_GroupMapper(); - $membershipmapper = new Application_Model_MembershipMapper(); - $personmapper = new Application_Model_PersonMapper(); - - $this->view->prebootlist = $prebootmapper->fetchAll(); - $this->view->update = array(); - - foreach ($this->view->prebootlist as $preboot){ - $this->view->update[$preboot->getID()] = $this->checkupdateAction($preboot); - $preboot->setGroupID("[".$preboot->getGroupID()."] ".$groupmapper->find($preboot->getGroupID())->getTitle()); - $preboot->setMembershipID("[".$preboot->getMembershipID()."] ".$personmapper->find($membershipmapper->find($preboot->getMembershipID())->getPersonID())->getFirstname()); - } + public function indexAction() { + $prebootmapper = new Application_Model_PreBootMapper(); + $groupmapper = new Application_Model_GroupMapper(); + $membershipmapper = new Application_Model_MembershipMapper(); + $personmapper = new Application_Model_PersonMapper(); + + $this->view->prebootlist = $prebootmapper->fetchAll(); + $this->view->update = array(); + + foreach ($this->view->prebootlist as $preboot) { + $this->view->update[$preboot->getID()] = $this->checkupdateAction($preboot); + $preboot->setGroupID("[".$preboot->getGroupID()."] ".$groupmapper->find($preboot->getGroupID())->getTitle()); + $preboot->setMembershipID("[".$preboot->getMembershipID()."] ".$personmapper->find($membershipmapper->find($preboot->getMembershipID())->getPersonID())->getFirstname()); } - - public function createprebootAction() - { - $groupmapper = new Application_Model_GroupMapper(); - - if (!isset($_POST["createpreboot"])){ - $createprebootForm = new dev_Form_PrebootCreate(array('grouplist' => $groupmapper->fetchAll())); - } else { - - $createprebootForm = new dev_Form_PrebootCreate(array('grouplist' => $groupmapper->fetchAll()),$_POST); - - if ($createprebootForm->isValid($_POST)) { - - $preboot = new Application_Model_PreBoot($_POST); - $preboot->setMembershipID('1'); - $prebootmapper = new Application_Model_PreBootMapper(); - - try { - - exec("wget --spider ".$preboot->getPath_preboot()." 2>&1 | grep 'Remote file exists.'", $exists_preboot); - - if(!array_pop($exists_preboot)){ - $this->view->createprebootForm = $createprebootForm; - return; - } - - $prebootID = $prebootmapper->save($preboot); - - $path_preboot = "../resources/bootmedium/$prebootID/"; - mkdir($path_preboot ,0777, true); - - exec("wget -O '".$path_preboot."preboot.zip' ".$preboot->getPath_preboot()); - - - }catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - - } - $this->_redirect('/dev/preboot'); - } - } - + } + + public function createprebootAction() { + $groupmapper = new Application_Model_GroupMapper(); + + if (!isset($_POST["createpreboot"])) { + $createprebootForm = new dev_Form_PrebootCreate(array('grouplist' => $groupmapper->fetchAll())); + } else { + + $createprebootForm = new dev_Form_PrebootCreate(array('grouplist' => $groupmapper->fetchAll()), $_POST); + + if ($createprebootForm->isValid($_POST)) { + + $preboot = new Application_Model_PreBoot($_POST); + $preboot->setMembershipID('1'); + $prebootmapper = new Application_Model_PreBootMapper(); + + try { + + exec("wget --spider ".$preboot->getPath_preboot()." 2>&1 | grep 'Remote file exists.'", $exists_preboot); + + if(!array_pop($exists_preboot)) { $this->view->createprebootForm = $createprebootForm; + return; + } + + $prebootID = $prebootmapper->save($preboot); + + $path_preboot = "../resources/bootmedium/$prebootID/"; + mkdir($path_preboot , 0777, true); + + exec("wget -O '".$path_preboot."preboot.zip' ".$preboot->getPath_preboot()); + + + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + + } + $this->_redirect('/dev/preboot'); + } } - - public function checkupdateAction($preboot) - { - $prebootID = $preboot->getID(); - exec("wget --server-response --spider ".escapeshellcmd($preboot->getPath_preboot())." 2>&1 | grep 'Last-Modified:'", $prebootdate); - - //print_a($prebootdate); - - $prebootdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($prebootdate)))); - - if(is_file("../resources/bootmedium/$prebootID/preboot.zip")) - $prebootolddate = filemtime("../resources/bootmedium/".$prebootID."/preboot.zip"); - else - $prebootolddate = false; - - //print_a($prebootname,$prebootdate,$prebootolddate); - - - if($prebootdate > $prebootolddate) - return true; - else - return false; - - } - - public function updateprebootAction() - { - - $prebootID = $this->_request->getParam('prebootID'); - - $prebootmapper = new Application_Model_PreBootMapper(); - $preboot = new Application_Model_PreBoot(); - $prebootmapper->find($prebootID,$preboot); - - $path_preboot = "../resources/bootmedium/$prebootID/"; - - exec("wget -O '".$path_preboot."preboot.zip' ".$preboot->getPath_preboot()); - - $filelist = array(); - $filelist = scandir($path_preboot); - - $bootisoMapper = new Application_Model_BootIsoMapper(); - - foreach($filelist as $file){ - if($file == "." || $file == ".." || $file == "preboot.zip"){ - //do nothing - } - else{ - $bootisoID = str_replace('.zip', '', $file); - $serialnumber = $bootisoMapper->find($bootisoID)->getSerialnumber(); - - copy("../resources/bootmedium/$prebootID/preboot.zip", "../resources/bootmedium/$prebootID/$bootisoID".".zip"); - $zip = new ZipArchive(); - $res = $zip->open("../resources/bootmedium/$prebootID/$bootisoID".".zip"); - if($res === true){ - $rootdir = $zip->getNameIndex(0); - $zip->addFromString($rootdir."build/rootfs/serial", $serialnumber); - $zip->close(); - } - } - } - - $this->_redirect('/dev/preboot'); + + $this->view->createprebootForm = $createprebootForm; + } + + public function checkupdateAction($preboot) { + $prebootID = $preboot->getID(); + exec("wget --server-response --spider ".escapeshellcmd($preboot->getPath_preboot())." 2>&1 | grep 'Last-Modified:'", $prebootdate); + + //print_a($prebootdate); + + $prebootdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($prebootdate)))); + + if(is_file("../resources/bootmedium/$prebootID/preboot.zip")) + { $prebootolddate = filemtime("../resources/bootmedium/".$prebootID."/preboot.zip"); } + else + { $prebootolddate = false; } + + //print_a($prebootname,$prebootdate,$prebootolddate); + + + if($prebootdate > $prebootolddate) + { return true; } + else + { return false; } + + } + + public function updateprebootAction() { + + $prebootID = $this->_request->getParam('prebootID'); + + $prebootmapper = new Application_Model_PreBootMapper(); + $preboot = new Application_Model_PreBoot(); + $prebootmapper->find($prebootID, $preboot); + + $path_preboot = "../resources/bootmedium/$prebootID/"; + + exec("wget -O '".$path_preboot."preboot.zip' ".$preboot->getPath_preboot()); + + $filelist = array(); + $filelist = scandir($path_preboot); + + $bootisoMapper = new Application_Model_BootIsoMapper(); + + foreach($filelist as $file) { + if($file == "." || $file == ".." || $file == "preboot.zip") { + //do nothing + } else { + $bootisoID = str_replace('.zip', '', $file); + $serialnumber = $bootisoMapper->find($bootisoID)->getSerialnumber(); + + copy("../resources/bootmedium/$prebootID/preboot.zip", "../resources/bootmedium/$prebootID/$bootisoID".".zip"); + $zip = new ZipArchive(); + $res = $zip->open("../resources/bootmedium/$prebootID/$bootisoID".".zip"); + if($res == = true) { + $rootdir = $zip->getNameIndex(0); + $zip->addFromString($rootdir."build/rootfs/serial", $serialnumber); + $zip->close(); + } + } } - public function editprebootAction() - { - $prebootID = $this->_request->getParam('prebootID'); - $groupmapper = new Application_Model_GroupMapper(); - - if (!isset($_POST["editpreboot"])){ - $prebootID = $this->_request->getParam('prebootID'); - if (!isset($prebootID) || !is_numeric($prebootID)){ - $this->_redirect('/dev/preboot'); - } else { - $preboot = new Application_Model_PreBoot(); - $prebootmapper = new Application_Model_PreBootMapper(); - $prebootmapper->find($prebootID, $preboot); - - $editprebootForm = new dev_Form_PrebootEdit(array('grouplist' => $groupmapper->fetchAll())); - $editprebootForm->populate($preboot->toArray()); - } - }else{ - $editprebootForm = new dev_Form_PrebootEdit(array('grouplist' => $groupmapper->fetchAll()),$_POST); - - if ($editprebootForm->isValid($_POST)) { - - $preboot = new Application_Model_PreBoot($_POST); - $preboot->setMembershipID('1'); - $prebootmapper = new Application_Model_PreBootMapper(); - $preboot->setID($prebootID); - - try { - $prebootmapper->save($preboot); - }catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - } - - $this->_redirect('/dev/preboot'); - } - - } - - $this->view->editprebootForm = $editprebootForm; + $this->_redirect('/dev/preboot'); + } + + public function editprebootAction() { + $prebootID = $this->_request->getParam('prebootID'); + $groupmapper = new Application_Model_GroupMapper(); + + if (!isset($_POST["editpreboot"])) { + $prebootID = $this->_request->getParam('prebootID'); + if (!isset($prebootID) || !is_numeric($prebootID)) { + $this->_redirect('/dev/preboot'); + } else { + $preboot = new Application_Model_PreBoot(); + $prebootmapper = new Application_Model_PreBootMapper(); + $prebootmapper->find($prebootID, $preboot); + + $editprebootForm = new dev_Form_PrebootEdit(array('grouplist' => $groupmapper->fetchAll())); + $editprebootForm->populate($preboot->toArray()); + } + } else { + $editprebootForm = new dev_Form_PrebootEdit(array('grouplist' => $groupmapper->fetchAll()), $_POST); + + if ($editprebootForm->isValid($_POST)) { + + $preboot = new Application_Model_PreBoot($_POST); + $preboot->setMembershipID('1'); + $prebootmapper = new Application_Model_PreBootMapper(); + $preboot->setID($prebootID); + + try { + $prebootmapper->save($preboot); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + } + + $this->_redirect('/dev/preboot'); + } + } - public function deleteprebootAction() - { - $prebootID = $this->_request->getParam('prebootID'); - if (!isset($prebootID)){ - $this->_redirect('/dev/preboot'); - } else { - $preboot = new Application_Model_PreBoot(); - $preboot->setID($prebootID); - $prebootmapper = new Application_Model_PreBootMapper(); - $prebootmapper->delete($preboot); - } - $this->_redirect('/dev/preboot'); + $this->view->editprebootForm = $editprebootForm; + } + + public function deleteprebootAction() { + $prebootID = $this->_request->getParam('prebootID'); + if (!isset($prebootID)) { + $this->_redirect('/dev/preboot'); + } else { + $preboot = new Application_Model_PreBoot(); + $preboot->setID($prebootID); + $prebootmapper = new Application_Model_PreBootMapper(); + $prebootmapper->delete($preboot); } + $this->_redirect('/dev/preboot'); + } } diff --git a/application/modules/dev/controllers/ResourceController.php b/application/modules/dev/controllers/ResourceController.php index 6889f9b..0c5fa85 100644 --- a/application/modules/dev/controllers/ResourceController.php +++ b/application/modules/dev/controllers/ResourceController.php @@ -1,172 +1,163 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_ResourceController extends Zend_Controller_Action -{ - - private $thisSession; - - public function init() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $alphasessionID = $this->_request->getParam('alpha'); - $session = new Application_Model_Session(); - $sm = new Application_Model_SessionMapper(); - $result = $sm->findBy(array('alphasessionID' => $alphasessionID), true); - # print_a($result); - $this->thisSession = $session->setOptions($result[0]); - $this->thisSession->setID($result[0]['sessionID']); - } - - public function indexAction() - { - - - } - - public function getinitramfsAction() - { - - $bootosID = $this->thisSession->getBootosID(); - - if(is_dir("../resources/bootos/$bootosID/initramfs/") && is_numeric($bootosID)){ - - header('Content-Type: application/x-gzip'); - $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; - header('Content-Disposition: ' . $content_disp . '; filename="initramfs"'); - header('Pragma: no-cache'); - header('Expires: 0'); - - // create file. - chdir("../resources/bootos/$bootosID/initramfs/"); - $initname = array_pop(scandir("./")); - - passthru( "cat ".$initname); - } - } - - public function getconfigAction() - { - $bootmenuentryID = $this->thisSession->getBootmenuentryID(); - - $bootmenuentry = new Application_Model_BootMenuEntries(); - $bmm = new Application_Model_BootMenuEntriesMapper(); - $bmm->find($bootmenuentryID,$bootmenuentry); - # print_a($bootmenuentry); - - $configID = $bootmenuentry->getConfigID(); - - if(is_dir("../resources/config/$configID/config/") && is_numeric($configID)){ - - header('Content-Type: application/x-gzip'); - $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; - header('Content-Disposition: ' . $content_disp . '; filename="config.tgz"'); - header('Pragma: no-cache'); - header('Expires: 0'); - - // create the gzipped tarfile. - chdir("../resources/config/$configID/config/"); - passthru( "tar cz ./"); - } - } - - public function getkernelAction() - { - $bootosID = $this->thisSession->getBootosID(); - - if(is_dir("../resources/bootos/$bootosID/kernel/") && is_numeric($bootosID)){ - - header('Content-Type: application/x-gzip'); - $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; - header('Content-Disposition: ' . $content_disp . '; filename="kernel"'); - header('Pragma: no-cache'); - header('Expires: 0'); - - // create the gzipped tarfile. - chdir("../resources/bootos/$bootosID/kernel/"); - $kernelname = array_pop(scandir("./")); - - passthru( "cat ". $kernelname); - } - } - - public function getkclAction() - { - $bmeID = $this->thisSession->getBootmenuentryID(); - - if(is_numeric($bmeID)){ - - $bmemapper = new Application_Model_BootMenuEntriesMapper(); - $bme = new Application_Model_BootMenuEntries(); - $bmemapper->find($bmeID,$bme); - - header('Content-Type: text/html'); - $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; - header('Content-Disposition: ' . $content_disp . '; filename="kcl.txt"'); - header('Pragma: no-cache'); - header('Expires: 0'); - - if($bme->getKcl() != null) - $result = $bme->getKcl() . " " . $bme->getKclappend(); - else - $result = $bme->getKclappend(); - - echo $result; - - - } - - } - - public function getbootmenuentryAction() - { - // obsolete function (now only for debugging) - // after selecting the BootOS it will be saved in session - // so getkclAction, getkernelAction, getconfigAction and getinitramfsAction - // can be called with session-identifier - $bootmenuentryID = $this->_request->getParam('bootmenuentryID'); - $bootosID = $this->_request->getParam('bootosID'); - - $this->thisSession->setBootosID($bootosID)->setBootmenuentryID($bootmenuentryID); - $sessionMapper = new Application_Model_SessionMapper(); - $sessionMapper->save($this->thisSession); - - if($this->thisSession->getBootmenuentryID() != null){ - header('Content-Type: application/json'); - $return_val = - array( - 'info' => 'This function is for debugging purpose only', - 'kernel' => $this->generateURL('getkernel', 'alpha', $_SESSION['alphasessionID'], "kernel"), - 'initramfs' => $this->generateURL('getinitramfs', 'alpha', $_SESSION['alphasessionID'], "initramfs"), - 'kcl' => $this->generateURL('getkcl', 'alpha', $_SESSION['alphasessionID'], "kcl.txt"), - 'config' => $_SESSION['alphasessionID'] - ); - echo json_encode($return_val); - } - else{ - echo json_encode( - array( 'info' => 'This function is for debugging purpose only', - 'error'=> 'your session is out of date') - ); - } - } - - private function generateURL($action, $varname, $varvalue, $filename){ - $path = '/dev/resource/'. $action .'/' . $varname .'/' . $varvalue .'/file/' . $filename ; - $path = "http://" . $_SERVER['SERVER_NAME'] . $path; - return $path; - } +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_ResourceController extends Zend_Controller_Action { + + private $thisSession; + + public function init() { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $alphasessionID = $this->_request->getParam('alpha'); + $session = new Application_Model_Session(); + $sm = new Application_Model_SessionMapper(); + $result = $sm->findBy(array('alphasessionID' => $alphasessionID), true); +# print_a($result); + $this->thisSession = $session->setOptions($result[0]); + $this->thisSession->setID($result[0]['sessionID']); + } + + public function indexAction() { + + + } + + public function getinitramfsAction() { + + $bootosID = $this->thisSession->getBootosID(); + + if(is_dir("../resources/bootos/$bootosID/initramfs/") && is_numeric($bootosID)) { + + header('Content-Type: application/x-gzip'); + $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; + header('Content-Disposition: ' . $content_disp . '; filename="initramfs"'); + header('Pragma: no-cache'); + header('Expires: 0'); + + // create file. + chdir("../resources/bootos/$bootosID/initramfs/"); + $initname = array_pop(scandir("./")); + + passthru( "cat ".$initname); + } + } + + public function getconfigAction() { + $bootmenuentryID = $this->thisSession->getBootmenuentryID(); + + $bootmenuentry = new Application_Model_BootMenuEntries(); + $bmm = new Application_Model_BootMenuEntriesMapper(); + $bmm->find($bootmenuentryID, $bootmenuentry); +# print_a($bootmenuentry); + + $configID = $bootmenuentry->getConfigID(); + + if(is_dir("../resources/config/$configID/config/") && is_numeric($configID)) { + + header('Content-Type: application/x-gzip'); + $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; + header('Content-Disposition: ' . $content_disp . '; filename="config.tgz"'); + header('Pragma: no-cache'); + header('Expires: 0'); + + // create the gzipped tarfile. + chdir("../resources/config/$configID/config/"); + passthru( "tar cz ./"); + } + } + + public function getkernelAction() { + $bootosID = $this->thisSession->getBootosID(); + + if(is_dir("../resources/bootos/$bootosID/kernel/") && is_numeric($bootosID)) { + + header('Content-Type: application/x-gzip'); + $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; + header('Content-Disposition: ' . $content_disp . '; filename="kernel"'); + header('Pragma: no-cache'); + header('Expires: 0'); + + // create the gzipped tarfile. + chdir("../resources/bootos/$bootosID/kernel/"); + $kernelname = array_pop(scandir("./")); + + passthru( "cat ". $kernelname); + } + } + + public function getkclAction() { + $bmeID = $this->thisSession->getBootmenuentryID(); + + if(is_numeric($bmeID)) { + + $bmemapper = new Application_Model_BootMenuEntriesMapper(); + $bme = new Application_Model_BootMenuEntries(); + $bmemapper->find($bmeID, $bme); + + header('Content-Type: text/html'); + $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; + header('Content-Disposition: ' . $content_disp . '; filename="kcl.txt"'); + header('Pragma: no-cache'); + header('Expires: 0'); + + if($bme->getKcl() != null) + { $result = $bme->getKcl() . " " . $bme->getKclappend(); } + else + { $result = $bme->getKclappend(); } + + echo $result; + + + } + + } + + public function getbootmenuentryAction() { + // obsolete function (now only for debugging) + // after selecting the BootOS it will be saved in session + // so getkclAction, getkernelAction, getconfigAction and getinitramfsAction + // can be called with session-identifier + $bootmenuentryID = $this->_request->getParam('bootmenuentryID'); + $bootosID = $this->_request->getParam('bootosID'); + + $this->thisSession->setBootosID($bootosID)->setBootmenuentryID($bootmenuentryID); + $sessionMapper = new Application_Model_SessionMapper(); + $sessionMapper->save($this->thisSession); + + if($this->thisSession->getBootmenuentryID() != null) { + header('Content-Type: application/json'); + $return_val = + array( + 'info' => 'This function is for debugging purpose only', + 'kernel' => $this->generateURL('getkernel', 'alpha', $_SESSION['alphasessionID'], "kernel"), + 'initramfs' => $this->generateURL('getinitramfs', 'alpha', $_SESSION['alphasessionID'], "initramfs"), + 'kcl' => $this->generateURL('getkcl', 'alpha', $_SESSION['alphasessionID'], "kcl.txt"), + 'config' => $_SESSION['alphasessionID'] + ); + echo json_encode($return_val); + } else { + echo json_encode( + array( 'info' => 'This function is for debugging purpose only', + 'error' => 'your session is out of date') + ); + } + } + + private function generateURL($action, $varname, $varvalue, $filename) { + $path = '/dev/resource/'. $action .'/' . $varname .'/' . $varvalue .'/file/' . $filename ; + $path = "http://" . $_SERVER['SERVER_NAME'] . $path; + return $path; + } } diff --git a/application/modules/dev/controllers/RoleController.php b/application/modules/dev/controllers/RoleController.php index ab5870b..468e2ae 100644 --- a/application/modules/dev/controllers/RoleController.php +++ b/application/modules/dev/controllers/RoleController.php @@ -1,279 +1,263 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_RoleController extends Zend_Controller_Action -{ - protected $roleMapper; - protected $rightMapper; - protected $rightRolesMapper; - - public function init() - { - if (Zend_Auth::getInstance()->hasIdentity()) { - $this->roleMapper = new Application_Model_RoleMapper(); - $this->rightMapper = new Application_Model_RightMapper(); - $this->rightRolesMapper = new Application_Model_RightRolesMapper(); - } else { - $this->_helper->redirector('login', 'auth'); - } - } - - public function indexAction() - { - $roleNamespace = Zend_Session::namespaceGet('role'); - if(isset($roleNamespace['groupID'])) { - $roleList = $this->roleMapper->findBy(array('groupID' => $roleNamespace['groupID']),true); - $this->view->groupID = $roleNamespace['groupID']; - $this->view->roleList = $roleList; - } else { - $this->_helper->redirector('groupselect', 'role'); - return; - } - } - - public function addAction() - { - $roleNamespace = Zend_Session::namespaceGet('role'); - if(isset($roleNamespace['groupID'])) { - if (!isset($_POST["add"])){ - $addForm = new dev_Form_RoleAdd(array('rightlist' => $rightList)); - } else { - $addForm = new dev_Form_RoleAdd(array('rightlist' => $rightList),$_POST); - if ($addForm->isValid($_POST)) { - - $_POST['groupID'] = $roleNamespace['groupID']; - $role = new Application_Model_Role($_POST); - try { - $this->roleMapper->save($role); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_helper->redirector('', 'role'); - return; - } - } - - $this->view->addForm = $addForm; - } else { - $this->_helper->redirector('groupselect', 'role'); - return; - } - } - - public function editAction() - { - $roleID = $this->_request->getParam('roleID'); - if(!isset($roleID)) { - $addForm = new dev_Form_RoleAdd(); - $this->view->addForm = $addForm; - return; - } - if (!isset($_POST["save"])){ - $role = $this->roleMapper->find($roleID); - $_POST['title'] = $role->getTitle(); - $_POST['description'] = $role->getDescription(); - $_POST['groupID'] = $role->getGroupID(); - $_POST['inheritance'] = $role->getInheritance(); - $editForm = new dev_Form_RoleEdit(); - } else { - $editForm = new dev_Form_RoleEdit($_POST); - if ($editForm->isValid($_POST)) { - $role = new Application_Model_Role($_POST); - $role->setID($this->_request->getParam('roleID')); - try { - $this->roleMapper->save($role); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_helper->redirector('', 'role'); - return; - } - } - $this->view->editForm = $editForm; - } - - public function showAction() - { - $roleID = $this->_request->getParam('roleID'); - if($roleID) { - $rightroles = $this->rightRolesMapper->findBy(array('roleID' => $roleID),true); - if(count($rightroles) > 0) { - foreach($rightroles as $rightrole) { - $right = $this->rightMapper->find($rightrole['rightID']); - $rightsList[] = $right; - } - if(is_array($rightsList)) { - $this->view->rightsList = $rightsList; - } - } - $this->view->role = $this->roleMapper->find($roleID); - $this->view->roleID = $roleID; - } else { - $this->_helper->redirector('', 'role'); - return; - } - } - - public function deleteAction() - { - $this->_helper->viewRenderer->setNoRender(); - $roleID = $this->_request->getParam('roleID'); - if (isset($roleID)){ - $role = $this->roleMapper->find($roleID); - try { - $this->roleMapper->delete($role); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_helper->redirector('', 'role'); - return; - } else { - $this->_helper->redirector('', 'role'); - return; - } - } - - public function linkrightAction() - { - $roleID = $this->_request->getParam('roleID'); - if(isset($roleID)) { - $rightroles = $this->rightRolesMapper->findBy(array('roleID' => $roleID),true); - $rights = $this->rightMapper->fetchAll(); - if(count($rightroles) > 0) { - if(count($rights) > 0) { - foreach($rights as $right) { - foreach($rightroles as $rightrole) { - if($right->getID() == $rightrole['rightID']) { - $found = true; - break; - } - } - if(!$found) { - $rightlist[] = $right; - } - $found = false; - } - } - } else { - $rightlist = $rights; - } - if(count($rightlist) > 0) { - if (!isset($_POST["link"])){ - $linkForm = new dev_Form_LinkRight(array('rightlist' => $rightlist, 'roleID' => $roleID)); - } else { - $linkForm = new dev_Form_LinkRight(array('rightlist' => $rightlist),$_POST); - if ($linkForm->isValid($_POST)) { - $rightroles = new Application_Model_RightRoles(); - $rightroles->setRightID($_POST['rightID']); - $rightroles->setRoleID($roleID); - try { - $this->rightRolesMapper->save($rightroles); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_redirect('/dev/role/show/roleID/' . $roleID); - return; - } - } - $this->view->linkForm = $linkForm; - } else { - $this->_redirect('/dev/role/show/roleID/' . $roleID); - return; - } - } else { - $this->_helper->redirector('', 'role'); - return; - } - } - - public function unlinkrightAction() - { - $this->_helper-> viewRenderer-> setNoRender(); - $rightRolesID = $this->_request->getParam('rightrolesID'); - if(isset($rightRolesID)) { - $rightRolesID = explode('-',$rightRolesID); - $roleID = $rightRolesID[0]; - $rightID = $rightRolesID[1]; - if (isset($roleID) && isset($rightID)){ - $rightroles = new Application_Model_RightRoles(); - $rightroles->setRoleID($roleID); - $rightroles->setRightID($rightID); - try { - $this->rightRolesMapper->delete($rightroles); - } catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - $this->_redirect('/dev/role/show/roleID/' . $roleID); - return; - } - } else { - $this->_helper->redirector('', 'role'); - return; - } - } - - public function groupselectAction() - { - $roleNamespace = Zend_Session::namespaceGet('role'); - if(isset($roleNamespace['groupID'])) { - $this->_helper->redirector('', 'role'); - } else { - if(isset($_POST['selectgroup'])) { - $roleSession = new Zend_Session_Namespace('role'); - $roleSession->groupID = $_POST['groupID']; - $this->_helper->redirector('', 'role'); - return; - } else { - $personMapper = new Application_Model_PersonMapper(); - $result = $personMapper->findBy(array('email' => Zend_Auth::getInstance()->getIdentity()),true); - $person = new Application_Model_Person($result[0]); - $person->setID($result[0]['personID']); - $membershipMapper = new Application_Model_MembershipMapper(); - $memberships = $membershipMapper->findBy(array("personID" => $person->getID(), true)); - $groupMapper = new Application_Model_GroupMapper(); - if(isset($memberships)) { - foreach($memberships as $membership) { - $group = $groupMapper->find($membership['groupID']); - $groupList[] = $group; - } - } - $groupSelectForm = new dev_Form_GroupSelect(array('grouplist' => $groupList)); - $this->view->groupSelectForm = $groupSelectForm; - } - } - } - - public function changegroupAction() - { - $this->_helper-> viewRenderer-> setNoRender(); - Zend_Session::namespaceUnset('role'); - $this->_helper->redirector('groupselect', 'role'); - return; - } +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_RoleController extends Zend_Controller_Action { + protected $roleMapper; + protected $rightMapper; + protected $rightRolesMapper; + + public function init() { + if (Zend_Auth::getInstance()->hasIdentity()) { + $this->roleMapper = new Application_Model_RoleMapper(); + $this->rightMapper = new Application_Model_RightMapper(); + $this->rightRolesMapper = new Application_Model_RightRolesMapper(); + } else { + $this->_helper->redirector('login', 'auth'); + } + } + + public function indexAction() { + $roleNamespace = Zend_Session::namespaceGet('role'); + if(isset($roleNamespace['groupID'])) { + $roleList = $this->roleMapper->findBy(array('groupID' => $roleNamespace['groupID']), true); + $this->view->groupID = $roleNamespace['groupID']; + $this->view->roleList = $roleList; + } else { + $this->_helper->redirector('groupselect', 'role'); + return; + } + } + + public function addAction() { + $roleNamespace = Zend_Session::namespaceGet('role'); + if(isset($roleNamespace['groupID'])) { + if (!isset($_POST["add"])) { + $addForm = new dev_Form_RoleAdd(array('rightlist' => $rightList)); + } else { + $addForm = new dev_Form_RoleAdd(array('rightlist' => $rightList), $_POST); + if ($addForm->isValid($_POST)) { + + $_POST['groupID'] = $roleNamespace['groupID']; + $role = new Application_Model_Role($_POST); + try { + $this->roleMapper->save($role); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_helper->redirector('', 'role'); + return; + } + } + + $this->view->addForm = $addForm; + } else { + $this->_helper->redirector('groupselect', 'role'); + return; + } + } + + public function editAction() { + $roleID = $this->_request->getParam('roleID'); + if(!isset($roleID)) { + $addForm = new dev_Form_RoleAdd(); + $this->view->addForm = $addForm; + return; + } + if (!isset($_POST["save"])) { + $role = $this->roleMapper->find($roleID); + $_POST['title'] = $role->getTitle(); + $_POST['description'] = $role->getDescription(); + $_POST['groupID'] = $role->getGroupID(); + $_POST['inheritance'] = $role->getInheritance(); + $editForm = new dev_Form_RoleEdit(); + } else { + $editForm = new dev_Form_RoleEdit($_POST); + if ($editForm->isValid($_POST)) { + $role = new Application_Model_Role($_POST); + $role->setID($this->_request->getParam('roleID')); + try { + $this->roleMapper->save($role); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_helper->redirector('', 'role'); + return; + } + } + $this->view->editForm = $editForm; + } + + public function showAction() { + $roleID = $this->_request->getParam('roleID'); + if($roleID) { + $rightroles = $this->rightRolesMapper->findBy(array('roleID' => $roleID), true); + if(count($rightroles) > 0) { + foreach($rightroles as $rightrole) { + $right = $this->rightMapper->find($rightrole['rightID']); + $rightsList[] = $right; + } + if(is_array($rightsList)) { + $this->view->rightsList = $rightsList; + } + } + $this->view->role = $this->roleMapper->find($roleID); + $this->view->roleID = $roleID; + } else { + $this->_helper->redirector('', 'role'); + return; + } + } + + public function deleteAction() { + $this->_helper->viewRenderer->setNoRender(); + $roleID = $this->_request->getParam('roleID'); + if (isset($roleID)) { + $role = $this->roleMapper->find($roleID); + try { + $this->roleMapper->delete($role); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_helper->redirector('', 'role'); + return; + } else { + $this->_helper->redirector('', 'role'); + return; + } + } + + public function linkrightAction() { + $roleID = $this->_request->getParam('roleID'); + if(isset($roleID)) { + $rightroles = $this->rightRolesMapper->findBy(array('roleID' => $roleID), true); + $rights = $this->rightMapper->fetchAll(); + if(count($rightroles) > 0) { + if(count($rights) > 0) { + foreach($rights as $right) { + foreach($rightroles as $rightrole) { + if($right->getID() == $rightrole['rightID']) { + $found = true; + break; + } + } + if(!$found) { + $rightlist[] = $right; + } + $found = false; + } + } + } else { + $rightlist = $rights; + } + if(count($rightlist) > 0) { + if (!isset($_POST["link"])) { + $linkForm = new dev_Form_LinkRight(array('rightlist' => $rightlist, 'roleID' => $roleID)); + } else { + $linkForm = new dev_Form_LinkRight(array('rightlist' => $rightlist), $_POST); + if ($linkForm->isValid($_POST)) { + $rightroles = new Application_Model_RightRoles(); + $rightroles->setRightID($_POST['rightID']); + $rightroles->setRoleID($roleID); + try { + $this->rightRolesMapper->save($rightroles); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_redirect('/dev/role/show/roleID/' . $roleID); + return; + } + } + $this->view->linkForm = $linkForm; + } else { + $this->_redirect('/dev/role/show/roleID/' . $roleID); + return; + } + } else { + $this->_helper->redirector('', 'role'); + return; + } + } + + public function unlinkrightAction() { + $this->_helper-> viewRenderer-> setNoRender(); + $rightRolesID = $this->_request->getParam('rightrolesID'); + if(isset($rightRolesID)) { + $rightRolesID = explode('-', $rightRolesID); + $roleID = $rightRolesID[0]; + $rightID = $rightRolesID[1]; + if (isset($roleID) && isset($rightID)) { + $rightroles = new Application_Model_RightRoles(); + $rightroles->setRoleID($roleID); + $rightroles->setRightID($rightID); + try { + $this->rightRolesMapper->delete($rightroles); + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_redirect('/dev/role/show/roleID/' . $roleID); + return; + } + } else { + $this->_helper->redirector('', 'role'); + return; + } + } + + public function groupselectAction() { + $roleNamespace = Zend_Session::namespaceGet('role'); + if(isset($roleNamespace['groupID'])) { + $this->_helper->redirector('', 'role'); + } else { + if(isset($_POST['selectgroup'])) { + $roleSession = new Zend_Session_Namespace('role'); + $roleSession->groupID = $_POST['groupID']; + $this->_helper->redirector('', 'role'); + return; + } else { + $personMapper = new Application_Model_PersonMapper(); + $result = $personMapper->findBy(array('email' => Zend_Auth::getInstance()->getIdentity()), true); + $person = new Application_Model_Person($result[0]); + $person->setID($result[0]['personID']); + $membershipMapper = new Application_Model_MembershipMapper(); + $memberships = $membershipMapper->findBy(array("personID" => $person->getID(), true)); + $groupMapper = new Application_Model_GroupMapper(); + if(isset($memberships)) { + foreach($memberships as $membership) { + $group = $groupMapper->find($membership['groupID']); + $groupList[] = $group; + } + } + $groupSelectForm = new dev_Form_GroupSelect(array('grouplist' => $groupList)); + $this->view->groupSelectForm = $groupSelectForm; + } + } + } + + public function changegroupAction() { + $this->_helper-> viewRenderer-> setNoRender(); + Zend_Session::namespaceUnset('role'); + $this->_helper->redirector('groupselect', 'role'); + return; + } } diff --git a/application/modules/dev/controllers/SessionController.php b/application/modules/dev/controllers/SessionController.php index 11da1be..58b4316 100644 --- a/application/modules/dev/controllers/SessionController.php +++ b/application/modules/dev/controllers/SessionController.php @@ -1,186 +1,177 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_SessionController extends Zend_Controller_Action -{ - - public function init() - { - /* Initialize action controller here */ +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_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(); +#print_a($_SESSION); + } + private function getUniqueCode($length = "") { + $code = md5(uniqid(rand(), true)); + if ($length != "") { return substr($code, 0, $length); } + else { return $code; } + } + + public function createsessionAction() { + $cm = new Application_Model_ClientMapper(); + $clients = $cm->fetchAll(); + + $bm = new Application_Model_BootOsMapper(); + $bootos = $bm->fetchAll(); + + $bi = new Application_Model_BootIsoMapper(); + $bootisos = $bi->fetchAll(); + + $bmem = new Application_Model_BootMenuEntriesMapper(); + $bootmenuentries = $bmem->fetchAll(); + + $mm = new Application_Model_MembershipMapper(); + $memberships = $mm->fetchAll(); + + + if (!isset($_POST["add"])) { + $createsession = new dev_Form_Session(array('buttontext' => 'Create Session', 'bootmenuentries' => $bootmenuentries, 'clients' => $clients, 'bootos' => $bootos, 'bootisos' => $bootisos, 'memberships' => $memberships)); + $this->view->createsession = $createsession; + } else { + // TODO extend with normal function not only with post + $createsession = new dev_Form_Session(array('buttontext' => 'Create Session', 'bootmenuentries' => $bootmenuentries, 'clients' => $clients, 'bootos' => $bootos, 'bootisos' => $bootisos), $_POST); +#print_a($_POST); + if ($createsession->isValid($_POST)) { + try { + $uniqid = $this->getUniqueCode(10); + $sm = new Application_Model_SessionMapper(); + while(count($sm->findBy(array('alphasessionID' => $uniqid), true)) > 0) { + $uniqid = $this->getUniqueCode(16); + } + + $session = new Application_Model_Session($_POST); + $session->setTime(strtotime($_POST['time'])); + $session->setAlphasessionID($uniqid); + + // UNIQUE ID IN SESSION SPEICHERN: + $_SESSION['alphasessionID'] = $uniqid; + + if($session->getClientID() == '') { + $session->setClientID(null); + } + if($session->getBootosID() == '') { + $session->setBootosID(null); + } + if($session->getBootmenuentryID() == '') { + $session->setBootmenuentryID(null); + } + if($session->getMembershipID() == '') { + $session->setMembershipID(null); + } + $sessionmapper = new Application_Model_SessionMapper(); + $sessionmapper->save($session); + + $this->_redirect('/dev/session'); + + } catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + } + $this->view->createsession = $createsession; } - - public function indexAction() - { - $mapper = new Application_Model_SessionMapper(); - $this->view->sessions = $mapper->fetchAll(); - #print_a($_SESSION); - } - private function getUniqueCode($length = "") - { - $code = md5(uniqid(rand(), true)); - if ($length != "") return substr($code, 0, $length); - else return $code; - } - - public function createsessionAction() - { - $cm = new Application_Model_ClientMapper(); - $clients = $cm->fetchAll(); - - $bm = new Application_Model_BootOsMapper(); - $bootos = $bm->fetchAll(); - - $bi = new Application_Model_BootIsoMapper(); - $bootisos = $bi->fetchAll(); - - $bmem = new Application_Model_BootMenuEntriesMapper(); - $bootmenuentries = $bmem->fetchAll(); - - $mm = new Application_Model_MembershipMapper(); - $memberships = $mm->fetchAll(); - - - if (!isset($_POST["add"])){ - $createsession = new dev_Form_Session(array('buttontext' => 'Create Session','bootmenuentries'=>$bootmenuentries,'clients'=>$clients,'bootos'=>$bootos,'bootisos'=>$bootisos,'memberships'=>$memberships)); - $this->view->createsession = $createsession; - }else { - // TODO extend with normal function not only with post - $createsession = new dev_Form_Session(array('buttontext' => 'Create Session','bootmenuentries'=>$bootmenuentries,'clients'=>$clients,'bootos'=>$bootos,'bootisos'=>$bootisos),$_POST); - #print_a($_POST); - if ($createsession->isValid($_POST)) { - try{ - $uniqid = $this->getUniqueCode(10); - $sm = new Application_Model_SessionMapper(); - while(count($sm->findBy(array('alphasessionID' => $uniqid),true))>0){ - $uniqid = $this->getUniqueCode(16); - } - - $session = new Application_Model_Session($_POST); - $session->setTime(strtotime($_POST['time'])); - $session->setAlphasessionID($uniqid); - - // UNIQUE ID IN SESSION SPEICHERN: - $_SESSION['alphasessionID'] = $uniqid; - - if($session->getClientID() == ''){ - $session->setClientID(null); - } - if($session->getBootosID() == ''){ - $session->setBootosID(null); - } - if($session->getBootmenuentryID() == ''){ - $session->setBootmenuentryID(null); - } - if($session->getMembershipID() == ''){ - $session->setMembershipID(null); - } - $sessionmapper = new Application_Model_SessionMapper(); - $sessionmapper->save($session); - - $this->_redirect('/dev/session'); - - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - } - } - $this->view->createsession = $createsession; - } + } + + public function editsessionAction() { + $cm = new Application_Model_ClientMapper(); + $clients = $cm->fetchAll(); + + $bm = new Application_Model_BootOsMapper(); + $bootos = $bm->fetchAll(); + + $bi = new Application_Model_BootIsoMapper(); + $bootisos = $bi->fetchAll(); + + $bmem = new Application_Model_BootMenuEntriesMapper(); + $bootmenuentries = $bmem->fetchAll(); + + $mm = new Application_Model_MembershipMapper(); + $memberships = $mm->fetchAll(); + + if (!isset($_POST["add"])) { + // TODO: ACL implementieren ob er editieren darf + $sessionID = $this->_request->getParam('sessionID'); + $session = new Application_Model_Session(); + try { + + $sessionmapper = new Application_Model_SessionMapper(); + $sessionmapper->find($sessionID, $session); + $session->setTime(date('d.m.Y H:i', $session->getTime())); + $session2 = $session->toArray(); +#print_a($session2); + + $editsession = new dev_Form_Session(array('buttontext' => 'Edit Session', 'bootmenuentries' => $bootmenuentries, 'clients' => $clients, 'bootos' => $bootos, 'bootisos' => $bootisos, 'memberships' => $memberships)); + $editsession->populate($session2); + $this->view->editsession = $editsession; + } catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + + } else { + try { + $sessionID = $this->_request->getParam('sessionID'); + + $editsession = new dev_Form_Session(array('buttontext' => 'Edit Session', 'bootmenuentries' => $bootmenuentries, 'clients' => $clients, 'bootos' => $bootos, 'bootisos' => $bootisos, 'memberships' => $memberships), $_POST); + + if ($editsession->isValid($_POST)) { + $_SESSION['alphasessionID'] = $_POST['alphasessionID']; + $session = new Application_Model_Session($_POST); + $session->setID($this->_request->getParam('sessionID')); + $session->setTime(strtotime($_POST['time'])); + if($session->getClientID() == '') { + $session->setClientID(null); + } + if($session->getBootosID() == '') { + $session->setBootosID(null); + } + if($session->getBootmenuentryID() == '') { + $session->setBootmenuentryID(null); + } + if($session->getMembershipID() == '') { + $session->setMembershipID(null); + } + $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('/dev/session'); } - - public function editsessionAction() - { - $cm = new Application_Model_ClientMapper(); - $clients = $cm->fetchAll(); - - $bm = new Application_Model_BootOsMapper(); - $bootos = $bm->fetchAll(); - - $bi = new Application_Model_BootIsoMapper(); - $bootisos = $bi->fetchAll(); - - $bmem = new Application_Model_BootMenuEntriesMapper(); - $bootmenuentries = $bmem->fetchAll(); - - $mm = new Application_Model_MembershipMapper(); - $memberships = $mm->fetchAll(); - - if (!isset($_POST["add"])){ - // TODO: ACL implementieren ob er editieren darf - $sessionID = $this->_request->getParam('sessionID'); - $session = new Application_Model_Session(); - try{ - - $sessionmapper = new Application_Model_SessionMapper(); - $sessionmapper->find($sessionID,$session); - $session->setTime(date('d.m.Y H:i',$session->getTime())); - $session2 = $session->toArray(); - #print_a($session2); - - $editsession = new dev_Form_Session(array('buttontext' => 'Edit Session','bootmenuentries'=>$bootmenuentries,'clients'=>$clients,'bootos'=>$bootos,'bootisos'=>$bootisos,'memberships'=>$memberships)); - $editsession->populate($session2); - $this->view->editsession = $editsession; - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - } - - } else{ - try{ - $sessionID = $this->_request->getParam('sessionID'); - - $editsession = new dev_Form_Session(array('buttontext' => 'Edit Session','bootmenuentries'=>$bootmenuentries,'clients'=>$clients,'bootos'=>$bootos,'bootisos'=>$bootisos,'memberships'=>$memberships),$_POST); - - if ($editsession->isValid($_POST)) { - $_SESSION['alphasessionID'] = $_POST['alphasessionID']; - $session = new Application_Model_Session($_POST); - $session->setID($this->_request->getParam('sessionID')); - $session->setTime(strtotime($_POST['time'])); - if($session->getClientID() == ''){ - $session->setClientID(null); - } - if($session->getBootosID() == ''){ - $session->setBootosID(null); - } - if($session->getBootmenuentryID() == ''){ - $session->setBootmenuentryID(null); - } - if($session->getMembershipID() == ''){ - $session->setMembershipID(null); - } - $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('/dev/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('/dev/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('/dev/session'); + } } |