<?php if(isset($_SESSION['successMsg'])){?>
	<div class="alert alert-success" role="alert"><?php echo $_SESSION['successMsg']; unset($_SESSION['successMsg']);?></div>
<?php }?>

<?php if(isset($_SESSION['errorMsg'])){?>
    <div class="alert alert-danger" role="alert"><?php echo $_SESSION['errorMsg']; unset($_SESSION['errorMsg']);?></div>
<?php }?>
<style>
.btn-sm, .btn-group-sm > .btn {
    padding: 0px 5px;
    font-size: 0.875rem;
    line-height: 1.5;
    border-radius: 0.1875rem;
}
.table td, .table th {
    padding:1px 1px;
	vertical-align: middle;
    font-size: 11px;
    line-height: 1;
    white-space: nowrap;
}
.btn i {
    margin-right: 0px;
}
.content-wrapper {
    background: #f2f8f9;
    padding: 0px;
    width: 100%;
    -webkit-flex-grow: 1;
    flex-grow: 1;
}
.page-body-wrapper:not(.auth-page) {
    padding-top: 50px;
}
</style>
<div class="col-lg-12 grid-margin stretch-card">	                
    <div class="card">    
        <div class="card-body">
        	
            <div class="text-center ActionBox" style="position:fixed;top:110px;width:calc(100% - 21%);z-index: 999;display:none;">            	
                <button type="button" class="btn btn-success btn-fw verifyQuestion"><i class="mdi mdi-check"></i> Verify</button>
                <button type="button" class="btn btn-danger btn-fw deleteQuestion"><i class="mdi mdi-alert-outline"></i>Delete</button>            
            </div>
                    		    		    	        
            <h4 class="card-title">Verify Upload SH List</h4>                   
            <div class="table-responsive">
                <table class="table datatable-sorting" id="myTable">
                    <thead>
                        <tr>                            
                            <th>STATE</th>
                            <th>SH CODE</th>
                            <th>SH NAME</th>
                            <th>ASM CODE</th>
                            <th>ASM NAME</th>
                            <th>DS CODE</th>
                            <th>DS NAME</th>
                            <th>SALES DISTRICT</th>                     
                            <th style="text-align:center;">Action</th>                                           
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                    if (isset($_GET['page_no']) && $_GET['page_no']!="") {
                        $page_no = $_GET['page_no'];
                    } else {
                        $page_no = 1;
                    }
                    $list_qry       = "select * from `tbl_sh` where `status`=1";
                    $total_records_per_page = 100;
                    $offset = ($page_no-1) * $total_records_per_page;
                    $previous_page = $page_no - 1;
                    $next_page = $page_no + 1;
                    $adjacents = "2"; 
                    
                    $result_count = mysqli_query($cn,$list_qry);
                    $total_records = mysqli_num_rows($result_count);
                    $total_no_of_pages = ceil($total_records / $total_records_per_page);
                    $second_last = $total_no_of_pages - 1; // total page minus 1
                    $list_qry  .= " LIMIT $offset, $total_records_per_page ";		
                    $sqlQuestion = mysqli_query($cn,$list_qry);			
                    while($sqlQuestionData = mysqli_fetch_array($sqlQuestion))
                    {								
                        ?>
                        <tr>                            
                            <td><?php echo $sqlQuestionData['state'];?></td>
                            <td><?php echo $sqlQuestionData['sh_code'];?></td>
                            <td><?php echo $sqlQuestionData['sh_name'];?></td>
                            <td><?php echo $sqlQuestionData['asm_code'];?></td>
                            <td><?php echo $sqlQuestionData['asm_name'];?></td>
                            <td><?php echo $sqlQuestionData['ds_code'];?></td>
                            <td><?php echo $sqlQuestionData['ds_name'];?></td>
                            <td><?php echo $sqlQuestionData['district'];?></td>                        
                            <td style="text-align:center;"><a href="home.php?pages=addSH&edit_id=<?php echo $sqlQuestionData['id'];?>" class="btn btn-outline-success btn-sm"><i class="mdi mdi-pencil"></i></a></td> 
                        </tr>
                    <?php }?>    
                    </tbody>
                </table>

                <?php if($total_no_of_pages>0){?>
                <div class="botoom-number">
                    <ul class="pagination realestate-pagination">                            
                        <li <?php if($page_no <= 1){ echo "class='disabled'"; } ?>>
                        <a <?php if($page_no > 1){ echo "href='home.php?pages=viewPendingSH&page_no=$previous_page'"; } ?>>Previous</a>
                        </li>
                           
                        <?php 
                        if($total_no_of_pages <= 10){  	 
                            for ($counter = 1; $counter <= $total_no_of_pages; $counter++){
                                if ($counter == $page_no) {
                               echo "<li><a class='active'>$counter</a></li>";	
                                    }else{
                               echo "<li><a href='home.php?pages=viewPendingSH&page_no=$counter'>$counter</a></li>";
                                    }
                            }
                        }
                        elseif($total_no_of_pages > 10){
                            
                        if($page_no <= 4) {			
                         for ($counter = 1; $counter < 8; $counter++){		 
                                if ($counter == $page_no) {
                               echo "<li><a class='active'>$counter</a></li>";	
                                    }else{
                               echo "<li><a href='home.php?pages=viewPendingSH&page_no=$counter'>$counter</a></li>";
                                    }
                            }
                            echo "<li><a>...</a></li>";
                            echo "<li><a href='home.php?pages=viewPendingSH&page_no=$second_last'>$second_last</a></li>";
                            echo "<li><a href='home.php?pages=viewPendingSH&page_no=$total_no_of_pages'>$total_no_of_pages</a></li>";
                            }
                    
                         elseif($page_no > 4 && $page_no < $total_no_of_pages - 4) {		 
                            echo "<li><a href='home.php?pages=viewPendingSH&page_no=1'>1</a></li>";
                            echo "<li><a href='home.php?pages=viewPendingSH&page_no=2'>2</a></li>";
                            echo "<li><a>...</a></li>";
                            for ($counter = $page_no - $adjacents; $counter <= $page_no + $adjacents; $counter++) {			
                               if ($counter == $page_no) {
                               echo "<li><a class='active'>$counter</a></li>";	
                                    }else{
                               echo "<li><a href='home.php?pages=viewPendingSH&page_no=$counter'>$counter</a></li>";
                                    }                  
                           }
                           echo "<li><a>...</a></li>";
                           echo "<li><a href='home.php?pages=viewPendingSH&page_no=$second_last'>$second_last</a></li>";
                           echo "<li><a href='home.php?pages=viewPendingSH&page_no=$total_no_of_pages'>$total_no_of_pages</a></li>";      
                                }
                            
                            else {
                            echo "<li><a href='home.php?pages=viewPendingSH&page_no=1'>1</a></li>";
                            echo "<li><a href='home.php?pages=viewPendingSH&page_no=2'>2</a></li>";
                            echo "<li><a>...</a></li>";
                    
                            for ($counter = $total_no_of_pages - 6; $counter <= $total_no_of_pages; $counter++) {
                              if ($counter == $page_no) {
                               echo "<li><a class='active'>$counter</a></li>";	
                                    }else{
                               echo "<li><a href='home.php?pages=viewPendingSH&page_no=$counter'>$counter</a></li>";
                                    }                   
                                    }
                                }
                        }
                    ?>
                        
                        <li <?php if($page_no >= $total_no_of_pages){ echo "class='disabled'"; } ?>>
                        <a <?php if($page_no < $total_no_of_pages) { echo "href='home.php?pages=viewPendingSH&page_no=$next_page'"; } ?>>Next</a>
                        </li>
                        <?php if($page_no < $total_no_of_pages){
                            echo "<li><a href='home.php?pages=viewPendingSH&page_no=$total_no_of_pages'>Last &rsaquo;&rsaquo;</a></li>";
                            } ?>
                    </ul>
                </div>
                <br />
            	<?php }?>
            </div>
        </div>
    </div>
</div>    
