<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*****************************************************************************
 * The contents of this file are subject to the RECIPROCAL PUBLIC LICENSE
 * Version 1.1 ("License"); You may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 * http://opensource.org/licenses/rpl.php. Software distributed under the
 * License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
 * either express or implied.
 *
 * You may:
 * a) Use and distribute this code exactly as you received without payment or
 *    a royalty or other fee.
 * b) Create extensions for this code, provided that you make the extensions
 *    publicly available and document your modifications clearly.
 * c) Charge for a fee for warranty or support or for accepting liability
 *    obligations for your customers.
 *
 * You may NOT:
 * a) Charge for the use of the original code or extensions, including in
 *    electronic distribution models, such as ASP (Application Service
 *    Provider).
 * b) Charge for the original source code or your extensions other than a
 *    nominal fee to cover distribution costs where such distribution
 *    involves PHYSICAL media.
 * c) Modify or delete any pre-existing copyright notices, change notices,
 *    or License text in the Licensed Software
 * d) Assert any patent claims against the Licensor or Contributors, or
 *    which would in any way restrict the ability of any third party to use the
 *    Licensed Software.
 *
 * You must:
 * a) Document any modifications you make to this code including the nature of
 *    the change, the authors of the change, and the date of the change.
 * b) Make the source code for any extensions you deploy available via an
 *    Electronic Distribution Mechanism such as FTP or HTTP download.
 * c) Notify the licensor of the availability of source code to your extensions
 *    and include instructions on how to acquire the source code and updates.
 * d) Grant Licensor a world-wide, non-exclusive, royalty-free license to use,
 *    reproduce, perform, modify, sublicense, and distribute your extensions.
 *
 * The Original Code is: CommuniCore
 *                       Olavo Farias
 *                       2006-04-7 olavo.farias@gmail.com
 *
 * The Initial Developer of the Original Code is CommuniCore.
 * Portions created by CommuniCore are Copyright (C) 2005 CommuniCore Ltda
 * All Rights Reserved.
 ********************************************************************************/
include("modules/EcmProducts/moduleMenu.php");

// INCLUDE SUPPPORT MODULES
   require_once('XTemplate/xtpl.php');
   require_once('data/Tracker.php');

// INCLUDE MODULE OBJECT AND FORMS
   require_once('modules/EcmProducts/EcmProduct.php');
   require_once('modules/EcmProducts/Forms.php');
   
   global $app_strings;
   global $mod_strings;
   global $mod_strings;
   global $current_user;
   global $sugar_version, $sugar_config;
   global $db;
   
// INSTANTIATES THE MODULE CLASSES  
   $focus       = new EcmProduct();
   
// IF PROCESSING AN EXISTING RECORD, RETRIEVE IT  
   if(isset($_REQUEST['record'])) {
    $focus->retrieve($_REQUEST['record']);
    $focus->format_all_fields();
   }
   if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
   	$focus->id             = "";
   	$focus->simplemodule_number = "";
   }
   
   $prefillArray = array(
          'priority'	    => 'priority',
   					  'name'     	 	 => 'name',
   					  'description'  => 'description',
   					  'status' 	 	   => 'status',
   					  'type' 	 	     => 'type',
    					);
   
   foreach($prefillArray as $requestKey => $focusVar) {
    if (isset($_REQUEST[$requestKey]) && is_null($focus->$focusVar)) {
     $focus->$focusVar = urldecode($_REQUEST[$requestKey]);
    }
   }
   
// BUILD MODULE TITLE LINE  
   echo "\n<p>\n";
   echo get_module_title($mod_strings['LBL_MODULE_ID'], $mod_strings['LBL_MODULE_NAME'].": ".$focus->name, true);
   echo "\n</p>\n";

   global $theme;
   $theme_path = "themes/".$theme."/";
   $image_path = $theme_path."images/";
   require_once ($theme_path.'layout_utils.php');
   
   $GLOBALS['log']->info("EcmProducts detail view");
   
