summaryrefslogblamecommitdiffstats
path: root/application/modules/user/controllers/BootmenuController.php
blob: 7d829de4f197a86dcd5babf65bee64f7ac4c2181 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

     
                                                            
 





                                         

                          
                                                      





                                                                                       
                        




                                                                                                           


                                                                    
         


                                 




















                                                                                           





                                                                                         
                                               
























                                                                                                                                                                           




















































































































                                                                                                                                        













































                                                                                                                                                                                                                             
















                                                                                     
                                                                                                                                                                                                                                                                  










                                                                                             
                                                                                                                                                                                                                                                              






























                                                                                                                                 

     














                                                                                        










                                                                       


 











 
<?php

class user_BootmenuController extends Zend_Controller_Action
{
	
	protected $bootmenuMapper;
	protected $bootmenuentriesMapper;
	protected $membershipMapper;
	protected $membership;
	
    public function init()
    {
        if (Zend_Auth::getInstance()->hasIdentity()) {
			$userIDsNamespace = Zend_Session::namespaceGet('userIDs');
			if($userIDsNamespace['membershipID'] ==''){
				$this->_redirect('/user/index');
			}
			
			$this->bootmenuMapper = new Application_Model_BootMenuMapper();
			
			$this->membershipMapper = new Application_Model_MembershipMapper();
			$this->membership = new Application_Model_Membership();
			$this->membershipMapper->find($userIDsNamespace['membershipID'],$this->membership);

			$this->db = Zend_Db_Table::getDefaultAdapter();
		} else {
			$this->_helper->redirector('login', 'auth');
		}
   	}

    public function indexAction()
    {
    	
        $result = $this->_request->getParam('addresult');
		if($result != ""){
			$pbsNotifier = new Pbs_Notifier();
			$this->view->notification = $pbsNotifier->notify('create',$result);
		}
		$result = $this->_request->getParam('deleteresult');
		if($result != ""){
			$pbsNotifier = new Pbs_Notifier();
			$this->view->notification = $pbsNotifier->notify('delete',$result);
		}
		$result = $this->_request->getParam('modifyresult');
		if($result != ""){
			$pbsNotifier = new Pbs_Notifier();
			$this->view->notification = $pbsNotifier->notify('modify',$result);
		} 
		
		//TODO ACL Darf er BootOsMenu sehen?
    	if(false)
    		$this->_redirect('/user/index');
		
    	$this->bootMenumapper = new Application_Model_BootMenuMapper();
	    $this->bootmenuentriesMapper = new Application_Model_BootMenuEntriesMapper();
	    $bootosMapper = new Application_Model_BootOsMapper();
	    $configMapper = new Application_Model_ConfigMapper();
	   
	    if(true){    		
	    	//TODO nur Bootmenus von Admins
	    	$bootmenu = $this->bootmenuMapper->findBy('groupID', $this->membership->getGroupID());
	    	foreach ($bootmenu as $bm){
		    	$bootmenuID = $bm->getID();
		    	$bootmenuentries[$bootmenuID] = $this->bootmenuentriesMapper->findBy('bootmenuID',$bootmenuID);
		    	foreach ($bootmenuentries[$bootmenuID] as $bootmenuentry){
		    		$bootmenuentry->setBootosID("[".$bootmenuentry->getBootosID()."] ".$bootosMapper->find($bootmenuentry->getBootosID())->getTitle());
					$bootmenuentry->setConfigID("[".$bootmenuentry->getConfigID()."] ".$configMapper->find($bootmenuentry->getConfigID())->gettitle());
		    	}
	    	}
	    }else{	

	    	$bootmenu = $this->bootmenuMapper->findBy('membershipID', $this->membership->getID());
	    	$bootmenuID = $bootmenu[0]->getID();
	    	$bootmenuentries[$bootmenuID] = $this->bootmenuentriesMapper->findBy('bootmenuID',$bootmenuID);
	    	foreach ($bootmenuentries[$bootmenuID] as $bootmenuentry){
	    		$bootmenuentry->setBootosID("[".$bootmenuentry->getBootosID()."] ".$bootosMapper->find($bootmenuentry->getBootosID())->getTitle());
				$bootmenuentry->setConfigID("[".$bootmenuentry->getConfigID()."] ".$configMapper->find($bootmenuentry->getConfigID())->gettitle());
	    	}
	    }	
	    	
	    	$this->view->bootmenulist = $bootmenu;
	    	$this->view->bootmenuentrylist = $bootmenuentries;
	    	
    }

    
    public function createbootmenuAction()
    {
    	//TODO ACL Darf er BootMenus erstellen?
    	if(false)
    		$this->_redirect('/user/bootmenu/index/page/'.$page.'/addresult/forbidden');
    		    	
        if (!isset($_POST["createbootmenu"])){
    	    $bootmenuForm = new user_Form_Bootmenu(array('action' => 'createbootmenu', 'rights' => 'all'));
    	} else {
    			
    	    $bootmenuForm = new user_Form_Bootmenu(array('action' => 'createbootmenu', 'rights' => 'all'),$_POST);
    			    			
    		if ($bootmenuForm->isValid($_POST)) {

    		    $bootmenu = new Application_Model_BootMenu($_POST);
    		    $bootmenu->setMembershipID($this->membership->getID());
    		    $bootmenu->setGroupID($this->membership->getGroupID());
    		    $bootmenu->setCreated(time());

    		    try{  
    		        $this->bootmenuMapper->save($bootmenu);
    		    }catch(Zend_Exception $e){
    		        echo "Caught exception: " . get_class($e) . "<br/>";
    				echo "Message: " . $e->getMessage() . "<br/>";	
    				$this->_redirect('/user/bootmenu/index/page/'.$page.'/addresult/error');
    		    }
				$this->_redirect('/user/bootmenu/index/page/'.$page.'/addresult/ok');
    		}
    	}
    
            $this->view->bootmenuForm = $bootmenuForm;
    }
    
