View file dcmssocialguard/guard/inc/head.php

File size: 7.68Kb
<?php
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
$ps=&$_SESSION; 
//меняем переменную сессии для удобства
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';
include_once '../sys/inc/thead.php';

class system
{
function head($title='SiteGuard')
	{
	global $ps;
	title($title);aut();
	if (isset($ps['msg']))
		{
		echo "<div class='$ps[div]'>$ps[msg]</div>";
		unset($ps['msg'],$ps['div']);
		}
	}

function msg($msg,$loc=null,$div='msg',$stop=null)
	{
	global $ps;
	$ps['msg']=$msg;
	if ($div)
	$ps['div']=$div;
	if ($loc!==null)
	header('Location: '.$loc);
	if ($stop)
	exit();
	}
function linenav()
	{
	$numargs = func_num_args();
    $arg = func_get_args();
    for ($i = 0; $i < $numargs; $i++) 
		{
		$arg[$i]=str_replace('[b]',null,$arg[$i],$count);
		if ($count)
			{
			$sb='<b>';$eb='</b>';
			}
			else
			{
			$sb=null;$eb=null;
			} //выделение текущего элемента
		$arg[$i]=preg_replace('/(.+)\=(.+)/i',"<a href='$2'>$sb$1$eb</a> ".($numargs==($i+1)?null:' | '),$arg[$i]);
		echo $arg[$i];
		}
	echo '<br />';
	}
	
function listnav()
	{
	$numargs = func_num_args();
    $arg = func_get_args();
	echo '<div class="post">';
    for ($i = 0; $i < $numargs; $i++) 
		{
		$arg[$i]=str_replace('[b]',null,$arg[$i],$count);
		if ($count)
			{
			$sb='<b>';$eb='</b>';
			}
			else
			{
			$sb=null;$eb=null;
			} //выделение текущего элемента
			$arg[$i]=preg_replace('/(.+)\=(.+)\=(.+)/i',"<a href='$3'><img src='/guard/icons/$1.png' alt='' /> $sb$2$eb</a>".($numargs==($i+1)?null:'<br />'),$arg[$i]);
		echo $arg[$i];
		}
	echo '</div>';
	}
	
function confirm($get,$loc)
	{
global $_GET;

if (isset($_GET[$get]))
		{
	if (isset($_GET['ok']))
			{
			$this->msg('Действие успешно применено',$loc);
			return true;
			}
			else
			echo "<div class='msg'>Вы точно хотите это сделать?<br />
			<a href='?".implode('&amp;',$_SERVER['argv'])."&amp;ok'>Подтвердить</a> | <a href='?".implode('&amp;',$_SERVER['argv'])."'>Отменить</a></div>";
		}	
	}
	
function assess($val,$fatal,$bad,$normal,$well,$text=null)
	{
	if ($val<=$well)
	return $val.$text.' <font color="darkgreen">(отлично)</font>';
	elseif ($val<=$normal)
	return $val.$text.' <font color="darkorange">(нормально)</font>';
	elseif ($val<=$bad)
	return $val.$text.' <font color="darkred">(плохо)</font>';
	elseif ($val<=$fatal)
	return $val.$text.' <font color="red">(перегрузка)</font>';
	} //оценивает скорость работы сервера
	
function month($month)
	{
	if ($month==1)
	$month='январь';
	elseif ($month==2)
	$month='февраль';
	elseif ($month==3)
	$month='март';
	elseif ($month==4)
	$month='апрель';
	elseif ($month==5)
	$month='май';
	elseif ($month==6)
	$month='июнь';
	elseif ($month==7)
	$month='июль';
	elseif ($month==8)
	$month='август';
	elseif ($month==9)
	$month='сентябрь';
	elseif ($month==10)
	$month='октябрь';
	elseif ($month==11)
	$month='ноябрь';
	elseif ($month==12)
	$month='декабрь';
	return $month;
	}
	
	
function timer($time)
	{
	if ($time<60)
		{
		$type='секунд(а)';
		}
		elseif ($time<3540)
		{
		$time=$time/60;
		$type='минут(а)';
		}
		elseif ($time<86340)
		{
		$time=$time/3600;
		$type='час';
		}
		else
		{
		$time=$time/86400;
		$type='день';
		}
	return round($time).' '.$type;
	}
//возвращает форматнутое время

	function icon($icon,$link=null)
	{
	if ($link==null)
	return '<img src="/guard/icons/'.$icon.'.png" alt="" />';
	else
	return '<a href="'.$link.'"><img src="/guard/icons/'.$icon.'.png" alt="" /></a>';
	}
	
