-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.php
204 lines (171 loc) · 6.49 KB
/
server.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
199
200
201
202
203
204
<?php
//session_start();
$username = "";
$email = "";
$department = "";
$semester = "";
$subject = "";
$date = "";
$admin="";
$password="";
$regno="";
$data="";
$apptime="";
$alertq="";
$errors = array();
// connect to the databse
$db = mysqli_connect('localhost','root','password','appointment');
// if the register button is clicked
if (isset($_POST['appoint'])){
//$username = mysqli_real_escape_string($db, $_POST['username']);
$department = mysqli_real_escape_string($db, $_POST['department']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$semester = mysqli_real_escape_string($db, $_POST['semester']);
$subject = mysqli_real_escape_string($db, $_POST['subject']);
$date = mysqli_real_escape_string($db, $_POST['date']);
//ensure that form fields are filled properly
/* if(empty($username)){
array_push($errors, "username is required"); // add error to errors array
}*/
if(empty($department)){
array_push($errors, "Department is required"); // add error to errors array
}
if(empty($email)){
array_push($errors, "E-mail is required"); // add error to errors array
}
if(empty($semester)){
array_push($errors, "Semester is required"); // add error to errors array
}
if(empty($subject)){
array_push($errors, "Subject is required"); // add error to errors array
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
array_push($errors, "Wrong email format");
}
$today=date("Y-m-d");
if(empty($date)){
array_push($errors, "Date is required");
$date=$today; // add error to errors array
}
if($date<$today)
{
array_push($errors, "Booking for this date is'nt available");
}
$diff = abs(strtotime($date) - strtotime($today));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
if($days>6)
{
array_push($errors, "Booking for this date is'nt available");
}
$rr="SELECT * FROM appointments WHERE date='$date'";
//$rr1="SELECT * FROM appointments WHERE regno='$regno'";
//$result1=mysqli_query($db,$rr1);
$result=mysqli_query($db,$rr);
// Return the number of rows in result set
$rowcount=mysqli_num_rows($result);
//$rowcount1=mysqli_num_rows($result1);
if($rowcount>5)
{
array_push($errors, "Booking for this date is already full");
}
if($rowcount>0 && $rowcount<3)
{
$apptime="10:00 A.M - 12:00 P.M";
}
if($rowcount>2 && $rowcount<6)
{
$apptime="2:00 A.M - 4:00 P.M";
}
/*if($rowcount1>5)
{
array_push($errors, "You have already booked for this date!");
}*/
if(date('D', strtotime($date)) == 'Sat' || date('D', strtotime($date)) == 'Sun') {
array_push($errors, "Booking isnt available for this date");
}
//if there are no errors, save user to database
if(count($errors)==0){
$sql = "INSERT INTO appointments (username, email, department, semester, subject, date)
VALUES ('$username', '$email', '$department', '$semester', '$subject', '$date')";
$alertq=mysqli_query($db, $sql);
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->SMTPAutoTLS = false;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = '[email protected]';
$mail->Password = 'toosoonsuperman';
$mail->setFrom('[email protected]', 'NSSCE OFFICE');
$mail->addReplyTo('[email protected]', 'AswinDinesh');
$mail->addAddress($email);
$mail->Subject = "NSSCE APPOINTMENT BOOKING SUCCESSFUL";
$mail->Body = " Appointment Confirmed for $username
Date : $date
Time : $apptime
Please keep required documents with you.
Thank You for booking with us!";
if (!$mail->Send()) {
$error = "Mailer Error: " . $mail->ErrorInfo;
?><script>alert('<?php echo $error ?>. Contact Admin.');</script><?php
}else{
echo "<script>alert(Contact Admin)</script>";
}
$_SESSION['username']=$username;
$_SESSION['success']="You are now logged in";
//header('location: index.php'); //redirect to home page
/*//echo 'alert("Password Invalid!")';
//header('location: index.php'); //redirect to home page
echo '<script>';
echo 'alert("BOOKING SUCCESSFULL!");';
//echo 'location.href="index.php"';
echo '</script>';*/
if($alertq)
{
//echo 'alert("Password Invalid!")';
//header('location: index.php'); //redirect to home page
echo '<script>';
echo 'alert("BOOKING SUCCESSFULL!");';
echo 'window.location.href="appoint.php"';
echo '</script>';
}
}
}
//log user in from login page
/* if(isset($_POST['login'])){
$admin = mysqli_real_escape_string($db, $_POST['admin']);
$password = mysqli_real_escape_string($db, $_POST['password']);
//ensure that form fields are filled properly
if(empty($admin)){
array_push($errors, "username is required"); // add error to errors array
}
if(empty($password)){
array_push($errors, "Password is required"); // add error to errors array
}
if(count($errors)==0){
$password=md5($password);
$query = "SELECT * FROM adminuser WHERE admin='$admin' AND password='$password'";
$result=mysqli_query($db, $query);
if(mysqli_num_rows($result)==1){
//log user in
$_SESSION['admin']=$admin;
$_SESSION['success']="You are now logged in";
header('location: admin.php'); //redirect to home page
}else{
array_push($errors, "Wrong username/password combination");
}
}
}
//logout
if(isset($_GET['logout'])){
session_destroy();
unset($_SESSION['regno']);
header('location: index.php');
}
*/
?>