    public function editbootmenuAction()
    {
        
        //TODO ACL Is he allowed to edit BootMenus?
    	if(false)
    		$this->_redirect('/user/bootmenu/index/page/'.$page.'/modifyresult/forbidden');
        
    	$bootmenuID = $this->_request->getParam('bootmenuID');
        if (!is_numeric($bootmenuID))
    		$this->_redirect('/user/bootmenu/index/page/'.$page.'/modifyresult/forbidden');	
    		
    	$bootmenu = new Application_Model_BootMenu();
    	$bootmenu = $this->bootmenuMapper->find($bootmenuID);

    	if($this->membership->getGroupID() != $bootmenu->getGroupID())
    		$this->_redirect('/user/bootmenu/index/page/'.$page.'/modifyresult/forbidden');	
    		
    	if (!isset($_POST["editbootmenu"])){

    		$bootmenuForm = new user_Form_Bootmenu(array('action' => 'editbootmenu', 'rights' => 'all'));
    		$bootmenuForm->populate($bootmenu->toArray()); 
    		
    	}else{
    		$bootmenuForm = new user_Form_Bootmenu(array('action' => 'editbootmenu', 'rights' => 'all'),$_POST);
    			    			
    		if ($bootmenuForm->isValid($_POST)) {

    			$bootmenuold = $bootmenu;
    			
    			$bootmenu = new Application_Model_BootMenu($_POST);
    			$bootmenu->setMembershipID($this->membership->getID());
    		   	$bootmenu->setCreated(time());
    		    $bootmenu->setID($bootmenuID);
    		    
    		    //TODO ACL Is he allowed to edit this?
    			if(false)
    				$this->_redirect('/user/bootmenu/index/page/'.$page.'/modifyresult/forbidden');
    		        
    		   	try {  
    		       	$this->bootmenuMapper->save($bootmenu);
    		    }catch(Zend_Exception $e)
    		    {
    		    	echo "Caught exception: " . get_class($e) . "<br/>";
    				echo "Message: " . $e->getMessage() . "<br/>";	
    				$this->_redirect('/user/bootmenu/index/page/'.$page.'/modifyresult/error');
    		    }
    		    
				$this->_redirect('/user/bootmenu/index/page/'.$page.'/modifyresult/ok');				
    		}
    			
    	}
    	
    	$this->view->editbootmenuForm = $editbootmenuForm;
    }
    