// ASSIGN XTEMPLATE
   $xtpl = new XTemplate ('modules/EcmProducts/EditView.html');

// FILL XTEMPLATE MODULE & APPLICATION LANGUAGE STRINGS
   $xtpl->assign("MOD",                  $mod_strings);
   $xtpl->assign("APP",                  $app_strings);
   $xtpl->assign("CALENDAR_DATEFORMAT",  $timedate->get_cal_date_format());
   
   if (isset($_REQUEST['return_module'])) $xtpl->assign("RETURN_MODULE", $_REQUEST['return_module']);
   if (isset($_REQUEST['return_action'])) $xtpl->assign("RETURN_ACTION", $_REQUEST['return_action']);
   if (isset($_REQUEST['return_id']))     $xtpl->assign("RETURN_ID",     $_REQUEST['return_id']);
   
   if (empty($_REQUEST['return_id'])) {
   	$xtpl->assign("RETURN_ACTION", 'index');
   }
   
///////////////////////////////////////
// SETUP POPUPS START
// Users Popup
   $json               = getJSONobj();
   $popup_request_data = array(
   	'call_back_function'  => 'set_return',
   	'form_name'           => 'EditView',
   	'field_to_name_array' => array(
   		'id'        => 'assigned_user_id',
   		'user_name' => 'assigned_user_name',
   		),
   	);
   $xtpl->assign('encoded_users_popup_request_data', $json->encode($popup_request_data));
   
   $popup_request_data = array(
   	'call_back_function'  => 'set_return',
   	'form_name'           => 'EditView',
   	'field_to_name_array' => array(
   		'id'        => 'product_category_id',
   		'name' => 'product_category',
   		),
   	);
   $xtpl->assign('encoded_ecmproductcategories_popup_request_data', $json->encode($popup_request_data));
   
   $popup_request_data = array(
   	'call_back_function'  => 'set_return',
   	'form_name'           => 'EditView',
   	'field_to_name_array' => array(
   		'id'        => 'product_line_id',
   		'name' => 'product_line',
   		),
   	);
   $xtpl->assign('encoded_ecmproductlines_popup_request_data', $json->encode($popup_request_data));
   
   $popup_request_data = array(
   	'call_back_function'  => 'set_return',
   	'form_name'           => 'EditView',
   	'field_to_name_array' => array(
   		'id'        => 'exchange_rate_id',
   		'name' => 'exchange_rate_name',
   		),
   	);
   $xtpl->assign('encoded_ecmproductexchangerates_popup_request_data', $json->encode($popup_request_data));
   
   $popup_request_data = array(
   	'call_back_function'  => 'set_return',
   	'form_name'           => 'EditView',
   	'field_to_name_array' => array(
   		'id'        => 'vat_id',
   		'name' => 'vat_name',
   		),
   	);
   $xtpl->assign('encoded_ecmvats_popup_request_data', $json->encode($popup_request_data));
   
   $popup_request_data = array(
   	'call_back_function'  => 'set_return',
   	'form_name'           => 'EditView',
   	'field_to_name_array' => array(
   		'id'        => 'usage_unit_id',
   		'name' => 'usage_unit_name',
   		),
   	);
   $xtpl->assign('encoded_ecmproductusageunits_popup_request_data', $json->encode($popup_request_data));
   
   $popup_request_data = array(
   	'call_back_function'  => 'set_return',
   	'form_name'           => 'EditView',
   	'field_to_name_array' => array(
   		'id'        => 'manufacturer_id',
   		'name' => 'manufacturer',
   		),
   	);
   $xtpl->assign('encoded_ecmproductmanufacturers_popup_request_data', $json->encode($popup_request_data));
   
   $popup_request_data = array(
   	'call_back_function'  => 'set_return',
   	'form_name'           => 'EditView',
   	'field_to_name_array' => array(
   		'id'        => 'fob_basis_id',
   		'name' => 'fob_basis_name',
   		),
   	);
   $xtpl->assign('encoded_ecmproductbasis_popup_request_data', $json->encode($popup_request_data));
   
   $popup_request_data = array(
   	'call_back_function'  => 'set_return',
   	'form_name'           => 'EditView',
   	'field_to_name_array' => array(
   		'id'        => 'packing_type_id',
   		'name' => 'packing_type_name',
   		),
   	);
   $xtpl->assign('encoded_ecmproductpackingtypes_popup_request_data', $json->encode($popup_request_data));
   
   $popup_request_data = array(
   	'call_back_function'  => 'set_return',
   	'form_name'           => 'EditView',
   	'field_to_name_array' => array(
   		'id'        => 'contact_id',
   		'name' => 'contact_name',
   		),
   	);
   $xtpl->assign('encoded_contacts_popup_request_data', $json->encode($popup_request_data));
   
   $popup_request_data = array(
   	'call_back_function'  => 'set_return',
   	'form_name'           => 'EditView',
   	'field_to_name_array' => array(
   		'id'        => 'parent_id',
   		'name' => 'parent_name',
   		),
   	);
   $xtpl->assign('encoded_parent_popup_request_data', $json->encode($popup_request_data));
   
   $popup_request_data = array(
   	'call_back_function'  => 'set_return',
   	'form_name'           => 'EditView',
   	'field_to_name_array' => array(
   		'id'        => 'vendor_id',
   		'name' => 'vendor_name',
   		),
   	);
   $xtpl->assign('encoded_ecmvendors_popup_request_data', $json->encode($popup_request_data));
