/
include.php
262 lines (247 loc) · 6 KB
/
include.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
//Database connection
if(!function_exists('dbconnect')){
function dbconnect()
{
// Create connection
$con=mysqli_connect("localhost","root","","controls");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else{
return $con;
}
}
}
//Salt function
if(!function_exists('salt'))
{
function salt( $length ) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$size = strlen( $chars );
$str="";
for( $i = 0; $i < $length; $i++ ) {
$str .= $chars[ rand( 0, $size - 1 ) ];
}
return $str;
}
}
//user table details in array
if(!function_exists('userdetails'))
{
function userdetails($user)
{
$con=dbconnect();
$result=mysqli_query($con,"SELECT * FROM users WHERE user='$user'");
$return=array();
while($row=mysqli_fetch_array($result))
{
array_push($return, $row);
}
return $return; //this will return data which will be used as $return[0]['index'];
}
}
//student table details in array
if(!function_exists('studentdetails'))
{
function studentdetails($cid)
{
$con=dbconnect();
$result=mysqli_query($con,"SELECT * FROM student WHERE cogni_id='$cid'");
$return=array();
while($row=mysqli_fetch_array($result))
{
array_push($return, $row);
}
return $return; //this will return data which will be used as $return[0]['index'];
}
}
//participant table details in array
if(!function_exists('participantdetails'))
{
function participantdetails($cid)
{
$con=dbconnect();
$result=mysqli_query($con,"SELECT * FROM participant WHERE cogni_id='$cid'");
$return=array();
while($row=mysqli_fetch_array($result))
{
array_push($return, $row);
}
return $return; //this will return data which will be used as $return[0]['index'];
}
}
//login function
if(!function_exists('login'))
{
function login($username,$pass)
{
@session_start();
@$user=userdetails($username);
@$salt=$user[0]['salt'];
@$password=$user[0]['password'];
if(md5($salt.md5($pass))==$password)
{
$_SESSION['user']=$username;
header("location: index.php");
}
else
{
$_SESSION['error']="Invalid Username or Password";
// header("location: login.php");
}
}
}
//adduser function
if(!function_exists('adduser'))
{
function adduser($username,$password, $usertype)
{
@session_start();
$salt=salt(8);
$user=userdetails($username);
$pass=md5($salt.md5($password));
if(count($user)==0)
{
$con=dbconnect();
mysqli_query($con,"INSERT INTO users (user, salt, password, type) VALUES ('$username', '$salt', '$pass', '$usertype')");
$_SESSION['success']="User added";
// header("location: adduser.php");
}
else
{
$_SESSION['error']="Username already exist";
// header("location: adduser.php");
}
}
}
//resetpassword function
if(!function_exists('resetpassword'))
{
function resetpassword($username,$password)
{
@session_start();
$salt=salt(8);
$user=userdetails($username);
if(count($user)==1)
{
$salt=$user[0]["salt"];
$pass=md5($salt.md5($password));
$con=dbconnect();
mysqli_query($con,"INSERT INTO users (password) VALUES ('$password')");
$_SESSION['success']="Password reset";
// header("location: resetpassword.php");
}
else
{
$_SESSION['error']="Invalid Username";
// header("location: resetpassword.php");
}
}
}
//loguser function
if(!function_exists('loguser'))
{
function loguser($username)
{
@session_start();
$user=userdetails($username);
if(count($user)==1)
{
$_SESSION['user']=$username;
header("location: index.php");
}
else
{
$_SESSION['error']="Invalid Username";
// header("location: resetpassword.php");
}
}
}
//counter1 function
if(!function_exists('counter1'))
{
function counter1($cid, $noc, $registrationreceipt, $payment)
{
@session_start();
$student=studentdetails($cid);
if(count($student)==1)
{
$fname=$student[0]['first_name'];
$lname=$student[0]['last_name'];
$name=$fname." ".$lname;
$college=$student[0]['collegeName'];
$mobile=$student[0]['mobileNo'];
$email=$student[0]['email'];
$pfees=$student[0]['participation_fees'];
$wfees=$student[0]['workshop_fees'];
$con=dbconnect();
mysqli_query($con,"INSERT INTO participant (cogni_id, name, collegeName, mobileNo, email, payment, participation_fees, workshop_fees, noc, registration_receipt, last_counter)
VALUES ('$cid','$name','$college','$mobile','$email','$payment','$pfees','$wfees','$noc','$registrationreceipt','1')");
$_SESSION['success']="Done";
}
else
{
$_SESSION['error']="Something went wrong";
// header("location: resetpassword.php");
}
}
}
//counter2 function
if(!function_exists('counter3'))
{
function counter3($cid, $idcard, $kit)
{
@session_start();
$student=studentdetails($cid);
if(count($student)==1)
{
$con=dbconnect();
mysqli_query($con,"UPDATE participant SET idcard='$idcard', kit='$kit', last_counter='3' WHERE cogni_id='$cid'");
$_SESSION['success']="Done";
}
else
{
$_SESSION['error']="Something went wrong";
// header("location: resetpassword.php");
}
}
}
//acco function
if(!function_exists('acco'))
{
function acco($cid, $bhawan, $room)
{
@session_start();
$student=studentdetails($cid);
if(count($student)==1)
{
$con=dbconnect();
mysqli_query($con,"UPDATE participant SET bhawan='$bhawan', room='$room' WHERE cogni_id='$cid'");
$_SESSION['success']="Done";
}
else
{
$_SESSION['error']="Something went wrong";
// header("location: resetpassword.php");
}
}
}
//partcount function
if(!function_exists('partcount'))
{
function partcount()
{
$con=dbconnect();
$result=mysqli_query($con,"SELECT * FROM participant WHERE last_counter='3'");
$count=0;
while($row=mysqli_fetch_array($result))
{
$count++;
}
return $count;
}
}
?>