summaryrefslogtreecommitdiffstats
path: root/application/modules/fbgui/controllers/IndexController.php
blob: fb8282af9219bb344fdef6f3a2f79a5d7c5346e5 (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
171
<?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 Fbgui_IndexController extends Zend_Controller_Action
{
	protected $membership;
	
    public function init()
    {
        /* Initialize action controller here */
        $membershipMapper = new Application_Model_MembershipMapper();
		$this->membership = new Application_Model_Membership();
		$membershipMapper->find($userIDsNamespace['membershipID'],$this->membership);
    }

    public function errorAction()
    {
    	$result = $this->_request->getParam('serialresult');
		if($result != ""){
			$pbsNotifier = new Pbs_Notifier();
			$this->view->notification = $pbsNotifier->notify('serial',$result);
		} 
    }
    
    public function indexAction()
    {     
		$mySession = new Zend_Session_Namespace('pbs');
		
		if(count($mySession->postdata)<=0)
			$mySession->postdata = $_POST;
		
		$d = new Pbs_Debug();
		$d->debug(array('FBGuiIndexController',$_SERVER['REMOTE_ADDR'],implode("\t",$mySession->postdata)));
			
        if(isset($mySession->postdata['bootisoID']) || isset($mySession->postdata['serialnumber'])){
        	// Create a session
        	$n = new Pbs_Session();
        	
        	$bootisomapper = new Application_Model_BootIsoMapper();
        	$bootiso = new Application_Model_BootIso();
        	if(isset($mySession->postdata['bootisoID'])){
    	    	$bootisomapper->find($mySession->postdata['bootisoID'],$bootiso);
	        	$groupID = $bootiso->getGroupID();
        	}
        	elseif(isset($mySession->postdata['serialnumber'])){   
        		$results = $bootisomapper->findBy(array('serialnumber' => $mySession->postdata['serialnumber']),true);
				if(count($results) == 0){
					$this->_redirect('/fbgui/index/error/serialresult/noserial2');
				}
        		$bootiso->setOptions($results[0]);
        		$bootiso->setID($results[0]['bootisoID']);
	        	$groupID = $bootiso->getGroupID();
        	
        	}
        	
        	$client = new Application_Model_Client();
        	$client->setMacadress($mySession->postdata['mac']);       	
			$client->setHardwarehash($mySession->postdata['hardwarehash']);	
			$client->setGroupID($groupID);
			$client = $n->createClient($client);
			$clientID = $client->getID();
        	
        	$userIDsNamespace = Zend_Session::namespaceGet('userIDs');
        	
        	if(!isset($_SESSION['alphasessionID'])){
				$session = new Application_Model_Session();
				$session->setBootisoID($bootiso->getID());
				$session->setClientID($clientID);
				$session->setTime(time());
				if($this->membership->getID() != ''){
					$session->setMembershipID($this->membership->getID());
				}
		   		$session->setIp($_SERVER['REMOTE_ADDR']);
				$session = $n->createSession($session);
				$_SESSION['alphasessionID'] = $session->getAlphasessionID();				
			}
			else{
				$session = new Application_Model_Session();
				$sessionMapper = new Application_Model_SessionMapper();
				$sessions = $sessionMapper->findBy(array('alphasessionID'=>$_SESSION['alphasessionID']));
				$session = $sessions[0];
				if($this->membership->getID() != ''){
					$session->setMembershipID($this->membership->getID());
					$session->save();
				}
			}
			// Request Bootmenu
			$pbsFilter = new Pbs_Filter();
			$bootmenuID = $pbsFilter->evaluate();
			if($bootmenuID != null){
				$this->view->alphasessionID = $_SESSION['alphasessionID'];
//					print_a('Debug Output',
//						'Session is now set',
//						'Your sessionID is '.$session->getID(),
//						'Your alphasessionID is '.$session->getAlphasessionID(),
//						'Your client is '.$session->getClientID(),
//						'goto bootmenu '.$bootmenuID);
				
				$bootmenuMapper = new Application_Model_BootMenuMapper();
				$bm = $bootmenuMapper->find($bootmenuID);
				$this->view->title = $bm->getTitle();
				
				$bootmenuentriesMapper = new Application_Model_BootMenuEntriesMapper();
				$res = $bootmenuentriesMapper->findBy(array('bootmenuID' => $bootmenuID),false);
				$this->view->entries = $res;
				#print_a(Zend_Auth::getInstance()->hasIdentity(),$bm->MembershipID ,$this->membership->getID());
				if (!Zend_Auth::getInstance()->hasIdentity()) {					
					# $pbsNotifier = new Pbs_Notifier();
					# $this->view->notification = $pbsNotifier->notify("This is not your Bootmenu. You have to login to get your own Bootmenu.<br />Click here to <a href='/fbgui/auth/login/'>login</a>",'info');
					$this->view->loginmenu = true;
				}
				if(Zend_Auth::getInstance()->hasIdentity()){		
					if($bm->MembershipID != '' && $bm->MembershipID == $this->membership->getID()){}
					else{
					$pbsNotifier = new Pbs_Notifier();
					$this->view->notification = $pbsNotifier->notify("This is not your Bootmenu. There is currently a BootMenu with a higher priority active.",'info');
					}
				}
			}
			else{
				
//				print_a('Debug Output',
//					'Session is now set',
//					'Your sessionID is '.$session->getID(),
//					'Your alphasessionID is '.$session->getAlphasessionID(),
//					'Your client is '.$session->getClientID(),
//					'there is no bootmenu for you');
				
				$pbsNotifier = new Pbs_Notifier();
				$this->view->notification = $pbsNotifier->notify("There is no BootMenu to show. Please log in to get your BootMenu.<br />Click here to <a href='/fbgui/auth/login/'>login</a>",'error');				
				
			}
		}
		else{
    		#$this->_redirect('/fbgui/index/error/serialresult/noserial');
    	}    	
    	
    }
	public function startAction(){
		$bootmenuntryID = $this->_request->getParam('bme');
		$a = $_SESSION['alphasessionID'];
		$bootmenuentriesMapper = new Application_Model_BootMenuEntriesMapper();
		$bootmenuentry = new Application_Model_BootMenuEntries();
		$bootmenuentriesMapper->find($bootmenuntryID,$bootmenuentry);
		
		$sessionMapper = new Application_Model_SessionMapper();
		$session_k = $sessionMapper->findBy(array('alphasessionID' => $a),true);	
		
    	$session = new Application_Model_Session();	
		$session->setOptions($session_k[0]);
		$session->setID($session_k[0]['sessionID']);
		#print_a($bootmenuentry);
		$session->setBootmenuentryID($bootmenuntryID);
		$session->setBootosID($bootmenuentry->getBootosID());
		$sessionMapper->save($session);
		
		
		$this->view->host = '132.230.4.27';
		$this->view->alphasessionID = $a;				
	}

}