/var/www/onesupportsys.onesolution.hk/profile/views/form.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
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
<!--
<?php
if (!Util::isAdmin()) {
    
header("Location: ../index.php");
    exit;
}

$sql "SELECT * FROM customerProfile";
$parameters = array(0);
if (!(
$sth $dbh->prepare($sql))) {
    throw new 
Exception("sql prepare statement failure: $sql");
}
$sth->setFetchMode(PDO::FETCH_ASSOC);
if (!
$sth->execute($parameters)) {
    throw new 
Exception("sql execute statement failure: $sql");
}
$customers $sth->fetchAll();
?>
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <?php require(__DIR__ '/../../inc/_head_meta.php'); ?>

    <?php require(__DIR__ '/../../inc/_head_css.php'); ?>

    <style type="text/css">
        body {
            padding-top: 60px;
            /* 60px to make the container go all the way to the bottom of the topbar */
            padding-bottom: 40px;
        }
    </style>

    <?php require(__DIR__ '/../../inc/_head_script.php'); ?>

    <style>
        tbody>tr:hover {
            background-color: teal;
            color:white;
        }
    </style>
    

    <script type="text/javascript">
        $(function () {
            $('.select2').select2();
        });
    </script>
</head>

<body>

    <?php require(__DIR__ '/../../inc/_navbar.php'); ?>

    <div class="container">

        <?php if (isset($message) && !empty($message)): ?>
            <div class="alert alert-info">
                <button type="button" class="close" data-dismiss="alert">&times;</button>
                <h5 class="alert-heading">Note:</h5>
                <p>
                    <?= $message ?>
                </p>
            </div>
        <?php endif; ?>

        <!-- <h2><?= empty($customer['cust_id']) ? 'Add' 'Modify' ?> Customer Profile</h2> -->
        
        <h3>Maintain Customer Profile </h3>        

        <form id="form" class="form-horizontal" method="post">

            <?php $attribute 'id'?>
            <input type="hidden" name="<?= $attribute ?>" value="<?= h($customer[$attribute]) ?>" />

            <?php $attribute 'customer_id'?>
            <input type="hidden" name="<?= $attribute ?>" value="<?= h($customer[$attribute]) ?>" />

            <div class="control-group">
                <?php $attribute 'device_type';
                
$label 'Device Type'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>

                <div class="controls">
                    <select id="<?= $attribute ?>" name="<?= $attribute ?>" placeholder="Select a <?= $label ?>"
                        class="select2">
                        <option value=""></option>
                        <?php
                        $_device_types 
lookuplist::selectOptions('deviceType');
                        foreach (
$_device_types as $_device_type):
                            
?>
                            <option value="<?= h($_device_type['val']) ?><?= $_device_type['val'] == $customer[$attribute] ? ' selected="selected"' '' ?>>
                                <?= h($_device_type['txt']) ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>


            <div class="control-group">
                <?php $attribute 'location';
                
$label 'Location'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <textarea id="<?= $attribute ?>" name="<?= $attribute ?>" class="span6"
                        placeholder="<?= $label ?>"><?= h($customer[$attribute]) ?></textarea>
                </div>
            </div>


            <div class="control-group">
                <?php $attribute 'ip_address';
                
$label 'IP address'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>"
                        value="<?= h($customer[$attribute]) ?>" placeholder="<?= $label ?>" />
                </div>
            </div>

            <div class="control-group">
                <?php $attribute 'mac_address';
                
$label 'MAC Address'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>"
                        value="<?= h($customer[$attribute]) ?>" placeholder="<?= $label ?>" />
                </div>
            </div>

            <div class="control-group">
                <?php $attribute 'port';
                
$label 'Port No.'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>"
                        value="<?= h($customer[$attribute]) ?>" placeholder="<?= $label ?>" />
                </div>
            </div>



            <div class="control-group">
                <?php $attribute 'domain_name';
                
$label 'Domain Name'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>"
                        value="<?= h($customer[$attribute]) ?>" placeholder="<?= $label ?>" />
                </div>
            </div>

            <div class="control-group">
                <?php $attribute 'device_name';
                
$label 'Device Name'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>"
                        value="<?= h($customer[$attribute]) ?>" placeholder="<?= $label ?>" />
                </div>
            </div>

            <div class="control-group">
                <?php $attribute 'function_text ';
                
