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



                                                       
        

                          

                                                         


                                 
                                                                 
                                                                               

                                                             
                                                                
    
                                   
                                                         
                                                                                                                         

                                                          

     

                                            
                                                              




                                                                                                                            
                                                

                                                                                                                                                                                  


                                                                                        
                


                                                                                       
                                                                   
                                                
                                                                                             
 
                               



                                                                                                    












                                                                                      



                                          

























                                                                                      



                                        
                                                              





































                                                                                



                                             

                                                                        
                                                             





                                                                                



                                                                                             
                                                                                                                                                                                                 
                   
                                                                                     






                                                                                          
                        


                                                                   
                                                                                         















                                                                                



                                               




                                                                            
                                                                                        
                                                                                
                                                                
                                                                     

                                      



                                          
                                                              
                                                             







                                                                            

     










                                                                       


 











 
<?php

class BootmenuController extends Zend_Controller_Action
{
	
    public function init()
    {
   		$db = Zend_Db_Table::getDefaultAdapter();
   	}

    public function indexAction()
    {
        $bootmenumapper = new Application_Model_BootMenuMapper();
        $bootmenuentriesmapper = new Application_Model_BootMenuEntriesMapper();
     	$bootosmapper = new Application_Model_BootOsMapper();
        
    	$this->view->bootmenulist = $bootmenumapper->fetchAll();
    
    	$bootmenuentries = array();
    	foreach ($this->view->bootmenulist as $bootmenu){
    		  $bootmenuentries[$bootmenu->getID()] = $bootmenuentriesmapper->findBy('bootmenuID',$bootmenu->getID());
    	}
    	$this->view->bootmenuentrylist = $bootmenuentries;
    }

