summaryrefslogtreecommitdiffstats
path: root/application/controllers/SessionController.php
blob: 6d0a873da7b8c65c44cecffc271847fa38de5d26 (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
<?php

class SessionController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $mapper = new Application_Model_SessionMapper();
		$this->view->sessions = $mapper->fetchAll();
    }

    public function createsessionAction()
    {
		$cm = new Application_Model_ClientMapper();
		$clients = $cm->fetchAll();

		$bm = new Application_Model_BootOsMapper();
		$bootos = $bm->fetchAll();

		$bi = new Application_Model_BootIsoMapper();
		$bootisos = $bi->fetchAll();

		if (!isset($_POST["add"])){
    		$createsession = new Application_Form_Session(array('buttontext' => 'Create Session','clients'=>$clients,'bootos'=>$bootos,'bootisos'=>$bootisos)); 		
			$this->view->createsession = $createsession;		
		}else {
			// TODO extend with normal function not only with post
			$createsession = new Application_Form_Session(array('buttontext' => 'Create Session','clients'=>$clients,'bootos'=>$bootos,'bootisos'=>$bootisos),$_POST);
			print_a($_POST);
			if ($createsession->isValid($_POST)) {			
				try{
					$session = new Application_Model_Session($_POST);
					$session->setTime(strtotime($_POST['time']));
					if($session->getClientID() == ''){
						$session->setClientID(null);
					}
					if($session->getBootosID() == ''){
						$session->setBootosID(null);
					}
					$sessionmapper = new Application_Model_SessionMapper();
					$sessionmapper->save($session);
				
					$this->_redirect('/session');
			    	
				}catch (Zend_Exception $e) {  
        			echo "Error message 2: " . $e->getMessage() . "\n";  
        		}				
			}
			$this->view->createsession = $createsession;
		}
    }

    public function editsessionAction()
    {
		$cm = new Application_Model_ClientMapper();
		$clients = $cm->fetchAll();

		$bm = new Application_Model_BootOsMapper();
		$bootos = $bm->fetchAll();

		$bi = new Application_Model_BootIsoMapper();
		$bootisos = $bi->fetchAll();
       if (!isset($_POST["add"])){
		    // TODO: ACL implementieren ob er editieren darf
			$sessionID = $this->_request->getParam('sessionID');
			$session = new Application_Model_Session();
			

			$sessionmapper = new Application_Model_SessionMapper();
			$sessionmapper->find($sessionID,$session);				
			$session->setTime(date('d.m.Y H:i',$session->getTime()));	
			$session2 = $session->toArray();

			$editsession = new Application_Form_Session(array('buttontext' => 'Edit Session','clients'=>$clients,'bootos'=>$bootos,'bootisos'=>$bootisos)); 
			$editsession->populate($session2);
			$this->view->editsession = $editsession;
		
		} else{
			try{
				$sessionID = $this->_request->getParam('sessionID');	
				
				$editsession = new Application_Form_Session(array('buttontext' => 'Edit Session','clients'=>$clients,'bootos'=>$bootos,'bootisos'=>$bootisos),$_POST);

				if ($editsession->isValid($_POST)) {	
					$session = new Application_Model_Session($_POST);
					$session->setID($this->_request->getParam('sessionID'));					
					$session->setTime(strtotime($_POST['time']));
					if($session->getClientID() == ''){
						$session->setClientID(null);
					}
					if($session->getBootosID() == ''){
						$session->setBootosID(null);
					}
					$sessionmapper = new Application_Model_SessionMapper();				
					$sessionmapper->save($session);
					echo 'valid';					
				}
				else
				{
					echo 'not valid';
				}
			}catch (Zend_Exception $e) {  
    			echo "Error message 2: " . $e->getMessage() . "\n";  
    		}
			$this->_redirect('/session');
		}		
    }

    public function deletesessionAction()
    {
       $sessionID = $this->_request->getParam('sessionID');
		if(is_numeric($sessionID)){
			$deletesession = new Application_Model_Session();
			$deletesession->setID($sessionID);
			$sessionmapper = new Application_Model_SessionMapper();
			$sessionmapper->delete($deletesession);
		}
		$this->_redirect('/session');
    }


}