$label 'Function'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <textarea id="<?= $attribute ?>" name="<?= $attribute ?>" class="span6"
                        placeholder="<?= $label ?>"><?= h($customer[$attribute]) ?></textarea>
                </div>
            </div>

            <div class="control-group">
                <?php $attribute 'remark';
                
$label 'Remark'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <textarea id="<?= $attribute ?>" name="<?= $attribute ?>" class="span6"
                        placeholder="<?= $label ?>"><?= h($customer[$attribute]) ?></textarea>
                </div>
            </div>

            <div class="control-group">
                <?php $attribute 'os_version';
                
$label 'OS version'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>"
                        value="<?= h($customer[$attribute]) ?>" placeholder="<?= $label ?>" />
                </div>
            </div>

            <div class="control-group">
                <?php $attribute 'other';
                
$label 'Other'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <textarea id="<?= $attribute ?>" name="<?= $attribute ?>" class="span6"
                        placeholder="<?= $label ?>"><?= h($customer[$attribute]) ?></textarea>
                </div>
            </div>

            <div class="control-group">
                <?php $attribute 'brand';
                
$label 'Brand'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>

                <div class="controls">
                    <select id="<?= $attribute ?>" name="<?= $attribute ?>" placeholder="Select a <?= $label ?>"
                        class="select2">
                        <option value=""></option>
                        <?php
                        $_brands 
lookuplist::selectOptions('brand');
                        foreach (
$_brands as $_brand):
                            
?>
                            <option value="<?= h($_brand['val']) ?><?= $_brand['val'] == $customer[$attribute] ? ' selected="selected"' '' ?>>
                                <?= h($_brand['txt']) ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>



            <div class="control-group">
                <?php $attribute 'model';
                
$label 'Model'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>"
                        value="<?= h($customer[$attribute]) ?>" placeholder="<?= $label ?>" />
                </div>
            </div>

            <div class="control-group">
                <?php $attribute 'serial_number';
                
$label 'Serial Number'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>"
                        value="<?= h($customer[$attribute]) ?>" placeholder="<?= $label ?>" />
                </div>
            </div>

            <div class="control-group">
                <?php $attribute 'processor';
                
$label 'Processor'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>"
                        value="<?= h($customer[$attribute]) ?>" placeholder="<?= $label ?>" />
                </div>
            </div>

            <div class="control-group">
                <?php $attribute 'ram';
                
$label 'RAM'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>"
                        value="<?= h($customer[$attribute]) ?>" placeholder="<?= $label ?>" />
                </div>
            </div>

            <div class="control-group">
                <?php $attribute 'disk_size';
                
