<?php

cw_load('sections');
$search_data =& cw_session_register("search_data");
$category_page =& cw_session_register('category_page');
$search_data['sections']['objects_per_page'] = $category_page['objects_per_page'];
$search_data['sections']['sort_field'] = $category_page['sort_field'];
$search_data['sections']['sort_direction'] = $category_page['sort_direction'];
$search_data['sections']['attributes'] = $att;
$search_data['sections']['flat_search'] = 1;
list($products, $navigation, $product_filter) = cw_call('cw_sections_get', array('section' => 'arrivals', 'data' => $search_data['sections'], '', 'info_type' => 8 + 32 + 128 + 256 + 1024));
$navigation['script'] = cw_call('cw_core_get_html_page_url', array(array('var' => $target, 'delimiter' => '&', 'att' => $att)));
$smarty->assign('navigation', $navigation);
$smarty->assign('products', $products);
$smarty->assign('product_filter', $product_filter);
$smarty->assign('sort_fields', cw_product_get_sort_fields());
$smarty->assign('search_prefilled', $search_data['sections']);
$location[] = array(cw_get_langvar_by_name('lbl_arrivals'), '');
$location = array_merge($location, cw_product_get_filter_location($product_filter, $navigation['script']));
$smarty->assign('current_section_dir', 'special_sections');
$smarty->assign('main', 'arrivals');
 if ($search_type == 'docs_O') {
     $posted_data = $_POST['posted_data'];
     $display_id = $posted_data['doc_id'];
     $result = array();
     $orders = cw_query("SELECT doc_id, display_id FROM {$tables['docs']} WHERE display_id like '{$display_id}%' AND type = 'O' LIMIT " . SEARCH_LIMIT_FOR_AUTOCOMPLETE);
     foreach ($orders as $order) {
         $result[] = array('id' => $order['doc_id'], 'name' => $order['display_id']);
     }
     exit(json_encode($result));
 }
 // search products
 if ($search_type == 'products') {
     cw_load('product');
     $posted_data = $_POST['posted_data'];
     $sort_direction = isset($_POST['sort_direction']) ? $_POST['sort_direction'] : 1;
     $sort_fields = cw_product_get_sort_fields();
     $sort_fields['quantity'] = cw_get_langvar_by_name("lbl_in_stock");
     if (is_array($posted_data) && !empty($posted_data)) {
         $date_fields = array('' => array('sold_date_start' => 0, 'sold_date_end' => 1, 'creation_date_start' => 0, 'creation_date_end' => 1, 'modify_date_start' => 0, 'modify_date_end' => 1));
         $multiple_fields = array('' => array('categories', 'avail_types', 'product_types', 'warehouse_customer_id'));
         cw_core_process_date_fields($posted_data, $date_fields, $multiple_fields);
         $search_data = $posted_data;
         $search_data['sort_direction'] = $sort_direction;
         $search_data['limit'] = SEARCH_LIMIT_FOR_AUTOCOMPLETE;
         $search_data['flat_search'] = 1;
         $info_type = 0;
         list($products, $navigation, $product_filter) = cw_func_call('cw_product_search', array('data' => $search_data, 'user_account' => $user_account, 'current_area' => 'A', 'info_type' => $info_type));
         $result = array();
         if (is_array($products) && count($products)) {
             foreach ($products as $product) {
                 $result[] = array('id' => $product['product_id'], 'name' => $product['product']);