ok cos i am in a good mood today...
Code:
<?
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart |
| Copyright (c) 2001-2003 Ruslan R. Fazliev <rrf@rrf.ru> |
| All rights reserved. |
+-----------------------------------------------------------------------------+
| PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php |
| |
| THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT RUSLAN R. |
| FAZLIEV (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING |
| AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). |
| PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT |
| CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, |
| COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY |
| (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS |
| LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS |
| AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND |
| OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE |
| THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. |
| |
| The Initial Developer of the Original Code is Ruslan R. Fazliev |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2003 |
| Ruslan R. Fazliev. All Rights Reserved. |
+-----------------------------------------------------------------------------+
\*****************************************************************************/
#
# $Id: categories.php,v 1.46.2.1 2003/06/02 11:57:44 svowl Exp $
#
#
# For users some categories may be disabled
#
if ($current_area == "C") {
$membership_condition = " AND ($sql_tbl[categories].membership='$user_account[membership]' OR $sql_tbl[categories].membership='') ";
} else {
$membership_condition = "";
}
// funkydunk modification
// amended query to get the main cat and subcat for each record
$categories_data = func_query("select $sql_tbl[categories].*, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', -1) as category_name, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', 1) as maincat, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', 2) as subcat from $sql_tbl[categories] ".($current_area=="C"?"where $sql_tbl[categories].avail='Y' $membership_condition ":"")." group by $sql_tbl[categories].categoryid order by ".($current_area=="C" ? "order_by" : "category"));
#
# Put all categories into $all_categories array and find current_category
# by categoryid stored in $cat
#
if(!$categories_data) $categories_data = array();
foreach($categories_data as $k=>$category_data) {
if ($current_area == "C") {
$int_res = func_query_first("SELECT * FROM $sql_tbl[categories_lng] WHERE code='$store_language' AND categoryid='$category_data[categoryid]'");
if ($int_res["category"])
$categories_data[$k]["category_name"] = $category_data["category_name"] = $int_res["category"];
if ($int_res["description"])
$categories_data[$k]["description"] = $category_data["description"] = $int_res["description"];
}
if ($category_data["categoryid"]==$cat) {
$current_category = $category_data;
}
// funkydunk code
if(strstr($category_data["category"],"/")) {
if ($category_data["category"] == $category_data["subcat"]){
// echo "got one";
// after taking off the initial category name this checks to see if this is only a sub category with no categories below it.
// if i didn't do this the subcategory would be duplicated in the list
$categories_data[$k]["subcatonly"]="true";
}
}
// end of funkydunk amended code
$all_categories = $categories_data;
// func_print_r ($all_categories);
}
#
# Put all root categories to $categories array
# Put all subcategories of current_category to $categories array
#
foreach($all_categories as $all_category) {
$category=$all_category["category"];
$cur_dir_len = strlen($current_category["category"]);
if(!strstr($category,"/")) {
$categories[]=$all_category;
if(empty($current_category)) {
$subcategories[]=$all_category;
}
}
if(substr($category,0,$cur_dir_len+1) == $current_category["category"]."/" and $category!=$current_category["category"])
if(!strstr(substr($category,$cur_dir_len+1),"/")) {
$all_category["category"]=ereg_replace("^.*/","",$all_category["category"]);
$subcategories[]=$all_category;
}
}
#
# Put subcategory_count to $subcategories array
#
if ($subcategories)
foreach($subcategories as $key =>$subcategory) {
$subcategory["subcategory_count"]=0;
foreach($all_categories as $all_category) {
if ($all_category["categoryid"]==$subcategory["categoryid"]) {
$cur_dir_len = strlen($all_category["category"]);
$current_subcategory=$all_category["category"];
}
}
foreach($all_categories as $all_category) {
$category=$all_category["category"];
if(substr($category,0,$cur_dir_len+1) == $current_subcategory."/" and $category!=$current_subcategory)
if(!strstr(substr($category,$cur_dir_len+1),"/"))
$subcategory["subcategory_count"]++;
}
$subcategories[$key]["subcategory_count"]=$subcategory["subcategory_count"];
}
#
# Generate category sequence, i.e.
# Books, Books/Poetry, Books/Poetry/Philosophy ...
#
$current_category_array = explode("/",$current_category["category"]);
$prev = $current_category_array[0];
list($key,$val)=each($current_category_array);
$new_array = array($val);
while(list($key,$val)=each($current_category_array)) {
$new_array[] = $prev."/".$val;
$prev = $prev."/".$val;
}
unset($current_category_array);
#
# Generate array for displaying categories sequence in location
#
$category_location=array();
reset($all_categories);
$my_cats = array ();
foreach($all_categories as $all_category) {
$categoryid=$all_category["categoryid"];
$category=$all_category["category"];
$my_cats [$categoryid] = $category;
}
asort ($my_cats);
foreach ($my_cats as $categoryid => $category) {
reset ($new_array);
while(list($key,$val)=each($new_array)) {
if ($val==$category) {
foreach($categories_data as $category_data) {
if ($category_data["categoryid"] == $categoryid)
$val = $category_data["category_name"];
}
$category_location[]=array(ereg_replace(".*/","",$val),"home.php?cat=".$categoryid);
}
}
}
#
# Assign Smarty variables
#
$smarty->assign("allcategories",$all_categories);
$smarty->assign("categories",$categories);
$smarty->assign("subcategories",$subcategories);
$smarty->assign("current_category",$current_category);
$smarty->assign("cat",$cat);
?>
Code:
{* dropdown.tpl funkydunk 2003 *}
{literal}
<script language="JavaScript1.2">
//Pop-it menu- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use
var linkset=new Array()
//SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT
{/literal}
{section name=cat_num loop=$categories}
{assign var="temp" value="0"}
{section name=cat loop=$allcategories}
{if $allcategories[cat].maincat eq $categories[cat_num].category_name}
{if $allcategories[cat].subcatonly}
{$temp}
{if $temp gt 0}
linkset[{$smarty.section.cat_num.index}] +='<div class="menuitems">
{$allcategories[cat].category_name}</div>'
{else}
linkset[{$smarty.section.cat_num.index}] ='<div class="menuitems">
{$allcategories[cat].category_name}</div>'
{/if}
{math equation="temp+1" temp=$temp assign=temp}
{/if}
{/if}
{/section}
{/section}
{literal}
////No need to edit beyond here
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers
function showmenu(e,which){
if (!document.all&&!document.getElementById&&!document.layers)
return
clearhidemenu()
menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj
if (ie4||ns6)
menuobj.innerHTML=which
else{
menuobj.document.write('<layer name=gui bgColor=#081589 width=165 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which+'</layer>')
menuobj.document.close()
}
menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
eventX=ie4? event.clientX : ns6? e.clientX : e.x
eventY=ie4? event.clientY : ns6? e.clientY : e.y
//Find out how close the mouse is to the corner of the window
var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY
//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
else
//position the horizontal position of the menu where the mouse was clicked
// menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX
//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
menuobj.thestyle.top=ie4? document.body.scrollTop+eventY-menuobj.contentheight : ns6? window.pageYOffset+eventY-menuobj.contentheight : eventY-menuobj.contentheight
else
menuobj.thestyle.top=ie4? document.body.scrollTop+event.clientY : ns6? window.pageYOffset+eventY : eventY
menuobj.thestyle.visibility="visible"
return false
}
function contains_ns6(a, b) {
//Determines if 1 element in contained in another- by Brainjar.com
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}
function hidemenu(){
if (window.menuobj)
menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
}
function dynamichide(e){
if (ie4&&!menuobj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}
function delayhidemenu(){
if (ie4||ns6||ns4)
delayhide=setTimeout("hidemenu()",500)
}
function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}
function highlightmenu(e,state){
if (document.all)
source_el=event.srcElement
else if (document.getElementById)
source_el=e.target
if (source_el.className=="menuitems"){
source_el.id=(state=="on")? "mouseoverstyle" : ""
}
else{
while(source_el.id!="popmenu"){
source_el=document.getElementById? source_el.parentNode : source_el.parentElement
if (source_el.className=="menuitems"){
source_el.id=(state=="on")? "mouseoverstyle" : ""
}
}
}
}
if (ie4||ns6)
document.onclick=hidemenu
</script>
{/literal}
{include file="customer/dropdown.tpl"} into the h<head> part of customer/home.tpl