-=[ Mr. Bumblebee ]=-
_Indonesia_

Path : /var/www/html/inc.bk/class/
File Upload :
Current File : /var/www/html/inc.bk/class/public.search.php

<?php

####################################################
// global search value
####################################################

	$total['styp']		= '' ;
	$total['sbox']		= '' ;
	$total['scode']		= '' ;

	$total['btyp']		= '' ;
	$total['bbox1']		= '' ;
	$total['bbox2']		= '' ;
	$total['bcode']		= '' ;

	$total['ftyp']			= '' ;
	$total['fbox']		= '' ;
	$total['fcode']		= '' ;

	$total['etyp']		= '' ;
	$total['ebox']		= '' ;
	$total['ecode']		= '' ;

	$total['atyp']		= '' ;
	$total['abox']		= '' ;
	$total['acode']		= '' ;

	$search_query	 = array (
						'total'		=> '' ,
						'within'	=> '' ,
						'fix'		=> '' ,
						'between'	=> ''
						) ;
	$order_query	= '' ;

####################################################
// within - styp && sbox
####################################################

	if ( !empty($_GET['styp']))
		$total['styp'] = $_GET['styp'] ;
	else if ( is_array($_POST['styp']))
		$total['styp'] = implode(',' , $_POST['styp']) ;
	else if (!emptY($_POST['styp']))
		$total['styp'] = $_POST['styp'] ;

	if ( !empty($_GET['sbox']))
		$total['sbox'] = $_GET['sbox'] ;
	else if ( is_array($_POST['sbox']))
		$total['sbox'] = implode(',' , $_POST['sbox']) ;
	else if (!emptY($_POST['sbox']))
		$total['sbox'] = $_POST['sbox'] ;

	if ( !empty($total['styp']) && !empty($total['sbox'])) {

		$search_keyword = explode(',' , $total['styp']) ;
		$search_values = explode(' ' , $total['sbox']) ;

		$search_values = array_unique ($search_values);
		foreach ( $search_values as $key=>$val ) {
			if ( empty($val)) unset($search_values[$key]) ;
		}

		if ( count($search_values) > 0)
			$search_values = " REGEXP '" . implode('|' , str_replace('(','',$search_values)) . "' " ;
		else
			$search_values = " LIKE '%" . implode(' ' , $search_values) . "' " ;

		if ( count($search_keyword) > 0 )
		{
			foreach ( $search_keyword as $key_is_temp => $val_is_real )
			{
				if ( empty($val_is_real)) continue ;
				if ( !empty($search_query['within'])) $search_query['within'].= " OR " ;
				$search_query['within'].= " " . $val_is_real . " " . $search_values ;
			}
			$search_query['within'] = " AND ( " . $search_query['within'] . " ) " ;
			$total['scode'] = '&styp=' . $total['styp'] . '&sbox=' . $total['sbox'] ;
		}
	}

####################################################
// between - btyp && bbox
####################################################

	if ( !empty($_GET['btyp']))
		$total['btyp'] = $_GET['btyp'] ;
	else if (!emptY($_POST['btyp']))
		$total['btyp'] = $_POST['btyp'] ;

	if ( !empty($_GET['bbox1']))
		$total['bbox1'] = $_GET['bbox1'] ;
	else if (!emptY($_POST['bbox1']))
		$total['bbox1'] = $_POST['bbox1'] ;

	if ( !empty($_GET['bbox2']))
		$total['bbox2'] = $_GET['bbox2'] ;
	else if (!emptY($_POST['bbox2']))
		$total['bbox2'] = $_POST['bbox2'] ;

	if ( !empty($total['btyp']))
	{
		if ( !empty($total['bbox1']))
		{
			if ( !empty($search_query['between'])) $search_query['between'].= " AND " ;
			$search_query['between'].= " date_format( " . $total['btyp'] . " , '%Y-%m-%d') >= '" . $total['bbox1'] . "' " ;
		}
		if ( !empty($total['bbox2']))
		{
			if ( !empty($search_query['between'])) $search_query['between'].= " AND " ;
			$search_query['between'].= " date_format( " . $total['btyp'] . " , '%Y-%m-%d') <= '" . $total['bbox2'] . "' " ;
		}

		if ( !empty($search_query['between'])) $search_query['between'] = " AND ( " . $search_query['between'] . " ) " ;
		$total['bcode'] = '&btyp=' . $total['btyp'] . '&bbox1=' . $total['bbox1'] . '&bbox2=' . $total['bbox2'] ;
	}

