<?

$whoisonline = false;

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);

if ($userdata['user_level'] != ADMIN) message_die(GENERAL_ERROR,'Тебе сюда нельзя!!!Пошел вон!!');

if (!isset($_GET[s])) $showmod=1; else $showmod=intval($_GET[s]);

if (isset($_GET[addbot]))
            {
                        $sql = "SELECT MAX(id) AS total
                                FROM " . USERS_TABLE.'_bots';
                        if ( !($result = $db->sql_query($sql)) )
                        {
                                message_die(GENERAL_ERROR, 'Could not obtain next user_id information', '', __LINE__, __FILE__, $sql);
                        }

                        if ( !($row = $db->sql_fetchrow($result)) )
                        {
                                message_die(GENERAL_ERROR, 'Could not obtain next user_id information', '', __LINE__, __FILE__, $sql);
                        }
                        $id = $row['total'] + 1;
            $bot=addslashes(trim(stripslashes(stripslashes(urldecode($_GET[addbot])))));
            $view=addslashes(trim(stripslashes(stripslashes(urldecode($_GET[view])))));

            $sql="INSERT INTO `".USERS_TABLE."_bots` VALUES ( '$id', '$bot', '$view', 0, '', '', 1 )";
            $db->sql_query($sql);
            header('Location: bot.php?s='.$showmod);
            }

if (isset($_GET[del]))
            {
            $bot=intval($_GET[del]);
            $sql="DELETE FROM `".USERS_TABLE."_bots` WHERE `id` = '".$bot."'";
            $db->sql_query($sql);
            header('Location: bot.php?s='.$showmod);
            }


if (isset($_GET[hide]))
            {
            $bot=intval($_GET[hide]);
            $sql="UPDATE ".USERS_TABLE."_bots SET `show` = 0 WHERE `id` = '".$bot."'";
            $db->sql_query($sql);
            header('Location: bot.php?s='.$showmod);
            }

if (isset($_GET[show]))
            {
            $bot=intval($_GET[show]);
            $sql="UPDATE ".USERS_TABLE."_bots SET `show` = 1 WHERE `id` = '".$bot."'";
            $db->sql_query($sql);
            header('Location: bot.php?s='.$showmod);
            }

if (isset($_GET[review]))
            {
            $id=intval($_GET[id]);
            $bot=addslashes(trim(stripslashes(stripslashes(urldecode($_GET[review])))));
            $bot2=addslashes(trim(stripslashes(stripslashes(urldecode($_GET[rename])))));
            $sql="UPDATE ".USERS_TABLE."_bots SET `view` = '".$bot."', `name` = '".$bot2."' WHERE `id` = '".$id."'";
            $db->sql_query($sql);
            header('Location: bot.php?s='.$showmod);
            }

if($showmod==0)
  $result = $db->sql_query("SELECT * FROM `".USERS_TABLE."_bots` ORDER BY `lastvisit` DESC");
  else
  $result = $db->sql_query("SELECT * FROM `".USERS_TABLE."_bots` WHERE lastvisit>".(time()-3600*30)." ORDER BY `lastvisit` DESC");
  $res=$db->sql_fetchrowset($result);

if (!$result) message_die(GENERAL_ERROR,'Not installed.');
$i=0;
$out.='<table width="100%" cellpadding="4" cellspacing="0" border="0" class="forumline">';
$out.='<tr>
<td class="catSides">
<span class="cattitle">Список</span>
</td>
</tr>';
if (count($res)>0) {
while ($i<count($res)) {
if ($res[$i][lastvisit]>100) {
   $mydate=date("d.m.Y H:i",$res[$i][lastvisit]);
   if (date("d.m.Y",$res[$i][lastvisit])===date("d.m.Y")) $mydate=$mydate;
   }
   else $mydate='-';
$mydata=$res[$i][ip];
if ($res[$i][show]==1) $hid='|<a href="bot.php?s='.$showmod.'&hide='.$res[$i][id].'">Скрывать</a>';
   else $hid='|<a href="bot.php?s='.$showmod.'&show='.$res[$i][id].'">Показывать</a>';
if (trim($mydata)==='') $mydata='-'; else $mydata.=' ('.$res[$i][was].')';
$out.='<tr><td class="row1"><a href="bot.php?s='.$showmod.'&del='.$res[$i][id].'">Уд</a>'.$hid.'<br/><b>IP/user-agent</b>: '.$res[$i][name].'<br/><b>Название</b>: '.$res[$i][view].'<br/><b>Посл.IP</b>:<br/>'.$mydata.'<br/><b>Посл.визит</b>:<br/>'.$mydate.'</td></tr>';
$i++;
}
$out.='<tr><td class="row1">';
if($showmod==0) $out.='- <a href="bot.php?s=1">Показать посещения только за сегодня</a>'; else
$out.='- <a href="bot.php?s=0">Показать всех</a></tr></td>';
} else $out.='<tr>
<td class="row1">Ботов за последние 30 часов не было<br/>- <a href="bot.php?s=0">Показать всех</a></tr></td>';

function inarray($needle, $haystack)
{
        for($i = 0; $i < sizeof($haystack); $i++ )
        {
                if( $haystack[$i] == $needle )
                {
                        return true;
                }
        }
        return false;
}

$out.='<tr>
<td class="catSides">
<span class="cattitle">Добавить бота</span>
</td>
</tr>
<form method=GET><input type=hidden name=s value='.$showmod.'>
<tr>
<td class="row1"><input type=text name=addbot value="ip/user agent">
<br><input type=text name=view value="название">
<br><input type=submit>
</form></table>';
message_die('na',$out);
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
?>