$label 'Disk Size'?>
                <label class="control-label" for="<?= $attribute ?>">
                    <?= $label ?>
                </label>
                <div class="controls">
                    <textarea id="<?= $attribute ?>" name="<?= $attribute ?>" class="span6"
                        placeholder="<?= $label ?>"><?= h($customer[$attribute]) ?></textarea>
                </div>
            </div>

            <div class="container">
                <div class="controls">
                    <button type="submit" class="btn btn-primary" style="width:100px;">Save</button>

                    <button id="account" type="button" class="btn btn-danger <?= $customer['id'] == "0" " hidden" "" ?>" style="width:100px;" data-bs-toggle="modal" data-bs-target="#edit" data-id="<?= $customer['id'?>">
                        Account 
                    </button>

                </div>
            </div>

            <!-- The Modal -->
            <div id="myModal" class="modal" style="display: none;">

                <div class="modal-header">
                    <div>
                        <span class="close">&times;</span>
                        <h4 class="modal-title" id="staticBackdropLabel">User Acccount Information</h4>
                    </div>
                </div>
                <!-- Modal content -->
                <div class="modal-content" style="padding-top:10px;">
                    <div id="mHdr">
                        <div style="padding-left: 10px;padding-right: 10px;">
                            <p id="actionType" style="background-color:green;text-align:center;font-weight:900;color:white;">Addition</p>
                        </div>
                    </div>
                    <div id="mDtl">
                        <div style="padding-left: 10px;padding-right: 10px;">
                            <table id="tbl" class="table">
                                <thead>
                                    <tr>
                                        <th>Account For</th>
                                        <th>Login Id</th>
                                        <th class="hidden">Password</th>
                                        <th class="hidden">id</th>
                                        <th class="hidden">profile_id</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <!--
                                    <tr>
                                        <td>Doe</td>
                                        <td>john@example.com</td>
                                        <td class="hidden">Tai</td>
                                        <td class="hidden">1</td>
                                        <td class="hidden">20</td>
                                    </tr>
                                    <tr>
                                        <td>Moe</td>
                                        <td>mary@example.com</td>
                                        <td class="hidden">Man</td>
                                        <td class="hidden">2</td>
                                        <td class="hidden">21</td>
                                    </tr> -->
                                </tbody>
                            </table>
                        </div>

                        <input id="d_id" class="text hidden">
                        <input id="d_profile_id" class="text hidden" value="<?= $customer['id'?>">
                        <input id="d_profile_delete" class="text hidden" value="N">
                        
                        <div class="control-group">
                            <label class="control-label" for="userFor">Account For</label>
                            <div class="controls">
                                <input type="text" id="userFor" name="userFor" value="" placeholder="Account For" />
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="loginId">Login ID</label>
                            <div class="controls">
                                <input type="text" id="loginId" name="loginId" value="" placeholder="Login ID" />
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="loginPw">Password</label>
                            <div class="controls">
                                <input type="text" id="loginPw" name="loginPw" value="" placeholder="Password" />
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" id="closeModal"
                        data-id="1" data-type="1">Close</button>
                    <button type="button" class="btn btn-warning" id="clearModal""
                        data-id="1" data-type="1">Clear</button>
                    <button type="button" class="btn btn-danger hidden" id="deleteModal">Delete</button>
                    <button type="button" class="btn btn-primary hidden" id="saveModal">Save</button>
                </div>
            </div>

        </form>

        <script type="text/javascript">
            $(function () {
                $('.select2').select2();
                $('#form').validate({
                    rules: {
                        'loginpw': {
                            minlength: 4
                        },
                        'loginpw2': {
                            equalTo: '#loginpw'
                        }
                    }
                });
            });

            $("#account").click(function () {
                var profileId = $(this).attr('data-id');
                $("#myModal").css("display", "block");

                $.ajax({url: 'modify.php',
                    type: 'POST',
                    data:{    profileId:profileId,
                            actionCode:'R'
                            },
                    dataType: 'json',
                    timeout: 1000,
                    error: function(){
                        alert('Error loading PHP document');
                        /*
                        window.location.reload();},*/
                    },
                    success: function(result){
                        $(".table>tbody").empty();
                        console.log(Object.entries(result));
                        //alert(result.length);
                        for ( var i=0; i< result.length; i++ ) {
                            $(".table>tbody").append("<tr onclick=(myFunction(this))>" +     
                                                    "<td>" + result[i]['account_for'] + "</td>" +
                                                    "<td>" + result[i]['login_id'] + "</td>" +
                                                    "<td class='hidden'>" + result[i]['login_pw'] + "</td>" +
                                                    "<td class='hidden'>" + result[i]['id'] + "</td>" +
                                                    "<td class='hidden'>" + result[i]['profile_id'] + "</td>" + "</tr>");
                        }
                    }
                });
                return false;
            })

            function getAccountList (profileId) {
                $.ajax({url: 'modify.php',
                    type: 'POST',
                    data:{    profileId:profileId,
                            actionCode:'R'
                            },
                    dataType: 'json',
                    timeout: 1000,
                    error: function(){
                        alert('Error loading PHP document');
                        /*
                        window.location.reload();},*/
                    },
                    success: function(result){
                        $(".table>tbody").empty();
                        console.log(Object.entries(result));
                        //alert(result.length);
                        for ( var i=0; i< result.length; i++ ) {
                            $(".table>tbody").append("<tr onclick=(myFunction(this))>" +     
                                                    "<td>" + result[i]['account_for'] + "</td>" +
                                                    "<td>" + result[i]['login_id'] + "</td>" +
                                                    "<td class='hidden'>" + result[i]['login_pw'] + "</td>" +
                                                    "<td class='hidden'>" + result[i]['id'] + "</td>" +
                                                    "<td class='hidden'>" + result[i]['profile_id'] + "</td>" + "</tr>");
                        }
                    }
                });                
            }

            $("#userFor, #loginId, #loginPw").change(function () { 
                if ( $("#userFor").val().length > 0 && 
                        $("#loginId").val().length > 0 && 
                        $("#loginPw").val().length > 0 ) {
                    $("#saveModal").removeClass("hidden");
                } else {
                    $("#saveModal").addClass("hidden");
                }
            });

            
            $("#deleteModal").click(function () { 
                if ( confirm("Are you sure you want to delete this record!") ) {
                    $("#d_profile_delete").val("Y");
                    $("#saveModal").click();
                }
                return false;
            });
            
            $("#saveModal").click(function () {
                var profileId = $("#d_profile_id").val();
                var userFor = $("#userFor").val();
                var    login_id = $("#loginId").val();
                var login_pw = $("#loginPw").val();
                var profile_delete = $("#d_profile_delete").val();
                
                var id = $("#d_id").val();
                id = id == "" ? "0" : id;
                
                $("#myModal").css("display", "block");
                
                //alert(profileId + " - " + userFor + " - " + login_id + " - " + login_pw + " - " + id + " - " + profile_delete);
                
                $.ajax({url: 'modify.php',
                    type: 'POST',
                    data:{    profile_id:$("#d_profile_id").val(),
                            account_for:$("#userFor").val(),
                            login_id:$("#loginId").val(),
                            login_pw:$("#loginPw").val(),
                            id:id,
                            actionCode:'S',
                            profile_delete:$("#d_profile_delete").val()
                            },
                    dataType: 'text',
                    timeout: 1000,
                    error: function(){
                        alert('Error loading PHP document');
                        /*
                        window.location.reload();},*/
                    },
                    success: function(result){
                        //$(".table>tbody").empty();
                            //alert($("#d_profile_id").val());
                            //alert(result);
                            getAccountList($("#d_profile_id").val());
                            $("#clearModal").click();
                    }
                });
                return false;
            })
            $(".close, #closeModal").click(function () {
                $("#myModal").css("display", "none");
                $("#clearModal").click();
            })

            $("#clearModal").click(function () {
                $("#d_id").val("");
                //$("#d_profile_id").val("");
                $("#userFor").val("");
                $("#loginId").val("");
                $("#loginPw").val("");
                $("#d_profile_delete").val("N");
                $("#actionType").text("Addtion").css('background-color', 'green');
                $("#saveModal, #deleteModal").addClass("hidden");
                //clearHighlight();
            })

            //$("tr").click(function () {
            //    var currentRow = $(this);
            //    var col1 = currentRow.find("td:eq(0)").text(); // get current row 1st TD - User For
            //    var col2 = currentRow.find("td:eq(1)").text(); // get current row 2nd TD - Login id
            //    var col3 = currentRow.find("td:eq(2)").text(); // get current row 3rd TD - Password
            //    var col4 = currentRow.find("td:eq(3)").text(); // get current row 4th TD - Table sequence Id
            //    var col5 = currentRow.find("td:eq(4)").text(); // get current row 5th TD - Customer Profile Id
            //    $("#userFor").val(col1);
            //    $("#loginId").val(col2);
            //    $("#loginPw").val(col3);
            //});

            function myFunction(x) {
                //clearHighlight();
                 document.getElementById("userFor").value = x.getElementsByTagName("td")[0].innerHTML;
                 document.getElementById("loginId").value = x.getElementsByTagName("td")[1].innerHTML;
                 document.getElementById("loginPw").value = x.getElementsByTagName("td")[2].innerHTML;
                 document.getElementById("d_id").value = x.getElementsByTagName("td")[3].innerHTML;
                 document.getElementById("d_profile_id").value = x.getElementsByTagName("td")[4].innerHTML;
                 $("#actionType").text("Modification").css('background-color', 'red');
                 $("#deleteModal").removeClass("hidden");
                 //x.style.background = "#ffffb3";
            }
            
            function clearHighlight(){
                var table = document.getElementById('tbl');
                for (var i=0;i < table.rows.length;i++){
                   var row = table.rows[i];
                   row.style.background ="white";
                 }
            }
        </script>


        <?php require(__DIR__ '/../../inc/_footer.php'); ?>

    </div> <!-- /container -->
</body>

</html>