Просмотр файла inc/func.php

Размер файла: 14.48Kb
<?php

if(isset($_COOKIE['login']) && isset($_COOKIE['pass'])){
if(empty($_SESSION['login']) && empty($_SESSION['pass'])){
$_SESSION['login'] = htmlspecialchars($_COOKIE['login']);
$_SESSION['pass'] = htmlspecialchars($_COOKIE['pass']);
}
}else{
if(isset($_SESSION['login']) && isset($_SESSION['pass'])){
$login_st = htmlspecialchars($_SESSION['login']);
$pass_st = htmlspecialchars($_SESSION['pass']);
SetCookie('login', $login_st, time() +3600 * 24 * 365);
SetCookie('pass', $pass_st, time() +3600 * 24 * 365);
}
}

class Navigator
{
function __construct($all,$pnumber,$script,$query=''){
$this->all=$all;
$this->pnumber=$pnumber;
$this->query=$query;
$this->script=$script;
$this->page=isset($_GET['page']) ? (int)$_GET['page'] : 1;
if(isset($_POST['page'])){
$this->page=(int)$_POST['page'];}
}
function start()
{
$this->num_pages=ceil($this->all/$this->pnumber);
if (isset($_GET['last']))
$this->page=$this->num_pages;
$this->start=$this->page*$this->pnumber-$this->pnumber;
if ($this->page > $this->num_pages || $this->page < 1)
{
$this->page=1;
$this->start=0;
}
return $this->start;
}
function navi()
{
if ($this->num_pages<2)
return '';
$buff='<div class="foot">';
if($this->page>1){
$n=$this->page;
$n--;
$buff.= '&laquo;<a href="'.$this->script.''.$n.''.$this->query.'">Назад</a>';}
if(($this->page>1) && ($this->page != $this->num_pages)){$buff.= ' | ';}
if($this->page != $this->num_pages){
$p=$this->page;
$p++;
$buff.= '<a href="'.$this->script.''.$p.''.$this->query.'">Далее</a>&raquo;';}
$buff.='<br/>';
for($pr = '', $i =1; $i <= $this->num_pages; $i++){
$buff.= 
$pr=(($i == 1 || $i == $this->num_pages || abs($i-$this->page) < 3) ? ($i == $this->page ? " ($i) " : ' <a href="'.$this->script.''.$i.''.$this->query.'">'.$i.'</a> ') : (($pr == '..' || $pr == '')? '' : '..'));}
$buff.= '';
$buff.='</div>';
return $buff.'';
}
}

