escape(trim($_GET['search'])); } else { $search = ""; } if(isset($_GET['offset'])){ $offset = $db -> escape(trim($_GET['offset'])); } else { $offset = ""; } if(isset($_GET['limit'])){ $limit = $db -> escape(trim($_GET['limit'])); $offset_limit = " LIMIT ". $offset.",".$limit; } else { $offset_limit = ""; } $customer_name = ""; if(isset($_GET['customer_id'])){ //if from customer profile $customer_record_id = $db -> escape(trim($_GET['customer_id'])); $customer_dms_ids = array(); $customer_dms_id_list = $db -> sql_query("SELECT customer_dms_id FROM `customer_dms` WHERE `customer_record_id` = '$customer_record_id'"); while($row = $customer_dms_id_list->fetch_assoc()) { $customer_dms_ids = array_merge($customer_dms_ids,array($row['customer_dms_id'])); } $customer_id = " AND v.customer_id IN (".implode(",",array_map('quote', $customer_dms_ids)).") "; } else { $customer_id = ""; } $json_arr['rows'] = array(); $vehicle_query = "SELECT %s FROM vehicle v INNER JOIN source_brand sb ON v.brand_id=sb.id INNER JOIN vehicle_color vc ON v.color_id=vc.id INNER JOIN source_car_model scm ON v.model_id=scm.id LEFT OUTER JOIN customer_dms cd ON v.customer_id=cd.customer_dms_id LEFT OUTER JOIN customer c ON cd.customer_record_id = c.id WHERE concat( IFNULL(v.plate_number,''), IFNULL(v.conduction_sticker,''), v.customer_id, IF( concat(c.first_name,c.last_name,c.corporation_name) <> '', concat(c.first_name,c.last_name,c.corporation_name), '' ) ) LIKE '%%%s%%' %s AND v.status = 1 GROUP BY v.id ORDER BY v.id DESC"; $count = " count(v.id) "; $fields = " v.id, scm.name AS model, v.plate_number, v.conduction_sticker, sb.name AS brand, vc.name AS color, v.customer_id,v.date_created,sb.logo, IF( c.type = 1, concat(c.first_name,' ',c.middle_name,' ',c.last_name),c.corporation_name ) as name "; // echo sprintf($vehicle_query, $fields, $search,$customer_id);exit; $vehicle_list_query = $db -> sql_query(sprintf($vehicle_query, $fields, $search,$customer_id)." $offset_limit"); $vehicle_list_query_count = $db -> select("SELECT COUNT(*) FROM ( ".sprintf($vehicle_query,$count,$search,$customer_id)." ) as total_count"); //echo sprintf($vehicle_query, $fields, $search,$customer_id); return; $json_arr['total'] = $vehicle_list_query_count; //total number of result if(isset($_GET['grid'])){ $json_arr['vehicle_list'] = ""; $json_arr['vehicle_list_paging'] = ""; // echo $json_arr['total'] % $limit; $goto_offset = 0; for($i = 0; $i < $json_arr['total'] / $limit; $i++){ if($offset == $goto_offset){ $grid_status = "active"; $grid_offset = ""; }else{ $grid_status = ""; $grid_offset = " onclick='gotoOffset(".$goto_offset.")' "; } $json_arr['vehicle_list_paging'] = $json_arr['vehicle_list_paging']."
  • ".($i+1)."
  • "; $goto_offset = $goto_offset+$limit; } if($goto_offset < 1){ $json_arr['vehicle_list_paging'] = "No Record"; } $json_arr['grid_offset'] = $goto_offset; while($row = $vehicle_list_query->fetch_assoc()) { $grid_customer_id = $row['customer_id']; $grid_date = ($row['date_created']) <> "" ? $row['date_created'] : "(Not provided)"; $grid_brand = ($row['brand']) <> "" ? $row['brand'] : "(Not provided)"; $grid_model = ($row['model']) <> "" ? $row['model'] : "(Not provided)";// $row['model']; $grid_plate = ($row['plate_number']) <> "" ? $row['plate_number'] : "(Not provided)"; $grid_cs = ($row['conduction_sticker']) <> "" ? $row['conduction_sticker'] : "(Not provided)"; $grid_vehicle_id = $row['id']; $grid_color = ($row['color']) <> "" ? $row['color'] : "(Not provided)"; $grid_brand_logo = $row['logo']; $grid_cs_data = $row['conduction_sticker']; $grid_plate_data = $row['plate_number']; $json_arr['vehicle_list'] = $json_arr['vehicle_list']."
    ".$grid_date."

    ".$grid_brand."

    Model: ".$grid_model."

    • Plate #: ".$grid_plate."
    • CS #: ".$grid_cs."
    logo
    "; } }else{ while($row = $vehicle_list_query->fetch_assoc()) { $json_arr['rows'] = array_merge($json_arr['rows'],array(array('model'=>$row['model'], 'plate_number'=>$row['plate_number'], 'brand'=>$row['brand'], 'color'=>$row['color'], 'conduction_sticker'=>$row['conduction_sticker'], 'id'=>$row['id'], 'customer_id'=>$row['customer_id'], 'customer_name_id'=>(($row['name']) <> "" ? $row['name'] : "(Not provided)") // 'customer_name_id'=>(($row['customer_id']) <> "" ? $row['customer_id'] : "") . " / " . // (($row['name']) <> "" ? $row['name'] : "(Not provided)") ))); } } echo json_encode($json_arr); //print_r($json_arr); function isNotEmpty($data){ return preg_match('/\S/', $data); } function quote($str) { return sprintf("'%s'", $str); } ?>