<?php
/*
$servername = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "kelapak_central";
*/

$userdb = "wahpet_user";
$passdb = "7bwt=~~QeOR3";
$servername = "localhost";
$dbname = "wahpet_kelapak";


ini_set('session.cache_limiter','public');
session_cache_limiter(false);

ini_set('max_execution_time', 180);

$conn = new mysqli($servername, $userdb, $passdb, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

date_default_timezone_set("Asia/Jakarta");
output_buffering : "4096";

function globaldate($d){
	$datetime = strtotime($d);
	$date_output = date("m/d/Y g:i A", $datetime);
	echo $date_output;
	}

	function is_odd($number) {
	  return $number & 1; // 0 = even, 1 = odd
	}


function getip()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}
function dtosql($date){
	$exp = explode('/',$date);
	if(count($exp) == 3) {
		$date = $exp[2].'-'.$exp[1].'-'.$exp[0];
	}
	return $date;
}
 
function dtostr($date){
	$exp = explode('-',$date);
	if(count($exp) == 3) {
		$date = $exp[2].'/'.$exp[1].'/'.$exp[0];
	}
	return $date;
	}

function iddate($date){  
        $BulanIndo = array("Januari", "Februari", "Maret",  
                           "April", "Mei", "Juni",  
                           "Juli", "Agustus", "September",  
                           "Oktober", "November", "Desember");  
      
        $tahun = substr($date, 0, 4);  
        $bulan = substr($date, 5, 2);  
        $tgl   = substr($date, 8, 2);  
          
        $result = $tgl . " " . $BulanIndo[(int)$bulan-1] . " ". $tahun;       
        return($result);  
}  

function iddate2($date){  
        $BulanIndo = array("Jan", "Feb", "Mar",  
                           "Apr", "Mei", "Jun",  
                           "Jul", "Aug", "Sep",  
                           "Okt", "Nov", "Des");  
      
        $tahun = substr($date, 0, 4);  
        $bulan = substr($date, 5, 2);  
        $tgl   = substr($date, 8, 2);  
          
        $result = $tgl . " " . $BulanIndo[(int)$bulan-1] . " ". $tahun;       
        return($result);  
}  

function transno($nomer){

	if(strlen($nomer)==1){
			$nomer = "0000".$nomer;
		}
	elseif(strlen($nomer)==2){
			$nomer = "000".$nomer;
		}
	elseif(strlen($nomer)==3){
			$nomer = "00".$nomer;
		}
	elseif(strlen($nomer)==4){
			$nomer = "0".$nomer;
		}
	return $nomer;
}


function transno3($nomer){

	if(strlen($nomer)==1){
			$nomer = "00".$nomer;
		}
	elseif(strlen($nomer)==2){
			$nomer = "0".$nomer;
		}
	return $nomer;
}


function enc($txt){
	$text = md5(md5(md5($txt)));
	return $text;
	}
	
$tgl = date('d');
$bln = date('m');
$thn = date('Y');

$tanggal = date('Y-m-d');
$limit = 13;
$adjacents = 3;

$userip = getip();
function format_angka($a) {
$a = str_replace(",","",$a);
return $a;
}


$page 	= $_REQUEST['page'];
$q 		= $_REQUEST['q'];
$f1 	= $_REQUEST['f1'];
$f2 	= $_REQUEST['f2'];
$f3 	= $_REQUEST['f3'];

if(!$page){$page = 1;}

$ar_month = array("","I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII");
$xbln = $bln + 0;
$page_filter = "?q=".$q."&page=".$page."&f1=".$f1."&f2=".$f2;





$sqlstat = "SELECT * FROM order_status";
$stat_conn = $conn->query($sqlstat) or die($sqlstat);
while($stat = $stat_conn->fetch_assoc()){;
	$status_id = $stat['status_autoid'];
	$status_desc[$status_id] =  $stat['status_style'];
	$_status_desc[$status_id] =  $stat['status_desc'];

}







// web config
$sqlconfig = "SELECT * FROM web_config WHERE web_id = 1";
$config_conn = $conn->query($sqlconfig) or die($sqlconfig);
$rsconfig = $config_conn->fetch_assoc();

	$web_name 			= $rsconfig['web_name'];
	$web_title 			= $rsconfig['web_title'];
	$web_logo 			= $rsconfig['web_image_logo'];
	$web_addr 			= $rsconfig['web_addr'];
	$web_contact_mail 	= $rsconfig['web_contact_mail'];
	$web_contact_wa 	= $rsconfig['web_contact_wa'];
	
	$web_mail_addr 		= $rsconfig['web_mail_addr'];
	$web_mail_name 		= $rsconfig['web_mail_name'];
	$web_mail_passwd 	= $rsconfig['web_mail_passwd'];
	$web_mail_host 		= $rsconfig['web_mail_host'];



function get_stok_info($id,$outlet,$conn){

	if($outlet=="0"){
		$sqlstok = "SELECT SUM(log_inqty - log_outqty) as stok FROM invlog WHERE pm_autoid = '$id' AND outlet_id = '0'";		
		}else{
		$sqlstok = "SELECT SUM(log_inqty - log_outqty) as stok FROM invlog WHERE pm_autoid = '$id' AND outlet_id = '$outlet'";		
			}

	$stok_con = $conn->query($sqlstok) or die($sqlstok);
	$rstok = $stok_con->fetch_assoc();	
	$stok_qty = $rstok['stok'];

				 
	return $stok_qty;


}
?>