summaryrefslogtreecommitdiffstats
path: root/application/modules/dev/controllers/PrebootController.php
blob: e319058050df31928c86984b6f61b1e85b5ef8b6 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php

class dev_PrebootController extends Zend_Controller_Action
{

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

    public function indexAction()
    {
    	$prebootmapper = new Application_Model_PreBootMapper();
    	$groupmapper = new Application_Model_GroupMapper();
    	$membershipmapper = new Application_Model_MembershipMapper();
    	$personmapper = new Application_Model_PersonMapper();
    	
    	$this->view->prebootlist = $prebootmapper->fetchAll();
    	$this->view->update = array();
    	
    	foreach ($this->view->prebootlist as $preboot){
    		$this->view->update[$preboot->getID()] = $this->checkupdateAction($preboot);    
    		$preboot->setGroupID("[".$preboot->getGroupID()."] ".$groupmapper->find($preboot->getGroupID())->getTitle());
    		$preboot->setMembershipID("[".$preboot->getMembershipID()."] ".$personmapper->find($membershipmapper->find($preboot->getMembershipID())->getPersonID())->getFirstname());
    	}
    }
    
    public function createprebootAction()
    {
    		$groupmapper = new Application_Model_GroupMapper();
    	
           	if (!isset($_POST["createpreboot"])){
    	        $createprebootForm = new dev_Form_PrebootCreate(array('grouplist' => $groupmapper->fetchAll()));
    		} else {
    			
    	        $createprebootForm = new dev_Form_PrebootCreate(array('grouplist' => $groupmapper->fetchAll()),$_POST);
    			    			
    		    if ($createprebootForm->isValid($_POST)) {

    		    	$preboot = new Application_Model_PreBoot($_POST);
    		    	$preboot->setMembershipID('1');
    		        $prebootmapper = new Application_Model_PreBootMapper();
    		        
    		    	try {  
    		    		
    		      		exec("wget --spider ".$preboot->getPath_preboot()." 2>&1 | grep 'Remote file exists.'", $exists_preboot);
    		      		
				    	if(!array_pop($exists_preboot)){
 							$this->view->createprebootForm = $createprebootForm;
 							return;		
				    	}		    	
    		    		
    		            $prebootID = $prebootmapper->save($preboot);
				    							
    		            $path_preboot = "../resources/bootmedium/$prebootID/";
    		            
						exec("wget -P  ".$path_preboot." -r -nH --cut-dirs=1 -np -R '*.html*' -N ".$preboot->getPath_preboot());
    		      		
    		    		
    		        }catch(Zend_Exception $e)
    		        {
    		            echo "Caught exception: " . get_class($e) . "<br/>";
    					echo "Message: " . $e->getMessage() . "<br/>";
    					
    		        }
					$this->_redirect('/dev/preboot');
    		     }
    		}
    
            $this->view->createprebootForm = $createprebootForm;
    }
    
    public function checkupdateAction($preboot)
    {
    	exec("wget --server-response --spider ".escapeshellcmd($preboot->getPath_preboot())."changed  2>&1 | grep 'Last-Modified:'", $prebootdate);

    	//print_a($prebootdate);
    	
    	$prebootdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($prebootdate))));
    	$prebootname = array_pop(scandir("../resources/bootmedium/".$preboot->getID()."/"));
    	
    	if($prebootname != "." && $prebootname != "..")
    		$prebootolddate = filemtime("../resources/bootmedium/".$preboot->getID()."/".$prebootname);
    	else 
    		$prebootolddate = false;    	
    	
    	//print_a($prebootname,$prebootdate,$prebootolddate);
    	
    		
    	if($prebootdate > $prebootolddate)
    		return true;
    	else 
    		return false;
    	   	
    }
    
    public function updateprebootAction()
    {
    	$prebootID = $this->_request->getParam('prebootID');
    	$prebootmapper = new Application_Model_PreBootMapper();
    	$preboot = new Application_Model_PreBoot();
    	$prebootmapper->find($prebootID,$preboot);
    	
    	$path_preboot = "../resources/bootmedium/$prebootID/";
    		            
		exec("wget -P  ".$path_preboot." -r -nH --cut-dirs=1 -np -R '*.html*' -N ".$preboot->getPath_preboot());
    	    	
    	$this->_redirect('/dev/preboot');
    }

    public function editprebootAction()
    {
    	$prebootID = $this->_request->getParam('prebootID');
    	$groupmapper = new Application_Model_GroupMapper();
    	
    	if (!isset($_POST["editpreboot"])){
    		$prebootID = $this->_request->getParam('prebootID');
     		if (!isset($prebootID) || !is_numeric($prebootID)){
   				$this->_redirect('/dev/preboot');
    		} else {
    		   $preboot = new Application_Model_PreBoot();
    		   $prebootmapper = new Application_Model_PreBootMapper();
    		   $prebootmapper->find($prebootID, $preboot);
    		   
    		   $editprebootForm = new dev_Form_PrebootEdit(array('grouplist' => $groupmapper->fetchAll()));
    		   $editprebootForm->populate($preboot->toArray()); 
    		}
    	}else{
    		$editprebootForm = new dev_Form_PrebootEdit(array('grouplist' => $groupmapper->fetchAll()),$_POST);
    			    			
    		if ($editprebootForm->isValid($_POST)) {

    			$preboot = new Application_Model_PreBoot($_POST);
    			$preboot->setMembershipID('1');
    		    $prebootmapper = new Application_Model_PreBootMapper();
    		    $preboot->setID($prebootID);
    		        
    		   	try {  
    		       	$prebootmapper->save($preboot);
    		    }catch(Zend_Exception $e)
    		    {
    		    	echo "Caught exception: " . get_class($e) . "<br/>";
    				echo "Message: " . $e->getMessage() . "<br/>";	
    		    }
    		    
				$this->_redirect('/dev/preboot');
    		}
    			
    	}
    	
    	$this->view->editprebootForm = $editprebootForm;
    }

    public function deleteprebootAction()
    {
   		$prebootID = $this->_request->getParam('prebootID');
     	if (!isset($prebootID)){
   			$this->_redirect('/dev/preboot');
    	} else {
    		   $preboot = new Application_Model_PreBoot();
    		   $preboot->setID($prebootID);
    		   $prebootmapper = new Application_Model_PreBootMapper();
    		   $prebootmapper->delete($preboot);
    	}
    	$this->_redirect('/dev/preboot');
    }


}