Also konkret:
Im Bild seht ihr, dass ich nun in der 4 Ebene (FIRST CARE) bin. Gerne hätte ich die vorherige Ebene mit angezeigt, damit der Kunde einfach wieder zu dieser zurückspringen kann. Kann mir jemand sagen, wie ich dies erreiche?
Besten Dank im Voraus
PS: Ich denke entweder in der webs / source / boxes / categories.php
Code: Alles auswählen
<?php
/** ----------------------------------------------------------------------------
*
* categories.php
*
* WEB-Shop Software http://www.webs.de/
*
* -----------------------------------------------------------------------------
*
* Released under the GNU General Public License
*
* @author Doc Olson (info@it-bites.de)
* @version $Id: categories.php 1972 2011-02-21 21:22:33Z xantiva $
* @copyright 2011 WEB-Shop Software http://www.webs.de/
*
* ----------------------------------------------------------------------------- */
/**
* Nur ausführen, wenn $current_category_id != 0
* Diese Prüfung muss entfernt werden, wenn der
* Kategoriebaum klassisch aufgebaut sein soll.
*/
if ( $current_category_id ) {
$box = new box();
$cache_id = $_SESSION['language'] . $_SESSION['customers_status']['customers_status_id'] . $cPath;
if ( !$box->is_cached('categories.html', $cache_id) ) {
require_once(DIR_FS_CATALOG . 'templates/' . CURRENT_TEMPLATE . '/source/class/categories.php');
$ct = new categories($cPath, $current_category_id);
/**
* Wieviele Ebenen des Kategoriebaums sollen initial bereits
* aufgeklappt sein?
*/
$ct->min_level = 1;
/**
* Mit der Kategorie-ID als Parameter,
* werden nur die jeweiligen Unterkategorien angezeigt
*/
$ct->getCategories($current_category_id);
/*
* Wenn ALLE Kategorien angezeigt werden sollen,
* muss getCategories OHNE Parameter aufgerufen werden
*/
//$ct->getCategories();
/*
* Beispiel, um einen beliebigen Link an beliebiger
* Stelle in den Kategoriebaum einzuhängen.
*/
//$ct->addLink('Home', xtc_href_link('index.php'), 0, 0);
$box->assign('CATEGORIES', $ct->getOutputHTML());
$box->assign('MAINCATEGORY', $ct->getMainCategory());
}
$smarty->assign('box_CATEGORIES', $box->fetch('categories.html', $cache_id));
}
Code: Alles auswählen
<?php
/** ----------------------------------------------------------------------------
*
* categories.php
*
* WEB-Shop Software http://www.webs.de/
*
* -----------------------------------------------------------------------------
*
* Released under the GNU General Public License
*
* @author Doc Olson (info@it-bites.de)
* @version $Id: categories.php 2319 2012-10-09 11:39:10Z joerg $
* @copyright 2012 WEB-Shop Software http://www.webs.de/
*
* ----------------------------------------------------------------------------- */
class categories
{
protected $path = array();
protected $cur_cat_id = 0;
protected $categories = array();
public $start_level = 0;
public $min_level = 1;
public $max_level = false;
public $hide_empty = false;
public $class_cur = 'current';
public $class_active = 'active';
public $class_cur_has_child = 'has_child';
public $class_level = 'level_';
public $class_cur_parent = 'current_parent';
/**
* __construct
*
*/
public function __construct($cPath, $cur_cat_id)
{
$this->path = explode('_', $cPath);
$this->cur_cat_id = $cur_cat_id;
}
/**
* addLink
*
* inserts a custom link into the category tree
*
*
* @param string $name
* @param string $link
* @param integer $parent_id
* @param integer $position
*/
public function addLink($name, $link, $parent_id = 0, $position = 0)
{
$level = 0;
$this->getLevel($this->categories, $level, $parent_id);
$parent_level = $level;
// if parent is not found in the current tree
if ($parent_level < 0) {
return false;
}
/*
* only add link, if it is...
* a. a child of the current category
* b. to be placed on a level that should be open initially (min_level)
*/
if (
($this->cur_cat_id != $parent_id && $parent_level + 1 >= $this->min_level) &&
$parent_id != 0
) {
return false;
}
$cats = false;
if ($parent_id == 0) {
$cats = &$this->categories;
} else {
$cats = &$this->getBranch($this->categories, $parent_id);
}
if (!is_array($cats)) {
return false;
}
$c = count($cats);
if ($position >= $c) {
$position = $c;
}
for ($i = count($cats); $i > $position; $i--) {
$cats[$i] = $cats[$i - 1];
}
$cats[$position] = array(
'id' => false,
'parent' => $parent_id,
'level' => $parent_level + 1,
'title' => $name,
'link' => $link,
'current' => false
);
}
/**
* getBranch
*
* returns a reference to the branch with the parent-id $parent
*
* @param array &$cats
* @param integer $parent_id
*/
protected function &getBranch(&$cats, $parent_id)
{
$result = false;
for ($i = 0, $c = count($cats); $i < $c; $i++) {
if ($cats[$i]['id'] == $parent_id) {
if (!is_array($cats[$i]['children'])) {
$cats[$i]['children'] = array();
}
$result = & $cats[$i]['children'];
} else {
if (is_array($cats[$i]['children']) && count($cats[$i]['children'])) {
$result = & $this->getBranch($cats[$i]['children'], $parent_id);
}
}
if (is_array($result)) {
break;
}
}
return $result;
}
/**
* determines on what level a category resides
* if the category is not found, -1 will be returned
*
* @param array $cats
* @param integer $cat_id
* @param integer $level
* @return integer
*/
private function getLevel(&$cats, &$level, $cat_id)
{
for ($i = 0, $c = count($cats); $i <= $c; $i++) {
if (isset($cats[$i]['children']) && count($cats[$i]['children'])) {
$level++;
$res = $this->getLevel($cats[$i]['children'], $level, $cat_id);
if ($res !== false) {
return $res;
}
}
if ($cats[$i]['id'] == $cat_id) {
return $level;
}
}
$level--;
return false;
}
/**
* getCategories
*
*/
public function getCategories($cat_id = 0)
{
$this->categories = array_merge($this->categories, $this->getSubCategories($cat_id));
}
/**
* getSubCategories
*
* @param integer $cat_id
* @param integer $level
* @return array
*/
protected function getSubCategories($cat_id = 0, $level = 1)
{
$category = array();
$group_check = '';
if (GROUP_CHECK == 'true') {
$group_check = 'AND c.group_permission_' .
$_SESSION['customers_status']['customers_status_id'] . ' = 1 ';
}
$res = xtc_db_query(
"-- categories.php template class
SELECT c.categories_id, cd.categories_name
FROM " . TABLE_CATEGORIES . " c
INNER JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd
ON c.categories_id = cd.categories_id
WHERE
c.parent_id = $cat_id AND
c.categories_status = 1
$group_check AND
cd.language_id = " . (int)$_SESSION['languages_id'] . "
ORDER BY c.sort_order, cd.categories_name"
);
while ($row = xtc_db_fetch_array($res, true)) {
$current = false;
$active = false;
if ($row['categories_id'] == $this->cur_cat_id) {
$current = true;
}
if (in_array($row['categories_id'], $this->path)) {
$active = true;
$current = true;
}
$prd_count = $this->countProducts($row['categories_id'], false, false);
if (($prd_count > 0 && $this->hide_empty ) || !$this->hide_empty) {
/*
// if only one product is present, the link will go to
// the product instead of the category
if ($prd_count == 1) {
$res2 = xtc_db_query("-- categories.php class
SELECT p.products_id, pd.products_name
FROM " . TABLE_PRODUCTS . " p
JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd
ON p.products_id = pd.products_id
JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc
ON p.products_id = ptc.products_id
WHERE ptc.categories_id = " . $row['categories_id'] . "
AND pd.language_id = " . (int) $_SESSION['languages_id'] . "
AND p.products_status = 1"
);
$row2 = xtc_db_fetch_array($res2, true);
$link = xtc_href_link(
FILENAME_PRODUCT_INFO,
xtc_product_link(
$row2['products_id'],
$row2['products_name']
)
);
} else {
$link = xtc_href_link(
FILENAME_DEFAULT,
xtc_category_link($row['categories_id'], $row['categories_name'])
);
}
*/
$link = xtc_href_link(
FILENAME_DEFAULT,
xtc_category_link($row['categories_id'], $row['categories_name'])
);
$title = htmlspecialchars(
$row['categories_name'],
ENT_COMPAT,
CHARSET,
false
);
$cat = array(
'id' => $row['categories_id'],
'parent' => $cat_id,
'level' => $level,
'title' => $title,
'link' => $link,
'current' => $current,
'active' => $active
);
if (SHOW_COUNTS == 'true' || $this->hide_empty) {
$cat['prd_count'] = $this->countProducts($row['categories_id']);
}
if (
( $level < $this->min_level || $active ) &&
( $level < $this->max_level || !$this->max_level )
) {
$cat['children'] = $this->getSubCategories($row['categories_id'], $level + 1);
}
$category[] = $cat;
}
}
return $category;
}
/**
* getMainCategory
*
* @return array
*/
public function getMainCategory()
{
$mainCategory = array();
$mainId = (int)$this->path[0];
if ($mainId == 0) {
$mainCategory = array(
'title' => HEADER_TITLE_TOP,
'link' => xtc_href_link(FILENAME_DEFAULT)
);
} else {
$group_check = NULL;
if (GROUP_CHECK == 'true') {
$group_check = 'AND c.group_permission_' .
$_SESSION['customers_status']['customers_status_id'] . ' = 1 ';
}
$res = xtc_db_query(
"-- categories.php template class
SELECT c.categories_id, cd.categories_name
FROM " . TABLE_CATEGORIES . " c
INNER JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd
ON c.categories_id = cd.categories_id
WHERE
c.categories_id = $mainId AND
c.categories_status = 1
$group_check AND
cd.language_id = " . (int)$_SESSION['languages_id'] . "
ORDER BY c.sort_order, cd.categories_name"
);
while ($row = xtc_db_fetch_array($res, true)) {
$link = xtc_href_link(
FILENAME_DEFAULT,
xtc_category_link($row['categories_id'], $row['categories_name'])
);
$title = htmlspecialchars(
$row['categories_name'],
ENT_COMPAT,
CHARSET,
false
);
$mainCategory = array(
'title' => $title,
'link' => $link
);
}
}
return $mainCategory;
}
/**
* getOutputHTML
*
* @param array $cats
* @param integer $level
* @return string
*/
public function getOutputHTML($cats = false, $level = 0)
{
if (!count($this->categories)) {
return null;
}
$cats = $cats ? $cats : $this->categories;
if ($level == 0) {
$result = sprintf('<ul class="%s">' . "\n", $this->class_level . $level);
} else {
$result = '';
}
foreach ($cats as $key => $cat) {
$classes = array();
if ($key == 0) {
$classes[] = 'first';
}
if (($key + 1) == count($cats)) {
$classes[] = 'last';
}
if ($cat['active']) {
$classes[] = $this->class_active;
}
if ($cat['current']) {
$classes[] = $this->class_cur;
if (count($cat['children']) > 0) {
$classes[] = $this->class_cur_has_child;
}
}
$prd_count = SHOW_COUNTS == 'true' ? ' (<em>' . $cat['prd_count'] . '</em>)' : '';
if (isset($cat['children']) and !empty($cat['children'])) {
$children = sprintf('<ul class="%s">' . "\n", $this->class_level . ($level + 1));
$children .= $this->getOutputHTML($cat['children'], $cat['level']);
$children .= "</ul>\n";
} else {
$children = '';
}
$classes = count($classes) ? ' class="' . implode(' ', $classes) . '"' : '';
$result .= sprintf(
'<li%s><a href="%s" title="%s"%s>%s%s</a>%s</li>',
$classes, $cat['link'], $cat['title'], $classes, $cat['title'], $prd_count, $children
) . "\n";
}
if ($level == 0) {
$result .= "</ul>\n";
}
return $result;
}
/**
* getOutput
*
* @param array $cats
* @param integer $level
*/
public function getOutput($cats = false, $level = 0)
{
return $this->categories;
}
/**
* countProducts
*
* @param integer $cat_id
* @param boolean $include_inactive
* @return integer
*/
public function countProducts($cat_id, $include_inactive = false)
{
$count = 0;
if ($include_inactive) {
$active = '';
} else {
$active = "AND p.products_status = '1'";
}
$res = xtc_db_query(
"SELECT count(*) AS total
FROM " . TABLE_PRODUCTS . " p
INNER JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
ON p.products_id = p2c.products_id
WHERE p2c.categories_id = $cat_id
$active
AND (
p.products_date_expire > NOW() OR
p.products_date_expire IS NULL OR
p.products_date_expire = '0000-00-00 00:00:00'
)"
);
$res = xtc_db_fetch_array($res, true);
$count += $res['total'];
$res = xtc_db_query("SELECT categories_id FROM " . TABLE_CATEGORIES . " WHERE parent_id = $cat_id");
if (xtc_db_num_rows($res, true)) {
while ($row = xtc_db_fetch_array($res, true)) {
$count += $this->countProducts($row['categories_id'], $include_inactive);
}
}
return $count;
}
}