-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin.php
executable file
·166 lines (141 loc) · 5.72 KB
/
admin.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/*
Code written and managed by Dario Magliocchetti-Lombi for e.quinox
Copying is under no circumstances allowed, unless prior WRITTEN (not email) consent from author.
COPY 2011-2012, dario-ml
www.dario-ml.com
Page Name: index.php
Description: Main page
Created: 22 December 2011
Last Modified: 25 December 2011
*/
define("SAFE_ZONE", 1);
require('global.php');
if ($_SESSION['equinox_code_permission'][0] != 1)
{
//We don't have access to view the admin panel
$core->noAccess();
}
if (@$_GET['subpage'] == 'newcust' || @$_GET['subpage'] == 'editcus')
{
//check permissions!
if ((($_GET['subpage'] == 'newcust') && ($core->getPermission(2) != 1)) || (($_GET['subpage'] == 'editcus') && ($core->getPermission(3) != 1)))
{
$core->noAccess();
}
if ($_GET['subpage'] == 'editcus')
{
$check = $db->prepare("SELECT shopID, boxID, deleted FROM customers WHERE customerID = ?");
$check->bind_param('s', $_GET['cid']);
$check->execute();
$check->bind_result($shopid, $boxid, $deleted);
if (!$check->fetch())
{
$error['general'] = "Undefined customer ID";
}
elseif (!$core->ShopPermission($shopid))
{
$core->noAccess();
}
elseif ($deleted && !$core->getPermission(4))
{
$core->noAccess();
}
$check->close();
}
if (!empty($_POST))
{
//Simple data verify , set $error if required
if (strlen(trim($_POST['cus_tel'])) < 1) {
$error['tel'] = 'Must be filled out';
}elseif (!is_numeric($_POST['cus_tel'])) {
$error['tel'] = 'Must be a number';
}
if (strlen(trim($_POST['cus_paid'])) < 1) {
$error['paid'] = 'Must be filled out';
}elseif (!is_numeric($_POST['cus_paid'])) {
$error['paid'] = 'Must be a number';
}
if (strlen(trim($_POST['cus_shop'])) < 1) {
$error['shop'] = 'Must be filled out';
} elseif (!is_numeric($_POST['cus_shop'])) {
$error['shop'] = 'Must be a number';
} elseif ($_POST['cus_shop'] < 1){
$error['shop'] = 'Cannot be negative';
} elseif (!$core->ShopPermission($_POST['cus_shop'])) { //Check that the user can add to this shop ID
$error['shop'] = "You do not own this shop";
}
if (strlen(trim($_POST['cus_box'])) < 1) {
$error['box'] = 'Must be filled out';
} elseif (substr($_POST['cus_box'], 0, 1) != 's' && substr($_POST['cus_box'], 0, 1) != 'l') {
$error['box'] = 'Invalid boxID (must begin with s or l)';
}elseif (!is_numeric(substr($_POST['cus_box'], 1))) {
$error['box'] = 'Must be a number';
}elseif ($_POST['cus_box'] != $boxid && $_POST['cus_box'] != 0) {
//Make sure the box is not in use by another customer
$check = $db->prepare("SELECT customerID, name FROM customers WHERE boxID = ?");
$check->bind_param('i', $_POST['cus_box']);
$check->execute();
$check->bind_result($cid, $cname);
if ($check->fetch())
{
$error['box'] = "Box in use by $cname [ID: $cid]";
}
$check->close();
}
if (strlen(trim($_POST['cus_name'])) < 5) {//names need to be longer than 5..?
$error['name'] = 'Needs to be longer than 5 characters';
}
//check the data is valid for SQL (Such as shop ID)
//If no errors, save!
if (!isset($error))
{
//Are we a new customer (unset id)
if ($_POST['neworedit'] == 'new')
{
//New customer
$test = $db->prepare("INSERT INTO `customers` (`customerID`, `shopID`, `name`, `telephone`, `boxID`, `notes`, `paid`) VALUES (NULL, ?, ?, ?, ?, ?, ?);");
$test->bind_param('issssd', $_POST['cus_shop'], $_POST['cus_name'], $_POST['cus_tel'], $_POST['cus_box'], $_POST['cus_notes'], $_POST['cus_paid']);
$test->execute();
header("Location: admin.php?subpage=newcust&done=" . $test->insert_id);
}
elseif ($_POST['neworedit'] == 'edit')
{
//We're trying to edit:
$test = $db->prepare("UPDATE `customers` SET `shopID` = ?, `name` = ?, `telephone` = ?, `boxID` = ?, `notes` = ?, paid = ? WHERE `customerID` = ?;");
$test->bind_param('issssdi', $_POST['cus_shop'], $_POST['cus_name'], $_POST['cus_tel'], $_POST['cus_box'], $_POST['cus_notes'], $_POST['cus_paid'], $_POST['cus_cid']);
$test->execute();
$test->close();
header("Location: admin.php?subpage=editcus&cid=" . $_POST['cus_cid'] . "&done=" . date("H:i:s"));
}
}
} // END !empty($_POST)
//check for success
if (isset($_GET['done']))
{
$error['success'] = ($_GET['subpage'] == 'newcust') ? "Successfully added customer with ID: $_GET[done]" : "Successfully edited customer @ $_GET[done]";
}
$row = (@is_numeric($_GET['cid'])) ? $db->query("SELECT * FROM customers WHERE customerID = '".$db->escape_string(@$_GET['cid'])."' LIMIT 1")->fetch_assoc() : null;
$content = $twig->render('admin_cusform',array('member' => @$row, 'error' => @$error, 'new' => (($row == null)?true:false), 'olddata'=>$_POST));
}
elseif (@$_GET['subpage'] == 'newadm' || @$_GET['subpage'] == 'editadm')
{
if (!empty($_POST))
{
} // END !empty($_POST)
//
//check for success
if (isset($_GET['done']))
{
$error['success'] = ($_GET['subpage'] == 'newcust') ? "Successfully added customer with ID: $_GET[done]" : "Successfully edited customer @ $_GET[done]";
}
$row = (@is_numeric($_GET['aid'])) ? $db->query("SELECT * FROM logins WHERE userID = '".$db->escape_string(@$_GET['aid'])."' LIMIT 1")->fetch_assoc() : null;
$content = $twig->render('admin_admform',array('member' => @$row, 'error' => @$error, 'new' => (($row == null)?true:false), 'olddata'=>$_POST));
}
else
{
$content = "Show your permissions..<br />You own shopIDs: ";
$content .= implode(", ", $_SESSION['equinox_code_shops']);
$content .= ($core->getPermission(1)) ? " (FULL ACCESS)" : null;
}
echo $twig->render('core', array('content'=>@$content));