summaryrefslogblamecommitdiffstats
path: root/application/controllers/EventController.php
blob: 7bf704eadd7c6ddb53d943dbe31f2033423d6643 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
     









                                                                           


                                                    
                               
                                       

                            
                                    
                       


                              
                                                              
                                                                      

                                                                        
                                                                                        


                                                                                                                                                                                                                     


                                                                                                         
                                
                                                                                         





                                                                    



                                     
                                                                                                                         
                                        
                                                                                                                                                                                                                             
                                                                         
                                                          


















                                                                                                            
                         
                                                                                                                                                                                                                         
                                                                     
                                                        









                                                                                                    
                         

                                                              
                                                                         
                                                                                                             




                                                                                                             
                                         



































                                                                                                                                                                                                                                           
                                         
                                 
                                                                                                               


                                                                                                     
                                                                            

                         

                                                           
                                                    
                                                  



                                   
                                                                            
                                                                                                                                                                                                                     
                                                                 
                                                  


















                                                                                                    
                 
                                                                                                                                                                                                                 
                                                             
                                                









                                                                                            
                 

                                                            
                                                                                                                                                                         
                        
                                                                                                                                                                                                           
                                                                                  
                                                                                                                                              


                                                                                                                                                  
                                                                                                       
                                                                                                     
                                                                                                                                                                              
                                                                                                                                                                                                                                                    



                                                                                        





                                                                                                                                                                                                                                              
                                                                                        




                                                                                                    
                                                                                                                                                                           
                                                                                                                                                                                                                                                                    


                                                                                                       
                                                                                                                                                          
                                                                                                                                                                                                                                                                    





                                                                                                                                                                                  
                                                                                                                                                                                                                                                                            










                                                                                                                                                                                    
                                                                                                                                                                                                                                                                            



                                                                                                               







                                                                                            
                                                            

                         

                                                           








                                                                
                                                         
                                                                                                                                                                                                                                                                                    

                                                       
                                                                                                                                                                                                                                                                              
                         








                                                                                    
                                                    


                                                    




                                    
                                                                            
                                                                                                                                                                                                                     
                                                                 
                                                  


















                                                                                                    
                 
                                                                                                                                                                                                                 
                                                             
                                                









                                                                                            
                 
                                                                



                                                                   

                                                                      
                                                                                                                                                                                                                     
                                                                                           
                                                                                                                                                      


                                                                                                                                                          


                                                                                   
                                                                                                                                                                                                                                                                                                    
                                                                          

                                                                       
                                                                                                                                                                                                                                                                                              
                                                                        
                                         
                                                                                             
                                                                
                                                                                                                                                                                      
                                                                                                                                                                                                                                                            



                                                                                                





                                                                                                                                                                                                                                                      
                                                                                                




                                                                                                            
                                                                                                                                                                                   
                                                                                                                                                                                                                                                                            


                                                                                                               
                                                                                                                                                                  
                                                                                                                                                                                                                                                                            





                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                    















                                                                                                                                                                                                                                                                              







                                                                                                    
                                                                    



                                                                           
                                                                                           
                                                                                             










                                                                                                                 
                                                                                                                                                                                                         

                                                          
                                                      

                 
 
                                      



                                                            

                                   
 
                                       
                      




                                                             


                                        




                                                             




                                       
 
<?php
/*
 * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg
 * This program is free software distributed under the GPL version 2.
 * See http://gpl.openslx.org/
 *
 * If you have any feedback please consult http://feedback.openslx.org/ and
 * send your suggestions, praise, or complaints to feedback@openslx.org
 *
 * General information about OpenSLX can be found at http://openslx.org/
 */

class EventController extends Zend_Controller_Action
{
	protected $eventMapper;
	protected $eventcategoryMapper;
	protected $config;
	protected $pbs2host;
	protected $userIDsNamespace;
	protected $acl;