function smile($text)
{
$text = str_replace(':01:','<img src="../smile/1.gif" alt="*"/>',$text);
$text = str_replace(':02:','<img src="../smile/2.gif" alt="*"/>',$text);
$text = str_replace(':03:','<img src="../smile/3.gif" alt="*"/>',$text);
$text = str_replace(':04:','<img src="../smile/4.gif" alt="*"/>',$text);
$text = str_replace(':05:','<img src="../smile/5.gif" alt="*"/>',$text);
$text = str_replace(':06:','<img src="../smile/6.gif" alt="*"/>',$text);
$text = str_replace(':07:','<img src="../smile/7.gif" alt="*"/>',$text);
$text = str_replace(':08:','<img src="../smile/8.gif" alt="*"/>',$text);
$text = str_replace(':09:','<img src="../smile/9.gif" alt="*"/>',$text);
$text = str_replace(':10:','<img src="../smile/10.gif" alt="*"/>',$text);
$text = str_replace(':11:','<img src="../smile/11.gif" alt="*"/>',$text);
$text = str_replace(':12:','<img src="../smile/12.gif" alt="*"/>',$text);
$text = str_replace(':13:','<img src="../smile/13.gif" alt="*"/>',$text);
$text = str_replace(':14:','<img src="../smile/14.gif" alt="*"/>',$text);
$text = str_replace(':15:','<img src="../smile/15.gif" alt="*"/>',$text);
$text = str_replace(':16:','<img src="../smile/16.gif" alt="*"/>',$text);
$text = str_replace(':17:','<img src="../smile/17.gif" alt="*"/>',$text);
$text = str_replace(':18:','<img src="../smile/18.gif" alt="*"/>',$text);
$text = str_replace(':19:','<img src="../smile/19.gif" alt="*"/>',$text);
$text = str_replace(':20:','<img src="../smile/20.gif" alt="*"/>',$text);
$text = str_replace(':21:','<img src="../smile/21.gif" alt="*"/>',$text);
$text = str_replace(':22:','<img src="../smile/22.gif" alt="*"/>',$text);
$text = str_replace(':23:','<img src="../smile/23.gif" alt="*"/>',$text);
$text = str_replace(':24:','<img src="../smile/24.gif" alt="*"/>',$text);
$text = str_replace(':25:','<img src="../smile/25.gif" alt="*"/>',$text);
$text = str_replace(':26:','<img src="../smile/26.gif" alt="*"/>',$text);
$text = str_replace(':27:','<img src="../smile/27.gif" alt="*"/>',$text);
$text = str_replace(':28:','<img src="../smile/28.gif" alt="*"/>',$text);
$text = str_replace(':29:','<img src="../smile/29.gif" alt="*"/>',$text);
$text = str_replace(':30:','<img src="../smile/30.gif" alt="*"/>',$text);
$text = str_replace(':31:','<img src="../smile/31.gif" alt="*"/>',$text);
$text = str_replace(':32:','<img src="../smile/32.gif" alt="*"/>',$text);
$text = str_replace(':33:','<img src="../smile/33.gif" alt="*"/>',$text);
$text = str_replace(':34:','<img src="../smile/34.gif" alt="*"/>',$text);
$text = str_replace(':35:','<img src="../smile/35.gif" alt="*"/>',$text);
$text = str_replace(':36:','<img src="../smile/36.gif" alt="*"/>',$text);
$text = str_replace(':37:','<img src="../smile/37.gif" alt="*"/>',$text);
$text = str_replace(':38:','<img src="../smile/38.gif" alt="*"/>',$text);
$text = str_replace(':39:','<img src="../smile/39.gif" alt="*"/>',$text);
$text = str_replace(':40:','<img src="../smile/40.gif" alt="*"/>',$text);
$text = str_replace(':41:','<img src="../smile/41.gif" alt="*"/>',$text);
$text = str_replace(':42:','<img src="../smile/42.gif" alt="*"/>',$text);
$text = str_replace(':43:','<img src="../smile/43.gif" alt="*"/>',$text);
$text = str_replace(':44:','<img src="../smile/44.gif" alt="*"/>',$text);
$text = str_replace(':45:','<img src="../smile/45.gif" alt="*"/>',$text);
$text = str_replace(':46:','<img src="../smile/46.gif" alt="*"/>',$text);
$text = str_replace(':47:','<img src="../smile/47.gif" alt="*"/>',$text);
$text = str_replace(':48:','<img src="../smile/48.gif" alt="*"/>',$text);
$text = str_replace(':49:','<img src="../smile/49.gif" alt="*"/>',$text);
$text = str_replace(':50:','<img src="../smile/50.gif" alt="*"/>',$text);
$text = str_replace(':51:','<img src="../smile/51.gif" alt="*"/>',$text);
$text = str_replace(':52:','<img src="../smile/52.gif" alt="*"/>',$text);
$text = str_replace(':53:','<img src="../smile/53.gif" alt="*"/>',$text);
$text = str_replace(':54:','<img src="../smile/54.gif" alt="*"/>',$text);
$text = str_replace(':55:','<img src="../smile/55.gif" alt="*"/>',$text);
$text = str_replace(':56:','<img src="../smile/56.gif" alt="*"/>',$text);
$text = str_replace(':57:','<img src="../smile/57.gif" alt="*"/>',$text);
$text = str_replace(':58:','<img src="../smile/58.gif" alt="*"/>',$text);
$text = str_replace(':59:','<img src="../smile/59.gif" alt="*"/>',$text);
$text = str_replace(':60:','<img src="../smile/60.gif" alt="*"/>',$text);
$text = str_replace(':61:','<img src="../smile/61.gif" alt="*"/>',$text);
$text = str_replace(':62:','<img src="../smile/62.gif" alt="*"/>',$text);
$text = str_replace(':63:','<img src="../smile/63.gif" alt="*"/>',$text);
$text = str_replace(':64:','<img src="../smile/64.gif" alt="*"/>',$text);
$text = str_replace(':65:','<img src="../smile/65.gif" alt="*"/>',$text);
$text = str_replace(':66:','<img src="../smile/66.gif" alt="*"/>',$text);
$text = str_replace(':67:','<img src="../smile/67.gif" alt="*"/>',$text);
$text = str_replace(':68:','<img src="../smile/68.gif" alt="*"/>',$text);
$text = str_replace(':69:','<img src="../smile/69.gif" alt="*"/>',$text);
$text = str_replace(':70:','<img src="../smile/70.gif" alt="*"/>',$text);
$text = str_replace(':71:','<img src="../smile/71.gif" alt="*"/>',$text);
$text = str_replace(':72:','<img src="../smile/72.gif" alt="*"/>',$text);
$text = str_replace(':73:','<img src="../smile/73.gif" alt="*"/>',$text);
$text = str_replace(':74:','<img src="../smile/74.gif" alt="*"/>',$text);
$text = str_replace(':75:','<img src="../smile/75.gif" alt="*"/>',$text);
$text = str_replace(':76:','<img src="../smile/76.gif" alt="*"/>',$text);
$text = str_replace(':77:','<img src="../smile/77.gif" alt="*"/>',$text);
return $text;
}

