<?php






// autoload application components
foreach (array (
        $_SERVER['DOCUMENT_ROOT'] . '/system/configs/',
        $_SERVER['DOCUMENT_ROOT'] . '/system/plugins/'
) as $dir) {
        foreach (array_merge (glob ($dir . '*.php'), array (
        )) as $file) {
                require_once $file;
        }
}





class PDO_ extends PDO
{
        public function __construct ($dsn, $username, $password)
        {

                parent :: __construct ($dsn, $username, $password);

                //$this -> setAttribute (PDO :: ATTR_ERRMODE, PDO :: ERRMODE_EXCEPTION);
                $this -> setAttribute (PDO :: ATTR_DEFAULT_FETCH_MODE, PDO :: FETCH_ASSOC);
        
        }

        function prepare ($sql) {
                $stmt = parent :: prepare($sql, array(
                        PDO :: ATTR_STATEMENT_CLASS => array('PDOStatement_')
                ));
                return $stmt;
        }
function query($sql, $params = array()) {
$stmt = $this -> prepare($sql);
$stmt -> execute($params);
return $stmt;
}
function querySingle($sql, $params = array()) {
$stmt = $this -> query($sql, $params);
$stmt -> execute($params);
return $stmt -> fetchColumn(0);
}
function queryFetch($sql, $params = array()) {
$stmt = $this -> query($sql, $params);
$stmt -> execute($params);
return $stmt -> fetch();
}
}
class PDOStatement_ extends PDOStatement {
function execute($params = array()) {
if (func_num_args() == 1) {
$params = func_get_arg(0);
} else {
$params = func_get_args();
}
if (!is_array($params)) {
$params = array($params);
}
parent :: execute($params);
return $this;
}

function fetchSingle() {
return $this -> fetchColumn(0);
}

        function fetchAssoc() {
        $this -> setFetchMode(PDO :: FETCH_NUM);
        $data = array();
        while ($row = $this -> fetch()) {
        $data[$row[0]] = $row[1];
        }
        return $data;
        }   

}


class DB {
        public static $dbs;        
        public function __construct ($config)
        {
                $this -> getInstance($config);
        }        
        public static function getInstance ($config) {
                //
                try {
                        self :: $dbs = new PDO_ ($config['dsn'], $config['user'], $config['password']);
                }
                catch (PDOException $e) {                
                        
                        
                        
                        
                        // add to log errors
                        
                        
                        exit ('Сайт выключен из-за технических неполадок!');
                
                }
        }
}







$array = explode(" ",microtime());
$gen = $array[1] + $array[0];







// 
$DB = new DB ($config['dbh']);
        DB :: $dbs -> query ("SET NAMES 'utf8'");










