function insertTreeProducts($category, $view, $focus)
{
    $bean = new oqc_Product();
    // get all products of the desired category
    //	$products = $bean->get_full_list("", "relatedcategory_id='{$category->id}' and publish_state = 'published' and oqc_product.active=1 and is_latest=1 and  is_option=0"); //1.7.6 extra conditions active and is_latest since produst are not deleted
    $products = $bean->get_full_list("", "relatedcategory_id='{$category->id}' and publish_state = 'published' and oqc_product.active=1 and is_latest=1 and is_option=0");
    //2.2RC1 options as products causes logic troubles
    $productitems = array();
    if (!empty($products)) {
        $productsArray = array();
        $counter = range('a', chr(ord('a') + count($products) - 1));
        foreach ($products as $product) {
            $productsArray[] = $product->toArray(true);
        }
        usort($productsArray, 'oqc_compare_catalog_position');
        foreach ($productsArray as $productArray) {
            $optionitems = array();
            if (!empty($productArray['optionssequence'])) {
                $options = get_all_linked_product_options_for_catalog($productArray['optionssequence']);
                $option_counter = range('1', count($options));
                foreach ($options as $option) {
                    $counter_string = $category->number . '.' . current($counter) . '.' . current($option_counter);
                    $children = oqc_getOptionsArray($option->optionssequence, $counter_string, $view, $focus);
                    $optionitems[] = array('key' => $option->id, 'title' => $view === 'DetailView' ? $counter_string . ' ' . $option->name : $option->name, 'children' => $children, 'isProduct' => false, 'isOption' => true, 'isFolder' => !empty($children) ? true : false, 'icon' => empty($children) ? 'Option_empty.gif' : 'Option_notempty.gif', 'description' => from_html($option->description), 'href' => $view === 'DetailView' ? oqc_getProductLink($option->id) : oqc_getProductEditLink($option->id, $focus));
                    next($option_counter);
                }
            }
            $productitems[] = array('key' => $productArray['id'], 'title' => $view === 'DetailView' ? $category->number . '.' . current($counter) . ' ' . $productArray['name'] : $productArray['name'], 'children' => $optionitems, 'isProduct' => true, 'isOption' => false, 'description' => from_html($productArray['description']), 'isFolder' => !empty($optionitems) ? true : false, 'icon' => empty($productArray['optionssequence']) ? 'Product_empty.gif' : 'Product_notempty.gif', 'href' => $view === 'DetailView' ? oqc_getProductLink($productArray['id']) : oqc_getProductEditLink($productArray['id'], $focus));
            //			$GLOBALS['log']->error("product catalog: ". var_export($productitems,true));
            next($counter);
        }
    }
    return $productitems;
}
function get_all_linked_product_options($focus)
{
    $optionsIds = explode(' ', trim($focus->optionssequence));
    $options = array();
    foreach ($optionsIds as $id) {
        $option = new oqc_Product();
        if ($option->retrieve($id)) {
            if ($option->is_latest == 1 || $focus->is_latest == 0) {
                $options[] = $option;
            } else {
                $option = $option->getLatestRevision();
                $options[] = $option;
            }
        }
    }
    return $options;
}
function getProductUsage($id)
{
    $productCatalog = new oqc_ProductCatalog();
    if ($productCatalog->retrieve($id)) {
        $frequency = array();
        $json = getJSONobj();
        $c = new oqc_Contract();
        $result = $c->get_list('', 'deleted=0');
        $allContracts = $result['list'];
        foreach ($allContracts as $contract) {
            // services of this contract
            $services = $contract->get_linked_beans('oqc_service', 'oqc_Service');
            foreach ($services as $service) {
                $product = new oqc_Product();
                // if the service refers to an existing product that is defined in this product catalog ...
                if ($product->retrieve($service->product_id) && $product->catalog_id == $id) {
                    // increase the frequency of the appearance of this product
                    $frequency[$product->name]['rate'] += $service->quantity;
                    if (!array_key_exists('category', $frequency[$product->name])) {
                        $category = new oqc_Category();
                        if ($category->retrieve($product->relatedcategory_id)) {
                            $frequency[$product->name]['category'] = $category->name;
                        }
                    }
                }
            }
        }
        $chartData = array();
        foreach ($frequency as $name => $frequencyArray) {
            $chartData[] = array('name' => $name, 'frequency' => $frequencyArray['rate'], 'category' => $frequencyArray['category']);
        }
        $encoded = $json->encode($chartData);
        echo $encoded;
    } else {
        echo "No Product Catalog with id='" + $id + "' found.";
    }
}
require_once 'modules/oqc_Product/oqc_Product.php';
$p = new oqc_Product();
$field = "oqc_product.packaged_product_ids";
$where = "{$field} IS NOT NULL AND NOT {$field} = ''";
$all = $p->get_list("", $where);
$all = $all['list'];
$url = 'https://' . $sugar_conf['host_name'] . '/index.php?module=oqc_Product&action=DetailView&record=';
foreach ($all as $packet) {
    if ("oqc_Product" === get_class($packet)) {
        // now we can be sure we look on a product instance..
        echo "Paket {$packet->name} <br />";
        $pairs = explode(' ', $packet->packaged_product_ids);
        $newPackagedProductValue = "";
        foreach ($pairs as $pair) {
            list($count, $id) = explode(':', $pair);
            $referencedProduct = new oqc_Product();
            if ($referencedProduct->retrieve($id)) {
                $unique = $referencedProduct->price > 0;
                $recurring = $referencedProduct->price_recurring > 0;
                $append = '';
                if ($unique && $recurring) {
                    $packetUrl = $url . $packet->id;
                    echo "Paket {$packet->name} muss nochmals angefasst werden, da bereits laufende und einmalige Kosten festgelegt sind, siehe {$packetUrl} <br />";
                    continue;
                } else {
                    if ($unique) {
                        $append = "1";
                    } else {
                        if ($recurring) {
                            $append = "0";
                        }
 function insertProducts(&$categories)
 {
     foreach ($categories as &$category) {
         $bean = new oqc_Product();
         //	$products = $bean->get_full_list("", "relatedcategory_id='{$category['id']}' and publish_state = 'published' and oqc_product.active=1 and is_latest=1 and is_option=0"); //1.7.6-2.0 extra conditions active and is_latest since produst are not deleted
         $products = $bean->get_full_list("", "relatedcategory_id='{$category['id']}' and publish_state = 'published' and oqc_product.active=1 and is_latest=1");
         //2.1RC1 Options are shown in pdf file
         //2.0 arrange beans according catalog_position field
         if (!empty($products)) {
             usort($products, array('oqc_Product', 'oqc_product_compare_catalog_position'));
         }
         $category['products'] = $this->beansToArrayWithAttachements($products);
         $this->insertProducts($category['subCategories']);
     }
 }
$jsonArray = array();
if (array_key_exists('id', $_REQUEST)) {
    if (!defined('sugarEntry')) {
        define('sugarEntry', true);
    }
    chdir("..");
    require_once 'include/entryPoint.php';
    require_once 'modules/oqc_Product/oqc_Product.php';
    $originatingProduct = new oqc_Product();
    $id = $_REQUEST['id'];
    // the product id that we search in the packages
    if ($originatingProduct->retrieve($id, true, true)) {
        //Do not proceed for deleted products
        //  $previousVersions = $originatingProduct->getAllPreviousVersions();
        //  $interestingProductIds = array_merge(array($id), $previousVersions);
        $p = new oqc_Product();
        $products = $p->get_list('', 'is_latest = "1"');
        $products = $products['list'];
        // foreach ($interestingProductIds as $productId) {
        // iterate over all products. add those to the jsonArray that are packages containing the product specified by $id
        for ($i = 0; $i < count($products); $i++) {
            if ($products[$i]->containsProductWithId($id)) {
                // package contains the product with given id
                // add its name and id to the packages array
                $jsonArray[] = array("Name" => $products[$i]->name, "Id" => $products[$i]->id);
            }
        }
        //   }
    }
}
require_once 'include/utils.php';
 function get_all_linked_product_options_for_catalog($optionssequence)
 {
     $optionsIds = explode(' ', trim($optionssequence));
     $options = array();
     foreach ($optionsIds as $id) {
         $option = new oqc_Product();
         if ($option->retrieve($id)) {
             if ($option->is_latest == 1) {
                 if ($option->active == 1 && $option->publish_state == 'published') {
                     $options[] = $option;
                 }
             } else {
                 $option = $option->getLatestRevision();
                 if ($option->active == 1 && $option->publish_state == 'published') {
                     $options[] = $option;
                 }
             }
         }
     }
     return $options;
 }
 private function saveCategories($subCategoryArray, $prefix = '', $masterCategory = '')
 {
     if (empty($subCategoryArray)) {
         return array();
     } else {
         //decode tree array into actions that we need to do after tree save
         $subCategoryIds = array();
         $productIds = array();
         $optionSequenceIds = array();
         $updateDescriptionsIds = array();
         foreach ($subCategoryArray as $number => $subCategoryItem) {
             if ($subCategoryItem['isProduct'] && $masterCategory) {
                 $productIds[] = array($subCategoryItem['key'], $subCategoryItem['title'], isset($subCategotyItem['wasActive']) ? true : false);
                 if ($subCategoryItem['children'] != '') {
                     $optionSequenceIds = array_merge($this->saveOptions($subCategoryItem['children'], $subCategoryItem['key'], $updateDescriptionsIds), $optionSequenceIds);
                 }
                 continue;
             }
             // initialize the category correctly if it does not exist yet
             if (($subCategory = oqc_Category::getFromId($subCategoryItem['key'])) == null) {
                 $subCategory = new oqc_Category();
             }
             $subCategory->number = $prefix . ($number + 1);
             $subCategory->name = $subCategoryItem['title'];
             $subCategory->description = isset($_POST['categoryDescription_' . $subCategoryItem['key']]) ? $_POST['categoryDescription_' . $subCategoryItem['key']] : "";
             if ($subCategoryItem['children'] != '') {
                 $subCategory->subcategories = implode(" ", $this->saveCategories($subCategoryItem['children'], $prefix . ($number + 1) . '.', $subCategoryItem['key']));
             } else {
                 $subCategory->subcategories = "";
             }
             $subCategory->catalog_id = $this->bean->id;
             $subCategory->save();
             // put id of this subcategory into the array $subCategoryIds
             if (array_search($subCategory->id, $subCategoryIds) === FALSE) {
                 $subCategoryIds[] = $subCategory->id;
             }
         }
         //2.2RC1 now process Products and options that are in this particular tree level
         //1. update Product descriptions if was Active, update ordering of Products, update title of products is was Active, update Product category (it might be changed is was Active
         //2. For options update ordering string and description if wasActive
         //$GLOBALS['log']->error("product catalog subcategories: ". var_export($subCategoryIds,true));
         //$GLOBALS['log']->error("product catalog products: ". var_export($productIds,true));
         //$GLOBALS['log']->error("product catalog options sequences: ". var_export($optionSequenceIds,true));
         //$GLOBALS['log']->error("product catalog descriptions: ". var_export($updateDescriptionsIds,true));
         if (!empty($productIds)) {
             foreach ($productIds as $number => $productId) {
                 $product = new oqc_Product();
                 if ($product->retrieve($productId[0])) {
                     $product->name = $productId[1];
                     $product->description = isset($_POST['categoryDescription_' . $productId[0]]) ? $_POST['categoryDescription_' . $productId[0]] : "";
                     if (array_key_exists($productId[0], $optionSequenceIds)) {
                         $product->optionssequence = $optionSequenceIds[$productId[0]];
                         unset($optionSequenceIds[$productId[0]]);
                     }
                     $product->catalog_position = $number + 1;
                     $product->relatedcategory_id = $masterCategory;
                     $product->save();
                 }
             }
         }
         if (!empty($optionSequenceIds)) {
             foreach ($optionSequenceIds as $key => $optionSequenceId) {
                 $option = new oqc_Product();
                 if ($option->retrieve($key)) {
                     if (isset($_POST['categoryDescription_' . $key]) && array_search($key, $updateDescriptionsIds)) {
                         $option->description = $_POST['categoryDescription_' . $key];
                         unset($updateDescriptionsIds[array_search($key, $updateDescriptionsIds)]);
                     }
                     if (array_key_exists($key, $optionSequenceIds)) {
                         $option->optionssequence = $optionSequenceIds[$key];
                         unset($optionSequenceIds[$key]);
                     }
                     //	$option->catalog_position = $number+1;
                     //	$option->relatedcategory_id = $key;
                     $option->save();
                 }
             }
         }
         if (!empty($updateDescriptionsIds)) {
             foreach ($updateDescriptionsIds as $updateDescriptionsId) {
                 if (isset($_POST['categoryDescription_' . $updateDescriptionsId])) {
                     $option = new oqc_Product();
                     if ($option->retrieve($updateDescriptionsId)) {
                         $option->description = $_POST['categoryDescription_' . $updateDescriptionsId];
                         //			unset($updateDescriptionsIds[array_search($key ,$updateDescriptionsIds)];
                         $option->save();
                     }
                 }
             }
         }
         return $subCategoryIds;
     }
 }
 require_once "modules/{$moduleName}/{$moduleName}.php";
 $contract = new $moduleName();
 $isUniqueServices = true;
 if (array_key_exists('u', $_REQUEST)) {
     $isUniqueServices = '1' === $_REQUEST['u'];
 }
 if ($contract->retrieve($_REQUEST['id'])) {
     if (!$contract->load_relationship('oqc_service')) {
         trigger_error("could not load relationship to oqc_service. cannot return the services related to this offering/contract!");
     } else {
         $services = $contract->get_linked_beans('oqc_service', 'oqc_Service');
         foreach ($services as $service) {
             if ($isUniqueServices && 'once' === $service->zeitbezug || !$isUniqueServices && 'once' != $service->zeitbezug) {
                 $productDeleted = true;
                 if (!empty($service->product_id)) {
                     $product = new oqc_Product();
                     if ($product->retrieve($service->product_id, true, true)) {
                         //2.2RC1 do not retrieve deleted product here
                         $productDeleted = false;
                     }
                     $updateable = !$product->is_latest && !$productDeleted;
                 } else {
                     $updateable = false;
                 }
                 //check if currency id is correct one
                 $jsonArray[] = array('Id' => $service->id, 'Position' => $service->position, 'Tax' => $service->oqc_vat === '' ? "default" : $service->oqc_vat, 'Name' => $service->name, 'Description' => html_entity_decode($service->description), 'Unit' => $service->unit, 'Price' => getFormattedCurrencyValue($service->price), 'Quantity' => $service->quantity, 'Recurrence' => $service->zeitbezug, 'ProductId' => $productDeleted ? '' : $service->product_id, 'Discount' => $service->discount_select, 'DiscountValue' => $service->discount_value, 'Updateable' => $updateable, 'isSumRow' => false, 'Currency' => $service->service_currency_id ? $service->service_currency_id : "-99");
             }
         }
         // 1.7.7 Do json array reordering according position value
         usort($jsonArray, 'compare_position');
     }
     define('sugarEntry', true);
 }
 chdir("..");
 require_once 'include/entryPoint.php';
 require_once 'include/oqc/common/common.php';
 // required for getFormattedCurrencyValue method
 require_once 'modules/oqc_Service/oqc_Service.php';
 require_once "modules/{$moduleName}/{$moduleName}.php";
 require_once 'modules/Currencies/Currency.php';
 $product = new oqc_Product();
 if ($product->retrieve($_REQUEST['id'])) {
     if (!empty($product->packaged_product_ids)) {
         $packaged_product_counts_and_ids = explode(' ', $product->packaged_product_ids);
         foreach ($packaged_product_counts_and_ids as $packaged_product_count_and_id) {
             list($packaged_product_count, $packaged_product_id, $isUnique) = explode(':', $packaged_product_count_and_id);
             $packaged_product = new oqc_Product();
             if ($packaged_product->retrieve($packaged_product_id)) {
                 $currency_id = $packaged_product->currency_id != '' ? $packaged_product->currency_id : '-99';
                 //2.2RC1 send also currency id of the product, if not set, then default currency
                 // Convert price to default currency, if currency_id is set
                 if ($currency_id != '-99') {
                     $currency = new Currency();
                     $currency->retrieve($currency_id);
                     $packaged_product->price = $packaged_product->price / $currency->conversion_rate;
                     //		$packaged_product->price_recurring = $packaged_product->price_recurring / $currency->conversion_rate;
                 }
                 if ($packaged_product->deleted) {
                     $packaged_product->name .= '<br>' . $app_strings['LBL_OQC_PRODUCT_DELETE'];
                 }
                 if (!$packaged_product->active) {
                     $packaged_product->name .= '<br>' . $app_strings['LBL_OQC_PRODUCT_INACTIVE'];
 function display()
 {
     // this is a copy of ViewPopup::display() except the marked region at the bottom. have fun reading it :)
     //////////////////////////////////////////////////////////////////////////////////////////////////
     global $popupMeta, $mod_strings, $sugar_version;
     if (isset($_REQUEST['metadata']) && strpos($_REQUEST['metadata'], "..") !== false) {
         die("Directory navigation attack denied.");
     }
     if (!empty($_REQUEST['metadata']) && $_REQUEST['metadata'] != 'undefined' && file_exists('modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php')) {
         // if custom metadata is requested
         require_once 'modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php';
     } elseif (file_exists('custom/modules/' . $this->module . '/metadata/popupdefs.php')) {
         require_once 'custom/modules/' . $this->module . '/metadata/popupdefs.php';
     } elseif (file_exists('modules/' . $this->module . '/metadata/popupdefs.php')) {
         require_once 'modules/' . $this->module . '/metadata/popupdefs.php';
     }
     if (!empty($popupMeta) && !empty($popupMeta['listviewdefs'])) {
         if (is_array($popupMeta['listviewdefs'])) {
             //if we have an array, then we are not going to include a file, but rather the
             //listviewdefs will be defined directly in the popupdefs file
             $listViewDefs[$this->module] = $popupMeta['listviewdefs'];
         } else {
             //otherwise include the file
             require_once $popupMeta['listviewdefs'];
         }
     } elseif (file_exists('custom/modules/' . $this->module . '/metadata/listviewdefs.php')) {
         require_once 'custom/modules/' . $this->module . '/metadata/listviewdefs.php';
     } elseif (file_exists('modules/' . $this->module . '/metadata/listviewdefs.php')) {
         require_once 'modules/' . $this->module . '/metadata/listviewdefs.php';
     }
     //check for searchdefs as well
     if (!empty($popupMeta) && !empty($popupMeta['searchdefs'])) {
         if (is_array($popupMeta['searchdefs'])) {
             //if we have an array, then we are not going to include a file, but rather the
             //searchdefs will be defined directly in the popupdefs file
             $searchdefs[$this->module]['layout']['advanced_search'] = $popupMeta['searchdefs'];
         } else {
             //otherwise include the file
             require_once $popupMeta['searchdefs'];
         }
     } else {
         if (empty($searchdefs) && file_exists('modules/' . $this->module . '/metadata/searchdefs.php')) {
             require_once 'modules/' . $this->module . '/metadata/searchdefs.php';
         }
     }
     if (!empty($this->bean) && isset($_REQUEST[$this->module . '2_' . strtoupper($this->bean->object_name) . '_offset'])) {
         //if you click the pagination button, it will poplate the search criteria here
         if (!empty($_REQUEST['current_query_by_page'])) {
             $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', 'lvso', 'sortOrder', 'orderBy', 'request_data', 'current_query_by_page');
             $current_query_by_page = unserialize(base64_decode($_REQUEST['current_query_by_page']));
             foreach ($current_query_by_page as $search_key => $search_value) {
                 if ($search_key != $this->module . '2_' . strtoupper($this->bean->object_name) . '_offset' && !in_array($search_key, $blockVariables)) {
                     $_REQUEST[$search_key] = $search_value;
                 }
             }
         }
     }
     if (!empty($listViewDefs) && !empty($searchdefs)) {
         //		require_once('include/Popups/PopupSmarty.php');
         $displayColumns = array();
         $filter_fields = array();
         $whereClauses = array();
         $initialFilterClauses = array();
         $popup = new oqc_ProductPopupSmarty($this->bean, $this->module);
         // exclude product with given id and products that contain other products (packages)
         //////////////////////////////////////////////////////////////////////////////////////////////////
         $formFields = array();
         if (isset($_REQUEST['not_this_product_id']) && !empty($_REQUEST['not_this_product_id'])) {
             $formFields['not_this_product_id'] = $_REQUEST['not_this_product_id'];
             $whereClauses = array($this->bean->table_name . ".id != '{$_REQUEST['not_this_product_id']}'", $this->bean->table_name . ".active != '0'", $this->bean->table_name . ".is_latest != '0'");
         } else {
             $formFields['not_this_product_id'] = '';
             $whereClauses = array($this->bean->table_name . ".active != '0'", $this->bean->table_name . ".is_latest != '0'");
         }
         if (isset($_REQUEST['is_option']) && $_REQUEST['is_option'] != '') {
             $formFields['is_option'] = $_REQUEST['is_option'];
             //if isset product_id found all options that are associated with this product 2.0
             if (isset($_REQUEST['product_id']) && !empty($_REQUEST['product_id'])) {
                 $product = new oqc_Product();
                 if ($product->retrieve($_REQUEST['product_id'])) {
                     $formFields['product_id'] = $_REQUEST['product_id'];
                     if (!empty($product->optionssequence)) {
                         $optionsIds = explode(' ', $product->optionssequence);
                         $productClauses = array();
                         foreach ($optionsIds as $optionId) {
                             //						$option = new oqc_Product();
                             $latestOptionId = $product->getLatestRevisionFromId($optionId);
                             $productClauses[] = $this->bean->table_name . ".id = '{$latestOptionId}'";
                         }
                         $productClause = implode(' or ', $productClauses);
                         $whereClauses[] = '(' . $productClause . ')';
                     } else {
                         $whereClauses[] = $this->bean->table_name . ".id = ''";
                     }
                 } else {
                     $whereClauses[] = $this->bean->table_name . ".id = ''";
                 }
             }
             $whereClauses[] = $this->bean->table_name . ".is_option = '{$_REQUEST['is_option']}'";
         } else {
             // 2.0 If user push Clear button then no Products will be displayed ! Its is real Clear Button! :-)
             //				$whereClauses[] = $this->bean->table_name.".id = ''";
             $whereClauses[] = $this->bean->table_name . ".is_option = '0'";
             $formFields['is_option'] = 0;
         }
         if (isset($_REQUEST['is_recurring']) && $_REQUEST['is_recurring'] != '') {
             $formFields['is_recurring'] = $_REQUEST['is_recurring'];
             if ($_REQUEST['is_recurring'] == '0') {
                 $whereClauses[] = $this->bean->table_name . ".is_recurring = '0'";
             } else {
                 $whereClauses[] = $this->bean->table_name . ".is_recurring = '1'";
             }
         }
         if (isset($_REQUEST['status']) && !empty($_REQUEST['status'])) {
             $formFields['status'] = $_REQUEST['status'];
             $initialFilterClauses = array($this->bean->table_name . ".status = '{$_REQUEST['status']}'");
         }
         $finalwhereClauses = array_merge($whereClauses, $initialFilterClauses);
         //$GLOBALS['log']->error('Popup where clauses: '. var_export($finalwhereClauses,true));
         $popup->searchForm = new ProductSearchForm($this->bean, $this->module, "index", $finalwhereClauses);
         //////////////////////////////////////////////////////////////////////////////////////////////////
         foreach ($listViewDefs[$this->module] as $col => $params) {
             $filter_fields[strtolower($col)] = true;
             if (!empty($params['related_fields'])) {
                 foreach ($params['related_fields'] as $field) {
                     //id column is added by query construction function. This addition creates duplicates
                     //and causes issues in oracle. #10165
                     if ($field != 'id') {
                         $filter_fields[$field] = true;
                     }
                 }
             }
             if (!empty($params['default']) && $params['default'] && $col != 'TEAM_NAME') {
                 $displayColumns[$col] = $params;
             }
         }
         $popup->displayColumns = $displayColumns;
         $popup->filter_fields = $filter_fields;
         //check to see if popupdes contains searchdefs
         $popup->_popupMeta = $popupMeta;
         $popup->listviewdefs = $listViewDefs;
         $popup->searchdefs = $searchdefs;
         if (isset($_REQUEST['query'])) {
             //2.2RC1 we unset Request fields for which we already produced sql query
             foreach ($formFields as $field => $value) {
                 unset($_REQUEST[$field]);
             }
             $popup->searchForm->populateFromRequest();
         }
         $massUpdateData = '';
         if (isset($_REQUEST['mass'])) {
             foreach (array_unique($_REQUEST['mass']) as $record) {
                 $massUpdateData .= "<input style='display: none' checked type='checkbox' name='mass[]' value='{$record}'>\n";
             }
         }
         $popup->massUpdateData = $massUpdateData;
         global $theme, $image_path;
         // 2.2RC1 PopupGeneric does not handle currency field properly- currency is always formatted with default currency symbol
         if (floatval(substr($sugar_version, 0, 3)) > 6.4) {
             $popup->setup('modules/oqc_Product/views/oqcProductPopup65.tpl');
         } elseif (floatval(substr($sugar_version, 0, 3)) > 6.3) {
             $popup->setup('modules/oqc_Product/views/oqcProductPopup64.tpl');
         } elseif (floatval(substr($sugar_version, 0, 3)) >= 6.0 && floatval(substr($sugar_version, 0, 3)) <= 6.3) {
             $popup->setup('modules/oqc_Product/views/oqcProductPopup62.tpl');
         } else {
             $popup->setup('include/Popups/tpls/PopupGeneric.tpl');
         }
         //$popup->setup('include/Popups/tpls/PopupGeneric.tpl');
         insert_popup_header($theme);
         //Quick Search support
         $sqsJavascript = '<script type="text/javascript" src="include/oqc/QuickSearch/oqcQS.js"></script>';
         echo $sqsJavascript;
         echo $popup->display(true, $formFields);
     } else {
         if (file_exists('modules/' . $this->module . '/Popup_picker.php')) {
             require_once 'modules/' . $this->module . '/Popup_picker.php';
         } else {
             require_once 'include/Popups/Popup_picker.php';
         }
         $popup = new Popup_Picker();
         $popup->_hide_clear_button = true;
         echo $popup->process_page();
     }
 }
function getProductBean($service)
{
    if ($service->product_id) {
        $product = new oqc_Product();
        $product->retrieve($service->product_id);
        return $product;
    } else {
        return null;
    }
}
<?php

session_start();
header("Content-type: application/json");
$jsonArray = array();
if (array_key_exists('id', $_REQUEST)) {
    if (!defined('sugarEntry')) {
        define('sugarEntry', true);
    }
    chdir("..");
    require_once 'include/entryPoint.php';
    require_once 'modules/oqc_Product/oqc_Product.php';
    $product = new oqc_Product();
    if ($product->retrieve($_REQUEST['id'])) {
        // if we would not decode this the html tags in the description field would be outputted in encoded form using entities like &lt; &gt; ..
        $jsonArray = array('Description' => html_entity_decode($product->description, ENT_COMPAT, 'UTF-8'), 'Vat' => $product->oqc_vat === '' ? "default" : $product->oqc_vat, 'Attachments' => $product->getTechnicalDescriptions());
    }
}
require_once 'include/utils.php';
$json = getJSONobj();
echo $json->encode($jsonArray);
session_write_close();
session_start();
header("Content-type: application/json");
$jsonArray = array();
if (array_key_exists('id', $_REQUEST)) {
    if (!defined('sugarEntry')) {
        define('sugarEntry', true);
    }
    chdir("..");
    require_once 'include/entryPoint.php';
    require_once 'include/oqc/common/common.php';
    // required for getFormattedCurrencyValue method
    require_once 'modules/oqc_Product/oqc_Product.php';
    require_once 'modules/Currencies/Currency.php';
    $id = $_REQUEST['id'];
    // the product id that we search in the packages
    $p = new oqc_Product();
    if ($p->retrieve($id)) {
        $latestVersion = $p->getLatestRevision();
        //2.2RC1 send also currency id of the product, if not set, then default currency
        // Convert price to default currency, if currency_id is set
        $currency_id = $latestVersion->currency_id != '' ? $latestVersion->currency_id : '-99';
        if ($currency_id != '-99') {
            $currency = new Currency();
            $currency->retrieve($currency_id);
            $latestVersion->price = $latestVersion->price / $currency->conversion_rate;
            //		$latestVersion->price_recurring = $latestVersion->price_recurring / $currency->conversion_rate;
        }
        $jsonArray = array('Tax' => $latestVersion->oqc_vat === '' ? "default" : $latestVersion->oqc_vat, 'Name' => $latestVersion->name, 'Unit' => $latestVersion->unit, 'Price' => empty($latestVersion->is_recurring) ? getFormattedCurrencyValue($latestVersion->price) : '0.00', 'PriceRecurring' => empty($latestVersion->is_recurring) ? '0.00' : getFormattedCurrencyValue($latestVersion->price), 'CancellationPeriod' => $latestVersion->cancellationperiod, 'MonthsGuaranteed' => $latestVersion->monthsguaranteed, 'ProductId' => $latestVersion->id, 'Description' => html_entity_decode($latestVersion->description, ENT_COMPAT, 'UTF-8'), 'Attachments' => $latestVersion->getTechnicalDescriptions(), 'Currency_id' => '-99', 'IsUnique' => empty($latestVersion->is_recurring));
    }
}
require_once 'include/utils.php';