    public function deletebootmenuAction()
    {

    	//TODO ACL Is he allowed to delete Bootos?
    	if(false)
    		$this->_redirect('/user/bootos/index/page/'.$page.'/deleteresult/forbidden');

    	try{
    		$bootmenuID = $this->_request->getParam('bootmenuID');
    		if (!is_numeric($bootmenuID))
	   			$this->_redirect('/user/bootmenu/index/page/'.$page.'/deleteresult/forbidden');
    	
    		$bootmenu = new Application_Model_BootMenu();
    		$this->bootmenuMapper->find($bootmenuID, $bootmenu);
    			
	    	if($this->membership->getGroupID() != $bootmenu->getGroupID())
	   			$this->_redirect('/user/bootmenu/index/page/'.$page.'/deleteresult/forbidden');

    		$this->bootmenuMapper->delete($bootmenu);
    		
    	}catch(Zend_Exception $e){
    		echo "Caught exception: " . get_class($e) . "<br/>";
    		echo "Message: " . $e->getMessage() . "<br/>";
    		$this->_redirect('/user/bootmenu/index/page/'.$page.'/deleteresult/error');	
    	}
	   		$this->_redirect('/user/bootmenu/index/page/'.$page.'/deleteresult/ok');
    }
    
    public function addbootmenuentryAction()
    {
    	$bootmenuID = $this->_request->getParam('bootmenuID');
    	$bootosmapper = new Application_Model_BootOsMapper();
    	$configmapper = new Application_Model_ConfigMapper();

    	if (!isset($_POST["addbootmenuentry"])){
    	    $addbootmenuentryForm = new user_Form_BootmenuEntriesAdd(array('bootoslist'=>$bootosmapper->fetchAll(), 'maxorder'=> $this->_request->getParam('maxorder'), 'configlist'=>$configmapper->fetchAll()));  
    	    $addbootmenuentryForm->populate(array('order' => $this->_request->getParam('maxorder')));
    	    unset($_POST['kcl']);
    	    unset($_POST['configID']);
    	    $addbootmenuentryForm->populate($_POST);
    	} else {
    			
    	        $addbootmenuentryForm = new user_Form_BootmenuEntriesAdd(array('bootoslist'=>$bootosmapper->fetchAll(), 'maxorder'=> $this->_request->getParam('maxorder'), 'configlist'=>$configmapper->fetchAll()),$_POST);
    	        
    		    if ($addbootmenuentryForm->isValid($_POST)) {
    		    	
    		    	$bootmenuentry = new Application_Model_BootMenuEntries($_POST);
    		    	$bootmenuentry->setBootmenuID($bootmenuID);
    		    	    		    	
    		        $bootmenuentrymapper = new Application_Model_BootMenuEntriesMapper();

    		    	try {  
    		    	    if($bootmenuentry->getOrder() < $this->_request->getParam('maxorder')){
    		    			$bootmenuentry->setOrder($bootmenuentry->getOrder());
 							$bootmenuentrymapper->order($bootmenuentry);
    		    		}

    		    		//print_a($bootmenuentry);
    		    		
    		            $bootmenuentrymapper->save($bootmenuentry);
    		        }catch(Zend_Exception $e)
    		        {
    		            echo "Caught exception: " . get_class($e) . "<br/>";
    					echo "Message: " . $e->getMessage() . "<br/>";
    					
    		        }
					$this->_redirect('/user/bootmenu');
    		     }
    		}
    
            $this->view->addbootmenuentryForm = $addbootmenuentryForm;
    	
    }