####################################################
// fix - ftyp && fbox
####################################################

	if ( !empty($_GET['ftyp']))
		$total['ftyp'] = $_GET['ftyp'] ;
	else if ( is_array($_POST['ftyp']))
		$total['ftyp'] = implode(',' , $_POST['ftyp']) ;
	else if (!emptY($_POST['ftyp']))
		$total['ftyp'] = $_POST['ftyp'] ;

	if ( !empty($_GET['fbox']))
		$total['fbox'] = $_GET['fbox'] ;
	else if ( is_array($_POST['fbox']))
		$total['fbox'] = implode(',' , $_POST['fbox']) ;
	else if (!emptY($_POST['fbox']))
		$total['fbox'] = $_POST['fbox'] ;

	if ( !empty($total['ftyp']) && !empty($total['fbox'])) {

		$search_keyword = explode(',' , $total['ftyp']) ;
		$search_values = explode(',' , $total['fbox']) ;

		if ( count($search_keyword) > 0 )
		{
			foreach ( $search_keyword as $key_is_num => $val_is_str )
			{
				if ( empty($val_is_str)) continue ;
				if ( !empty($search_query['fix'])) $search_query['fix'].= " AND " ;
				$search_query['fix'].= " " . $val_is_str . " = '" . $search_values[$key_is_num] . "' " ;
			}

			if ( !empty($search_query['fix'])) $search_query['fix'] = " AND ( " . $search_query['fix'] . " ) " ;
			$total['fcode'] = '&ftyp=' . $total['ftyp'] . '&fbox=' . $total['fbox'] ;
		}
	}

####################################################
// no search group - etyp && ebox
####################################################

	if ( !empty($_GET['etyp']))
		$total['etyp'] = $_GET['etyp'] ;
	else if ( is_array($_POST['etyp']))
		$total['etyp'] = implode(',' , $_POST['etyp']) ;
	else if (!emptY($_POST['etyp']))
		$total['etyp'] = $_POST['etyp'] ;

	if ( !empty($_GET['ebox']))
		$total['ebox'] = $_GET['ebox'] ;
	else if ( is_array($_POST['ebox']))
		$total['ebox'] = implode(',' , $_POST['ebox']) ;
	else if (!emptY($_POST['ebox']))
		$total['ebox'] = $_POST['ebox'] ;

	if ( !emptY($total['etyp'])) $total['ecode'] = '&etyp=' . $total['etyp'] . '&ebox=' . $total['ebox'] ;

####################################################
// order
####################################################

	if ( !empty($_GET['atyp']))
		$total['atyp'] = $_GET['atyp'] ;
	else if ( is_array($_POST['atyp']))
		$total['atyp'] = implode(',' , $_POST['atyp']) ;
	else if (!emptY($_POST['atyp']))
		$total['atyp'] = $_POST['atyp'] ;

	if ( !empty($_GET['abox']))
		$total['abox'] = $_GET['abox'] ;
	else if ( is_array($_POST['abox']))
		$total['abox'] = implode(',' , $_POST['abox']) ;
	else if (!emptY($_POST['abox']))
		$total['abox'] = $_POST['abox'] ;


	if ( !empty($total['atyp'])) {

		$order_keyword = explode(',' , $total['atyp']) ;
		$order_types = explode(',' , $total['abox']) ;

		if ( count($order_keyword) > 0 )
		{
			foreach ( $order_keyword as $key_is_num => $val_is_str )
			{
				if ( emptY($val_is_str)) continue ;
				if ( !empty($order_query)) $order_query.= " , " ;
				$order_query.= " " . $val_is_str ;
				if ( strtolower($order_types[$key_is_num]) == 'asc') $order_query.= " asc " ;
				else $order_query.= " desc " ;
			}
			if ( !empty($order_query)) $order_query = " order by " . $order_query ;
			$total['acode'] = '&atyp=' . $total['atyp'] . '&abox=' . $total['abox'] ;
		}
	}
	foreach ( $search_query as $key=>$val ) {
		if ( $key == 'total' ) continue ;
		if ( empty($val)) continue ;
		$search_query['total'].= ' ' . $val ;
	}
?>

Copyright © 2017 || Recoded By Mr.Bumblebee