/
pos-user-add-b.php
executable file
·364 lines (322 loc) · 11.7 KB
/
pos-user-add-b.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<?
#This program is copyright by Andre Coetzee email: ac@main.me
#and is licensed under the GPL v3
#
#
#
#
#Please add yourself to: http://www.accounting-123.com
#Developers, Software Vendors, Support, Accountants, Users
#
#
#The full software license can be found here:
#http://www.accounting-123.com/a.php?a=153/GPLv3
#
#
#
#
#
#
#
#
#
#
#
# admin-usradd.php :: Module to add users to the system
##
require ("settings.php");
if ($_POST) {
switch ($_POST["key"]) {
case "confirm":
$OUTPUT = confirmUser ($_POST);
break;
case "write":
$OUTPUT = writeUser ($_POST);
break;
default:
$OUTPUT = enterUser ();
}
}
else {
$OUTPUT = enterUser ();
}
require ("template.php");
##
# functions
##
# enter new users details
function enterUser ($username="", $postype='P', $manager=false, $err="")
{
# Connect to db
db_connect ();
$brans = "<select name='div'>";
$sql = "SELECT * FROM branches ORDER BY branname ASC";
$branRslt = db_exec($sql);
if(pg_numrows($branRslt) < 1){
return "<li>There are no branches in Cubit.";
}else{
while($bran = pg_fetch_array($branRslt)){
$brans .= "<option value='$bran[div]'>($bran[brancod]) $bran[branname]</option>";
}
}
$brans .= "</select>";
$posman_hgh = "";
if ( $postype == 'S' ) {
$posman_vis = "visible";
$posman_hgh = "";
} else {
$posman_vis = "hidden";
//$posman_hgh = "height: 0px;";
}
$enterUser = "
<h3>Add new user to database</h3>
<script>
function showPosMan() {
x = document.getElementById('div_posman');
x.style.visibility = 'visible';
}
function hidePosMan() {
x = document.getElementById('div_posman');
x.style.visibility = 'hidden';
}
</script>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<form action='".SELF."' method=post>
<input type=hidden name=key value=confirm>
<input type=hidden name=f1 value='0'>
$err
<tr><th>Field</th><th>Value</th></tr>
<tr class='bg-odd'><td>".REQ."Branch</td><td>$brans</td></tr>
<tr class='bg-even'><td>".REQ."Username</td><td><input type=text size=20 name=username value='$username'> must not contain spaces</td></tr>
<tr class='bg-odd'><td>".REQ."Password</td><td><input type=password size=20 name=password></td></tr>
<tr class='bg-even'><td>".REQ."Confirm password</td><td><input type=password size=20 name=password2></td></tr>
<tr class='bg-odd'>
<td rowspan=2>POS Type</td>
<td>
<table><tr>
<td><input type=radio name=postype value='P' ".($postype=='P'?"checked":"")." onClick='hidePosMan();'>POS User</td>
</tr></table>
</td>
</tr>
<tr class='bg-odd'>
<td>
<table><tr>
<td><input type=radio name=postype value='S' ".($postype=='S'?"checked":"")." onClick='showPosMan();'>Speed POS User</td>
<td><div id='div_posman' style='visibility: $posman_vis; $posman_hgh'><input type=checkbox name=manager ".($manager?"checked":"")."> Manager</div></td>
</tr></table>
</td>
</tr>
<tr><td align=right colspan=2><input type=submit value='Confirm »'></td></tr>
</form>
</table>
<p>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<tr><th>Quick Links</th></tr>
<tr class='bg-odd'><td><a href='main.php'>Main Menu</a></td></tr>
</table>";
return $enterUser;
}
# confirm entered info
function confirmUser ($_POST)
{
# Get vars
foreach ($_POST as $key => $value) {
$$key = $value;
}
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($username, "string", 1, 20, "Invalid user name.");
$username2 = str_replace(" ", "", $username);
if(strlen($username) > strlen($username2))
$v->isOk ($username, "num", 0, 0, "Error : user name must not contain spaces.");
$v->isOk ($div, "num", 1, 20, "Invalid Branch.");
$v->isOk ($password, "string", 1, 20, "Invalid password.");
if ( $postype != 'P' && $postype != 'S' ) {
$v->addError("", "Invalid POS user.");
}
if(isset($f1))
{
$v->isOk ($password2, "string", 1, 20, "Invalid password 2.");
$v->pwMatch ($password, $password2, "Passwords do not match.");
}
if(isset($manager) && $postype == "S") {
$manager="Yes";
} else {
$manager="No";
}
# display errors, if any
if ($v->isError ()) {
$theseErrors = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$theseErrors .= "-".$e["msg"]."<br>";
}
$theseErrors = "<tr><td class=err colspan=2>$theseErrors</td></tr>
<tr><td colspan=2><br></td></tr>";
return enterUser($username,$postype,$manager=="Yes"?true:false,$theseErrors);
exit;
}
# Get branch name
db_connect();
$sql = "SELECT branname FROM branches WHERE div = '$div'";
$branRslt = db_exec($sql);
$bran = pg_fetch_array($branRslt);
if(isset($f1))
{
$ex="<input type=hidden name=f2 value=''>";
# exit if user exists
$sql = "SELECT username FROM users WHERE username = '$username'";
$usrRslt = db_exec ($sql) or errDie ("Unable to check database for existing username.");
if (pg_numrows ($usrRslt) > 0) {
return "User, $username, already exists in database.";
}
} else {$ex="";}
$confirmUser ="
<h3>Add user to database</h3>
<h4>Confirm entry</h4>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<form action='".SELF."' method=post name=form>
<input type=hidden name=key value=write>
<input type=hidden name=username value='$username'>
<input type=hidden name=div value='$div'>
<input type=hidden name=password value='$password'>
<input type=hidden name=manager value='$manager'>
<input type=hidden name=postype value='$postype'>
$ex
<tr><th>Field</th><th>Value</th></tr>
<tr class='bg-odd'><td>Branch</td><td>$bran[branname]</td>
<tr class='bg-even'><td>Username</td><td>$username</td>
<tr class='bg-odd'><td>Password</td><td>********</td>";
if ( $postype == "P" ) {
$confirmUser .= "
<tr class='bg-even'><td>POS Type</td><td>POS User</td>";
} else if ( $postype == "S" ) {
$confirmUser .= "
<tr class='bg-even'><td>POS Type</td><td>Speed POS User</td>
<tr class='bg-even'><td>POS Manager</td><td>$manager</td>";
}
$confirmUser .= "
<tr><td><br></td></tr></table>";
$confirmUser .="</table></td></tr>
<tr><td align=right colspan=3><input type=submit name=doneBtn value='Write »'></td></tr>
</form>
</table>
<p>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<tr><th>Quick Links</th></tr>
<tr class='bg-odd'><td><a href='main.php'>Main Menu</a></td></tr>
</table>";
return $confirmUser;
}
# write user to db
function writeUser ($_POST)
{
# get vars
foreach ($_POST as $key => $value) {
$$key = $value;
}
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($div, "num", 1, 20, "Invalid Branch.");
$v->isOk ($username, "string", 1, 20, "Invalid user name.");
$v->isOk ($password, "string", 1, 20, "Invalid password.");
//$v->isOk ($tool, "string", 1, 3, "Invalid tooltips selection.");
if ( $postype != 'P' && $postype != 'S' ) {
$v->addError("", "Invalid POS user.");
}
$v->isOk ($username, "string", 1, 20, "Invalid user name.");
$username2 = str_replace(" ", "", $username);
if(strlen($username) > strlen($username2)) {
$v->addError("", "Error : user name must not contain spaces.");
}
$v->isOk ($div, "num", 1, 20, "Invalid Branch.");
$v->isOk ($password, "string", 1, 20, "Invalid password.");
if ( $postype != 'P' && $postype != 'S' ) {
$v->addError("", "Invalid POS user.");
}
if(isset($f1))
{
$v->isOk ($password2, "string", 1, 20, "Invalid password 2.");
$v->pwMatch ($password, $password2, "Passwords do not match.");
}
# display errors, if any
if ($v->isError ()) {
$theseErrors = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$theseErrors .= "-".$e["msg"]."<br>";
}
$theseErrors = "<tr><td class=err colspan=2>$theseErrors</td></tr>
<tr><td colspan=2><br></td></tr>";
return enterUser($username,$postype,$manager=="Yes"?true:false,$theseErrors);
exit;
}
# connect to db
db_connect ();
if ( ! isset($admin)) $admin=0;
if(isset($f2))
{
# exit if user exists
$sql = "SELECT username FROM users WHERE username='$username'";
$usrRslt = db_exec ($sql) or errDie ("Unable to check database for existing username.");
if (pg_numrows ($usrRslt) > 0) {
return "User, $username, already exists in database.";
}
# get md5 hash of password
$password = md5 ($password);
if($manager=="Yes"){
$abo=1000;
} else {
$abo=0;
}
$sql = "INSERT INTO users (username, password, services_menu, admin,div, usertype,abo)
VALUES ('$username', '$password', 'L', $admin, '$div', '$postype','$abo')";
$nwUsrRslt = db_exec ($sql) or errDie ("Unable to add user to database.");
} else {
// update the admin variable
db_exec("UPDATE users SET admin=$admin WHERE username='$username'");
}
$Sql = "DELETE FROM userscripts WHERE username='$username'";
$Ex = db_exec($Sql);
$Sql = "INSERT INTO userscripts (username, script) VALUES ('$username', 'top_menu.php')";
$Ex = db_exec ($Sql) or errDie ("Unable to add user to database.");
$Sql = "INSERT INTO userscripts (username, script) VALUES ('$username', 'diary.php')";
$Ex = db_exec ($Sql) or errDie ("Unable to add user to database.");
$Sql = "INSERT INTO userscripts (username, script) VALUES ('$username', 'diary-day.php')";
$Ex = db_exec ($Sql) or errDie ("Unable to add user to database.");
$Sql = "INSERT INTO userscripts (username, script) VALUES ('$username', 'glodiary.php')";
$Ex = db_exec ($Sql) or errDie ("Unable to add user to database.");
$Sql = "INSERT INTO userscripts (username, script) VALUES ('$username', 'glodiary-day.php')";
$Ex = db_exec ($Sql) or errDie ("Unable to add user to database.");
$Sql = "INSERT INTO userscripts (username, script) VALUES ('$username', 'todo.php')";
$Ex = db_exec ($Sql) or errDie ("Unable to add user to database.");
$Sql = "INSERT INTO userscripts (username, script) VALUES ('$username', 'index_die.php')";
$Ex = db_exec ($Sql) or errDie ("Unable to add user to database.");
$Sql = "INSERT INTO userscripts (username, script) VALUES ('$username', 'index-services.php')";
$Ex = db_exec ($Sql) or errDie ("Unable to add user to database.");
$Sql = "INSERT INTO userscripts (username, script) VALUES ('$username', 'pos-invoice-new.php')";
$Ex = db_exec ($Sql) or errDie ("Unable to add user to database.");
$Sql = "INSERT INTO userscripts (username, script) VALUES ('$username', 'pos-slip.php')";
$Ex = db_exec ($Sql) or errDie ("Unable to add user to database.");
$Sql = "INSERT INTO userscripts (username, script) VALUES ('$username', 'pos-invoice-print.php')";
$Ex = db_exec ($Sql) or errDie ("Unable to add user to database.");
$Sql = "INSERT INTO userscripts (username, script) VALUES ('$username', 'index-sales.php')";
$Ex = db_exec ($Sql) or errDie ("Unable to add user to database.");
# status report
$writeUser ="
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."' width='50%'>
<tr><th>New user added to database</th></tr>
<tr class=datacell><td>New user, $username, was successfully added to Cubit.</td></tr>
</table>
<p>
<tr>
<table border=0 cellpadding='2' cellspacing='1'>
<tr><th>Quick Links</th></tr>
<tr bgcolor='#88BBFF'><td><a href='".SELF."'>Add another user</a></td></tr>
<tr bgcolor='#88BBFF'><td><a href='main.php'>Main Menu</a></td></tr>
</tr>";
return $writeUser;
}
?>