-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
91 lines (80 loc) · 1.98 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
require_once('init.php');
require_once(ROOT . 'lib/database/MySQL.class.php');
require_once(ROOT . 'lib/contact/ContactManager.class.php');
require_once(ROOT . 'lib/session/SessionManager.class.php');
if(!isset($_COOKIE["lcmsession"]) or $_COOKIE["lcmsession"]<0){
header("Location:login.php");
exit;
}
$sessionid=$_COOKIE["lcmsession"];
$sm=new SessionManager();
$mysql = new MySQL();
$uid=$sm->getUid($sessionid,$mysql);
$title = "Local Contact Manager";
echo <<<HEADER
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>$title</title>
</head>
<body>
HEADER;
echo "<h1><enhanCSE/> Local Contact Manager</h1>";
echo '<p align="right"><a href="logout.php">Logout!</a></p>';
$cm = new ContactManager();
if(isset($_POST['action'])){
$action = $_POST['action'];
switch($action) {
case 'New Contact ...' :
{
$cm->displayForm($mysql);
break;
}
case 'Edit' :
{
if(!isset($_POST['cid']))
echo "<p>The contact was not selected. Please try again.</p>";
else {
$cid = $_POST['cid'];
$cm->displayForm($mysql, $cid, $uid);
}
break;
}
case 'Delete' :
{
if(!isset($_POST['cid']))
echo "<p>The contact was not selected. Please try again.</p>";
else {
$cid = $_POST['cid'];
$cm->deleteContact($mysql, $cid, $uid);
}
break;
}
case 'Save' :
{
if(!isset($_POST['cname']))
echo "<p>The contact cannot be empty.</p>";
else {
$name = $_POST['cname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$cid = $_POST['cid'];
if($cid == 0)
$cm->addContact($mysql, $name, $email, $phone, $uid);
else
$cm->updateContact($mysql, $cid, $name, $email, $phone, $uid);
}
break;
}
default :
}
}
$cm->viewContacts($uid, $mysql);
echo <<<FOOTER
<div id="footer"><p>Powered by enhanCSE 2011</p></div>
</body>
</html>
FOOTER;
?>