-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
148 lines (125 loc) · 3.3 KB
/
api.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
session_start();
list($domain,$port) = explode(':',$_SERVER['HTTP_HOST']);
if($domain == 'localhost'){
$db = mysqli_connect('localhost','root','root','waterloo');
}else{
$db = mysqli_connect('localhost','algobku8_free','algobku8_free','algobku8_waterloo');
}
define("USER",'user');
define("CATEGORIES",'categories');
define("PRODUCTS",'products');
define("PROJECTS",'projects');
if(isset($_POST['login']))
{
if($_POST['email'] && $_POST['password'])
{
$sql = "SELECT * FROM ".USER.
" WHERE email='".$_POST['email'].
"' AND password='".$_POST['password']."'";
$query = mysqli_query($db,$sql);
if(mysqli_num_rows($query) == 1)
{
$row = mysqli_fetch_array($query,MYSQLI_ASSOC);
$_SESSION['sess'] = [
'uid' => $row['id'],
'fname' => $row['fullname'],
'email' => $row['email'],
'role' => $row['role']
];
echo "200";
exit;
}
}
}
if(isset($_POST['register']))
{
if($_POST['email'] && $_POST['password'])
{
$query = mysqli_query($db,"INSERT INTO user SET email='".$_POST['email']."', password='".$_POST['password']."',role='user',country='".$_POST['country']."',dob='".$_POST['dob']."',fullname='".$_POST['fullname']."',created='".date('d/M/Y')."',updated='".date('d/M/Y')."',status=1");
if($query)
{
echo "200";
exit;
}
}
}
if($_POST['isSession']){
if(is_array($_SESSION['sess'])){
echo json_encode($_SESSION['sess'],true);
}
}
if(isset($_POST['logout'])){
session_destroy();
echo "200";
}
if(isset($_POST['create_category']))
{
if($_POST['category'])
{
$query = mysqli_query($db,"INSERT INTO CATEGORIES SET category_name='".$_POST['category']."',created='".date('d/M/Y')."',updated='".date('d/M/Y')."',status=1");
if($query)
{
echo "200";
exit;
}
}
}
if(isset($_POST['categories']))
{
$query = mysqli_query($db,"SELECT FROM CATEGORIES WHERE status=1");
if($query)
{
echo $query;
}
}
if(isset($_POST['create_products']))
{
if($_POST['category'] && $_POST['product'])
{
$query = mysqli_query($db,"INSERT INTO PRODUCTS SET product_name='".$_POST['product']."',category_id='".$_POST['category_id']."',created='".date('d/M/Y')."',updated='".date('d/M/Y')."',status=1");
if($query)
{
echo $query;
}
}
}
if(isset($_POST['products']))
{
$query = mysqli_query($db,"SELECT FROM PRODUCTS WHERE status = 1");
if($query)
{
echo $query;
}
}
if(isset($_POST['createProject']))
{
$query = mysqli_query($db,"INSERT INTO PROJECTS SET project_name='".$_POST['project_name']."',project_reference='".$_POST['project_reference']."',user_id='".$_SESSION['sess']['uid']."',created='".date('d/M/Y')."',updated='".date('d/M/Y')."',status=1");
if($query)
{
echo "200";
exit;
}
}
if(isset($_POST['calculation']))
{
if($_POST['email'] && $_POST['password'])
{
$query = mysqli_query($db,"SELECT FROM user WHERE email=".$_POST['email']." AND password=".$_POST['password']);
if($query)
{
echo $query;
}
}
}
if(isset($_POST['export']))
{
if($_POST['email'] && $_POST['password'])
{
$query = mysqli_query($db,"SELECT FROM user WHERE email=".$_POST['email']." AND password=".$_POST['password']);
if($query)
{
echo $query;
}
}
}