<?php

/*
 * @name        JMY CMS
 * @link        https://jmy.su/
 * @copyright   Copyright (C) 2012-2025 JMY LTD
 * @license     LICENSE.txt (see attached file)
 * @version     VERSION.txt (see attached file)
 * @author      Komarov Ivan
 * @edited      Orlov Alexsey
 */

if (!defined('ACCESS')) {
    header('Location: /');
    exit;
}
loadConfigBLOCK('cats');
global $core, $config, $lang, $cats_conf;
$core->loadblockLang('cats');
$module = $cats_conf['module'] == 'all' ? '' : $cats_conf['module'];
if (empty($core->catArray)) $core->catArray = getcache('categories');
$parse = $core->catArray[$module] ?? '';
if ($cats_conf['on']) {
    if ($cats_conf['old']) {
        echo '<ul>
   <li class="cat-item"><a href="/">' . $lang['cats_main'] . '</a></li>';
        if (!empty($parse)) {
            foreach ($parse as $info) {
                echo '<li class="cat-item"><a href="' . $module . '/' . $info['altname'] . '">' . $info['title'] . '</a></li>';
            }
        }
        echo '</ul>';
    } else {
        if ($cats_conf['module'] == 'all') {
            foreach ($core->getModList() as $module) {
                if (!empty($core->tpl->modules[$module])) {
                    $parse = $core->catArray[$module] ?? '';
                    if (!empty($parse)) {
                        foreach ($parse as $info) {
                            $core->tpl->loadFile('blocks/cats');
                            $core->tpl->setVar('ctitle', $info['title']);
                            $core->tpl->setVar('cmodule', $module);
                            $core->tpl->setVar('cname', $info['altname']);
                            $core->tpl->setVar('cicon', $config['url'] . '/media/cats/' . $info['icon']);
                            $core->tpl->setVar('curl', $module . '/' . $info['altname']);
                            $core->tpl->end();
                        }
                    }
                }
            }
        } else {
            if (!empty($parse)) {
                foreach ($parse as $info) {
                    $core->tpl->loadFile('blocks/cats');
                    $core->tpl->setVar('ctitle', $info['title']);
                    $core->tpl->setVar('cmodule', $module);
                    $core->tpl->setVar('cname', $info['altname']);
                    $core->tpl->setVar('cicon', $config['url'] . '/media/cats/' . $info['icon']);
                    $core->tpl->setVar('curl', $module . '/' . $info['altname']);
                    $core->tpl->end();
                }
            }
        }
    }
} else {
    if ($cats_conf['info_off']) $core->tpl->info($lang['cats_off']);
}