summaryrefslogtreecommitdiffstats
path: root/application/controllers/BootosController.php
blob: 3a7ab90b1026be7439ac9581d88d18933cc51bb6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php

class BootosController extends Zend_Controller_Action
{

    public function init()
    {
   		$db = Zend_Db_Table::getDefaultAdapter();
    }

    public function indexAction()
    {
    	
    	$bootosmapper = new Application_Model_BootOsMapper();
    	
        $groupmapper = new Application_Model_GroupMapper();
    	$membershipmapper = new Application_Model_MembershipMapper();
    	$personmapper = new Application_Model_PersonMapper();
    	$configmapper = new Application_Model_ConfigMapper();
    	
    	$this->view->bootoslist = $bootosmapper->fetchAll();
    	if(count($this->view->bootoslist)>0){
			foreach ($this->view->bootoslist as $bootos){
				  $bootos->setGroupID("[".$bootos->getGroupID()."] ".$groupmapper->find($bootos->getGroupID())->getTitle());
				  $bootos->setMembershipID("[".$bootos->getMembershipID()."] ".$personmapper->find($membershipmapper->find($bootos->getMembershipID())->getPersonID())->getFirstname());
				  $bootos->setConfigID("[".$bootos->getConfigID()."] ".$configmapper->find($bootos->getConfigID())->getTitle());
				  
			}
		}
    	
    }

    public function createbootosAction()
    {
    	$groupmapper = new Application_Model_GroupMapper();
    	$configmapper = new Application_Model_ConfigMapper();    	
    	
    	if (!isset($_POST["createbootos"])){
    	        $createbootosForm = new Application_Form_BootosCreate(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()));
    		} else {
    			
    	        $createbootosForm = new Application_Form_BootosCreate(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()),$_POST);
    			    			
    		    if ($createbootosForm->isValid($_POST)) {

    		    	$bootos = new Application_Model_BootOs($_POST);
    		    	$bootos->setMembershipID('1');
    		    	if($bootos->getConfigID() == '')
    		    		$bootos->setConfigID(NULL);
    		        $bootosmapper = new Application_Model_BootOsMapper();
    		        $bootos->setCreated(time());
    		        
    		    	try {  
    		            $bootosID = $bootosmapper->save($bootos);
						
    		            $initpath = "../resources/bootos/".$bootosID."/initramfs/";
    		            $kernelpath = "../resources/bootos/".$bootosID."/kernel/";
    		              
    		      		exec("wget -P  ".$kernelpath." ".$bootos->getPath_kernel());
    		      		exec("wget -P  ".$initpath." ".$bootos->getPath_init());    		            
    		            
    		        }catch(Zend_Exception $e)
    		        {
    		            echo "Caught exception: " . get_class($e) . "<br/>";
    					echo "Message: " . $e->getMessage() . "<br/>";
    					
    		        }
    		        
					$this->_redirect('/bootos');
    		     }
    		}
    
            $this->view->createbootosForm = $createbootosForm;
    }

    public function editbootosAction()
    {
    	$bootosID = $this->_request->getParam('bootosID');
    	$groupmapper = new Application_Model_GroupMapper();
    	$configmapper = new Application_Model_ConfigMapper();
    	
    	if (!isset($_POST["editbootos"])){
    		$bootosID = $this->_request->getParam('bootosID');
     		if (!isset($bootosID) || !is_numeric($bootosID)){
   				$this->_redirect('/bootos');
    		} else {
    		   $bootos = new Application_Model_BootOs();
    		   $bootosmapper = new Application_Model_BootOsMapper();
    		   $bootos = $bootosmapper->find($bootosID);
    		   
    		   $editbootosForm = new Application_Form_BootosEdit(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()));
    		   $editbootosForm->populate($bootos->toArray()); 
    		}
    	}else{
    		$editbootosForm = new Application_Form_BootosEdit(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()),$_POST);
    			    			
    		if ($editbootosForm->isValid($_POST)) {

    			$bootos = new Application_Model_BootOs($_POST);
    			$bootos->setMembershipID('1');
    		   	if($bootos->getConfigID() == '')
    		    	$bootos->setConfigID(NULL);
    		    $bootosmapper = new Application_Model_BootOsMapper();
    		    $bootos->setCreated(time());
    		    $bootos->setID($bootosID);
    		        
    		   	try {  
    		       	$bootosmapper->save($bootos);
    		    }catch(Zend_Exception $e)
    		    {
    		    	echo "Caught exception: " . get_class($e) . "<br/>";
    				echo "Message: " . $e->getMessage() . "<br/>";	
    		    }
    		    
				$this->_redirect('/bootos');
    		}
    			
    	}
    	
    	$this->view->editbootosForm = $editbootosForm;
    	
    }

    public function deletebootosAction()
    {
    	$bootosID = $this->_request->getParam('bootosID');
     	if (!isset($bootosID)){
   			$this->_redirect('/bootos');
    	} else {
    		   $bootos = new Application_Model_BootOs();
    		   $bootos->setID($bootosID);
    		   $bootosmapper = new Application_Model_BootOsMapper();
    		   $bootosmapper->delete($bootos);
    	}
    	$this->_redirect('/bootos');
    		
    }


}