/**
  * Lists all child/sister products of the given product
  *
  * @param int $product_id
  * @return string HTML code with Items, attributes & price
  */
 function list_attribute_drop_multi($product_id, $cls_suffix)
 {
     global $VM_LANG, $CURRENCY_DISPLAY, $mm_action_url, $sess;
     require_once CLASSPATH . 'ps_product.php';
     $ps_product = new ps_product();
     $Itemid = $sess->getShopItemid();
     $category_id = vmGet($_REQUEST, 'category_id', "");
     $db = new ps_DB();
     $db_sku = new ps_DB();
     $db_item = new ps_DB();
     $tpl = new $GLOBALS['VM_THEMECLASS']();
     $tpl->set("cls_suffix", $cls_suffix);
     $tpl->set("product_id", $product_id);
     // Set Advanced Attributes
     $tpl->set("advanced_attribute", $this->list_advanced_attribute($product_id, $db->f("product_id")));
     $tpl->set("custom_attribute", $this->list_custom_attribute($product_id, $db->f("product_id")));
     // Get list of children
     $q = "SELECT product_id,product_name FROM #__{vm}_product WHERE product_parent_id='{$product_id}' AND product_publish='Y'";
     $db->setQuery($q);
     $db->query();
     if ($db->num_rows() < 1) {
         // Try to Get list of sisters & brothers
         $q = "SELECT product_parent_id FROM #__{vm}_product WHERE product_id='{$product_id}'";
         $db->setQuery($q);
         $db->query();
         $child_id = $product_id;
         $product_id = $db->f("product_parent_id") != "0" ? $db->f("product_parent_id") : $product_id;
         $q = "SELECT product_id,product_name FROM #__{vm}_product WHERE product_parent_id='" . $db->f("product_parent_id") . "' AND product_parent_id<>0 AND product_publish='Y'";
         $db->setQuery($q);
         $db->query();
     }
     if ($db->num_rows() > 0) {
         $flypage = $ps_product->get_flypage($product_id);
         $html = "<input type=\"hidden\" name=\"product_id\" value=\"{$product_id}\" />";
         $html .= "<label for=\"product_id_field\">" . $VM_LANG->_('PHPSHOP_PLEASE_SEL_ITEM') . "</label>: <br />";
         // If content plugins are enabled, reload the whole page; otherwise, use ajax
         if (VM_CONTENT_PLUGINS_ENABLE == '1') {
             $html .= "<select class=\"inputbox\" onchange=\"var id = \$('product_id_field')[selectedIndex].value; if(id != '') { document.location = '" . $mm_action_url . "index.php?option=com_virtuemart&amp;page=shop.product_details&amp;flypage={$flypage}&amp;Itemid={$Itemid}&amp;category_id={$category_id}&amp;product_id=' + id; }\" id=\"product_id_field\" name=\"prod_id[]\">\n";
         } else {
             $html .= "<select class=\"inputbox\" onchange=\"var id = \$('product_id_field')[selectedIndex].value; if(id != '') { loadNewPage( 'vmMainPage', '" . $mm_action_url . "index2.php?option=com_virtuemart&amp;page=shop.product_details&amp;flypage={$flypage}&amp;Itemid={$Itemid}&amp;category_id={$category_id}&amp;product_id=' + id ); }\" id=\"product_id_field\" name=\"prod_id[]\">\n";
         }
         $html .= "<option value=\"{$product_id}\">" . $VM_LANG->_('PHPSHOP_SELECT') . "</option>";
         while ($db->next_record()) {
             $selected = isset($child_id) ? $db->f("product_id") == $child_id ? "selected=\"selected\"" : "" : "";
             // Start row for this child
             $html .= "<option value=\"" . $db->f("product_id") . "\" {$selected}>";
             $html .= $db->f("product_name") . " - ";
             // For each child get attribute values by looping through attribute list
             $q = "SELECT product_id, attribute_name FROM #__{vm}_product_attribute_sku ";
             $q .= "WHERE product_id='{$product_id}' ORDER BY attribute_list ASC";
             $db_sku->setQuery($q);
             $db_sku->query();
             while ($db_sku->next_record()) {
                 $q = "SELECT attribute_name, attribute_value, product_id ";
                 $q .= "FROM #__{vm}_product_attribute WHERE ";
                 $q .= "product_id='" . $db->f("product_id") . "' AND ";
                 $q .= "attribute_name='" . $db_sku->f("attribute_name") . "'";
                 $db_item->setQuery($q);
                 $db_item->query();
                 while ($db_item->next_record()) {
                     $html .= $db_item->f("attribute_name") . " ";
                     $html .= "(" . $db_item->f("attribute_value") . ")";
                     if (!$db_sku->is_last_record()) {
                         $html .= '; ';
                     }
                 }
             }
             // Attributes for this item are done.
             // Now get item price
             if ($_SESSION['auth']['show_prices']) {
                 $price = $ps_product->get_price($db->f("product_id"));
                 $price["product_price"] = $GLOBALS['CURRENCY']->convert($price["product_price"], $price["product_currency"]);
                 if ($_SESSION["auth"]["show_price_including_tax"] == 1) {
                     $tax_rate = 1 + $ps_product->get_product_taxrate($db->f("product_id"));
                     $price['product_price'] *= $tax_rate;
                 }
                 $html .= ' - ' . $CURRENCY_DISPLAY->getFullValue($price["product_price"]);
             }
             $html .= "</option>\n";
         }
         $html .= "</select>\n";
         $tpl->set("drop_down", $html);
     } else {
         $html = "<input type=\"hidden\" name=\"product_id\" value=\"{$product_id}\" />\n";
         $html .= "<input type=\"hidden\" name=\"prod_id[]\" value=\"{$product_id}\" />\n";
         $tpl->set("drop_down", $html);
     }
     $html = $tpl->fetch('product_details/includes/addtocart_drop.tpl.php');
     return array($html, "drop");
 }
 function list_attribute($product_id, $fils = true)
 {
     global $VM_LANG, $CURRENCY_DISPLAY;
     $ps_product = new ps_product();
     $db = new ps_DB();
     $db_sku = new ps_DB();
     $db_item = new ps_DB();
     // Get list of children
     if ($fils) {
         $q = "SELECT product_id,product_name FROM #__{vm}_product WHERE product_parent_id='{$product_id}' AND product_publish='Y'";
     } else {
         $q = "SELECT product_parent_id FROM #__{vm}_product WHERE product_id='{$product_id}'";
         $db->setQuery($q);
         $db->query();
         $db->next_record();
         $product_parent_id = $db->f("product_parent_id");
         $q = "SELECT product_id,product_name FROM #__{vm}_product WHERE product_parent_id='{$product_parent_id}' AND product_publish='Y'";
     }
     $db->setQuery($q);
     $db->query();
     if ($db->num_rows() > 0) {
         $display = '<select name="product_id" onChange="this.form.add_product_validate.value=0;this.form.submit();">';
         $display .= '<option value="-1">Choisissez un produit item</option>';
         while ($db->next_record()) {
             $display .= '<option value="' . $db->f("product_id") . '"';
             if ($product_id == $db->f("product_id")) {
                 $display .= ' selected="yes"';
             }
             $display .= '>' . $db->f("product_name");
             // For each child get attribute values by looping through attribute list
             $q = "SELECT product_id, attribute_name FROM #__{vm}_product_attribute_sku ";
             $q .= "WHERE product_id='{$product_id}' ORDER BY attribute_list ASC";
             $db_sku->setQuery($q);
             $db_sku->query();
             while ($db_sku->next_record()) {
                 $q = "SELECT attribute_name, attribute_value, product_id ";
                 $q .= "FROM #__{vm}_product_attribute WHERE ";
                 $q .= "product_id='" . $db->f("product_id") . "' AND ";
                 $q .= "attribute_name='" . $db_sku->f("attribute_name") . "'";
                 $db_item->setQuery($q);
                 $db_item->query();
                 while ($db_item->next_record()) {
                     $display .= ' - ' . $db_item->f("attribute_name") . " ";
                     $display .= "(" . $db_item->f("attribute_value") . ")";
                     if (!$db_sku->is_last_record()) {
                         $display .= '; ';
                     }
                 }
             }
             // Attributes for this item are done.
             // Now get item price
             $price = $ps_product->get_price($db->f("product_id"));
             if ($_SESSION["auth"]["show_price_including_tax"] == 1) {
                 $tax_rate = 1 + $ps_product->get_product_taxrate($db->f("product_id"));
                 $price['product_price'] *= $tax_rate;
             }
             $display .= ' - ' . $CURRENCY_DISPLAY->getFullValue($price["product_price"]);
             $display .= '</option>';
         }
         $display .= '</select>';
     } else {
         $display = "<input type=\"hidden\" name=\"product_id\" value=\"{$product_id}\" />\n";
     }
     return $display;
 }