-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
79 lines (71 loc) · 2 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
<?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;
}
}
// redirect to login
//header("Location: login.php");
//die;
}
function check_login_and_redirect($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;
}
}
// redirect to login
header("Location: login.php");
die;
}
function random_num($length)
{
$text = "";
if ($length < 5) {
$length = 5;
}
$len = rand(4, $length);
for ($i = 0; $i < $len; $i++) {
$text .= rand(0, 9);
}
return $text;
}
function check_login_and_role($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);
if ($user_data['role'] == 'admin' || $user_data['role'] == 'owner') {
return $user_data;
} else {
header("Location: index.php");
die;
}
}
}
// redirect to login
header("Location: login.php");
die;
}
function format_money($value)
{
return 'R' . number_format((float)$value, 2, '.', '');
}
function format_money_no_sym($value)
{
return number_format((float)$value, 2, '.', '');
}