guestbook.php
3.12 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
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
<?php
/**
* Project: Guestbook of OEDL Homepage. This is derived from the Smarty
* Guestbook example. The original comment to this code can be found
* below.
* Changes: First of all this guestbook uses gettext to achive i18n
* On mozilla i try to figure out the language to use by the
* information provided by the browser. It seems that this works
* also for IE, sadly konqueror behaves different. Well, on
* IE and konquerer it is not possible to view the HP correctly
* 'cause of different reasons, at the moment.
* The next big change is, that i moved the page from Smarty to
* Savant2 this was done with absolutely no pain at all.
* There might ba additions to the functionality of this class
* in future.
* Author: Georg Steffers <georg [AT] steffers [DOT] org>
* Date: Oct 26th, 2006
* File: guestbook.php
* Version: 0.1
*/
/**
* Original comment
* Project: Guestbook Sample Smarty Application
* Author: Monte Ohrt <monte [AT] ohrt [DOT] com>
* Date: March 14th, 2005
* File: guestbook.lib.tpl
* Version: 1.0
*/
require_once (OEDL_DIR . 'libs/guestbook_db.php');
/**
* guestbook application library
*
*/
class Guestbook
{
// database object
var $gdDb = null;
// error number
var $error = 0;
// error messages
var $err_msg = array ();
/**
* class constructor
*/
function __construct ()
{
// instantiate the sql object
$this->gbDb =& new GuestbookDb (OEDL_DIR . 'db/guestbook.db');
$this->gbDb->open ();
// initialize error messages
array_push
(
$this->err_msg,
_("No error"),
_("You must supply a name"),
_("You must supply a comment")
);
}
function __destruct ()
{
if ($this->gbDb)
$this->gbDb->close ();
}
/**
* display the guestbook entry form
*
* @param array $formvars the form variables
*/
function getFormData ($formvars = array ('Name' => '', 'Comment' => ''))
{
return array (
'post' => $formvars,
'error' => $this->error,
'err_msg' => $this->err_msg[$this->error],
'contentTpl' => 'guestbook_form.tpl.php'
);
}
/**
* fix up form data if necessary
*
* @param array $formvars the form variables
*/
function mungeFormData (&$formvars)
{
// trim off excess whitespace
$formvars['Name'] = trim ($formvars['Name']);
$formvars['Comment'] = trim ($formvars['Comment']);
}
/**
* test if form information is valid
*
* @param array $formvars the form variables
*/
function isValidForm ($formvars)
{
// reset error message
$this->error = null;
// test if "Name" is empty
if (strlen ($formvars['Name']) == 0)
{
$this->error = 1;
return false;
}
// test if "Comment" is empty
if (strlen ($formvars['Comment']) == 0)
{
$this->error = 2;
return false;
}
// form passed validation
return true;
}
/**
* add a new guestbook entry
*
* @param array $formvars the form variables
*/
function addEntry ($formvars)
{
return $this->gbDb->addEntry ($formvars['Name'], $formvars['Comment']);
}
/**
* get the guestbook entries
*/
function getEntries ()
{
return $this->gbDb->getEntries ();
}
}
?>