/
event.php
198 lines (149 loc) · 5.53 KB
/
event.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
include("header.php");
include("getInputSafe.php");
include("social_media.php");
$valid_user = validate_user();
$id = $_GET['id'];
if(!validateInput($number_match,$id))
{
header("Location: main.php?errorMsg=".urlencode("Illegal DATA in GET to Access an Event!"));
return '';
}
//get event
$stmt = $dbh->prepare("SELECT * from events
INNER JOIN users
ON users.id=events.owner
INNER JOIN eventTypes
ON eventTypes.id=events.eventtype
WHERE events.id_event= ?");
$stmt->execute(array($id));
$event_info = $stmt->fetchAll();
if($event_info[0]['publico']==0) {
if($valid_user) {
$stmt = $dbh->prepare("SELECT * from invitations
WHERE user_id=? AND event_id=?");
$stmt->execute(array($_SESSION['login_user'],$id));
$invitations = $stmt->fetchAll();
if(count($invitations)<=0 && $_SESSION['login_user']!=$event_info[0]['owner']) {
header("Location: main.php");
}
}
else {
header("Location: main.php");
}
}
//get event comments
$stmt = $dbh->prepare("SELECT * from comments
INNER JOIN users ON users.id=comments.user_id
WHERE comments.event_id= ? ORDER BY date_comment DESC");
$stmt->execute(array($id));
$comments = $stmt->fetchAll();
//get event users
$stmt = $dbh->prepare("SELECT * from registers
INNER JOIN users ON users.id=registers.user_id
WHERE registers.event_id= ? ORDER BY username ASC");
$stmt->execute(array($id));
$registredUsers = $stmt->fetchAll();
$last_comment_id = end($comments)['id'];
/* function htmlencode($str) {
$str = HTMLPurifier_Encoder::cleanUTF8($str);
$str = htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
return $str;
}*/
/*function checkRegister($userid) {
$stmt = $dbh->prepare("SELECT COUNT(*) from registers
WHERE event_id=? AND user_id=?");
$stmt->execute(array($id,$userid));
return $stmt->fetch();
}*/
?>
<!DOCTYPE HTML>
<html>
<head>
<title><?=$event_info[0]['title']?></title>
<meta property="og:url" content="<?php echo 'http://'.$_SERVER['HTTP_HOST'].'/event.php?id='.$event_info[0]['id_event'];?>" />
<meta property="og:type" content="website" />
<meta property="og:title" content="EventBook - <?=$event_info[0]['title']?>" />
<meta property="og:description" content="<?=$event_info[0]['description']?>" />
<meta charset="utf-8">
<link rel="stylesheet" href="css/myStyle.css">
<?php
meta_includes();
$_SESSION['display_event_id']=$id;//echo ("var event_id=".json_encode($id).";");
//echo ("var last_comment_id=0;");//.json_encode($last_comment_id).";");
?>
<?php if($valid_user) echo "<script type=\"text/javascript\" src=\"login_funcs.js\"></script>"; ?>
<script type="text/javascript" src="event.js"></script>
</head>
<body>
<!--input type="hidden" id="event_id" data-value=<!--php? echo $id; ?>-->
<header>
<?php login_header(); ?>
<h1><?=$event_info[0]['title']?></h1>
</header>
<section id="pseudo_chat" >
<?php
if($valid_user)
echo '<br><form action="sendimage.php" method="post" enctype="multipart/form-data">
<input type="file" name="image">
<input type="hidden" name="event_id" value="'.$_GET['id'].'")>
<input type="submit" value="upload image">
</form>';
?>
<h3 id="show_regs_or_coms_button" >Click me to see Registers</h3>
</section>
<div id="comments" > </div>
<div id="registered_users">
<!--p><strong>Registered Users</strong></p-->
<?php foreach($registredUsers as $row) { ?>
<?php echo $row['username']; ?><br>
<?php } ?>
</div>
<aside id="event">
<section id="social_media">
<?php facebook_share($event_info[0]['id_event']); twitter_share();?>
</section>
<section>
<br>
<?php
if($valid_user) {
$stmt = $dbh->prepare("SELECT COUNT(*) as count from registers
WHERE event_id=? AND user_id=?");
$stmt->execute(array($id,$_SESSION['login_user']));
$registered = $stmt->fetch();
if($registered['count']==0) {
echo '<form method="post" action="register.php">
<input type="hidden" name="event_id" value="'.$event_info[0]['id_event'].'">
<input type="hidden" name="user_id" value="'.$_SESSION['login_user'].'">
<input type="submit" value="Going">
</form>';
}
else {
echo '<form method="post" action="register_delete.php">
<input type="hidden" name="event_id" value="'.$event_info[0]['id_event'].'">
<input type="hidden" name="user_id" value="'.$_SESSION['login_user'].'">
<input type="submit" value="Not going" >
</form>';
}
}
else {
echo '<b>Create an account (or login) to register yourself!</b>';
}
if($valid_user && $_SESSION['login_user']==$event_info[0]['owner']) {
echo '<br>
<a href="edit_event.php?id='.$event_info[0]['id_event'].'" class="button">Edit</a>
<a href="delete_event.php?id='.$event_info[0]['id_event'].'" class="button">Delete</a>
<a href="event_invite.php?id='.$event_info[0]['id_event'].'" class="button">Invite</a>
';
}
?>
<br>
<p>Creator: <?=$event_info[0]['username']?></p>
<p>Date: <?=$event_info[0]['event_date']?></p>
<p>Type: <?=$event_info[0]['name']?></p>
<p>Description:<br> <?=$event_info[0]['description']?></p>
</section>
</aside>
<footer id="image_slider"></footer>
</body>
</html>