-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
104 lines (97 loc) · 3.15 KB
/
view.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
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.2//EN">
<HEAD>
<TITLE>Chattr</TITLE>
</HEAD>
<BODY BGCOLOR=WHITE>
<TABLE ALIGN="CENTER">
<TR><TD>
<H1>Chattr</H1>
</TD></TR>
<?php
session_start();
// The following <TR> element should only appear if the user is
// logged in and viewing his own entry.
if(!empty($_SESSION['user']))
{
$URLUSER = $_GET['user'];
if(!($URLUSER) || (($URLUSER) && ($URLUSER == $_SESSION['user'][1])))
{
echo '<TR><TD>';
echo '<FORM ACTION="post.php" METHOD="POST">';
echo '<TABLE CELLPADDING=5>';
echo '<TR><TD>Message:</TD><TD><INPUT TYPE="TEXT" NAME="TEXT">';
echo '<INPUT TYPE="SUBMIT" VALUE="Submit"></TD></TR>';
echo '</TABLE>';
echo '</FORM>';
echo '</TD></TR>';
}
}
?>
<?php
// The following <TR> element should always appear if the user
// exists.
?>
<TR><TD>
<TABLE CELLPADDING=5>
<?php
// Display user's posts here. The structure is:
//
$conn = pg_connect("host=localhost dbname=chattr user=student password=hacktheplanet");
$URLUSER = $_GET['user'];
$result = pg_query($conn, "SELECT * FROM public.user WHERE username='$URLUSER'");
if($row = pg_fetch_row($result))
{
echo '<TR><TH>When</TH><TH>Who</TH><TH>What</TH></TR>';
$result = pg_query($conn, "SELECT * FROM public.msg WHERE username='$URLUSER'");
while($row = pg_fetch_row($result))
{
echo '<TR>';
echo '<TD>'.$row[2].'</TD>';
echo '<TD>'.$row[0].'</TD>';
echo '<TD>'.$row[1].'</TD>';
echo '</TR>';
}
}
else if(!empty($_SESSION['user']) && !($URLUSER))
{
echo '<TR><TH>When</TH><TH>Who</TH><TH>What</TH></TR>';
$currUser = $_SESSION['user'][1];
$result = pg_query($conn, "SELECT * FROM public.msg WHERE username='$currUser'");
while($row = pg_fetch_row($result))
{
echo '<TR>';
echo '<TD>'.$row[2].'</TD>';
echo '<TD>'.$row[0].'</TD>';
echo '<TD>'.$row[1].'</TD>';
echo '</TR>';
}
}
?>
</TABLE>
</TD></TR>
<?php
// The following <TR> element should be displayed if the user
// name does not exist. Add code to display user name.
$conn = pg_connect("host=localhost dbname=chattr user=student password=hacktheplanet");
$URLUSER = $_GET['user'];
$result = pg_query($conn, "SELECT * FROM public.user WHERE username='$URLUSER'");
if(!($row = pg_fetch_row($result)) && $URLUSER)
{
echo '<TR><TD>';
echo '<H2>User '.$_GET['user'].' does not exist!</H2>';
echo '</TD></TR>';
}
?>
<?php
// The following <TR> element should only be shown if the user
// is logged in.
if(!empty($_SESSION['user']))
{
echo '<TR><TD><A HREF="logout.php">Logout</A></TR></TD>';
}
?>
<?php
// Done!
?>
</TABLE>
</BODY>