View file sys/fnc.php

File size: 3.32Kb
<?php
session_start();
$DB_HOST='localhost';//адрес хоста базы
$DB_USER='';//имя пользователя базы
$DB_PASS='';//пароль пользователя базы
$DB_BASE='';//база
$str=10;//сколько сообщений выводить на страницу





$db = new mysqli($DB_HOST,$DB_USER,$DB_PASS,$DB_BASE);
$db->query('set charset utf8'); 
$db->query('SET names utf8'); 
$db->query('set character_set_client="utf8"'); 
$db->query('set character_set_connection="utf8"'); 
$db->query('set character_set_result="utf8"');


$time=time();



function vremja($time)
{



$timep="".date("j M  в H:i", $time)."";
$time_p[0]=date("j n ", $time);
$time_p[1]=date("H:i", $time);


if ($time_p[0]==date("j n Y"))$timep=date("H:i:s", $time);

if ($time_p[0]==date("j n Y", time()-60*60*24))$timep="Вчера в $time_p[1]";




$timep=str_replace("Jan","Янв",$timep);
$timep=str_replace("Feb","Фев",$timep);
$timep=str_replace("Mar","Марта",$timep);
$timep=str_replace("May","Мая",$timep);
$timep=str_replace("Apr","Апр",$timep);
$timep=str_replace("Jun","Июня",$timep);
$timep=str_replace("Jul","Июля",$timep);
$timep=str_replace("Aug","Авг",$timep);
$timep=str_replace("Sep","Сент",$timep);
$timep=str_replace("Oct","Окт",$timep);
$timep=str_replace("Nov","Ноября",$timep);
$timep=str_replace("Dec","Дек",$timep);
return $timep;
}



function mess_str($pref,$page,$dop)
{
	global $db,$str;
	$mess = $db->query("select * from `".$pref."` $dop");
	$mess_col=$mess->num_rows;
	$str_col=ceil($mess_col/$str);
	for($i=1; $i<$str_col+1; $i++)
	{
		if(($page/$str+1)==$i)
		{
			echo $i;
		}
		else
		{
			echo'<a href="javascript:'.$pref.'_mess_str('.($i-1)*$str.')">'.$i.'</a>';
		}
	}
	$mess->close();
}

function filtr($msg)
{
	$msg=trim(htmlspecialchars($msg));
	return $msg;
}

function bbcod($msg)
{
	$msg=str_replace('[br]','<br>',$msg);
	$msg=str_replace("\n",'<br>',$msg);
	$msg=str_replace('[cit]','<i>',$msg);
	$msg=str_replace('[/cit]','</i><p>',$msg);
	return $msg;
}
function ajax()
{
?>
	<script type="text/javascript">


	//подключение
	function getXmlHttp()
	{
		var xmlhttp;
		
		try 
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		
		catch (e) 
		{
			try 
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			
			catch (E) 
			{
				xmlhttp = false;
			}
			
		}

		if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
		{
			xmlhttp = new XMLHttpRequest();
		}
		
		return xmlhttp;
	}


	</script>


	<?
	$dir=opendir("ajax/");
	while($file=readdir($dir))
	{
		if(($file!=".") and ($file!=".."))
		{
			echo'<script type="text/javascript" src="ajax/'.$file.'"></script>';
		}
	}
	closedir($dir);
}








$log=filtr($_SESSION['login']);
$pass=filtr($_SESSION['password']);

if($log!="" and $pass!="")
{
	
		$u=$db->query("select * from `user` where `user`='$log' and `pass`='$pass'");
		if($u->num_rows==0)
		{
			unset($_SESSION['login']);
			unset($_SESSION['password']);
			unset($log);
			unset($pass);
			$u->close();
		}
		else
		{
			$user = $u->fetch_array();
		}
}
else
{
	unset($_SESSION['login']);
	unset($_SESSION['password']);
	unset($log);
	unset($pass);
}
?>