This repository has been archived by the owner on Jan 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
108 lines (84 loc) · 2.59 KB
/
functions.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
<?php
function check_login($con){
if(isset($_SESSION['user_id'])){
$id = $_SESSION['user_id'];
$query = "select * from users where user_id= '$id' limit 1";
$result = mysqli_query($con,$query);
if($result && mysqli_num_rows($result) > 0){
$user_data = mysqli_fetch_assoc($result);
return $user_data;
}
}else{
//redirect to login
header("Location: /index.php");
die;
}
}
function already_login($con){
if(isset($_SESSION['user_id'])){
$id = $_SESSION['user_id'];
$query = "select * from users where user_id= '$id' limit 1";
$result = mysqli_query($con,$query);
if($result && mysqli_num_rows($result) > 0){
$user_data = mysqli_fetch_assoc($result);
return $user_data;
}
//if already logged-in dont login or sign up again go straight to welcome page
//this is useful in case user presses back from welcome page and tries to login again
header("Location: welcome.php");
}else{
//do nothing, stay at login
}
}
function getDataByID($id,$con){
check_admin();
$query = "SELECT name,surname,username,email,role FROM users WHERE id = '$id' LIMIT 1";
$result = mysqli_query($con,$query);
if($result && mysqli_num_rows($result) > 0){
$user_data = mysqli_fetch_assoc($result);
return $user_data;
}
}
function getUnameByID($id,$con){
check_login($con);
check_user();
$query = "SELECT username FROM users WHERE id = '$id' LIMIT 1";
$result = mysqli_query($con,$query);
if($result && mysqli_num_rows($result) > 0){
$user_data = mysqli_fetch_assoc($result);
return $user_data;
}
}
function check_admin(){
if(isset($_SESSION['user_id'])){
if($_SESSION['user_role'] === "ADMIN"){
//do nothing
}else{
header("Location: /authfailed.php");
}
}else{
header("Location: /index.php");
}
}
function check_user(){
if(isset($_SESSION['user_id'])){
if($_SESSION['user_role'] === "USER"){
//do nothing
}else{
header("Location: /authfailed.php");
}
}else{
header("Location: /index.php");
}
}
function check_organizer(){
if(isset($_SESSION['user_id'])){
if($_SESSION['user_role'] === "ORGANIZER"){
//do nothing
}else{
header("Location: /authfailed.php");
}
}else{
header("Location: /index.php");
}
}