<?
require_once 'medoo.php';

$mdb = new medoo( [
  'database_type' => 'mysql',
  'database_name' => 'host439372_b2b',
  'server' => 'localhost',
  'username' => 'host439372_b2b',
  'password' => 'BNbuvNMs22Dq48drp6Ee',
  'charset' => 'utf8'
] );

if ( $_POST['a'] == 'get-email' )
{
  echo 'zam@redline.com.pl';
  exit;
}

if ( $_POST['a'] == 'get-phone' )
{
  echo '+48 14 68 33 333';
  exit;
}

if ( $_POST['a'] == 'load-customer-b2b-data' )
{
  $order_id = $mdb -> get( 'ps_orders', 'id_order', [ 'id_customer' => $_POST['customer_id'], 'ORDER' => [ 'id_order' => 'DESC' ] ] );
  $row['fvat'] = $mdb -> get( 'ps_custom_field_userdata', 'field_value', [ 'AND' => [ 'id_order' => $order_id, 'id_custom_field' => 1 ], 'ORDER' => [ 'id_order' => 'DESC' ], 'LIMIT' => 1 ] );
  $row['firm'] = $mdb -> get( 'ps_custom_field_userdata', 'field_value', [ 'AND' => [ 'id_order' => $order_id, 'id_custom_field' => 2 ], 'ORDER' => [ 'id_order' => 'DESC' ], 'LIMIT' => 1 ] );
  $row['nip'] = $mdb -> get( 'ps_custom_field_userdata', 'field_value', [ 'AND' => [ 'id_order' => $order_id, 'id_custom_field' => 3 ], 'ORDER' => [ 'id_order' => 'DESC' ], 'LIMIT' => 1 ] );
  $row['street'] = $mdb -> get( 'ps_custom_field_userdata', 'field_value', [ 'AND' => [ 'id_order' => $order_id, 'id_custom_field' => 4 ], 'ORDER' => [ 'id_order' => 'DESC' ], 'LIMIT' => 1 ] );
  $row['city'] = $mdb -> get( 'ps_custom_field_userdata', 'field_value', [ 'AND' => [ 'id_order' => $order_id, 'id_custom_field' => 5 ], 'ORDER' => [ 'id_order' => 'DESC' ], 'LIMIT' => 1 ] );
  $row['postal_code'] = $mdb -> get( 'ps_custom_field_userdata', 'field_value', [ 'AND' => [ 'id_order' => $order_id, 'id_custom_field' => 6 ], 'ORDER' => [ 'id_order' => 'DESC' ], 'LIMIT' => 1 ] );
  echo json_encode( $row );
  exit;
}