diff options
author | Sebastian Schmelzer | 2012-01-11 14:36:35 +0100 |
---|---|---|
committer | Sebastian Schmelzer | 2012-01-11 14:36:35 +0100 |
commit | fca04a6dab252eb9e8c0a92ce3b7e14b32e68d1e (patch) | |
tree | 6e6aaf749f34db8c7c7153c23ef85c57187430bb /library | |
parent | API: mit addBootos kann man nun auch editieren (diff) | |
download | pbs2-fca04a6dab252eb9e8c0a92ce3b7e14b32e68d1e.tar.gz pbs2-fca04a6dab252eb9e8c0a92ce3b7e14b32e68d1e.tar.xz pbs2-fca04a6dab252eb9e8c0a92ce3b7e14b32e68d1e.zip |
format source files
Diffstat (limited to 'library')
-rw-r--r-- | library/Pbs/Acl.php | 81 | ||||
-rw-r--r-- | library/Pbs/Controller/Plugin/Modularlayout.php | 48 | ||||
-rw-r--r-- | library/Pbs/Debug.php | 22 | ||||
-rw-r--r-- | library/Pbs/Filter.php | 886 | ||||
-rw-r--r-- | library/Pbs/Graph.php | 269 | ||||
-rw-r--r-- | library/Pbs/NewConfig.php | 114 | ||||
-rw-r--r-- | library/Pbs/NewMember.php | 122 | ||||
-rw-r--r-- | library/Pbs/Notifier.php | 326 | ||||
-rw-r--r-- | library/Pbs/Pagination.php | 168 | ||||
-rw-r--r-- | library/Pbs/Search.php | 310 | ||||
-rw-r--r-- | library/Pbs/Session.php | 70 |
11 files changed, 1195 insertions, 1221 deletions
diff --git a/library/Pbs/Acl.php b/library/Pbs/Acl.php index 766274a..a4b6e48 100644 --- a/library/Pbs/Acl.php +++ b/library/Pbs/Acl.php @@ -1,4 +1,4 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg * This program is free software distributed under the GPL version 2. @@ -10,45 +10,44 @@ * General information about OpenSLX can be found at http://openslx.org/ */ -class Pbs_Acl -{ - - public static function checkRight($rightShortcut) { - - $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); - if(!isset($userIDsNamespace['roleID'])) - return false; - $roleID = $userIDsNamespace['roleID']; - - $rightMapper = new Application_Model_RightMapper(); - $element = $rightMapper->findBy(array('shortcut' => $rightShortcut),true); - - if($element == null) - return false; - - $rightRolesMapper = new Application_Model_RightRolesMapper(); - $rightroles = $rightRolesMapper->findBy(array('roleID' => $roleID, 'rightID' => $element[0]['rightID']),true); - - if($rightroles != null) - return true; - - return false; - - } - - public static function checkRightByMembershipID($membershipID, $rightShortcut) { - $membershipMapper = new Application_Model_MembershipMapper(); - $membership = $membershipMapper->find($membershipID); - $rightRolesMapper = new Application_Model_RightRolesMapper(); - $rightroles = $rightRolesMapper->findBy(array('roleID' => $membership->getRoleID()),true); - $rightMapper = new Application_Model_RightMapper(); - foreach($rightroles as $rightrole) { - $right = $rightMapper->find($rightrole['rightID']); - if($right->getShortcut == $rightShortcut) { - return true; - } - } - return false; - } +class Pbs_Acl { + + public static function checkRight($rightShortcut) { + + $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); + if(!isset($userIDsNamespace['roleID'])) + { return false; } + $roleID = $userIDsNamespace['roleID']; + + $rightMapper = new Application_Model_RightMapper(); + $element = $rightMapper->findBy(array('shortcut' => $rightShortcut), true); + + if($element == null) + { return false; } + + $rightRolesMapper = new Application_Model_RightRolesMapper(); + $rightroles = $rightRolesMapper->findBy(array('roleID' => $roleID, 'rightID' => $element[0]['rightID']), true); + + if($rightroles != null) + { return true; } + + return false; + + } + + public static function checkRightByMembershipID($membershipID, $rightShortcut) { + $membershipMapper = new Application_Model_MembershipMapper(); + $membership = $membershipMapper->find($membershipID); + $rightRolesMapper = new Application_Model_RightRolesMapper(); + $rightroles = $rightRolesMapper->findBy(array('roleID' => $membership->getRoleID()), true); + $rightMapper = new Application_Model_RightMapper(); + foreach($rightroles as $rightrole) { + $right = $rightMapper->find($rightrole['rightID']); + if($right->getShortcut == $rightShortcut) { + return true; + } + } + return false; + } } diff --git a/library/Pbs/Controller/Plugin/Modularlayout.php b/library/Pbs/Controller/Plugin/Modularlayout.php index fdde67c..69b0087 100644 --- a/library/Pbs/Controller/Plugin/Modularlayout.php +++ b/library/Pbs/Controller/Plugin/Modularlayout.php @@ -1,4 +1,4 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg * This program is free software distributed under the GPL version 2. @@ -10,30 +10,28 @@ * General information about OpenSLX can be found at http://openslx.org/ */ -class Pbs_Controller_Plugin_Modularlayout extends Zend_Controller_Plugin_Abstract -{ - - public function routeShutdown(Zend_Controller_Request_Abstract $request) - { - $config = Zend_Controller_Front::getInstance() - ->getParam('bootstrap')->getOptions(); - $moduleName = $request->getModuleName(); - if($moduleName == 'default'){ - $path = $config['resources']['layout']['layoutPath']; - $file = $config['resources']['layout']['layout']; - Zend_Layout::getMvcInstance()->setLayoutPath($path/*. DIRECTORY_SEPARATOR .$layoutPath*/); - Zend_Layout::getMvcInstance()->setLayout($file); - } - if (isset($config[$moduleName]['resources']['layout']['layoutPath']) && $moduleName != 'default') { - $layoutPath = $config[$moduleName]['resources']['layout']['layoutPath']; - $moduleDir = Zend_Controller_Front::getInstance()->getModuleDirectory(); - $moduleDir .= "/layouts"; - $layoutScript = $config[$moduleName]['resources']['layout']['layout']; - $str = $moduleDir."/".$layoutScript; - Zend_Layout::getMvcInstance()->setLayoutPath($moduleDir/*. DIRECTORY_SEPARATOR .$layoutPath*/); - Zend_Layout::getMvcInstance()->setLayout($layoutScript); - - } +class Pbs_Controller_Plugin_Modularlayout extends Zend_Controller_Plugin_Abstract { + + public function routeShutdown(Zend_Controller_Request_Abstract $request) { + $config = Zend_Controller_Front::getInstance() + ->getParam('bootstrap')->getOptions(); + $moduleName = $request->getModuleName(); + if($moduleName == 'default') { + $path = $config['resources']['layout']['layoutPath']; + $file = $config['resources']['layout']['layout']; + Zend_Layout::getMvcInstance()->setLayoutPath($path/*. DIRECTORY_SEPARATOR .$layoutPath*/); + Zend_Layout::getMvcInstance()->setLayout($file); + } + if (isset($config[$moduleName]['resources']['layout']['layoutPath']) && $moduleName != 'default') { + $layoutPath = $config[$moduleName]['resources']['layout']['layoutPath']; + $moduleDir = Zend_Controller_Front::getInstance()->getModuleDirectory(); + $moduleDir . = "/layouts"; + $layoutScript = $config[$moduleName]['resources']['layout']['layout']; + $str = $moduleDir."/".$layoutScript; + Zend_Layout::getMvcInstance()->setLayoutPath($moduleDir/*. DIRECTORY_SEPARATOR .$layoutPath*/); + Zend_Layout::getMvcInstance()->setLayout($layoutScript); + } + } } diff --git a/library/Pbs/Debug.php b/library/Pbs/Debug.php index c2031a1..8610ede 100644 --- a/library/Pbs/Debug.php +++ b/library/Pbs/Debug.php @@ -1,4 +1,4 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg * This program is free software distributed under the GPL version 2. @@ -9,15 +9,15 @@ * * General information about OpenSLX can be found at http://openslx.org/ */ -class Pbs_Debug{ +class Pbs_Debug { - function debug($str){ - $path = "../resources/debugs/"; - @mkdir($path ,0777, true); - $fp = fopen($path.'lastsession.txt', "a"); - if(is_array($str)) - $str = implode("\t",$str); - fputs ($fp,date("Y-m-d H:i:s",time())."\t".$str."\n"); - fclose ($fp); - } + function debug($str) { + $path = "../resources/debugs/"; + @mkdir($path , 0777, true); + $fp = fopen($path.'lastsession.txt', "a"); + if(is_array($str)) + { $str = implode("\t", $str); } + fputs ($fp, date("Y-m-d H:i:s", time())."\t".$str."\n"); + fclose ($fp); + } } diff --git a/library/Pbs/Filter.php b/library/Pbs/Filter.php index ced0607..c8119ed 100644 --- a/library/Pbs/Filter.php +++ b/library/Pbs/Filter.php @@ -1,456 +1,438 @@ -<?php - -class Pbs_Filter{ - - private $db = null; - private $membership; - - public function evaluate() - { - $this->db = Zend_Db_Table::getDefaultAdapter(); - $db = $this->db; - $debuglevel = 0; - - $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); - - $membershipMapper = new Application_Model_MembershipMapper(); - $this->membership = new Application_Model_Membership(); - if(isset($userIDsNamespace['membershipID'])){ - $membershipMapper->find($userIDsNamespace['membershipID'],$this->membership); - } - else{ - $this->membership->setID(null); - } - - // 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{ - $set = array(); - - $session = new Application_Model_Session(); - $sessionmapper = new Application_Model_SessionMapper(); - $sessionarray = $sessionmapper->findBy(array('alphasessionID' => $_SESSION['alphasessionID']),true); - $session->setOptions($sessionarray[0]); - $session->setID($sessionarray['sessionID']); - - if(!isset($userIDsNamespace['membershipID'])){ - $bootisoMapper = new Application_Model_BootIsoMapper(); - $bootiso = new Application_Model_BootIso(); - $bootisoMapper->find($session->getBootisoID(),$bootiso); - $groupID = $bootiso->getGroupID(); - }else{ - $groupID = $userIDsNamespace['groupID']; - } - - ######################################################### - // 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)); - $stmt = $db->query("SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE - fe.filtertypeID = ".$filtertypID." AND - REPLACE(fe.filtervalue,'.','') <= '".$ipAdress."' AND - '".$ipAdress."' <= REPLACE(fe.filtervalue2,'.','') AND - fe.filterID = f.filterID AND - f.groupID = '".$groupID."'"); - - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; - } - - if($debuglevel >= 3 ) - 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 fe, pbs_filter f WHERE - fe.filtertypeID = ".$filtertypID." AND - fe.filtervalue <= '".$macAdress."' AND - '".$macAdress."' <= fe.filtervalue2 AND - fe.filterID = f.filterID AND - f.groupID = '".$groupID."'"); - - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; - } - } - catch(Exception $e){} - if($debuglevel >= 3) - 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 fe, pbs_filter f WHERE - fe.filtertypeID = ".$filtertypID." AND - fe.filtervalue = ".$poolID." AND - fe.filterID = f.filterID AND - f.groupID = '".$groupID."'"); - $result = $stmt->fetchAll(); - if(count($result)>0){ - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; - } - } - } - catch(Exception $e){} - - if($debuglevel >= 3) - 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 fe, pbs_filter f WHERE - fe.filtertypeID = ".$filtertypID." AND - fe.filtervalue = ".$clientID." AND - fe.filterID = f.filterID AND - f.groupID = '".$groupID."'"); - - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; - } - } - catch(Exception $e){} - - if($debuglevel >= 3) - 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 fe, pbs_filter f WHERE - fe.filtertypeID = ".$filtertypID." AND - fe.filtervalue = ".$bootisoID." AND - fe.filterID = f.filterID AND - f.groupID = '".$groupID."'"); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; - } - } - catch(Exception $e){} - - if($debuglevel >= 3) - print_a('bootisoID',$result,$set[$filtertypID]); - ######################################################### - // MembershipID - $filtertypID = 5; - if($this->membership->getID() != null){ - if(!$testFilter){ - // get membership from the session - //TODO: GET MEMBERSHIP from SESSION - $membershipID = $this->membership->getID(); - } - try{ - $stmt = $db->query("SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE - fe.filtertypeID = ".$filtertypID." AND - fe.filtervalue = ".$membershipID." AND - fe.filterID = f.filterID AND - f.groupID = '".$groupID."'"); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; - } - } - catch(Exception $e){} - - if($debuglevel >= 3) - print_a('membership',$result,$set[$filtertypID]); - } - ######################################################### - // GroupID - $filtertypID = 6; - if($this->membership->getID() != null){ - if(!$testFilter){ - // get membership from the session - $membergroupID = $this->membership->getGroupID(); - } - } - - if(isset($membergroupID)){ - try{ - $stmt = $db->query("SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE - fe.filtertypeID = ".$filtertypID." AND - fe.filtervalue = ".$membergroupID." AND - fe.filterID = f.filterID AND - f.groupID = '".$groupID."'"); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; - } - } - catch(Exception $e){} - - if($debuglevel >= 3) - print_a('groupID',$result,$set[$filtertypID]); - } - ######################################################### - // Time - $filtertypID = 7; - if(!$testFilter){ - $nowShort = date("H:i"); - } - else{ - $nowShort = date("H:i",$time); - } - - $nowShort = str_replace(":","",$nowShort); - try{ - - $stmt = $db->query('SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE - fe.filtertypeID = '.$filtertypID.' AND - REPLACE(fe.filtervalue,":","") <= '.$nowShort.' AND - REPLACE(fe.filtervalue2,":","") >= '.$nowShort." AND - fe.filterID = f.filterID AND - f.groupID = '".$groupID."'"); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; - } - } - catch(Exception $e){} - - if($debuglevel >= 3) - print_a('time',$result,$set[$filtertypID]); - ######################################################### - // Hardwarehash - $filtertypID = 9; - if(!$testFilter){ - // get hardwarehash from session - $client = new Application_Model_Client(); - $clientmapper = new Application_Model_ClientMapper(); - $clientmapper->find($session->getClientID(),$client); - $hardwarehash = $client->getHardwarehash(); - } - - try{ - $stmt = $db->query("SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE - fe.filtertypeID = ".$filtertypID." AND - fe.filtervalue = ".$hardwarehash." AND - fe.filterID = f.filterID AND - f.groupID = '".$groupID."'"); - $result = $stmt->fetchAll(); - - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; - } - } - catch(Exception $e){} - - if($debuglevel >= 3) - print_a('hardwarehash',$result,$set[$filtertypID]); - ######################################################### - // weekday - $filtertypID = 10; - if(!$testFilter){ - $weekday = date('N'); - } - - try{ - $stmt = $db->query("SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE - fe.filtertypeID = ".$filtertypID." AND - fe.filtervalue <= ".$weekday." AND - ".$weekday." <= fe.filtervalue2 AND - fe.filterID = f.filterID AND - f.groupID = '".$groupID."'"); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; - } - } - catch(Exception $e){} - - if($debuglevel >= 3) - print_a('weekday',$result,$set[$filtertypID]); - ######################################################### - // date - $filtertypID = 11; - if(!$testFilter){ - $date = strtotime(date('d.m.Y')); - } - - try{ - $stmt = $db->query("SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE - fe.filtertypeID = ".$filtertypID." AND - fe.filtervalue <= ".$date." AND - ".$date." <= fe.filtervalue2 AND - fe.filterID = f.filterID AND - f.groupID = '".$groupID."'"); - $result = $stmt->fetchAll(); - foreach($result as $r){ - $set[$filtertypID][] = $r['filterID']; - } - } - catch(Exception $e){} - - if($debuglevel >= 3) - print_a('date',$result,$set[$filtertypID],$date); - ######################################## - $result = array(); - // ErgebnisSet auswerten - if($debuglevel >= 2) - 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; - } - if($debuglevel >= 2) - print_a('Übereinstimmungen pro Filter',$a); - // Get the number of filtertypes every filter has - $stmt = $db->query( - "SELECT f.filterID,SUM(num) as num FROM ( - SELECT *, '1' as num - FROM pbs_filterentries - GROUP BY filterID, filtertypeID - ) d RIGHT OUTER JOIN pbs_filter f ON d.filterID = f.filterID - WHERE groupID = '".$groupID."' GROUP BY d.filterID"); - $resultset = $stmt->fetchAll(); - foreach($resultset as $d){ - if($d['num'] == NULL){ - $d['num'] = 0; - // write filter with empty filterrules in resultset - $result[] = $d['filterID']; - } - - $database[$d['filterID']] = $d['num']; - } - if($debuglevel >= 2) - print_a('Anzahl Filterentries in Datenbank',$database); - - // remove all filters from resultset, which to few filtertypes satisfied - - foreach($a as $i=>$b){ - if($a[$i] < $database[$i]){ - unset($a[$i]); - } - else{ - $result[] = $i; - } - } - if($debuglevel >= 1) - print_a('Valid 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); - return $bootmenuID; - } - else{ - return null; - } - - }catch (Zend_Exception $e) { - echo "class: ".get_class($e)."<br>\n"; - 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); +<? php + +class Pbs_Filter { + + private $db = null; + private $membership; + + public function evaluate() { + $this->db = Zend_Db_Table::getDefaultAdapter(); + $db = $this->db; + $debuglevel = 0; + + $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); + + $membershipMapper = new Application_Model_MembershipMapper(); + $this->membership = new Application_Model_Membership(); + if(isset($userIDsNamespace['membershipID'])) { + $membershipMapper->find($userIDsNamespace['membershipID'], $this->membership); + } else { + $this->membership->setID(null); + } + + // 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 { + $set = array(); + + $session = new Application_Model_Session(); + $sessionmapper = new Application_Model_SessionMapper(); + $sessionarray = $sessionmapper->findBy(array('alphasessionID' => $_SESSION['alphasessionID']), true); + $session->setOptions($sessionarray[0]); + $session->setID($sessionarray['sessionID']); + + if(!isset($userIDsNamespace['membershipID'])) { + $bootisoMapper = new Application_Model_BootIsoMapper(); + $bootiso = new Application_Model_BootIso(); + $bootisoMapper->find($session->getBootisoID(), $bootiso); + $groupID = $bootiso->getGroupID(); + } else { + $groupID = $userIDsNamespace['groupID']; + } + +######################################################### + // 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)); + $stmt = $db->query("SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE + fe.filtertypeID = ".$filtertypID." AND + REPLACE(fe.filtervalue,'.','') <= '".$ipAdress."' AND + '".$ipAdress."' <= REPLACE(fe.filtervalue2,'.','') AND + fe.filterID = f.filterID AND + f.groupID = '".$groupID."'"); + + $result = $stmt->fetchAll(); + foreach($result as $r) { + $set[$filtertypID][] = $r['filterID']; + } + + if($debuglevel >= 3 ) + { 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 fe, pbs_filter f WHERE + fe.filtertypeID = ".$filtertypID." AND + fe.filtervalue <= '".$macAdress."' AND + '".$macAdress."' <= fe.filtervalue2 AND + fe.filterID = f.filterID AND + f.groupID = '".$groupID."'"); + + $result = $stmt->fetchAll(); + foreach($result as $r) { + $set[$filtertypID][] = $r['filterID']; + } + } catch(Exception $e) {} + if($debuglevel >= 3) + { 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 fe, pbs_filter f WHERE + fe.filtertypeID = ".$filtertypID." AND + fe.filtervalue = ".$poolID." AND + fe.filterID = f.filterID AND + f.groupID = '".$groupID."'"); + $result = $stmt->fetchAll(); + if(count($result) > 0) { + foreach($result as $r) { + $set[$filtertypID][] = $r['filterID']; + } + } + } catch(Exception $e) {} + + if($debuglevel >= 3) + { 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 fe, pbs_filter f WHERE + fe.filtertypeID = ".$filtertypID." AND + fe.filtervalue = ".$clientID." AND + fe.filterID = f.filterID AND + f.groupID = '".$groupID."'"); + + $result = $stmt->fetchAll(); + foreach($result as $r) { + $set[$filtertypID][] = $r['filterID']; + } + } catch(Exception $e) {} + + if($debuglevel >= 3) + { 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 fe, pbs_filter f WHERE + fe.filtertypeID = ".$filtertypID." AND + fe.filtervalue = ".$bootisoID." AND + fe.filterID = f.filterID AND + f.groupID = '".$groupID."'"); + $result = $stmt->fetchAll(); + foreach($result as $r) { + $set[$filtertypID][] = $r['filterID']; + } + } catch(Exception $e) {} + + if($debuglevel >= 3) + { print_a('bootisoID', $result, $set[$filtertypID]); } +######################################################### + // MembershipID + $filtertypID = 5; + if($this->membership->getID() != null) { + if(!$testFilter) { + // get membership from the session + //TODO: GET MEMBERSHIP from SESSION + $membershipID = $this->membership->getID(); + } + try { + $stmt = $db->query("SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE + fe.filtertypeID = ".$filtertypID." AND + fe.filtervalue = ".$membershipID." AND + fe.filterID = f.filterID AND + f.groupID = '".$groupID."'"); + $result = $stmt->fetchAll(); + foreach($result as $r) { + $set[$filtertypID][] = $r['filterID']; + } + } catch(Exception $e) {} + + if($debuglevel >= 3) + { print_a('membership', $result, $set[$filtertypID]); } + } +######################################################### + // GroupID + $filtertypID = 6; + if($this->membership->getID() != null) { + if(!$testFilter) { + // get membership from the session + $membergroupID = $this->membership->getGroupID(); + } + } + + if(isset($membergroupID)) { + try { + $stmt = $db->query("SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE + fe.filtertypeID = ".$filtertypID." AND + fe.filtervalue = ".$membergroupID." AND + fe.filterID = f.filterID AND + f.groupID = '".$groupID."'"); + $result = $stmt->fetchAll(); + foreach($result as $r) { + $set[$filtertypID][] = $r['filterID']; + } + } catch(Exception $e) {} + + if($debuglevel >= 3) + { print_a('groupID', $result, $set[$filtertypID]); } + } +######################################################### + // Time + $filtertypID = 7; + if(!$testFilter) { + $nowShort = date("H:i"); + } else { + $nowShort = date("H:i", $time); + } + + $nowShort = str_replace(":", "", $nowShort); + try { + + $stmt = $db->query('SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE + fe.filtertypeID = '.$filtertypID.' AND + REPLACE(fe.filtervalue,":","") <= '.$nowShort.' AND + REPLACE(fe.filtervalue2,":","") >= '.$nowShort." AND + fe.filterID = f.filterID AND + f.groupID = '".$groupID."'"); + $result = $stmt->fetchAll(); + foreach($result as $r) { + $set[$filtertypID][] = $r['filterID']; + } + } catch(Exception $e) {} + + if($debuglevel >= 3) + { print_a('time', $result, $set[$filtertypID]); } +######################################################### + // Hardwarehash + $filtertypID = 9; + if(!$testFilter) { + // get hardwarehash from session + $client = new Application_Model_Client(); + $clientmapper = new Application_Model_ClientMapper(); + $clientmapper->find($session->getClientID(), $client); + $hardwarehash = $client->getHardwarehash(); + } + + try { + $stmt = $db->query("SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE + fe.filtertypeID = ".$filtertypID." AND + fe.filtervalue = ".$hardwarehash." AND + fe.filterID = f.filterID AND + f.groupID = '".$groupID."'"); + $result = $stmt->fetchAll(); + + foreach($result as $r) { + $set[$filtertypID][] = $r['filterID']; + } + } catch(Exception $e) {} + + if($debuglevel >= 3) + { print_a('hardwarehash', $result, $set[$filtertypID]); } +######################################################### + // weekday + $filtertypID = 10; + if(!$testFilter) { + $weekday = date('N'); + } + + try { + $stmt = $db->query("SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE + fe.filtertypeID = ".$filtertypID." AND + fe.filtervalue <= ".$weekday." AND + ".$weekday." <= fe.filtervalue2 AND + fe.filterID = f.filterID AND + f.groupID = '".$groupID."'"); + $result = $stmt->fetchAll(); + foreach($result as $r) { + $set[$filtertypID][] = $r['filterID']; + } + } catch(Exception $e) {} + + if($debuglevel >= 3) + { print_a('weekday', $result, $set[$filtertypID]); } +######################################################### + // date + $filtertypID = 11; + if(!$testFilter) { + $date = strtotime(date('d.m.Y')); + } + + try { + $stmt = $db->query("SELECT * FROM pbs_filterentries fe, pbs_filter f WHERE + fe.filtertypeID = ".$filtertypID." AND + fe.filtervalue <= ".$date." AND + ".$date." <= fe.filtervalue2 AND + fe.filterID = f.filterID AND + f.groupID = '".$groupID."'"); + $result = $stmt->fetchAll(); + foreach($result as $r) { + $set[$filtertypID][] = $r['filterID']; + } + } catch(Exception $e) {} + + if($debuglevel >= 3) + { print_a('date', $result, $set[$filtertypID], $date); } +######################################## + $result = array(); + // ErgebnisSet auswerten + if($debuglevel >= 2) + { 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; + } + if($debuglevel >= 2) + { print_a('Übereinstimmungen pro Filter', $a); } + // Get the number of filtertypes every filter has + $stmt = $db->query( + "SELECT f.filterID,SUM(num) as num FROM ( + SELECT *, '1' as num + FROM pbs_filterentries + GROUP BY filterID, filtertypeID + ) d RIGHT OUTER JOIN pbs_filter f ON d.filterID = f.filterID + WHERE groupID = '".$groupID."' GROUP BY d.filterID"); + $resultset = $stmt->fetchAll(); + foreach($resultset as $d) { + if($d['num'] == NULL) { + $d['num'] = 0; + // write filter with empty filterrules in resultset + $result[] = $d['filterID']; + } + + $database[$d['filterID']] = $d['num']; + } + if($debuglevel >= 2) + { print_a('Anzahl Filterentries in Datenbank', $database); } + + // remove all filters from resultset, which to few filtertypes satisfied + + foreach($a as $i => $b) { + if($a[$i] < $database[$i]) { + unset($a[$i]); + } else { + $result[] = $i; + } + } + if($debuglevel >= 1) + { print_a('Valid 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); + return $bootmenuID; + } else { + return null; + } + + } catch (Zend_Exception $e) { + echo "class: ".get_class($e)."<br>\n"; + echo "Error message 2: " . $e->getMessage() . "\n"; + } + } + private function fillIP($ip) { + $ar = explode(".", $ip); + $representation = array(); + foreach($ar as $part) { + $representation[] = sprintf("%03s", $part); } + return implode(".", $representation); + } - private function fillMac($ip) - { - $ar = explode(":",$ip); - $representation = array(); - foreach($ar as $part){ - $representation[] = sprintf("%02s",$part); - } - return implode(":",$representation); + private function fillMac($ip) { + $ar = explode(":", $ip); + $representation = array(); + foreach($ar as $part) { + $representation[] = sprintf("%02s", $part); } + return implode(":", $representation); + } } -?> +? > diff --git a/library/Pbs/Graph.php b/library/Pbs/Graph.php index f9b236a..a37af35 100644 --- a/library/Pbs/Graph.php +++ b/library/Pbs/Graph.php @@ -1,4 +1,4 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg * This program is free software distributed under the GPL version 2. @@ -10,138 +10,137 @@ * General information about OpenSLX can be found at http://openslx.org/ */ -class Pbs_Graph{ - - private $db = null; - private $membership; - private $graphstring; - private $level; - private $edges; - private $crawledNodes; - private $childs = array(); - - public function graph($groupID) - { - $this->db = Zend_Db_Table::getDefaultAdapter(); - $db = $this->db; - - - $path = "../resources/groupgraphs/"; - @mkdir($path ,0777, true); - - $this->graphstring = 'digraph groups { - size="7,5"; - pad=0.1; - graph[ bgcolor=transparent ]; - node [ style=filled fillcolor="#ffffffff" ];'; - if($this->level <0) - $this->graphstring .= '"'.$this->getGroupTitle($groupID).'"'; - else - $this->graphstring .= '"'.$this->getGroupTitle($groupID).'" [ fontcolor="#ffffffff", style=filled, fillcolor="#004A99FF"];'; - - if(count($this->childs) >=1){ - foreach($this->childs as $childID){ - $this->edges[$groupID][$childID] = 1; - $this->graphstring .= '"'.$this->getGroupTitle($groupID).'" -> "'.$this->getGroupTitle($childID).'";'."\n"; - $this->getChildGroups($childID); - } - } - $this->getParentGroups($groupID); - $this->getChildGroups($groupID); - $this->graphstring .= '}'; - - // for debugging - # $fp = fopen($path.'thisgraph.dot', "w"); - # fputs ($fp, $this->graphstring); - # fclose ($fp); - - - $this->graphstring = str_replace(array("\t","\n"),"",$this->graphstring); - $this->graphstring = str_replace('"','\"',$this->graphstring); - - $md5 = md5($this->graphstring); - $path = "../resources/groupgraphs/"; - @mkdir($path ,0777, true); - - // randomly delete cached files, old files are not needed - // so delete it sometimes - if(rand(0,20) == 1){ - $days = "14"; // delete all files older than this many days - $seconds = ($days*24*60*60); - - $files = scandir($path); - foreach ($files as $num => $fname){ - if (file_exists("{$path}{$fname}") && ((time() - filemtime("{$path}{$fname}")) > $seconds)) { - $mod_time = filemtime("{$path}{$fname}"); - unlink("{$path}{$fname}"); - } - } - } - - if(!file_exists($path.$md5.".png")){ - $str = 'echo "'; - $str .= $this->graphstring; - $str .= '" | dot -Tpng >'.$path.$md5.".png"; - exec($str); - } - - passthru("cat ".$path.$md5.".png", $result); - return $result; - } - private function getGroupTitle($groupID){ - $group = new Application_Model_Group(); - $groupmapper = new Application_Model_GroupMapper(); - $groupmapper->find($groupID,$group); - return $group->getTitle(); - } - public function newChild($id){ - $this->childs[] = $id; - } - - private function getParentGroups($groupID, $level=1) { - if($this->crawledNodes['parent'][$groupID] == 1) - return; - $this->crawledNodes['parent'][$groupID] = 1; - $db = Zend_Db_Table::getDefaultAdapter(); - $query = 'SELECT parentID FROM pbs_groupgroups WHERE groupID="'.$groupID.'"'; - $stmt = $db->query($query); - $result = $stmt->fetchAll(); - foreach($result as $row){ - // save the current groupID in level-list - #$data[$level][] = $row['parentID']; - if($this->edges[$row['parentID']][$groupID] != 1){ - $this->graphstring .= '"'.$this->getGroupTitle($row['parentID']).'" -> "'.$this->getGroupTitle($groupID).'";'."\n"; - $this->edges[$row['parentID']][$groupID] = 1; - } - // get the function recursive an increase the level - $this->getParentGroups($row['parentID'], $level+1); - } - } - - // Gets all childs-groups from a given group - private function getChildGroups($groupID, $level=1) { - if(@$this->crawledNodes['child'][$groupID] == 1) - return; - $this->crawledNodes['child'][$groupID] = 1; - $db = Zend_Db_Table::getDefaultAdapter(); - $query = 'SELECT groupID FROM pbs_groupgroups WHERE parentID="'.$groupID.'"'; - $stmt = $db->query($query); - $result = $stmt->fetchAll(); - foreach($result as $row){ - // save the current groupID in level-list - #$data[$level][] = $row['groupID']; - if(@$this->edges[$groupID][$row['groupID']] != 1){ - $this->graphstring .= '"'.$this->getGroupTitle($groupID).'" -> "'.$this->getGroupTitle($row['groupID']).'";'."\n"; - $this->edges[$groupID][$row['groupID']] = 1; - } - if($this->level >= $level){ - $this->graphstring .= '"'.$this->getGroupTitle($row['groupID']).'"'.' [ fontcolor="#ffffffff", style=filled, fillcolor="#004A99FF"];'."\n"; - } - // get the function recursive an increase the level - $this->getChildGroups($row['groupID'], $level+1); - } - } - public function setHiglightLevel($i){ - $this->level = $i; - } +class Pbs_Graph { + + private $db = null; + private $membership; + private $graphstring; + private $level; + private $edges; + private $crawledNodes; + private $childs = array(); + + public function graph($groupID) { + $this->db = Zend_Db_Table::getDefaultAdapter(); + $db = $this->db; + + + $path = "../resources/groupgraphs/"; + @mkdir($path , 0777, true); + + $this->graphstring = 'digraph groups { + size="7,5"; + pad=0.1; + graph[ bgcolor=transparent ]; + node [ style=filled fillcolor="#ffffffff" ];'; + if($this->level < 0) + { $this->graphstring . = '"'.$this->getGroupTitle($groupID).'"'; } + else + { $this->graphstring . = '"'.$this->getGroupTitle($groupID).'" [ fontcolor="#ffffffff", style=filled, fillcolor="#004A99FF"];'; } + + if(count($this->childs) >= 1) { + foreach($this->childs as $childID) { + $this->edges[$groupID][$childID] = 1; + $this->graphstring . = '"'.$this->getGroupTitle($groupID).'" -> "'.$this->getGroupTitle($childID).'";'."\n"; + $this->getChildGroups($childID); + } + } + $this->getParentGroups($groupID); + $this->getChildGroups($groupID); + $this->graphstring . = '}'; + + // for debugging +# $fp = fopen($path.'thisgraph.dot', "w"); +# fputs ($fp, $this->graphstring); +# fclose ($fp); + + + $this->graphstring = str_replace(array("\t", "\n"), "", $this->graphstring); + $this->graphstring = str_replace('"', '\"', $this->graphstring); + + $md5 = md5($this->graphstring); + $path = "../resources/groupgraphs/"; + @mkdir($path , 0777, true); + + // randomly delete cached files, old files are not needed + // so delete it sometimes + if(rand(0, 20) == 1) { + $days = "14"; // delete all files older than this many days + $seconds = ($days * 24 * 60 * 60); + + $files = scandir($path); + foreach ($files as $num => $fname) { + if (file_exists("{$path}{$fname}") && ((time() - filemtime("{$path}{$fname}")) > $seconds)) { + $mod_time = filemtime("{$path}{$fname}"); + unlink("{$path}{$fname}"); + } + } + } + + if(!file_exists($path.$md5.".png")) { + $str = 'echo "'; + $str . = $this->graphstring; + $str . = '" | dot -Tpng >'.$path.$md5.".png"; + exec($str); + } + + passthru("cat ".$path.$md5.".png", $result); + return $result; + } + private function getGroupTitle($groupID) { + $group = new Application_Model_Group(); + $groupmapper = new Application_Model_GroupMapper(); + $groupmapper->find($groupID, $group); + return $group->getTitle(); + } + public function newChild($id) { + $this->childs[] = $id; + } + + private function getParentGroups($groupID, $level = 1) { + if($this->crawledNodes['parent'][$groupID] == 1) + { return; } + $this->crawledNodes['parent'][$groupID] = 1; + $db = Zend_Db_Table::getDefaultAdapter(); + $query = 'SELECT parentID FROM pbs_groupgroups WHERE groupID="'.$groupID.'"'; + $stmt = $db->query($query); + $result = $stmt->fetchAll(); + foreach($result as $row) { + // save the current groupID in level-list +#$data[$level][] = $row['parentID']; + if($this->edges[$row['parentID']][$groupID] != 1) { + $this->graphstring . = '"'.$this->getGroupTitle($row['parentID']).'" -> "'.$this->getGroupTitle($groupID).'";'."\n"; + $this->edges[$row['parentID']][$groupID] = 1; + } + // get the function recursive an increase the level + $this->getParentGroups($row['parentID'], $level + 1); + } + } + + // Gets all childs-groups from a given group + private function getChildGroups($groupID, $level = 1) { + if(@$this->crawledNodes['child'][$groupID] == 1) + { return; } + $this->crawledNodes['child'][$groupID] = 1; + $db = Zend_Db_Table::getDefaultAdapter(); + $query = 'SELECT groupID FROM pbs_groupgroups WHERE parentID="'.$groupID.'"'; + $stmt = $db->query($query); + $result = $stmt->fetchAll(); + foreach($result as $row) { + // save the current groupID in level-list +#$data[$level][] = $row['groupID']; + if(@$this->edges[$groupID][$row['groupID']] != 1) { + $this->graphstring . = '"'.$this->getGroupTitle($groupID).'" -> "'.$this->getGroupTitle($row['groupID']).'";'."\n"; + $this->edges[$groupID][$row['groupID']] = 1; + } + if($this->level >= $level) { + $this->graphstring . = '"'.$this->getGroupTitle($row['groupID']).'"'.' [ fontcolor="#ffffffff", style=filled, fillcolor="#004A99FF"];'."\n"; + } + // get the function recursive an increase the level + $this->getChildGroups($row['groupID'], $level + 1); + } + } + public function setHiglightLevel($i) { + $this->level = $i; + } } diff --git a/library/Pbs/NewConfig.php b/library/Pbs/NewConfig.php index 2101bf9..7a832a1 100644 --- a/library/Pbs/NewConfig.php +++ b/library/Pbs/NewConfig.php @@ -1,4 +1,4 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg * This program is free software distributed under the GPL version 2. @@ -10,61 +10,61 @@ * General information about OpenSLX can be found at http://openslx.org/ */ -class Pbs_NewConfig{ - - public function createDefaultConfig(Application_Model_BootOs $bootos){ - - if($bootos == null) - return; - - $config = new Application_Model_Config(); - $configMapper = new Application_Model_ConfigMapper(); - $bootosuser = new Application_Model_BootOsUser(); - $bootosuserkiosk = new Application_Model_BootOsUser(); - $bootosuserMapper = new Application_Model_BootOsUserMapper(); - - try{ - - $config->setTitle('Default') - ->setDescription('This is the default Config for Bootos: '.$bootos->getTitle()) - ->setGroupID($bootos->getGroupID()) - ->setVisible('1') - ->setCreated(time()) - ->setBootosID($bootos->getID()); - - $configID = $configMapper->save($config); - - $bootosuser->setConfigID($configID) - ->setLogin('%username%') - ->setPassword('%password%') - ->setHomepath('/home/%username%') - ->setHometypeID('0'); - - $bootosuserMapper->save($bootosuser); - - $bootosuserkiosk->setConfigID($configID) - ->setLogin('kiosk') - ->setPassword(crypt('kiosk', '$6$'.randomString(8).'$')) - ->setHomepath('/home/kiosk') - ->setHometypeID('0'); - - $bootosuserMapper->save($bootosuserkiosk); - - }catch(Zend_Exception $e){ - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - return; - } - - - - } - - public function parseConfig($bootosID){ - $configpath = "../resources/bootos/".$bootosID."/config/"; - //Do something... - - } +class Pbs_NewConfig { + + public function createDefaultConfig(Application_Model_BootOs $bootos) { + + if($bootos == null) + { return; } + + $config = new Application_Model_Config(); + $configMapper = new Application_Model_ConfigMapper(); + $bootosuser = new Application_Model_BootOsUser(); + $bootosuserkiosk = new Application_Model_BootOsUser(); + $bootosuserMapper = new Application_Model_BootOsUserMapper(); + + try { + + $config->setTitle('Default') + ->setDescription('This is the default Config for Bootos: '.$bootos->getTitle()) + ->setGroupID($bootos->getGroupID()) + ->setVisible('1') + ->setCreated(time()) + ->setBootosID($bootos->getID()); + + $configID = $configMapper->save($config); + + $bootosuser->setConfigID($configID) + ->setLogin('%username%') + ->setPassword('%password%') + ->setHomepath('/home/%username%') + ->setHometypeID('0'); + + $bootosuserMapper->save($bootosuser); + + $bootosuserkiosk->setConfigID($configID) + ->setLogin('kiosk') + ->setPassword(crypt('kiosk', '$6$'.randomString(8).'$')) + ->setHomepath('/home/kiosk') + ->setHometypeID('0'); + + $bootosuserMapper->save($bootosuserkiosk); + + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + + + + } + + public function parseConfig($bootosID) { + $configpath = "../resources/bootos/".$bootosID."/config/"; + //Do something... + + } } -?> +? > diff --git a/library/Pbs/NewMember.php b/library/Pbs/NewMember.php index 3a1e868..4fe5776 100644 --- a/library/Pbs/NewMember.php +++ b/library/Pbs/NewMember.php @@ -1,4 +1,4 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg * This program is free software distributed under the GPL version 2. @@ -10,66 +10,66 @@ * General information about OpenSLX can be found at http://openslx.org/ */ -class Pbs_NewMember{ +class Pbs_NewMember { - public function createDefaults(Application_Model_Membership $membership){ - $personMapper = new Application_Model_PersonMapper(); - $bootmenuMapper = new Application_Model_BootMenuMapper(); - $bootmenuentriesMapper = new Application_Model_BootMenuEntriesMapper(); - $filterMapper = new Application_Model_FilterMapper(); - $filterentriesMapper = new Application_Model_FilterEntriesMapper(); - - // First we copy the default bootmenu with all the entries - $groupID = $membership->getGroupID(); - $person = $personMapper->find($membership->getPersonID()); - $personname = $person->getFirstName(). " " . $person->getName(); - - $defaultBootmenu = $bootmenuMapper->findBy(array('groupID'=>$groupID, 'defaultbootmenu'=>'1')); - $defaultBootmenu = $defaultBootmenu[0]; - - $userBootmenu = new Application_Model_BootMenu(); - $userBootmenu->setID(null); - $userBootmenu->setGroupID(null); - $userBootmenu->setMembershipID($membership->getID()); - $userBootmenu->setTitle("BootMenu of ".$personname); - $userBootmenu->setStartcounter(300); - $userBootmenu->setCreated(time()); - $userBootmenu->setDefaultbootmenu(0); - $userBootmenuID = $bootmenuMapper->save($userBootmenu); - $userBootmenu->setID($userBootmenuID); - - # print_a('userbootmenu',$userBootmenu); - if($defaultBootmenu != ''){ - $bootmenuentries = $bootmenuentriesMapper->findBy(array('bootmenuID'=>$defaultBootmenu->getID())); - foreach($bootmenuentries as $bme){ - $bme->setID(null); - $bme->setBootmenuID($userBootmenuID); - $bootmenuentriesMapper->save($bme); - #print_a('bootmenuentry',$bme); - } - } - - // Second we create a filter - $filter = new Application_Model_Filter(); - $filter->setTitle("Filter of ".$personname); - $filter->setDescription("This filter was automatically created to forward the user to his own bootmenu"); - $filter->setMembershipID($membership->getID()); - $filter->setGroupID($membership->getGroupID()); - $filter->setBootmenuID($userBootmenuID); - $filter->setCreated(time()); - $filter->setPriority(25); - $filterID = $filterMapper->save($filter); - # print_a('filter',$filter); - - $filterentry = new Application_Model_FilterEntries(); - $filterentry->setFilterID($filterID); - $filterentry->setFiltertypeID(5); - $filterentry->setFiltervalue($membership->getID()); - $filterentriesMapper->save($filterentry); - # print_a('filterentry',$filterentry); - - - } + public function createDefaults(Application_Model_Membership $membership) { + $personMapper = new Application_Model_PersonMapper(); + $bootmenuMapper = new Application_Model_BootMenuMapper(); + $bootmenuentriesMapper = new Application_Model_BootMenuEntriesMapper(); + $filterMapper = new Application_Model_FilterMapper(); + $filterentriesMapper = new Application_Model_FilterEntriesMapper(); + + // First we copy the default bootmenu with all the entries + $groupID = $membership->getGroupID(); + $person = $personMapper->find($membership->getPersonID()); + $personname = $person->getFirstName(). " " . $person->getName(); + + $defaultBootmenu = $bootmenuMapper->findBy(array('groupID' => $groupID, 'defaultbootmenu' => '1')); + $defaultBootmenu = $defaultBootmenu[0]; + + $userBootmenu = new Application_Model_BootMenu(); + $userBootmenu->setID(null); + $userBootmenu->setGroupID(null); + $userBootmenu->setMembershipID($membership->getID()); + $userBootmenu->setTitle("BootMenu of ".$personname); + $userBootmenu->setStartcounter(300); + $userBootmenu->setCreated(time()); + $userBootmenu->setDefaultbootmenu(0); + $userBootmenuID = $bootmenuMapper->save($userBootmenu); + $userBootmenu->setID($userBootmenuID); + +# print_a('userbootmenu',$userBootmenu); + if($defaultBootmenu != '') { + $bootmenuentries = $bootmenuentriesMapper->findBy(array('bootmenuID' => $defaultBootmenu->getID())); + foreach($bootmenuentries as $bme) { + $bme->setID(null); + $bme->setBootmenuID($userBootmenuID); + $bootmenuentriesMapper->save($bme); +#print_a('bootmenuentry',$bme); + } + } + + // Second we create a filter + $filter = new Application_Model_Filter(); + $filter->setTitle("Filter of ".$personname); + $filter->setDescription("This filter was automatically created to forward the user to his own bootmenu"); + $filter->setMembershipID($membership->getID()); + $filter->setGroupID($membership->getGroupID()); + $filter->setBootmenuID($userBootmenuID); + $filter->setCreated(time()); + $filter->setPriority(25); + $filterID = $filterMapper->save($filter); +# print_a('filter',$filter); + + $filterentry = new Application_Model_FilterEntries(); + $filterentry->setFilterID($filterID); + $filterentry->setFiltertypeID(5); + $filterentry->setFiltervalue($membership->getID()); + $filterentriesMapper->save($filterentry); +# print_a('filterentry',$filterentry); + + + } } -?> +? > diff --git a/library/Pbs/Notifier.php b/library/Pbs/Notifier.php index 509d7de..cfe2066 100644 --- a/library/Pbs/Notifier.php +++ b/library/Pbs/Notifier.php @@ -1,4 +1,4 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg * This program is free software distributed under the GPL version 2. @@ -10,169 +10,169 @@ * General information about OpenSLX can be found at http://openslx.org/ */ -class Pbs_Notifier{ +class Pbs_Notifier { - - public function notify($action,$result){ - - switch($action){ - default: - switch($result){ - case "forbidden": - $result = "errorbox"; - break; - case "ok": - $result = "okbox"; - break; - case "error": - $result = "warningbox"; - break; - case "info": - $result = "infobox"; - break; - } - $result = "<div class='$result'>$action</div>"; - break; - case "delete": - switch($result){ - case "forbidden": - $result = "<div class='errorbox'>Not allowed to delete this</div>"; - break; - case "ok": - $result = "<div class='okbox'>Delete sucessful</div>"; - break; - case "error": - $result = "<div class='warningbox'>Delete failed</div>"; - break; - } - break; - case "view": - switch($result){ - case "forbidden": - $result = "<div class='errorbox'>Not allowed to see this</div>"; - break; - } - break; - case "download": - switch($result){ - case "forbidden": - $result = "<div class='errorbox'>Not allowed to download this</div>"; - break; - case "404": - $result = "<div class='errorbox'>The Resource was not found on the Server</div>"; - break; - case "error": - $result = "<div class='errorbox'>Download failed</div>"; - break; - } - break; - case "modify": - switch($result){ - case "forbidden": - $result = "<div class='errorbox'>Not allowed to modify this</div>"; - break; - case "ok": - $result = "<div class='okbox'>Modify sucessful</div>"; - break; - case "error": - $result = "<div class='warningbox'>Modify failed</div>"; - break; - } - break; - case "create": - switch($result){ - case "forbidden": - $result = "<div class='errorbox'>Not allowed to create this</div>"; - break; - case "ok": - $result = "<div class='okbox'>Creation sucessful</div>"; - break; - case "error": - $result = "<div class='warningbox'>Creation failed</div>"; - break; - case "file": - $result = "<div class='errorbox'>The File must be greater than 0 bytes</div>"; - break; - } - break; - case "update": - switch($result){ - case "forbidden": - $result = "<div class='errorbox'>Not allowed to update this</div>"; - break; - case "404": - $result = "<div class='errorbox'>The Resource was not found on the specified path</div>"; - break; - case "ok": - $result = "<div class='okbox'>Update sucessful</div>"; - break; - case "error": - $result = "<div class='warningbox'>Update failed</div>"; - break; - } - break; - case "serial": - switch($result){ - case "noserial": - $result = "<div class='errorbox'>Your PreBoot is broken, please download a new Version or contact a PBS Administrator</div>"; - break; - } - break; - case "link": - switch($result){ - case "forbidden": - $result = "<div class='errorbox'>Not allowed to link this</div>"; - break; - case "ok": - $result = "<div class='okbox'>Link sucessful</div>"; - break; - case "error": - $result = "<div class='warningbox'>Link failed</div>"; - break; - } - break; - case "unlink": - switch($result){ - case "forbidden": - $result = "<div class='errorbox'>Not allowed to unlink this</div>"; - break; - case "ok": - $result = "<div class='okbox'>Unlink sucessful</div>"; - break; - case "error": - $result = "<div class='warningbox'>Unlink failed</div>"; - break; - } - break; - case "json": - switch($result){ - default:{ - $result = unserialize($result); - $result2 = "<div class='infobox'>"; - $result2 .= "<table class='json'>"; - $result2 .= "<tr><td><b>info</b>: </td><td>".$result['info']."</td></tr>"; - $result2 .= "<tr><td><b>kernel</b>: </td><td><a href=".$result['kernel'].">".$result['kernel']."<a></td></tr>"; - $result2 .= "<tr><td><b>initramfs</b>: </td><td><a href=".$result['initramfs'].">".$result['initramfs']."<a></td></tr>"; - $result2 .= "<tr><td><b>kcl</b>: </td><td><a href=".$result['kcl'].">".$result['kcl']."<a></td></tr>"; - $result2 .= "<tr><td><b>config</b>: </td><td>".$result['config']."</td></tr>"; - $result2 .= "</table>"; - $result2 .= "</div>"; - $result = $result2; - } - break; - case "forbidden": - $result = "<div class='errorbox'>Not allowed to display ressources</div>"; - break; - case "error": - $result = "<div class='warningbox'>Displaying ressources failed</div>"; - break; - } - break; - } - return $result; - - } + public function notify($action, $result) { + + switch($action) { + default: + switch($result) { + case "forbidden": + $result = "errorbox"; + break; + case "ok": + $result = "okbox"; + break; + case "error": + $result = "warningbox"; + break; + case "info": + $result = "infobox"; + break; + } + $result = "<div class='$result'>$action</div>"; + break; + case "delete": + switch($result) { + case "forbidden": + $result = "<div class='errorbox'>Not allowed to delete this</div>"; + break; + case "ok": + $result = "<div class='okbox'>Delete sucessful</div>"; + break; + case "error": + $result = "<div class='warningbox'>Delete failed</div>"; + break; + } + break; + case "view": + switch($result) { + case "forbidden": + $result = "<div class='errorbox'>Not allowed to see this</div>"; + break; + } + break; + case "download": + switch($result) { + case "forbidden": + $result = "<div class='errorbox'>Not allowed to download this</div>"; + break; + case "404": + $result = "<div class='errorbox'>The Resource was not found on the Server</div>"; + break; + case "error": + $result = "<div class='errorbox'>Download failed</div>"; + break; + } + break; + case "modify": + switch($result) { + case "forbidden": + $result = "<div class='errorbox'>Not allowed to modify this</div>"; + break; + case "ok": + $result = "<div class='okbox'>Modify sucessful</div>"; + break; + case "error": + $result = "<div class='warningbox'>Modify failed</div>"; + break; + } + break; + case "create": + switch($result) { + case "forbidden": + $result = "<div class='errorbox'>Not allowed to create this</div>"; + break; + case "ok": + $result = "<div class='okbox'>Creation sucessful</div>"; + break; + case "error": + $result = "<div class='warningbox'>Creation failed</div>"; + break; + case "file": + $result = "<div class='errorbox'>The File must be greater than 0 bytes</div>"; + break; + } + break; + case "update": + switch($result) { + case "forbidden": + $result = "<div class='errorbox'>Not allowed to update this</div>"; + break; + case "404": + $result = "<div class='errorbox'>The Resource was not found on the specified path</div>"; + break; + case "ok": + $result = "<div class='okbox'>Update sucessful</div>"; + break; + case "error": + $result = "<div class='warningbox'>Update failed</div>"; + break; + } + break; + case "serial": + switch($result) { + case "noserial": + $result = "<div class='errorbox'>Your PreBoot is broken, please download a new Version or contact a PBS Administrator</div>"; + break; + } + break; + case "link": + switch($result) { + case "forbidden": + $result = "<div class='errorbox'>Not allowed to link this</div>"; + break; + case "ok": + $result = "<div class='okbox'>Link sucessful</div>"; + break; + case "error": + $result = "<div class='warningbox'>Link failed</div>"; + break; + } + break; + case "unlink": + switch($result) { + case "forbidden": + $result = "<div class='errorbox'>Not allowed to unlink this</div>"; + break; + case "ok": + $result = "<div class='okbox'>Unlink sucessful</div>"; + break; + case "error": + $result = "<div class='warningbox'>Unlink failed</div>"; + break; + } + break; + case "json": + switch($result) { + default: { + $result = unserialize($result); + + $result2 = "<div class='infobox'>"; + $result2 . = "<table class='json'>"; + $result2 . = "<tr><td><b>info</b>: </td><td>".$result['info']."</td></tr>"; + $result2 . = "<tr><td><b>kernel</b>: </td><td><a href=".$result['kernel'].">".$result['kernel']."<a></td></tr>"; + $result2 . = "<tr><td><b>initramfs</b>: </td><td><a href=".$result['initramfs'].">".$result['initramfs']."<a></td></tr>"; + $result2 . = "<tr><td><b>kcl</b>: </td><td><a href=".$result['kcl'].">".$result['kcl']."<a></td></tr>"; + $result2 . = "<tr><td><b>config</b>: </td><td>".$result['config']."</td></tr>"; + $result2 . = "</table>"; + $result2 . = "</div>"; + $result = $result2; + } + break; + case "forbidden": + $result = "<div class='errorbox'>Not allowed to display ressources</div>"; + break; + case "error": + $result = "<div class='warningbox'>Displaying ressources failed</div>"; + break; + } + break; + } + return $result; + + } } -?> +? > diff --git a/library/Pbs/Pagination.php b/library/Pbs/Pagination.php index c83ec74..6468897 100644 --- a/library/Pbs/Pagination.php +++ b/library/Pbs/Pagination.php @@ -1,4 +1,4 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg * This program is free software distributed under the GPL version 2. @@ -10,89 +10,89 @@ * General information about OpenSLX can be found at http://openslx.org/ */ -class Pbs_Pagination{ +class Pbs_Pagination { + + private $element; + private $perpage; + private $requestpage; + private $maxNumber; + private $numpages; + private $pageUrl; + + public function pagination($url = null, $selected = null, $max = null) { + if($selected == null) + { $selected = $this->requestpage; } + if($max == null) + { $max = $this->numpages; } + if($url == null) + { $url = $this->pageUrl; } + +#print_a($url,$selected,$max); + + $str = "<div class='pbs_pagination'>"; + if ( 1 <= $selected) { + $str . = "<a href='$url/page/0' ><<</a>"; + $str . = "<a href='$url/page/".(($selected) - 1)."' rel='next'><</a>"; + } else { + $str . = "<span class='disabled'><<</span>"; + $str . = "<span class='disabled'><</span>"; + } + +# + $rightleft = 2; + for($i = 0; $i < ($max); $i++) { + if($selected == $i) + { $str . = "<a class='active'>".($i + 1) ."</a> "; } + else if($i >= $selected - $rightleft && $i <= $selected + $rightleft) + { $str . = "<a href='$url/page/".($i)."'>".($i + 1) ."</a> "; } + } + +# + if ( $max - 2 >= $selected) { + $str . = "<a href='$url/page/".(($selected) + 1)."'>></a> "; + $str . = "<a href='$url/page/".($max - 1)."'>>></a> "; + } else { + $str . = "<span class='disabled'>></span> "; + $str . = "<span class='disabled'>>></span> "; + } + + $str . = "</div>"; + return $str; + } + public function setPerPage($perpage) { + $this->perpage = $perpage; + return $this; + } + public function getPerPage() { + return $this->perpage; + } + public function setRequestPage($requestpage) { + if($requestpage < 0 || !is_numeric($requestpage) ) + { $requestpage = 0; } + if($requestpage >= $this->numpages) + { $requestpage = $this->numpages - 1; } + $this->requestpage = $requestpage; + return $this; + } + public function getRequestPage() { + return $this->requestpage; + } + public function setElement($element) { + $this->element = $element; + $this->maxNumber = count($element); + $this->numpages = ceil(count($element) / $this->perpage); + return $this; + } + public function getStartItem() { + return $this->requestpage * $this->perpage; + } + public function getElements() { + return array_slice($this->element, $this->getStartItem(), $this->getPerPage(), true); + } + public function setPageUrl($url) { + $this->pageUrl = $url; + return $this; + } - private $element; - private $perpage; - private $requestpage; - private $maxNumber; - private $numpages; - private $pageUrl; - - public function pagination($url=null,$selected=null,$max=null){ - if($selected == null) - $selected = $this->requestpage; - if($max == null) - $max = $this->numpages; - if($url == null) - $url = $this->pageUrl; - - #print_a($url,$selected,$max); - - $str = "<div class='pbs_pagination'>"; - if ( 1 <= $selected){ - $str .= "<a href='$url/page/0' ><<</a>"; - $str .= "<a href='$url/page/".(($selected)-1)."' rel='next'><</a>"; - }else{ - $str .= "<span class='disabled'><<</span>"; - $str .= "<span class='disabled'><</span>"; - } - - # - $rightleft = 2; - for($i=0;$i<($max);$i++){ - if($selected == $i) - $str .= "<a class='active'>".($i+1) ."</a> "; - else if($i >= $selected -$rightleft && $i <= $selected+$rightleft) - $str .= "<a href='$url/page/".($i)."'>".($i+1) ."</a> "; - } - - # - if ( $max-2 >= $selected){ - $str .= "<a href='$url/page/".(($selected)+1)."'>></a> "; - $str .= "<a href='$url/page/".($max-1)."'>>></a> "; - }else{ - $str .= "<span class='disabled'>></span> "; - $str .= "<span class='disabled'>>></span> "; - } - - $str .= "</div>"; - return $str; - } - public function setPerPage($perpage){ - $this->perpage = $perpage; - return $this; - } - public function getPerPage(){ - return $this->perpage; - } - public function setRequestPage($requestpage){ - if($requestpage < 0 || !is_numeric($requestpage) ) - $requestpage = 0; - if($requestpage >= $this->numpages) - $requestpage = $this->numpages-1; - $this->requestpage = $requestpage; - return $this; - } - public function getRequestPage(){ - return $this->requestpage; - } - public function setElement($element){ - $this->element = $element; - $this->maxNumber = count($element); - $this->numpages = ceil(count($element)/$this->perpage); - return $this; - } - public function getStartItem(){ - return $this->requestpage * $this->perpage; - } - public function getElements(){ - return array_slice($this->element,$this->getStartItem(),$this->getPerPage(),true); - } - public function setPageUrl($url){ - $this->pageUrl = $url; - return $this; - } - } diff --git a/library/Pbs/Search.php b/library/Pbs/Search.php index 587b656..7959775 100644 --- a/library/Pbs/Search.php +++ b/library/Pbs/Search.php @@ -1,4 +1,4 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg * This program is free software distributed under the GPL version 2. @@ -10,160 +10,158 @@ * General information about OpenSLX can be found at http://openslx.org/ */ -class Pbs_Search{ +class Pbs_Search { - private $searchTerm = ''; - private $searcha; - private $searchb; - private $module; - private $countall; - private $countresult; - private $type; - - public function searchForm(){ - $str = "<form style='float:left;' action='"; - if($this->type == ''){ - $str .= "/user/".$this->module."/search"; - } - else{ - $str .= "/user/".$this->module."/search/type/".$this->type; - } - $str .= "'> - <div><input type='text' id='search' name='search' ".(($this->searchTerm != '')?'value="'.htmlentities($this->searchTerm, ENT_QUOTES).'"':'')." /> - <button type='submit' class='searchbutton' value='search'> Search</button></div>"; - - $highlight = array(); - if($this->searchTerm != ''){ - $str .= "<a href='/user/".$this->module."/'><img src='/media/img/delete.png' alt='Delete Client'/></a>"; - $str .= "<div class='searchsub'>$this->countresult result".(($this->countresult==1)?'':'s')." found</div>"; - $str .="<script type='text/javascript' src='/media/js/jquery.highlight-3.js'></script>"; - foreach($this->getSearchTerms() as $term){ - $highlight[] = "$('table').highlight('".$term."');"; - $highlight[] = "$('.element .number').highlight('".$term."');"; - $highlight[] = "$('.element .title').highlight('".$term."');"; - $highlight[] = "$('.element .subtitle').highlight('".$term."');"; - $highlight[] = "$('.element .item').highlight('".$term."');"; - } - - } - $str .= "<div class='searchsub dsf'>Display searchfilter</div>"; - $str .= "<script type='text/javascript'> - $(document).ready(function(){"; - $str .= implode("\n",$highlight); - $str .= "$('.searchvars').data('m','0');\n"; - - $str .= "$('.dsf') - .click(function(){ - if($('.searchvars').is(':visible') == false){ - $('.searchvars').data('m','1').slideDown(); - } - else{ - $('.searchvars').data('m','0').slideUp(); - } - });"; - $str .= "$('.searchvars .code').click(function(){ - $('#search').val($('#search').val()+' '+$(this).text()+':'); - });"; - $str .= "$('#search') - .focus(function() { - $('table th .code').show(); - $('.searchvars').slideDown(); - }).focusout(function() { - $('table th .code').hide(); - if($('.searchvars').data('m') == '0'){ - $('.searchvars').slideUp(); - } - }); - $('table th').click(function(){ - $('#search').val($('#search').val()+' '+$(this).find('.code').text()+':'); - });"; - $str .= "}); - </script>"; - $str .= "</form>"; - return $str; - } - public function setModule($m){ - $this->module = $m; - return $this; - } - public function setType($t){ - $this->type = $t; - return $this; - } - public function setSearchTerm($search){ - $this->searchTerm = trim($search); - - // search for "text" - preg_match_all("!\"(.*?)\"!is",$this->searchTerm,$matches); - $tmpsearch = $this->searchTerm; - for($i=0;$i<=count($matches[0]);$i++){ - @$replace = str_replace(" ","<|>",$matches[0][$i]); - @$tmpsearch = str_replace($matches[0][$i],$replace,$tmpsearch); - } - $parts = explode(" ",$tmpsearch); - foreach($parts as $search){ - if(stristr($search,":") && preg_match('/^[a-z_A-Z]+$/',$search) >= 0){ - $key = substr($search,0,strpos($search,":")); - $value = substr($search,strpos($search,":")+1); - if(stristr($value,'"')){ - $value = substr(str_replace('<|>',' ',$value),1,-1); - } - $searcha[$key] = $value; - } - else{ - if(stristr($search,'"')){ - $search = substr(str_replace('<|>',' ',$search),1,-1); - } - $searchb[] = $search; - } - } - $this->searcha = @$searcha; - $this->searchb = @$searchb; - return $this; - } - public function getSearchTerm(){ - return $this->searchTerm; - } - public function getSearchTerms(){ - $beta = $this->searcha; - foreach($this->searchb as $b) - $beta[] = $b; - return $beta; - } - public function search($array){ - $this->countall = count($array); - foreach($array as $counter => $cig){ - if(is_object($cig)){ - $cig = $cig->toArray(); - } - foreach($cig as $k => $v){ - if(count($this->searcha) > 0){ - foreach($this->searcha as $sk => $sv){ - if($k == $sk){ - if(stristr($v,$sv) || $v == $sv){ - $com1[$counter] += 1; - } - } - } - } - if(count($this->searchb) >= 0){ - foreach($this->searchb as $sk => $sv){ - $comm = stristr($v,$sv); - if($comm != false || $v == $sv){ - $com2[$counter] += 1; - } - } - } - } - #print_a($com2[$counter]." >= ".count($this->searchb)." && ".$com1[$counter]." >= ".count($this->searcha)); - if($com2[$counter] >= count($this->searchb) && $com1[$counter] >= count($this->searcha)){ - // add item in resultlist - $data[] = $counter; - } - } - foreach( $data as $c) - $ges[] = $array[$c]; - $this->countresult = count($ges); - return $ges; - } + private $searchTerm = ''; + private $searcha; + private $searchb; + private $module; + private $countall; + private $countresult; + private $type; + + public function searchForm() { + $str = "<form style='float:left;' action='"; + if($this->type == '') { + $str . = "/user/".$this->module."/search"; + } else { + $str . = "/user/".$this->module."/search/type/".$this->type; + } + $str . = "'> + <div><input type='text' id='search' name='search' ".(($this->searchTerm != '') ? 'value="'.htmlentities($this->searchTerm, ENT_QUOTES).'"' : '')." /> + <button type='submit' class='searchbutton' value='search'> Search</button></div>"; + + $highlight = array(); + if($this->searchTerm != '') { + $str . = "<a href='/user/".$this->module."/'><img src='/media/img/delete.png' alt='Delete Client'/></a>"; + $str . = "<div class='searchsub'>$this->countresult result".(($this->countresult == 1) ? '' : 's')." found</div>"; + $str . = "<script type='text/javascript' src='/media/js/jquery.highlight-3.js'></script>"; + foreach($this->getSearchTerms() as $term) { + $highlight[] = "$('table').highlight('".$term."');"; + $highlight[] = "$('.element .number').highlight('".$term."');"; + $highlight[] = "$('.element .title').highlight('".$term."');"; + $highlight[] = "$('.element .subtitle').highlight('".$term."');"; + $highlight[] = "$('.element .item').highlight('".$term."');"; + } + + } + $str . = "<div class='searchsub dsf'>Display searchfilter</div>"; + $str . = "<script type='text/javascript'> + $(document).ready(function(){"; + $str . = implode("\n", $highlight); + $str . = "$('.searchvars').data('m','0');\n"; + + $str . = "$('.dsf') + .click(function(){ + if($('.searchvars').is(':visible') == false){ + $('.searchvars').data('m','1').slideDown(); + } + else{ + $('.searchvars').data('m','0').slideUp(); + } + });"; + $str . = "$('.searchvars .code').click(function(){ + $('#search').val($('#search').val()+' '+$(this).text()+':'); + });"; + $str . = "$('#search') + .focus(function() { + $('table th .code').show(); + $('.searchvars').slideDown(); + }).focusout(function() { + $('table th .code').hide(); + if($('.searchvars').data('m') == '0'){ + $('.searchvars').slideUp(); + } + }); + $('table th').click(function(){ + $('#search').val($('#search').val()+' '+$(this).find('.code').text()+':'); + });"; + $str . = "}); + </script>"; + $str . = "</form>"; + return $str; + } + public function setModule($m) { + $this->module = $m; + return $this; + } + public function setType($t) { + $this->type = $t; + return $this; + } + public function setSearchTerm($search) { + $this->searchTerm = trim($search); + + // search for "text" + preg_match_all("!\"(.*?)\"!is", $this->searchTerm, $matches); + $tmpsearch = $this->searchTerm; + for($i = 0; $i <= count($matches[0]); $i++) { + @$replace = str_replace(" ", "<|>", $matches[0][$i]); + @$tmpsearch = str_replace($matches[0][$i], $replace, $tmpsearch); + } + $parts = explode(" ", $tmpsearch); + foreach($parts as $search) { + if(stristr($search, ":") && preg_match('/^[a-z_A-Z]+$/', $search) >= 0) { + $key = substr($search, 0, strpos($search, ":")); + $value = substr($search, strpos($search, ":") + 1); + if(stristr($value, '"')) { + $value = substr(str_replace('<|>', ' ', $value), 1, -1); + } + $searcha[$key] = $value; + } else { + if(stristr($search, '"')) { + $search = substr(str_replace('<|>', ' ', $search), 1, -1); + } + $searchb[] = $search; + } + } + $this->searcha = @$searcha; + $this->searchb = @$searchb; + return $this; + } + public function getSearchTerm() { + return $this->searchTerm; + } + public function getSearchTerms() { + $beta = $this->searcha; + foreach($this->searchb as $b) + $beta[] = $b; + return $beta; + } + public function search($array) { + $this->countall = count($array); + foreach($array as $counter => $cig) { + if(is_object($cig)) { + $cig = $cig->toArray(); + } + foreach($cig as $k => $v) { + if(count($this->searcha) > 0) { + foreach($this->searcha as $sk => $sv) { + if($k == $sk) { + if(stristr($v, $sv) || $v == $sv) { + $com1[$counter] += 1; + } + } + } + } + if(count($this->searchb) >= 0) { + foreach($this->searchb as $sk => $sv) { + $comm = stristr($v, $sv); + if($comm != false || $v == $sv) { + $com2[$counter] += 1; + } + } + } + } +#print_a($com2[$counter]." >= ".count($this->searchb)." && ".$com1[$counter]." >= ".count($this->searcha)); + if($com2[$counter] >= count($this->searchb) && $com1[$counter] >= count($this->searcha)) { + // add item in resultlist + $data[] = $counter; + } + } + foreach( $data as $c) + $ges[] = $array[$c]; + $this->countresult = count($ges); + return $ges; + } } diff --git a/library/Pbs/Session.php b/library/Pbs/Session.php index 12e6738..bc4587e 100644 --- a/library/Pbs/Session.php +++ b/library/Pbs/Session.php @@ -1,4 +1,4 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg * This program is free software distributed under the GPL version 2. @@ -10,41 +10,39 @@ * General information about OpenSLX can be found at http://openslx.org/ */ -class Pbs_Session{ +class Pbs_Session { - public function createSession(Application_Model_Session $session){ - $sessionmapper = new Application_Model_SessionMapper(); - $uniqid = $this->getUniqueCode(10); - $sm = new Application_Model_SessionMapper(); - while(count($sm->findBy(array('alphasessionID' => $uniqid),true))>0){ - $uniqid = $this->getUniqueCode(16); - } - - $session->setAlphasessionID($uniqid); - - $id = $sessionmapper->save($session); - $sessionmapper->find($id, $session); - return $session; - } - public function createClient(Application_Model_Client $client){ - $clientmapper = new Application_Model_ClientMapper(); - $result = $clientmapper->findBy(array('macadress' => $client->getMacadress(),'groupID'=>$client->getGroupID()),true); - if(count($result)>0){ - $client->setOptions($result[0]); - $client->setID($result[0]['clientID']); - } - else{ - $id = $clientmapper->save($client); - $clientmapper->find($id, $client); - } - return $client; - } - private function getUniqueCode($length = "") - { - $code = md5(uniqid(rand(), true)); - if ($length != "") return substr($code, 0, $length); - else return $code; - } + public function createSession(Application_Model_Session $session) { + $sessionmapper = new Application_Model_SessionMapper(); + $uniqid = $this->getUniqueCode(10); + $sm = new Application_Model_SessionMapper(); + while(count($sm->findBy(array('alphasessionID' => $uniqid), true)) > 0) { + $uniqid = $this->getUniqueCode(16); + } + + $session->setAlphasessionID($uniqid); + + $id = $sessionmapper->save($session); + $sessionmapper->find($id, $session); + return $session; + } + public function createClient(Application_Model_Client $client) { + $clientmapper = new Application_Model_ClientMapper(); + $result = $clientmapper->findBy(array('macadress' => $client->getMacadress(), 'groupID' => $client->getGroupID()), true); + if(count($result) > 0) { + $client->setOptions($result[0]); + $client->setID($result[0]['clientID']); + } else { + $id = $clientmapper->save($client); + $clientmapper->find($id, $client); + } + return $client; + } + private function getUniqueCode($length = "") { + $code = md5(uniqid(rand(), true)); + if ($length != "") { return substr($code, 0, $length); } + else { return $code; } + } } -?> +? > |