-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
74 lines (69 loc) · 2.21 KB
/
index.php
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
<?php
/**
* Project: Guestbook Sample Smarty Application
* Author: Monte Ohrt <monte [AT] ohrt [DOT] com>
* File: index.php
* Version: 1.1
*/
// define our application directory
define('GUESTBOOK_DIR', '/home/ricblt/workspace/guestbook/');
// define smarty lib directory
define('SMARTY_DIR', '/home/ricblt/workspace/guestbook/Smarty-3.1.16/libs/');
// include the setup script
include(GUESTBOOK_DIR . 'libs/guestbook_setup.php');
include(GUESTBOOK_DIR . 'libs/GuestbookData.php');
$data = new GuestbookData();
// create guestbook object
$guestbook = new Guestbook($data);
// set the current action
$_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
switch($_action) {
case 'add':
// adding a guestbook entry
$guestbook->displayForm();
break;
case 'submit':
// submitting a guestbook entry
$guestbook->mungeFormData($_POST);
if($guestbook->isValidForm($_POST)) {
$guestbook->addEntry($_POST);
$guestbook->displayBook($guestbook->getEntries());
} else {
$guestbook->displayForm($_POST);
}
break;
case 'view':
default:
if(!isset($_SESSION['id']) || $_SESSION['id']== 0){
$guestbook->displayLoginForm();
}else{
$guestbook->logout();
$guestbook->displayLogoutForm();
}
// viewing the guestbook
$guestbook->displayBook($guestbook->getEntries());
break;
case 'loginSubmit':
$guestbook->mungeLoginFormData($_POST);
if($guestbook->isValidLoginForm($_POST)) {
$guestbook->login($_POST);
$guestbook->displayLoginForm($_POST);
}else{
$guestbook->displayLoginForm($_POST);
}
break;
case 'reg':
//if(!isset($_SESSION['id']) || $_SESSION['id']== 0){
$guestbook->displayRegForm();
// }
break;
case 'regSubmit':
$guestbook->mungeRegFormData($_POST);
if($guestbook->isValidRegForm($_POST)) {
$guestbook->registration($_POST);
$guestbook->displayRegForm($_POST);
}else{
$guestbook->displayRegForm($_POST);
}
break;
}