<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
$_SESSION['cuPages']='prj_projectlist.php';   
$cuPage='prj_projectlist.php';    
$aid=$_SESSION['uid'];
$uty=$_SESSION['utype'];    
$brid=$_SESSION['abrid'];     
}else{
header('Location:../index.php');
exit;    
}
$mhead='project';
$menuh='Manage Project';
$phead='prjlist';
$page='Project Record List';
$dtnow = date("Y-m-d h:i:s", time());
$today = strftime("%Y-%m-%d", time());
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>

<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">

<div class="row">
<div class="col-md-8">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">Project Record</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>    
<div class="col-md-12 table-responsive">
<table class="table table-bordered table-striped" id="datarec">
<thead class="text-uppercase">
<tr>
<th style="width:40px;">SN</th>   
<th>ID</th>    
<th>Name</th>
<th>Sub-Group</th>
<th>Group</th>
<th>Contact</th>
<th>Contractor</th>    
<th>Status</th>    
<th style="width:40px; text-align:center;">Action</th>    
</tr>
</thead>    
<tbody>
<?php
if($brid=='0'){
    $sql="SELECT * FROM tbl_project  ORDER BY name ASC"; 
    }else{
      $sql="SELECT * FROM tbl_project WHERE brid='$brid' ORDER BY name ASC"; 
}    
$query=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($row=mysqli_fetch_array($query)){
$id=$row['id'];
?>
<tr>
<td class="center"><?php echo count_id();?></td>
<td><?php echo $row['prjid'];?></td>    
<td><b class="detailsrec" id="<?php echo 'PO_'.$row['id'];?>" style="cursor: pointer;"><?php  echo $row['name'];?> </b></td>
<td><?php if($row['psgid']!=''){echo get_fild_data('tbl_prosubgroup',$row['psgid'],'name');}?></td>
<td><?php if($row['pgid']!=''){echo get_fild_data('tbl_progroup',$row['pgid'],'name');}?></td>
<td><?php echo show_addres($row['cperson'],$row['cnumber'],'','','','');?></td>
<td><?php if($row['coid']!=''){echo get_fild_data('tbl_contractor',$row['coid'],'name');}?></td>    
<td>
<?php 
if($row['status']=='0'){echo 'Start';}elseif($row['status']=='1'){echo 'On-Process';}elseif($row['status']=='3'){echo 'Apply';}elseif($row['status']=='4'){echo 'Reject';}else{echo 'Done';}    
?>    
</td>
<td nowrap="">
<a class="btn btn-flat bg-purple" href="#" onclick="edit_item('ED_<?php echo $row['id'];?>')"><i class="fa fa-edit"></i></a> 
<a class="btn btn-flat bg-purple" href="#" onclick="remove_item('DL_<?php echo $row['id'];?>')"><i class="fa fa-trash"></i></a>
<form action="prj_projectlist.php" id="DL_<?php echo $row['id'];?>" method="post" >
<input type="hidden" name="delprj" value="<?php echo $row['id']; ?>" />
</form>
<form action="prj_projectedit.php" id="ED_<?php echo $row['id'];?>" method="post" >
<input type="hidden" name="editprj" value="<?php echo $row['id']; ?>" />
</form>     
</td>    
</tr>    
<?php } ?>    
</tbody>   
</table>
</div>
<div class="clearfix" ></div>  
<div class="row"style="margin-top: 15px" >
<div class="col-md-12 table-responsive">    
<div class="col-md-8"></div>
<div class="col-md-4 text-right" >
<a href="prj_projectcteate.php" class="btn btn-flat bg-purple">Add Project</a>
</div>
</div>    
</div>    
</div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-12">
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">History </h3>
</div>
<!-- /.box-header -->
<div class="box-body" >
<?php if($_SESSION['utype']=='1'){echo read_activity($aid,'PRJ','A');}else{echo read_activity($aid,'PRJ','U');}?>
</div>
</div>
</div>
</div>
</div>
</div> 
        
<?php include('../layout/quick.php');?>    
</section>
<!-- /.main content -->    
<?php include('../layout/details.php'); ?>   
</div>
<?php
include('../layout/footer.php');
?>
<!-- page script -->
<script type="text/javascript">
$(document).ready(function() {    
$('#datarec').DataTable({stateSave: true});
});
function edit_item(id) {
document.getElementById(id).submit(); 
}
    
function remove_item(id) {
bootbox.confirm({
title: "Confirm",
message: "Are you sure to delete ?",
buttons: {
confirm: {
label: 'Yes',
className: 'btn-flat bg-purple'
},
cancel: {
label: 'Cancel',
className: 'btn-flat bg-gray'
}
},
callback: function (result) {
if (result == true) {
document.getElementById(id).submit();
}
}
});

} 
$(document).on('click', '.detailsrec', function(e) {    
id_arr = $(this).attr('id');
id = id_arr.split("_");
if(id[1]==0)return;
$.ajax({
url: 'axe_prjdetails.php',
method: "POST",
data:{ 
cusdet: 1,cusid: id[1],type:id[0]
},
success: function(data){
$('#profile').html(data);    
}
});    
    
$.ajax({
url: 'axe_prjdetails.php',
method: "POST",
data:{ 
tradet: 1,cusid: id[1],type:id[0]
},
success: function(data){
$('#details').html(data);   
}
});    
    
$('.right-side-details').toggle('slide', { direction: 'right' }, 300);    
e.preventDefault();    
});
    
$(document).on('click', '#closedet', function() {
$('#profile').html('');
$('#details').html('');    
if($('.right-side-details').is(':visible')) {
$('.right-side-details').toggle('slide', { direction: 'right' }, 300);
}    
});    
</script>    
<!-- /page script -->
</html>    