<?php 
 ####### UPDATE START STATUS#######
 if(isset($_POST['wkstste'])){
    try{
        $wkstste=$_REQUEST['wkstste'];
        $projcid=$_REQUEST['projcid'];
        $sql = $db->query("UPDATE `tbl_projects` SET `wrk_state` = '$wkstste',prjsts=12 WHERE `projid` = '$projcid'");
        $msg = "Updated Successfully";
        
    }catch(PDOException $e){
        echo $e->getMessage();
    }
}

?>

<div class="card mb-g border shadow-0">
    <div class="card-header bg-white p-0 header">
        <div class="p-3 d-flex flex-row">
            <div class="d-block ml-2">
                <span class="h6 font-weight-bold text-uppercase d-block m-0">
                    <?php echo $title;?> 
                </span>
                <div class="clearfix"></div>  
            </div>
        </div>
    </div>

    <div class="card-body">
     <br>
                 
        <table id="dt-basic-example" class="table table-hover table-striped w-100"  style="font-size: 11px;">
            <thead class="header">
                <tr>
                    <th style="font-weight: bold;"></th>
                    <th style="font-weight: bold;">CODE</th>
                    <th style="font-weight: bold;">PROJECT</th>
                    <th style="font-weight: bold;">AGREEMENT/WORK ORDER N<sup>o</sup></th>
                    <th style="font-weight: bold;">SIGNED DATE</th>
                    <th style="font-weight: bold;">STARTED DATE</th>
                    <th style="font-weight: bold;">DURATION</th>
                    <th style="font-weight: bold;">WORK STATE</th>
                    <th class="text-center" style="font-weight: bold;">COMPLETED DATE</th>
                </tr>
            </thead>
            
            <tbody>
                <?php 
                    $n=0;
                    $sth = $db->prepare('SELECT *FROM tbl_projects p
                    INNER JOIN tbl_clients c ON c.ct_id=p.clnt 
                    WHERE prjsts=10
                    ORDER BY projid DESC');
                    $sth->execute();
                    while($getp = $sth->fetch()){
                    $projid = $getp['projid'];
                    $wrkp = $getp['wps'];
                    $process = $getp['prces'];
                    $n++;

                    $wrk_state=$getp['wrk_state'];
                    if($wrk_state == 0){
                        $icon='<i class="fa fa-check" aria-hidden="true"></i>';
                        $btn='btn-success';
                        $statee='Work Ourselves';
                    }elseif($wrk_state == 1){
                        $icon='<i class="fa fa-exclamation-circle" aria-hidden="true"></i>';
                        $btn='btn-warning';
                        $statee='Subcontracting';
                    }else{
                        $icon='<i class="fa fa-folder-open" aria-hidden="true"></i>';
                        $btn='btn-default';
                        $statee='Other';
                    }
                  
                ?>
                
                    <tr class="beam-dir" href="gate?b=cptebox&pID=<?php echo $projid;?>" style="cursor: pointer;">
                        <td><i class="fa fa-share" aria-hidden="true"></i></td>
                        <td><?php echo $getp['codeproj'];?></td>
                        <td><?php echo $getp['projname'];?></td>
                        <td><?php echo $getp['aggreno'];?></td>
                        <td><?php echo date('d/m/Y', strtotime($getp['signdate']));?></td>
                        <td><?php echo date('d/m/Y', strtotime($getp['startDue']));?></td>
                        <td><i style="color: #596d43"><?php echo $getp['durat']." Month(s)";?></i></td>                        
                        <td>
                            <label class="btn <?php echo $btn;?> btn-xs" style="font-weight: bold;"><?php echo  $icon." ".$statee;?></label>
                        </td>

                        <td class="text-center"><?php echo date('d/m/Y', strtotime($getp['cptetrm']));?></td>
                    </tr>
                <?php
                }
                ?>
            </tfoot>
        </table>

    </div>
</div>

<script>
    $(document).ready(function(){
    $('.beam-dir').click(function(){
        window.location = $(this).attr('href');
        return false;
        });
    });
</script>