<?php
function SqlInj($iWordName){
		
		$iPageUrl = trim($iWordName);
		$replace = array("'", "]", "'");
		//$replace = '';
		$iMakeLetter= str_replace($replace,"",$iWordName);
		return $iMakeLetter;
}
function token($iTable)
{
	global $db;
	$iLastInsertID	= $db->getVal("select id from  $iTable order by id desc")+1;			
	return randomnum(10).$iLastInsertID;
}
function lastid($iTable)
{
	global $db;
	return $db->getVal("select id from  $iTable order by id desc")+1;
}
function SQLPOST($iString)
{
	return  strtoupper($iString);
}
function removespace($iWordName)
	{
		$iPageUrl = trim($iWordName);
		$iGetstring = preg_replace("/[^ \w]+/", "", $iPageUrl);
		$replace = array(",","'", "!","@","#","$", "%", "^", "&", "*", "(", ")" , "+" , "=", "â", "’","?","&","+","~"," ");
		$makeurl= str_replace($replace,"-",$iGetstring);
		$iRmoveHypn = array("------","------","-----","-----","-----","----","---","--");
		$blog_url= str_replace($iRmoveHypn,"-",$makeurl);
		$iFinalNameWord = str_replace(array('/\s+/', ' '), '_', trim($blog_url));
		return $iMakeLetter = strtolower($iFinalNameWord);
	}
function get_client_ip() {
    $ipaddress = '';
    if (getenv('HTTP_CLIENT_IP'))
        $ipaddress = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
        $ipaddress = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
       $ipaddress = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
        $ipaddress = getenv('REMOTE_ADDR');
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}
function createbyuser($iUserid)
		{
			global $db;
			$iCreateUserID=$db->getVal("select   create_by from  admin_login where id='".$iUserid."'");	
			return $iCreateUserID;
		}

function redirect($url=NULL)
{
 		echo "<script>window.location='".$url."'</script>";
 		header("Location:".$url);
		echo '<meta http-equiv="refresh" content="1;url='.$url.'" />';
 		exit;
}
function msg($msg)
{
	if(count($msg))
	foreach($msg as $type => $content)
	if($msg[$type]!='')
	{
	 return '<div class="alert alert-'.$type.' alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>'.$content.'</div>';

	}
} 
function curPageURL() 
{
	$pageURL = 'http';
 	if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 	$pageURL .= "://";
 	if ($_SERVER["SERVER_PORT"] != "80") 
	{
  		$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 	} 
	else 
	{
  		$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 	}
 	return $pageURL;
}
function randomnum($length)
{
	$random= "";
	srand((double)microtime()*1000000);
	$data = "1234567890";
	for($i = 0; $i < $length; $i++)
	{
		$random .= substr($data, (rand()%(strlen($data))), 1);
	}
	return $random;
}
function roundof($numbers, $length)
{
	return number_format((float)$numbers, $length, '.', '');
}

function getIndianCur(float $number)
{
    $decimal = round($number - ($no = floor($number)), 2) * 100;
    $hundred = null;
    $digits_length = strlen($no);
    $i = 0;
    $str = array();
    $words = array(0 => '', 1 => 'one', 2 => 'two',
        3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six',
        7 => 'seven', 8 => 'eight', 9 => 'nine',
        10 => 'ten', 11 => 'eleven', 12 => 'twelve',
        13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen',
        16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen',
        19 => 'nineteen', 20 => 'twenty', 30 => 'thirty',
        40 => 'forty', 50 => 'fifty', 60 => 'sixty',
        70 => 'seventy', 80 => 'eighty', 90 => 'ninety');
    $digits = array('', 'hundred','thousand','lakh', 'crore');
    while( $i < $digits_length ) {
        $divider = ($i == 2) ? 10 : 100;
        $number = floor($no % $divider);
        $no = floor($no / $divider);
        $i += $divider == 10 ? 1 : 2;
        if ($number) {
            $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
            $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
            $str [] = ($number < 21) ? $words[$number].' '. $digits[$counter]. $plural.' '.$hundred:$words[floor($number / 10) * 10].' '.$words[$number % 10]. ' '.$digits[$counter].$plural.' '.$hundred;
        } else $str[] = null;
    }
    $Rupees = implode('', array_reverse($str));
    $paise = ($decimal > 0) ? "." . ($words[$decimal / 10] . " " . $words[$decimal % 10]) . ' Paise' : '';
    return ($Rupees ? $Rupees . 'Rupees ' : '') . $paise;
}
?>