forked from Chamara-g/RegionalServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddClient.php
More file actions
416 lines (335 loc) · 13.8 KB
/
AddClient.php
File metadata and controls
416 lines (335 loc) · 13.8 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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
<?php session_start(); ?>
<?php require_once('../inc/connection.php'); ?>
<?php
if(isset($_POST['Submit'])){
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$addr_line1 = $_POST['address_line1'];
$addr_line2 = $_POST['address_line2'];
$addr_line3 = $_POST['address_line3'];
$home_phone = $_POST['home_phone'];
$mobile_phone = $_POST['mobile_phone'];
$nic = $_POST['nic'];
$email = $_POST['email'];
$tax_number = $_POST['tax_number'];
$deed_number = $_POST['deed_number'];
$current = $_POST['current'];
$purpose = $_POST['purpose'];
$meter_ID = $_POST['meter_ID'];
$is_delete = 0;
$address = $addr_line1 ." " .$addr_line2 ." " .$addr_line3;
//client table
$query = "INSERT INTO client_tb (first_name,last_name,address,home_phone,mobile_phone,NIC,email,tax_number,deed_no,current,purpose,meter_id,is_delete) VALUES ('{$first_name}','{$last_name}','{$address}','{$home_phone}','{$mobile_phone}','{$nic}','{$email}','{$tax_number}','{$deed_number}','{$current}','{$purpose}',{$meter_ID},{$is_delete})";
$result = mysqli_query($connection,$query);
if($result){
//get client_id
$queryNew = "SELECT * FROM client_tb WHERE meter_id = {$meter_ID} ";
$result = mysqli_query($connection,$queryNew);
//$new_meter = array();
$meter_id = "";
$client_id = "";
$password = "";
while($row = mysqli_fetch_assoc($result)){
/* $new_meter[] = array(
'meter_id' => $row["meter_id"],
'client_id' => $row["client_id"],
'password' => "Gihan123"
);*/
$meter_id = $row["meter_id"];
$client_id = $row["client_id"];
$password = "gundu";
//add to meter table
$queryToMeter = "INSERT INTO meter_tb(meter_id,client_id,password,meter_type) VALUES ('".$row["meter_id"]."','".$row["client_id"]."','$password','".$row["purpose"]."')";
mysqli_query($connection,$queryToMeter);
}
header("Location: http://localhost/MyphpActivities/elec_meter/provincialReq/getnewMeters.php?meter_id=$meter_id&client_id=$client_id&password=$password");
//header("Location:../Admin_search/admin_search.php");
//echo "successfully added";
}else{
echo "Error";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add client</title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
<script type="text/javascript">
function validation(arg){
var fName = arg.first_name.value;
var lName = arg.last_name.value;
var addrline1 = arg.address_line1.value;
var addrline2 = arg.address_line2.value;
var addrline3 = arg.address_line3.value;
var homePhone = arg.home_phone.value;
var mobilePhone = arg.mobile_phone.value;
var taxNo = arg.tax_number.value;
var deedNo = arg.deed_number.value;
var meterID = arg.meter_ID.value;
var nic = arg.nic.value;
var email = arg.email.value;
var current = arg.current.value;
var purpose = arg.purpose.value;
var ePat = /^[a-z-._0-9]+@[a-z0-9]+\.[a-z.]{2,5}$/;
var namePatDt = /\./;
var namePatDgt = /\d/;
var nicPat1 = /^[0-9]+V/;
var nicPat2 = /^[0-9]+X/;
var nicPat3 = /^[0-9]+v/;
var nicPat4 = /^[0-9]+x/;
var err = "";
var errNum = 0;
if(fName == ""){
errNum++;
err += errNum + ". First name cannot be empty.\n";
}else if(fName.length< 2 || namePatDt.test(fName) || namePatDgt.test(fName)){
errNum++;
err += errNum + ". Invalid first name.\n";
}
if(lName == ""){
errNum++;
err += errNum + ". Last name cannot be empty.\n";
}else if(lName.length< 2 || namePatDt.test(lName) || namePatDgt.test(lName)){
errNum++;
err += errNum + ". Invalid last name.\n";
}
if(addrline1 == ""){
errNum++;
err += errNum + ". Address line 1 cannot be empty.\n";
}
if(addrline2 == ""){
errNum++;
err += errNum + ". Address line 2 cannot be empty.\n";
}else if(addrline2.length< 2){
errNum++;
err += errNum + ". Invalid address line 2.\n";
}
if(addrline3 == ""){
errNum++;
err += errNum + ". Address line 3 cannot be empty.\n";
}else if(addrline3.length< 2){
errNum++;
err += errNum + ". Invalid address line 3.\n";
}
if ( (homePhone != "") && (homePhone.length!= 10 || isNaN(homePhone)) ) {
errNum++;
err += errNum + ". Invalid home phone number.\n";
}
if (mobilePhone == "") {
errNum++;
err += errNum + ". Mobile phone number cannot be empty.\n";
}else if(mobilePhone.length!= 10 || isNaN(mobilePhone)){
errNum++;
err += errNum + ". Invalid mobile phone number.\n";
}
if(taxNo!=""){
if (taxNo.length> 10 || isNaN(taxNo)) {
errNum++;
err += errNum + ". Invalid tax number.\n";
}
}
if (deedNo == "") {
errNum++;
err += errNum + ". Deed number cannot be empty.\n";
}else if(deedNo.length> 10 || isNaN(deedNo)){
errNum++;
err += errNum + ". Invalid deed number.\n";
}
if (meterID == "") {
errNum++;
err += errNum + ". Meter ID cannot be empty.\n";
}else if(meterID.length> 10 || isNaN(meterID)){
errNum++;
err += errNum + ". Invalid meter ID.\n";
}
if (nic == "") {
errNum++;
err += errNum + ". NIC cannot be empty.\n";
}else if(nic.length!= 10 || !(nicPat1.test(nic) || nicPat2.test(nic) || nicPat3.test(nic) || nicPat4.test(nic))){
errNum++;
err += errNum + ". Invalid NIC\n";
}
if(email!=""){
if(!ePat.test(email)){
errNum++;
err += errNum + ". Invalid Email.\n";
}
}
if (!arg.current[0].checked && !arg.current[1].checked && !arg.current[2].checked) {
errNum++;
err += errNum + ". Select Current.\n";
}
if (!arg.purpose[0].checked && !arg.purpose[1].checked && !arg.purpose[2].checked && !arg.purpose[3].checked) {
errNum++;
err += errNum + ". Select purpose.\n";
}
if (errNum>0) {
alert(err);
return false;
}else{
alert('done');
return true;
}
}
</script>
</head>
<body>
<?php require_once('../header.php'); ?>
<div class="container" style="overflow-y: scroll; min-height: 680px; max-height: 680px;">
<form action="addClient.php" class="well form-horizontal" method="post" id="contact-form" onsubmit="return validation(this);">
<fieldset>
<legend><p class="text-center"><i class="glyphicon glyphicon-plus"></i>Add Client</p></legend>
<!--First Name-->
<div class="form-group">
<label class="col-sm-2 control_label"><p class="text-center"><mark>Full Name</mark></p></label>
<label class="col-sm-2 col-xs-12 control_label"><p>First Name</p></label>
<div class="col-sm-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" name="first_name" placeholder="Enter First Name here" class="form-control">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control_label"><p class="text-center"></p></label>
<label class="col-sm-2 col-xs-12 control_label"><p>Last Name</p></label>
<div class="col-sm-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" name="last_name" placeholder="Enter Last Name here" class="form-control">
</div>
</div>
</div>
<br>
<!--Address-->
<div class="form-group">
<label class="col-sm-2 control_label"><p class="text-center"><mark>Address</mark></p></label>
<label class="col-sm-2 col-xs-12 control_label"><p>line 1</p></label>
<div class="col-sm-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<input type="text" name="address_line1" placeholder="Address line 1 here" class="form-control">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control_label"><p class="text-center"></p></label>
<label class="col-sm-2 col-xs-12 control_label"><p>line 2</p></label>
<div class="col-sm-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<input type="text" name="address_line2" placeholder="Address line 2 here" class="form-control">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control_label"><p class="text-center"></p></label>
<label class="col-sm-2 col-xs-12 control_label"><p>line 3</p></label>
<div class="col-sm-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<input type="text" name="address_line3" placeholder="Address line 3 here" class="form-control">
</div>
</div>
</div>
<br>
<!--Phone Numbers-->
<div id="col1" style="width :50%; height: 100%; float: left">
<div class="form-group">
<label class="col-sm-2 col-xs-12 control_label"><p>Home</p></label>
<div class="col-sm-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-phone-alt"></i></span>
<input type="text" name="home_phone" placeholder="Home phone number" class="form-control">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 col-xs-12 control_label"><p>Mobile</p></label>
<div class="col-sm-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-phone"></i></span>
<input type="text" name="mobile_phone" placeholder="Mobile phone number" class="form-control">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 col-xs-12 control_label"><p>Tax No:</p></label>
<div class="col-sm-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-briefcase"></i></span>
<input type="text" name="tax_number" placeholder="TAX number" class="form-control">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 col-xs-12 control_label"><p>Deed No:</p></label>
<div class="col-sm-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-briefcase"></i></span>
<input type="text" name="deed_number" placeholder="Deed number" class="form-control">
</div>
</div>
</div>
<br>
<div class="form-group">
<label class="col-sm-2 col-xs-12 control_label"><p>Meter ID</p></label>
<div class="col-sm-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-flag"></i></span>
<input type="text" name="meter_ID" placeholder="Enter Meter ID here" class="form-control">
</div>
</div>
</div>
</div>
<div id="col2" style="width :50%; height: 100%; float: left">
<div class="form-group">
<label class="col-sm-2 col-xs-12 control_label"><p>NIC</p></label>
<div class="col-sm-10 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-asterisk"></i></span>
<input type="text" name="nic" placeholder="National Identity Card Number" class="form-control">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 col-xs-12 control_label"><p>Email</p></label>
<div class="col-sm-10 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-send"></i></span>
<input type="text" name="email" placeholder="Email" class="form-control">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 col-xs-12 control_label"><p>Current</p></label>
<label class="radio-inline"><input type="radio" name="current" value="15">15 A</label>
<label class="radio-inline"><input type="radio" name="current" value="30">30 A</label>
<label class="radio-inline"><input type="radio" name="current" value="60">60 A</label>
</div>
<div class="form-group">
<label class="col-sm-4 col-xs-12 control_label"><p>Purpose</p></label>
<label class="radio-inline"><input type="radio" name="purpose" value="Domestic">Domestic</label>
<label class="radio-inline"><input type="radio" name="purpose" value="Merchant">Merchant</label>
<label class="radio-inline"><input type="radio" name="purpose" value="Industry">Industry</label>
<label class="radio-inline"><input type="radio" name="purpose" value="Other">Other</label>
</div>
<br>
<!--Submit button-->
<div class="form-group">
<label class="col-md-2 control_label"></label>
<div class="col-sm-12 col-sm-offset-2">
<div class="input-group">
<button name="Submit" style="height:50px; width: 300px" type="Submit" class="btn btn-primary">Confirm & add client</button>
</div>
</div>
</div>
</fieldset>
</form>
</div>
<?php require_once('../footer.php'); ?>
</body>
</html>
<?php mysqli_close($connection); ?>