-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
104 lines (88 loc) · 2.13 KB
/
functions.php
File metadata and controls
104 lines (88 loc) · 2.13 KB
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
<?php
function prx($data){
echo '<pre>';
print_r($data);
die();
}
function get_safe_value($data){
global $con;
if($data){
return mysqli_real_escape_string($con,$data);
}
}
function redirect($link){
?>
<script>
window.location.href="<?php echo $link?>";
</script>
<?php
}
function checkUser(){
if(isset($_SESSION['UID']) && $_SESSION['UID']!=''){
}else{
redirect('index.php');
}
}
function getCategory($category_id='',$page=''){
global $con;
$res=mysqli_query($con,"select * from category order by name asc");
$fun="required";
if($page=='reports'){
//$fun="onchange=change_cat()";
$fun="";
}
$html='<select $fun name="category_id" id="category_id" class="form-control">';
$html.='<option value="">Select Category</option>';
while($row=mysqli_fetch_assoc($res)){
if($category_id>0 && $category_id==$row['id']){
$html.='<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
}else{
$html.='<option value="'.$row['id'].'">'.$row['name'].'</option>';
}
}
$html.='</select>';
return $html;
}
function getDashboardExpense($type){
global $con;
$today=date('Y-m-d');
if($type=='today'){
$sub_sql=" and expense_date='$today'";
$from=$today;
$to=$today;
}
elseif($type=='yesterday'){
$yesterday=date('Y-m-d',strtotime('yesterday'));
$sub_sql=" and expense_date='$yesterday'";
$from=$yesterday;
$to=$yesterday;
}elseif($type=='week' || $type=='month' || $type=='year'){
$from=date('Y-m-d',strtotime("-1 $type"));
$sub_sql=" and expense_date between '$from' and '$today'";
$to=$today;
}else{
$sub_sql=" ";
$from='';
$to='';
}
$res=mysqli_query($con,"select sum(price) as price from expense where added_by='".$_SESSION['UID']."' $sub_sql");
$row=mysqli_fetch_assoc($res);
$p=0;
$link="";
if($row['price']>0){
$p=$row['price'];
$link=" <a href='dashboard_report.php?from=".$from."&to=".$to."' target='_blank' class='detail_link'>Details</a>";
}
return $p.$link;
}
function adminArea(){
if($_SESSION['UROLE']!='Admin'){
redirect('dashboard.php');
}
}
function userArea(){
if($_SESSION['UROLE']!='User'){
redirect('category.php');
}
}
?>