diff options
| author | Simon | 2011-03-13 00:29:00 +0100 |
|---|---|---|
| committer | Simon | 2011-03-13 00:29:00 +0100 |
| commit | 8618f91b2ba420eea204e70355470af94d3ca2b7 (patch) | |
| tree | 1aafe6899935c52e85ae9f8041d9662b0a8185a1 | |
| parent | css repariert (diff) | |
| download | pbs2-8618f91b2ba420eea204e70355470af94d3ca2b7.tar.gz pbs2-8618f91b2ba420eea204e70355470af94d3ca2b7.tar.xz pbs2-8618f91b2ba420eea204e70355470af94d3ca2b7.zip | |
filtertypen hinzugefügt, Zeit, Datum und Wochentage können in Filtern definiert werden, Formular wird automatisch aktualisiert
| -rw-r--r-- | application/controllers/FilterController.php | 163 | ||||
| -rw-r--r-- | application/forms/FilterEntriesAdd.php | 128 | ||||
| -rw-r--r-- | application/forms/FilterEvaluate.php | 13 | ||||
| -rw-r--r-- | application/views/scripts/filter/editfilterentry.phtml | 1 | ||||
| -rw-r--r-- | pbs.sql | 20 |
5 files changed, 256 insertions, 69 deletions
diff --git a/application/controllers/FilterController.php b/application/controllers/FilterController.php index 7b05b0e..da52c34 100644 --- a/application/controllers/FilterController.php +++ b/application/controllers/FilterController.php @@ -122,7 +122,12 @@ class FilterController extends Zend_Controller_Action // TODO: ACL implementieren ob er editieren darf if (!isset($_POST["add"])){ try{ - $editfilterform = new Application_Form_FilterEntriesAdd(array('buttontext' => 'Add Filterentry','filterID' => $this->_request->getParam('filterID'))); + $editfilterform = new Application_Form_FilterEntriesAdd( + array( 'buttontext' => 'Add Filterentry', + 'filterID' => $this->_request->getParam('filterID'), + 'data' => $_POST + )); + $editfilterform->populate($_POST); $this->view->editfilterform = $editfilterform; }catch (Zend_Exception $e) { echo "Error message 2: " . $e->getMessage() . "\n"; @@ -145,6 +150,7 @@ class FilterController extends Zend_Controller_Action $newfilter2 = new Application_Model_FilterEntriesMapper(); $newfilter2->save($newfilterenty); + #print_a($newfilterenty); $this->_redirect('/filter'); } $this->view->editfilterform = $editfilterform; @@ -156,17 +162,25 @@ class FilterController extends Zend_Controller_Action 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 = new Application_Form_FilterEntriesAdd(array('buttontext' => 'Edit Filterentry')); + + + #$editfilterform->setFilterID($filterID); + if(isset($_POST['filtertypeID']) && $_POST['filtertypeID'] != $filterentry->getFiltertypeID()){ + $filterentry->setFiltertypeID($_POST['filtertypeID']) ; + } + $data = $filterentry->toArray(); + print_a($data); + $editfilterform = new Application_Form_FilterEntriesAdd( + array('buttontext' => 'Edit Filterentry', + 'data' => $data)); + $editfilterform->populate($filterentry->toArray()); - $editfilterform->setFilterID($filterID); $this->view->editfilterform = $editfilterform; }catch (Zend_Exception $e) { @@ -176,7 +190,9 @@ class FilterController extends Zend_Controller_Action try{ $filterentriesID = $this->_request->getParam('filterentriesID'); $editfilterform = new Application_Form_FilterEntriesAdd(array('buttontext' => 'Edit Filterentry'),$_POST); - if ($editfilterform->isValid($_POST)) { + if ($editfilterform->isValid($_POST)) { + if($_POST['filterID'] == '') + unset($_POST['filterID']); $newfilterenty = new Application_Model_FilterEntries($_POST); $newfilterenty->setID($filterentriesID); if($_POST['filtertypeID'] == 1){ @@ -189,6 +205,7 @@ class FilterController extends Zend_Controller_Action } $newfilter2 = new Application_Model_FilterEntriesMapper(); $newfilter2->save($newfilterenty); + #print_a($newfilterenty); $this->_redirect('/filter'); } @@ -202,24 +219,24 @@ class FilterController extends Zend_Controller_Action public function removefilterentryAction() { try{ - $filterentriesID = $this->_request->getParam('filterentriesID'); - - // TODO: ACL implementieren ob er den filter löschen darf - if(is_numeric($filterentriesID)){ - $deletefilterentry = new Application_Model_FilterEntries(); - $deletefilterentry->setID($filterentriesID); - echo "<pre style='border:1px solid black;background-color:#F5B800'>"; - print_r($deletefilterentry); - echo "</pre>"; - - $filterentriesmapper = new Application_Model_FilterEntriesMapper(); - $filterentriesmapper->delete($deletefilterentry); - echo "ok"; - } - $this->_redirect('/filter'); - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - } + $filterentriesID = $this->_request->getParam('filterentriesID'); + + // TODO: ACL implementieren ob er den filter löschen darf + if(is_numeric($filterentriesID)){ + $deletefilterentry = new Application_Model_FilterEntries(); + $deletefilterentry->setID($filterentriesID); + echo "<pre style='border:1px solid black;background-color:#F5B800'>"; + print_r($deletefilterentry); + echo "</pre>"; + + $filterentriesmapper = new Application_Model_FilterEntriesMapper(); + $filterentriesmapper->delete($deletefilterentry); + echo "ok"; + } + $this->_redirect('/filter'); + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } } private function fillIP($ip) @@ -258,8 +275,10 @@ class FilterController extends Zend_Controller_Action $bootisoID = $_POST['bootisoID']; $membershipID = $_POST['membershipID']; $groupID = $_POST['groupID']; - $time = strtotime($_POST['time']); + $time = ($_POST['time']); $clientID = $_POST['clientID']; + $weekday = $_POST['weekday']; + $date = $_POST['date']; print_a('Input', array('ipAdress'=>$ipAdress, 'macAdress'=>$macAdress, @@ -267,8 +286,11 @@ class FilterController extends Zend_Controller_Action 'bootisoID' => $bootisoID, 'membershipID'=>$membershipID, 'groupID'=>$groupID, - 'time'=>$time." - ".date('d.m.Y H:i:s',$time), - 'clientID' => $clientID)); + 'time'=> $time." - ".date('d.m.Y H:i:s',$time), + 'clientID' => $clientID, + 'hardwarehash' => $hardwarehash, + 'weekday' => $weekday, + 'date' => $date)); } @@ -276,7 +298,7 @@ class FilterController extends Zend_Controller_Action $mysession = '1'; $set = array(); - $filtertypID = 8; + $session = new Application_Model_Session(); $sessionmapper = new Application_Model_SessionMapper(); $sessionmapper->find($mysession,$session); @@ -447,21 +469,18 @@ class FilterController extends Zend_Controller_Action // Time $filtertypID = 7; if(!$testFilter){ - $time = time(); + $time = time("H:i"); } - $nowShort = date('H-i',$time); - $nowLong = date('Y-m-d-H-i',$time); + $nowShort = $time; - $nowShort = str_replace("-","",$nowShort); - $nowLong = str_replace("-","",$nowLong); + $nowShort = str_replace(":","",$nowShort); try{ $select = $db->select() ->from(array('pbs_filterentries') ) ->where('filtertypeID = ?',$filtertypID) - ->where('REPLACE(filtervalue,"-","") <= ? AND ? <= REPLACE(filtervalue2,"-","")',$nowShort) - ->orWhere('REPLACE(filtervalue,"-","") <= ? AND ? <= REPLACE(filtervalue2,"-","")',$nowLong); + ->where('REPLACE(filtervalue,":","") <= ? AND ? <= REPLACE(filtervalue2,":","")',$nowShort); $stmt = $select->query(); $result = $stmt->fetchAll(); @@ -473,6 +492,78 @@ class FilterController extends Zend_Controller_Action 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); diff --git a/application/forms/FilterEntriesAdd.php b/application/forms/FilterEntriesAdd.php index 3b051f5..9f9c642 100644 --- a/application/forms/FilterEntriesAdd.php +++ b/application/forms/FilterEntriesAdd.php @@ -2,35 +2,101 @@ class Application_Form_FilterEntriesAdd extends Zend_Form { - - private $filterID = null; + private $filterID = 0; public function init() { $this->setName("Add Filterentry"); $this->setMethod('post'); + $this->setAttrib('id','filterentryform'); + #print_a($this->data); try{ $filtertypemapper = new Application_Model_FilterTypeMapper(); $filtertype = $filtertypemapper->fetchAll(); - }catch (Zend_Exception $e) { - echo "Error message 1: " . $e->getMessage() . "\n"; - } + $filtertypes = $this->createElement('select','filtertypeID'); $filtertypes ->setLabel('Type:'); + $filtertypes ->setAttrib('id','filtertype'); + $filtertypes->addMultiOption('',''); foreach($filtertype as $f){ $filtertypes->addMultiOption($f->getID(),$f->getFiltertypename()); - } - $this->addElement($filtertypes); - + } + $filterentry = $filtertypes->getMultiOption($this->data['filtertypeID']); + $filterentryID = $this->data['filtertypeID']; + }catch (Zend_Exception $e) { + echo "Error message 1: " . $e->getMessage() . "\n"; + } + switch($filterentryID){ + default: + $desc = "Select the filtertype"; + $label1 = 'Value 1:'; + $label2 = 'Value 2:'; + break; + case "1": + $desc = "You can set one IP or an IP-Range"; + $label1 = 'Start:'; + $label2 = 'End:'; + break; + case "2": + $desc = "You can set one Mac-Adress or an Mac-Range"; + $label1 = 'Start:'; + $label2 = 'End:'; + break; + case "3": + $desc = "Select your Pool"; + $label1 = 'PoolID:'; + break; + case "4": + $desc = "Select your BootIso"; + $label1 = 'BootIsoID:'; + break; + case "5": + $desc = "Select a Membership"; + $label1 = 'Membership:'; + break; + case "6": + $desc = "Select a Group"; + $label1 = 'Group:'; + break; + case "7": + $desc = "Specify a time-range"; + $label1 = 'Start:'; + $label2 = 'End:'; + break; + case "8": + $desc = "Select a Client"; + $label1 = 'Client:'; + break; + case "9": + $desc = "Define a Hardwarehash"; + $label1 = 'Hardwarehash:'; + break; + case "10": + $desc = "Specify the Weekday (Monday:1, Tuesday:2 ... Sunday:7) or a range"; + $label1 = 'Start Day:'; + $label2 = 'End Day:'; + break; + case "11": + $desc = "Specify the date or a day range of the filter"; + $label1 = 'Start Date:'; + $label2 = 'End Date:'; + break; + } + $filtertypes->setDescription($desc); + $this->addElement($filtertypes); $this->addElement('text', 'filtervalue', array( - 'label' => 'Value1:' - )); - - $this->addElement('text', 'filtervalue2', array( - 'label' => 'Value2:' + 'label' => $label1, + 'id' => 'val1' )); + + if(!in_array($filterentryID,array(3,4,5,6,8,9))){ + $this->addElement('text', 'filtervalue2', array( + 'label' => $label2, + 'id' => 'val2' + )); + } $this->addElement('submit', 'add', array( 'required' => false, @@ -41,19 +107,39 @@ class Application_Form_FilterEntriesAdd extends Zend_Form $this->addElement('button', 'Cancel', array( 'onclick' => 'self.location="/filter"' )); + + $this->addElement('hidden', 'filterID', array( + 'value' => $this->filterID + )); - $this->addElement('hidden', 'filterID', array( - 'value' => $this->filterID - )); + } - public function setFilterID($id) - { - $this->filterID = $id; - } + private $buttontext = 'Save'; function setButtontext($v){ $this->buttontext = $v; } - + private $data ; + function setData($v){ + $this->data = $v; + } + function setFilterID($v){ + $this->filterID = $v; + } } +?> +<script> + $('#filtertype').change(function(){ + //alert($("#filtertype option:selected").val()); + $('#filterentryform').submit(); + }); + $('#val1').focusout(function(){ + if($("#filtertype option:selected").val() == 1 && $('#val2').val() == ""){ + $('#val2').val($('#val1').val()); + } + if($("#filtertype option:selected").val() == 2 && $('#val2').val() == ""){ + $('#val2').val($('#val1').val()); + } + }); +</script> diff --git a/application/forms/FilterEvaluate.php b/application/forms/FilterEvaluate.php index 28dd848..b7c2b51 100644 --- a/application/forms/FilterEvaluate.php +++ b/application/forms/FilterEvaluate.php @@ -95,7 +95,16 @@ class Application_Form_FilterEvaluate extends Zend_Form } $clientfield->setRegisterInArrayValidator(false); $this->addElement($clientfield); - + ###################################### + $this->addElement('text', 'hardwarehash', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => false, + 'label' => 'Hardwarehash:', + )); + $this->addElement('submit', 'submit', array( 'required' => false, 'ignore' => true, @@ -117,7 +126,5 @@ class Application_Form_FilterEvaluate extends Zend_Form function setClients($v){ $this->clients = $v; } - - } diff --git a/application/views/scripts/filter/editfilterentry.phtml b/application/views/scripts/filter/editfilterentry.phtml index 8bf501a..038f16a 100644 --- a/application/views/scripts/filter/editfilterentry.phtml +++ b/application/views/scripts/filter/editfilterentry.phtml @@ -1,3 +1,2 @@ <?php -$this->editfilterform->setAction($this->url()); echo $this->editfilterform; @@ -306,12 +306,16 @@ ALTER TABLE `pbs_filterentries` ADD CONSTRAINT `pbs_filterentries_ibfk_2` FOREIGN KEY (`filtertypeID`) REFERENCES `pbs_filtertype` (`filtertypeID`) ON DELETE CASCADE; -- Insert Filtertypes -INSERT INTO `pbs`.`pbs_filtertype` (`filtertypeID`, `filtertypename`) VALUES (NULL, 'IP'); -INSERT INTO `pbs`.`pbs_filtertype` (`filtertypeID`, `filtertypename`) VALUES (NULL, 'MAC'); -INSERT INTO `pbs`.`pbs_filtertype` (`filtertypeID`, `filtertypename`) VALUES (NULL, 'PoolID'); -INSERT INTO `pbs`.`pbs_filtertype` (`filtertypeID`, `filtertypename`) VALUES (NULL, 'BootIso'); -INSERT INTO `pbs`.`pbs_filtertype` (`filtertypeID`, `filtertypename`) VALUES (NULL, 'Membership'); -INSERT INTO `pbs`.`pbs_filtertype` (`filtertypeID`, `filtertypename`) VALUES (NULL, 'Group'); -INSERT INTO `pbs`.`pbs_filtertype` (`filtertypeID`, `filtertypename`) VALUES (NULL, 'Time'); -INSERT INTO `pbs`.`pbs_filtertype` (`filtertypeID`, `filtertypename`) VALUES (NULL, 'Client'); +INSERT INTO `pbs_filtertype` (`filtertypeID`, `filtertypename`) VALUES +(1, 'IP'), +(2, 'MAC'), +(3, 'PoolID'), +(4, 'BootIso'), +(5, 'Membership'), +(6, 'Group'), +(7, 'Time'), +(8, 'Client'), +(9, 'Hardwarehash'), +(10, 'Weekday'), +(11, 'Date'); |
