<?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('themes');
global $config, $db, $core, $themes_conf, $lang;
$core->loadblockLang('themes');
if ($themes_conf['on']) {
    if ($themes_conf['old']) {
        echo '<div style="text-align:center"><select id="_themeselect">';
        foreach (glob(ROOT . 'usr/tpl/*/index.tpl') as $file) {
            if (is_file($file) && !eregStrt('/admin', $file) && !eregStrt('/default', $file) && !eregStrt('/smartphone', $file)) {
                $file = explode('/', $file);
                $file = $file[count($file) - 2];
                echo '<option value="' . $file . '" ' . ($config['tpl'] == $file ? 'selected' : '') . '>' . $file . '</option>';
            }
        }
        echo '</select>';
        echo '<br/><br/><input type="button" value="Выбрать тему" onclick="window.location.href = \'index.php?theme=\'+gid(\'_themeselect\').value;" />
</div>';
    } else {
        $themeskin = '';
        foreach (glob(ROOT . 'usr/tpl/*/index.tpl') as $file) {
            if (is_file($file) && !eregStrt('/admin', $file) && !eregStrt('/default', $file) && !eregStrt('/smartphone', $file)) {
                $file = explode('/', $file);
                $file = $file[count($file) - 2];
                $themeskin .= '<option value="' . $file . '" ' . ($config['tpl'] == $file ? 'selected' : '') . '>' . $file . '</option>';
            }
        }
        $themeselect = 'onclick="window.location.href = \'index.php?theme=\'+gid(\'_themeselect\').value;"';
        $core->tpl->loadFile('blocks/themes');
        $core->tpl->setVar('themeskin', $themeskin);
        $core->tpl->setVar('themeselect', $themeselect);
        $core->tpl->end();
    }
} else {
    if ($themes_conf['info_off']) $core->tpl->info($lang['themes_off']);
}