	function verify($arg,$type=0)
	{
	global $_GET,$_POST;
	if ($type=='0')
		{
		if (isset($_GET["$arg"]))
		return my_esc($_GET["$arg"]);
		}
		else
		{
		if (isset($_POST["$arg"]))
		return my_esc($_POST["$arg"]);
		}
	}
}

class user
{
function only_level($owner=null,$link=null)
	{
	global $user;	
	$exit=false; //начальное значение
	if ($owner==null)
		{
		if ($user['level']<4) //только админам
		$exit=true;
		}
		elseif ($owner==0) //для модераторов
		{
		if ($user['level']==0)
		$exit=true;
		}
		elseif ($user['id']!==$owner) //для владельца элемента
		$exit=true;
		
		if ($exit==true)
		{
		if (empty($link))
			{
		echo "<div class='err'>Этот раздел доступен только администрации</div>";	
		include 'inc/foot.php';
			}
			else
			{
			return false; //запрещаем доступ
			}
		}
		else
		return true; //разрешаем доступ
	} //защита от взлома
	
function info($user,$info=null)
	{
	global $set;
	$ank=get_user($user);
	$res="<a href='/info.php?id=$ank[id]'><img src='/style/themes/$set[set_them]/user/$ank[pol].png' alt='' /> $ank[nick]</a>".online($user);
	if (empty($info))
		{
		$spam=mysql_num_rows(mysql_query("SELECT * FROM `guard_suspic_msgs` WHERE `user` = '$user'"));
		$hack=mysql_num_rows(mysql_query("SELECT * FROM `guard_attempt_hacks` WHERE `user` = '$user'"));
		if ($spam>0)
		$res.="<br />
		Спам: $spam штук(а)
		";
		if ($hack>0)
		$res.="<br />
		Попытки взлома: $hack
		";
		}
		return $res;
	}
} 

class sql
{
function cycle($tbl,$pars=null,$order='`id` DESC',$list_page=null,$listoff=0,$distinct='*')
	{
	global $while,$set,$nullres,$list;
	
	if ($pars)
		$pars='WHERE '.$pars;
		else
		$pars=null;
	if ($order!==null)
		$order='ORDER BY '.$order;
	$k_post=mysql_result(mysql_query("SELECT ".($distinct!=='*'?"COUNT(DISTINCT(`$distinct`))":'COUNT(*)')." FROM `$tbl`$pars"),0);
	$k_page=k_page($k_post,$set['p_str']);
	$page=page($k_page);
	$start=$set['p_str']*$page-$set['p_str'];
	if ($k_post==0)	
	{
	$nullres=1;
	echo '<div class="post">Нет результатов</div>';
	}
	if ($distinct!=='*')
	$distinct="DISTINCT(`$distinct`)";
	$while=mysql_query("SELECT $distinct FROM `$tbl` $pars $order".($listoff==false?" LIMIT $start, $set[p_str]":null));
	if ($listoff==false)
	$list=($k_page>1?str('?'.$list_page.'&amp;',$k_page,$page):null);
	} //вывод данных из mysql
	
function part_cycle($k_post,$list_page=null)
	{
	global $set,$nullres;
	
	$k_page=k_page($k_post,$set['p_str']);
	$page=page($k_page);
	$start=$set['p_str']*$page-$set['p_str'];
	if ($k_post==0)	
		{
		$nullres=1;
		echo 'Нет результатов<br />';
		}
	$list=($k_page>1?str('?'.$list_page.'&amp;',$k_page,$page):null);
	}
	
function mass($tbl,$pars,$order=null,$distinct='*')
	{
	if ($distinct!=='*')
		$distinct="DISTINCT(`$distinct`)";	
	if (is_numeric($pars))
		$pars='`id` = '.intval($pars);
	if ($pars!==null)
		$pars='WHERE '.$pars;
	if ($order!==null)
		$order='ORDER BY '.$order;
	if (($mass=mysql_fetch_assoc(mysql_query("SELECT $distinct FROM `$tbl` $pars $order LIMIT 1"))))
		return $mass;
		else
		return false;
	} //возвращает ассоциативный массив из mysql
}

class design
{
function title($title)
	{
	return "<div class='menu_razd'>$title</div>";
	}
}
//список классов

$style=new design;
$sql=new sql;
$usr=new user;
$sys=new system;
//обьявления классов

$usr->only_level();
?>