-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddTask.php
More file actions
807 lines (615 loc) · 36.3 KB
/
Copy pathaddTask.php
File metadata and controls
807 lines (615 loc) · 36.3 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
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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
<?php
session_start();
include ("./connection.php");
$db= $con;
$tableName="users";
if($_SESSION['userlevel'] == "PIC"){
header("location: index.php");
}
$dateStarted = '2022-08-22';
$dateStarted = new DateTime($dateStarted);
$dateStarted->modify('-1 day');
$dateStarted = $dateStarted->format('Y-m-d');
// // $dateStarted =date('F j, Y',strtotime('2022-08-22'));
// $dateStarted =date('F j, Y',strtotime($dateStarted));
// echo $dateStarted;
// $dateStarted = new DateTime('2022-08-02');
// $dateStarted->modify('-1 day');
// $dateStarted = $dateStarted->format('Y-m-d');
// $dateStarted =date('F j, Y',strtotime($dateStarted));
// echo $dateStarted;
// $taskType="daily";
// $dateStarted = date('F j, Y');
// // $dateStarted = date('F j, Y');
// if($taskType == "daily"){
// $dateStarted = new DateTime($dateStarted);
// $dateStarted->modify('-1 day');
// $dateStarted = $dateStarted->format('Y-m-d');
// }
// echo $dateStarted;
$tableNameCat = 'category';
$columnsCat= ['categoryId', 'CategoryName'];
$fetchDataCat = fetch_dataCat($db, $tableNameCat, $columnsCat, $username);
function fetch_dataCat($db, $tableNameCat, $columnsCat, $username){
if(empty($db)){
$msg= "Database connection error";
}elseif (empty($columnsCat) || !is_array($columnsCat)) {
$msg="columns Name must be defined in an indexed array";
}elseif(empty($tableNameCat)){
$msg= "Table Name is empty";
}else{
$query = "SELECT * FROM `category`;";
// SELECT * FROM `usertask` ORDER BY taskCategory ASC;
// SELECT * FROM `usertask` WHERE `username` = 'cjorozo';
$result = $db->query($query);
if($result== true){
if ($result->num_rows > 0) {
$row= mysqli_fetch_all($result, MYSQLI_ASSOC);
$msg= $row;
} else {
$msg= "No Data Found";
}
}else{
$msg= mysqli_error($db);
}
}
return $msg;
}
$columns= ['username'];
$fetchData = fetch_data($db, $tableName, $columns);
function fetch_data($db, $tableName, $columns){
if(empty($db)){
$msg= "Database connection error";
}elseif (empty($columns) || !is_array($columns)) {
$msg="columns Name must be defined in an indexed array";
}elseif(empty($tableName)){
$msg= "Table Name is empty";
}else{
$columnName = implode(", ", $columns);
$Department = $_SESSION['userDept'];
$query = "SELECT * FROM `users` WHERE `department` = '$Department' AND `userlevel` = 'PIC'";
// SELECT * FROM `usertask` WHERE `username` = 'cjorozo';
$result = $db->query($query);
if($result== true){
if ($result->num_rows > 0) {
$row= mysqli_fetch_all($result, MYSQLI_ASSOC);
$msg= $row;
} else {
$msg= "No Data Found";
}
}else{
$msg= mysqli_error($db);
}
}
return $msg;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register</title>
<link rel="icon" type="image/x-icon" href="design_files/images/Task Monitoring Icon.ico">
<link rel="stylesheet" href="./css/bootstrap.min.css">
<link rel="stylesheet" href="design_files/css/bootstrap.min.css">
<!-- MATERIAL DESIGN ICONIC FONT -->
<link rel="stylesheet" href="design_files/fonts/material-design-iconic-font/css/material-design-iconic-font.min.css">
<!-- STYLE CSS -->
<link rel="stylesheet" href="design_files/css/style.css">
<!-- <link rel="stylesheet" href="design_files/css/style.css"> -->
<link rel="stylesheet" href="fontawesome-free-5.15.3-web/fontawesome-free-5.15.3-web/css/all.css">
<link rel="stylesheet" href="./css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script type="text/javascript" src="./js/jquery.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="./node_modules/sweetalert2/dist/sweetalert2.all.min.js"></script>
<link rel="stylesheet" href="./node_modules/sweetalert2/dist/sweetalert2.min.css">
</head>
<body>
<?php
if(isset($_POST['btnAddtask'])){
$src1User = $_POST['strnowUser'];
$array11User = explode(",", $src1User);
$numberofAddedUser = $_POST['countInputUser'];
for($u=0;$u<$numberofAddedUser;$u++){
$src1 = $_POST['strnow'];
$array11 = explode(",", $src1);
// print_r($array11);
// const numberOfAddedProducts=document.getElementById("countInput").value;
$numberofAddedTask = $_POST['countInput'];
// $enteredUserName = $_POST['username'];
$enteredUserName = htmlspecialchars($_POST["username".$array11User[$u]]);
// $endTargetDate = $_POST['endTargetDate'];
// $dateAdded = $_POST['StartDate'];
// $dateAdded = date('Y-m-d');
$arrraayyy = $_POST['strnow'];
echo '<script>console.log("Number of Added Task: '.$numberofAddedTask.'")</script>';
$num = 1;
$taskname = htmlspecialchars($_POST["taskName".$num]);
$taskCategory = htmlspecialchars($_POST["taskCategory".$num]);
$taskType = htmlspecialchars($_POST["taskType".$num]);
$taskArea = htmlspecialchars($_POST["taskArea".$num]);
$dateStarted = htmlspecialchars($_POST["StartDate".$num]);
$dateAdded = htmlspecialchars($_POST["StartDate".$num]);
$endTargetDate = htmlspecialchars($_POST["endTargetDate".$num]);
// echo '<script>window.alert("TEST: '.$taskname.'")</script>';
// $b = 0;
$selectUserID = "SELECT `userid` FROM `users` WHERE `username` = '$enteredUserName';";
$resultUserId = mysqli_query($con, $selectUserID);
$resultUserId1;
if (mysqli_num_rows($resultUserId) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($resultUserId)) {
$resultUserId1 = $row["userid"];
}
// echo '<script>console.log("TEST: '.$resultUserId.'")</script>';
}
$selectUserDept= "SELECT `department` FROM `users` WHERE `username` = '$enteredUserName';";
$resultUserDept = mysqli_query($con, $selectUserDept);
$resultUserDept1;
if (mysqli_num_rows($resultUserDept) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($resultUserDept)) {
$resultUserDept1 = $row["department"];
}
// echo '<script>console.log("TEST: '.$resultUserId.'")</script>';
}
for($b=0;$b<$numberofAddedTask;$b++){
$taskname = htmlspecialchars($_POST["taskName".$array11[$b]]);
$taskCategory = htmlspecialchars($_POST["taskCategory".$array11[$b]]);
$taskType = htmlspecialchars($_POST["taskType".$array11[$b]]);
$taskArea = htmlspecialchars($_POST["taskArea".$array11[$b]]);
$dateStarted = htmlspecialchars($_POST["StartDate".$array11[$b]]);
$dateAdded = htmlspecialchars($_POST["StartDate".$array11[$b]]);
$endTargetDate = htmlspecialchars($_POST["endTargetDate".$array11[$b]]);
echo '<script>console.log("TEST: '.$taskname.'")</script>';
echo '<script>console.log("TEST: '.$taskCategory.'")</script>';
echo '<script>console.log("TEST: '.$taskType.'")</script>';
// echo '<script>console.log("arrayyyy: '.$finalarray[1].'")</script>';
// $dateStarted = date('F j, Y');
// $dateStarted = $_POST['StartDate'];
// $EndDate = new DateTime($March); $endDATE = $EndDate->format('Y-m-d');
// $dateStarted = new DateTime(); $dateStarted = $dateStarted->format('Y-m-d');
try {
if($taskType == "daily"){
$dateStarted = new DateTime($dateAdded);
$dateStarted->modify('-1 day');
$dateStarted = $dateStarted->format('Y-m-d');
// $dateStarted = $dateStarted->format('Y-m-d');
// $dateStarted =date('F j, Y',strtotime($dateStarted));
}
else if($taskType == "weekly"){
$dateStarted = new DateTime($dateAdded);
$dateStarted->modify('monday last week');
$dateStarted = $dateStarted->format('Y-m-d');
}
else if($taskType == "monthly"){
$dateStarted = new DateTime($dateAdded);
$dateStarted->modify('last month');
$dateStarted = $dateStarted->format('Y-m-d');
}
else if($taskType == "annual"){
$dateStarted = new DateTime($dateAdded);
$dateStarted->modify('last year');
$dateStarted = $dateStarted->format('Y-m-d');
}
$sqlinsert = "INSERT INTO `usertask`(`userid`, `username`, `taskName`, `taskCategory`, `taskArea`, `taskType`, `Department`, `dateStarted`, `dateAdded`,`targetDate`) VALUES ('$resultUserId1','$enteredUserName','$taskname','$taskCategory','$taskArea','$taskType', '$resultUserDept1', '$dateStarted','$dateAdded','$endTargetDate');";
mysqli_query($con, $sqlinsert);
$num++;
}
catch (Exception $e){
?><script>
Swal.fire({
icon: 'error',
title: 'Unsucessfull',
text: 'You have not successfully added task/s!',
// footer: '<a href="">Why do I have this issue?</a>'
})
</script><?php
}
finally {
if( $_SESSION['admin']=="TRUE"){
?><script>
Swal.fire({
icon: 'success',
title: 'Successfull',
text: 'You have successfully added task/s!',
// footer: '<a href="">Why do I have this issue?</a>'
}).then(function() {
window.location = "leader.php";
});
</script><?php
// header("location: admin.php");
}
else{
?><script>
Swal.fire({
icon: 'success',
title: 'Successfull',
text: 'You have successfully added task/s!',
// footer: '<a href="">Why do I have this issue?</a>'
}).then(function() {
window.location = "leader.php";
});
</script><?php
}
}
}
}
// if($b>=1){
// // $taskname = $_POST['taskName'.$num.];
// $num = 1;
// // $username = $_POST['username'];
// // $password = $_POST['password'];
// // echo '<script>alert("OK")</script>';
// }
//LINTEK
}
?>
<div>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<a class="navbar-brand" href="
<?php
if($_SESSION['admin'] == "False")
{
echo "leader.php";
}
else{
echo "admin.php";
}
?>"> <img src="design_files/images/GloryPhLogo.jpg" alt="..." height="40"> Task Monitoring</a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarSupportedContent">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="<?php
if($_SESSION['admin'] == "False")
{
echo "leader.php";
}
else{
echo "admin.php";
}
?>">Home</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Add Task</a>
</li>
<!-- <li class="nav-item">
<a class="nav-link" href="#">About</a>
</li> -->
</ul>
</div>
</nav>
</div>
<div class="wrapper" style="background: linear-gradient(to right, rgb(22, 34, 42), rgb(58, 96, 115));">
<div class="inner" style="width: 1200px; height: 500px; max-width: 1200px; border-radius: 60px" id="formId">
<form id="account-settings" action="addTask.php" method = "POST" style="width: 1200px; padding: 10px;" >
<!-- <h3>Register User</h3> -->
<h3 style="text-align: center; margin-bottom: 40px; ">Add task</h3>
<div class="overflow-x">
<div class="overflow-y" style="overflow-y: scroll; overflow-x: hidden; display: block; height: 50px" id="adduser">
<div class="form-group row" id="NewTaskDivUser1">
<label for="colFormLabelSm" class="col-sm-2 col-form-label col-form-label-sm">User Name</label>
<!-- <div class="col-sm-5">
<input type="text" name="username" class="form-control form-control-sm" id="colFormLabelSm" style="width:100%; padding: 10px;" placeholder="" >
</div> -->
<div class="col-sm-5">
<select name="username1" id="usernameSelect1" class=" form-control form-select form-select-sm"
style="padding-left:10px;">
<option value="" disabled selected>Select User Name</option>
<!-- <option value="weekly">Weekly</option>
<option value="monthly">Monthly</option> -->
<?php
if(is_array($fetchData)){
foreach($fetchData as $data){
?>
<option value="<?php echo $data['username']??''; ?>"><?php echo $data['f_name']??''; ?></option>
<?php
}}else{ ?>
<option colspan="8">
<?php echo $fetchData; ?>
</option>
<?php
}?>
</select>
</div>
<div class="col-sm-1">
<!-- <input name="btnplus" type="submit" value="+" class="btn btn-success" id="addProdBtn" style="margin-top: 0px; width: 50px; height: 30px; padding: 0px" onclick="addNewInputsForAddTask()" > -->
<button type="button" class="btn btn-success" id="addUserBtn" style="margin-top: 0px; width: 50px; height: 30px; padding: 0px" onclick="addNewUser()">+</button>
<input class="col-sm-1 col-form-label" style="text-align: center; font-size: 13px; display: none; width: 80px; height: 30px" type="number" name="countInputUser" id="countInputUser" value=1>
</div>
</div>
</div>
</div>
<input type="text" id="strUser" value="1" name="strnowUser"style="display: none" />
<input type="button" id="btnUser" name="submitnowUser" value="Submit" style="display: none"/>
<?php
$dateOfNow = new DateTime(date('Y-m-d'));
$MonthOfNow = $dateOfNow->format('F');
$YearToUseForApril = "";
$YearToUseforMarch = "";
if($MonthOfNow=="January" || $MonthOfNow=="February" || $MonthOfNow=="March"){
$YearToUseforMarch = $dateOfNow->format('Y');
$dateOfNow->modify('last year');
$YearToUseForApril = $dateOfNow->format('Y');
}
else{
$YearToUseForApril = $dateOfNow->format('Y');
$dateOfNow->modify('next year');
$YearToUseforMarch = $dateOfNow->format('Y');
}
$April = new DateTime($YearToUseForApril.'-04-01');
$March = new DateTime($YearToUseforMarch.'-03-31');
$April = $April->format('Y-m-d');
$March = $March->format('Y-m-d');
?>
<!-- <div class="form-group row" style="margin-bottom: 30px">
<label class="col-sm-2 col-form-label col-form-label sm"> Start Date </label>
<div class="col-sm-3">
<input type="date" style="height: 100%; width: 100%;" id="startDate" value="<?php $startDate = new DateTime(); $startDATE = $startDate->format('Y-m-d'); echo $startDATE ?>" name="StartDate" onchange="filterMonth();">
</div>
<label class="col-sm-2 col-form-label col-form-label sm"> Target End Date </label>
<div class="col-sm-3">
<input type="date" style="height: 100%; width: 100%;" id="endTargetDate" value="<?php $EndDate = new DateTime($March); $endDATE = $EndDate->format('Y-m-d'); echo $endDATE ?>" name="endTargetDate" onchange="filterMonth();">
</div>
</div> -->
<div class="form-group row" style="padding-bottom: 0; margin-bottom: 0">
<div class="col-sm-1"> </div>
<div class="col-sm-2"> </div>
<div class="col-sm-2"> </div>
<div class="col-sm-2"> </div>
<div class="col-sm-1"> </div>
<div class=" form-group row col-sm-3" style="text-align: center">
<div class="col-sm-6" style="padding:0; margin:0"><h7>Start Date</h7></div>
<div class="col-sm-6" style="padding:0; margin:0"><h7>Target End Date</h7></div>
</div>
<div class="col-sm-1"> </div>
</div>
<div class="overflow-x">
<div class="overflow-y" style="overflow-y: scroll; overflow-x: hidden; display: block; height: 240px" id="addtask">
<div class="form-group row">
<label for="colFormLabelSm" class="col-sm-1 col-form-label col-form-label-sm" style="font-size: 10pt; padding-right: 0px">Add Task</label>
<div class="col-sm-2">
<input type="text" name="taskName1" class="form-control form-control-sm" id="taskName1" style="width:100%; padding: 10px; height: 38px" placeholder="Task Name" >
</div>
<div class="col-sm-2">
<select name="taskType1" id="taskType1" class=" form-control form-select form-select-sm" style="padding-left:10px;">
<option value="" disabled selected>Type</option>
<option value="daily">Daily</option>
<option value="weekly">Weekly</option>
<option value="monthly">Monthly</option>
<option value="annual">Annual</option>
<option value="others">Others</option>
<!-- Update for October 07 2022 -->
</select>
</div>
<div class="col-sm-2">
<select name="taskCategory1" id="taskCategory1" class=" form-control form-select form-select-sm" style="padding-left:10px;">
<option value="" disabled selected>Category</option>
<?php
if(is_array($fetchDataCat)){
foreach($fetchDataCat as $data){
?>
<option value="<?php echo $data['CategoryName']??''; ?>"><?php echo $data['CategoryName']??''; ?></option>
<?php
}}else{ ?>
<option colspan="8">
<?php echo $fetchDataCat; ?>
</option>
<?php
}?>
</select>
</div>
<div class="col-sm-1" style="padding: 0">
<select name="taskArea1" id="taskArea1" class=" form-control form-select form-select-sm" style="padding-left:10px;">
<option value="" disabled >Area</option>
<option value="All" selected>All</option>
<option value="GPI 1">GPI 1</option>
<option value="GPI 2">GPI 2</option>
<option value="GPI 3">GPI 3</option>
<option value="GPI 4">GPI 4</option>
<option value="GPI 5">GPI 5</option>
<option value="GPI 6">GPI 6</option>
<option value="GPI 7">GPI 7</option>
<option value="GPI 8">GPI 8</option>
<option value="GPI 9">GPI 9</option>
</select>
</div>
<div class="col-sm-3" style="text-align: center">
<input type="date" style="height: 60%; width: 47%; margin: 0" id="startDate1" value="<?php $startDate = new DateTime(); $startDATE = $startDate->format('Y-m-d'); echo $startDATE ?>" name="StartDate1" onchange="filterMonth();">
<input type="date" style="height: 60%; width: 47%;" id="endTargetDate1" value="<?php $EndDate = new DateTime($March); $endDATE = $EndDate->format('Y-m-d'); echo $endDATE ?>" name="endTargetDate1" onchange="filterMonth();">
</div>
<div class="col-sm-1">
<!-- <input name="btnplus" type="submit" value="+" class="btn btn-success" id="addProdBtn" style="margin-top: 0px; width: 50px; height: 30px; padding: 0px" onclick="addNewInputsForAddTask()" > -->
<button type="button" class="btn btn-success" id="addProdBtn" style="margin-top: 0px; width: 50px; height: 30px; padding: 0px" onclick="addNewInputForProducts()">+</button>
</div>
<input class="col-sm-1 col-form-label" style="text-align: center; font-size: 13px; display: none; width: 80px; height: 30px" type="number" name="countInput" id="countInput" value=1>
</div>
</div>
</div>
<div class="form-group container-login100-form-btn" >
<button id="btn-register" class="btn-signin" type="button" name="btnRegister" value="Register" style="margin: auto; width: 200px; margin-top: 0px" onclick=" checkTextBox('','','','','')">
Add Task</button>
<input id="sbt-php-addtask" class="btn-signin" type="submit" name="btnAddtask" value="Register" style="margin: auto; width: 200px; margin-top: -10px; display: none;">
<!-- <input id="btn-signup" class="btn-signin" name="sbtregister" type="submit" value="Register" disabled style="margin: auto;" > -->
</div>
<input type="text" id="str" value="1" name="strnow"style="display: none" />
<input type="button" id="btn" name="submitnow" value="Submit" style="display: none"/>
</form>
</div>
</div>
<script>
const DivProdContainer = document.getElementById("addtask");
const DivProdContainerUser = document.getElementById("adduser");
// var formheight = 70;
// var numForID=2;
// const formAddProducts = document.getElementById("AddProductsForm")
var formheight = 70;
var numForID=2;
var numForIDUser=2;
var arrayList;
var arrayListUser;
const divIdArray = [1];
const divIdArrayUser = [1];
var finalArrayLenght = 1;
var finalArrayLenghtUser = 1;
function addNewInputForProducts()
{
document.getElementById("countInput").stepUp(1);
const newDiv=document.createElement("div");
newDiv.classList.add("col-sm-12");
newDiv.style.padding = '0px';
// var taskInput='<div class="form-group row"><div class="col-lg-4"><input class="form-control" id="inputItem'+numForID+'" required ><div class="invalid-feedback"style=" margin-bottom: 20px; margin-left: 30px">Please fill out this field.</div></div><div class="col-lg-4"><input class="form-control" id="inputDesc'+numForID+'" ></div><div class="col-lg-3"><input class="form-control" id="inputPrice'+numForID+'" ></div></div>'
var taskInput='<div class="form-group row" id="NewTaskDiv'+numForID+'"style="margin-top: -30px"> <label for="colFormLabelSm" class="col-sm-1 col-form-label col-form-label-sm" style="font-size: 10pt; padding-right: 0px"> </label><div class="col-sm-2"><input type="text" class="form-control form-control-sm" id="taskName'+numForID+'" style="width:100%; padding: 10px;height: 38px" name="taskName'+numForID+'" placeholder="Task Name" ></div><div class="col-sm-2"><select name="taskType'+numForID+'" id="taskType'+numForID+'" class=" form-control form-select form-select-sm" style="padding-left:10px;"> <option value="" disabled selected>Type</option><option value="daily">Daily</option><option value="weekly">Weekly</option> <option value="monthly">Monthly</option><option value="annual">Annual</option><option value="others">Others</option> </select></div> <div class="col-sm-2"><select name="taskCategory'+numForID+'" id="taskCategory'+numForID+'" class=" form-control form-select form-select-sm" style="padding-left:10px;"> <option value="" disabled selected>Category</option> <?php if(is_array($fetchDataCat)){ foreach($fetchDataCat as $data){?> <option value="<?php echo $data["CategoryName"] ?>"><?php echo $data["CategoryName"] ?></option> <?php }}else{ ?> <option colspan="8"> <?php echo $fetchDataCat ?> </option> <?php }?> </select></div><div class="col-sm-1" style="padding: 0"><select name="taskArea'+numForID+'" id="taskArea'+numForID+'" class=" form-control form-select form-select-sm" style="padding-left:10px;"><option value="" disabled selected>Area</option> <option value="All">All</option><option value="GPI 1">GPI 1</option><option value="GPI 2">GPI 2</option><option value="GPI 3">GPI 3</option><option value="GPI 4">GPI 4</option><option value="GPI 5">GPI 5</option><option value="GPI 6">GPI 6</option><option value="GPI 7">GPI 7</option><option value="GPI 8">GPI 8</option><option value="GPI 9">GPI 9</option></select></div><div class="col-sm-3" style="text-align: center"><input type="date" style="height: 60%; width: 47%;margin: 0" id="startDate'+numForID+'" value="<?php $startDate = new DateTime(); $startDATE = $startDate->format('Y-m-d'); echo $startDATE ?>" name="StartDate'+numForID+'" onchange="filterMonth();"> <input type="date" style="height: 60%; width: 47%;" id="endTargetDate'+numForID+'" value="<?php $EndDate = new DateTime($March); $endDATE = $EndDate->format('Y-m-d'); echo $endDATE ?>" name="endTargetDate'+numForID+'" onchange="filterMonth();"></div><div class="col-sm-1"><button type="button" class="btn btn-danger" id="addProdBtn" style="margin-top: 0px; width: 50px; height: 30px; padding: 0px" onclick="RemoveInputForProducts('+numForID+')">-</button></div>';
//Update for October 07 2022
newDiv.innerHTML=taskInput;
DivProdContainer.appendChild(newDiv);
divIdArray.push(numForID);
document.getElementById("str").value = divIdArray;
console.log(divIdArray);
console.log(divIdArray.length);
finalArrayLenght++;
// document.getElementById("btn").click();
// var formheightInt= 320+formheight;
// formAddProducts.style.height=formheightInt+"px";
// formheight+=70;
numForID++;
}
var height = 50;
var heightForm = 500;
function addNewUser()
{
height = height+50;
heightForm = heightForm+50;
document.getElementById("adduser").style.height = height+"px";
document.getElementById("formId").style.height = heightForm+"px";
document.getElementById("countInputUser").stepUp(1);
const newDiv=document.createElement("div");
newDiv.classList.add("col-sm-12");
newDiv.style.padding = '0px';
// var taskInput='<div class="form-group row"><div class="col-lg-4"><input class="form-control" id="inputItem'+numForID+'" required ><div class="invalid-feedback"style=" margin-bottom: 20px; margin-left: 30px">Please fill out this field.</div></div><div class="col-lg-4"><input class="form-control" id="inputDesc'+numForID+'" ></div><div class="col-lg-3"><input class="form-control" id="inputPrice'+numForID+'" ></div></div>'
var taskInput='<div class="form-group row" style="margin-top: -30px" id="NewTaskDivUser'+numForIDUser+'" style="margin-bottom: 0px"> <label for="colFormLabelSm" class="col-sm-2 col-form-label col-form-label-sm"></label> <div class="col-sm-5"> <select name="username'+numForIDUser+'" id="usernameSelect'+numForIDUser+'" class=" form-control form-select form-select-sm" style="padding-left:10px;"> <option value="" disabled selected>Select User Name</option> <?php if(is_array($fetchData)){ foreach($fetchData as $data){ ?> <option value="<?php echo $data['username']??''; ?>"><?php echo $data['f_name']??''; ?></option><?php }}else{ ?> <option colspan="8"> <?php echo $fetchData; ?> </option> <?php }?></select> </div> <div class="col-sm-1"><button type="button" class="btn btn-danger" id="addProdBtn" style="margin-top: 0px; width: 50px; height: 30px; padding: 0px" onclick="RemoveInputForUser('+numForIDUser+')">-</button> </div></div>';
newDiv.innerHTML=taskInput;
DivProdContainerUser.appendChild(newDiv);
divIdArrayUser.push(numForIDUser);
document.getElementById("strUser").value = divIdArrayUser;
console.log(divIdArrayUser);
console.log(divIdArrayUser.length);
finalArrayLenghtUser++;
// document.getElementById("btn").click();
// var formheightInt= 320+formheight;
// formAddProducts.style.height=formheightInt+"px";
// formheight+=70;
numForIDUser++;
}
function RemoveInputForProducts(divID){
// numForID--;
document.getElementById("countInput").stepDown(1);
var newdivID = "NewTaskDiv"+numForID.toString()+"";
console.log(newdivID);
const elem = document.getElementById("NewTaskDiv"+divID);
elem.remove();
divID--;
// delete divIdArray[divID];
divIdArray.splice(divIdArray.indexOf(divID+1), 1);
console.log(divIdArray);
finalArrayLenght--;
console.log(finalArrayLenght);
arrayList = divIdArray.join();
document.getElementById("str").value = divIdArray;
}
function RemoveInputForUser(divID){
height = height-50;
heightForm = heightForm-50;
document.getElementById("adduser").style.height = height+"px";
document.getElementById("formId").style.height = heightForm+"px";
// numForID--;
document.getElementById("countInputUser").stepDown(1);
var newdivID = "NewTaskDivUser"+numForIDUser.toString()+"";
console.log(newdivID);
const elem = document.getElementById("NewTaskDivUser"+divID);
elem.remove();
divID--;
// delete divIdArray[divID];
divIdArrayUser.splice(divIdArrayUser.indexOf(divID+1), 1);
console.log(divIdArrayUser);
finalArrayLenghtUser--;
console.log(finalArrayLenghtUser);
arrayListUser = divIdArrayUser.join();
document.getElementById("strUser").value = divIdArrayUser;
}
$(document).ready(function(){
$("#btn").click( function() {
$.post( $("#addTaskForm").attr("action"),
$('#str').val(JSON.stringify(arrayList)),
//$("#myForm :input").serializeArray(),
function(info){ $("#result").html(info);
});
});
$("#addTaskForm").submit( function() {
return false;
});
});
$(document).ready(function(){
$("#btnUser").click( function() {
$.post( $("#addUserForm").attr("action"),
$('#str').val(JSON.stringify(arrayList)),
//$("#myForm :input").serializeArray(),
function(info){ $("#result").html(info);
});
});
$("#addUserForm").submit( function() {
return false;
});
});
function checkTextBox(count,id1,id2,id3,store){
// const username=document.getElementById("usernameSelect1").value;
const numberOfAddedTask=document.getElementById("countInput").value;
const numberOfAddedUser=document.getElementById("countInputUser").value;
console.log(numberOfAddedTask-1);
var c;
var numb=1;
var d=0;
var cUser;
var numbUser=1;
var dUser=0;
// var taskName1awda=document.getElementById("taskName1").value;
// console.log(taskName1awda)
//Age !=""&&NameOfKid !="" && MiddleInitial != ""&& LastName!=""&&
for(c=0;c<numberOfAddedTask;c++){
console.log("Array natin to: "+divIdArray[c]);
const taskName1=document.getElementById("taskName"+divIdArray[c]);
const taskType1=document.getElementById("taskType"+divIdArray[c]);
const taskCategory1=document.getElementById("taskCategory"+divIdArray[c]);
if(taskName1.value != "" && taskType1.value != "" && taskCategory1.value !="")
{
d++;
}
numb++;
}
for(cUser=0;cUser<numberOfAddedUser;cUser++){
console.log("Array natin to: "+divIdArrayUser[cUser]);
const user=document.getElementById("usernameSelect"+divIdArrayUser[cUser]);
if(user.value != "")
{
dUser++;
}
numbUser++;
}
if(d==numberOfAddedTask && dUser==numberOfAddedUser){
console.log("ok")
document.getElementById("sbt-php-addtask").click();
}
else{
// var formssag = document.getElementById('inputProducts');
// formssag.classList.add('was-validated');
window.alert("Form is incomplete. Please fill out all fields")
}
}
</script>
</body>
</html>