	public function init()
	{
		if (Zend_Auth::getInstance()->hasIdentity()) {
			$bootstrap = $this->getInvokeArg('bootstrap');
			$this->config = $bootstrap->getOptions();
			$this->pbs2host = $this->config['pbs2']['host'];
			$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']);
			}
			if($this->userIDsNamespace['membershipID'] !='') {
				$this->eventMapper = new Application_Model_EventMapper();
				$this->eventcategoryMapper = new Application_Model_EventcategoryMapper();
			} else {
				$this->_helper->redirector('selectmembership', 'person');
				return;
			}
		} else {
			$this->_helper->redirector('login', 'auth');
			return;
		}
	}

	public function indexAction()
	{
		$events = $this->eventMapper->findBy(array("pbs_membershipID", $this->userIDsNamespace['membershipID']));
		if(count($events) > 0) {
			$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;
				}
			}
			$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;
				}
			}
			foreach($events as $eventObj) {
				$event = $eventObj->toArray();
				$bootos = new Application_Model_BootOs();
				$event['pbs_bootos_title'] = $bootoslist[$event['pbs_bootosID']]->getTitle();
				if($event['pbs_membershipID'] == $this->userIDsNamespace['membershipID']) {
					foreach(Zend_Session::namespaceGet('persons') as $person) {
						if($person->getID() == $this->userIDsNamespace['personID']) {
							break;
						}
					}
				} else {
					foreach(Zend_Session::namespaceGet('memberships') as $membership) {
						if($membership->getID() == $event['pbs_membershipID']) {
							break;
						}
					}
					$person = null;
					foreach(Zend_Session::namespaceGet('persons') as $sessionPerson) {
						if($sessionPerson->getID() == $membership->getPersonID()) {
							$person = $sessionPerson;
							break;
						}
					}
					if($person == null) {
						$personApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getperson'] . $membership->getApikey(), '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');
							$personID = $person->getID();
							$personSession->$personID = $person;
						}
					}
				}
				$event['pbs_person_name'] = $person->getFirstname() . " " . $person->getName();
				$eventcategory = new Application_Model_Eventcategory();
				$this->eventcategoryMapper->find($event['category'], $eventcategory);
				$event['category'] = $eventcategory->getTitle();
				$eventlist[$event['pbs_poolID']][] = $event;
			}
		}
		$params = $this->getRequest()->getParams();
		$this->view->params = $params;
		$this->view->eventlist = $eventlist;
		$this->view->poollist = $poollist;
	}

	public function addAction()
	{
		$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;
			}
		}
		$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;
			}
		}
		$add = $this->getRequest()->getParam("add");
		if (!isset($add)){
			$addForm = new Application_Form_EventAdd(array('eventcategorylist' => $eventcategorylist, 'bootoslist' => $bootoslist, 'poollist' => $poollist));
		} else {
			$addForm = new Application_Form_EventAdd(array('eventcategorylist' => $eventcategorylist, 'bootoslist' => $bootoslist, 'poollist' => $poollist, $this->getRequest()->getParams()));
			if ($addForm->isValid($this->getRequest()->getParams())) {
				$this->getRequest()->setParam('start', date ('Y-m-d H:i', strtotime($this->getRequest()->getParam('start'))));
				if($this->getRequest()->getParam('end')) {
					$this->getRequest()->setParam('end', date ('Y-m-d H:i', strtotime($this->getRequest()->getParam('end'))));
				}
				$event = new Application_Model_Event($this->getRequest()->getParams());
				$event->setPbs_membershipID($this->userIDsNamespace['membershipID']);
				$bootmenuquery = "bootosID=" . $event->getPbs_bootosID() . "&startcounter=0&title=" . $event->getTitle() . "&defaultbootmenu=1&order=0&kcl=0";
				$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->bootmenuid);
				$event->setPbs_bootmenuID($bootmenuID);
				$filterquery = "bootmenuID=" . $event->getPbs_bootmenuID() . "&title=" . $event->getTitle() . "&description=Poolctrl Filter für " . $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->filterid);
				$event->setPbs_filterID($filterID);
				$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));
				}
				$filterentriesquery1 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=7&filtervalue=" . $startTime . "&filtervalue2=" . $endTime;
				$filterentriesApiResult1 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentrie'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery1);
				$filterentriesXMLString1 = $filterentriesApiResult1['http-body'];
				$filterentriesXML1 = new SimpleXMLElement($filterentriesXMLString1);
				$filterentriesID1 = sprintf("%s", $filterentriesXML1->filterentriesid);
				$filterentriesquery2 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=3&filtervalue=" . $event->getPbs_poolID();
				$filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentrie'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2);
				$filterentriesXMLString2 = $filterentriesApiResult2['http-body'];
				$filterentriesXML2 = new SimpleXMLElement($filterentriesXMLString2);
				$filterentriesID2 = sprintf("%s", $filterentriesXML2->filterentriesid);
				if($event->getRepeat()) {
					$weekday = date('N', strtotime($event->getStart()));
					$filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=10&filtervalue=" . $weekday . "&filtervalue2=" . $weekday;
					$filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentrie'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3);
					$filterentriesXMLString3 = $filterentriesApiResult3['http-body'];
					$filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3);
					$filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentriesid);
				} else {
					$startDate = date('Y-m-d', strtotime($event->getStart()));
					if($event->getEnd()) {
						$endDate = date('Y-m-d', strtotime($event->getEnd()));
					} else {
						$endDate = date('Y-m-d', strtotime($event->getStart()));
					}
					$filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . $startDate . "&filtervalue2=" . $endDate;
					$filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentrie'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3);
					$filterentriesXMLString3 = $filterentriesApiResult3['http-body'];
					$filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3);
					$filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentriesid);
				}
				try {
					$eventID = $this->eventMapper->save($event);
				} catch(Zend_Exception $e)
				{
					echo "Caught exception: " . get_class($e) . "<br/>";
					echo "Message: " . $e->getMessage() . "<br/>";
					return;
				}
				$this->_redirect('/event/');
			}
		}
		$params = $this->getRequest()->getParams();
		$this->view->params = $params;
		$this->view->addForm = $addForm;
	}

	public function deleteAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$eventID = $this->_request->getParam('eventID');
		if(isset($eventID)) {
			$event = new Application_Model_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=" . $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=" . $event->getPbs_filterID());
			}
			$this->eventMapper->find($eventID, $event);
			try {
				$this->eventMapper->delete($event);
			} catch(Zend_Exception $e)
			{
				echo "Caught exception: " . get_class($e) . "<br/>";
				echo "Message: " . $e->getMessage() . "<br/>";
				return;
			}
			$this->_redirect('/event/');
		} else {
			$this->_redirect('/event/');
			return;
		}
	}

	public function editAction()
	{
		$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;
			}
		}
		$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;
			}
		}
		$eventID = $this->_request->getParam('eventID');
		if(!isset($eventID)) {
			$this->_helper->redirector('add', 'event');
			return;
		} else {
			$save = $this->getRequest()->getParam("save");
			if (isset($save)){
				$editForm = new Application_Form_EventEdit(array('eventcategorylist' => $eventcategorylist, 'bootoslist' => $bootoslist, 'poollist' => $poollist, $this->getRequest()->getParams()));
				if ($editForm->isValid($this->getRequest()->getParams())) {
					$this->getRequest()->setParam('start', date ('Y-m-d H:i', strtotime($this->getRequest()->getParam('start'))));
					if($this->getRequest()->getParam('end')) {
						$this->getRequest()->setParam('end', date ('Y-m-d H:i', strtotime($this->getRequest()->getParam('end'))));
					}
					$event = new Application_Model_Event();
					$this->eventMapper->find($eventID, $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=" . $event->getPbs_bootmenuID());
						unset($bootmenuApiResult);
					}
					if($event->getPbs_filterID()) {
						$filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "bootmenuid=" . $event->getPbs_filterID());
						unset($filterApiResult);
					}
					$event->setOptions($this->getRequest()->getParams());
					$event->setID($eventID);
					$bootmenuquery = "bootosID=" . $event->getPbs_bootosID() . "&startcounter=0&title=" . $event->getTitle() . "&defaultbootmenu=1&order=0&kcl=0";
					$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->bootmenuid);
					$event->setPbs_bootmenuID($bootmenuID);
					$filterquery = "bootmenuID=" . $event->getPbs_bootmenuID() . "&title=" . $event->getTitle() . "&description=Poolctrl Filter für " . $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->filterid);
					$event->setPbs_filterID($filterID);
					$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));
					}
					$filterentriesquery1 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=7&filtervalue=" . $startTime . "&filtervalue2=" . $endTime;
					$filterentriesApiResult1 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentrie'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery1);
					$filterentriesXMLString1 = $filterentriesApiResult1['http-body'];
					$filterentriesXML1 = new SimpleXMLElement($filterentriesXMLString1);
					$filterentriesID1 = sprintf("%s", $filterentriesXML1->filterentriesid);
					$filterentriesquery2 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=3&filtervalue=" . $event->getPbs_poolID();
					$filterentriesApiResult2 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentrie'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery2);
					$filterentriesXMLString2 = $filterentriesApiResult2['http-body'];
					$filterentriesXML2 = new SimpleXMLElement($filterentriesXMLString2);
					$filterentriesID2 = sprintf("%s", $filterentriesXML2->filterentriesid);
					if($event->getRepeat()) {
						$weekday = date('N', strtotime($event->getStart()));
						$filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=10&filtervalue=" . $weekday . "&filtervalue2=" . $weekday;
						$filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentrie'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3);
						$filterentriesXMLString3 = $filterentriesApiResult3['http-body'];
						$filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3);
						$filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentriesid);
					} else {
						$startDate = date('Y-m-d', strtotime($event->getStart()));
						if($event->getEnd()) {
							$endDate = date('Y-m-d', strtotime($event->getEnd()));
						} else {
							$endDate = date('Y-m-d', strtotime($event->getStart()));
						}
						$filterentriesquery3 = "filterID=" . $event->getPbs_filterID() . "&filtertypeID=11&filtervalue=" . $startDate . "&filtervalue2=" . $endDate;
						$filterentriesApiResult3 = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery3);
						$filterentriesXMLString3 = $filterentriesApiResult3['http-body'];
						$filterentriesXML3 = new SimpleXMLElement($filterentriesXMLString3);
						$filterentriesID3 = sprintf("%s", $filterentriesXML3->filterentriesid);
					}
					try {
						$this->eventMapper->save($event);
					} catch(Zend_Exception $e)
					{
						echo "Caught exception: " . get_class($e) . "<br/>";
						echo "Message: " . $e->getMessage() . "<br/>";
						return;
					}
					$this->_redirect('/event/');
				}
			} else {
				$event = new Application_Model_Event();
				$this->eventMapper->find($eventID, $event);
				$this->getRequest()->setParam('title', $event->getTitle());
				$this->getRequest()->setParam('action', $event->getAction());
				$this->getRequest()->setParam('immediate', $event->getImmediate());
				$this->getRequest()->setParam('start', $event->getStart());
				$this->getRequest()->setParam('end', $event->getEnd());
				$this->getRequest()->setParam('repeat', $event->getRepeat());
				$this->getRequest()->setParam('participants', $event->getParticipants());
				$this->getRequest()->setParam('category', $event->getCategory());
				$this->getRequest()->setParam('note', $event->getNote());
				$this->getRequest()->setParam('pbs_poolID', $event->getPbs_poolID());
				$this->getRequest()->setParam('pbs_bootosID', $event->getPbs_bootosID());
				$this->getRequest()->setParam('pbs_membershipID', $event->getPbs_membershipID());
				$params = $this->getRequest()->getParams();
				$editForm = new Application_Form_EventEdit(array('eventcategorylist' => $eventcategorylist, 'bootoslist' => $bootoslist, 'poollist' => $poollist , 'params' => $params));
			}
			$this->view->editForm = $editForm;
			$this->view->params = $params;
		}
	}

	public function listAction() {

		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();

		$year = date('Y');
		$month = date('m');

		echo json_encode(array(
		array(
				'id' => 111,
				'title' => "Event1",
				'start' => "$year-$month-10",
				'end' => "$year-$month-11",
				'url' => "http://yahoo.com/"
				),
					
				array(
				'id' => 222,
				'title' => "Event2",
				'start' => "$year-$month-20",
				'end' => "$year-$month-22",
				'url' => "http://yahoo.com/"
				)

				));
				return;
	}
}