function traverse_tree_down(&$mymenu_content, $category_id = '0', $level = '0') { static $ibg = -1; global $db, $module, $mosConfig_live_site; $level++; $query = "SELECT category_name as cname, category_id as cid, category_child_id as ccid " . "FROM #__{vm}_category as a, #__{vm}_category_xref as b " . "WHERE a.category_publish='Y' AND " . " b.category_parent_id='{$category_id}' AND a.category_id=b.category_child_id " . "ORDER BY category_parent_id, list_order, category_name ASC"; $db->query($query); $categories = $db->record; if (!($categories == null)) { $i = 1; $numCategories = count($categories); foreach ($categories as $category) { $ibg++; $Treeid = $ibg == 0 ? 1 : $ibg; $itemid = isset($_REQUEST['Itemid']) ? '&Itemid=' . intval($_REQUEST['Itemid']) : ""; $mymenu_content .= str_repeat("\t", $level - 1); if ($level > 1 && $i == 1) { $mymenu_content .= ","; } $mymenu_content .= "['" . addslashes($category->cname); $mymenu_content .= ps_product_category::products_in_category($category->cid); $mymenu_content .= "','" . $_SERVER['PHP_SELF'] . '?option=com_virtuemart&page=product.product_category_form&category_id=' . $category->cid . "'\n "; $q = "SELECT #__{vm}_product.product_name,#__{vm}_product.product_id FROM #__{vm}_product, #__{vm}_product_category_xref "; $q .= "WHERE #__{vm}_product.product_id=#__{vm}_product_category_xref.product_id "; $q .= "AND #__{vm}_product_category_xref.category_id='" . $category->cid . "' "; $q .= "ORDER BY #__{vm}_product.product_name"; $db->query($q); $products = $db->record; $xx = 1; if (count($products) > 0) { $mymenu_content .= ",\n"; } foreach ($products as $product) { // get name and link (just to save space in the code later on) $mymenu_content .= str_repeat("\t", $level) . "['" . addslashes($product->product_name); $url = $_SERVER['PHP_SELF'] . '?option=com_virtuemart&page=product.product_form&product_id=' . $product->product_id; $mymenu_content .= "','" . $url . "']"; if ($xx++ < sizeof($products)) { $mymenu_content .= ",\n"; } else { $mymenu_content .= "\n"; } } /* recurse through the subcategories */ $this->traverse_tree_down($mymenu_content, $category->ccid, $level); $mymenu_content .= str_repeat("\t", $level - 1); /* let's see if the loop has reached its end */ if ($i == sizeof($categories) && $level == 1) { $mymenu_content .= "]\n"; } else { $mymenu_content .= "],\n"; } $i++; } } else { } }
function traverse_tree_down(&$mymenu_content, $category_id = '0', $level = '0') { static $ibg = -1; global $mosConfig_live_site, $sess; $db = new ps_DB(); $level++; $query = "SELECT category_name, category_id, category_child_id " . "FROM #__{vm}_category as a, #__{vm}_category_xref as b " . "WHERE a.category_publish='Y' AND " . " b.category_parent_id='{$category_id}' AND a.category_id=b.category_child_id " . "ORDER BY category_parent_id, list_order, category_name ASC"; $db->query($query); while ($db->next_record()) { $ibg++; $Treeid = $ibg == 0 ? 1 : $ibg; $itemid = '&Itemid=' . $sess->getShopItemid(); $mymenu_content .= ",\n[null,'" . $db->f("category_name", false); $mymenu_content .= ps_product_category::products_in_category($db->f("category_id")); $mymenu_content .= "','" . sefRelToAbs('index.php?option=com_virtuemart&page=shop.browse&category_id=' . $db->f("category_id") . $itemid . "&TreeId={$Treeid}") . "','_self','" . $db->f("category_name", false) . "'\n "; /* recurse through the subcategories */ $this->traverse_tree_down($mymenu_content, $db->f("category_child_id"), $level); /* let's see if the loop has reached its end */ $mymenu_content .= "]"; } }
// so: for the rest of this module track if this menu contains the selected item // Default value: first node (=baseid), but not selected $opento = $baseid; $opento_selected = "false"; // what do you know... the first node was selected if ($baseid == $openid) { $opento_selected = "true"; } $target = ""; // create the first node, parent is always -1 $menu_htmlcode .= "{$tree}.add(\"{$baseid}\",\"-1\",\"{$basename}\",\"{$baselink}\",\"\",\"{$target}\");\n"; $db->reset(); // process each of the nodes while ($db->next_record()) { // get name and link (just to save space in the code later on) $name = htmlentities($db->f("category_name"), ENT_QUOTES, vmGetCharset()) . ps_product_category::products_in_category($db->f("category_id")); $url = $sess->url($mm_action_url . "index.php?page=shop.browse&category_id=" . $db->f("category_id")); $menu_htmlcode .= "{$tree}.add(\"" . $db->f("category_id") . "\",\"" . $db->f("category_parent_id") . "\",\"{$name}\",\"{$url}\",\"\",\"{$target}\");\n"; // if this node is the selected node if ($db->f("category_id") == $openid) { $opento = $openid; $opento_selected = "true"; } } $menu_htmlcode .= "document.write({$tree});\n"; $menu_htmlcode .= $openAll == "true" ? "{$tree}.openAll();\n" : "{$tree}.closeAll();\n"; $menu_htmlcode .= "{$tree}.openTo(\"{$opento}\",\"{$opento_selected}\");\n"; $menu_htmlcode .= "</script>\n"; $menu_htmlcode .= "<noscript>\n"; $menu_htmlcode .= $ps_product_category->get_category_tree($category_id, $class_mainlevel); $menu_htmlcode .= "</noscript>\n";
/** * Creates a link list to subcategories of category $category_id * * @param int $category_id * @param string $css_class The CSS to be applied to the link * @return string HTML code */ function get_subcategory($category_id, $css_class = "") { global $sess; $ps_vendor_id = $_SESSION["ps_vendor_id"]; if ($css_class != "") { $class = "class=\"{$css_class}\""; } else { $class = ""; } $db = new ps_DB(); $q = "SELECT category_id, category_child_id,category_name FROM #__{vm}_category,#__{vm}_category_xref "; $q .= "WHERE #__{vm}_category_xref.category_parent_id='{$category_id}' "; $q .= "AND #__{vm}_category.category_id=#__{vm}_category_xref.category_child_id "; //$q .= "AND #__{vm}_category.vendor_id='$ps_vendor_id' "; $q .= "AND #__{vm}_category.category_publish='Y' "; $q .= "ORDER BY #__{vm}_category.list_order, #__{vm}_category.category_name ASC"; $db->setQuery($q); $db->query(); $html = ""; $nbsp = " "; while ($db->next_record()) { $html .= "<a style=\"display:block;\" class=\"sublevel\" title=\"" . $db->f("category_name") . "\" href=\""; $html .= $sess->url(URL . "index.php?page=shop.browse&root={$category_id}&category_id=" . $db->f("category_child_id")); $html .= "\" {$class}>{$nbsp}" . $db->f("category_name"); $html .= ps_product_category::products_in_category($db->f("category_child_id")); $html .= "</a>\n"; } return $html; }