/**
  * Show the window to configure an item (variations, configurable fields) etc in the
  * order that's being created/edited.
  */
 private function OrderConfigureProduct()
 {
     if (!isset($_REQUEST['cartItemId']) || !isset($_REQUEST['orderSession'])) {
         exit;
     }
     // Initialize the cart management API
     $orderClass = GetClass('ISC_ADMIN_ORDERS');
     $orderClass->GetCartApi($_REQUEST['orderSession']);
     $existingProduct = $orderClass->GetCartApi()->GetProductInCart($_REQUEST['cartItemId']);
     if (is_array($existingProduct)) {
         if (isset($_REQUEST['productId']) && $existingProduct['product_id'] != $_REQUEST['productId']) {
             $existingProduct = false;
         } else {
             $_REQUEST['productId'] = $existingProduct['product_id'];
         }
     }
     // Fetch the product class on the front end as it'll be doing most of the work for this page
     $productClass = new ISC_PRODUCT($_REQUEST['productId']);
     if (!$productClass->GetProductId()) {
         exit;
     }
     if (!is_array($existingProduct) && !isset($_REQUEST['productId'])) {
         exit;
     } else {
         if (is_array($existingProduct)) {
             $GLOBALS['EditingExistingProduct'] = 1;
             $GLOBALS['Intro'] = GetLang('OrderConfigureProductEdit');
             $GLOBALS['ButtonLabel'] = GetLang('OrderConfigureProductEditButton');
             $productPrice = $existingProduct['product_price'];
             $GLOBALS['VariationId'] = $existingProduct['variation_id'];
         } else {
             $GLOBALS['Intro'] = GetLang('OrderConfigureProduct');
             $GLOBALS['ButtonLabel'] = GetLang('AddProductToOrder');
             // Finally, determine the price based on the customer group
             $product = $productClass->GetProduct();
             $productPrice = CalcProdCustomerGroupPrice($product, $product['prodcalculatedprice']);
         }
     }
     $GLOBALS['ProductPrice'] = FormatPrice($productPrice);
     $productVariations = $productClass->GetProductVariations();
     $GLOBALS['ProductName'] = isc_html_escape($productClass->GetProductName());
     $GLOBALS['ProductId'] = (int) $productClass->GetProductId();
     $GLOBALS['OrderSession'] = isc_html_escape($_REQUEST['orderSession']);
     $GLOBALS['CartItemId'] = isc_html_escape($_REQUEST['cartItemId']);
     $GLOBALS['Quantity'] = (int) $_REQUEST['quantity'];
     $GLOBALS['ProductOptionRequired'] = 0;
     $GLOBALS['VariationList'] = '';
     if (!empty($productVariations)) {
         // If we have an existing variation already, look up the combination
         $existingCombination = array();
         if (is_array($existingProduct) && $existingProduct['variation_id']) {
             $query = "\n\t\t\t\t\t\tSELECT vcoptionids\n\t\t\t\t\t\tFROM [|PREFIX|]product_variation_combinations\n\t\t\t\t\t\tWHERE combinationid='" . (int) $existingProduct['variation_id'] . "'\n\t\t\t\t\t";
             $existingCombination = explode(',', $GLOBALS['ISC_CLASS_DB']->FetchOne($query));
         }
         if ($productClass->IsOptionRequired()) {
             $GLOBALS['ProductOptionRequired'] = 1;
             $GLOBALS['VariationRequired'] = '*';
         } else {
             $GLOBALS['VariationRequired'] = ' ';
         }
         $GLOBALS['VariationNumber'] = 0;
         foreach ($productVariations as $name => $options) {
             $GLOBALS['VariationNumber']++;
             $optionList = '';
             foreach ($options as $option) {
                 $sel = '';
                 if (in_array($option['voptionid'], $existingCombination)) {
                     $sel = 'selected="selected"';
                 }
                 $optionList .= '<option value="' . $option['voptionid'] . '" ' . $sel . '>' . isc_html_escape($option['vovalue']) . '</option>';
             }
             $GLOBALS['VariationOptions'] = $optionList;
             $GLOBALS['VariationName'] = isc_html_escape($name);
             $GLOBALS['VariationList'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('OrderProductConfigurationVariation');
         }
         $GLOBALS['ProductVariationJavascript'] = $productClass->GetProductVariationCombinationJavascript();
     } else {
         $GLOBALS['HideVariationList'] = 'display: none';
     }
     $fields = $productClass->GetProductFields($_REQUEST['productId']);
     $GLOBALS['ProductFields'] = '';
     if (!empty($fields)) {
         foreach ($fields as $field) {
             $GLOBALS['FieldId'] = $field['id'];
             $GLOBALS['FieldRequired'] = '&nbsp;';
             $requiredClass = '';
             $GLOBALS['FieldName'] = isc_html_escape($field['name']) . ':';
             $GLOBALS['HideFieldHelp'] = 'display: none';
             $GLOBALS['FieldHelp'] = '';
             $GLOBALS['HideFileCurrentValue'] = 'display: none';
             $existingValue = '';
             if (isset($existingProduct['product_fields'][$field['id']])) {
                 if ($field['type'] == 'file') {
                     $existingValue = isc_html_escape($existingProduct['product_fields'][$field['id']]['fileOriginName']);
                     $existingFileName = $existingProduct['product_fields'][$field['id']]['fileName'];
                 } else {
                     $existingValue = isc_html_escape($existingProduct['product_fields'][$field['id']]['fieldValue']);
                 }
             }
             if ($field['required'] == 1) {
                 $requiredClass = 'FieldRequired';
                 $GLOBALS['FieldRequired'] = '*';
             }
             switch ($field['type']) {
                 case 'textarea':
                     $inputField = '<textarea cols="30" rows="3" name="productFields[' . $field['id'] . ']" class="Field300 ' . $requiredClass . '">' . $existingValue . '</textarea>';
                     break;
                 case 'file':
                     if ($existingValue) {
                         $requiredClass .= 'HasExistingValue';
                     }
                     $inputField = '<input type="file" name="productFields[' . $field['id'] . ']" class="Field300 ' . $requiredClass . '" />';
                     $help = array();
                     if ($field['fileSize'] > 0) {
                         $help[] = GetLang('MaximumSize') . ': ' . NiceSize($field['fileSize'] * 1024);
                     }
                     if ($field['fileType'] != '') {
                         $help[] = GetLang('AllowedTypes') . ': ' . '<span class="FileTypes">' . isc_strtoupper(isc_html_escape($field['fileType']) . '</span>');
                     }
                     $help = implode('. ', $help);
                     if ($help != '') {
                         $GLOBALS['HideFieldHelp'] = '';
                         $GLOBALS['FieldHelp'] = '<em>(' . $help . ')</em>';
                     }
                     if ($existingValue) {
                         $GLOBALS['HideFileCurrentValue'] = '';
                         if (!$field['required']) {
                             $GLOBALS['HideRemoveFile'] = 'display: none';
                         }
                         $GLOBALS['CurrentFileName'] = $existingValue;
                         if (isset($existingProduct['product_fields'][$field['id']]['fieldExisting'])) {
                             $fileDirectory = 'configured_products';
                         } else {
                             $fileDirectory = 'configured_products_tmp';
                         }
                         $GLOBALS['CurrentFileLink'] = GetConfig('ShopPath') . '/' . GetConfig('ImageDirectory') . '/' . $fileDirectory . '/' . $existingFileName;
                     }
                     break;
                 case 'checkbox':
                     $checked = '';
                     if ($existingValue) {
                         $checked = 'checked="checked"';
                     }
                     $inputField = '<label><input type="checkbox" name="productFields[' . $field['id'] . ']" ' . $checked . ' value="1" /> ' . GetLang('TickToSelect') . '</label>';
                     break;
                 default:
                     $inputField = '<input type="text" name="productFields[' . $field['id'] . ']" class="Field300 ' . $requiredClass . '" value="' . $existingValue . '"/>';
             }
             $GLOBALS['InputField'] = $inputField;
             $GLOBALS['ProductFields'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('OrderProductConfigurationField');
         }
     } else {
         $GLOBALS['HideConfigurableFields'] = 'display: none';
     }
     if ($productClass->GetEventDateRequired() == 1) {
         $this->LoadEventDate($productClass, $existingProduct);
     } else {
         $GLOBALS['EventDate'] = '';
         $GLOBALS['HideEventDate'] = 'display : none;';
     }
     echo $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('OrderProductConfiguration');
     exit;
 }