-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
73 lines (63 loc) · 1.61 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
<?php
function messageFlash()
{
if (isset($_SESSION['flash'])) {
echo $_SESSION['flash'];
unset($_SESSION['flash']);
}
}
function setLists($bdd, $tableName, $displayField, $withTitle = false, $selectedId = null)
{
if ($withTitle) {
?>
<option>Select <?php echo $displayField ?></option>
<?php
}
$result = $bdd->query("SELECT * FROM " . $tableName);
while ($row = $result->fetch_object()) {
?>
<option
<?= $selectedId == $row->id ? 'selected' : '' ?>
value="<?= $row->id ?>"><?= $row->$displayField ?></option>
<?php
}
}
function checkPermissions($role) {
if (isset($_SESSION['roles'])) {
$array = $_SESSION['roles'];
if (in_array($role, $array)) {
//That's OK
} else {
header('location:index.php?user=login');
}
} else {
header('location:index.php?user=login');
}
}
function isAdmin() {
if (isset($_SESSION['roles'])) {
$array = $_SESSION['roles'];
if (in_array('Banker', $array)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
function sanitizeText($text)
{
$textMinuscule = mb_strtolower($text);
$string = (string)$textMinuscule;
$string1 = str_replace("select", "", $string);
$string2 = str_replace("update", "", $string1);
$string3 = str_replace("delete", "", $string2);
$string4 = str_replace("update", "", $string3);
return $string4;
}
function sanitizeNumber($number)
{
$num = (int)$number;
return $num;
}