//
////////////////////////////////////////////////////////////////////////////////
   
   
// ACCOUNT_ID WILL BE SET WHEN USER CHOOSES TO CREATE A NEW SIMPLEMODULE FROM ACCOUNT DETAIL VIEW.
   if (isset($_REQUEST['account_id'])) $xtpl->assign("ACCOUNT_ID", $_REQUEST['account_id']);
   if (isset($_REQUEST['contact_id'])) $xtpl->assign("CONTACT_ID", $_REQUEST['contact_id']);
   
// SET THE CASE_ID, IF SET.
// WITH NEW CONCEPT OF SUBPANELS IT, 
// WHEN THE SUBPANEL IS DISPLAYED IT PULLS FROM THE CLASS NAME WHICH IN THE SITUATION OF CASES IS ACASE SO THE FORM IS GENERATED
// WITH ACASE_ID INSTEAD OF CASE_ID, SO I HAVE DONE THE MAPPING HERE
   if (isset($_REQUEST['acase_id']))    $xtpl->assign("CASE_ID",$_REQUEST['acase_id']);
   else if(isset($_REQUEST['case_id'])) $xtpl->assign("CASE_ID",$_REQUEST['case_id']);

////////////////////////////////////////////////////////////////////////////////
// QUICK SEARCH SETUP
   require_once('include/QuickSearchDefaults.php');
   $qsd = new QuickSearchDefaults();

   $sqs_objects = array(
   'assigned_user_name' => $qsd->getQSUser(),
   'product_category' => array( 
					'method' => 'query',
					'modules' => array('EcmProductCategories'), 
					'group' => 'or', 
					'field_list' => array('name', 'id'), 
					'populate_list' => array('product_category', 'product_category_id'), 
					'conditions' => array(array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')), 
					'order' => 'name', 
					'limit' => '30',
					'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
					),
   'product_line' => array( 
					'method' => 'query',
					'modules' => array('EcmProductLines'), 
					'group' => 'or', 
					'field_list' => array('name', 'id'), 
					'populate_list' => array('product_line', 'product_line_id'), 
					'conditions' => array(array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')), 
					'order' => 'name', 
					'limit' => '30',
					'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
					),
   'exchange_rate_name' => array( 
					'method' => 'query',
					'modules' => array('EcmProductExchangeRates'), 
					'group' => 'or', 
					'field_list' => array('name', 'id'), 
					'populate_list' => array('exchange_rate_name', 'exchange_rate_id'), 
					'conditions' => array(
					array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')
					),
					'order' => 'name', 
					'limit' => '30',
					'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
					),
   'vat_name' => array( 
					'method' => 'query',
					'modules' => array('EcmVats'), 
					'group' => 'or', 
					'field_list' => array('name', 'id'), 
					'populate_list' => array('vat_name', 'vat_id'), 
					'conditions' => array(
					array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')
					),
					'order' => 'name', 
					'limit' => '30',
					'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
					),
   'manufacturer' => array( 
					'method' => 'query',
					'modules' => array('EcmProductManufacturers'), 
					'group' => 'or', 
					'field_list' => array('name', 'id'), 
					'populate_list' => array('manufacturer', 'manufacturer_id'), 
					'conditions' => array(
					array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')
					),
					'order' => 'name', 
					'limit' => '30',
					'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
					),
   'fob_basis_name' => array( 
					'method' => 'query',
					'modules' => array('EcmProductBasis'), 
					'group' => 'or', 
					'field_list' => array('name', 'id'), 
					'populate_list' => array('fob_basis_name', 'fob_basis_id'), 
					'conditions' => array(
					array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')
					),
					'order' => 'name', 
					'limit' => '30',
					'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
					),
   'packing_type_name' => array( 
					'method' => 'query',
					'modules' => array('EcmProductPackingTypes'), 
					'group' => 'or', 
					'field_list' => array('name', 'id'), 
					'populate_list' => array('packing_type_name', 'packing_type_id'), 
					'conditions' => array(
					array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')
					),
					'order' => 'name', 
					'limit' => '30',
					'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
					),
   'contact_name' => array( 
					'method' => 'query',
					'modules' => array('Contacts'), 
					'group' => 'or', 
					'field_list' => array('name', 'id'), 
					'populate_list' => array('contact_name', 'contact_id'), 
					'conditions' => array(
					array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')
					),
					'order' => 'name', 
					'limit' => '30',
					'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
					),
   'vendor_name' => array( 
					'method' => 'query',
					'modules' => array('EcmVendors'), 
					'group' => 'or', 
					'field_list' => array('name', 'id'), 
					'populate_list' => array('vendor_name', 'vendor_id'), 
					'conditions' => array(
					array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')
					),
					'order' => 'name', 
					'limit' => '30',
					'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
					),
   'product_index' => array( 
					'method' => 'query',
					'modules' => array('EcmProducts'), 
					'group' => 'or', 
					'field_list' => array('product_index', 'id'), 
					'populate_list' => array('product_index', 'index_id'), 
					'conditions' => array(
					array('name'=>'product_index','op'=>'like_custom','end'=>'%','value'=>'')
					),
					'order' => 'product_index', 
					'limit' => '30',
					'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
					),
   );
   $quicksearch_js  = $qsd->getQSScripts();
   $quicksearch_js .= '<script type="text/javascript" language="javascript">sqs_objects = ' . $json->encode($sqs_objects) . '</script>';
// QUICK SEARCH SETUP
////////////////////////////////////////////////////////////////////////////////
   
////////////////////////////////////////////////////////////////////////////////
// ASSIGN GLOBAL VARIABLES
   $ptype='<option value="Accounts"';
   if($focus->parent_type=="Accounts")$ptype.=" selected";
   $ptype.='>Accounts</option><option value="Leads"';
   if($focus->parent_type=="Leads")$ptype.=" selected";
   $ptype.='>Leads</option>';

   $focus->parent_type=$ptype;

   $uunit='';
   $result = $db->query("select id,name from ecmproductusageunits order by name asc");
   while(($row=$db->fetchByAssoc($result))!=null)
   {
		$uunit.='<option value="'.$row['id'].'"';
		if($focus->usage_unit_id==$row['id'])$uunit.=' selected';
		$uunit.='>'.$row['name'].'</option>';
   }
   
   $focus->usage_unit_id=$uunit;

   $tax='';
   $result = $db->query("select id,name from ecmvats where deleted='0' order by name asc");
   while(($row=$db->fetchByAssoc($result))!=null)
   {
		$tax.='<option value="'.$row['id'].'"';
		if($focus->vat_id==$row['id'])$tax.=' selected';
		$tax.='>'.$row['name'].'</option>';
   }
   
   $focus->vat_id=$tax;

   $fbas='';
   $result = $db->query("select id,name from ecmproductbasis order by name asc");
   while(($row=$db->fetchByAssoc($result))!=null)
   {
		$fbas.='<option value="'.$row['id'].'"';
		if($focus->fob_basis_id==$row['id'])$fbas.=' selected';
		$fbas.='>'.$row['name'].'</option>';
   }
   
   $focus->fob_basis_id=$fbas;

   $pack='';
   $result = $db->query("select id,name from ecmproductpackingtypes order by name asc");
   while(($row=$db->fetchByAssoc($result))!=null)
   {
		$pack.='<option value="'.$row['id'].'"';
		if($focus->packing_type_id==$row['id'])$pack.=' selected';
		$pack.='>'.$row['name'].'</option>';
   }
   
   $focus->packing_type_id=$pack;
   
   $xtpl->assign("THEME",               $theme);
   $xtpl->assign("IMAGE_PATH",          $image_path);$xtpl->assign("PRINT_URL", "index.php?".$GLOBALS['request_string']);
   $xtpl->assign("JAVASCRIPT",          get_set_focus_js().get_validate_record_js(). $quicksearch_js);
   $xtpl->assign("USER_DATEFORMAT", '('. $timedate->get_user_date_format().')');
   $xtpl->assign("CALENDAR_DATEFORMAT",  $timedate->get_cal_date_format());
   
   
   
// ASSIGN GLOBAL VARIABLES
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// ASSIGN MODULE DEFAULT VARIABLES
   $xtpl->assign("ID",                $focus->id);
   if (!empty($focus->name)) 
        $xtpl->assign("NAME",         $focus->name);
   else $xtpl->assign("NAME",         "");
   $xtpl->assign("DATE_ENTERED",      $focus->date_entered);
   $xtpl->assign("DATE_MODIFIED",     $focus->date_modified);
   $xtpl->assign("CREATED_BY",        $focus->created_by_name);
   $xtpl->assign("MODIFIED_BY",       $focus->modified_by_name);

   if (empty($focus->assigned_user_id) && empty($focus->id))  $focus->assigned_user_id   = $current_user->id;
   if (empty($focus->assigned_name)    && empty($focus->id))  $focus->assigned_user_name = $current_user->user_name;
   $xtpl->assign("ASSIGNED_USER_OPTIONS",    get_select_options_with_id(get_user_array(TRUE, "Active", $focus->assigned_user_id), $focus->assigned_user_id));
   $xtpl->assign("ASSIGNED_USER_NAME",       $focus->assigned_user_name);
   $xtpl->assign("ASSIGNED_USER_ID",         $focus->assigned_user_id );
   
// ASSIGN MODULE SPECIFIC VARIABLES 


	$xtpl->assign("PARENT_TYPE",$ptype);
	

    $xtpl->assign("CODE",   $focus->code);


    $xtpl->assign("PRODUCT_CATEGORY_ID",   $focus->product_category_id);


    $xtpl->assign("PRODUCT_CATEGORY",   $focus->product_category);


    $xtpl->assign("PRODUCT_LINE_ID",   $focus->product_line_id);


    $xtpl->assign("PRODUCT_LINE",   $focus->product_line);


    $xtpl->assign("MANUFACTURER_ID",   $focus->manufacturer_id);


    $xtpl->assign("MANUFACTURER",   $focus->manufacturer);


    $xtpl->assign("CONTACT_ID",   $focus->contact_id);


    $xtpl->assign("CONTACT_NAME",   $focus->contact_name);


    $xtpl->assign("VENDOR_ID",   $focus->vendor_id);


    $xtpl->assign("VENDOR_NAME",   $focus->vendor_name);


    $xtpl->assign("VENDOR_PART_NO",   $focus->vendor_part_no);
    if (!empty($_REQUEST['product_active'])) {
    $xtpl->assign("PRODUCT_ACTIVE", "checked");
    }


if ($focus->product_active == '1') $xtpl->assign("PRODUCT_ACTIVE", "checked");


    $xtpl->assign("SALES_START_DATE",   $focus->sales_start_date);


    $xtpl->assign("SALES_END_DATE",   $focus->sales_end_date);


    $xtpl->assign("PARENT_TYPE",   $focus->parent_type);


    $xtpl->assign("PARENT_ID",   $focus->parent_id);


    $xtpl->assign("PARENT_NAME",   $focus->parent_name);


    $xtpl->assign("WEBSITE",   $focus->website);


    $xtpl->assign("PART_NO",   $focus->part_no);


    $xtpl->assign("SERIAL_NO",   $focus->serial_no);


    $xtpl->assign("EXCHANGE_RATE_ID",   $focus->exchange_rate_id);


    $xtpl->assign("EXCHANGE_RATE_NAME",   $focus->exchange_rate_name);


    $xtpl->assign("FOB_PRICE",   $focus->fob_price);


    $xtpl->assign("PURCHASE_PRICE",   $focus->purchase_price);


    $xtpl->assign("SELLING_PRICE",   $focus->selling_price);


    $xtpl->assign("EMS_ORDERED",   $focus->ems_ordered);


    $xtpl->assign("EMS_PRICE",   $focus->ems_price);


    $xtpl->assign("COMMISSION_RATE",   $focus->commission_rate);


    $xtpl->assign("CUSTOM_DUTY_RATE",   $focus->custom_duty_rate);


    $xtpl->assign("SRP_PRICE",   $focus->srp_price);


    $xtpl->assign("SRP_PROMO_PRICE",   $focus->srp_promo_price);


    $xtpl->assign("VAT_ID",   $focus->vat_id);


    $xtpl->assign("TAX_CLASS_NAME",   $focus->tax_class_name);


    $xtpl->assign("USAGE_UNIT_ID",   $focus->usage_unit_id);


    $xtpl->assign("USAGE_UNIT_NAME",   $focus->usage_unit_name);


    $xtpl->assign("QTY_IN_STOCK",   $focus->qty_in_stock);


    $xtpl->assign("QTY_IN_DEMAND",   $focus->qty_in_demand);


    $xtpl->assign("EMS_QTY_IN_STOCK",   $focus->ems_qty_in_stock);


    $xtpl->assign("REORDER_LEVEL",   $focus->reorder_level);


    $xtpl->assign("SALES_LAST_MONTH_1",   $focus->sales_last_month_1);


    $xtpl->assign("SALES_LAST_MONTH",   $focus->sales_last_month);


    $xtpl->assign("SALES_THIS_MONTH",   $focus->sales_this_month);


    $xtpl->assign("QTY_PER_UNIT",   $focus->qty_per_unit);


    $xtpl->assign("AVERAGE_SALE_3_MONTHS",   $focus->average_sale_3_months);


    $xtpl->assign("SALES_PLUS_1",   $focus->sales_plus_1);


    $xtpl->assign("SALES_PLUS_2",   $focus->sales_plus_2);


    $xtpl->assign("SALES_PLUS_3",   $focus->sales_plus_3);


    $xtpl->assign("PRODUCT_PICTURE",   $focus->product_picture);
	if($focus->product_picture)$xtpl->assign("PRODUCT_PICTURE_UPLOAD",$mod_strings['LBL_UPLOADED']);


    $xtpl->assign("PACKING_FRONT_PICTURE",   $focus->packing_front_picture);
	if($focus->packing_front_picture)$xtpl->assign("PACKING_FRONT_PICTURE_UPLOAD",$mod_strings['LBL_UPLOADED']);


    $xtpl->assign("DRIVER_1",   $focus->driver_1);
	if($focus->driver_1)$xtpl->assign("DRIVER_1_UPLOAD",$mod_strings['LBL_UPLOADED']);


    $xtpl->assign("DRIVER_2",   $focus->driver_2);
	if($focus->driver_2)$xtpl->assign("DRIVER_2_UPLOAD",$mod_strings['LBL_UPLOADED']);


    $xtpl->assign("MOQ",   $focus->moq);


    $xtpl->assign("FOB_BASIS_ID",   $focus->fob_basis_id);


    $xtpl->assign("FOB_BASIS_NAME",   $focus->fob_basis_name);


    $xtpl->assign("DELIVERY_TIME_FOB",   $focus->delivery_time_fob);


    $xtpl->assign("PIECES_PER_CARTON",   $focus->pieces_per_carton);


    $xtpl->assign("PRODUCT_NETTO_WEIGHT",   $focus->product_netto_weight);


    $xtpl->assign("PRODUCT_BRUTTO_WEIGHT",   $focus->product_brutto_weight);


    $xtpl->assign("PACKING_TYPE_ID",   $focus->packing_type_id);


    $xtpl->assign("PACKING_TYPE_NAME",   $focus->packing_type_name);


    $xtpl->assign("PACKING_DIMENSIONS_1",   $focus->packing_dimensions_1);


    $xtpl->assign("PACKING_DIMENSIONS_2",   $focus->packing_dimensions_2);


    $xtpl->assign("PACKING_DIMENSIONS_3",   $focus->packing_dimensions_3);


    $xtpl->assign("RMA",   $focus->rma);


    $xtpl->assign("CARTON_DIMENSIONS_1",   $focus->carton_dimensions_1);


    $xtpl->assign("CARTON_DIMENSIONS_2",   $focus->carton_dimensions_2);


    $xtpl->assign("CARTON_DIMENSIONS_3",   $focus->carton_dimensions_3);


    $xtpl->assign("CARTON_NETTO_WEIGHT",   $focus->carton_netto_weight);


    $xtpl->assign("CARTON_BRUTTO_WEIGHT",   $focus->carton_brutto_weight);


    $xtpl->assign("CARTON_VOLUME_METER",   $focus->carton_volume_meter);


    $xtpl->assign("CARTON_VOLUME_FEET",   $focus->carton_volume_feet);


    $xtpl->assign("COUNTRY_OF_ORIGIN",   $focus->country_of_origin);
    if (!empty($_REQUEST['certificate_of_origin'])) {
    $xtpl->assign("CERTIFICATE_OF_ORIGIN", "checked");
    }
	
	$xtpl->assign("TAX_CLASS_ID",get_select_options_with_id($app_list_strings['ecmproducts_vat_dom'], $focus->vat_id));
	//load currencies
    require_once('modules/Currencies/Currency.php');
    $currency = new Currency();
    $currency_list = $currency->get_full_list('name');
    $currency->retrieve('-99');
    if(is_array($currency_list))
	{
    	$currency_list = array_merge(Array($currency), $currency_list);
    }
	else
	{
   		$currency_list = Array($currency); 
    } 
    $arr = array();
    foreach($currency_list as $key=>$value)
	{
    	$arr[$value->id] = $value->name;
    } 
    $xtpl->assign("EXCHANGE_RATE_ID", get_select_options_with_id($arr, $focus->exchange_rate_id));


if ($focus->certificate_of_origin == '1') $xtpl->assign("CERTIFICATE_OF_ORIGIN", "checked");
    if (!empty($_REQUEST['form_a'])) {
    $xtpl->assign("FORM_A", "checked");
    }


if ($focus->form_a == '1') $xtpl->assign("FORM_A", "checked");
 
// ASSIGN MODULE DROPDOWNS WITH DEFAULT KEY
   
// ASSIGN MODULE VARIABLES AFFECTED BY DUPLICATE ACTION   
   if(!isset($_REQUEST['isDuplicate'])) {
    $focus->id = "";
   }

   $result = $db->query("select ean,remarks,short_description,long_description,language from ecmproduct_language where ecmproduct_id='".$_REQUEST['record']."'");
   while(($row=$db->fetchByAssoc($result))!=null)
   {
   		$xtpl->assign("EAN_".strtolower($row['language']),$row['ean']);
   		$xtpl->assign("REMARKS_".strtolower($row['language']),$row['remarks']);
   		$xtpl->assign("SHORT_DESCRIPTION_".strtolower($row['language']),$row['short_description']);
   		$xtpl->assign("LONG_DESCRIPTION_".strtolower($row['language']),$row['long_description']);
   }

// ASSIGN MODULE DROPDOWNS WITHOUT DEFAULT KEY

//BUILDER:END of xtpl

// ADD CUSTOM FIELDS
   require_once('modules/DynamicFields/templates/Files/EditView.php');

////////////////////////////////////////////////////////////////////////////////
// USER ASSIGNMENT
   global $current_user;
   if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
   	$record = '';
// USER ASSIGNMENT
////////////////////////////////////////////////////////////////////////////////

   	if(!empty($_REQUEST['record'])){
   		$record = 	$_REQUEST['record'];
   	}
   	$xtpl->assign("ADMIN_EDIT","<a href='index.php?action=index&module=DynamicLayout&from_action=".$_REQUEST['action'] ."&from_module=".$_REQUEST['module'] ."&record=".$record. "'>".get_image($image_path."EditLayout","border='0' alt='Edit Layout' align='bottom'")."</a>");
   }

   
   
   $xtpl->parse("main");
   $xtpl->out("main");
   require_once('include/javascript/javascript.php');
   $javascript = new javascript();
   $javascript->setFormName('EditView');
   $javascript->setSugarBean($focus);
   $javascript->addAllFields('');

//BUILDER:START Pro only 
//   $javascript->addFieldGeneric(              'team_name',          'varchar', $app_strings['LBL_TEAM'] ,'true');
//   $javascript->addToValidateBinaryDependency('team_name',          'alpha',   $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_TEAM'],        'false', '', 'team_id');
//BUILDER:END Pro only 

   $javascript->addToValidateBinaryDependency('assigned_user_name', 'alpha',   $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ASSIGNED_TO'], 'false', '', 'assigned_user_id');
   
   echo $javascript->getScript();
   
////////////////////////////////////////////////////////////////////////////////
/// SELECT CHANGES TEXT INPUT FIELD
/*
    $prob_array = $json->encode($app_list_strings['sales_probability_dom']);
    $prePopProb = '';
    if(empty($focus->id)) $prePopProb = 'document.getElementsByName(\'sales_stage\')[0].onchange();';
    echo <<<EOQ
    	<script>
    	prob_array = $prob_array;
    	document.getElementsByName('sales_stage')[0].onchange = function() {
    			if(typeof(document.getElementsByName('sales_stage')[0].value) != "undefined" && prob_array[document.getElementsByName('sales_stage')[0].value]) {
    				document.getElementsByName('probability')[0].value = prob_array[document.getElementsByName('sales_stage')[0].value];
    			} 
    		};
    	$prePopProb
    	</script>
EOQ;
*/
//
/// SELECT CHANGES TEXT INPUT FIELD
////////////////////////////////////////////////////////////////////////////////
   require_once('modules/SavedSearch/SavedSearch.php');
   $savedSearch        = new SavedSearch();
   $json               = getJSONobj();
   $savedSearchSelects = $json->encode(array($GLOBALS['app_strings']['LBL_SAVED_SEARCH_SHORTCUT'] . '<br>' . $savedSearch->getSelect('EcmProducts')));
   $str = "<script>
   YAHOO.util.Event.addListener(window, 'load', SUGAR.util.fillShortcuts, $savedSearchSelects);
   </script>";
   echo $str;

?>