    public function addbootmenuentryAction()
    {
    	$bootmenuID = $this->_request->getParam('bootmenuID');
    	$bootosmapper = new Application_Model_BootOsMapper();
//    	$bootmenuentriesmapper = new Application_Model_BootMenuEntriesMapper();
//
//    	$bootoslist = $this->arrayDiff($bootosmapper->fetchAll(), $bootmenuentriesmapper->findBy('bootmenuID',$bootmenuID));

    	if (!isset($_POST["addbootmenuentry"])){
    	    $addbootmenuentryForm = new Application_Form_BootmenuEntriesAdd(array('bootoslist'=>$bootosmapper->fetchAll(), 'maxorder'=> $this->_request->getParam('maxorder')));  
    	    $addbootmenuentryForm->populate(array('order' => $this->_request->getParam('maxorder')));
    		} else {
    			
    	        $addbootmenuentryForm = new Application_Form_BootmenuEntriesAdd($_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);
    		    		}
    		            $bootmenuentrymapper->save($bootmenuentry);
    		        }catch(Zend_Exception $e)
    		        {
    		            echo "Caught exception: " . get_class($e) . "<br/>";
    					echo "Message: " . $e->getMessage() . "<br/>";
    					
    		        }
					$this->_redirect('/bootmenu');
    		     }
    		}
    
            $this->view->addbootmenuentryForm = $addbootmenuentryForm;
    	
    }

    public function createbootmenuAction()
    {
            if (!isset($_POST["createbootmenu"])){
    	        $createbootmenuForm = new Application_Form_BootmenuCreate();
    		} else {
    			
    	        $createbootmenuForm = new Application_Form_BootmenuCreate($_POST);
    			    			
    		    if ($createbootmenuForm->isValid($_POST)) {

    		    	$bootmenu = new Application_Model_BootMenu($_POST);
    		    	$bootmenu->setMembershipID('1');
    		    	$bootmenu->setCreated(time());
    		        $bootmenumapper = new Application_Model_BootMenuMapper();
    		        
    		    	try {  
    		            $bootmenumapper->save($bootmenu);
    		        }catch(Zend_Exception $e)
    		        {
    		            echo "Caught exception: " . get_class($e) . "<br/>";
    					echo "Message: " . $e->getMessage() . "<br/>";
    					
    		        }
					$this->_redirect('/bootmenu');
    		     }
    		}
    
            $this->view->createbootmenuForm = $createbootmenuForm;
    }

    public function editbootmenuAction()
    {
        $bootmenuID = $this->_request->getParam('bootmenuID');
    	if (!isset($_POST["editbootmenu"])){
    		$bootmenuID = $this->_request->getParam('bootmenuID');
     		if (!isset($bootmenuID) || !is_numeric($bootmenuID)){
   				$this->_redirect('/bootmenu');
    		} else {
    		   $bootmenu = new Application_Model_BootMenu();
    		   $bootmenumapper = new Application_Model_BootMenuMapper();
    		   $bootmenumapper->find($bootmenuID, $bootmenu);
    		   
    		   $editbootmenuForm = new Application_Form_BootmenuEdit();
    		   $editbootmenuForm->populate($bootmenu->toArray()); 
    		}
    	}else{
    		$editbootmenuForm = new Application_Form_BootmenuEdit($_POST);
    			    			
    		if ($editbootmenuForm->isValid($_POST)) {

    			$bootmenu = new Application_Model_BootMenu($_POST);
    			$bootmenu->setMembershipID('1');
    		   	$bootmenu->setCreated(time());
    		    $bootmenumapper = new Application_Model_BootMenuMapper();
    		    
    		    $bootmenu->setID($bootmenuID);
    		        
    		   	try {  
    		       	$bootmenumapper->save($bootmenu);
    		    }catch(Zend_Exception $e)
    		    {
    		    	echo "Caught exception: " . get_class($e) . "<br/>";
    				echo "Message: " . $e->getMessage() . "<br/>";	
    		    }
    		    
				$this->_redirect('/bootmenu');
    		}
    			
    	}
    	
    	$this->view->editbootmenuForm = $editbootmenuForm;
    }

    public function editbootmenuentryAction()
    {
        $bootmenuentryID = $this->_request->getParam('bootmenuentryID');
        $bootmenuID = $this->_request->getParam('bootmenuID');
        $bootosmapper = new Application_Model_BootOsMapper();
    	
    	if (!isset($_POST["editbootmenuentry"])){
    		$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);
    		   
    		  	$editbootmenuentryForm = new Application_Form_BootmenuEntriesEdit(array('bootoslist'=>$bootosmapper->fetchAll(), 'maxorder' => $this->_request->getParam('maxorder')));  
    		   
    		   	$editbootmenuentryForm->populate($bootmenuentry->toArray()); 
    		}
    	}else{
    		$editbootmenuentryForm = new Application_Form_BootmenuEntriesEdit($_POST);
    			    			
    		if ($editbootmenuentryForm->isValid($_POST)) {

    			$bootmenuentry = new Application_Model_BootMenuEntries($_POST);
    			
    			$bootmenuentry->setBootmenuID($bootmenuID);
    			$bootmenuentry->setID($bootmenuentryID);
 
    		    $bootmenuentrymapper = new Application_Model_BootMenuEntriesMapper();
    		        
    		   	try {  
    		       	$bootmenuentrymapper->save($bootmenuentry);
    		    }catch(Zend_Exception $e)
    		    {
    		    	echo "Caught exception: " . get_class($e) . "<br/>";
    				echo "Message: " . $e->getMessage() . "<br/>";	
    		    }
    		    
				$this->_redirect('/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('/bootmenu');
    }

    public function deletebootmenuAction()
    {
    	$bootmenuID = $this->_request->getParam('bootmenuID');
     	if (!isset($bootmenuID) || !is_numeric($bootmenuID)){
   			$this->_redirect('/bootmenu');
    	} else {
    		   $bootmenu = new Application_Model_BootMenu();
    		   $bootmenu->setID($bootmenuID);
    		   $bootmenumapper = new Application_Model_BootMenuMapper();
    		   $bootmenumapper->delete($bootmenu);
    	}
    	$this->_redirect('/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;
	}
	

}