    public function editbootmenuentryAction()
    {
        $bootmenuentryID = $this->_request->getParam('bootmenuentryID');
        $bootmenuID = $this->_request->getParam('bootmenuID');
        $bootosmapper = new Application_Model_BootOsMapper();
        $configmapper = new Application_Model_ConfigMapper();
    	$bootmenuentry = new Application_Model_BootMenuEntries();
    	$bootmenuentrymapper = new Application_Model_BootMenuEntriesMapper();
    	
    	if (!isset($_POST["editbootmenuentry"])){
    		$bootmenuentryID = $this->_request->getParam('bootmenuentryID');
     		if (!isset($bootmenuentryID) || !is_numeric($bootmenuentryID)){
   				$this->_redirect('/user/bootmenu');
    		} else {
    		   	
    		   	$bootmenuentrymapper->find($bootmenuentryID, $bootmenuentry);
    		       		   	
    		  	$editbootmenuentryForm = new user_Form_BootmenuEntries(array('bootoslist'=>$bootosmapper->fetchAll(), 'maxorder' => $this->_request->getParam('maxorder'), 'configlist'=>$configmapper->fetchAll(), 'kcl' => $bootmenuentry->getKcl()));  

    		  	if(!isset($_POST['configID'])){	
    		  		$editbootmenuentryForm->populate($bootmenuentry->toArray()); 
				}
    		  	else{ 
    		  		unset($_POST['kcl']);
    		  		unset($_POST['configID']);
    		  		$editbootmenuentryForm->populate($_POST);
    		  	}
    		}
    	}else{
    		$editbootmenuentryForm = new user_Form_BootmenuEntries(array('bootoslist'=>$bootosmapper->fetchAll(), 'maxorder'=> $this->_request->getParam('maxorder'), 'configlist'=>$configmapper->fetchAll(), 'kcl' => $bootmenuentry->getKcl()),$_POST);
    			    			
    		if ($editbootmenuentryForm->isValid($_POST)) {
    			
    			$bootmenuentry = new Application_Model_BootMenuEntries($_POST);
    			
    			$bootmenuentry->setBootmenuID($bootmenuID);
    			$bootmenuentry->setID($bootmenuentryID);
 
    		    $bootmenuentrymapper = new Application_Model_BootMenuEntriesMapper();
    		        
    		   	try {  
    		   		if($bootmenuentry->getOrder() < $this->_request->getParam('oldorder'))
    		   			$bootmenuentrymapper->orderbefore($bootmenuentry, $this->_request->getParam('oldorder'));
    		   		else 
    		   			$bootmenuentrymapper->orderafter($bootmenuentry, $this->_request->getParam('oldorder'));
    		   			
    		       	$bootmenuentrymapper->save($bootmenuentry);
    		       	
    		    }catch(Zend_Exception $e)
    		    {
    		    	echo "Caught exception: " . get_class($e) . "<br/>";
    				echo "Message: " . $e->getMessage() . "<br/>";	
    		    }
    		    
				$this->_redirect('/user/bootmenu');
    		}
    			
    	}
    	
    	$this->view->editbootmenuentryForm = $editbootmenuentryForm;
    	
    }

    public function removebootmenuentryAction()
    {
        $bootmenuentryID = $this->_request->getParam('bootmenuentryID');
     	if (!isset($bootmenuentryID) || !is_numeric($bootmenuentryID)){
   			$this->_redirect('/bootmenu');
    	} else {
    		   $bootmenuentry = new Application_Model_BootMenuEntries();
    		   $bootmenuentrymapper = new Application_Model_BootMenuEntriesMapper();
    		   $bootmenuentrymapper->find($bootmenuentryID, $bootmenuentry);
    		   $bootmenuentrymapper->delete($bootmenuentry);
    		   $bootmenuentrymapper->orderremove($bootmenuentry);
    	}
    	$this->_redirect('/user/bootmenu');
    }

    private function arrayDiff($a, $b){
		foreach($a as $k1 => $i1){
			foreach($b as $k2 => $i2){
				if($i1->getID() == $i2->getBootosID()){
					unset($a[$k1]);
				}
			}
		}
		return $a;
	}
	

}