<?php
require('../flowap/system.php');
switch($act) {
    default: 
    	$title->SetTitle('Гости онлайн');
    	$title->GetHeader();
	    // для пагинации
	    $onl = DB::$dbs->querySingle('SELECT COUNT(id) FROM `online` WHERE `time` > ?',[time() - 360]);
	    $num = 10;
	    $total = intval(($onl - 1) / $num) + 1;
	    $page = isset($_GET['page'])?intval($_GET['page']):1;
	    if(empty($page) or $page < 0) $page = 1;
	    if($page > $total) $page = $total;
	    $start = $page * $num - $num;
    	$sql = DB::$dbs->query("SELECT `cool`,`usera`,`time`,`id`,`color`,`bote`,`url` FROM `online` WHERE `time` > ? ORDER BY `time` DESC LIMIT $start, $num",[time() - 360])->fetchAll(PDO::FETCH_BOTH);
        foreach ($sql as $online): ?>
        	<div class="flowap3 flowap3d">
        		<div class="bogess">
                    <?php echo $online['bote']==1?'<i class="fas fa-user-secret" style="margin-right:3px;"></i>':'<i class="fad fa-user-alt" style="margin-right:3px;"></i>'?> <span style="cursor: not-allowed;color:<?php echo $online['color'];?>;font-weight: 700;text-shadow: 0 0 4px <?php echo $online['color'];?>;">Гость #<?php echo $online['id'];?></span> <span style="color: orange;font-size: 10px;vertical-align: 5px;" title="переходов по сайту">[<?php echo $online['cool'];?>]</span>
        			<time class="fontniz2" style="float: right;" title="время">
						<i class="far fa-clock"></i> <?php echo functions::vremja($online['time']);?>
					</time>	
        		</div>
        	</div>
    	<?php endforeach;
    	echo functions::page('?',$start,$total);
    	$title->GetFooter();
	break;
    case 'all':
        $title->SetTitle('Гости онлайн');
        $title->GetHeader();
        /////
        function boters1($text) {
            if (isset($text)):
                $options = ['builtwith.com', 'google.com','yandex.com','xml-sitemaps.com','mj12bot.com','Google Favicon','clarabot.info'];
                foreach($options as $row):
                    if (stripos($text, $row)):
                        return 1;
                    endif;
                endforeach;
            endif;
            return 0;
        }
        // для пагинации
        $onl = DB::$dbs->querySingle('SELECT COUNT(id) FROM `online`');
        $num = 10;
        $total = intval(($onl - 1) / $num) + 1;
        $page = isset($_GET['page'])?intval($_GET['page']):1;
        if(empty($page) or $page < 0) $page = 1;
        if($page > $total) $page = $total;
        $start = $page * $num - $num;
        $sql = DB::$dbs->query("SELECT `cool`,`usera`,`time`,`id`,`color`,`bote` FROM `online` ORDER BY `time` DESC LIMIT $start, $num")->fetchAll(PDO::FETCH_BOTH);
        foreach ($sql as $online): ?>
            <div class="flowap3 flowap3d">
                <div class="fontniz">
                    <?php echo boters1($online['usera']);?><?php echo $online['bote']==1?'<i class="fas fa-user-secret" style="margin-right:3px;"></i>':'<i class="fad fa-user-alt" style="margin-right:3px;"></i>'?> <span style="cursor: not-allowed;color:<?php echo $online['color'];?>;font-weight: 700;text-shadow: 0 0 4px <?php echo $online['color'];?>;">Гость #<?php echo $online['id'];?></span> <span style="color: orange;font-size: 10px;vertical-align: 5px;" title="переходов по сайту">[<?php echo $online['cool'];?>]</span>
                    <time class="fontniz2" style="float: right;" title="время">
                        <i class="far fa-clock"></i> <?php echo functions::vremja($online['time']);?>
                    </time> 
                </div>
                <div class="bogess"><?php echo $online['usera'];?></div>
            </div>
        <?php endforeach;
        echo functions::page('?',$start,$total);
        $title->GetFooter();    
    break;
}
?>