-
Notifications
You must be signed in to change notification settings - Fork 1
/
out.php
145 lines (130 loc) · 4.24 KB
/
out.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="snackbar.css" rel="stylesheet"/>
</head>
<body>
<div id="snackbar">Incorrect Username/Password Plese recheck and enter again</div>
<script type="text/javascript" src="snackbar.js"></script>
<?php
date_default_timezone_set( "Asia/Colombo" );
function navigate( $location = null, $msg = null ) {
if ( $msg == null ) {
echo '<script>window.location.replace("' . $location . '");</script>';
} else {
echo '<script>window.location.replace("' . $location . '?msg=' . $msg . '");</script>';
}
}
session_start();
if ( isset( $_SESSION[ "member-visit" ] ) && $_SESSION[ "member-visit" ] != "" ) {
if ( isset( $_COOKIE[ 'date' ] ) && isset( $_COOKIE[ 'timein' ] ) && $_COOKIE[ 'date' ] == date( "Y-m-d" ) ) {
} else {
unset( $_SESSION );
session_destroy();
if ( isset( $_COOKIE[ 'date' ] ) ) {
unset( $_COOKIE[ 'date' ] );
setcookie( 'date', null, -1, '/' );
}
if ( isset( $_COOKIE[ 'timein' ] ) ) {
unset( $_COOKIE[ 'timein' ] );
setcookie( 'timein', null, -1, '/' );
}
navigate( "member-enter.php" );
}
require 'conn.php';
$sql = "SELECT * FROM `member` WHERE `MemUName`='" . $_SESSION[ "member-visit" ] . "';";
$result = mysqli_query( $conn, $sql );
if ( mysqli_num_rows( $result ) > 0 ) {
$row = mysqli_fetch_assoc( $result );
$uname = $row[ 'MemName' ];
} else {
navigate( "member-enter.php","incorrect username" );
exit;
}
$conn->close();
} elseif ( isset( $_SESSION[ "visitor-visit" ] ) && $_SESSION[ "visitor-visit" ] != "" ) {
if ( isset( $_COOKIE[ 'date' ] ) && isset( $_COOKIE[ 'timein' ] ) && $_COOKIE[ 'date' ] == date( "Y-m-d" ) ) {
} else {
unset( $_SESSION );
session_destroy();
if ( isset( $_COOKIE[ 'date' ] ) ) {
unset( $_COOKIE[ 'date' ] );
setcookie( 'date', null, -1, '/' );
}
if ( isset( $_COOKIE[ 'timein' ] ) ) {
unset( $_COOKIE[ 'timein' ] );
setcookie( 'timein', null, -1, '/' );
}
navigate( "visitor-enter.php" );
}
require 'conn.php';
$sql = "SELECT * FROM `visitor` WHERE `ViNIC`='" . $_SESSION[ "visitor-visit" ] . "';";
$result = mysqli_query( $conn, $sql );
if ( mysqli_num_rows( $result ) > 0 ) {
$row = mysqli_fetch_assoc( $result );
$uname = $row[ 'ViName' ];
} else {
navigate( "visitor-enter.php" );
exit;
}
$conn->close();
} else {
navigate( "index.php" );
}
?>
<h1>You checked in as <?php echo($uname); ?></h1>
<h2>Date : <?php echo($_COOKIE[ "date" ]); ?></h2>
<h2>time : <?php echo($_COOKIE[ "timein" ]); ?></h2>
<h3><?php echo date_default_timezone_get(); ?></h3>
<form method="post" action="out.php">
<button type="submit" name="out">Mark out</button>
</form>
<?php
if ( isset( $_POST[ 'out' ] ) ) {
if(isset($_SESSION[ "member-visit" ])){
require 'conn.php';
$sql = "UPDATE `member_log` SET `TimeOut`='" . date( "H:i:s" ) . "' WHERE `MemUName`= '" . $_SESSION[ "member-visit" ] . "' AND `Date` = '" . $_COOKIE[ "date" ] . "' AND `TimeIn`='" . $_COOKIE[ "timein" ] . "';";
echo( $sql );
if ( $conn->query( $sql ) === TRUE ) {
unset( $_SESSION );
session_destroy();
if ( isset( $_COOKIE[ 'date' ] ) ) {
unset( $_COOKIE[ 'date' ] );
setcookie( 'date', null, -1, '/' );
}
if ( isset( $_COOKIE[ 'timein' ] ) ) {
unset( $_COOKIE[ 'timein' ] );
setcookie( 'timein', null, -1, '/' );
}
navigate( "member-enter.php" );
} else {
navigate( "out.php", $conn->error );
}
$conn->close();
}elseif(isset($_SESSION[ "visitor-visit" ])){
require 'conn.php';
$sql="UPDATE `visitor_log` SET `TimeOut`='" . date( "H:i:s" ) . "' WHERE `ViNIC`= '" . $_SESSION[ "visitor-visit" ] . "' AND `Date`='" . $_COOKIE[ "date" ] . "' AND `TimeIn`= '" . $_COOKIE[ "timein" ] . "'";
echo( $sql );
if ( $conn->query( $sql ) === TRUE ) {
unset( $_SESSION );
session_destroy();
if ( isset( $_COOKIE[ 'date' ] ) ) {
unset( $_COOKIE[ 'date' ] );
setcookie( 'date', null, -1, '/' );
}
if ( isset( $_COOKIE[ 'timein' ] ) ) {
unset( $_COOKIE[ 'timein' ] );
setcookie( 'timein', null, -1, '/' );
}
navigate( "member-enter.php" );
} else {
echo( $conn->error );
}
$conn->close();
}
}
?>
</body>
</html>