<?php
include "include/db.php";
include "include/adminauth.php";
include "header.php";



if(isset($_REQUEST['delete'])){
    if(strlen($_REQUEST['delete'])> 0){
       $prop_id = $_REQUEST['delete'];
       $prop_case_num = $_REQUEST['prop_case_num'];
       $query_prop_insert = "UPDATE prop_assign SET is_delete = 1 WHERE prop_id = $prop_id";  
    
       $run_prop_insert = mysqli_query($conn, $query_prop_insert);
       if(mysqli_affected_rows($conn) > 0){
           $successmessage = "$prop_case_num has been Disabled from further use in the system.";
   
       }else{
           $message = "Something went wrong. Try Again";
       }     
       

    }
}

?>
<div id="page-wrapper">
<h3>Client Property Details</h3>                                                     
               <?php if(isset($successmessage)){
                    echo '<div class="alert alert-success">
                    <strong>'. $successmessage .'</strong></div>';
                } 
                if(isset($message)){
                    echo '<div class="alert alert-danger">
                    <strong>'. $message .'</strong>
                  </div>';
                }?> 

<div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
            <div class="panel-body">

                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwizzz">
                                    <thead>
                                        <tr>
                                        
                                                <th>
                                                Case/Loan Number
                                                </th>
                                                <th>
                                                Address
                                                 </th>                                            
                                                <th>
                                               County
                                                </th>                                               
                                                
                                                <th>
                                                 View Details
                                                </th>
                                                <th>
                                                 Edit
                                                </th>
                                            <th>Disable / Enable</th>
                                           
                                        </tr>
                                        </thead>
                                        <tbody>
<?php
    if($conn){
        $query = "SELECT * FROM property ORDER BY prop_county";
        $run = mysqli_query($conn, $query);

        if($run){
            while($row = mysqli_fetch_array($run)){
                $prop_id = $row['prop_id'];
                $prop_full_add = $row['prop_full_add']; 
                $prop_case_num = $row['prop_case_num'];       

               
                $prop_county = $row['prop_county'];       
                
                $is_delete = $row['is_delete'];  
    
                echo '<tr class="odd gradeX">';
                echo '<td>' .$prop_case_num. '</td>';
                echo '<td>' .$prop_full_add. '</td>';
                echo '<td>' .$prop_county. '</td>';              
                


                echo "<td><a href='property.php?view=$prop_id'>View</a> </td>";
                echo "<td><a href='property.php?edit=$prop_id'>Edit</a> </td>";              
                if($is_delete == NULL){
                echo "<td><a href='property.php?delete=$prop_id&prop_case_num=$prop_case_num' class=\"delete\" data-confirm=\"Are you sure to disable $prop_case_num?\">Deactivate</a> </td>";
                }else{
                    echo "<td><a href='property.php?active=$prop_id&prop_case_num=$prop_case_num' class=\"delete\" data-confirm=\"Are you sure to activate $prop_case_num?\">Activate</a> </td>";
                }
                echo '</tr>';
            }
        }

    }

?>
                                            
                                            </tbody>
                                    
                                    </table>
                                    
                                    </div><!-- panel-body  -->
                 </div> <!-- panel panel-default -->
            </div> <!--  col lg 12-->
        </div> <!-- row -->


</div> <!--  page wrapper -->
<?php  include "footer.php";   ?>