function smiles($text)
{
$text = str_replace('<img src="../smile/1.gif" alt="*"/>',':1:',$text);
$text = str_replace('<img src="../smile/2.gif" alt="*"/>',':2:',$text);
$text = str_replace('<img src="../smile/3.gif" alt="*"/>',':3:',$text);
$text = str_replace('<img src="../smile/4.gif" alt="*"/>',':4:',$text);
$text = str_replace('<img src="../smile/5.gif" alt="*"/>',':5:',$text);
$text = str_replace('<img src="../smile/6.gif" alt="*"/>',':6:',$text);
$text = str_replace('<img src="../smile/7.gif" alt="*"/>',':7:',$text);
$text = str_replace('<img src="../smile/8.gif" alt="*"/>',':8:',$text);
$text = str_replace('<img src="../smile/9.gif" alt="*"/>',':9:',$text);
$text = str_replace('<img src="../smile/10.gif" alt="*"/>',':10:',$text);
$text = str_replace('<img src="../smile/11.gif" alt="*"/>',':11:',$text);
$text = str_replace('<img src="../smile/12.gif" alt="*"/>',':12:',$text);
$text = str_replace('<img src="../smile/13.gif" alt="*"/>',':13:',$text);
$text = str_replace('<img src="../smile/14.gif" alt="*"/>',':14:',$text);
$text = str_replace('<img src="../smile/15.gif" alt="*"/>',':15:',$text);
$text = str_replace('<img src="../smile/16.gif" alt="*"/>',':16:',$text);
$text = str_replace('<img src="../smile/17.gif" alt="*"/>',':17:',$text);
$text = str_replace('<img src="../smile/18.gif" alt="*"/>',':18:',$text);
$text = str_replace('<img src="../smile/19.gif" alt="*"/>',':19:',$text);
$text = str_replace('<img src="../smile/20.gif" alt="*"/>',':20:',$text);
$text = str_replace('<img src="../smile/21.gif" alt="*"/>',':21:',$text);
$text = str_replace('<img src="../smile/22.gif" alt="*"/>',':22:',$text);
$text = str_replace('<img src="../smile/23.gif" alt="*"/>',':23:',$text);
$text = str_replace('<img src="../smile/24.gif" alt="*"/>',':24:',$text);
$text = str_replace('<img src="../smile/25.gif" alt="*"/>',':25:',$text);
$text = str_replace('<img src="../smile/26.gif" alt="*"/>',':26:',$text);
$text = str_replace('<img src="../smile/27.gif" alt="*"/>',':27:',$text);
$text = str_replace('<img src="../smile/28.gif" alt="*"/>',':28:',$text);
$text = str_replace('<img src="../smile/29.gif" alt="*"/>',':29:',$text);
$text = str_replace('<img src="../smile/30.gif" alt="*"/>',':30:',$text);
$text = str_replace('<img src="../smile/31.gif" alt="*"/>',':31:',$text);
$text = str_replace('<img src="../smile/32.gif" alt="*"/>',':32:',$text);
$text = str_replace('<img src="../smile/33.gif" alt="*"/>',':33:',$text);
$text = str_replace('<img src="../smile/34.gif" alt="*"/>',':34:',$text);
$text = str_replace('<img src="../smile/35.gif" alt="*"/>',':35:',$text);
$text = str_replace('<img src="../smile/36.gif" alt="*"/>',':36:',$text);
$text = str_replace('<img src="../smile/37.gif" alt="*"/>',':37:',$text);
$text = str_replace('<img src="../smile/38.gif" alt="*"/>',':38:',$text);
$text = str_replace('<img src="../smile/39.gif" alt="*"/>',':39:',$text);
$text = str_replace('<img src="../smile/40.gif" alt="*"/>',':40:',$text);
$text = str_replace('<img src="../smile/41.gif" alt="*"/>',':41:',$text);
$text = str_replace('<img src="../smile/42.gif" alt="*"/>',':42:',$text);
$text = str_replace('<img src="../smile/43.gif" alt="*"/>',':43:',$text);
$text = str_replace('<img src="../smile/44.gif" alt="*"/>',':44:',$text);
$text = str_replace('<img src="../smile/45.gif" alt="*"/>',':45:',$text);
$text = str_replace('<img src="../smile/46.gif" alt="*"/>',':46:',$text);
$text = str_replace('<img src="../smile/47.gif" alt="*"/>',':47:',$text);
$text = str_replace('<img src="../smile/48.gif" alt="*"/>',':48:',$text);
$text = str_replace('<img src="../smile/49.gif" alt="*"/>',':48:',$text);
$text = str_replace('<img src="../smile/50.gif" alt="*"/>',':50:',$text);
$text = str_replace('<img src="../smile/51.gif" alt="*"/>',':51:',$text);
$text = str_replace('<img src="../smile/52.gif" alt="*"/>',':52:',$text);
$text = str_replace('<img src="../smile/53.gif" alt="*"/>',':53:',$text);
$text = str_replace('<img src="../smile/54.gif" alt="*"/>',':54:',$text);
$text = str_replace('<img src="../smile/55.gif" alt="*"/>',':55:',$text);
$text = str_replace('<img src="../smile/56.gif" alt="*"/>',':56:',$text);
$text = str_replace('<img src="../smile/57.gif" alt="*"/>',':57:',$text);
$text = str_replace('<img src="../smile/58.gif" alt="*"/>',':58:',$text);
$text = str_replace('<img src="../smile/59.gif" alt="*"/>',':59:',$text);
$text = str_replace('<img src="../smile/60.gif" alt="*"/>',':60:',$text);
$text = str_replace('<img src="../smile/61.gif" alt="*"/>',':61:',$text);
$text = str_replace('<img src="../smile/62.gif" alt="*"/>',':62:',$text);
$text = str_replace('<img src="../smile/63.gif" alt="*"/>',':63:',$text);
$text = str_replace('<img src="../smile/64.gif" alt="*"/>',':64:',$text);
$text = str_replace('<img src="../smile/65.gif" alt="*"/>',':65:',$text);
$text = str_replace('<img src="../smile/66.gif" alt="*"/>',':66:',$text);
$text = str_replace('<img src="../smile/67.gif" alt="*"/>',':67:',$text);
$text = str_replace('<img src="../smile/68.gif" alt="*"/>',':68:',$text);
$text = str_replace('<img src="../smile/69.gif" alt="*"/>',':69:',$text);
$text = str_replace('<img src="../smile/70.gif" alt="*"/>',':70:',$text);
$text = str_replace('<img src="../smile/71.gif" alt="*"/>',':71:',$text);
$text = str_replace('<img src="../smile/72.gif" alt="*"/>',':72:',$text);
$text = str_replace('<img src="../smile/73.gif" alt="*"/>',':73:',$text);
$text = str_replace('<img src="../smile/74.gif" alt="*"/>',':74:',$text);
$text = str_replace('<img src="../smile/75.gif" alt="*"/>',':75:',$text);
$text = str_replace('<img src="../smile/76.gif" alt="*"/>',':76:',$text);
$text = str_replace('<img src="../smile/77.gif" alt="*"/>',':77:',$text);
return $text;
}