if (isset ($_COOKIE['id'], $_COOKIE['pass'])) {
        $query = DB :: $dbs -> query ("SELECT * FROM `us` WHERE (`id`=?) AND (`pass`=?)", array (intval ($_COOKIE['id']), addslashes ($_COOKIE['pass'])));
        if ($query -> rowCount () != 0) {
                $us = $query -> fetch ();
                
                
                // update activity
                DB :: $dbs -> query("UPDATE `us` SET `last`='" . time () . "',`ip`=?,`soft`=? WHERE (`id`='" . $us['id'] . "')", array ($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']));
                
                
                // if last activity < 1 hour update all online
                if ((time () - $us['last']) < 3600) {
                        DB :: $dbs -> query("UPDATE `us` SET `online`=`online`+'" . (time () - $us['last']) . "' WHERE (`id`='" . $us['id'] . "')", array ($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']));
                }
                
        }
}







function H ($title = '', $menu_title = NULL)
{
    
        global $us;
        
        
        header ('content-type: text/html');
        ob_start ('ob_gzhandler');
        
        if (isset ($us)) {
                $query = DB :: $dbs -> query("SELECT * FROM `reg` WHERE (`us`='" . $us['id'] . "')");
                if ($query -> rowCount () != 0) {
                    $reg = $query -> fetch ();
                            if ($reg['dop'] == 'mod') {
                            $title = 'Одобрение регистрации';
                    }
                    elseif ($reg['dop']=='net') {
                            $title = 'Нет допуска';
                    }
                }
        }
        
        // 
        echo '<!DOCTYPE html>';
        echo '<html>';
        echo '<head>';
        echo '<meta name="description" content="Территория WAP мастера!"/>';
        echo '<meta name="keywords" content="wap форум, wap мастер, php скрипты"/>';
        echo '<meta name="viewport" content="width=device-width; initial-scale=1.0;"/>';
        echo '<link rel="shortcut icon" href="/favicon.ico?' . passgen () . '"/>';
        echo '<link rel="stylesheet" href="/styles/snowy/style.css" type="text/css"/>';
        echo '<link rel="stylesheet" href="/styles/ef.css?' . passgen () . '" type="text/css"/>';
        echo '<title>' . $title . '</title>';
        echo '</head><body>';
        
        
        
        if (isset ($us['id'])) {
               
        }
        else {
           
                

        }
echo'<div class="verx"><a href="/"><img src="/styles/logo.png" alt="Портал разработчиков"/></a></div>'; 
        if ($_SERVER['PHP_SELF'] == '/index.php') {

        
         if (isset ($us['id'])) {}else{
echo '<div class="auth"><a  href="/log.in.php">Авторизация</a> <a  href="/reg.php">Регистрация</a></div>';

}
include 'ads/advert.php';
include 'ads/advert.php';
                echo '<div class="rekl">';
                $query = DB :: $dbs -> query ("SELECT * FROM `ads` WHERE (`time`>'" . time () . "') ORDER BY RAND() LIMIT 3");
                while ($ads = $query -> fetch ()) {
                        echo '<img src="/styles/snowy/resources/n.png" alt="" align="rekl"/> <a href="' . $ads['link'] . '"><b>'. $ads['name'] .'</b></a><br/>';
                }
                echo '</div>';
        }
		
        
        
        
        
        
        if ($_SERVER['PHP_SELF'] != '/mail.php' && $_SERVER['PHP_SELF'] != '/msg.php' && $_SERVER['PHP_SELF'] != '/kab/index.php') {
                
                if (isset ($us)) {
                        
                        $n_a = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `action` WHERE (`us`='" . $us['id'] . "') AND (`see`='1')");
                        $n_m = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `msg`    WHERE (`us`='" . $us['id'] . "') AND (`see`='1')");

                        if ($us['panel']==0) {
                                echo '<div class="panell"><table width="100%" cellpadding="0" cellspacing="0"><tr>';
                                echo '<td width="25%" align="center"><a href="/kab"><img src="/images/menu/upanel.png"></a></td>';
                                echo '<td width="25%" align="center"><a href="/mail.php"><img src="/images/menu/message.png"> ' . ($n_m != 0 ? '<span class="coun">+' . $n_m . '</span>' : '') . '</a></td>';
                                echo '<td width="25%" align="center"><a href="/action.php"><img src="/images/menu/lenta.png"> ' . ($n_a != 0 ? '<span class="coun">+' . $n_a . '</span>' : '') . '</a></td>';
                                echo '<td width="25%" align="center"><a href="/?exit"><img src="/images/menu/logout.png"></a></td>';
                                echo '</tr></table></div>';
                        }
                        if (isset ($menu_title)) {
 
                echo '<div class="menu">' . $menu_title . '</div>';
        
        }       
if ( $us['wmid']== NULL){
echo '<div class="raz"><a href="/bill/wmid.php"> <font color=#ff0000>У вас не заполнены данные WMR и WMID просим вас заполнить их и потвердите!</font></a></div>' ;
}
if ( $us['qiwi']== NULL){
echo '<div class="raz"><a href="/bill/qiwi.php"> <font color=#ff0000>У вас не заполнены данные QIWI просим вас заполнить их и потвердите!</font></a></div>' ;
}
                        else {

                                if ($n_a != 0) {
                                }
                                
                                if ($n_m != 0) {
                                }

                        }
                    
                }
    
        }
    
           $query = DB :: $dbs -> query ("SELECT * FROM `ban` WHERE (`us`='" . $us['id'] . "') AND (`end`>'" . time () . "')");
        if ($query -> rowCount () != 0) {
                $ban = $query -> fetch ();                
                if ($_SERVER['PHP_SELF'] != '/ban.php') {
                        header ('location: /ban.php');
                        exit;
                }
        }
        
        
    
}
//Модерация юзерей.
$time = microtime(1);
if($us['id'] == true) {
$query = DB :: $dbs -> query("SELECT `id`,`dop`,`us` FROM `reg` WHERE (`us` = '" . $us['id'] . "')");
if ($query -> rowCount () != 0) {
$reg = $query -> fetch ();
if ($reg['dop'] == 'mod') {
$title = 'Одобрение регистрации';
$menu_title = 'Одобрение регистрации';
echo '<div class="menu2">Одобрение регистрации</div>';
echo '<div class="access">Дождитесь одобрения вашей регистрации.</div>';
F ();
exit;
}
elseif ($reg['dop']=='net') {
$title = 'Нет допуска';
$menu_title  = 'Нет допуска';
echo '<div class="menu2">Одобрение регистрации</div>';
echo '<div class="lst">К сожалению вы не были допущены на сайт!</div>';
F ();
exit;
}
}
}


function F ()
{
        


        
        $last = DB :: $dbs -> queryFetch ("SELECT * FROM `us` ORDER BY `reg` DESC LIMIT 1");
        
        if ($_SERVER['PHP_SELF']!='/index.php') {
                echo '<div class="navg"><img src="/images/homepage.gif" alt=""/> <a href="/">На главную</a></div>';
        }
        
        

echo '<div class="blk">';
                
        echo 'Онлайн: <a href="/online.php" style="color:white;">' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `us` WHERE (`last`>'" . (time () - 3600) . "')") . '</a> из <a href="/masters.php" style="color:white;">' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `us`") . ' мастеров</a></a><br/>';
        echo 'Новичек: <a href="/us' . $last['id'] . '" style="color:white;"><b>' . $last['nick'] . '</b></a><br/>';
        
        echo '© WAP-MAS.RU by <a href="/us1"><font color="orange"><b>DoTTeD</b></font></a>';
                
        echo '</div>';

      


echo '<center><a href="http://statok.net/go/10829"><img src="http://statok.net/image/10829" alt="Statok.net" /></a>   <a href="http://king-top.ru/go/11"><img src="http://king-top.ru/img/11" alt="King-TOP.RU" /></a></center>';
}