<?php

$header_post_link = !empty(HOME_URL) ? HOME_URL . '?dtype=product&class_name=ec_confirm_order' : '?dtype=product&class_name=ec_confirm_order';
$hidden_field_stmt = '';
$user_id_h = null;
//$f = new inoform();
if (!empty($_POST) && !empty($_POST['ec_product_id'])) {
 foreach ($_POST as $field_name => $value_a) {
  foreach ($value_a as $c => $field_v) {
   $hidden_field_stmt .= $f->hidden_field_withCLass($field_name, $field_v, 'hidden');
  }
 }
}

//asign values of fields on form but not in databse only if $$class->$primary_cloumn is not null
if (!empty($$class->ar_customer_id)) {
 $ac = new ar_customer();
 $ac->findBy_id($$class->ar_customer_id);
 $$class->customer_name = $ac->customer_name;
 $$class->customer_number = $ac->customer_number;
}
if (empty($$class->hd_subscription_header_id)) {
 $$class->subscription_type = empty($$class->subscription_type) ? 'NEW' : $$class->subscription_type;
 $$class->document_type = empty($$class->document_type) ? 'BASIC' : $$class->BASIC;
// $$class->subscription_type = empty($$class->subscription_type) ? 'NEW' : $$class->subscription_type;
// $$class->subscription_type = empty($$class->document_type) ? 'NEW' : $$class->document_type;

 if (!empty($ino_user->ino_user_id)) {
  $$class->first_name = $ino_user->first_name;
  $$class->last_name = $ino_user->last_name;
  $$class->full_name = $ino_user->first_name . ' ' . $ino_user->last_name;
  $$class->email = $ino_user->email;
  $$class->mobile_phone1 = $ino_user->phone;

  $all_address = address_reference::find_by_reference_detailts('ino_user', $ino_user->ino_user_id);
  if ($all_address) {
   $ship_add = $bill_add = $all_address[0];
   $ship_to_id = $bill_to_id = $all_address[0]->address_id;
  } else {
   $ship_add = $bill_add = new address();
  }
  $user_id_h = $ino_user->ino_user_id;
 }
}

if (empty($ship_add)) {
 $ship_add = new address();
}

if (empty($bill_add)) {
 $bill_add = new address();
}

if (empty($all_address)) {
 $all_address = [new address()];
}


if (!empty($_SESSION['ec_product_id']) && is_array($_SESSION['ec_product_id'])) {
 $cart_object = [];
 foreach ($_SESSION['ec_product_id'] as $key => $ec_prd_id) {
  $ec_prd_details = ec_product::find_by_id($ec_prd_id);
  $ec_user_cart = new ec_user_cart();
  if ($ec_prd_details) {
   foreach ($ec_prd_details as $file_k => $field_v) {
    if (property_exists($ec_user_cart, $file_k)) {
     $ec_user_cart->$file_k = $field_v;
    }
   }
  } else {
   unset($_SESSION['ec_product_id'][$key]);
  }

  array_push($cart_object, $ec_user_cart);
 }
} else {
 $cart_object = [new ec_user_cart()];
}

if (empty($$class->order_source_type)) {
 $$class->order_source_type = 'MANUAL';
}

$mode = 9;


$pageno = !empty($_GET['pageno']) ? $_GET['pageno'] : 1;
$per_page = !empty($_GET['per_page']) ? $_GET['per_page'] : 10;
$total_count = count($cart_object);
$pagination = new pagination($pageno, $per_page, $total_count);
$pagination->setProperty('_path', 'form');
$position = ($pageno - 1) * $per_page;
?>

