<?php
	
	if(!isset($_SESSION['login_user'])){
		header('location: ../../../login.php'); // Mengarahkan ke Home Page
	}

	if(isset($_SESSION['jabatan']) AND $_SESSION['jabatan'] <> 'TRUE')
	{
		?>
		  <div class="alert alert-danger alert-dismissible" id="succsess-alert">
	        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
	        <h4><i class="icon fa fa-ban"></i> Alert!</h4>
	        Dilarang mengakses file ini.
	      </div>
		<?php
	}
	else{
	//link buat paging
	$linkaksi = 'med.php?mod=jabatan';

	if(isset($_GET['act']))
	{
		$act = $_GET['act'];
		$linkaksi .= '&act='.$act;
	}
	else
	{
		$act = '';
	}

	$aksi = 'mod/data_master/jabatan/act_jabatan.php';

	?>
	<?php
	switch ($act) {
		case 'form':
			if(!empty($_GET['id']))
			{
				$act = "$aksi?mod=jabatan&act=edit&idmx=".$_GET['idmx'];
				$query = mysqli_query($conn,"SELECT * FROM tb_jabatan WHERE id = '$_GET[id]'");
				$temukan = mysqli_num_rows($query);
				if($temukan > 0)
				{
					$c = mysqli_fetch_assoc($query);
				}
				else
				{
					header("location:med.php?mod=jabatan&idmx=".$_GET['idmx']);
				}

			}
			else
			{
				$act = "$aksi?mod=jabatan&act=simpan&idmx=".$_GET['idmx'];
			}
			?>
            <div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
				<div class="breadcrumb-title pe-3">Data Master</div>
				<div class="ps-3">
					<nav aria-label="breadcrumb">
						<ol class="breadcrumb mb-0 p-0">
							<li class="breadcrumb-item"><a href="javascript:;"><i class="bx bx-home-alt"></i></a>
							</li>
							<li class="breadcrumb-item active" aria-current="page">Form <?php echo ucwords($title) ?></li>
						</ol>
					</nav>
				</div>
			</div>
            <?php
	        flash('example_message');
	        ?>
            <div class="row">
                <div class="col-lg-12">
                    <div class="card ">
                        <div class="card-header bg-primary text-center">
                            <h4 class="m-b-0 text-white">Form <?php echo ucwords($title) ?></h4>
                        </div>

				    	<form class="form-horizontal" role="form" method='POST' action='<?php echo $act ?>' enctype="multipart/form-data">
				    		<div class="card-body">
					    		<input type="hidden" name="id" value="<?php echo isset($c['id']) ? $c['id'] : '' ;?>">
		                    	
				            	<div class="row mb-3">
			                        <label for="inputEmail1" class="col-lg-2 col-sm-2 col-form-label">Nama</label>
			                        <div class="col-lg-10">
			                            <input type="text" name="nama" class="form-control " value="<?php echo isset($c['nama']) ? $c['nama'] : '' ;?>" required>
			                        </div>
			                    </div>
			                    <div class="row mb-3">
			                        <label for="inputEmail1" class="col-lg-2 col-sm-2 col-form-label">Keterangan</label>
			                        <div class="col-lg-10">
			                        	<textarea  class="form-control" name="keterangan" rows="3"><?php echo isset($c['keterangan']) ? $c['keterangan'] : '';?></textarea>
			                        </div>
			                    </div>
			                    <div class="row mb-3">
			                      <label class="col-lg-2 col-sm-2 col-form-label">Status</label>
			                      <div class="col-lg-10">
			                          <select name="status" class="form-control" style="width: 100%">
			                          	  <option value="<?php echo isset($c['status']) ? $c['status'] : 'Pilih Status' ;?>"><?php echo isset($c['status']) ? $c['status'] : 'Pilih Status' ;?></option>
			                              <option value="active">active</option>
			                              <option value="inactive">inactive</option>
			                          </select>
			                      	</div>
			                  	</div>
					    		<hr>
                                <div class="d-flex align-items-center justify-content-between">
						         	<button type="submit" name="submit" value="simpan" class="btn btn-success"><i class='fa fa-save'></i> Simpan</button>
									<button type="button" name="submit" onclick="history.back()" class="btn btn-dark"><i class='fa fa-rotate-left'></i> Kembali</button>
						        </div>
					    	</div>
				    	</form>
				    </div>
				</div>
			</div>

			<?php
		break;

		default :
			?>
			  <!--breadcrumb-->
              <div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
                <div class="breadcrumb-title pe-3">Data Master</div>
                <div class="ps-3">
                  <nav aria-label="breadcrumb">
                    <ol class="breadcrumb mb-0 p-0">
                      <li class="breadcrumb-item"><a href="javascript:;"><i class="bx bx-home-alt"></i></a>
                      </li>
                      <li class="breadcrumb-item active" aria-current="page">Data <?php echo ucwords($title) ?></li>
                    </ol>
                  </nav>
                </div>
                <div class="ms-auto">
                    <?php
						$qmn = "SELECT * FROM tb_group_menu WHERE `kode_group` = '$level_check' AND id_menu='$_GET[idmx]'";
						$sqqmn = mysqli_query($conn,$qmn);	
						$mn = mysqli_fetch_assoc($sqqmn);
						if ($mn['insert']=="Aktif") {
						?>	
						<a href="med.php?mod=jabatan&act=form&idmx=<?php echo $mn['id_menu'] ?>">
                            <button class="btn btn-primary px-4"><i class="bi bi-plus-lg me-2"></i>Add Product</button>
						</a>
					<?php }?>
                </div>
              </div>
              <!--end breadcrumb-->
                <?php
    	        flash('example_message');
    	        ?>
        
              <div class="card mt-4">
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="example" class="table table-striped table-hover align-middle">
							<thead>
              					<tr>
									<th class="text-center">No</th>
									<th class="text-center">Nama</th>
									<th class="text-center">Keterangan</th>
									<th class="text-center">Status</th>
									
									<?php if($mn['update']=="Aktif" OR $mn['view']=="Aktif" OR $mn['delete']=="Aktif"){?>
                  					<th class="text-center">Aksi</th>
                  					<?php } ?>
								</tr>
		                  	</thead>
		                  	<tbody>
                			<?php
								$query = "SELECT * FROM `tb_jabatan`";
								$sql_kul = mysqli_query($conn,$query);	
								$i=1;
								while ($m = mysqli_fetch_assoc($sql_kul)) {										
						    		$nama = $m['nama'];
									
							?>
		                        <tr class="">
		                            <td align="center"><?php echo $i ?></td>
		                            <td align=""><?php echo $nama ?></td>	                                    
		                            <td align=""><?php echo $m['keterangan']?></td>	                                    
		                            
		                            <td align="center">
		                            	<?php 
		                            	if ($m['status']=='active') {
		                            	?>
		                            	    <span class="lable-table bg-success-subtle text-success rounded border border-success-subtle font-text2 fw-bold">Active<i class="bi bi-check2 ms-2"></i></span>
        									
		                            	<?php
		                            	}else{
		                            	?>
        									<span class="lable-table bg-danger-subtle text-danger rounded border border-danger-subtle font-text2 fw-bold">Inactive<i class="bi bi-x-lg ms-2"></i></span>
		                            	<?php
		                            	}

		                            	?>
		                            		
		                            </td>
		                            
									<?php if($mn['update']=="Aktif" OR $mn['view']=="Aktif" OR $mn['delete']=="Aktif"){?>
									<td align="center">
    	   								<div class="btn-group" role="group" aria-label="Aksi">
                                            <?php if ($mn['update'] == "Aktif") { ?>					
                                                <a href="med.php?mod=jabatan&act=form&id=<?php echo $m['id']; ?>&idmx=<?php echo $mn['id_menu']; ?>" 
                                                   class="btn btn-outline-success btn-sm" 
                                                   title="Edit Data">
                                                    <i class="material-icons-outlined">edit</i>
                                                </a>
                                            <?php } ?>
                                        
                                            <?php if ($mn['delete'] == "Aktif") { ?>		
                                                <button type="button" 
                                                        class="btn btn-outline-danger btn-sm btn-hapus" 
                                                        data-url="<?php echo $aksi; ?>?mod=jabatan&act=hapus&id=<?php echo $m['id']; ?>&idmx=<?php echo $mn['id_menu']; ?>" 
                                                        title="Hapus Data">
                                                    <i class="material-icons-outlined">close</i>
                                                </button>
                                            <?php } ?>
                                        </div>
                                
									</td>
									<?php } ?>
                				</tr>
			
                				<?php
									 $i++;
								 }
								?>
            				</tbody>
							<tfoot>
								<tr>
									<th class="text-center">No</th>
									<th class="text-center">Nama</th>
									<th class="text-center">Keterangan</th>
									<th class="text-center">Status</th>
									
									<?php if($mn['update']=="Aktif" OR $mn['view']=="Aktif" OR $mn['delete']=="Aktif"){?>
                  					<th class="text-center">Aksi</th>
                  					<?php } ?>
								</tr>
							</tfoot>
						</table>
						</div>
                </div>
              </div>

			<?php
		break;
	}

	}
?>


