-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
55 lines (41 loc) · 1.37 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
<?php
//create database connection
function dbConn() {
$server = "localhost";
$username = "root";
$password = "";
$db = "msmo";
$conn = new mysqli($server, $username, $password, $db);
if ($conn->connect_error) {
die("Database Error :" . $conn->connect_error);
} else {
return $conn;
}
}
//End Database connection
//Data clean function---------------------------------
function dataClean($data = null) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
//End data clean--------------------------------------
//function to check permission------------------
function checkPermission($current_url = null, $userid = null){//get current url dynamically
$parsed_url = parse_url($current_url);//parse the url
$path = $parsed_url['path'];//extract the path component
$file_name = basename($path, '.php');//get file name without extention
$folder_name = basename(dirname($path));//get folder name
$db = dbConn();
$sql = "SELECT * FROM `user_modules` um "
. "INNER JOIN modules m ON m.Id=um.ModuleId"
. " WHERE um.UserID='$userid' AND m.Path = '$folder_name' AND m.File='$file_name';";
$result = $db->query($sql);
if($result->num_rows<=0){
return false;
}else{
return true;
}
}
?>