summaryrefslogblamecommitdiffstats
path: root/application/modules/user/controllers/PrebootController.php
blob: b0b107776a46e94942642e6ab9984562077def89 (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 User_PrebootController extends Zend_Controller_Action
{

	protected $prebootMapper;
	protected $membershipMapper;
	protected $membership;
	protected $page;

	public function init()
	{
		if (Zend_Auth::getInstance()->hasIdentity()) {
			$userIDsNamespace = Zend_Session::namespaceGet('userIDs');
			if($userIDsNamespace['membershipID'] ==''){
				$this->_redirect('/user/index');
			}
				
			$this->prebootMapper = new Application_Model_PreBootMapper();
				
			$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');
		}
		$this->page = $this->_request->getParam('page');
	}


	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);
		}
    	    	
    	$groupID = $this->membership->getGroupID();    	
    	
    	//ACL Darf er PrebootMenu sehen?
    	if(!Pbs_Acl::checkRight('pro'))
    		$this->_redirect('/user/index');

    	$this->view->prebootlist = $this->prebootMapper->findBy(array("groupID" => $groupID));
        foreach ($this->view->prebootlist as $preboot){
    		$preboot->setCreated(date(Zend_Registry::get('dateformat'),$preboot->getCreated()));  
    	}
    	
    	// Search
		$search = $this->_request->getParam('search');
		$mySearch = new Pbs_Search();
		$mySearch->setSearchTerm($search);
		$mySearch->setModule('preboot');
		if($search != ''){
			$this->view->search = $mySearch->getSearchTerm();
			$this->view->prebootlist = $mySearch->search($this->view->prebootlist);
		}
		$this->view->searchform = $mySearch->searchForm();
		 
		// Pagination
		$pagination = new Pbs_Pagination();
		$pagination->setPerPage(10);
		$pagination->setElement($this->view->prebootlist);
		$pagination->setRequestPage($this->_request->getParam('page'));
		$pagination->setPageUrl('/user/preboot/index'.((isset($this->view->search))?'/search/'.$this->view->search:''));
		$this->view->prebootlist = $pagination->getElements();

		$this->view->pagination = $pagination->pagination();

		$this->view->page 		= $pagination->getRequestPage();    	

    }
    
    public function searchAction(){
		$this->_redirect('/user/preboot/index/search/'.($_GET['search']));
	}

	public function createprebootAction()
	{
		 
		//ACL Is he allowed to create Preboots?
		if(!Pbs_Acl::checkRight('prc'))
		$this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/forbidden');
		 
		if (!isset($_POST["createpreboot"])){
			$prebootForm = new user_Form_Preboot(array(
    	        									'action' => 'createpreboot',
    	        									'page' => $this->page));
		} else {
			 
			$prebootForm = new user_Form_Preboot(array(
    	        									'action' => 'createpreboot',
    	        									'page' => $this->page),$_POST);

			if ($prebootForm->isValid($_POST)) {

				$groupID = $this->membership->getGroupID();
				$source = $_SERVER['REMOTE_ADDR'];
				
				try {
					if($_FILES['preboot']['size'] == 0 && $_FILES['preboot']['name'] != ''){
						$this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/file');
					}	
					
			
					$preboot = new Application_Model_PreBoot($_POST);
					
					$preboot->setGroupID($groupID);
					$preboot->setSource($source);
					$preboot->setCreated(time());
					
					$prebootID = $this->prebootMapper->save($preboot);
			
					$prebootpath = "../resources/bootmedium/".$prebootID."/";
					mkdir($prebootpath ,0777, true);
			
					if($_FILES['preboot']['name'] != ''){
						move_uploaded_file($_FILES['preboot']['tmp_name'], $prebootpath."preboot.zip");
					}


				}catch(Zend_Exception $e)
				{
					echo "Caught exception: " . get_class($e) . "<br/>";
					echo "Message: " . $e->getMessage() . "<br/>";
					$this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/error');
					//TODO Delete folder + preboot in DB
						
				}
				$this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/ok');
			}
		}

		$this->view->prebootForm = $prebootForm;
	}

	public function editprebootAction()
	{
		//ACL Is he allowed to edit Preboots?
		if(!Pbs_Acl::checkRight('pre') && !Pbs_Acl::checkRight('prem'))
		$this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/forbidden');
		 
		$prebootID = $this->_request->getParam('prebootID');
		 
		if (!is_numeric($prebootID))
		$this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/forbidden');
		 
		$preboot = new Application_Model_PreBoot();
		$this->prebootMapper->find($prebootID, $preboot);
		 
		if($this->membership->getGroupID() != $preboot->getGroupID())
		$this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/forbidden');
		 
		if (!isset($_POST["editpreboot"])){
	   
			$prebootForm = new user_Form_Preboot(array(
    	 										'action' => 'editpreboot',
    	 										'page' => $this->page));
			$prebootForm->populate($preboot->toArray());

		}else{

			$prebootForm = new user_Form_Preboot(array(
    											'action' => 'editpreboot',
    	 										'page' => $this->page),$_POST);
			 
			if ($prebootForm->isValid($_POST)) {

				$prebootold = $preboot;
				$source = $_SERVER['REMOTE_ADDR'];
				
				$preboot = new Application_Model_PreBoot($_POST);
				$preboot->setGroupID($this->membership->getGroupID());
				$preboot->setID($prebootID);
				$preboot->setSource($prebootold->getSource());
				$preboot->setCreated(time());

				if($_FILES['preboot']['name'] != ''){
					//ACL Is he allowed to edit other than Metadata?
					if(!Pbs_Acl::checkRight('pre'))
					$this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/forbidden');
				}
				
				if($_FILES['preboot']['size'] == 0 && $_FILES['preboot']['name'] != ''){
					$this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/file');
				}	
				
				$prebootpath = "../resources/bootmedium/$prebootID/";
					
				mkdir($prebootpath ,0777, true);
			
				if($_FILES['preboot']['name'] != ''){
					$preboot->setSource($source);
					move_uploaded_file($_FILES['preboot']['tmp_name'], $prebootpath."preboot.zip");
				}
	    
				try {
					$this->prebootMapper->save($preboot);

				}catch(Zend_Exception $e){
					echo "Caught exception: " . get_class($e) . "<br/>";
					echo "Message: " . $e->getMessage() . "<br/>";
					$this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/error');
					//TODO Delete Folder + Preboot
				}

				$this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/ok');
			}
		}

		$this->view->prebootForm = $prebootForm;
	}

	public function deleteprebootAction()
	{
		 
		//ACL Is he allowed to delete Preboots?
		if(!Pbs_Acl::checkRight('prd'))
		$this->_redirect('/user/preboot/index/page/'.$this->page.'/deleteresult/forbidden');
		 
		try{
			$prebootID = $this->_request->getParam('prebootID');
			if (!is_numeric($prebootID))
			$this->_redirect('/user/preboot/index/page/'.$this->page.'/deleteresult/forbidden');
			 
			$preboot = new Application_Model_PreBoot();
			$this->prebootMapper->find($prebootID, $preboot);

			if($this->membership->getGroupID() != $preboot->getGroupID())
			$this->_redirect('/user/preboot/index/page/'.$this->page.'/deleteresult/forbidden');
				
			$this->prebootMapper->delete($preboot);
			exec("rm -r ../resources/bootmedium/".$prebootID);

		}catch(Zend_Exception $e){
			echo "Caught exception: " . get_class($e) . "<br/>";
			echo "Message: " . $e->getMessage() . "<br/>";
			$this->_redirect('/user/preboot/index/page/'.$this->page.'/deleteresult/error');
		}
		$this->_redirect('/user/preboot/index/page/'.$this->page.'/deleteresult/ok');
	}


}