Files
2026-04-30 14:38:11 +02:00

89 lines
2.4 KiB
PHP

<?php defined('SYSPATH') or die('No direct script access.');
class categories_Core {
public static function print_menu($menu, $path, $selected = '', $level = 0)
{
echo "\n<ul>\n";
foreach($menu as $item)
{
$class = 'level_'. $level;
if (!$item[0]->parent_id)
{
$class .= ' main';
}
if ($item[0]->id == $selected || $item[0]->name == $selected)
{
$class .= ' selected';
}
echo '<li class="'. $class .'">';
echo "<div>";
echo html::anchor($path. $item[0]->name, $item[0]->title);
echo "</div>";
if ($item[1])
{
self::print_menu($item[1], $path, $selected, $level+1);
}
echo "</li>\n";
}
echo "</ul>\n";
}
public static function print_menu_admin($menu, $path, $pad = 0)
{
if($pad == 0)
{
echo '<table cellpadding="0" cellspacing="0">'."\n";
}
foreach($menu as $item)
{
echo '<tr>';
echo '<td style="padding-left: '. (5+$pad*15) .'px;">';
echo html::anchor($path.'edit/'. $item[0]->id, $item[0]->title);
echo '</td><td class="action">';
if(!$item[0]->has_products)
{
echo html::anchor(
$path.'add/'. $item[0]->id,
html::image('images/admin/add.png'),
array('title' => 'dodaj podkategorię')
);
}
else
{
echo '<a title="dodaj podkategorię (niedostępne)">'. html::image('images/admin/add_gray.png') .'</a>';
}
echo html::anchor(
$path.'edit/'. $item[0]->id,
html::image('images/admin/edit.png'),
array('title' => 'edytuj podkategorię')
);
# czy posiada podkategorie lub produkty?
if($item[1] == null && !$item[0]->has_products)
{
echo html::anchor(
$path.'delete/'. $item[0]->id,
html::image('images/admin/delete.png'),
array('title' => 'usuń podkategorię', 'onclick' => "return confirm('Czy chcesz usunąć kategorię?');")
);
}
else
{
echo '<a title="usuń podkategorię (niedostępne)">'. html::image('images/admin/delete_gray.png') .'</a>';
}
echo '</td></tr>'."\n";
if ($item[1])
{
self::print_menu_admin($item[1],$path, $pad+1);
}
}
if($pad == 0)
{
echo '</table>'."\n";
}
}
}