<div class="row mt-2">
	<div class="col-12">
		<div class="card">
			<div class="card-body">
				<h5 class="card-title text-center">Recent Activity</h5>
				
				<nav>
					<div class="nav nav-tabs" id="nav-tab" role="tablist">
						<button class="nav-link <?php echo '' . (($_SESSION['userposid'] == '1') ? 'active' : '');?>" id="nav-home-tab" data-bs-toggle="tab" data-bs-target="#nav-allActivity" type="button" role="tab" aria-controls="nav-home" aria-selected="true">All Activity</button>
						<button class="nav-link <?php echo '' . (($_SESSION['userposid'] == '2' || $_SESSION['userposid'] == '4') ? 'active' : '');?>" id="nav-profile-tab" data-bs-toggle="tab" data-bs-target="#nav-ivdActivity" type="button" role="tab" aria-controls="nav-profile" aria-selected="false">IVD Activity</button>
						<button class="nav-link <?php echo '' . (($_SESSION['userposid'] == '3' || $_SESSION['userposid'] == '5') ? 'active' : '');?>" id="nav-contact-tab" data-bs-toggle="tab" data-bs-target="#nav-itActivity" type="button" role="tab" aria-controls="nav-contact" aria-selected="false">IT Activity</button>
						<button class="nav-link <?php echo '' . (($_SESSION['userposid'] == '6' || $_SESSION['userposid'] == '14') ? 'active' : '');?>" id="nav-contact-tab" data-bs-toggle="tab" data-bs-target="#nav-psActivity" type="button" role="tab" aria-controls="nav-contact" aria-selected="false">PS Activity</button>
					</div>
				</nav>

				<div class="tab-content" id="nav-tabContent">
					
					<!-- Menampilkan Recent Activity Milik Semua TSO -->
					<div class="tab-pane fade <?php echo '' . (($_SESSION['userposid'] == '1') ? 'show active' : '');?>" id="nav-allActivity" role="tabpanel" tabindex="0">
						<div class="table-responsive">
							<table id="ActivityTable" class="table small display border">
								<thead class="table-info">
									<tr>
										<th>Site</th>
										<th>Product</th>
										<th>Subject</th>
										<th>Status</th>
										<th>Open/Close</th>
										<th>Creator/Owner</th>
									</tr>
								</thead>
								<tbody>
								<?php
									foreach($tampildata as $row) {
										$opendate = $row['opendate'];
										$closedate = $row['closedate'];
										if($opendate != '') { if(substr($opendate,0,10)=='0000-00-00') {$opendate = '';} else { $opendate = substr($opendate,0,16); } }
										if($closedate != '') { if(substr($closedate,0,10)=='0000-00-00') {$closedate = '';} else { $closedate = substr($closedate,0,16); } }
								?>
									<tr>
										<td><?=$row['sitename'];?></td>
										<td>
											<?php 
												if ($row['actby'] == 'P') {
													$row['productname'] != '' ? $row['productname'] = $row['productname'] : $row['productname'] = ' -- ';
													echo ($row['productname']);
												} else if ($row['actby'] == 'V') {
													echo ($row['vendorname'] . " (Vendor)");
												} else if ($row['actby'] == 'C') {
													echo ("Consumable / Reagent");
												} else if ($row['actby'] == 'O') {
													echo ("Other");
												} else {
													echo (" -- ");
												}
											?>
										</td>
										<td><a href="activities/detail/<?= $row['actid']?>" onclick="window.open(this.href, 'Activity Detail','width=900,height=800,toolbar=1,resizable=0'); return false;"><?=$row['subject'];?></a></td>
										<td>
											<?php 
												$activitystatus = $row['activitystatus'];
												if($activitystatus == "O") { echo "<button type='button' class='btn btn-sm btn-dark'>Open</button>"; }
												else if($activitystatus == "C") { echo "<button type='button' class='btn btn-sm btn-danger'>Closed</button>"; }
												else if($activitystatus == "R") { echo "<button type='button' class='btn btn-sm btn-info'>Refer</button>"; }
												else if($activitystatus == "P") { echo "<button type='button' class='btn btn-sm btn-light'>Pending</button>"; }
												else if($activitystatus == "S") { echo "<button type='button' class='btn btn-sm btn-warning'>Suspend</button>"; }
												else if($activitystatus == "D") { echo "<button type='button' class='btn btn-sm btn-secondary'>Disable</button>"; }
											?>
										</td>
										<td>Open : <?= $opendate; ?> <br> Close : <?= $closedate; ?></td>
										<td>Creator : <?= $row['creator_name']; ?> <br> Owner : <?= $row['username']; ?></td>
									</tr>
								<?php
									}
								?>
								</tbody>
							</table>
						</div>
					</div>
					
					<!-- Menampilkan Recent Activity Milik IVD -->
					<div class="tab-pane fade <?php echo '' . (($_SESSION['userposid'] == '2' || $_SESSION['userposid'] == '4') ? 'show active' : '');?>" id="nav-ivdActivity" role="tabpanel" tabindex="0">
						<div class="table-responsive">
							<table id="ivdActivityTable" class="table small display border">
								<thead class="table-info">
									<tr>
										<th>Site</th>
										<th>Product</th>
										<th>Subject</th>
										<th>Status</th>
										<th>Open/Close</th>
										<th>Creator/Owner</th>
									</tr>
								</thead>
								<tbody>
								<?php
									foreach($tampildata as $row) {
										$opendate = $row['opendate'];
										$closedate = $row['closedate'];
										$userposid = $row['userposid'];
										if($opendate != '') { if(substr($opendate,0,10)=='0000-00-00') {$opendate = '';} else { $opendate = substr($opendate,0,16); } }
										if($closedate != '') { if(substr($closedate,0,10)=='0000-00-00') {$closedate = '';} else { $closedate = substr($closedate,0,16); } }

										if ($userposid == '2' || $userposid == '4') {
								?>
									<tr>
										<td><?=$row['sitename'];?></td>
										<td>
											<?php 
												if ($row['actby'] == 'P') {
													$row['productname'] != '' ? $row['productname'] = $row['productname'] : $row['productname'] = ' -- ';
													echo ($row['productname']);
												} else if ($row['actby'] == 'V') {
													echo ($row['vendorname'] . " (Vendor)");
												} else if ($row['actby'] == 'C') {
													echo ("Consumable / Reagent");
												} else if ($row['actby'] == 'O') {
													echo ("Other");
												} else {
													echo (" -- ");
												}
											?>
										</td>
										<td><a href="activities/detail/<?= $row['actid']?>" onclick="window.open(this.href, 'Activity Detail','width=900,height=800,toolbar=1,resizable=0'); return false;"><?=$row['subject'];?></a></td>
										<td>
											<?php 
												$activitystatus = $row['activitystatus'];
												if($activitystatus == "O") { echo "<button type='button' class='btn btn-sm btn-dark'>Open</button>"; }
												else if($activitystatus == "C") { echo "<button type='button' class='btn btn-sm btn-danger'>Closed</button>"; }
												else if($activitystatus == "R") { echo "<button type='button' class='btn btn-sm btn-info'>Refer</button>"; }
												else if($activitystatus == "P") { echo "<button type='button' class='btn btn-sm btn-light'>Pending</button>"; }
												else if($activitystatus == "S") { echo "<button type='button' class='btn btn-sm btn-warning'>Suspend</button>"; }
												else if($activitystatus == "D") { echo "<button type='button' class='btn btn-sm btn-secondary'>Disable</button>"; }
											?>
										</td>
										<td>Open : <?= $opendate; ?> <br> Close : <?= $closedate; ?></td>
										<td>Creator : <?= $row['creator_name']; ?> <br> Owner : <?= $row['username']; ?></td>
									</tr>
								<?php
										}
									}
								?>
								</tbody>
							</table>
						</div>
					</div>

					<!-- Menampilkan Recent Activity Milik IT -->
					<div class="tab-pane fade <?php echo '' . (($_SESSION['userposid'] == '3' || $_SESSION['userposid'] == '5') ? 'show active' : '');?>" id="nav-itActivity" role="tabpanel" tabindex="0">
						<div class="table-responsive">
							<table id="itActivityTable" class="table small display border">
								<thead class="table-info">
									<tr>
										<th>Site</th>
										<th>Product</th>
										<th>Subject</th>
										<th>Status</th>
										<th>Open/Close</th>
										<th>Creator/Owner</th>
									</tr>
								</thead>
								<tbody>
								<?php
									foreach($tampildata as $row) {
										$opendate = $row['opendate'];
										$closedate = $row['closedate'];
										$userposid = $row['userposid'];
										if($opendate != '') { if(substr($opendate,0,10)=='0000-00-00') {$opendate = '';} else { $opendate = substr($opendate,0,16); } }
										if($closedate != '') { if(substr($closedate,0,10)=='0000-00-00') {$closedate = '';} else { $closedate = substr($closedate,0,16); } }
										if ($userposid == '3' || $userposid == '5') {
								?>
									<tr>
										<td><?=$row['sitename'];?></td>
										<td>
											<?php 
												if ($row['actby'] == 'P') {
													$row['productname'] != '' ? $row['productname'] = $row['productname'] : $row['productname'] = ' -- ';
													echo ($row['productname']);
												} else if ($row['actby'] == 'V') {
													echo ($row['vendorname'] . " (Vendor)");
												} else if ($row['actby'] == 'C') {
													echo ("Consumable / Reagent");
												} else if ($row['actby'] == 'O') {
													echo ("Other");
												} else {
													echo (" -- ");
												}
											?>
										</td>
										<td><a href="activities/detail/<?= $row['actid']?>" onclick="window.open(this.href, 'Activity Detail','width=900,height=800,toolbar=1,resizable=0'); return false;"><?=$row['subject'];?></a></td>
										<td>
											<?php 
												$activitystatus = $row['activitystatus'];
												if($activitystatus == "O") { echo "<button type='button' class='btn btn-sm btn-dark'>Open</button>"; }
												else if($activitystatus == "C") { echo "<button type='button' class='btn btn-sm btn-danger'>Closed</button>"; }
												else if($activitystatus == "R") { echo "<button type='button' class='btn btn-sm btn-info'>Refer</button>"; }
												else if($activitystatus == "P") { echo "<button type='button' class='btn btn-sm btn-light'>Pending</button>"; }
												else if($activitystatus == "S") { echo "<button type='button' class='btn btn-sm btn-warning'>Suspend</button>"; }
												else if($activitystatus == "D") { echo "<button type='button' class='btn btn-sm btn-secondary'>Disable</button>"; }
											?>
										</td>
										<td>Open : <?= $opendate; ?> <br> Close : <?= $closedate; ?></td>
										<td>Creator : <?= $row['creator_name']; ?> <br> Owner : <?= $row['username']; ?></td>
									</tr>
								<?php
										}
									}
								?>
								</tbody>
							</table>
						</div>
					</div>

					<!-- Menampilkan Recent Activity Milik Product Specialist -->
					<div class="tab-pane fade <?php echo '' . (($_SESSION['userposid'] == '6' || $_SESSION['userposid'] == '14') ? 'show active' : '');?>" id="nav-psActivity" role="tabpanel" tabindex="0">
						<div class="table-responsive">
							<table id="psActivityTable" class="table small display border">
								<thead class="table-info">
									<tr>
										<th>Site</th>
										<th>Product</th>
										<th>Subject</th>
										<th>Status</th>
										<th>Open/Close</th>
										<th>Creator/Owner</th>
									</tr>
								</thead>
								<tbody>
								<?php
									foreach($tampildata as $row) {
										$opendate = $row['opendate'];
										$closedate = $row['closedate'];
										$userposid = $row['userposid'];
										if($opendate != '') { if(substr($opendate,0,10)=='0000-00-00') {$opendate = '';} else { $opendate = substr($opendate,0,16); } }
										if($closedate != '') { if(substr($closedate,0,10)=='0000-00-00') {$closedate = '';} else { $closedate = substr($closedate,0,16); } }
										if ($userposid >= '6') {
								?>
									<tr>
										<td><?=$row['sitename'];?></td>
										<td>
											<?php 
												if ($row['actby'] == 'P') {
													$row['productname'] != '' ? $row['productname'] = $row['productname'] : $row['productname'] = ' -- ';
													echo ($row['productname']);
												} else if ($row['actby'] == 'V') {
													echo ($row['vendorname'] . " (Vendor)");
												} else if ($row['actby'] == 'C') {
													echo ("Consumable / Reagent");
												} else if ($row['actby'] == 'O') {
													echo ("Other");
												} else {
													echo (" -- ");
												}
											?>
										</td>
										<td><a href="activities/detail/<?= $row['actid']?>" onclick="window.open(this.href, 'Activity Detail','width=900,height=800,toolbar=1,resizable=0'); return false;"><?=$row['subject'];?></a></td>
										<td>
											<?php 
												$activitystatus = $row['activitystatus'];
												if($activitystatus == "O") { echo "<button type='button' class='btn btn-sm btn-dark'>Open</button>"; }
												else if($activitystatus == "C") { echo "<button type='button' class='btn btn-sm btn-danger'>Closed</button>"; }
												else if($activitystatus == "R") { echo "<button type='button' class='btn btn-sm btn-info'>Refer</button>"; }
												else if($activitystatus == "P") { echo "<button type='button' class='btn btn-sm btn-light'>Pending</button>"; }
												else if($activitystatus == "S") { echo "<button type='button' class='btn btn-sm btn-warning'>Suspend</button>"; }
												else if($activitystatus == "D") { echo "<button type='button' class='btn btn-sm btn-secondary'>Disable</button>"; }
											?>
										</td>
										<td>Open : <?= $opendate; ?> <br> Close : <?= $closedate; ?></td>
										<td>Creator : <?= $row['creator_name']; ?> <br> Owner : <?= $row['username']; ?></td>
									</tr>
								<?php
										}
									}
								?>
								</tbody>
							</table>
						</div>
					</div>
					

				</div>

			</div>
		</div>
	</div>
</div>