oedl_ctrl.php
2.91 KB
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
<?php
// Guestbook Kram
require_once (OEDL_DIR . 'libs/guestbook.php');
// get all stuff about menus
require_once (OEDL_DIR . 'libs/menu.php');
// get GNURU_WISDOM constant
require_once (OEDL_DIR . 'libs/gnuru.php');
// get Savant2 baseclass
require_once ('/usr/share/php/Savant2.php');
// now create out controller
class OEDLController extends Savant2
{
/*** private member ***/
private $menu; /* a reference to a menu object */
private $gnuru; /* a reference to a gnuru object */
private $gb; /* mein Gästebuch */
/*** public methods ***/
/*
* Constructor
*/
function __construct ()
{
$this->addPath ('template', OEDL_DIR . 'templates');
$this->addPath ('resource', SAVANT_DIR);
$this->addPath ('resource', OEDL_DIR . 'resources');
error_reporting (E_ALL);
try
{
$this->menu =& new menu;
$this->gnuru =& new gnuru;
$this->gb =& new Guestbook;
}
catch (MyException $e)
{
$this->display ('init_err.tpl.php');
exit (1);
}
$this->assign ('gnuruWisdom', $this->gnuru->getWisdom ());
}
/*
* doRequest: processes a request. The only public function beneath the
* constructor (well, at the moment)
*
* @param: request array containing the request (normally $_REQUEST)
*/
function doRequest ($request)
{
$content = isset($request['cont']) ? $request['cont'] : 'about';
$this->assign ('menuItems', $this->menu->menuGet ());
$this->assign ('contentId', $content);
$this->assign ('contentHead', $this->menu->menuGetTextById ($content));
$this->assign ('contentTpl', $this->menu->menuGetTplById ($content));
$action = isset($request['action']) ? $request['action'] : 'view';
switch ($content)
{
case 'guestbook':
switch ($action)
{
/* all actions that could accure will be handles here */
case 'add':
// adding a guestbook entry
$this->assign ($this->gb->getFormData ());
break;
case 'submit':
// submitting a guestbook entry
$this->gb->mungeFormData($_POST);
if($this->gb->isValidForm($_POST))
{
try
{
$this->gb->addEntry($_POST);
$this->assign ('data', $this->gb->getEntries());
}
catch (MyException $e)
{
$this->assign ('contentId', $content);
$this->assign ('contentHead', _('Error'));
$this->assign ('contentTpl', 'error.tpl.php');
}
}
else
{
$this->assign ($this->gb->getFormData($_POST));
}
break;
case 'view':
default:
try {
$this->assign ('data', $this->gb->getEntries());
}
catch (MyException $e)
{
$this->assign ('contentId', $content);
$this->assign ('contentHead', _('Error'));
$this->assign ('contentTpl', 'error.tpl.php');
}
break;
}
}
$this->display ('frame.tpl.php');
}
}
?>