-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelper.lib.php
93 lines (75 loc) · 1.81 KB
/
helper.lib.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
<?php
function EncryptPassword($password)
{
global $password_salt;
return hash("sha256", $password_salt.$password.$password_salt);
}
function CleanString($str)
{
return trim(strtolower($str));
}
function RedirectTimer($page, $seconds)
{
echo "<meta http-equiv=\"refresh\" content=\"$seconds;url=index.php?p=$page\">";
ShowInfo("You will be redirected in $seconds seconds...");
}
function ShowError($msg, $hideGoBack = false)
{
echo "<p class=\"bg-danger bigp\"><span class=\"glyphicon glyphicon-exclamation-sign\"></span> $msg</p>";
if(!$hideGoBack)
{
ShowGoBack();
}
}
function ShowAlert($msg)
{
echo "<p class=\"bg-warning bigp\"><span class=\"glyphicon glyphicon-warning-sign\"></span> $msg</p>";
}
function ShowInfo($msg)
{
echo "<p class=\"bg-info bigp\"><span class=\"glyphicon glyphicon-info-sign\"></span> $msg</p>";
}
function ShowGoBack()
{
echo "<button type=\"button\" class=\"btn btn-default\" onclick=\"history.go(-1);\"><i class=\"fa fa-arrow-left\"></i> Go Back</button>";
}
function DisplayDatetime($time)
{
if($time <= 0)
{
return "N/A";
}
return date("n/d/y h:i:s A", $time);
}
function DisplayLimited($str, $limit = 100)
{
if(strlen($str) > $limit)
{
return substr($str, 0, $limit - 4)."...";
}
return $str;
}
function LogAction($msg)
{
LogGeneric("Error", $msg);
}
function LogError($msg)
{
LogGeneric("Error", $msg);
}
function LogGeneric($type, $msg)
{
global $me;
if(!file_exists("log.data"))
{
file_put_contents("log.data", "{}", LOCK_EX);
}
$data = json_decode(file_get_contents("log.data"), true);
if(!is_array($data))
{
$data = array();
}
array_push($data, array("Time" => time(), "User" => is_null($me) ? "N/A" : $me->GetUsername(), $type => $msg, "RequestUri" => $_SERVER["REQUEST_URI"]));
file_put_contents("log.data", json_encode($data), LOCK_EX);
}
?>