<?= $this->extend('layouts/main.php') ?>

<?= $this->section('content') ?>
<style>
.small { font-size : 11px; }
.buglink:hover { background-color:#888; }
.right {}
</style>
<div class="page-wrapper">
	<div class="container-fluid">
		<div class="row page-titles">
			<div class="col-md-5 align-self-center">
				<h4 class="text-themecolor">Bugs Management Page</h4>
			</div>
		</div>
		<div class="row">
			<div class="col-12">
				<div class="alert alert-warning" role="alert">
					Apabila menemukan <b>Bugs, Error dan Ingin Fitur Tambahan/Baru</b> ataupun yang berhubungan dengan CRM mohon dituliskan disini. Terima Kasih <i class="fa-regular fa-face-grin-wide"></i>
				</div>
			</div>

			<div class="col-12">
				<div class="card">
					<div class="card-body">
						<div class="row mb-3">
							<div class="col-12">
								<a class='btn btn-info btn-sm text-white' href='bugs/create/' 
									onclick="window.open(this.href, 'Create Bugs','width=1000,height=600,toolbar=1,resizable=0'); return false;">
									<i class="fas fa-plus-circle"></i> Add Bugs
								</a>
							</div>
						</div>

						<div class='row p-2'>

							<ul class="nav nav-tabs mb-2" id="myTab" role="tablist">
								<li class="nav-item" role="presentation">
									<button class="nav-link active" id="open-tab" data-bs-toggle="tab" data-bs-target="#open-tab-pane" type="button" role="tab">Open</button>
								</li>
								<li class="nav-item" role="presentation">
									<button class="nav-link" id="pending-tab" data-bs-toggle="tab" data-bs-target="#pending-tab-pane" type="button" role="tab">Pending</button>
								</li>
								<li class="nav-item" role="presentation">
									<button class="nav-link" id="close-tab" data-bs-toggle="tab" data-bs-target="#close-tab-pane" type="button" role="tab">Close</button>
								</li>
								<li class="nav-item" role="presentation">
									<button class="nav-link" id="suspend-tab" data-bs-toggle="tab" data-bs-target="#suspend-tab-pane" type="button" role="tab">Suspend</button>
								</li>
							</ul>
							
							<div class="tab-content" id="myTabContent">
							
								<div class="tab-pane fade show active" id="open-tab-pane" role="tabpanel" tabindex="0">
									<div class="table-responsive">
										<table id="openTable" class="table display border">
											<thead>
												<th>bugs#</th> <th>status</th> <th>priority</th> <th>date</th>
											</thead>
											<tbody>
											<?php
												foreach ($bugs as $data) {
													
													$bugstatus = $data['bugstatus'];

													if ($bugstatus == 'O') {

														$bugid = $data['bugid'];
														$bugtitle = $data['bugtitle'];
														$bugcreator = $data['creator_firstname'].' '.$data['creator_lastname'];
														
														$bugpriority = $data['bugpriority'];
														if($bugpriority == '0') { $bugprioritytext = "<td><span class='badge bg-success'>low</span></td>"; }
														else if($bugpriority == '1') { $bugprioritytext = "<td><span class='badge bg-warning'>medium</span></td>"; }
														else if($bugpriority == '2') { $bugprioritytext = "<td><span class='badge bg-danger'>high</span></td>"; }
														
														$bugreportdate = substr($data['reportdate'],0,16);
														$bugcommentcount = $data['bugcommentcount'];
														$buglastcommentdate = $data['buglastcommentdate'];
														
														$buglastcommentdatetext = '';
														if($buglastcommentdate != '') {
															$buglastcommentdate = substr($buglastcommentdate,0,16);
															$buglastcommentdatetext = "<br/> last comment <i>$buglastcommentdate</i>";
														}
														
														$bugstatustext = "<td><span class='badge bg-danger'>open</span></td>";
														
														echo "
														<tr class='buglink' onclick=\"window.open('bugs/view/$bugid', 'form','width=1000,height=700'); return false;\"> 
															<td>
																$bugtitle <b>#$bugid</b> 
																<br/><span class='small'>by <i>$bugcreator</i></span> <span class='small' style='float:right;'>total comment : $bugcommentcount</span>
															</td> 
															$bugstatustext $bugprioritytext 
															<td>
																report at <i>$bugreportdate</i> 
																$buglastcommentdatetext
															</td> 
														</tr>";
													}
													 												
												}
											?>
											</tbody>
										</table>
									</div> 
								</div>
								<div class="tab-pane fade" id="pending-tab-pane" role="tabpanel" tabindex="0">
									<div class="table-responsive">
										<table id="pendingTable" class="table display border">
											<thead>
												<tr>
													<th>bugs#</th> 
													<th>status</th> 
													<th>priority</th> 
													<th>date</th>
												</tr>
											</thead>
											<tbody>
											<?php
												foreach ($bugs as $data) {
													
													$bugstatus = $data['bugstatus'];

													if ($bugstatus == 'P') {

														$bugid = $data['bugid'];
														$bugtitle = $data['bugtitle'];
														$bugcreator = $data['creator_firstname'].' '.$data['creator_lastname'];
														
														$bugpriority = $data['bugpriority'];
														if($bugpriority == '0') { $bugprioritytext = "<td><span class='badge bg-success'>low</span></td>"; }
														else if($bugpriority == '1') { $bugprioritytext = "<td><span class='badge bg-warning'>medium</span></td>"; }
														else if($bugpriority == '2') { $bugprioritytext = "<td><span class='badge bg-danger'>high</span></td>"; }
														
														$bugreportdate = substr($data['reportdate'],0,16);
														$bugcommentcount = $data['bugcommentcount'];
														$buglastcommentdate = $data['buglastcommentdate'];
														
														$buglastcommentdatetext = '';
														if($buglastcommentdate != '') {
															$buglastcommentdate = substr($buglastcommentdate,0,16);
															$buglastcommentdatetext = "<br/> last comment <i>$buglastcommentdate</i>";
														}
														
														$bugstatustext = "<td><span class='badge bg-warning'>pending</span></td>";
														
														echo "
														<tr class='buglink' onclick=\"window.open('bugs/view/$bugid', 'form','width=1000,height=700'); return false;\"> 
															<td>
																$bugtitle <b>#$bugid</b> 
																<br/><span class='small'>by <i>$bugcreator</i></span> <span class='small' style='float:right;'>total comment : $bugcommentcount</span>
															</td> 
															$bugstatustext $bugprioritytext 
															<td>
																report at <i>$bugreportdate</i> 
																$buglastcommentdatetext
															</td> 
														</tr>";
													}
													 												
												}
											?>
											</tbody>
										</table>
									</div>
								</div>
								<div class="tab-pane fade" id="close-tab-pane" role="tabpanel" tabindex="0">
									<div class="table-responsive">
										<table id="closeTable" class="table display border">
											<thead>
												<th>bugs#</th> <th>status</th> <th>priority</th> <th>date</th>
											</thead>
											<tbody>
											<?php
												foreach ($bugs as $data) {
													
													$bugstatus = $data['bugstatus'];

													if ($bugstatus == 'C') {

														$bugid = $data['bugid'];
														$bugtitle = $data['bugtitle'];
														$bugcreator = $data['creator_firstname'].' '.$data['creator_lastname'];
														
														$bugpriority = $data['bugpriority'];
														if($bugpriority == '0') { $bugprioritytext = "<td><span class='badge bg-success'>low</span></td>"; }
														else if($bugpriority == '1') { $bugprioritytext = "<td><span class='badge bg-warning'>medium</span></td>"; }
														else if($bugpriority == '2') { $bugprioritytext = "<td><span class='badge bg-danger'>high</span></td>"; }
														
														$bugreportdate = substr($data['reportdate'],0,16);
														$bugcommentcount = $data['bugcommentcount'];
														$buglastcommentdate = $data['buglastcommentdate'];
														
														$buglastcommentdatetext = '';
														if($buglastcommentdate != '') {
															$buglastcommentdate = substr($buglastcommentdate,0,16);
															$buglastcommentdatetext = "<br/> last comment <i>$buglastcommentdate</i>";
														}
														
														$bugstatustext = "<td><span class='badge bg-success'>closed</span></td>";
														
														echo "
														<tr class='buglink' onclick=\"window.open('bugs/view/$bugid', 'form','width=1000,height=700'); return false;\"> 
															<td>
																$bugtitle <b>#$bugid</b> 
																<br/><span class='small'>by <i>$bugcreator</i></span> <span class='small' style='float:right;'>total comment : $bugcommentcount</span>
															</td> 
															$bugstatustext $bugprioritytext 
															<td>
																report at <i>$bugreportdate</i> 
																$buglastcommentdatetext
															</td> 
														</tr>";
													}
													 												
												}
											?>
											</tbody>
										</table>
									</div>
								</div>
								<div class="tab-pane fade" id="suspend-tab-pane" role="tabpanel" tabindex="0">
									<div class="table-responsive">
										<table id="suspendTable" class="table display border">
											<thead>
												<th>bugs#</th> <th>status</th> <th>priority</th> <th>date</th>
											</thead>
											<tbody>
											<?php
												foreach ($bugs as $data) {
													
													$bugstatus = $data['bugstatus'];

													if ($bugstatus == 'S') {

														$bugid = $data['bugid'];
														$bugtitle = $data['bugtitle'];
														$bugcreator = $data['creator_firstname'].' '.$data['creator_lastname'];
														
														$bugpriority = $data['bugpriority'];
														if($bugpriority == '0') { $bugprioritytext = "<td><span class='badge bg-success'>low</span></td>"; }
														else if($bugpriority == '1') { $bugprioritytext = "<td><span class='badge bg-warning'>medium</span></td>"; }
														else if($bugpriority == '2') { $bugprioritytext = "<td><span class='badge bg-danger'>high</span></td>"; }
														
														$bugreportdate = substr($data['reportdate'],0,16);
														$bugcommentcount = $data['bugcommentcount'];
														$buglastcommentdate = $data['buglastcommentdate'];
														
														$buglastcommentdatetext = '';
														if($buglastcommentdate != '') {
															$buglastcommentdate = substr($buglastcommentdate,0,16);
															$buglastcommentdatetext = "<br/> last comment <i>$buglastcommentdate</i>";
														}
														
														$bugstatustext = "<td><span class='badge bg-dark'>suspend</span></td>";
														
														echo "
														<tr class='buglink' onclick=\"window.open('bugs/view/$bugid', 'form','width=1000,height=700'); return false;\"> 
															<td>
																$bugtitle <b>#$bugid</b> 
																<br/><span class='small'>by <i>$bugcreator</i></span> <span class='small' style='float:right;'>total comment : $bugcommentcount</span>
															</td> 
															$bugstatustext $bugprioritytext 
															<td>
																report at <i>$bugreportdate</i> 
																$buglastcommentdatetext
															</td> 
														</tr>";
													}
													 												
												}
											?>
											</tbody>
										</table>
									</div>
								</div>

							</div>

							<!-- All bugs -->
							<!-- <div class="table-responsive">
								<table id="myTable" class="table display border">
									<thead>
										<th>bugs#</th> <th>status</th> <th>priority</th> <th>date</th>
									</thead>
									<tbody>
										<?php
											foreach ($bugs as $data) {
												$bugid = $data['bugid'];
												$bugtitle = $data['bugtitle'];
												$bugcreator = $data['creator_firstname'].' '.$data['creator_lastname'];
												
												$bugpriority = $data['bugpriority'];
												if($bugpriority == '0') { $bugprioritytext = "<td><span class='badge bg-success'>low</span></td>"; }
												else if($bugpriority == '1') { $bugprioritytext = "<td><span class='badge bg-warning'>medium</span></td>"; }
												else if($bugpriority == '2') { $bugprioritytext = "<td><span class='badge bg-danger'>high</span></td>"; }
												
												$bugreportdate = substr($data['reportdate'],0,16);
												$bugcommentcount = $data['bugcommentcount'];
												$buglastcommentdate = $data['buglastcommentdate'];
												
												$buglastcommentdatetext = '';
												if($buglastcommentdate != '') {
													$buglastcommentdate = substr($buglastcommentdate,0,16);
													$buglastcommentdatetext = "<br/> last comment <i>$buglastcommentdate</i>";
												}
												
												$bugstatus = $data['bugstatus'];
												if($bugstatus == 'O') { $bugstatustext = "<td><span class='badge bg-danger'>open</span></td>"; } 
												else if($bugstatus == 'C') { $bugstatustext = "<td><span class='badge bg-success'>close</span></td>"; }
												else if($bugstatus == 'P') { $bugstatustext = "<td><span class='badge bg-warning text-dark'>pending</span></td>"; }
												else if($bugstatus == 'S') { $bugstatustext = "<td><span class='badge bg-dark'>suspend</span></td>"; }
												
												echo "<tr class='buglink' onclick=\"window.open('bugs/view/$bugid', 'form','width=1000,height=700'); return false;\"> 
													<td>
														$bugtitle <b>#$bugid</b> 
														<br/><span class='small'>by <i>$bugcreator</i></span> <span class='small' style='float:right;'>total comment : $bugcommentcount</span>
													</td> 
													$bugstatustext $bugprioritytext 
													<td>
														report at <i>$bugreportdate</i> 
														$buglastcommentdatetext
													</td> 
													</tr>"; 												
											}
										?>
									</tbody>
								</table>
							</div> -->
						</div>
						
					</div>
				</div>
			</div>
			
		</div>
    </div>
</div>
<?= $this->endSection() ?>
<?= $this->section('script') ?>
<script>
$(function () {
	$('#openTable').DataTable({
		"order" : [],
		"pageLength" : 10,
	});
});
$(function () {
	$('#pendingTable').DataTable({
		"order" : [],
		"pageLength" : 10,
	});
});
$(function () {
	$('#closeTable').DataTable({
		"order" : [],
		"pageLength" : 10,
	});
});
$(function () {
	$('#suspendTable').DataTable({
		"order" : [],
		"pageLength" : 10,
	});
});
</script>
<?= $this->endSection() ?>