Your IP : 216.73.216.26


Current Path : /home2/wtmwscom/public_html/admin/
Upload File :
Current File : /home2/wtmwscom/public_html/admin/pin_model.php

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

//$pin_type_length = array('a'=>8, 'b'=>9,'c'=>10, 'd'=>11,'e'=>12, 'f'=>13,'g'=>14, 'h'=>15, 'i'=>16,'j'=>17,'k'=>18,'l'=>19,'m'=>20,'n'=>21,'o'=>22,'p'=>23,'q'=>24);

$type = $_POST['type'];
$quantity = $_POST['pin'];

if($quantity <= 0 || $quantity == ''){
    setMessage('Please enter vaild number of pin.', 'alert-msg error');
    redirect("pin.php?type=$type");
    die();
}
else{
    /* generate pin */
    $md5 = '';
    $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;
    for($i=0; $i<$quantity; $i++){
        $md5 = '';
        //$pin_length = getno($type);
        $md5 = str_rand($pin_length, $type, $pin_package->package_amount);
        $md5 = '';
    }
    setMessage('E-pins generated successfully.', 'alert-msg success');
    redirect("pin.php?type=$type");
}

/* pin related functions here */

function str_rand($length, $type, $package_amount){
    $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){
        //global $pin_length;
        //$pin_length = $pin_length;
        str_rand($length, $type);
    }
    else{
        //global $next_week;
        mysqli_query($GLOBALS['connection'], "INSERT INTO `dynamicpinnumber` (`datetime`, `pinumber`, `status`, `type`, `generated_by`, `amount`) VALUES ('".date('Y-m-d H:i:s')."', '$str', 'unused', '$type', 'Admin', '$package_amount')");
        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;
}*/
?>