<?php
// +---------------------------------------------+
// |     Copyright 2003 -2006 weenCompany        |
// |     http://www.weentech.com                 |
// |     This file may not be redistributed.     |
// +---------------------------------------------+

if(!defined('TABLE_PREFIX'))
  define('TABLE_PREFIX', "");

if(!defined('IN_WEENCOMPANY'))
  die("File not found!");



// ########################## DISPLAY SUBCATEGORY MENU #########################

function m31_DisplaySubcategoryMenu()
{
  global $DB;
  global $categoryid;
  global $userinfo;

  // get module settings
  $getsettings = $DB->query("SELECT title, value FROM " . TABLE_PREFIX . "modulesettings WHERE moduleid = '31'");
  for($i = 0; $setting = $DB->fetch_array($getsettings); $i++)
  {
    $settings[$setting['title']] = $setting['value'];
  }

  // display custom css?
  if($settings['菜单样式'])
  {
    echo '<!--StartSubcategoryCustomCSS-->
          <style type="text/css">
          a.m31css:link    { ' . $settings['基本样式'] . ' }
          a.m31css:active  { ' . $settings['活动时样式'] . ' }
          a.m31css:visited { ' . $settings['访问后样式'] . ' }
          a.m31css:hover   { ' . $settings['翻转时样式'] . ' }
          </style>
          <!--EndSubcategoryCustomCSS-->';
  }

  // get subcategories
  $subcategories = $DB->query("SELECT categoryid, name, link FROM " . TABLE_PREFIX . "categories
                               WHERE parentid = '$categoryid' ORDER BY displayorder");

  $subcategoryrows = $DB->get_num_rows($subcategories);

  // are we in a subcategory?
  if($subcategoryrows == 0)
  {
    $parentcategory = $DB->query_first("SELECT parentid FROM " . TABLE_PREFIX . "categories
                                        WHERE categoryid = '$categoryid'");

    if($parentcategory['parentid'] != 0)
    {
      unset($subcategories);
      $subcategories = $DB->query("SELECT categoryid, name, link FROM " . TABLE_PREFIX . "categories
                                   WHERE parentid = '" . $parentcategory['parentid'] . "' ORDER BY displayorder");

      $subcategoryrows = $DB->get_num_rows($subcategories);
    }
  }

  // display subcategories
  for($i = 0; $subcategory = $DB->fetch_array($subcategories); $i++)
  {
    if(@in_array($subcategory['categoryid'], $userinfo['categorymenuids']))
    {
      $subcategorylink = strlen($subcategory['link']) ? $subcategory['link'] : RewriteLink('index.php?categoryid=' . $subcategory['categoryid']);

      echo '<a ' . iif($settings['菜单样式'], 'class="m31css"', '') . ' href="' . $subcategorylink . '">' . $subcategory['name'] . '</a>';

      if( ($i + 1) != $subcategoryrows)
      {
        echo $settings['分隔符'];
      }
    }
    else
    {
      $i--;
    }  
  }

}


m31_DisplaySubcategoryMenu()

?>