function pol($pol)
{
switch($pol)
{
case '1':
return 'Мужской';
break;
case '2':
return 'Женский';
break;
}
}

$sql = mysql_query("SELECT * FROM `users` WHERE `login`='".mysql_real_escape_string(htmlspecialchars($_SESSION['login']))."' AND `password`='".mysql_real_escape_string(htmlspecialchars($_SESSION['pass']))."'");
$s = mysql_fetch_array($sql);
if(empty($s['status'])){ $s['status']=0; }

$online = mysql_num_rows(mysql_query("SELECT * FROM `online` WHERE `ip`='".mysql_real_escape_string(htmlspecialchars($_SERVER['REMOTE_ADDR']))."';"));
if($online == 0){
mysql_query("INSERT INTO `online` SET `ip`='".mysql_real_escape_string(htmlspecialchars($_SERVER['REMOTE_ADDR']))."', `date`=NOW()");
}else{
mysql_query("UPDATE `online` SET `date`=NOW() WHERE `ip`='".mysql_real_escape_string(htmlspecialchars($_SERVER['REMOTE_ADDR']))."';");
}
mysql_query("DELETE FROM `online` WHERE `date` < NOW() - INTERVAL '5' MINUTE");

if(!empty($_SESSION['login'])){
$online_user = mysql_num_rows(mysql_query("SELECT * FROM `online_user` WHERE `login`='".mysql_real_escape_string(htmlspecialchars($_SESSION['login']))."'"));
if($online_user == 0){
mysql_query("INSERT INTO `online_user` SET `login`='".mysql_real_escape_string(htmlspecialchars($_SESSION['login']))."', `date`=NOW()");
}else{
mysql_query("UPDATE `online_user` SET `date`=NOW() WHERE `login`='".mysql_real_escape_string(htmlspecialchars($_SESSION['login']))."'");
}
mysql_query("DELETE FROM `online_user` WHERE `date` < NOW() - INTERVAL '5' MINUTE");
}

?>