Просмотр файла click/_inc/functions.php

Размер файла: 3.52Kb
<?
	function title($title)
	{
		header("Content-type: application/xhtml+xml; charset=utf-8");
		header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
		header("Last-Modified: ".gmdate("D, d M Y H:i:s")."GMT");
		header("Cache-Control: no-cache, must-revalidate");
		header("Cache-Control: max-age=0");
		header("Pragma: no-cache");
		
		return '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>'.$title.'</title>
<link href="_img/style.css" rel="stylesheet" type="text/css" />
</head>
<body>';	
	}
	
	function the_end()
	{
		global $copyright;
		return '<div class="hf">'.$copyright.'</div></body></html>';
	}
	
	function error($error,$flag=NULL)
	{
		if($flag != NULL)
		{
			write_log($flag);
		}
		
		$content = title('error!').'<div class="main">'.htmlspecialchars($error).'</div>'.the_end();
		die($content);
	}
	
	function autorize($id,$ps)
	{
		if(mysql_num_rows(mysql_query('SELECT `id` FROM `sites` WHERE `id` = '.(int)$id.' and `password` = MD5("'.mysql_escape_string($ps).'");')) == 1) return (boolean)TRUE;
		else return (boolean)FALSE;
	}
	
	function get_config($id)
	{
		$row = mysql_fetch_array(mysql_query('SELECT * FROM `sites` WHERE `id` = '.$id.';'));
		
		return $row;
	}
	
	function write_log($description)
	{
		if(!is_writable('./security_log.txt'))
		{
			die('error: in journal of safety not possible to add new record, beforehand not it is enough rights.');
		}
		
		$ip = $_SERVER['HTTP_X_REAL_IP'];
		$ua = trim($_SERVER['HTTP_USER_AGENT']);
		
		if(round(filesize('./security_log.txt')/1024) > 1024) $root = 'w+';
		else $root = 'a+';
		
		$fp = fopen('./security_log.txt',$root);
		fputs($fp,'Новая запись.'."\n");
		fputs($fp,'Дата: '.date('d/m/Y H:i:s')."\n");
		fputs($fp,'IP: '.$ip."\n");
		fputs($fp,'Host: '.trim(gethostbyaddr($ip))."\n");
		fputs($fp,'UA: '.$ua."\n");
		fputs($fp,'Замечен: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.trim($_SERVER['QUERY_STRING'])."\n");
		fputs($fp,'Примечание системы: '.trim($description)."\n");
		fputs($fp,'Переданные заголовки броузера:'."\n".'Поддержка расширений: '.trim($_SERVER['HTTP_ACCEPT'])."\n".'Язык: '.trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])."\n");
		fputs($fp,'Encoding: '.trim($_SERVER['HTTP_ACCEPT_ENCODING'])."\n");
		fputs($fp,'Кодировки: '.trim($_SERVER['HTTP_ACCEPT_CHARSET'])."\n");
		fputs($fp,'-----------------------------------'."\n");
		fclose($fp);
	}
	
	function no_access()
	{
		global $id;
		
		if($id != 1)
		{
			error('No Access!');
		}
	}
	
	function ip_exists($start_ip,$end_ip)
	{
		if(mysql_num_rows(mysql_query('SELECT `id` FROM `ips` WHERE INET_ATON("'.$start_ip.'") BETWEEN `start_ip` AND `end_ip`')) > 0) return (boolean) FALSE;
		if(mysql_num_rows(mysql_query('SELECT `id` FROM `ips` WHERE INET_ATON("'.$end_ip.'") BETWEEN `start_ip` AND `end_ip`')) > 0) return (boolean) FALSE;
		return (boolean) TRUE;
	}
	
	function money_payed()
	{
		$i = 0;

		$q = mysql_query('SELECT `have_paid` FROM `get_money` WHERE 1;');
		
		while($r = mysql_fetch_array($q))
		{
			$i = $i + $r['have_paid'];
		}
		
		return $i;
	}
	
	function v_kasse()
	{
		$i = 0;

		$q = mysql_query('SELECT `balance` FROM `sites` WHERE 1;');
		
		while($r = mysql_fetch_array($q))
		{
			$i = $i + $r['balance'];
		}
		
		return $i;
	}
?>