Your IP : 216.73.216.26


Current Path : /home2/wtmwscom/www/member/
Upload File :
Current File : /home2/wtmwscom/www/member/pin_model.php

<?php
session_start();
include('../connection.php');
include('../function_lib.php');

$uid = $_SESSION['userid'];
$pin_type =  array('a'=>10000,'b'=>25000,'c'=>50000,'d'=>100000,);
//$pin_type_length = array('a'=>8,'b'=>9,'c'=>10,'d'=>11,);
$type = $_POST['type'];
$wallet_type = $_POST['wallet_type'];
$quantity = 1;

//$wallet = mysqli_fetch_object(mysqli_query($connection, "SELECT uid, email, mobile, wallet FROM user WHERE uid='$uid'"))->wallet;
$wallet_row = mysqli_fetch_object(mysqli_query($connection, "SELECT wallet, wallet_fund FROM user WHERE uid='$uid'"));

$wallet = $wallet_type=="primary_wallet" ? $wallet_row->wallet : $wallet_row->wallet_fund; 
$pin_package = mysqli_fetch_object(mysqli_query($connection, "SELECT pin_length, package_amount FROM pin_package WHERE id ='$type'"));
$pin_length = $pin_package->pin_length;
$amount = $pin_package->package_amount;
if( $amount > $wallet){
    setMessage('Insuffcient wallet to generate pin!', 'alert-msg error');
    redirect("pin.php?type=$type");
    die();
}
else{
    /* generate pin */
    $md5 = '';
    for($i=0; $i<$quantity; $i++){
        $md5 = '';
        //$pin_length = getno($type);
        $md5 = str_rand($pin_length, $type);
        
        $user_sql = $wallet_type=="primary_wallet" ? "UPDATE user SET wallet = wallet - '$amount' WHERE uid='".$uid."'" : "UPDATE user SET wallet_fund = wallet_fund - '$amount' WHERE uid='".$uid."'"; 
        mysqli_query($connection, $user_sql);
        
        $md5 = '';
    }
    setMessage('E-pins generated successfully.', 'alert-msg success');
    redirect("pin.php?type=$type");
}

/* pin related functions here */

function str_rand($length, $type){
    $seeds = 'alphanum';
    
    // Possible seeds
    $seedings['alpha'] = 'abcdefghijklmnopqrstuvwqyz';
    $seedings['numeric'] = '1234567891';
    $seedings['alphanum'] = '1234567891';
    $seedings['hexidec'] = '0123456789abcdef';

    // Choose seed
    if (isset($seedings[$seeds])){
        $seeds = $seedings[$seeds];
    }
    
    // Generate
    $str = '';
    $seeds_count = strlen($seeds);

    for ($i = 0; $length > $i; $i++){
        $str .= $seeds{mt_rand(0, $seeds_count - 1)};
    }

    $str = trim($str,"");
    $count = strlen($str);
    if($count < $length){
        str_rand($length, $type);
    }
    else{
        global $next_week;
        mysqli_query($connection, "INSERT INTO `dynamicpinnumber` (`datetime`, `pinumber`, `status`, `type`, `generated_by`) VALUES ('".date('Y-m-d H:i:s')."', '$str', 'unused', '$type', '".$_SESSION['loginid']."')");
        return $str;
    }
}

/* function getno($pin_type){
    global $pin_type_length;
    foreach($pin_type_length as $key => $value){
        if($pin_type == $key){
            $pin_length = $value;
        }
    }
    return $pin_length;
} */
?>