-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstudentonlycss.html
581 lines (447 loc) · 18.8 KB
/
studentonlycss.html
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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Student Registration Form</title>
<link rel="stylesheet" href="studentonlycss.css">
<link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet'>
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'>
<script type="text/javascript">
window.addEventListener("load",initialize);
//INITIALIZING FUNCTIONS
function initialize() {
ajax=new XMLHttpRequest();
students=new Array();
//binding
//validation
regex= new Object();
regex.name= new RegExp("^[a-zA-Z]+$");
regex.mobile=new RegExp("^(([076]|[077])|[071])[0-9]{9}$");
regex.bitreg=new RegExp("^([rR][0-9]{6})$");
//authorization(btn disable kranawa nm)
user= new Object();
user.privilages= new Object();
user.privilages.studentSubmit= true;
user.privilages.studentClear= true;
user.privilages.studentUpdate=true;
user.privilages.studentDelete=true;
user.privilages.studentSearch=true;
btnSubmit.addEventListener('click',btnSubmitMC);
btnClear.addEventListener('click',btnClearMC);
btnUpdate.addEventListener('click',btnUpdateMC);
btnDelete.addEventListener('click',btnDeleteMC);
btnSearch.addEventListener("click", btnSearchMC);
btnSearchClear.addEventListener("click", btnSearchClearMC);
txtname.addEventListener('keyup',txtNameKU);
txtmobile.addEventListener('keyup',txtMobileKU);
txtbitreg.addEventListener('keyup',txtBITRegKU);
btnRealSearch.addEventListener("click", btnRealSearchLoadMC);
btnRealSearchClear.addEventListener("click", btnRealSearchClearMC);
loadForm();
loadTable();
}
function loadForm(){
student= new Object();
students= new Array();
oldstudent= null;
valid="lightgreen";
invalid="pink";
initial="white";
updated="#DBFF33";
txtname.value="";
txtmobile.value="";
txtbitreg.value="";
disableButtons(false,true,true);
setDefaultColor(initial);
}
function disableButtons(add, upd, del){
if(!user.privilages.studentSubmit|| add )
btnSubmit.setAttribute("disabled","disabled");
else btnSubmit.removeAttribute("disabled");
if(!user.privilages.studentUpdate || upd )
btnUpdate.setAttribute("disabled","disabled");
else btnUpdate.removeAttribute("disabled");
if(!user.privilages.studentDelete || del )
btnDelete.setAttribute("disabled","disabled");
else btnDelete.removeAttribute("disabled");
}
function loadTable(){
httpSearchRequest("getall");
}
function setDefaultColor(style){
txtname.style.backgroundColor=style;
txtmobile.style.backgroundColor=style;
txtbitreg.style.backgroundColor=style;
}
function fillTable(isValid){
tblstudent.lastElementChild.innerHTML="";
for (index in students){
tr=document.createElement("tr");
td1=document.createElement("td");
tx1=document.createTextNode(window.parseInt(index)+1);
td1.appendChild(tx1);
tr.appendChild(td1);
td2=document.createElement("td");
tx2=document.createTextNode(students[index].name);
td2.appendChild(tx2);
tr.appendChild(td2);
td3=document.createElement("td");
tx3=document.createTextNode(students[index].mobile);
td3.appendChild(tx3);
tr.appendChild(td3);
td4=document.createElement("td");
tx4=document.createTextNode(students[index].bitreg);
td4.appendChild(tx4);
tr.appendChild(td4);
td5=document.createElement("td");
btn=document.createElement("input");
btn.setAttribute("class","btn btn-default btn-sm");
btn.setAttribute("type","button");
btn.setAttribute("value","Delete");
td5.appendChild(btn);
tr.appendChild(td5);
tr.addEventListener("click",function(){
idx=window.parseInt(this.firstChild.innerHTML);
fillForm(students[idx-1]);});
if(isValid(students[index]))
tblstudent.lastElementChild.appendChild(tr);
}
}
function fillForm(stu){
//window.alert(student.id);
student=JSON.parse(JSON.stringify(stu));
oldstudent=JSON.parse(JSON.stringify(stu));
txtname.value=student.name;
txtmobile.value=student.mobile;
txtbitreg.value=student.bitreg;
disableButtons(true,false,false);
setDefaultColor(valid);
}
function btnRealSearchLoadMC(){}
function btnRealSearchClearMC(){
fillTable(function(student){return true;});
txtRealSearchName.value="";
txtRealSearchMobile.value="";
txtRealSearchbitreg.value="";
}
function filterTable(x){
//window.alert(x);
var name = txtRealSearchName.value.trim();
var mobile = txtRealSearchMobile.value.trim();
var bitreg= txtSearchbitreg.value.trim();
var sname=name != "";
var smobile=mobile != "";
var sbitreg=bitreg !="";
//if(column=="name"&& //employees[index].name.substring(0,x.length).toLowerCase()==x.toLowerCase())
//tblEmployee.lastElementChild.appendChild(tr);
//if(employees[index][column].substring(0,x.length).toLowerCase()==x.toLowerCase())
//tblEmployee.lastElementChild.appendChild(tr);
if(sname && !smobile && !sbitreg)
fillTable(function(student){
return student.name.substring(0,name.length).toLowerCase()==name.toLowerCase();
});
if(!sname && smobile && !sbitreg)
fillTable(function(student){
return student.mobile.substring(0,mobile.length).toLowerCase()==mobile.toLowerCase();
});
if(!sname && !smobile && sbitreg)
fillTable(function(student){
return student.bitreg.substring(0,bitreg.length).toLowerCase()==bitreg.toLowerCase();
});
if(sname && smobile && !sbitreg)
fillTable(function(student){ return (student.name.substring(0,name.length).toLowerCase()==name.toLowerCase()) &&(student.mobile.substring(0,mobile.length).toLowerCase()==mobile.toLowerCase());
});
if(sname && !smobile && sbitreg)
fillTable(function(student){
return (student.name.substring(0,name.length).toLowerCase()==name.toLowerCase()) && (student.bitreg.substring(0,bitreg.length).toLowerCase()==bitreg.toLowerCase());
});
if(!sname && smobile && sbitreg)
fillTable(function(student){
return (student.mobile.substring(0,mobile.length).toLowerCase()==mobile.toLowerCase()) && (student.bitreg.substring(0,bitreg.length).toLowerCase()==bitreg.toLowerCase());
});
if(sname && smobile && sbitreg)
fillTable(function(student){ return (student.name.substring(0,name.length).toLowerCase()==name.toLowerCase())&&(student.nic.substring(0,nic.length).toLowerCase()==nic.toLowerCase()) && (student.bitreg.substring(0,bitreg.length).toLowerCase()==bitreg.toLowerCase());
});
}
//VALIDATIONS AND DATA BINDING
function txtNameKU(){
if(regex.name.test(txtname.value)){
student.name=txtname.value;
if(oldstudent!=null && oldstudent.name!=student.name)
txtname.style.background=updated;
else txtname.style.backgroundColor=valid;
}
else {txtname.style.backgroundColor=invalid;
student.name=null;
}
}
function txtMobileKU(){
if(regex.mobile.test(txtmobile.value)){
student.mobile=txtmobile.value;
if(oldstudent!=null && oldstudent.mobile!=student.mobile)
txtmobile.style.background=updated;
else txtmobile.style.backgroundColor=valid;
}
else {txtmobile.style.backgroundColor=invalid;
student.mobile=null;
}
}
function txtBITRegKU(){
if(regex.bitreg.test(txtbitreg.value)){
student.bitreg=txtbitreg.value;
if(oldstudent!=null && oldstudent.bitreg!=student.bitreg)
txtbitreg.style.background=updated;
else
txtbitreg.style.backgroundColor=valid;
}
else {txtbitreg.style.backgroundColor=invalid;
student.bitreg=null;
}
}
//OPERATION FUNCTIONS
//---------Add-----------
function btnSubmitMC(){
var errors = getErrors();
if(errors==""){
var op=window.confirm("Are you sure to add following Student? \n\n Name: "+student.name + "\nMobile: "+student.mobile + "\nBIT Registration No: "+student.bitreg);
if(op==true){httpModifyRequest("add");}
}
else
window.alert("You have following Errors\n\n"+errors);
}
function getErrors(){
var errors = "";
if( student.name == null )
errors = errors + "\nName is incorrect";
if( student.mobile == null )
errors = errors + "\nMobile No is incorrect";
if( student.bitreg == null )
errors = errors + "\nBIT Registration No is incorrect";
return errors;
}
//--------Update--------
function btnUpdateMC(){
var errors = getErrors();
if(errors==""){
var updates = getUpdates();
if(updates=="") window.alert("Nothing Updated!");
else {
var op = window.confirm("\n\nAre your sure to update followings ! \n\n"+updates);
if(op==true){httpModifyRequest("update"); } } }
else
window.alert("You have some errors in your form");
}
function getUpdates(){
var updates = "";
if( student.name !=oldstudent.name )
updates = updates + "\nName is changed";
if( student.mobile !=oldstudent.mobile )
updates = updates + "\nMobile is changed";
if( student.bitreg !=oldstudent.bitreg )
updates = updates + "\nBIT Registration No is changed";
return updates;
}
//--------Clear---------
function btnClearMC(){
var op = window.confirm("Do you need to clear the Form?");
if(op==true)
loadForm();
}
//-------Delete---------
function btnDeleteMC(){
updates=getUpdates();
if(updates!="")
window.alert("\n\n You have unsaved updates!")
else{
var op=window.confirm("\n\nAre u sure to Delete ! \n\n"+student.name);
if(op==true){{httpModifyRequest("delete"); }}
}
}
//-------Search---------
function btnSearchMC(){
var search = "";
var name = txtSearchName.value;
var mobile = txtSearchMobile.value;
var bitreg=txtSearchbitreg.value;
var sname = regex.name.test(name);
var smobile = regex.mobile.test(mobile);
var sbitreg=regex.bitreg.test(bitreg);
if( sname && !smobile && !sbitreg )
search = "getallbyname&name="+name;
if( !sname && smobile && !sbitreg )
search = "getallbymobile&mobile="+mobile;
if( !sname && !smobile && sbitreg )
search = "getallbybitreg&bitreg="+bitreg;
if( sname && smobile && !sbitreg )
search = "getallbynameandmob&name="+name+"&mobile="+mobile;
if( sname && !smobile && sbitreg )
search = "getallbynameandbitreg&name="+name+"&bitreg="+bitreg;
if( !sname && smobile && sbitreg )
search = "getallbymobandbitreg&mobile="+mobile+"&bitreg="+bitreg;
if( sname && smobile && sbitreg )
search = "getallbynameandmobandbitreg&name="+name+"&mobile="+mobile+"&bitreg="+bitreg;
httpSearchRequest(search);
}
function btnSearchClearMC(){
txtSearchName.value="";
txtSearchMobile.value="";
txtSearchbitreg.value="";
loadTable();
}
//-------Modify-----------
function httpModifyRequest(operation){
var json = JSON.stringify(student);
ajax.onreadystatechange =
function(){//err.innerHTML=ajax.responseText;
if(ajax.readyState==4){
if(ajax.status==200)
if(ajax.responseText==1)
{window.alert("Successfully "+operation+"ed");
loadForm();
loadTable();
}
else
window.alert("Failed to "+operation+" as "+ajax.responseText);
else
window.alert("Could not contact the Server"); } };
ajax.open("GET","studentcontroller.php?op="+operation+"&student="+json,true);
ajax.send();
}
function httpSearchRequest(query){
ajax.onreadystatechange =
function(){//err.innerHTML=ajax.responseText;
if(ajax.readyState==4 && ajax.status==200){students=JSON.parse(ajax.responseText); fillTable(function(student){return true;});
}
};
ajax.open("GET","studentcontroller.php?op="+query,true);
ajax.send();
}
</script>
</head>
<body STYLE="font-family: montserrat, arial, verdana;">
<!-- multistep form -->
<h1 style="text-align: center;">Student Registration Form</h1>
<hr>
<div class="form-container">
<form role="form">
<input id='step2' type='checkbox'>
<div id="part1" >
<div class="panel panel-default">
<div class="panel-body"><h3 class="panel-title center">Multi-Step Form with CSS Only</h3>
<div class="form-group row">
<label for="txtname" class="col-form-label col-sm-2">Name:</label>
<div class="col-sm-10">
<input type="text" id="txtname" class="form-control" placeholder="Type Name here" >
</div>
</div>
<div class="form-group row">
<label for="txtmobile" class="col-form-label col-sm-2" >Mobile:</label>
<div class="col-sm-10">
<input type="text" id="txtmobile" class="form-control" placeholder="Type Mobile here" >
</div>
</div>
<div class="form-group row">
<label for="txtbitreg" class="col-form-label col-sm-2" >BIT Reg No:</label>
<div class="col-sm-10">
<input type="text" id="txtbitreg" class="form-control" placeholder="Type BIT Reg No here" >
</div>
</div>
<br/>
<label for='step2' id="continue-step2" class="continue" role="button">
<div class="btn btn-primary button">Continue<span class="glyphicon glyphicon-chevron-right"></div>
</label>
<button type="button" id="btnDelete" class="btn btn-danger continue button">Delete<span class="glyphicon glyphicon-trash"></span></button>
<button type="button" id="btnUpdate" class="btn btn-warning continue button">Update<span class="glyphicon glyphicon-refresh"></span></button>
<button type="submit" id="btnSubmit" class="btn btn-success button continue" >Submit<span class="glyphicon glyphicon-plus"></span></button>
<button type="reset" id="btnClear" class="btn btn-warning button continue" >Clear<span class="glyphicon glyphicon-scissors"></span></button>
<span id="err"></span>
</div>
</div>
</div>
<div id="part2" class="form-group">
<div class="panel panel-danger">
<div class="panel-body">
<!--fixed block button-->
<div class="container-fluid ">
<!-- Button to Open the Modal -->
<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#myModal">Search<span class="glyphicon glyphicon-search"></span>
</button>
<!-- The Modal -->
<div class="modal fade" id="myModal">
<div class="modal-dialog modal-dialog-centered danger">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header" style="background-color: hsla(0, 100%, 30%, 0.3);">
<button type="button" class="close" aria-label="Close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body" style="background-color: hsla(0, 100%, 30%, 0.3);">
<div class="form-group row">
<label for="txtSearchName" class="col-form-label col-sm-2">Search By Name:</label>
<div class="col-sm-10">
<input type="text" id="txtSearchName" class="form-control" placeholder="Search Name here" /></div>
</div>
<div class="form-group row">
<label for="txtSearchMobile" class="col-form-label col-sm-2">Search By Mobile:</label>
<div class="col-sm-10">
<input type="text" id="txtSearchMobile" class="form-control" placeholder="Search Mobile here" /></div>
</div>
<div class="form-group row">
<label for="txtSearchbitreg" class=" col-form-label col-sm-2">Search By BIT Registration No:</label>
<div class="col-sm-10">
<input type="text" id="txtSearchbitreg" class="form-control" placeholder="Search BIT Registration No here" /></div>
</div>
<button type="button" id="btnSearchClear" class="btn btn-info button continue" >Clear Search
</button>
<button type="button" id="btnSearch" class="btn btn-info button continue">Search<span class="glyphicon glyphicon-search">
</button>
</div>
<!-- Modal footer -->
<div class="modal-footer" style="background-color: hsla(0, 100%, 30%, 0.3);">
<button type="button" class="btn btn-danger button" data-dismiss="modal">Close
</button>
</div>
</div>
</div>
</div>
</div>
<label for='step2' id="back-step2" class="back">
<div class="btn btn-danger back button"><span class="glyphicon glyphicon-chevron-left">Back</div>
</label>
<table class="table table-condensed table-sm" id="tblstudent">
<thead>
<tr>
<th>Index</th>
<th>Name</th>
<th>Mobile</th>
<th>BIT Registration No</th>
<th></th>
</tr>
<tr>
<th>--</th>
<th><input type="text" id="txtRealSearchName" onKeyUp="filterTable(this.value)"/></th>
<th><input type="text" id="txtRealSearchMobile" onKeyUp="filterTable(this.value)"/></th>
<th><input type="text" id="txtRealSearchbitreg" onKeyUp="filterTable(this.value)"/></th>
<th>---</th>
</tr>
</thead>
<tbody> </tbody>
</table>
<input type="button" class="button btn btn-info back" value="Load Records for Real Search" id="btnRealSearch" />
<input type="button" class="button btn btn-info continue" value="Clear Real Search" id="btnRealSearchClear" />
</div>
</div>
</div>
</form>
</div>
<script src='http://allurewebsolutions.com/allure.js'></script>
</body>
</html>