<?php
/*
 * JohnCMS NEXT Mobile Content Management System (http://johncms.com)
 *
 * For copyright and license information, please see the LICENSE.md
 * Installing the system or redistributions of files must retain the above copyright notice.
 *
 * @link        http://johncms.com JohnCMS Project
 * @copyright   Copyright (C) JohnCMS Community
 * @license     GPL-3
 */

defined('_IN_JOHNADM') or die('Error: restricted access');

/** @var Psr\Container\ContainerInterface $container */
$container = App::getContainer();

/** @var Johncms\Api\UserInterface $systemUser */
$systemUser = $container->get(Johncms\Api\UserInterface::class);

$config = $container->get('config')['johncms'];

// Проверяем права доступа
if ($systemUser->rights < 9) {
    header('Location: /?err');
    exit;
}

$headmod = 'botpanel_admin';
$textl = 'Admin Settings For Bot';
require_once('../system/head.php');

echo '<div class="mainblok"><div class="phdr" style="font-weight:bold;">Setting for bot</div>' . "\n";
if (isset($_POST['submit'])) {
    // Settings For Robots
    $config['botnamea'] = isset($_POST['botnamea']) ? trim($_POST['botnamea']) : 'SpamBot';
    $config['botnameb'] = isset($_POST['botnameb']) ? trim($_POST['botnameb']) : 'CatGirl';
    $config['botnamec'] = isset($_POST['botnamec']) ? trim($_POST['botnamec']) : 'SuperBot';
    $config['botida'] = isset($_POST['botida']) ? intval($_POST['botida']) : 0;
    $config['botidb'] = isset($_POST['botidb']) ? intval($_POST['botidb']) : 0;
    $config['botidc'] = isset($_POST['botidc']) ? intval($_POST['botidc']) : 0;

        $configFile = "<?php\n\n" . 'return ' . var_export(['johncms' => $config], true) . ";\n";

   if (!file_put_contents(ROOT_PATH . 'system/config/system.local.php', $configFile)) {
           echo 'ERROR: Can not write system.local.php</body></html>';
           exit;
         }
        echo '<div class="rmenu">' . _t('Settings are saved successfully') . '</div>';
    }

echo '<form action="index.php?act=botsett" method="POST"><div class="menu">';
echo '<p>' .
'<h3>Duty for bot work</h3>Bot sex can be boy or girl and only allowed number not word at bot id else not gonna works..<br/>First bot id:<br/>' . '<input type="text" name="botida" size="2" maxlength="4" value="' . intval($config['botida']) . '"/><br/>First Bot name:<br/>' . '<input type="text" name="botnamea" value="' . htmlentities($config['botnamea'], ENT_QUOTES, 'UTF-8') . '"/><br/>Second bot id:<br/>' . '<input type="text" name="botidb" size="2" maxlength="4" value="' . intval($config['botidb']) . '"/><br/>Second Bot name:<br/>' . '<input type="text" name="botnameb" value="' . htmlentities($config['botnameb'], ENT_QUOTES, 'UTF-8') . '"/><br/>Third bot id:<br/>' . '<input type="text" name="botidc" size="2" maxlength="4" value="' . intval($config['botidc']) . '"/><br/>Third Bot name:<br/>' . '<input type="text" name="botnamec" value="' . htmlentities($config['botnamec'], ENT_QUOTES, 'UTF-8') . '"/></p>' . '<input type="submit" name="submit" value="Save setting"/>' . "\n";
echo '</form></div>';
echo '<div class="gmenu">Info:<br/>1. First bot id duty at shout<br/>2. Second bot id duty at shout<br/>3. Third bot id duty at guestbook<br/>4. To disable bot just clear the bot id<br/>and bot will offline..</div>';
echo '<div class="phdr"><a href="index.php">Admin panel</a></div>';
echo '</div>';

?>