<?php

if (session_status() === PHP_SESSION_NONE) session_start();
if (!isset($_SESSION['reid'])) header('location:index.php');

require_once("../dashboard/conn.php");

require_once '../dashboard/dbconfig4.php';

if(isset($_SESSION['reid'])){

	$user_qury=mysqli_query($conn,"SELECT * FROM ormsregister WHERE reid='$_SESSION[reid]'");

	$user_resalt=mysqli_fetch_array($user_qury);

	$customer = $user_resalt['reid'];
	
	$addbycustomer = $user_resalt['userid'];
	
	$userbalance = number_format((float)$user_resalt['balance'],2);
	
	$sellertype2 = $user_resalt['sellertype'];
	
	if($user_resalt['image']==""){

		$image_path="../dashboard/images/empty.jpg";

	}

	else{

		$image_path="../dashboard/images/sellers/".$user_resalt['image'];

	}

}

   
?>
<!DOCTYPE html>
<html lang="en">

<head>
	
	<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>All Resellers | Recharge and Billing System | ORMS | Dashbaord</title>
    <?php
	require_once 'headercss.php';
	?>

</head>

<body>

    <!--**********************************
        Main wrapper start
    ***********************************-->
    <div id="main-wrapper">

    <?php
	require_once 'header.php';
	?>

        <!--**********************************
            Sidebar start
        ***********************************-->
        <div class="deznav">
            <div class="deznav-scroll">
	<?php

	require_once 'sidebarmenu.php';

	?>
            </div>
        </div>
        <!--**********************************
            Sidebar end
        ***********************************-->
		
        <!--**********************************
            Content body start
        ***********************************-->
        <div class="content-body">
            <!-- row -->
            <div class="container-fluid">
				<div class="row">
				<div class="col-xl-12 col-xxl-12 col-sm-12">
				<div class="alert alert-danger bg-danger text-white" role="alert">
				<strong>Alert!</strong> ඔබගේ ගිනුම තහවුරු කිරීම අසම්පුර්නයි.<a href="identity_verify.php" class="btn btn-success float-right" style="background-color:#0847cb;font-weight:bold;font-size:18px;color:#ffffff;padding:4px 4px;">සම්පුර්න කරන්න</a>
				</div>
				</div>
				</div>    
                <div class="row page-titles mx-0">
                    <div class="col-sm-6 p-md-0">
                        <div class="welcome-text">
                            <h4>All Resellers</h4>
                        </div>
                    </div>
                    <div class="col-sm-6 p-md-0 justify-content-sm-end mt-2 mt-sm-0 d-flex">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="home.php">Home</a></li>
                            <li class="breadcrumb-item active"><a href="javascript:void(0);">Resellers</a></li>
                            <li class="breadcrumb-item active"><a href="javascript:void(0);">All Resellers</a></li>
                        </ol>
                    </div>
                </div>
				
				<div class="row">
					<div class="col-lg-12">
						<div class="row tab-content">
							<div id="list-view" class="tab-pane fade active show col-lg-12">
								<div class="card">
									<div class="card-header">
										<h4 class="card-title">All Resellers</h4>
										<a href="add_customers.php" class="btn btn-square btn-secondary">+ Add Resellers</a>
									</div>
									<div class="card-body">
										<div class="table-responsive">
											<table id="example" class="table table-bordered">
												<thead>
													<tr>
														<th>ID</th>						
														<th>Action</th>
														<th>Status</th>
														<th>Seller Name</th>
														<th>Seller Username</th>
														<th>Seller Mobile Number</th>
														<th>Seller Roll</th>
														<th>Credit</th>
														<th>Date</th>
													</tr>
												</thead>
												<tbody>
								<?php

								$stmt = $DB_con->prepare('SELECT * FROM ormsregister where userid="'.$customer.'" and usertype="Seller" and selltype="'.$sellertype2.'" ORDER BY reid DESC');

								$stmt->execute();

								if($stmt->rowCount() > 0)

								{

								while($row=$stmt->fetch(PDO::FETCH_ASSOC))

								{

								extract($row);

								?>
													<tr>
														<td><?php echo $row['reid']; ?></td>
														<td>
														<?php 
                            if($sellertype2 == "1"){
							?>                           

                            <a class="btn btn-sm btn-primary" href="edit_customers.php?reid=<?php echo $row["reid"]; ?>" onClick="return confirm('Are youe sure edit this customer');"><i class="la la-edit"></i></a>
							<a class="btn btn-sm btn-danger" href="delete_customers.php?reid=<?php echo $row["reid"]; ?>" onClick="return confirm('Are youe sure remove this customer');"><i class="la la-trash-o"></i></a>
							<a class="btn btn-sm btn-dark" href="change_customers_password.php?change=<?php echo $row["reid"]; ?>" onClick="return confirm('Are youe sure change password this customer');"><i class="la la-shield"></i></a>
														
                            <?php 
							
                            }else if($sellertype2 == "2"){
							?> 
							
							<a class="btn btn-sm btn-primary" href="edit_customers.php?reid=<?php echo $row["reid"]; ?>" onClick="return confirm('Are youe sure edit this customer');"><i class="la la-edit"></i></a>
							<a class="btn btn-sm btn-danger" href="delete_customers.php?reid=<?php echo $row["reid"]; ?>" onClick="return confirm('Are youe sure remove this customer');"><i class="la la-trash-o"></i></a>
							<a class="btn btn-sm btn-dark" href="change_customers_password.php?change=<?php echo $row["reid"]; ?>" onClick="return confirm('Are youe sure change password this customer');"><i class="la la-shield"></i></a>
							<?php 
							
                            }else if($sellertype2 == "3"){
							?> 
							
							<a class="btn btn-sm btn-primary" href="edit_customers.php?reid=<?php echo $row["reid"]; ?>" onClick="return confirm('Are youe sure edit this customer');"><i class="la la-edit"></i></a>
							<a class="btn btn-sm btn-danger" href="delete_customers.php?reid=<?php echo $row["reid"]; ?>" onClick="return confirm('Are youe sure remove this customer');"><i class="la la-trash-o"></i></a>
							<a class="btn btn-sm btn-dark" href="change_customers_password.php?change=<?php echo $row["reid"]; ?>" onClick="return confirm('Are youe sure change password this customer');"><i class="la la-shield"></i></a>
							<?php 
							
                            }else if($sellertype2 == "4"){
							?> 
							
							<a class="btn btn-sm btn-primary" href="edit_customers.php?reid=<?php echo $row["reid"]; ?>" onClick="return confirm('Are youe sure edit this customer');"><i class="la la-edit"></i></a>
							<a class="btn btn-sm btn-danger" href="delete_customers.php?reid=<?php echo $row["reid"]; ?>" onClick="return confirm('Are youe sure remove this customer');"><i class="la la-trash-o"></i></a>
							<a class="btn btn-sm btn-dark" href="change_customers_password.php?change=<?php echo $row["reid"]; ?>" onClick="return confirm('Are youe sure change password this customer');"><i class="la la-shield"></i></a>
														
							<?php 
                            }else if($sellertype2 == "5"){
							?>
							<a href="#" class="badge badge-primary">No Permission</a>
                                                   
							<?php 
                            }

                            ?>
														
														</td>
														<td>
														<?php 
						
														if($row['status'] == "0"){

														echo '<button class="btn btn-primary btn-sm">Deactive</button>';

														}else if($row['status'] == "1"){

														echo '<button class="btn btn-success btn-sm">Active</button>';

														}
						
														?>
														</td>
														<td><p class="btn btn-primary btn-sm"><strong><?php echo $row['title']; ?>. <?php echo $row['fname']; ?> <?php echo $row['lname']; ?></strong></p></td>
														<td><p class="btn btn-danger btn-sm"><strong><?php echo $row['username']; ?></strong></p></td>
														<td><p class="btn btn-dark btn-sm"><strong>0<?php echo $row['mobilenumber']; ?></strong></p></td>
														<td>
														<p>
														<strong>
														<?php 
						
														if($row['sellertype'] == "1"){

														echo '<button class="btn btn-primary btn-sm">Admin</button>';

														}else if($row['sellertype'] == "2"){

														echo '<button class="btn btn-primary btn-sm">Master</button>';

														}else if($row['sellertype'] == "3"){

														echo '<button class="btn btn-primary btn-sm">Manager</button>';

														}else if($row['sellertype'] == "4"){

														echo '<button class="btn btn-primary btn-sm">Distributor</button>';

														}else if($row['sellertype'] == "5"){

														echo '<button class="btn btn-primary btn-sm">Retailer</button>';

														}
						
														?>
														</strong>
														</p>
														</td>
														<td>
														
														
														<?php 
                            if($sellertype2 == "1"){
							?>                           
														<?php 
						
														if($row['creditadd'] == "0"){
															
														?>
														<button class="btn btn-primary btn-sm" id="btn1">Disabled</button>
														<?php 
														
														}else if($row['status'] == "1"){
														
														?>
														<a class="btn btn-sm btn-danger" href="add_credit.php?reid=<?php echo $row["reid"]; ?>"><i class="la la-plus"></i></a>	
														<button class="btn btn-primary btn-sm" id="btn1">Disabled</button>
														<button class="btn btn-success btn-sm" id="btn2">Enabled</button>
														<?php 
														}
						
														?>
														<hr>
														<h4 style="display:none;">Rs.<?php echo number_format((float)$row['balance'],2); ?> </h4>
														
                            <?php 
							
                            }else if($sellertype2 == "2"){
							?> 
							<?php 
						
														if($row['creditadd'] == "0"){
															
														?>
														<button class="btn btn-primary btn-sm" id="btn1">Disabled</button>
														<?php 
														
														}else if($row['status'] == "1"){
														
														?>
														<a class="btn btn-sm btn-danger" href="add_credit.php?reid=<?php echo $row["reid"]; ?>"><i class="la la-plus"></i></a>	
														<button class="btn btn-primary btn-sm" id="btn1">Disabled</button>
														<button class="btn btn-success btn-sm" id="btn2">Enabled</button>
														<?php 
														}
						
														?>
														<hr>
														<h4 style="display:none;">Rs.<?php echo number_format((float)$row['balance'],2); ?> </h4>
							<?php 
							
                            }else if($sellertype2 == "3"){
							?> 
														<?php 
						
														if($row['creditadd'] == "0"){
															
														?>
														<button class="btn btn-primary btn-sm" id="btn1">Disabled</button>
														<?php 
														
														}else if($row['status'] == "1"){
														
														?>
														<a class="btn btn-sm btn-danger" href="add_credit.php?reid=<?php echo $row["reid"]; ?>"><i class="la la-plus"></i></a>	
														<button class="btn btn-primary btn-sm" id="btn1">Disabled</button>
														<button class="btn btn-success btn-sm" id="btn2">Enabled</button>
														<?php 
														}
						
														?>
														<hr>
														<h4 style="display:none;">Rs.<?php echo number_format((float)$row['balance'],2); ?> </h4>
							<?php 
							
                            }else if($sellertype2 == "4"){
							?> 
							
														<?php 
						
														if($row['creditadd'] == "0"){
															
														?>
														<button class="btn btn-primary btn-sm" id="btn1">Disabled</button>
														<?php 
														
														}else if($row['status'] == "1"){
														
														?>
														<a class="btn btn-sm btn-danger" href="add_credit.php?reid=<?php echo $row["reid"]; ?>"><i class="la la-plus"></i></a>	
														<button class="btn btn-primary btn-sm" id="btn1">Disabled</button>
														<button class="btn btn-success btn-sm" id="btn2">Enabled</button>
														<?php 
														}
						
														?>
														<hr>
														<h4 style="display:none;">Rs.<?php echo number_format((float)$row['balance'],2); ?> </h4>
														
							<?php 
                            }else if($sellertype2 == "5"){
							?>
							<a href="#" class="badge badge-primary">No Permission</a>
                                                   
							<?php 
                            }

                            ?>
														
														</td>
														<td><p class="btn btn-danger btn-sm"><?php echo $row['add_date']; ?></p></td>											
													</tr>
								<?php } 

								}
								?>
												</tbody>
											</table>
										</div>
									</div>
                                </div>
                            </div>
						</div>
					</div>
				</div>
				
            </div>
        </div>
        <!--**********************************
            Content body end
        ***********************************-->

		<?php
		require_once 'footer.php';
		?>

		<!--**********************************
           Support ticket button start
        ***********************************-->

        <!--**********************************
           Support ticket button end
        ***********************************-->


    </div>
    <!--**********************************
        Main wrapper end
    ***********************************-->

    <?php
	require_once 'footerjs.php';
	?>
	
