From 09389b149c05033f14708d7535dee851f3fce0d8 Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Mon, 14 Nov 2011 17:51:28 +0100 Subject: EventController Cleaning: API in eigene Klasse ausgelagert --- application/controllers/AuthController.php | 85 +-- application/controllers/ErrorController.php | 2 + application/controllers/EventController.php | 658 ++++------------------- application/controllers/IndexController.php | 2 + application/controllers/PersonController.php | 24 +- application/controllers/StatisticsController.php | 2 + 6 files changed, 146 insertions(+), 627 deletions(-) (limited to 'application') diff --git a/application/controllers/AuthController.php b/application/controllers/AuthController.php index 0ba5027..b3f6bbf 100755 --- a/application/controllers/AuthController.php +++ b/application/controllers/AuthController.php @@ -14,6 +14,7 @@ class AuthController extends Zend_Controller_Action { protected $config = null; protected $pbs2host = null; + protected $pbs2Api = null; protected $userIDsNamespace = null; protected $acl = null; @@ -22,6 +23,7 @@ class AuthController extends Zend_Controller_Action $bootstrap = $this->getInvokeArg('bootstrap'); $this->config = $bootstrap->getOptions(); $this->pbs2host = $this->config['pbs2']['host']; + $this->pbs2Api = new Poolctrl_Pbs2Api($this->config); $this->userIDsNamespace = Zend_Session::namespaceGet('userIDs'); if(isset($this->userIDsNamespace['apikey'])) { $this->acl = new Poolctrl_Acl($this->pbs2host, $this->config['pbs2']['checkright'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); @@ -42,75 +44,28 @@ class AuthController extends Zend_Controller_Action $loginForm = new Application_Form_Login(); } else { $loginForm = new Application_Form_Login($_POST); - if ($loginForm->isValid($_POST)) { - $loginquery = "email=" . $loginForm->getValue('email') . "&password=" . $loginForm->getValue('password'); - $loginApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['login'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $loginquery); - $loginXMLString = $loginApiResult['http-body']; - if(strlen($loginXMLString) > 0) { - $loginXML = new SimpleXMLElement($loginXMLString); - $login = $loginXML->login; - $success = sprintf("%s", $login->success); - if ($success === "true") { - $membershipSession = new Zend_Session_Namespace('memberships'); - $count = 0; - foreach($login->membershiplist->membership as $membershipXML) - { - $membership = new Application_Model_Membership(); - $membership->setID(sprintf("%s", $membershipXML->id)); - $membership->setPersonID(sprintf("%s", $membershipXML->personid)); - $membership->setGroupID(sprintf("%s", $membershipXML->groupid)); - $membership->setRoleID(sprintf("%s", $membershipXML->roleid)); - $membership->setApikey(sprintf("%s", $membershipXML->apikey)); - $membership->setSuspend(sprintf("%s", $membershipXML->suspend)); - $membershipID = $membership->getID(); - $membershipSession->$membershipID = $membership; - if($count == 0) { - $apikey = sprintf("%s", $membershipXML->apikey); - } - $count++; - } - - $personApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getperson'] . $apikey, 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); - $personXMLString = $personApiResult['http-body']; - if(strlen($personXMLString) > 0) { - $personXML = new SimpleXMLElement($personXMLString); - $person = new Application_Model_Person(); - $person->setID(sprintf("%s", $personXML->person->id)); - $person->setCity(sprintf("%s", $personXML->person->city)); - $person->setEmail(sprintf("%s", $personXML->person->email)); - $person->setFirstname(sprintf("%s", $personXML->person->firstname)); - $person->setHousenumber(sprintf("%s", $personXML->person->housenumber)); - $person->setLogin(sprintf("%s", $personXML->person->login)); - $person->setLogindate(sprintf("%s", $personXML->person->logindate)); - $person->setName(sprintf("%s", $personXML->person->name)); - $person->setPostalcode(sprintf("%s", $personXML->person->postalcode)); - $person->setRegisterdate(sprintf("%s", $personXML->person->registerdate)); - $person->setStreet(sprintf("%s", $personXML->person->street)); - $person->setSuspend(sprintf("%s", $personXML->person->suspend)); - $person->setTitle(sprintf("%s", $personXML->person->title)); - $personSession = new Zend_Session_Namespace('persons'); - $personName = sprintf("%s", $login->personid); - $personSession->$personName = $person; - } + $membershipSession = new Zend_Session_Namespace('memberships'); + if($this->pbs2Api->login($loginForm->getValue('email'), $loginForm->getValue('password'), $membershipSession)) { + $personSession = new Zend_Session_Namespace('persons'); + $this->pbs2Api->getPerson($personSession); - $userSession = new Zend_Session_Namespace('userIDs'); - $userSession->personID = sprintf("%s", $login->personid); + $userSession = new Zend_Session_Namespace('userIDs'); + $userSession->personID = sprintf("%s", $login->personid); - $authSession = new Zend_Session_Namespace('auth'); - $authSession->storage = $loginForm->getValue('email'); + $authSession = new Zend_Session_Namespace('auth'); + $authSession->storage = $loginForm->getValue('email'); - $this->_helper->redirector('selectmembership', 'person'); - return; - } else { - $error = sprintf("%s", $login->error); - if($error == "wrong email or password") { - $poolctrlNotifier = new Poolctrl_Notifier(); - $this->view->notification = $poolctrlNotifier->notify('Wrong Email or Password', 'error'); - } else if($error == "person suspended") { - $poolctrlNotifier = new Poolctrl_Notifier(); - $this->view->notification = $poolctrlNotifier->notify('Your Account is suspended', 'error'); - } + $this->_helper->redirector('selectmembership', 'person'); + return; + } else { + $error = sprintf("%s", $login->error); + if($error == "wrong email or password") { + $poolctrlNotifier = new Poolctrl_Notifier(); + $this->view->notification = $poolctrlNotifier->notify('Wrong Email or Password', 'error'); + } else if($error == "person suspended") { + $poolctrlNotifier = new Poolctrl_Notifier(); + $this->view->notification = $poolctrlNotifier->notify('Your Account is suspended', 'error'); } } } diff --git a/application/controllers/ErrorController.php b/application/controllers/ErrorController.php index 49ecdcf..1cca34f 100755 --- a/application/controllers/ErrorController.php +++ b/application/controllers/ErrorController.php @@ -4,6 +4,7 @@ class ErrorController extends Zend_Controller_Action { protected $config; protected $pbs2host; + protected $pbs2Api; protected $userIDsNamespace; protected $acl; @@ -12,6 +13,7 @@ class ErrorController extends Zend_Controller_Action $bootstrap = $this->getInvokeArg('bootstrap'); $this->config = $bootstrap->getOptions(); $this->pbs2host = $this->config['pbs2']['host']; + $this->pbs2Api = new Poolctrl_Pbs2Api($this->config); $this->userIDsNamespace = Zend_Session::namespaceGet('userIDs'); if(isset($this->userIDsNamespace['apikey'])) { $this->acl = new Poolctrl_Acl($this->pbs2host, $this->config['pbs2']['checkright'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); diff --git a/application/controllers/EventController.php b/application/controllers/EventController.php index b2877e9..6ce76ba 100755 --- a/application/controllers/EventController.php +++ b/application/controllers/EventController.php @@ -17,6 +17,7 @@ class EventController extends Zend_Controller_Action protected $config; protected $pbs2host; protected $userIDsNamespace; + protected $pbs2Api; protected $acl; protected $gearmanClient; protected $gearmanServerHost; @@ -30,6 +31,7 @@ class EventController extends Zend_Controller_Action $bootstrap = $this->getInvokeArg('bootstrap'); $this->config = $bootstrap->getOptions(); $this->pbs2host = $this->config['pbs2']['host']; + $this->pbs2Api = new Poolctrl_Pbs2Api($this->config); $this->gearmanServerHost = $this->config['gearman']['server']['host']; $this->gearmanServerPort = $this->config['gearman']['server']['port']; $this->gearmanWorkerWaitTime = $this->config['gearman']['worker']['waitTime']; @@ -84,63 +86,13 @@ class EventController extends Zend_Controller_Action } $eventcategorylist = $this->eventcategoryMapper->fetchAll(); $this->poolVal = $this->getRequest()->getParam('poolSelectBoxVal'); - $bootOsApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getbootoss'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); - $bootOsXMLString = $bootOsApiResult['http-body']; - if(strlen($bootOsXMLString) > 0) { - $bootOsXML = new SimpleXMLElement($bootOsXMLString); - foreach($bootOsXML->bootoslist->bootos as $bootos) { - $bootosobj = new Application_Model_BootOs(); - $bootosobj->setID(sprintf("%s", $bootos->id)); - $bootosobj->setCreated(sprintf("%s", $bootos->created)); - $bootosobj->setDefaultkcl(sprintf("%s", $bootos->defaultkcl)); - $bootosobj->setDescription(sprintf("%s", $bootos->description)); - $bootosobj->setDistro(sprintf("%s", $bootos->distro)); - $bootosobj->setDistroversion(sprintf("%s", $bootos->distroversion)); - $bootosobj->setExpires(sprintf("%s", $bootos->expires)); - $bootosobj->setGroupID(sprintf("%s", $bootos->groupid)); - $bootosobj->setMembershipID(sprintf("%s", $bootos->membershipid)); - $bootosobj->setPublic(sprintf("%s", $bootos->public)); - $bootosobj->setShare(sprintf("%s", $bootos->share)); - $bootosobj->setShortname(sprintf("%s", $bootos->shortname)); - $bootosobj->setSource(sprintf("%s", $bootos->source)); - $bootosobj->setTitle(sprintf("%s", $bootos->title)); - $bootoslist[$bootosobj->getID()] = $bootosobj; - foreach($bootos->configs->config as $config) { - $configobj = new Application_Model_Config(); - $configobj->setID(sprintf("%s", $config->configid)); - $configobj->setBootosID(sprintf("%s", $bootosobj->getID())); - $configobj->setCreated(sprintf("%s", $config->created)); - $configobj->setMembershipID(sprintf("%s", $config->membershipid)); - $configobj->setDescription(sprintf("%s", $config->description)); - $configobj->setGroupID(sprintf("%s", $config->groupid)); - $configobj->setTitle(sprintf("%s", $config->title)); - $configobj->setVisible(sprintf("%s", $config->visible)); - if($configobj->getVisible()) { - if($configobj->getTitle() == 'Default') { - $configlist[$bootosobj->getID()][0] = $configobj; - } else { - $configlist[$bootosobj->getID()][$configobj->getID()] = $configobj; - } - } - } - } - } + $bootoslist = array(); + $configlist = array(); + $this->pbs2Api->getBootos($bootoslist, $configlist); if(!isset($this->userIDsNamespace['poolID'])) { - $poolApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getpools'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); - $poolXMLString = $poolApiResult['http-body']; - if(strlen($poolXMLString) > 0) { - $poolXML = new SimpleXMLElement($poolXMLString); - foreach($poolXML->poollist->pool as $pool) { - $poolobj = new Application_Model_Pool(); - $poolobj->setID(sprintf("%s", $pool->id)); - $poolobj->setDescription(sprintf("%s", $pool->description)); - $poolobj->setGroupID(sprintf("%s", $pool->groupid)); - $poolobj->setLocation(sprintf("%s", $pool->location)); - $poolobj->setTitle(sprintf("%s", $pool->title)); - $poollist[$poolobj->getID()] = $poolobj; - } - } + $poollist = array(); + $this->pbs2Api->getPool($poollist); } $repeatendMapper = new Application_Model_RepeatendMapper(); $repeatendlist = $repeatendMapper->fetchAll(); @@ -224,20 +176,13 @@ class EventController extends Zend_Controller_Action $result = $this->eventcategoryMapper->findBy(array('title' => 'Shutdown')); $shutdownCategory = $result[0]; if($event->getCategory() != $shutdownCategory->getID()) { - $bootmenuquery = "bootosID=" . $event->getPbs_bootosID() . "&startcounter=0&title=Poolctrl-Bootmenu for " . $event->getTitle() . "&defaultbootmenu=0&order=0&kcl=0"; if($event->getPbs_configID()) { - $bootmenuquery .= "&configID=" . $event->getPbs_configID(); + $bootmenuID = $this->pbs2Api->addBootmenu($event->getTitle(), $event->getPbs_bootosID(), $event->getPbs_configID()); + } else { + $bootmenuID = $this->pbs2Api->addBootmenu($event->getTitle(), $event->getPbs_bootosID()); } - $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addbootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $bootmenuquery); - $bootmenuXMLString = $bootmenuApiResult['http-body']; - $bootmenuXML = new SimpleXMLElement($bootmenuXMLString); - $bootmenuID = sprintf("%s", $bootmenuXML->bootmenu->id); $event->setPbs_bootmenuID($bootmenuID); - $filterquery = "bootmenuID=" . $event->getPbs_bootmenuID() . "&title=Poolctrl-Filter for " . $event->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $event->getTitle() . "&created= " . time() . "&priority=100"; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterquery); - $filterXMLString = $filterApiResult['http-body']; - $filterXML = new SimpleXMLElement($filterXMLString); - $filterID = sprintf("%s", $filterXML->filter->id); + $filterID = $this->pbs2Api->addFilter($event->getTitle(), $event->getPbs_bootmenuID()); $event->setPbs_filterID($filterID); $startTime = date('H:i', strtotime($event->getStart())); if($event->getEnd()) { @@ -245,16 +190,8 @@ class EventController extends Zend_Controller_Action } else { $endTime = date('H:i', strtotime($event->getStart()) + 900); } - $filterentriesquery1 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=7&filtervalue=" . $startTime . "&filtervalue2=" . $endTime; - $filterentriesApiResult1 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery1); - $filterentriesXMLString1 = $filterentriesApiResult1['http-body']; - $filterentriesXML1 = new SimpleXMLElement($filterentriesXMLString1); - $filterentriesID1 = sprintf("%s", $filterentriesXML1->filterentry->id); - $filterentriesquery2 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=3&filtervalue=" . $event->getPbs_poolID(); - $filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2); - $filterentriesXMLString2 = $filterentriesApiResult2['http-body']; - $filterentriesXML2 = new SimpleXMLElement($filterentriesXMLString2); - $filterentriesID2 = sprintf("%s", $filterentriesXML2->filterentry->id); + $filterentriesID1 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 7, $startTime, $endTime); + $filterentriesID2 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 3, $event->getPbs_poolID(), ''); if(!$event->getRepeat()) { $startDate = date('d.m.Y', strtotime($event->getStart())); if($event->getEnd()) { @@ -262,11 +199,7 @@ class EventController extends Zend_Controller_Action } else { $endDate = date('d.m.Y', strtotime($event->getStart())); } - $filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } } if($event->getImmediate()) { @@ -360,11 +293,11 @@ class EventController extends Zend_Controller_Action $this->_redirect('/'); } } - if($event->getPbs_bootmenuID() && $event->getRepeat() == 0) { - $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletebootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "bootmenuid=" . $event->getPbs_bootmenuID()); + if($event->getPbs_bootmenuID() && $event->getRepeat() != 1) { + $this->pbs2Api->deleteBootmenu($event->getPbs_bootmenuID()); } if($event->getPbs_filterID() && $event->getRepeat() != 1) { - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "filterid=" . $event->getPbs_filterID()); + $this->pbs2Api->deleteFilter($event->getPbs_filterID()); } try { $this->eventMapper->delete($event); @@ -400,60 +333,11 @@ class EventController extends Zend_Controller_Action exit; } $eventcategorylist = $this->eventcategoryMapper->fetchAll(); - $bootOsApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getbootoss'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); - $bootOsXMLString = $bootOsApiResult['http-body']; - if(strlen($bootOsXMLString) > 0) { - $bootOsXML = new SimpleXMLElement($bootOsXMLString); - foreach($bootOsXML->bootoslist->bootos as $bootos) { - $bootosobj = new Application_Model_BootOs(); - $bootosobj->setID(sprintf("%s", $bootos->id)); - $bootosobj->setCreated(sprintf("%s", $bootos->created)); - $bootosobj->setDefaultkcl(sprintf("%s", $bootos->defaultkcl)); - $bootosobj->setDescription(sprintf("%s", $bootos->description)); - $bootosobj->setDistro(sprintf("%s", $bootos->distro)); - $bootosobj->setDistroversion(sprintf("%s", $bootos->distroversion)); - $bootosobj->setExpires(sprintf("%s", $bootos->expires)); - $bootosobj->setGroupID(sprintf("%s", $bootos->groupid)); - $bootosobj->setMembershipID(sprintf("%s", $bootos->membershipid)); - $bootosobj->setPublic(sprintf("%s", $bootos->public)); - $bootosobj->setShare(sprintf("%s", $bootos->share)); - $bootosobj->setShortname(sprintf("%s", $bootos->shortname)); - $bootosobj->setSource(sprintf("%s", $bootos->source)); - $bootosobj->setTitle(sprintf("%s", $bootos->title)); - $bootoslist[$bootosobj->getID()] = $bootosobj; - foreach($bootos->configs->config as $config) { - $configobj = new Application_Model_Config(); - $configobj->setID(sprintf("%s", $config->configid)); - $configobj->setBootosID(sprintf("%s", $bootosobj->getID())); - $configobj->setCreated(sprintf("%s", $config->created)); - $configobj->setDescription(sprintf("%s", $config->description)); - $configobj->setGroupID(sprintf("%s", $config->groupid)); - $configobj->setTitle(sprintf("%s", $config->title)); - $configobj->setVisible(sprintf("%s", $config->visible)); - if($configobj->getVisible()) { - if($configobj->getTitle() == 'Default') { - $configlist[$bootosobj->getID()][0] = $configobj; - } else { - $configlist[$bootosobj->getID()][$configobj->getID()] = $configobj; - } - } - } - } - } - $poolApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getpools'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); - $poolXMLString = $poolApiResult['http-body']; - if(strlen($poolXMLString) > 0) { - $poolXML = new SimpleXMLElement($poolXMLString); - foreach($poolXML->poollist->pool as $pool) { - $poolobj = new Application_Model_Pool(); - $poolobj->setID(sprintf("%s", $pool->id)); - $poolobj->setDescription(sprintf("%s", $pool->description)); - $poolobj->setGroupID(sprintf("%s", $pool->groupid)); - $poolobj->setLocation(sprintf("%s", $pool->location)); - $poolobj->setTitle(sprintf("%s", $pool->title)); - $poollist[$poolobj->getID()] = $poolobj; - } - } + $bootoslist = array(); + $configlist = array(); + $this->pbs2Api->getBootos($bootoslist, $configlist); + $poollist = array(); + $this->pbs2Api->getPool($poollist); if($event->getPbs_membershipID() != $this->userIDsNamespace['membershipID']) { if(!$this->acl->checkRight('eeo')) { $this->_redirect('/'); @@ -562,56 +446,36 @@ class EventController extends Zend_Controller_Action if($event->getCategory() != $shutdownCategory->getID()) { $diff = $this->eventMapper->compare($oldEvent, $event); if(isset($diff['pbs_bootosID']) || isset($diff['title']) || isset($diff['pbs_configID'])) { - $bootmenuquery = "bootmenuid=" . $event->getPbs_bootmenuID() . "&bootosID=" . $event->getPbs_bootosID() . "&startcounter=0&title=Poolctrl-Bootmenu for " . $event->getTitle() . "&defaultbootmenu=0&order=0&kcl=0&changeentry=1"; if($event->getPbs_configID()) { - $bootmenuquery .= "&configID=" . $event->getPbs_configID(); + $this->pbs2Api->changeBootmenu($event->getTitle(), $event->getPbs_bootosID(), $event->getPbs_configID()); + } else { + $this->pbs2Api->changeBootmenu($event->getTitle(), $event->getPbs_bootosID()); } - $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changebootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $bootmenuquery); - } if(isset($diff['title'])) { - $filterQuerie = "filterid=" . $event->getPbs_filterID() . "&title=Poolctrl-Filter for " . $event->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $event->getTitle(); - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterQuerie); - unset($filterApiResult); + $this->pbs2Api->changeFilter($event->getPbs_filterID(), $event->getTitle()); } if(isset($diff['start']) || isset($diff['end']) || isset($diff['pbs_poolID'])) { if($event->getRepeat() != 2) { - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "filterid=" . $oldEvent->getPbs_filterID()); - unset($filterApiResult); + $this->pbs2Api->deleteFilter($event->getPbs_filterID()); } - $filterquery = "bootmenuID=" . $event->getPbs_bootmenuID() . "&title=Poolctrl-Filter for " . $event->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $event->getTitle() . "&created= " . time() . "&priority=100"; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterquery); - $filterXMLString = $filterApiResult['http-body']; - $filterXML = new SimpleXMLElement($filterXMLString); - $filterID = sprintf("%s", $filterXML->filter->id); + $filterID = $this->pbs2Api->addFilter($event->getTitle(), $event->getPbs_bootmenuID()); $event->setPbs_filterID($filterID); - $filterentriesquery1 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=3&filtervalue=" . $event->getPbs_poolID(); - $filterentriesApiResult1 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery1); - $filterentriesXMLString1 = $filterentriesApiResult1['http-body']; - $filterentriesXML1 = new SimpleXMLElement($filterentriesXMLString1); - $filterentriesID1 = sprintf("%s", $filterentriesXML1->filterentry->id); $startTime = date('H:i', strtotime($event->getStart())); if($event->getEnd()) { $endTime = date('H:i', strtotime($event->getEnd())); } else { $endTime = date('H:i', strtotime($event->getStart()) + 900); } - $filterentriesquery2 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=7&filtervalue=" . $startTime . "&filtervalue2=" . $endTime; - $filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2); - $filterentriesXMLString2 = $filterentriesApiResult2['http-body']; - $filterentriesXML2 = new SimpleXMLElement($filterentriesXMLString2); - $filterentriesID2 = sprintf("%s", $filterentriesXML2->filterentry->id); + $filterentriesID1 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 7, $startTime, $endTime); + $filterentriesID2 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 3, $event->getPbs_poolID(), ''); $startDate = date('d.m.Y', strtotime($event->getStart())); if($event->getEnd()) { $endDate = date('d.m.Y', strtotime($event->getEnd())); } else { $endDate = date('d.m.Y', strtotime($event->getStart())); } - $filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } } } @@ -686,11 +550,11 @@ class EventController extends Zend_Controller_Action } try { foreach($events as $event) { - if ($event->getPbs_bootmenuID()) { - $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletebootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "bootmenuid=" . $events[0]->getPbs_bootmenuID()); + if($event->getPbs_bootmenuID()) { + $this->pbs2Api->deleteBootmenu($event->getPbs_bootmenuID()); } - if ($event->getPbs_filterID()) { - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "bootmenuid=" . $events[0]->getPbs_filterID()); + if($event->getPbs_filterID()) { + $this->pbs2Api->deleteFilter($event->getPbs_filterID()); } if($event->getRunning() == 0) { $this->eventMapper->delete($event); @@ -721,20 +585,7 @@ class EventController extends Zend_Controller_Action } $this->_helper->layout->disableLayout(); $poollist = array(); - $poolApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getpools'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); - $poolXMLString = $poolApiResult['http-body']; - if(strlen($poolXMLString) > 0) { - $poolXML = new SimpleXMLElement($poolXMLString); - foreach($poolXML->poollist->pool as $pool) { - $poolobj = new Application_Model_Pool(); - $poolobj->setID(sprintf("%s", $pool->id)); - $poolobj->setDescription(sprintf("%s", $pool->description)); - $poolobj->setGroupID(sprintf("%s", $pool->groupid)); - $poolobj->setLocation(sprintf("%s", $pool->location)); - $poolobj->setTitle(sprintf("%s", $pool->title)); - $poollist[$poolobj->getID()] = $poolobj; - } - } + $this->pbs2Api->getPool($poollist); if(isset($this->userIDsNamespace['poolID'])) { $this->view->poolID = $this->userIDsNamespace['poolID']; } @@ -1042,42 +893,25 @@ class EventController extends Zend_Controller_Action if($event->getCategory() != $shutdownCategory->getID()) { if($event->getPbs_filterID()) { if($oldEvent->getRepeat() == 0 || $oldEvent->getRepeat() == 2) { - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "filterid=" . $oldEvent->getPbs_filterID()); - unset($filterApiResult); - } - $filterquery = "bootmenuID=" . $event->getPbs_bootmenuID() . "&title=Poolctrl-Filter for " . $event->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $event->getTitle() . "&created=" . time() . "&priority=100"; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterquery); - $filterXMLString = $filterApiResult['http-body']; - $filterXML = new SimpleXMLElement($filterXMLString); - $filterID = sprintf("%s", $filterXML->filter->id); + $this->pbs2Api->deleteFilter($oldEvent->getPbs_filterID()); + } + $filterID = $this->pbs2Api->addFilter($event->getTitle(), $event->getPbs_bootmenuID()); $event->setPbs_filterID($filterID); - $filterentriesquery1 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=3&filtervalue=" . $event->getPbs_poolID(); - $filterentriesApiResult1 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery1); - $filterentriesXMLString1 = $filterentriesApiResult1['http-body']; - $filterentriesXML1 = new SimpleXMLElement($filterentriesXMLString1); - $filterentriesID1 = sprintf("%s", $filterentriesXML1->filterentry->id); $startTime = date('H:i', strtotime($event->getStart())); if($event->getEnd()) { $endTime = date('H:i', strtotime($event->getEnd())); } else { $endTime = date('H:i', strtotime($event->getStart()) + 900); } - $filterentriesquery2 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=7&filtervalue=" . $startTime . "&filtervalue2=" . $endTime; - $filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2); - $filterentriesXMLString2 = $filterentriesApiResult2['http-body']; - $filterentriesXML2 = new SimpleXMLElement($filterentriesXMLString2); - $filterentriesID2 = sprintf("%s", $filterentriesXML2->filterentry->id); + $filterentriesID1 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 7, $startTime, $endTime); + $filterentriesID2 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 3, $event->getPbs_poolID(), ''); $startDate = date('d.m.Y', strtotime($event->getStart())); if($event->getEnd()) { $endDate = date('d.m.Y', strtotime($event->getEnd())); } else { $endDate = date('d.m.Y', strtotime($event->getStart())); } - $filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } } try { @@ -1172,18 +1006,13 @@ class EventController extends Zend_Controller_Action $newStartDate = date("N", strototime($newStartDate)); $newEndDate = ''; $filterentriesQuerie = "filterid=" . $event->getPbs_filterID() . "&oldvalue1=" . strtotime($oldStartDate) . "&oldvalue2=" . strtotime($oldEndDate) . "&value1=" . strtotime($newStartDate) . "&value2=" . strtotime($newEndDate); - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesQuerie); - unset($filterApiResult); + $this->pbs2Api->changeFilterentry($event->getPbs_filterID(), strtotime($oldStartDate), strtotime($oldEndDate), strtotime($newStartDate), strtotime($newEndDate)); } } else { - $filterentriesQuerie = "filterid=" . $event->getPbs_filterID() . "&oldvalue1=" . strtotime($oldStartDate) . "&oldvalue2=" . strtotime($oldEndDate) . "&value1=" . strtotime($newStartDate) . "&value2=" . strtotime($newEndDate); - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesQuerie); - unset($filterApiResult); + $this->pbs2Api->changeFilterentry($event->getPbs_filterID(), strtotime($oldStartDate), strtotime($oldEndDate), strtotime($newStartDate), strtotime($newEndDate)); } if($count == 1) { - $filterentriesQuerie = "filterid=" . $event->getPbs_filterID() . "&oldvalue1=" . $oldStartTime . "&oldvalue2=" . $oldEndTime . "&value1=" . $newStartTime . "&value2=" . $newEndTime; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesQuerie); - unset($filterApiResult); + $this->pbs2Api->changeFilterentry($event->getPbs_filterID(), $oldStartTime, $oldEndTime, $newStartTime, $newEndTime); } } } @@ -1232,11 +1061,7 @@ class EventController extends Zend_Controller_Action foreach($otherEvents as $event) { $event->setRepeat(2); - $filterquery = "bootmenuID=" . $event->getPbs_bootmenuID() . "&title=Poolctrl-Filter for " . $event->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $event->getTitle() . "&created= " . time() . "&priority=100"; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterquery); - $filterXMLString = $filterApiResult['http-body']; - $filterXML = new SimpleXMLElement($filterXMLString); - $filterID = sprintf("%s", $filterXML->filter->id); + $filterID = $this->pbs2Api->addFilter($event->getTitle(), $event->getPbs_bootmenuID()); $event->setPbs_filterID($filterID); $startTime = date('H:i', strtotime($event->getStart())); if($event->getEnd()) { @@ -1244,27 +1069,15 @@ class EventController extends Zend_Controller_Action } else { $endTime = date('H:i', strtotime($event->getStart()) + 900); } - $filterentriesquery1 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=7&filtervalue=" . $startTime . "&filtervalue2=" . $endTime; - $filterentriesApiResult1 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery1); - $filterentriesXMLString1 = $filterentriesApiResult1['http-body']; - $filterentriesXML1 = new SimpleXMLElement($filterentriesXMLString1); - $filterentriesID1 = sprintf("%s", $filterentriesXML1->filterentry->id); - $filterentriesquery2 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=3&filtervalue=" . $event->getPbs_poolID(); - $filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2); - $filterentriesXMLString2 = $filterentriesApiResult2['http-body']; - $filterentriesXML2 = new SimpleXMLElement($filterentriesXMLString2); - $filterentriesID2 = sprintf("%s", $filterentriesXML2->filterentry->id); + $filterentriesID1 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 7, $startTime, $endTime); + $filterentriesID2 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 3, $event->getPbs_poolID(), ''); $startDate = date('d.m.Y', strtotime($event->getStart())); if($event->getEnd()) { $endDate = date('d.m.Y', strtotime($event->getEnd())); } else { $endDate = date('d.m.Y', strtotime($event->getStart())); } - $filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); try { $this->eventMapper->save($event); //save the event with the new data } catch (Zend_Exception $e) { @@ -1341,18 +1154,13 @@ class EventController extends Zend_Controller_Action $newStartDate = date("N", strototime($newStartDate)); $newEndDate = ''; $filterentriesQuerie = "filterid=" . $event->getPbs_filterID() . "&oldvalue1=" . strtotime($oldStartDate) . "&oldvalue2=" . strtotime($oldEndDate) . "&value1=" . strtotime($newStartDate) . "&value2=" . strtotime($newEndDate); - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesQuerie); - unset($filterApiResult); + $this->pbs2Api->changeFilterentry($event->getPbs_filterID(), strtotime($oldStartDate), strtotime($oldEndDate), strtotime($newStartDate), strtotime($newEndDate)); } } else { - $filterentriesQuerie = "filterid=" . $event->getPbs_filterID() . "&oldvalue1=" . strtotime($oldStartDate) . "&oldvalue2=" . strtotime($oldEndDate) . "&value1=" . strtotime($newStartDate) . "&value2=" . strtotime($newEndDate); - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesQuerie); - unset($filterApiResult); + $this->pbs2Api->changeFilterentry($event->getPbs_filterID(), strtotime($oldStartDate), strtotime($oldEndDate), strtotime($newStartDate), strtotime($newEndDate)); } if($count == 1) { - $filterentriesQuerie = "filterid=" . $event->getPbs_filterID() . "&oldvalue1=" . $oldStartTime . "&oldvalue2=" . $oldEndTime . "&value1=" . $newStartTime . "&value2=" . $newEndTime; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesQuerie); - unset($filterApiResult); + $this->pbs2Api->changeFilterentry($event->getPbs_filterID(), $oldStartTime, $oldEndTime, $newStartTime, $newEndTime); } } } @@ -1404,43 +1212,25 @@ class EventController extends Zend_Controller_Action if($event->getCategory() != $shutdownCategory->getID()) { if($event->getPbs_filterID()) { if($oldEvent->getRepeat() == 0 || $oldEvent->getRepeat() == 2) { - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "filterid=" . $oldEvent->getPbs_filterID()); - unset($filterApiResult); - } - $filterquery = "bootmenuID=" . $event->getPbs_bootmenuID() . "&title=Poolctrl-Filter for " . $event->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $event->getTitle() . "&created= " . time() . "&priority=100"; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterquery); - $filterXMLString = $filterApiResult['http-body']; - $filterXML = new SimpleXMLElement($filterXMLString); - $filterID = sprintf("%s", $filterXML->filter->id); + $this->pbs2Api->deleteFilter($oldEvent->getPbs_filterID()); + } + $filterID = $this->pbs2Api->addFilter($event->getTitle(), $event->getPbs_bootmenuID()); $event->setPbs_filterID($filterID); - $filterentriesquery1 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=3&filtervalue=" . $event->getPbs_poolID(); - $filterentriesApiResult1 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery1); - $filterentriesXMLString1 = $filterentriesApiResult1['http-body']; - $filterentriesXML1 = new SimpleXMLElement($filterentriesXMLString1); - $filterentriesID1 = sprintf("%s", $filterentriesXML1->filterentry->id); $startTime = date('H:i', strtotime($event->getStart())); if($event->getEnd()) { $endTime = date('H:i', strtotime($event->getEnd())); } else { $endTime = date('H:i', strtotime($event->getStart()) + 900); } - $filterentriesquery2 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=7&filtervalue=" . $startTime . "&filtervalue2=" . $endTime; - $filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2); - $filterentriesXMLString2 = $filterentriesApiResult2['http-body']; - $filterentriesXML2 = new SimpleXMLElement($filterentriesXMLString2); - $filterentriesID2 = sprintf("%s", $filterentriesXML2->filterentry->id); + $filterentriesID1 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 7, $startTime, $endTime); + $filterentriesID2 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 3, $event->getPbs_poolID(), ''); $startDate = date('d.m.Y', strtotime($event->getStart())); if($event->getEnd()) { $endDate = date('d.m.Y', strtotime($event->getEnd())); } else { $endDate = date('d.m.Y', strtotime($event->getStart())); } - $filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); - } + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate));date('d.m.Y', strtotime($event->getStart())); } } $this->eventMapper->save($event); //save the event with the new data } @@ -1494,9 +1284,7 @@ class EventController extends Zend_Controller_Action $shutdownCategory = $result[0]; if($event->getCategory() != $shutdownCategory->getID()) { if($event->getPbs_filterID()) { - $filterentriesQuerie = "filterid=" . $event->getPbs_filterID() . "&oldvalue1=" . $oldStartTime . "&oldvalue2=" . $oldEndTime . "&value1=" . $newStartTime . "&value2=" . $newEndTime; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesQuerie); - unset($filterApiResult); + $this->pbs2Api->changeFilterentry($event->getPbs_filterID(), $oldStartTime, $oldEndTime, $newStartTime, $newEndTime); } } } @@ -1544,11 +1332,7 @@ class EventController extends Zend_Controller_Action foreach($otherEvents as $event) { $event->setRepeat(2); - $filterquery = "bootmenuID=" . $event->getPbs_bootmenuID() . "&title=Poolctrl-Filter for " . $event->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $event->getTitle() . "&created= " . time() . "&priority=100"; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterquery); - $filterXMLString = $filterApiResult['http-body']; - $filterXML = new SimpleXMLElement($filterXMLString); - $filterID = sprintf("%s", $filterXML->filter->id); + $filterID = $this->pbs2Api->addFilter($event->getTitle(), $event->getPbs_bootmenuID()); $event->setPbs_filterID($filterID); $startTime = date('H:i', strtotime($event->getStart())); if($event->getEnd()) { @@ -1556,27 +1340,15 @@ class EventController extends Zend_Controller_Action } else { $endTime = date('H:i', strtotime($event->getStart()) + 900); } - $filterentriesquery1 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=7&filtervalue=" . $startTime . "&filtervalue2=" . $endTime; - $filterentriesApiResult1 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery1); - $filterentriesXMLString1 = $filterentriesApiResult1['http-body']; - $filterentriesXML1 = new SimpleXMLElement($filterentriesXMLString1); - $filterentriesID1 = sprintf("%s", $filterentriesXML1->filterentry->id); - $filterentriesquery2 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=3&filtervalue=" . $event->getPbs_poolID(); - $filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2); - $filterentriesXMLString2 = $filterentriesApiResult2['http-body']; - $filterentriesXML2 = new SimpleXMLElement($filterentriesXMLString2); - $filterentriesID2 = sprintf("%s", $filterentriesXML2->filterentry->id); + $filterentriesID1 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 7, $startTime, $endTime); + $filterentriesID2 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 3, $event->getPbs_poolID(), ''); $startDate = date('d.m.Y', strtotime($event->getStart())); if($event->getEnd()) { $endDate = date('d.m.Y', strtotime($event->getEnd())); } else { $endDate = date('d.m.Y', strtotime($event->getStart())); } - $filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); try { $this->eventMapper->save($event); //save the event with the new data } catch (Zend_Exception $e) { @@ -1622,9 +1394,7 @@ class EventController extends Zend_Controller_Action $shutdownCategory = $result[0]; if($event->getCategory() != $shutdownCategory->getID()) { if($event->getPbs_filterID()) { - $filterentriesQuerie = "filterid=" . $event->getPbs_filterID() . "&oldvalue1=" . $oldStartTime . "&oldvalue2=" . $oldEndTime . "&value1=" . $newStartTime . "&value2=" . $newEndTime; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesQuerie); - unset($filterApiResult); + $this->pbs2Api->changeFilterentry($event->getPbs_filterID(), $oldStartTime, $oldEndTime, $newStartTime, $newEndTime); } } } @@ -1802,65 +1572,15 @@ class EventController extends Zend_Controller_Action } else { $data['force'] = false; } - $poolRequest = "poolid=" . $event->getPbs_poolID(); - $this->config['pbs2']['getpools']; - $poolApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getpools'] . $apikey, 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $poolRequest); - $poolXMLString = $poolApiResult['http-body']; $clients = array(); - if(strlen($poolXMLString) > 0) { - $poolXML = new SimpleXMLElement($poolXMLString); - foreach($poolXML->poollist->pool as $pool) { - $clientsXML = $pool->clients; - $count = 1; - foreach($clientsXML->client as $clientNew) { - $participants = $event->getParticipants(); - if(!isset($participants) || ($participants > 0 && $event->getParticipants() >= $count)) { - $client = new Application_Model_Client(); - $client->setID(sprintf("%s", $clientNew->clientID)); - $client->setCreated(sprintf("%s", $clientNew->created)); - $client->setGroupID(sprintf("%s", $clientNew->groupid)); - $client->setHardwarehash(sprintf("%s", $clientNew->location)); - $client->setIp(sprintf("%s", $clientNew->ip)); - $client->setIp6(sprintf("%s", $clientNew->ip6)); - $client->setMacadress(sprintf("%s", $clientNew->macadress)); - $clientArray = array( - 'id' => $client->getID(), - 'ip' => $client->getIp(), - 'mac' => $client->getMacadress()); - $clients[] = $clientArray; - $count++; - } else { - break; - } - } - } - } + $this->pbs2Api->getPoolClients($clients, $event->getPbs_poolID()); $data['clients'] = $clients; if($boot) { - $bootOsRequest = "bootosid=" . $event->getPbs_bootosID(); - $bootOsApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getbootoss'] . $apikey, 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $bootOsRequest); - $bootOsXMLString = $bootOsApiResult['http-body']; - if(strlen($bootOsXMLString) > 0) { - $bootOsXML = new SimpleXMLElement($bootOsXMLString); - foreach($bootOsXML->bootoslist->bootos as $bootosNew) { - $bootos = new Application_Model_BootOs(); - $bootos->setID(sprintf("%s", $bootosNew->id)); - $bootos->setCreated(sprintf("%s", $bootosNew->created)); - $bootos->setDefaultkcl(sprintf("%s", $bootosNew->defaultkcl)); - $bootos->setDescription(sprintf("%s", $bootosNew->description)); - $bootos->setDistro(sprintf("%s", $bootosNew->distro)); - $bootos->setDistroversion(sprintf("%s", $bootosNew->distroversion)); - $bootos->setExpires(sprintf("%s", $bootosNew->expires)); - $bootos->setGroupID(sprintf("%s", $bootosNew->groupid)); - $bootos->setMembershipID(sprintf("%s", $bootosNew->membershipid)); - $bootos->setPublic(sprintf("%s", $bootosNew->public)); - $bootos->setShare(sprintf("%s", $bootosNew->share)); - $bootos->setShortname(sprintf("%s", $bootosNew->shortname)); - $bootos->setSource(sprintf("%s", $bootosNew->source)); - $bootos->setTitle(sprintf("%s", $bootosNew->title)); - } - $data['eventOS'] = $bootos->getDistro() . " " . $bootos->getDistroversion(); - } + $bootoslist = array(); + $configlist = array(); + $this->pbs2Api->getBootos($bootoslist, $configlist); + $bootos = $bootoslist[0]; + $data['eventOS'] = $bootos->getDistro() . " " . $bootos->getDistroversion(); $dataString = json_encode($data); $result = $this->gearmanClient->do("boot", $dataString, 'boot' . $event->getTitle()); if (! $this->gearmanClient->runTasks()) @@ -2115,22 +1835,10 @@ class EventController extends Zend_Controller_Action $reportlist[$i]->setType($reportType); } - $clientRequest = "poolid=" . $event->getPbs_poolID(); - $clientApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getclient'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $clientRequest); - $clientXMLString = $clientApiResult['http-body']; - if(strlen($clientXMLString) > 0) { - $clientXML = new SimpleXMLElement($clientXMLString); - foreach($clientXML->clientlist->client as $clientNew) { - $client = new Application_Model_Client(); - $client->setID(sprintf("%s", $clientNew->clientID)); - $client->setCreated(sprintf("%s", $clientNew->created)); - $client->setGroupID(sprintf("%s", $clientNew->groupid)); - $client->setHardwarehash(sprintf("%s", $clientNew->location)); - $client->setIp(sprintf("%s", $clientNew->ip)); - $client->setIp6(sprintf("%s", $clientNew->ip6)); - $client->setMacadress(sprintf("%s", $clientNew->macadress)); - $clients[$client->getID()] = $client; - } + $clientlist = array(); + $this->pbs2Api->getPoolClients($clientlist, $event->getPbs_poolID()); + foreach($clientlist as $client) { + $clients[$client->getID()] = $client; } $this->view->eventTitle = $event->getTitle(); @@ -2187,37 +1895,8 @@ class EventController extends Zend_Controller_Action } else { $data['force'] = false; } - $poolRequest = "poolid=" . $event->getPbs_poolID(); - $this->config['pbs2']['getpools']; - $poolApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getpools'] . $apikey, 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $poolRequest); - $poolXMLString = $poolApiResult['http-body']; - if(strlen($poolXMLString) > 0) { - $poolXML = new SimpleXMLElement($poolXMLString); - foreach($poolXML->poollist->pool as $pool) { - $clientsXML = $pool->clients; - $count = 1; - foreach($clientsXML->client as $clientNew) { - if($event->getImmediate() || ($event->getParticipants() > 0 && $event->getParticipants() > $count)) { - $client = new Application_Model_Client(); - $client->setID(sprintf("%s", $clientNew->clientID)); - $client->setCreated(sprintf("%s", $clientNew->created)); - $client->setGroupID(sprintf("%s", $clientNew->groupid)); - $client->setHardwarehash(sprintf("%s", $clientNew->location)); - $client->setIp(sprintf("%s", $clientNew->ip)); - $client->setIp6(sprintf("%s", $clientNew->ip6)); - $client->setMacadress(sprintf("%s", $clientNew->macadress)); - $clientArray = array( - 'id' => $client->getID(), - 'ip' => $client->getIp(), - 'mac' => $client->getMacadress()); - $clients[] = $clientArray; - $count++; - } else { - break; - } - } - } - } + $clients = array(); + $this->pbs2Api->getPoolClients($clients, $event->getPbs_poolID()); $data['clients'] = $clients; $result = $this->eventcategoryMapper->fetchAll(); foreach($result as $category) { @@ -2259,30 +1938,11 @@ class EventController extends Zend_Controller_Action } $runningtypeMapper = new Application_Model_RunningtypeMapper(); if($boot) { - $bootOsRequest = "bootosid=" . $event->getPbs_bootosID(); - $bootOsApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getbootoss'] . $apikey, 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $bootOsRequest); - $bootOsXMLString = $bootOsApiResult['http-body']; - if(strlen($bootOsXMLString) > 0) { - $bootOsXML = new SimpleXMLElement($bootOsXMLString); - foreach($bootOsXML->bootoslist->bootos as $bootosNew) { - $bootos = new Application_Model_BootOs(); - $bootos->setID(sprintf("%s", $bootosNew->id)); - $bootos->setCreated(sprintf("%s", $bootosNew->created)); - $bootos->setDefaultkcl(sprintf("%s", $bootosNew->defaultkcl)); - $bootos->setDescription(sprintf("%s", $bootosNew->description)); - $bootos->setDistro(sprintf("%s", $bootosNew->distro)); - $bootos->setDistroversion(sprintf("%s", $bootosNew->distroversion)); - $bootos->setExpires(sprintf("%s", $bootosNew->expires)); - $bootos->setGroupID(sprintf("%s", $bootosNew->groupid)); - $bootos->setMembershipID(sprintf("%s", $bootosNew->membershipid)); - $bootos->setPublic(sprintf("%s", $bootosNew->public)); - $bootos->setShare(sprintf("%s", $bootosNew->share)); - $bootos->setShortname(sprintf("%s", $bootosNew->shortname)); - $bootos->setSource(sprintf("%s", $bootosNew->source)); - $bootos->setTitle(sprintf("%s", $bootosNew->title)); - } - $data['eventOS'] = $bootos->getDistro() . " " . $bootos->getDistroversion(); - } + $bootoslist = array(); + $configlist = array(); + $this->pbs2Api->getBootos($bootoslist, $configlist); + $bootos = $bootoslist[0]; + $data['eventOS'] = $bootos->getDistro() . " " . $bootos->getDistroversion(); $dataString = json_encode($data); $result = $this->gearmanClient->do("boot", $dataString, 'boot' . $event->getTitle()); if (! $this->gearmanClient->runTasks()) @@ -2351,11 +2011,7 @@ class EventController extends Zend_Controller_Action switch($repeattype->getTitle()) { case 'Daily': if($newEvent->getCategory() != $shutdownCategory->getID()) { - $filterentriesquery3 = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } $onedaytime = 24 * 60 * 60; $newStartTime = strtotime($newEvent->getStart()) + $onedaytime; @@ -2401,11 +2057,7 @@ class EventController extends Zend_Controller_Action } else { $endDate = date('d.m.Y', strtotime($newEvent->getStart())); } - $filterentriesquery = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery); - $filterentriesXMLString = $filterentriesApiResult['http-body']; - $filterentriesXML = new SimpleXMLElement($filterentriesXMLString); - $filterentriesID = sprintf("%s", $filterentriesXML->filterentry->id); + $filterentriesID = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } $newEvent = clone $newEvent; } @@ -2449,11 +2101,7 @@ class EventController extends Zend_Controller_Action } else { $endDate = date('d.m.Y', strtotime($newEvent->getStart())); } - $filterentriesquery = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery); - $filterentriesXMLString = $filterentriesApiResult['http-body']; - $filterentriesXML = new SimpleXMLElement($filterentriesXMLString); - $filterentriesID = sprintf("%s", $filterentriesXML->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } $newEvent = clone $newEvent; $i++; @@ -2465,11 +2113,7 @@ class EventController extends Zend_Controller_Action case 'Once a week': if($newEvent->getCategory() != $shutdownCategory->getID()) { $weekday = date('N', strtotime($newEvent->getStart())); - $filterentriesquery3 = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=10&filtervalue=" . $weekday . "&filtervalue2=" . $weekday; - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($newEvent->getPbs_filterID(), 10, $weekday, $weekday); } $oneweektime = 7 * 24 * 60 * 60; $newStartTime = strtotime($newEvent->getStart()) + $oneweektime; @@ -2552,11 +2196,7 @@ class EventController extends Zend_Controller_Action case 'Every couple of weeks': if($newEvent->getCategory() != $shutdownCategory->getID()) { - $filterentriesquery3 = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } $twoweekstime = 14 * 24 * 60 * 60; $newStartTime = strtotime($newEvent->getStart()) + $twoweekstime; @@ -2602,11 +2242,7 @@ class EventController extends Zend_Controller_Action } else { $endDate = date('d.m.Y', strtotime($newEvent->getStart())); } - $filterentriesquery = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery); - $filterentriesXMLString = $filterentriesApiResult['http-body']; - $filterentriesXML = new SimpleXMLElement($filterentriesXMLString); - $filterentriesID = sprintf("%s", $filterentriesXML->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } $newEvent = clone $newEvent; } @@ -2650,11 +2286,7 @@ class EventController extends Zend_Controller_Action } else { $endDate = date('d.m.Y', strtotime($newEvent->getStart())); } - $filterentriesquery = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery); - $filterentriesXMLString = $filterentriesApiResult['http-body']; - $filterentriesXML = new SimpleXMLElement($filterentriesXMLString); - $filterentriesID = sprintf("%s", $filterentriesXML->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } $newEvent = clone $newEvent; $i++; @@ -2665,11 +2297,7 @@ class EventController extends Zend_Controller_Action case 'Every month': if($newEvent->getCategory() != $shutdownCategory->getID()) { - $filterentriesquery3 = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } $startMonth = date('m', strtotime($newEvent->getStart())) + 1; $startDay = date('d', strtotime($newEvent->getStart())); @@ -2756,11 +2384,7 @@ class EventController extends Zend_Controller_Action } else { $endDate = date('d.m.Y', strtotime($newEvent->getStart())); } - $filterentriesquery = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery); - $filterentriesXMLString = $filterentriesApiResult['http-body']; - $filterentriesXML = new SimpleXMLElement($filterentriesXMLString); - $filterentriesID = sprintf("%s", $filterentriesXML->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } $newEvent = clone $newEvent; } @@ -2812,11 +2436,7 @@ class EventController extends Zend_Controller_Action } else { $endDate = date('d.m.Y', strtotime($newEvent->getStart())); } - $filterentriesquery = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery); - $filterentriesXMLString = $filterentriesApiResult['http-body']; - $filterentriesXML = new SimpleXMLElement($filterentriesXMLString); - $filterentriesID = sprintf("%s", $filterentriesXML->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($event->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } $newEvent = clone $newEvent; $i++; @@ -2853,10 +2473,10 @@ class EventController extends Zend_Controller_Action } } else { if($events[0]->getPbs_bootmenuID()) { - $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletebootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "bootmenuid=" . $events[0]->getPbs_bootmenuID()); + $this->pbs2Api->deleteBootmenu($event->getPbs_bootmenuID()); } if($events[0]->getPbs_filterID()) { - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "filterid=" . $events[0]->getPbs_filterID()); + $this->pbs2Api->deleteFilter($event->getPbs_filterID()); } } @@ -2921,18 +2541,6 @@ class EventController extends Zend_Controller_Action } $event->setEnd($newEnd); } - if($newEvent->getCategory() != $shutdownCategory->getID()) { - if($repeattype != "Once a week") { - $startDate = date('d.m.Y', strtotime($event->getStart())); - if($event->getEnd()) { - $endDate = date('d.m.Y', strtotime($event->getEnd())); - } else { - $endDate = date('d.m.Y', strtotime($event->getStart()) + 900); - } - $filterentriesquery2 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2); - } - } } } @@ -2949,41 +2557,25 @@ class EventController extends Zend_Controller_Action if(isset($diff['pbs_bootosID']) || isset($diff['title']) || isset($diff['pbs_configID'])) { $bootmenuquery = "bootmenuid=" . $newEvent->getPbs_bootmenuID() . "&bootosID=" . $newEvent->getPbs_bootosID() . "&startcounter=0&title=Poolctrl-Bootmenu for " . $newEvent->getTitle() . "&defaultbootmenu=0&order=0&kcl=0&changeentry=1"; if($newEvent->getPbs_configID()) { - $bootmenuquery .= "&configID=" . $newEvent->getPbs_configID(); + $this->pbs2Api->changeBootmenu($oldEvent->getPbs_bootmenuID(), $newEvent->getTitle(), $newEvent->getPbs_bootosID(), $newEvent->getPbs_configID()); + } else { + $this->pbs2Api->changeBootmenu($oldEvent->getPbs_bootmenuID(), $newEvent->getTitle(), $newEvent->getPbs_bootosID()); } - $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changebootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $bootmenuquery); } - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "filterid=" . $oldEvent->getPbs_filterID()); - unset($filterApiResult); - $filterquery = "bootmenuID=" . $newEvent->getPbs_bootmenuID() . "&title=Poolctrl-Filter for " . $newEvent->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $newEvent->getTitle() . "&created= " . time() . "&priority=100"; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterquery); - $filterXMLString = $filterApiResult['http-body']; - $filterXML = new SimpleXMLElement($filterXMLString); - $filterID = sprintf("%s", $filterXML->filter->id); + $this->pbs2Api->deleteFilter($oldEvent->getPbs_filterID()); + $filterID = $this->pbs2Api->addFilter($newEvent->getTitle(), $newEvent->getPbs_bootmenuID()); $newEvent->setPbs_filterID($filterID); - $filterentriesquery1 = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=3&filtervalue=" . $newEvent->getPbs_poolID(); - $filterentriesApiResult1 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery1); - $filterentriesXMLString1 = $filterentriesApiResult1['http-body']; - $filterentriesXML1 = new SimpleXMLElement($filterentriesXMLString1); - $filterentriesID1 = sprintf("%s", $filterentriesXML1->filterentry->id); $startTime = date('H:i', strtotime($newEvent->getStart())); if($newEvent->getEnd()) { $endTime = date('H:i', strtotime($newEvent->getEnd())); } else { $endTime = date('H:i', strtotime($newEvent->getStart()) + 900); } - $filterentriesquery2 = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=7&filtervalue=" . $startTime . "&filtervalue2=" . $endTime; - $filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2); - $filterentriesXMLString2 = $filterentriesApiResult2['http-body']; - $filterentriesXML2 = new SimpleXMLElement($filterentriesXMLString2); - $filterentriesID2 = sprintf("%s", $filterentriesXML2->filterentry->id); + $filterentriesID1 = $this->pbs2Api->addFilterentry($newEvent->getPbs_filterID(), 7, $startTime, $endTime); + $filterentriesID2 = $this->pbs2Api->addFilterentry($newEvent->getPbs_filterID(), 3, $event->getPbs_poolID(), ''); if($repeattype == "Once a week") { $weekday = date('N', strtotime($diff['start'])); - $filterentriesquery3 = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=10&filtervalue=" . $weekday . "&filtervalue2=" . $weekday; - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID = sprintf("%s", $filterentriesXML1->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($newEvent->getPbs_filterID(), 10, $weekday, $weekday); } } foreach($events as $event) { @@ -2995,11 +2587,7 @@ class EventController extends Zend_Controller_Action } else { $endDate = date('d.m.Y', strtotime($event->getStart())); } - $filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($newEvent->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } try { $this->eventMapper->save($event); @@ -3017,41 +2605,31 @@ class EventController extends Zend_Controller_Action if(isset($diff['pbs_bootosID']) || isset($diff['title']) || isset($diff['pbs_configID'])) { $bootmenuquery = "bootmenuid=" . $newEvent->getPbs_bootmenuID() . "&bootosID=" . $newEvent->getPbs_bootosID() . "&startcounter=0&title=Poolctrl-Bootmenu for " . $newEvent->getTitle() . "&defaultbootmenu=0&order=0&kcl=0&changeentry=1"; if($newEvent->getPbs_configID()) { - $bootmenuquery .= "&configID=" . $newEvent->getPbs_configID(); + $this->pbs2Api->changeBootmenu($oldEvent->getPbs_bootmenuID(), $newEvent->getTitle(), $newEvent->getPbs_bootosID(), $newEvent->getPbs_configID()); + } else { + $this->pbs2Api->changeBootmenu($oldEvent->getPbs_bootmenuID(), $newEvent->getTitle(), $newEvent->getPbs_bootosID()); } - $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changebootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $bootmenuquery); } if(isset($diff['title'])) { - $filterQuerie = "filterid=" . $newEvent->getPbs_filterID() . "&title=Poolctrl-Filter for " . $newEvent->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $newEvent->getTitle(); - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterQuerie); - unset($filterApiResult); + $this->pbs2Api->changeFilter($newEvent->getPbs_filterID(), $newEvent->getTitle()); } $newFilter = false; if(isset($diff['pbs_poolID'])) { - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "filterid=" . $oldEvent->getPbs_filterID()); - unset($filterApiResult); - $filterquery = "filterID=" . $newEvent->getPbs_bootmenuID() . "&title=Poolctrl-Filter for " . $newEvent->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $newEvent->getTitle() . "&created= " . time() . "&priority=100"; - $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterquery); - $filterXMLString = $filterApiResult['http-body']; - $filterXML = new SimpleXMLElement($filterXMLString); - $filterID = sprintf("%s", $filterXML->filter->id); + $this->pbs2Api->deleteFilter($oldEvent->getPbs_filterID()); + $filterID = $this->pbs2Api->addFilter($newEvent->getTitle(), $newEvent->getPbs_bootmenuID()); $newEvent->setPbs_filterID($filterID); - $filterentriesquery1 = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=3&filtervalue=" . $newEvent->getPbs_poolID(); - $filterentriesApiResult1 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery1); - $filterentriesXMLString1 = $filterentriesApiResult1['http-body']; - $filterentriesXML1 = new SimpleXMLElement($filterentriesXMLString1); - $filterentriesID1 = sprintf("%s", $filterentriesXML1->filterentry->id); $startTime = date('H:i', strtotime($newEvent->getStart())); if($newEvent->getEnd()) { $endTime = date('H:i', strtotime($newEvent->getEnd())); } else { $endTime = date('H:i', strtotime($newEvent->getStart()) + 900); } - $filterentriesquery2 = "filterID=" . $newEvent->getPbs_filterID() . "&filtertypeID=7&filtervalue=" . $startTime . "&filtervalue2=" . $endTime; - $filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2); - $filterentriesXMLString2 = $filterentriesApiResult2['http-body']; - $filterentriesXML2 = new SimpleXMLElement($filterentriesXMLString2); - $filterentriesID2 = sprintf("%s", $filterentriesXML2->filterentry->id); + $filterentriesID1 = $this->pbs2Api->addFilterentry($newEvent->getPbs_filterID(), 7, $startTime, $endTime); + $filterentriesID2 = $this->pbs2Api->addFilterentry($newEvent->getPbs_filterID(), 3, $event->getPbs_poolID(), ''); + if($repeattype == "Once a week") { + $weekday = date('N', strtotime($diff['start'])); + $filterentriesID3 = $this->pbs2Api->addFilterentry($newEvent->getPbs_filterID(), 10, $weekday, $weekday); + } $newFilter = true; } } @@ -3061,18 +2639,14 @@ class EventController extends Zend_Controller_Action $event->setOptions($diff); if($newFilter) { $event->setPbs_filterID($newEvent->getPbs_filterID()); - if($event->getCategory() != $shutdownCategory->getID() && isset($diff['pbs_poolID'])) { + if($repeattype != "Once a week" && $event->getCategory() != $shutdownCategory->getID() && isset($diff['pbs_poolID'])) { $startDate = date('d.m.Y', strtotime($event->getStart())); if($event->getEnd()) { $endDate = date('d.m.Y', strtotime($event->getEnd())); } else { $endDate = date('d.m.Y', strtotime($event->getStart())); } - $filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . strtotime($startDate) . "&filtervalue2=" . strtotime($endDate); - $filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3); - $filterentriesXMLString3 = $filterentriesApiResult3['http-body']; - $filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3); - $filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentry->id); + $filterentriesID3 = $this->pbs2Api->addFilterentry($newEvent->getPbs_filterID(), 11, strtotime($startDate), strtotime($endDate)); } } if(!$event->getParticipants()) { diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php index 65757c1..ad61927 100755 --- a/application/controllers/IndexController.php +++ b/application/controllers/IndexController.php @@ -4,6 +4,7 @@ class IndexController extends Zend_Controller_Action { protected $config; protected $pbs2host; + protected $pbs2Api; protected $userNamespace; protected $acl; @@ -12,6 +13,7 @@ class IndexController extends Zend_Controller_Action $bootstrap = $this->getInvokeArg('bootstrap'); $this->config = $bootstrap->getOptions(); $this->pbs2host = $this->config['pbs2']['host']; + $this->pbs2Api = new Poolctrl_Pbs2Api($this->config); $this->userIDsNamespace = Zend_Session::namespaceGet('userIDs'); if(isset($this->userIDsNamespace['apikey'])) { $this->acl = new Poolctrl_Acl($this->pbs2host, $this->config['pbs2']['checkright'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); diff --git a/application/controllers/PersonController.php b/application/controllers/PersonController.php index 09638cc..72ef196 100755 --- a/application/controllers/PersonController.php +++ b/application/controllers/PersonController.php @@ -16,6 +16,7 @@ class PersonController extends Zend_Controller_Action protected $currentMembership = null; protected $memberships = null; protected $groups = null; + protected $pbs2Api; protected $userIDsNamespace = null; protected $config; protected $pbs2host; @@ -27,6 +28,7 @@ class PersonController extends Zend_Controller_Action $bootstrap = $this->getInvokeArg('bootstrap'); $this->config = $bootstrap->getOptions(); $this->pbs2host = $this->config['pbs2']['host']; + $this->pbs2Api = new Poolctrl_Pbs2Api($this->config); $this->userIDsNamespace = Zend_Session::namespaceGet('userIDs'); if(isset($this->userIDsNamespace['apikey'])) { $this->acl = new Poolctrl_Acl($this->pbs2host, $this->config['pbs2']['checkright'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); @@ -81,17 +83,7 @@ class PersonController extends Zend_Controller_Action if($useGroupnamespace) { $group = $groups[$groupID]; } else { - $grouprequest = "groupid=" . $groupID; - $groupApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getgroup'] . $membership->getApikey(), 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $grouprequest); - $groupXMLString = $groupApiResult['http-body']; - if(strlen($groupXMLString) > 0) { - $groupXML = new SimpleXMLElement($groupXMLString); - $group = new Application_Model_Group(); - $group->setID(sprintf("%s", $groupXML->group->id)); - $group->setTitle(sprintf("%s", $groupXML->group->title)); - $group->setDescription(sprintf("%s", $groupXML->group->description)); - $groupSession->$groupID = $group; - } + $this->pbs2Api->getGroup($groupSession, $groupID); } $roleID = $membership->getRoleID(); if($useRolenamespace) { @@ -100,15 +92,7 @@ class PersonController extends Zend_Controller_Action $roleApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getrole'] . $membership->getApikey(), 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); $roleXMLString = $roleApiResult['http-body']; if(strlen($roleXMLString) > 0) { - $roleXML = new SimpleXMLElement($roleXMLString); - $role = new Application_Model_Role(); - $role->setID(sprintf("%s", $roleXML->role->id)); - $role->setGroupID(sprintf("%s", $roleXML->role->groupid)); - $role->setTitle(sprintf("%s", $roleXML->role->title)); - $role->setDescription(sprintf("%s", $roleXML->role->description)); - $role->setInheritance(sprintf("%s", $roleXML->role->inheritance)); - - $roleSession->$roleID = $role; + $this->pbs2Api->getRole($roleSession, $roleID); } } $apikeys[$group->getID()] = $membership->getApikey(); diff --git a/application/controllers/StatisticsController.php b/application/controllers/StatisticsController.php index 7416ec5..5bf798e 100755 --- a/application/controllers/StatisticsController.php +++ b/application/controllers/StatisticsController.php @@ -3,6 +3,7 @@ class StatisticsController extends Zend_Controller_Action { protected $config; protected $pbs2host; + protected $pbs2Api; protected $eventMapper; protected $eventcategoryMapper; protected $eventreportMapper; @@ -14,6 +15,7 @@ class StatisticsController extends Zend_Controller_Action $bootstrap = $this->getInvokeArg('bootstrap'); $this->config = $bootstrap->getOptions(); $this->pbs2host = $this->config['pbs2']['host']; + $this->pbs2Api = new Poolctrl_Pbs2Api($this->config); $this->eventMapper = new Application_Model_EventMapper(); $this->eventcategoryMapper = new Application_Model_EventcategoryMapper(); $this->eventreportMapper = new Application_Model_EventreportMapper(); -- cgit v1.2.3-55-g7522