diff options
| author | michael pereira | 2011-03-09 20:54:27 +0100 |
|---|---|---|
| committer | michael pereira | 2011-03-09 20:54:27 +0100 |
| commit | fbff9df0469ee998389fa263d8638cc3bf3618b5 (patch) | |
| tree | 04adfd6a021e574055469ce6d0469988cb4684bd /application/controllers | |
| parent | KCL und BootMenuFilter (diff) | |
| parent | FilterController Evaluate funktioniert (diff) | |
| download | pbs2-fbff9df0469ee998389fa263d8638cc3bf3618b5.tar.gz pbs2-fbff9df0469ee998389fa263d8638cc3bf3618b5.tar.xz pbs2-fbff9df0469ee998389fa263d8638cc3bf3618b5.zip | |
Merge branch 'master' of openslx.org:lsfks/master-teamprojekt/pbs2
Diffstat (limited to 'application/controllers')
| -rw-r--r-- | application/controllers/ClientController.php | 21 | ||||
| -rw-r--r-- | application/controllers/FilterController.php | 563 | ||||
| -rw-r--r-- | application/controllers/PoolController.php | 20 | ||||
| -rw-r--r-- | application/controllers/SessionController.php | 51 |
4 files changed, 393 insertions, 262 deletions
diff --git a/application/controllers/ClientController.php b/application/controllers/ClientController.php index ff663ba..580eb6e 100644 --- a/application/controllers/ClientController.php +++ b/application/controllers/ClientController.php @@ -16,16 +16,15 @@ class ClientController extends Zend_Controller_Action public function addclientAction() { - $mac = $this->_request->getParam('mac'); - $hh = $this->_request->getParam('hh'); + $mac = $this->_request->getParam('mac'); + $hh = $this->_request->getParam('hh'); if (!isset($_POST["add"])){ - $addclient = new Application_Form_Client(); - $this->view->addclient = $addclient; + $addclient = new Application_Form_Client(); + $this->view->addclient = $addclient; } else{ $addfilterform = new Application_Form_Client($_POST); - print_a($_POST,$addfilterform->isValid($_POST)); if ($addfilterform->isValid($_POST) || ($mac != '' && $hh != '') ) { $client = new Application_Model_Client(); $mac = ($mac!='')?$mac:$_POST['macadress']; @@ -37,9 +36,7 @@ class ClientController extends Zend_Controller_Action print_a('inserted'); $this->_redirect('/client'); } - else{ - print_a('no insert'); - } + $this->view->addclient = $addclient; } } @@ -69,8 +66,8 @@ class ClientController extends Zend_Controller_Action $this->view->editclient = $editclient; } else{ - $addfilterform = new Application_Form_Client($_POST); - if ($addfilterform->isValid($_POST) || ($mac != '' && $hh != '') ) { + $editclient = new Application_Form_Client($_POST); + if ($editclient->isValid($_POST) || ($mac != '' && $hh != '') ) { $client = new Application_Model_Client($_POST); $client->setID($this->_request->getParam('clientID')); $clientmapper = new Application_Model_ClientMapper(); @@ -78,9 +75,7 @@ class ClientController extends Zend_Controller_Action print_a('updated'); $this->_redirect('/client'); } - else{ - print_a('no update'); - } + $this->view->editclient = $editclient; } } diff --git a/application/controllers/FilterController.php b/application/controllers/FilterController.php index 54bcb19..9141e10 100644 --- a/application/controllers/FilterController.php +++ b/application/controllers/FilterController.php @@ -4,16 +4,18 @@ class FilterController extends Zend_Controller_Action { private $_filtermapper = null; - private $db; + + 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->_filtermapper = new Application_Model_FilterMapper(); + }catch (Zend_Exception $e) { + echo "Error message 1: " . $e->getMessage() . "\n"; + } + $this->db = Zend_Db_Table::getDefaultAdapter(); } public function indexAction() @@ -21,25 +23,25 @@ class FilterController extends Zend_Controller_Action try{ $this->_filtermapper = new Application_Model_FilterMapper(); $this->view->filters = $this->_filtermapper->fetchAll(); - }catch (Zend_Exception $e) { + }catch (Zend_Exception $e) { echo "Error message 2: " . $e->getMessage() . "\n"; - } - } + } + } public function addfilterAction() { - if (!isset($_POST["add"])){ - $addfilterform = new Application_Form_FilterAdd(); - $this->view->addfilterform = $addfilterform; + $bmmapper = new Application_Model_BootMenuMapper(); + //TODO get bootmenu by group + $bootmenus = $bmmapper->fetchAll(); + if (!isset($_POST["add"])){ + $addfilterform = new Application_Form_FilterAdd(array('bootmenus'=>$bootmenus)); + $this->view->addfilterform = $addfilterform; }else { - $addfilterform = new Application_Form_FilterAdd($_POST); + $addfilterform = new Application_Form_FilterAdd(array('bootmenus'=>$bootmenus),$_POST); if ($addfilterform->isValid($_POST)) { try{ - $newfilter = new Application_Model_Filter(); - $newfilter->setTitle($_POST['title']); + $newfilter = new Application_Model_Filter($_POST); $newfilter->setCreated(time()); - $newfilter->setDescription($_POST['description']); - $newfilter->setPriority($_POST['priority']); // TODO: Ändere mit ACL $newfilter->setGroupID('1'); @@ -54,89 +56,80 @@ class FilterController extends Zend_Controller_Action echo "Error message 2: " . $e->getMessage() . "\n"; } } + $this->view->addfilterform = $addfilterform; } } public function removefilterAction() { - - $filterID = $this->_request->getParam('filterID'); - // TODO: ACL implementieren ob er den filter löschen darf - if(is_numeric($filterID)){ - $deletefilter = new Application_Model_Filter(); - $deletefilter->setID($filterID); - $filtermapper = new Application_Model_FilterMapper(); - $filtermapper->delete($deletefilter); - } - $this->_redirect('/filter'); + $filterID = $this->_request->getParam('filterID'); + // TODO: ACL implementieren ob er den filter löschen darf + if(is_numeric($filterID)){ + $deletefilter = new Application_Model_Filter(); + $deletefilter->setID($filterID); + $filtermapper = new Application_Model_FilterMapper(); + $filtermapper->delete($deletefilter); + } + $this->_redirect('/filter'); } public function editfilterAction() { - if (!isset($_POST["add"])){ - // TODO: ACL implementieren ob er editieren darf - $filterID = $this->_request->getParam('filterID'); - $filter = new Application_Model_Filter(); - - - $filtermapper = new Application_Model_FilterMapper(); - $filtermapper->find($filterID,$filter); - $filter2 = $filter->toArray(); - - $editfilterform = new Application_Form_FilterAdd(); - $editfilterform->populate($filter2); - $this->view->editfilterform = $editfilterform; - - } else{ - try{ - $filterID = $this->_request->getParam('filterID'); - - $editfilterform = new Application_Form_FilterAdd($_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'; - } - else - { - echo 'not valid'; - } - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - } - $this->_redirect('/filter'); - } + $bmmapper = new Application_Model_BootMenuMapper(); + //TODO get bootmenu by group + $bootmenus = $bmmapper->fetchAll(); + if (!isset($_POST["add"])){ + // TODO: ACL implementieren ob er editieren darf + $filterID = $this->_request->getParam('filterID'); + $filter = new Application_Model_Filter(); + + + $filtermapper = new Application_Model_FilterMapper(); + $filtermapper->find($filterID,$filter); + $filter2 = $filter->toArray(); + + $editfilterform = new Application_Form_FilterAdd(array('bootmenus'=>$bootmenus)); + $editfilterform->populate($filter2); + $this->view->editfilterform = $editfilterform; + + } else{ + try{ + $filterID = $this->_request->getParam('filterID'); + + $editfilterform = new Application_Form_FilterAdd(array('bootmenus'=>$bootmenus),$_POST); + //TODO: ACL integrieren + $_POST['groupID'] = 1; + $_POST['membershipID'] = 1; + $_POST['created'] = time(); + + if ($editfilterform->isValid($_POST)) { + $newfilterenty = new Application_Model_Filter($_POST); + $newfilterenty->setID($this->_request->getParam('filterID')); + $newfilter2 = new Application_Model_FilterMapper(); + $newfilter2->save($newfilterenty); + echo 'valid'; + $this->_redirect('/filter'); + } + $this->view->editfilterform = $editfilterform; + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + } } public function addfilterentryAction() { - // TODO: ACL implementieren ob er editieren darf if (!isset($_POST["add"])){ - echo "case1"; try{ $editfilterform = new Application_Form_FilterEntriesAdd(array('filterID' => $this->_request->getParam('filterID'))); $this->view->editfilterform = $editfilterform; - echo "<pre style='padding:5px;border:1px solid black;background-color:#3CF'>"; - print_r(array('debug','case1')); - echo "</pre>"; - }catch (Zend_Exception $e) { echo "Error message 2: " . $e->getMessage() . "\n"; } } else{ - $editfilterform = new Application_Form_FilterEntriesAdd($_POST); - echo "<pre style='padding:5px;border:1px solid black; background-color:#3CF;'>case2</pre>"; - - if ($editfilterform->isValid($_POST)) { - echo "<pre style='padding:5px;border:1px solid black; background-color:#3CF;'>case 2.2</pre>"; + $editfilterform = new Application_Form_FilterEntriesAdd($_POST); + if ($editfilterform->isValid($_POST)) { $newfilterenty = new Application_Model_FilterEntries(); $newfilterenty->setFilterID($_POST['filterID']); $newfilterenty->setFiltertypeID($_POST['filtertypeID']); @@ -151,15 +144,14 @@ class FilterController extends Zend_Controller_Action } $newfilter2 = new Application_Model_FilterEntriesMapper(); - echo "<pre style='border:1px solid black;background-color:#F5B800'>"; - print_r($newfilterenty); - echo "</pre>"; $newfilter2->save($newfilterenty); + $this->_redirect('/filter'); } - $this->_redirect('/filter'); + $this->view->editfilterform = $editfilterform; } } - public function editfilterentryAction() + + public function editfilterentryAction() { if (!isset($_POST["add"])){ echo "case1"; @@ -174,13 +166,9 @@ class FilterController extends Zend_Controller_Action $editfilterform = new Application_Form_FilterEntriesAdd(); - echo "<pre style='border:1px solid black;background-color:#F5B800'>"; - print_r($filterentry->toArray()); - echo "</pre>"; $editfilterform->populate($filterentry->toArray()); $editfilterform->setFilterID($filterID); $this->view->editfilterform = $editfilterform; - echo "case 1.1"; }catch (Zend_Exception $e) { echo "Error message 2: " . $e->getMessage() . "\n"; @@ -189,8 +177,7 @@ class FilterController extends Zend_Controller_Action try{ $filterentriesID = $this->_request->getParam('filterentriesID'); $editfilterform = new Application_Form_FilterEntriesAdd($_POST); - if ($editfilterform->isValid($_POST)) { - echo "valid\n"; + if ($editfilterform->isValid($_POST)) { $newfilterenty = new Application_Model_FilterEntries($_POST); $newfilterenty->setID($filterentriesID); if($_POST['filtertypeID'] == 1){ @@ -201,68 +188,94 @@ class FilterController extends Zend_Controller_Action $newfilterenty->setFiltervalue($_POST['filtervalue']); $newfilterenty->setFiltervalue2($_POST['filtervalue2']); } - echo "<pre style='border:1px solid black;background-color:#F5B800'>"; - print_r($newfilterenty); - echo "</pre>"; $newfilter2 = new Application_Model_FilterEntriesMapper(); $newfilter2->save($newfilterenty); + $this->_redirect('/filter'); } - else{ - echo 'nö'; - } + $this->view->editfilterform = $editfilterform; }catch (Zend_Exception $e) { echo "Error message 2: " . $e->getMessage() . "\n"; - } - $this->_redirect('/filter'); + } } } - 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"; + 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"; } -# echo "ready"; - $this->_redirect('/filter'); - }catch (Zend_Exception $e) { - echo "Error message 2: " . $e->getMessage() . "\n"; - } } - private function fillIP($ip){ - $ar = explode(".",$ip); - $representation = array(); - foreach($ar as $part){ - $representation[] = sprintf("%03s",$part); - } - return implode(".",$representation); - } - private function fillMac($ip){ - $ar = explode(":",$ip); - $representation = array(); - foreach($ar as $part){ - $representation[] = sprintf("%02s",$part); + + private function fillIP($ip) + { + $ar = explode(".",$ip); + $representation = array(); + foreach($ar as $part){ + $representation[] = sprintf("%03s",$part); + } + return implode(".",$representation); + } + + private function fillMac($ip) + { + $ar = explode(":",$ip); + $representation = array(); + foreach($ar as $part){ + $representation[] = sprintf("%02s",$part); + } + return implode(":",$representation); + } + + public function evaluateAction() + { + $db = $this->db; + $showPartResults = false; + // For Testing Filters + + + $testFilter = (isset($_POST['submit']))?true:false; + + if($testFilter){ + $ipAdress = $_POST['ip']; + $macAdress = $_POST['mac']; + $poolID = $_POST['poolID']; + $bootisoID = $_POST['bootisoID']; + $membershipID = $_POST['membershipID']; + $groupID = $_POST['groupID']; + $time = strtotime($_POST['time']); + $clientID = $_POST['clientID']; + 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)); } - return implode(":",$representation); - } - public function evaluateAction(){ - $db = $this->db; - $showPartResults = false; - try{ - + + + try{ $mysession = '1'; + $set = array(); $filtertypID = 8; $session = new Application_Model_Session(); @@ -272,148 +285,199 @@ class FilterController extends Zend_Controller_Action // IP Adress $filtertypID = 1; // get it from session_table with session_id from the session - $ipAdress = $session->getIp(); + if(!$testFilter){ + $ipAdress = $session->getIp(); + } $ipAdress = str_replace(".","",$this->fillIP($ipAdress)); + $select = $db->select() - ->from(array('pbs_filterentries') + ->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 - $client = new Application_Model_Client(); - $clientmapper = new Application_Model_ClientMapper(); - $clientmapper->find($session->getClientID(),$client); - - $macAdress = $client->getMacadress(); - $macAdress = str_replace(":","",$this->fillMac($ipAdress)); - $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE - filtertypeID = ".$filtertypID." AND - CONV(HEX('filtervalue'),16,10) <= CONV(HEX('".$macAdress."'),16,10) AND - CONV(HEX('".$macAdress."'),16,10) <= CONV(HEX('filtervalue2'),16,10)"); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; + if(!$testFilter){ + $client = new Application_Model_Client(); + $clientmapper = new Application_Model_ClientMapper(); + $clientmapper->find($session->getClientID(),$client); + $macAdress = $client->getMacadress(); } + try{ + $macAdress = str_replace(":","",$this->fillMac($ipAdress)); + $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE + filtertypeID = ".$filtertypID." AND + CONV(HEX('filtervalue'),16,10) <= CONV(HEX('".$macAdress."'),16,10) AND + CONV(HEX('".$macAdress."'),16,10) <= CONV(HEX('filtervalue2'),16,10)"); + $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 - $poolentry = new Application_Model_PoolEntries(); - $poolentrymapper = new Application_Model_PoolEntriesMapper(); - $poolentry = $poolentrymapper->findby('clientID',$client->getID()); - $poolentry = $poolentry[0]; - - $poolID = $poolentry['poolID']; - print_a($poolentry); - $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE - filtertypeID = ".$filtertypID." AND - filtervalue = ".$poolID." "); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; + if(!$testFilter){ + $poolentry = new Application_Model_PoolEntries(); + $poolentrymapper = new Application_Model_PoolEntriesMapper(); + $poolentry = $poolentrymapper->findby('clientID',$client->getID()); + $poolentry = $poolentry[0]; + + $poolID = $poolentry['poolID']; + } + + try{ + $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE + filtertypeID = ".$filtertypID." AND + filtervalue = ".$poolID." "); + $result = $stmt->fetchAll(); + if(count($result)>0){ + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + } } + catch(Exception $e){} + if($showPartResults) print_a('poolID',$result,$set[$filtertypID]); ######################################################### // ClientID $filtertypID = 8; // get client_ID from session_id from the session - $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE - filtertypeID = ".$filtertypID." AND - filtervalue = ".$session->getClientID()." "); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; + + if(!$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 - $bootisoID = $session->getBootisoID(); - $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE - filtertypeID = ".$filtertypID." AND - filtervalue = ".$bootisoID." "); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; + // 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; - // get membership from the session - //TODO: GET MEMBERSHIP from SESSION - $membershipID = 1; - $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE - filtertypeID = ".$filtertypID." AND - filtervalue = ".$membershipID." "); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; + if(!$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; - // get membership from the session - //TODO: GET GROUP from SESSION - $groupID = 1; - $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE - filtertypeID = ".$filtertypID." AND - filtervalue = ".$groupID." "); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; + if(!$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; - $nowShort = date('H-i',time()); - $nowLong = date('Y-m-d-H-i',time()); + if(!$testFilter){ + $time = time(); + } + + $nowShort = date('H-i',$time); + $nowLong = date('Y-m-d-H-i',$time); $nowShort = str_replace("-","",$nowShort); $nowLong = str_replace("-","",$nowLong); - - $select = $db->select() - ->from(array('pbs_filterentries') - ) - ->where('filtertypeID = ?',$filtertypID) - ->where('REPLACE(filtervalue,"-","") <= ? AND ? <= REPLACE(filtervalue2,"-","")',$nowShort) - ->orWhere('REPLACE(filtervalue,"-","") <= ? AND ? <= REPLACE(filtervalue2,"-","")',$nowLong); - - $stmt = $select->query(); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; + 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); + + $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]); ######################################## // ErgebnisSet auswerten print_a('the result sets of the filtertypes',$set); - + // Merging of the resultsets of the filter $kk = array(); foreach($set as $myset){ @@ -421,18 +485,21 @@ class FilterController extends Zend_Controller_Action } $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]); @@ -441,8 +508,8 @@ class FilterController extends Zend_Controller_Action $result[] = $i; } } - - print_a('result set of filterIDs',$result); + + print_a('True Filters',$result); // now selecting the filter with the highest priority $query = 'SELECT filterID, bootmenuID, priority FROM pbs_filter WHERE '; @@ -451,16 +518,58 @@ class FilterController extends Zend_Controller_Action } $query .= implode(" OR ", $queryTmp); $query .= 'ORDER BY priority DESC LIMIT 0,1'; - $stmt = $db->query($query); - $resultset = $stmt->fetchAll(); - print_a($resultset); - echo "<h1>".$resultset[0]['bootmenuID']."</h1>"; - + $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"; + 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 Application_Form_FilterEvaluate( + array( 'pools' => $pools, + 'bootisos' => $bootisos, + 'memberships' => $memberships, + 'groups' => $groups, + 'clients' => $clients, + + )); + $this->view->filterevaluate = $filterevaluate; + } + } @@ -472,3 +581,5 @@ class FilterController extends Zend_Controller_Action + + diff --git a/application/controllers/PoolController.php b/application/controllers/PoolController.php index cb38a80..7c5092e 100644 --- a/application/controllers/PoolController.php +++ b/application/controllers/PoolController.php @@ -25,7 +25,6 @@ class PoolController extends Zend_Controller_Action $assignedclientsArray[] = $c->toArray(); } $freeclients = $this->arrayDiff($clientsArray,$assignedclientsArray); - #print_a($freeclients); $this->view->freeclients = $freeclients; @@ -49,6 +48,7 @@ class PoolController extends Zend_Controller_Action echo "Error message 2: " . $e->getMessage() . "\n"; } } + $this->view->addpool = $addfilterform; } } @@ -80,8 +80,8 @@ class PoolController extends Zend_Controller_Action $this->view->editpoolform = $editpool; }else { - $addpoolform = new Application_Form_Pool($_POST); - if ($addpoolform->isValid($_POST)) { + $editpoolform = new Application_Form_Pool($_POST); + if ($editpoolform->isValid($_POST)) { try{ $pool = new Application_Model_Pool($_POST); $pool->setID($this->_request->getParam('poolID')); @@ -92,6 +92,7 @@ class PoolController extends Zend_Controller_Action echo "Error message 2: " . $e->getMessage() . "\n"; } } + $this->view->editpoolform = $editpoolform; } } @@ -99,10 +100,8 @@ class PoolController extends Zend_Controller_Action { $clientID = $this->_request->getParam('clientID'); $poolID = $this->_request->getParam('poolID'); - print_a($clientID,$poolID); if(!isset($_POST['clientID']) && ($clientID == '' && $poolID == '')){ - print_a($_POST); $clientmapper = new Application_Model_ClientMapper(); $clients = $clientmapper->fetchAll(); foreach($clients as $c){ @@ -117,10 +116,8 @@ class PoolController extends Zend_Controller_Action $poolclient = new Application_Form_PoolClient(array('clients'=> $freeclients)); $this->view->poolclient = $poolclient; - }else { - #$_POST['poolID'] = $this->_request->getParam('poolID'); - $poolclientform = new Application_Form_PoolClient($_POST); - + }else { + $poolclient = new Application_Form_PoolClient($_POST); try{ $pool = new Application_Model_PoolEntries($_POST); $pool->setPoolID($this->_request->getParam('poolID')); @@ -133,6 +130,7 @@ class PoolController extends Zend_Controller_Action }catch (Zend_Exception $e) { echo "Error message 2: " . $e->getMessage() . "\n"; } + $this->view->poolclient = $poolclient; } } @@ -156,15 +154,11 @@ class PoolController extends Zend_Controller_Action if(is_numeric($poolentriesID)){ $deletepoolentries = new Application_Model_PoolEntries(); $deletepoolentries->setID($poolentriesID); - echo "<pre style='border:1px solid black;background-color:#F5B800'>"; - print_r($deletepoolentries); - echo "</pre>"; $deletepoolentriesmapper = new Application_Model_PoolEntriesMapper(); $deletepoolentriesmapper->delete($deletepoolentries); echo "ok"; } -# echo "ready"; $this->_redirect('/pool'); } diff --git a/application/controllers/SessionController.php b/application/controllers/SessionController.php index fc3b962..09eadc9 100644 --- a/application/controllers/SessionController.php +++ b/application/controllers/SessionController.php @@ -16,15 +16,32 @@ class SessionController extends Zend_Controller_Action 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(); + if (!isset($_POST["add"])){ - $createsession = new Application_Form_Session(); + $createsession = new Application_Form_Session(array('clients'=>$clients,'bootos'=>$bootos,'bootisos'=>$bootisos)); $this->view->createsession = $createsession; }else { - $createsession = new Application_Form_Session($_POST); + // TODO extend with normal function not only with post + $createsession = new Application_Form_Session(array('clients'=>$clients,'bootos'=>$bootos,'bootisos'=>$bootisos),$_POST); print_a($_POST); if ($createsession->isValid($_POST)) { try{ $session = new Application_Model_Session($_POST); + $session->setTime(strtotime($_POST['time'])); + if($session->getClientID() == ''){ + $session->setClientID(null); + } + if($session->getBootosID() == ''){ + $session->setBootosID(null); + } $sessionmapper = new Application_Model_SessionMapper(); $sessionmapper->save($session); @@ -34,16 +51,22 @@ class SessionController extends Zend_Controller_Action echo "Error message 2: " . $e->getMessage() . "\n"; } print_a('saved'); - $this->_redirect('/session'); - } - else{ - print_a('not saved'); + #$this->_redirect('/session'); } + $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(); if (!isset($_POST["add"])){ // TODO: ACL implementieren ob er editieren darf $sessionID = $this->_request->getParam('sessionID'); @@ -51,10 +74,11 @@ class SessionController extends Zend_Controller_Action $sessionmapper = new Application_Model_SessionMapper(); - $sessionmapper->find($sessionID,$session); + $sessionmapper->find($sessionID,$session); + $session->setTime(date('d.m.Y H:i',$session->getTime())); $session2 = $session->toArray(); - $editsession = new Application_Form_Session(); + $editsession = new Application_Form_Session(array('clients'=>$clients,'bootos'=>$bootos,'bootisos'=>$bootisos)); $editsession->populate($session2); $this->view->editsession = $editsession; @@ -62,11 +86,18 @@ class SessionController extends Zend_Controller_Action try{ $sessionID = $this->_request->getParam('sessionID'); - $editsession = new Application_Form_Session($_POST); + $editsession = new Application_Form_Session(array('clients'=>$clients,'bootos'=>$bootos,'bootisos'=>$bootisos),$_POST); if ($editsession->isValid($_POST)) { $session = new Application_Model_Session($_POST); - $session->setID($this->_request->getParam('sessionID')); + $session->setID($this->_request->getParam('sessionID')); + $session->setTime(strtotime($_POST['time'])); + if($session->getClientID() == ''){ + $session->setClientID(null); + } + if($session->getBootosID() == ''){ + $session->setBootosID(null); + } $sessionmapper = new Application_Model_SessionMapper(); $sessionmapper->save($session); echo 'valid'; |