<script>
$(document).ready(function(){
  $("#btn1").click(function(){
    $("h4").hide();
  });
  $("#btn2").click(function(){
    $("h4").show();
  });
});
</script>    
	
	<script>

function exportTableToExcel(tableID, filename = ''){
    var downloadLink;
    var dataType = 'application/vnd.ms-excel';
    var tableSelect = document.getElementById(tableID);
    var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
    
    // Specify file name
    filename = filename?filename+'.xls':'excel_data.xls';
    
    // Create download link element
    downloadLink = document.createElement("a");
    
    document.body.appendChild(downloadLink);
    
    if(navigator.msSaveOrOpenBlob){
        var blob = new Blob(['\ufeff', tableHTML], {
            type: dataType
        });
        navigator.msSaveOrOpenBlob( blob, filename);
    }else{
        // Create a link to the file
        downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
    
        // Setting the file name
        downloadLink.download = filename;
        
        //triggering the function
        downloadLink.click();
    }
}
</script>

<script>

$(document).ready(function(){

    loadGallery(true, 'a.thumbnail');

    //This function disables buttons when needed
    function disableButtons(counter_max, counter_current){
        $('#investow-previous-image, #investow-next-image').investow();
        if(counter_max == counter_current){
            $('#investow-next-image').hide();
        } else if (counter_current == 1){
            $('#investow-previous-image').hide();
        }
    }

    /**
     *
     * @param setIDs        Sets IDs when DOM is loaded. If using a PHP counter, set to false.
     * @param setClickAttr  Sets the attribute for the click handler.
     */

    function loadGallery(setIDs, setClickAttr){
        var current_image,
            selector,
            counter = 0;

        $('#investow-next-image, #investow-previous-image').click(function(){
            if($(this).attr('id') == 'investow-previous-image'){
                current_image--;
            } else {
                current_image++;
            }

            selector = $('[data-image-id="' + current_image + '"]');
            updateGallery(selector);
        });

        function updateGallery(selector) {
            var $sel = selector;
            current_image = $sel.data('image-id');
            $('#image-gallery-caption').text($sel.data('caption'));
            $('#image-gallery-title').text($sel.data('title'));
            $('#image-gallery-image').attr('src', $sel.data('image'));
            disableButtons(counter, $sel.data('image-id'));
        }

        if(setIDs == true){
            $('[data-image-id]').each(function(){
                counter++;
                $(this).attr('data-image-id',counter);
            });
        }
        $(setClickAttr).on('click',function(){
            updateGallery($(this));
        });
    }
});
</script>

</body>
</html>