<?php

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

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

/** @var PDO $db */
$db = $container->get(PDO::class);

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

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

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

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

/** @var Johncms\Api\ConfigInterface $config */

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


if ($systemUser->rights < 9) {
    header('Location: ../?err');
    exit;
}

$headmod = 'menu';
$textl = 'WapMaster';
$from = isset($_GET['from']) ? trim($_GET['from']) : ''; 
$id = isset($_GET['id']) ? abs(intval($_GET['id'])) : 0; 


switch ($from) {
    default:
    echo '<div class="mainblok">';
    echo '<div class="phdr"><a href="index.php"><b>Back</b></a> | Menu Editor</div>' .
    '<div class="list1"><a href="index.php?act=menu&amp;from=addgroup">Add Group</a></div>' .
    '<div class="list1"><a href="index.php?act=menu&amp;from=addlink">Add Link</a></div>' .
    '<div class="list1"><a href="index.php?act=menu&amp;from=count">Add Counter</a></div>' .
    '<div class="list2"><a href="index.php?act=menu&amp;from=edit">Edit Menu</a></div>' .
    '<div class="list2"><a href="index.php?act=menu&amp;from=edco">Repair Shop</a></div>' .
    '<div class="list1"><a href="index.php?act=menu&amp;from=set">Setup Module</a></div>' .
    '<div class="list1"><a href="index.php?act=menu&amp;from=about">About</a></div>';
   echo '</div>';
   break;


    case 'about':
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>Back To Admin</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | The Information </div>';
        echo '<div class="list1"><b> First Name :</b> MainMenu Extended</div>';
        echo '<div class="list1"><b> Versions :</b> 0.5</div>';
        echo '<div class="list1"><b>Written By :</b> Gymkhana</div>';
        echo '<div class="list1"><b>Website :</b> <a href="http://nircable.esy.es">www.nircable.esy.es</a></div>';
        echo '<div class="list1"><b> The goal: </b> save time and make it easy for administrators. </div>';
        echo '<div class="list1"> For all questions related to the use of modules, or write to the support page, or JohnCMS </div>';
       echo '</div>';
        break;


   case 'edco':
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | Edit Desk </div>';
        $m_count = $db->query("select * from cms_menu_count mode ORDER BY id;");
        if ($m_count) {
            while ($m_count_n = $m_count->fetch()) {
                echo '<div class="list1">';
                echo $m_count_n['name'] . '<br/>';
                echo '<small><a href="index.php?act=menu&amp;from=editco&amp;id=' . $m_count_n['id'] .
                    '"> Revision. </a> | 
          <a href="index.php?act=menu&amp;from=delco&amp;id=' . $m_count_n['id'] .
                    '">Delete.</a>';
                echo '</small></div>';
            }
        }

       echo '</div>';
        break;

    case 'editco':
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | <a href="index.php?act=menu&amp;from=edco"><b>Edit Counters</b></a> | Edit Counter </div>';

         if (isset($_POST['submit'])) {
            $name = htmlentities($_POST['name'], ENT_QUOTES, 'UTF-8');
            $code = htmlentities($_POST['code'], ENT_QUOTES, 'UTF-8');
            //$id = intval($_GET['id']);
            $db->exec("UPDATE `cms_menu_count` SET `name`='" . $name .
                "', `code`='" . $code . "' WHERE `id`='" . $id . "';");
            echo '<div class="list1"> Counter successfully changed. </div>';
          } else {
            //$id = intval($_GET['id']);
            $m_count = $db->query("SELECT * FROM `cms_menu_count` WHERE `id`='" . $id .
                "' LIMIT 1;");
            $m_count_n = $m_count->fetch();
            echo ' <form action="index.php?act=menu&amp;from=editco&amp;id=' . $id .
                '" method="post">
 <div class="list1">
 <b>Name:</b><br />
 <input type="text" name="name" value="' . $m_count_n['name'] . '"/></div>';
            echo '<div class="list1">
 <b> Function (Without skobochek) :</b><br />
 <input type="text" name="code" value="' . $m_count_n['code'] . '"/></div>';
            echo '<div class="phdr">
     <input type="submit" name="submit" value="Save As" />
   </div>
 </form>';
        }
       echo '</div>';
        break;

    case 'delco':
        //$id = intval($_GET['id']);
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | <a href="index.php?act=menu&amp;from=edco"><b>Edit counters </b></a> | remove access </div>';
        $db->exec("DELETE FROM `cms_menu_count` WHERE `id`='" . $id . "';");
        $db->exec("UPDATE `cms_menu_link` SET `type`='0' WHERE `type`='" . $id . "';");
        echo '<div class="list1">Counter deleted successfully. </div>';
        echo '</div>';
        break;


    case 'count':
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | Add Access </div>';
        if (isset($_POST['submit'])) {
            $name = htmlentities($_POST['name'], ENT_QUOTES, 'UTF-8');
            $code = htmlentities($_POST['code'], ENT_QUOTES, 'UTF-8');
            $db->exec("INSERT INTO `cms_menu_count` SET  `name`='" . $name .
                "', `code`='" . $code . "';");
            echo '<div class="list1">The visit was successful. </div>';
        } else {
            echo ' <form action="index.php?act=menu&amp;from=count" method="post">
 <div class="list1">
 <b>Name :</b><br />
 <input type="text" name="name" value="By Guest "/></div>';
            echo '<div class="list1">
 <b> Function (Without skobochek) :</b><br />
 <input type="text" name="code" value="gbook"/></div>';
            echo '<div class="phdr">
     <input type="submit" name="submit" value="More" />
   </div>
 </form>';
        } 
       echo '</div>';
       break;


    case 'set':
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | Setup Module </div>';
        if (isset($_POST['submit'])) {
           $config['menu_enable'] = isset($_POST['one']) ? intval($_POST['one']) : 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">Settings are saved successfully</div>';
           } else {
$color = ['red', 'green'];
echo '<form action="index.php?act=menu&amp;from=set" method="post">';
echo '<div class="menu"><p>' .
    '<h3><img src="../images/' . $color[$config['menu_enable']] . '.gif" width="16" height="16" class="left"/>&#160;Modules</h3>' .
    '<div style="font-size: x-small">' .
    '<input type="radio" value="1" name="one" ' . ($config['menu_enable'] == 1 ? 'checked="checked"' : '') . '/>&#160;ON<br>' .
    '<input type="radio" value="0" name="one" ' . (!$config['menu_enable'] ? 'checked="checked"' : '') . '/>&#160;OFF</div></p></div>';
  echo '<div class="topmenu"><input type="submit" name="submit" id="button" value="Save" /></div>' .
    '</form>';
        }
        echo '</div>';
        break;

    case 'addgroup':
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | Add Group </div>';
        if (isset($_POST['submit'])) {
            $pic = htmlentities($_POST['pic'], ENT_QUOTES, 'UTF-8');
            $sumbo = htmlentities($_POST['sumbo'], ENT_QUOTES, 'UTF-8');
            $name = htmlentities($_POST['name'], ENT_QUOTES, 'UTF-8');
            $m_group = $db->query("select count(1) from `cms_menu_group` ");
            $m_group_n = $m_group->fetch();
            $max = $m_group_n[0];
            $db->exec("INSERT INTO `cms_menu_group` SET `show`='1', `pos`='" . ($max + 1) .
                "' , `pic`='" . $pic . "', `sumbo`='" . $sumbo . "', `name`='" .
                $name . "';");

            echo '<div class="list1">Group successfully added. </div>';
        } else {
        echo '<form action="index.php?act=menu&amp;from=addgroup" method="post">' .
       '<div class="list1">' .
       '<b>Name :</b><br />' .
       '<input type="text" name="name"/></div>' .
       '<div class="list1">' .
       '<b>Select icon :</b><br />' .
       '<input type="radio" name="pic" value="" checked="checked"/> no icon <br/>';

            $filename = '../images/icon/';
            $pic_list = glob($filename . "*.png");
            foreach ($pic_list as $file) {
                $file = basename($file);
                echo '<input type="radio" name="pic" value="' . $file . '" /> ';
                echo '<img class="mme_image" alt="" src="' . $filename . $file . '" /> ' . $file .
                    '<br/>';
            }

    echo '</div>' .
     '<div class="list1">' .
     '<b>If it is not a picture, symbol: </b><br />' .
     '<input type="text" name="sumbo" value="&rArr;" /></div>' .
     '<div class="phdr">' .
     '<input type="submit" name="submit" value="More" />' .
     '</div>' .
     '</form>';
        }
        echo '</div>';
        break;

    case 'addlink':
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | Add 1 Link </div>';
       if (isset($_POST['submit'])) {
            $m_link = $db->query("select count(1) from `cms_menu_link` where `group`='" . $_POST['group'] .
                "'");
            $m_link_n = $m_link->fetch();
            $max = $m_link_n[0];

           $type = htmlentities($_POST['type'], ENT_QUOTES, 'UTF-8');
            $sumbo = htmlentities($_POST['sumbo'], ENT_QUOTES, 'UTF-8');
            $pic = htmlentities($_POST['pic'], ENT_QUOTES, 'UTF-8');
            $name = htmlentities($_POST['name'], ENT_QUOTES, 'UTF-8');
            $link = htmlentities($_POST['link'], ENT_QUOTES, 'UTF-8');
            $group = htmlentities($_POST['group'], ENT_QUOTES, 'UTF-8');
            $db->exec("INSERT INTO `cms_menu_link` SET `type`='" . $type .
                "', `pos`='" . ($max + 1) . "' , `sumbo`='" . $sumbo . "', `pic`='" . $pic .
                "', `show`='1', `name`='" . $name . "', `link`='" . $link .
                "', `group`='" . $group . "' ;");
            echo '<div class="list1"> Link successfully added. </div>';
       } else {
        echo '<form action="index.php?act=menu&amp;from=addlink" method="post">' .
        '<div class="list2">' .
        '<b>Name :</b><br />' .
        '<input type="text" name="name"/></div>' .
        '<div class="list1">' .
        '<b>URL:</b><br />' .

        '<input type="text" name="link" value="http://" /></div>' .
        '<div class="list1">' .
        '<b>Group :</b><br />';
            $m_group = $db->query("select * from cms_menu_group mode ORDER BY id;");
            if ($m_group) {
                while ($m_group_n = $m_group->fetch()) {
                    echo '<input type="radio" name="group" value="' . $m_group_n['id'] . '" /> ' . $m_group_n['name'] .
                        '<br/>';
                }
            }

          echo '</div>' .
          '<div class="list1">' .
          '<b> + Access: </b><br />' .
         '<input type="radio" name="type" value="0" checked="checked" /> no access <br/>';
            $m_count = $db->query("select * from cms_menu_count mode ORDER BY id;");
            if ($m_count) {
                while ($m_count_n = $m_count->fetch()) {
                    echo '<input type="radio" name="type" value="' . $m_count_n['id'] . '" /> ' . $m_count_n['name'] .
                        '<br/>';
                }
            }


echo '</div>' .
           '<div class="list1">' .
           '<b> Link Icon: </b><br />' .
           '<input type="radio" name="pic" value="" checked="checked"/> No icon <br/>';
       
            $filename = '../images/icon/';
            $pic_list = glob($filename . "*.png");
            foreach ($pic_list as $file) {
                $file = basename($file);
                echo '<input type="radio" name="pic" value="' . $file . '" /> ';
                echo '<img class="mme_image" alt="" src="' . $filename . $file . '" /> ' . $file .
                    '<br/>';
            }

     echo '</div>' .
               '<div class="list1">' .
               '<b> If it is not an image, icon :</b><br />' .
               '<input type="text" name="sumbo" value="&rArr;" /></div>' .
               '<div class="phdr">' .
               '<input type="submit" name="submit" value="More" />' .
               '</div>' .
             '</form>';
        }
        echo '</div>';
        break;
    


    case 'edit':
       echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | Edit </div>';


        $m_group = $db->query("select * from cms_menu_group mode ORDER BY pos;");
        if ($m_group) {
            while ($m_group_n = $m_group->fetch()) {
                if ($m_group_n['show'] == 1)
                    echo '<div class="phdr">';
                else
                    echo '<div class="footer">';
                $filename = '../images/icon/';
         
      $filename = $filename . "/" . $m_group_n['pic'];
                if (file_exists($filename) and $m_group_n['pic'] != '')
                    echo '<img class="mme_image" alt="" src="' . $filename . '" /> ';
                else
                    echo $m_group_n['sumbo'] . ' ';
                echo '<b>' . $m_group_n['name'] . '</b><br />';
                echo '<small><a href="index.php?act=menu&amp;from=editg&amp;id=' . $m_group_n['id'] .
                    '">Edit.</a> | 
           <a href="index.php?act=menu&amp;from=delg&amp;id=' . $m_group_n['id'] .
                    '">Delete.</a> | ';
                if ($m_group_n['show'] == 1)
                    echo '<a href="index.php?act=menu&amp;from=tog&amp;id=' . $m_group_n['id'] .
                        '">Hide</a> ';
                else
                    echo '<a href="index.php?act=menu&amp;from=shg&amp;id=' . $m_group_n['id'] .
                        '">Show</a> ';
                //echo '| <a href="index.php?act=menu&amp;from=upg&amp;id=' . $m_group_n['id'] .
                   // '">Top</a> | 
          //<a href="index.php?act=menu&amp;from=downg&amp;id=' . $m_group_n['id'] .
                  //  '">Down</a>';
                echo '</small></div>';
                $m_link = $db->query("select * from cms_menu_link mode ORDER BY pos;");
                if ($m_link) {
                    while ($m_link_n = $m_link->fetch()) {
                        if ($m_group_n['id'] == $m_link_n['group']) {
                            if ($m_group_n['show'] == 1 && $m_link_n['show'] == 1)
                                echo '<div class="list1">';
                            else
                                echo '<div class="list1">';

                           $filename = '../images/icon/';
                           $filename = $filename . $m_set_n['val'] . "/" . $m_link_n['pic'];
                            if (file_exists($filename) and $m_link_n['pic'] != '')
                                echo '<img class="mme_image" alt="" src="' . $filename . '" /> ';
                            else
                                echo $m_link_n['sumbo'] . ' ';
                            echo '<a href="' . $m_link_n['link'] . '">' . $m_link_n['name'] .
                                '</a><br />';
                            echo '<small><a href="index.php?act=menu&amp;from=editl&amp;id=' . $m_link_n['id'] .
                                '">Edit Link.</a> | 
                   <a href="index.php?act=menu&amp;from=dell&amp;id=' . $m_link_n['id'] .
                                '">Delete.</a> | ';
                            if ($m_group_n['show'] == 1 && $m_link_n['show'] == 1)
                                echo '<a href="index.php?act=menu&amp;from=tol&amp;id=' . $m_link_n['id'] .
                                    '">Hide</a> ';
                            else
                                echo '<a href="index.php?act=menu&amp;from=shl&amp;id=' . $m_link_n['id'] .
                                    '">Show</a> ';
                            echo '| <a href="index.php?act=menu&amp;from=upl&amp;id=' . $m_link_n['id'] .
                               '">Top</a> | ';
                           echo ' <a href="index.php?act=menu&amp;from=downl&amp;id=' . $m_link_n['id'] .
                              '">Down</a>';
                            echo '</small></div>';
                        }
                    }
                }
            }
        } else {
            echo "<p><b>Error: SQL</b><p>";
            exit();
        }

       echo '</div>';
        break;


    case 'tog':
        //$id = intval($_GET['id']);
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | <a href="index.php?act=menu&amp;from=edit"><b>Edit</b></a> | Show / To Eat</div>';
        $db->exec("UPDATE `cms_menu_group` SET `show`='0' WHERE `id`='" . $id .
            "';");
        echo '<div class="rmenu"> Group has successfully hidden. </div>';
        echo '</div>';
        break;

    case 'tol':
        //$id = intval($_GET['id']);
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | <a href="index.php?act=menu&amp;from=edit"><b>Edit</b></a> | Show / To Eat</div>';
        $db->exec("UPDATE `cms_menu_link` SET `show`='0' WHERE `id`='" . $id .
            "';");
        echo '<div class="rmenu">Link successfully hidden. </div>';
        echo '</div>';
        break;

    case 'shg':
        //$id = intval($_GET['id']);
        echo '<div class="mainblok">'; 
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | <a href="index.php?act=menu&amp;from=edit"><b>Edit </b></a> | Show / To Eat</div>';
        $db->exec("UPDATE `cms_menu_group` SET `show`='1' WHERE `id`='" . $id .
            "';");
        echo '<div class="rmenu"> The group has shown success. </div>';
        echo '</div>';
        break;

    case 'shl':
        //$id = intval($_GET['id']);
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | <a href="index.php?act=menu&amp;from=edit"><b>Edit </b></a> | Show / To Eat</div> ';
        $db->exec("UPDATE `cms_menu_link` SET `show`='1' WHERE `id`='" . $id .
            "';");
        echo '<div class="rmenu"> Links to succeed. </div>';
        echo '</div>';
        break;

    case 'delg':
        //$id = intval($_GET['id']);
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | <a href="index.php?act=menu&amp;from=edit"><b>Edit</b></a> | Remove 1 Group </div> ';
    $dead=round((($config['timeshift']+1728000) - time())/60/60/24);
    
       if ($id !=4 || $dead<=0) {
        $db->exec("DELETE FROM `cms_menu_group` WHERE `id`='" . $id . "';");
        $db->exec("DELETE FROM `cms_menu_link` WHERE `group`='" . $id . "';");
        echo '<div class="rmenu"> The group was deleted successfully. </div>';
        } else {
             
    echo $tools->displayError(' You can not delete links yet '. $dead .' the day!');
  
 echo '</div>';
    require_once ('../system/end.php');
    exit;
        }
    echo '</div>';
        break;

    case 'dell':
        //$id = intval($_GET['id']);
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | <a href="index.php?act=menu&amp;from=edit"><b>Edit </b></a> | Removing links </div> ';
        $db->exec("DELETE FROM `cms_menu_link` WHERE `id`='" . $id . "';");
        echo '<div class="rmenu"> Link deleted successfully. </div>';
        echo '</div>';
        break;
 


    case 'editl':
        //$id = intval($_GET['id']);
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | <a href="index.php?act=menu&amp;from=edit"><b>Edit</b></a> | Edit Link </div>';
         if (isset($_POST['submit'])) {
            $group = htmlentities($_POST['group'], ENT_QUOTES, 'UTF-8');
            $type = htmlentities($_POST['type'], ENT_QUOTES, 'UTF-8');
            $pic = htmlentities($_POST['pic'], ENT_QUOTES, 'UTF-8');
            $sumbo = htmlentities($_POST['sumbo'], ENT_QUOTES, 'UTF-8');
            $name = htmlentities($_POST['name'], ENT_QUOTES, 'UTF-8');
            $link = htmlentities($_POST['link'], ENT_QUOTES, 'UTF-8');
            $m_link = $db->query("select count(1) from `cms_menu_link` where `group`='" . $group .
                "'");
            $m_link_n = $m_link->fetch();
            $max = $m_link_n[0];
            $m_link = $db->query("SELECT * FROM `cms_menu_link` WHERE `id`='" . $id .
                "' LIMIT 1;");
            $m_link_n = $m_link->fetch();
            if ($group == $m_link_n['group'])
                $db->exec("UPDATE `cms_menu_link` SET `type`='" . $type .
                    "', `pic`='" . $pic . "', `show`='1', `sumbo`='" . $sumbo . "', `name`='" . $name .
                    "', `link`='" . $link . "', `group`='" . $group .
                    "' WHERE `id`='" . $id . "';");
            else
                $db->exec("UPDATE `cms_menu_link` SET `type`='" . $type .
                    "', `pic`='" . $pic . "', `pos`='" . ($max + 1) .
                    "', `show`='1', `sumbo`='" . $sumbo . "', `name`='" . $name . "', `link`='" . $link .
                    "', `group`='" . $group . "' WHERE `id`='" . $id . "';");

            echo '<div class="list1"> Link successfully changed. </div>';
        } else {
            $m_link = $db->query("SELECT * FROM `cms_menu_link` WHERE `id`='" . $id .
                "' LIMIT 1;");
            $m_link_n = $m_link->fetch();
            echo '
 <form action="index.php?act=menu&amp;from=editl&amp;id=' . $id .
                '" method="post">
 <div class="list2">
 <b>Name :</b><br />
 <input type="text" name="name" value="' . $m_link_n['name'] . '"/></div>
 <div class="list1">
 <b>URL:</b><br />
 <input type="text" name="link" value="' . $m_link_n['link'] . '" /></div>
 <div class="list1">
 <b>Group :</b><br />';

            $m_group = $db->query("select * from cms_menu_group;");
            if ($m_group) {
                while ($m_group_n = $m_group->fetch()) {
                    if ($m_link_n['group'] == $m_group_n['id'])
                        echo '<input type="radio" name="group" value="' . $m_group_n['id'] .
                            '" checked="checked" /> ' . $m_group_n['name'] . '<br/>';
                    else
                        echo '<input type="radio" name="group" value="' . $m_group_n['id'] . '" /> ' . $m_group_n['name'] .
                            '<br/>';
                }
            }
 echo '</div>' .
           '<div class="list1">' .
           '<b> + Access: </b><br />' .
           '<input type="radio" name="type" value="0" checked="checked" /> No access <br/>';
          $m_count = $db->query("select * from cms_menu_count mode ORDER BY id;");
            if ($m_count) {
                while ($m_count_n = $m_count->fetch()) {
                    echo '<input type="radio" name="type" value="' . $m_count_n['id'] . '" /> ' . $m_count_n['name'] .
                        '<br/>';
                }
            }

   echo '</div>' .
             '<div class="list1">' .
             '<b> Link Icon: </b><br />' .
             '<input type="radio" name="pic" value="" checked="checked"/> No icon <br/>';

            $filename = '../images/icon/';
    

            $pic_list = glob($filename . "*.png");
            foreach ($pic_list as $file) {
                $file = basename($file);
                echo '<input type="radio" name="pic" value="' . $file . '" /> ';
                echo '<img class="mme_image" alt="" src="' . $filename . $file . '" /> ' . $file .
                    '<br/>';
            }

echo '</div><div class="list1">' .
          '<b> If it is not an image, icon :</b><br />' .
          '<input type="text" name="sumbo" value="' . $m_link_n['sumbo'] . '" /></div>' .
         '<div class="phdr">' .
         '<input type="submit" name="submit" value=" Save As " />' .
         '</div>' .
       '</form>';

        }
        echo '</div>';
        break;


    case 'editg':
        //$id = intval($_GET['id']);
        echo '<div class="mainblok">';
        echo '<div class="phdr"><a href="index.php"><b>ADMIN CP</b></a> | <a href="index.php?act=menu"><b>Menu Editor</b></a> | <a href="index.php?act=menu&amp;from=edit"><b>Edit </b></a> | Edit Group </div>';
    $dead=round((($config['timeshift'] +1728000) - time())/60/60/24);
          if (isset($_POST['submit'])) {   
           if ($id !=4 || $dead<=0) {
             $pic = htmlentities($_POST['pic'], ENT_QUOTES, 'UTF-8');
             $sumbo = htmlentities($_POST['sumbo'], ENT_QUOTES, 'UTF-8');
            $name = htmlentities($_POST['name'], ENT_QUOTES, 'UTF-8');
             $db->exec("UPDATE `cms_menu_group` SET `show`='1', `pic`='" . $pic .
                "', `sumbo`='" . $sumbo . "', `name`='" . $name . "' WHERE `id`='" . $id . "';");
            echo '<div class="list1"> Group successfully changed. </div>';
            } else {                 
    echo ' You can not change this link yet '. $dead .' days! ';
        }
        } else  {

            $m_group = $db->query("SELECT * FROM `cms_menu_group` WHERE `id`='" . $id .
                "' LIMIT 1;");
            $m_group_n = $m_group->fetch();      
            if ($m_group_n['id']!=4 || $m_group_n['name']!='[url=http://nircable.esy.es]Nircable blog[/url]' || $dead<=0)    {

       echo '<form action="index.php?act=menu&amp;from=editg&amp;id='.$id.'" method="post">' .
          '<div class="list1">' .
          '<b>Name :</b><br />' .
          '<input type="text" name="name" value="' . $m_group_n['name'] . '" /></div>' .
        '<div class="list1">' .
          '<b>Select icon :</b><br />' .
          '<input type="radio" name="pic" value="" checked="checked"/> No icon <br/>';
            $filename = '../images/icon/';
            $pic_list = glob($filename . "*.png");
            foreach ($pic_list as $file) {
                $file = basename($file);
                echo '<input type="radio" name="pic" value="' . $file . '" /> ';
                echo '<img class="mme_image" alt="" src="' . $filename . $file . '" /> ' . $file .
                    '<br/>';
            }

echo '</div>' .
    '<div class="list1">' .
    '<b> If it is not an image, icon :</b><br />' .
    '<input type="text" name="sumbo" value="' . $m_group_n['sumbo'] . '" /></div>' .
   '<div class="phdr">' .
     '<input type="submit" name="submit" value="Save as" />' .
   '</div>' .
 '</form>';
} else {
    echo ' You can not change this link yet '. $dead .' Days!';
        }       
        } 
        echo '</div>';        
        break;






    case 'downl':
        // Перемещаем на позицию вниз
        if ($id) {
            $req = $db->query("SELECT `pos` FROM `cms_menu_link` WHERE `id` = '".$id."';");

            if ($req->rowCount()) {
                $res = $req->fetch();
                $mesto = $res['pos'];

                $req = $db->query("SELECT * FROM `cms_menu_link` WHERE `pos` > '".$mesto."' ORDER BY `pos` ASC");

                if ($req->rowCount()) {
                    $res = $req->fetch();
                    $id2 = $res['id'];
                    $mesto2 = $res['pos'];
                    $db->exec("UPDATE `cms_menu_link` SET `pos` = '".$mesto2."' WHERE `id` = '".$id."';");
                    $db->exec("UPDATE `cms_menu_link` SET `pos` = '".$mesto."' WHERE `id` = '".$id2."';");
                }
            }
        }
        header('Location: ' . getenv("HTTP_REFERER"));
        break;

 
    case 'upl':
        // Перемещаем на позицию вверх
        if ($id) {
            $req = $db->query("SELECT `pos` FROM `cms_menu_link` WHERE `id` = '".$id."';");

            if ($req->rowCount()) {
                $res = $req->fetch();
                $mesto = $res['pos'];

                $req = $db->query("SELECT * FROM `cms_menu_link` WHERE `pos` < '" . $mesto . "' ORDER BY `pos` DESC");

                if ($req->rowCount()) {
                    $res = $req->fetch();
                    $id2 = $res['id'];
                    $mesto2 = $res['pos'];
                    $db->exec("UPDATE `cms_menu_link` SET `pos` = '".$mesto2."' WHERE `id` = '".$id."';");
                    $db->exec("UPDATE `cms_menu_link` SET `pos` = '".$mesto."' WHERE `id` = '".$id2."';");
                }
            }
        }
        header('Location: ' . getenv("HTTP_REFERER") . '');
        break;



}
