<?php

ob_start();
session_start();

require_once 'includes.php';

require_once("conn.php");

require_once("config.php");

require_once 'dbconfig4.php';

$message ='';

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

	$user_qury=mysqli_query($conn,"SELECT * FROM ormsusers WHERE user_id='$_SESSION[admin_user_id]'");

	$user_resalt=mysqli_fetch_array($user_qury);

	$customer = $user_resalt['user_id'];
	
	$adminbalance = number_format((float)$user_resalt['balance'],2);

	if($user_resalt['image']==""){

		$image_path="images/empty.jpg";

	}

	else{

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

	}

}

$message ='';

if (isset($_POST['add_credit'])) {

		$user_qury=mysqli_query($conn,"SELECT * FROM `slips` WHERE id=(SELECT MAX(id) FROM slips);");
		$user_resalt=mysqli_fetch_array($user_qury);
		$transnumber = $user_resalt['id']+1;
		$transid = "0000$transnumber";

		$userreid =  $_POST['userreid'];

        $user_qury=mysqli_query($conn,"INSERT INTO `slips` (`transid`,`user_id`, `path`, `price`, `type`,`isPay`, `customer`,`usertype`,`ptype`) VALUES ('".$transid."','".$userreid."','', '".$_POST['amount']."', '1' , '0' , '".$customer."', 'Admin', 'Credit');");


        $message='<div class="alert" role="alert" style="color: #ffffff;background-color: #1bcfb4; border-color: #1bcfb4;">
        <i class="mdi mdi-check-decagram"></i>Credit Tranfer Successfully Done</div>';
		
		
    }


?>
<!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>CREDIT TRANSFER | Recharge and Billing System | ORMS | Dashbaord</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Dropify/0.2.2/css/dropify.min.css" integrity="sha512-EZSUkJWTjzDlspOoPSpUFR0o0Xy7jdzW//6qhUkoZ9c4StFkVsp9fbbd0O06p9ELS3H486m4wmrCELjza4JEog==" crossorigin="anonymous" referrerpolicy="no-referrer" />

    <?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="padding: 0px 3px;">සම්පුර්න කරන්න</a>
				</div>
				</div>
				</div>    
                <div class="row page-titles mx-0">
                    <div class="col-sm-6 p-md-0">
                        <div class="welcome-text">
                            <h4>CREDIT TRANSFER</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);">CREDIT</a></li>
                            <li class="breadcrumb-item active"><a href="javascript:void(0);">CREDIT TRANSFER</a></li>
                        </ol>
                    </div>
                </div>
				
			<div class="container" style="max-width: 33rem;">
			<div class="card">
				<div class="card-body">
					<h2 class="text-center">CREDIT TRANSFER</h2>
					<hr>
                    <?=$message?>
					<form autocomplete="off" class="p-2 mt-4" id="add_tickets_frm" action="add_credit.php" method="post" enctype="multipart/form-data">
					
						<div class="form-group niftra-field-icon">
						<?php 
	
						if (isset($_GET['reid']))
						
						{
							
						?>
							
							<input type="hidden" class="form-control" id="reid" name="userreid" value="<?php echo $_GET['reid']; ?>" placeholder="Enter User">
							
						<?php 
	
						}
							
						?>
						
							<span class="fas fa-money-bill-alt form-control-feedback">Amount</span>
							<input type="text" class="form-control" id="amount" name="amount" placeholder="Enter Credit Amount" required="">
						</div>

						<div class="form-group text-center mt-2">
							<label id="lbl_trans_fee"></label>
						</div>
						<div class="row mt-4">
							<a class="btn btn-secondary col-md-3" href="home.php">BACK</a>
							<input type="submit" class="btn btn-success col-md-9" id="btnsave" name="add_credit" value="Submit Transfer">
						</div>
					</form>
				</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 src="https://cdnjs.cloudflare.com/ajax/libs/Dropify/0.2.2/js/dropify.min.js" integrity="sha512-8QFTrG0oeOiyWo/VM9Y8kgxdlCryqhIxVeRpWSezdRRAvarxVtwLnGroJgnVW9/XBRduxO/z1GblzPrMQoeuew==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

	<script>
        $('.dropify').dropify();

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>