<?php
#-----------------------------------------------------#
#          ********* WAP-MOTORS *********             #
#             Made by   :  VANTUZ                     #
#               E-mail  :  visavi.net@mail.ru         #
#                 Site  :  http://pizdec.ru           #
#             WAP-Site  :  http://visavi.net          #
#                  ICQ  :  36-44-66                   #
#  Вы не имеете право вносить изменения в код скрипта #
#-----------------------------------------------------#	
require_once"../template/start.php";
require_once"../template/regglobals.php";
require_once"../template/config.php";
require_once"../template/functions.php";
require_once"../template/antidos.php";
require_once"../template/cookies.php";
require_once"../template/gzip.php";
require_once"../template/header.php";
require_once"../template/referer.php";
include_once"../themes/$config_themes/index.php";
include_once"../template/isset.php";

if(isset($_POST['uz'])){$uz=check(trim($_POST['uz']));} else {$uz=check(trim($_GET['uz']));}

echo '<img src="../images/img/partners.gif" alt=""> <b>Рейтинг долгожителей</b><br><br>';

//------------------------------ НОВАЯ ФУНКЦИЯ КЕШИРОВАНИЯ ------------------------------//
$filtime=filemtime(BASEDIR."local/datatmp/lifelist.dat");
$userfile=file("../local/datatmp/lifelist.dat");
$user_count=count($userfile);

$filtime=$filtime+(3600*$config_lifelistcache);

if($sitetime>$filtime || $user_count<50){
	
foreach (glob(BASEDIR."local/datalife/*.dat") as $filename) {
$a[] = basename($filename);
}

$total = count($a); 

for ($i = 0; $i < $total; $i++){
$tex = file(BASEDIR."local/datalife/$a[$i]");
$data = explode("|",$tex[0]);

if($data[0]!=""){
	
$dat_life[]=(int)$data[1];
$dat_login[]=check($data[2]);

}}

arsort($dat_life);

foreach($dat_life as $k=>$v){ $gg++;
$dat_top[]='|'.$gg.'|'.$dat_login[$k].'|'.$v.'|';	
}

$dat_top=implode("\r\n",$dat_top);

if($dat_top!=""){
$fp = fopen(BASEDIR."local/datatmp/lifelist.dat","a+");
flock ($fp,LOCK_EX);
ftruncate ($fp,0);
fputs($fp,"$dat_top\r\n");
fflush ($fp);
flock ($fp,LOCK_UN);
fclose($fp);
chmod ($fp, 0666); 
chmod (BASEDIR."local/datatmp/lifelist.dat", 0666); 
}
}



//------------------------------ ВЫВОД ИЗ КЕША ------------------------------//	
$file = file(BASEDIR."local/datatmp/lifelist.dat");
$total = count($file);

$start = (int)$_GET['start'];
if($start < 0 || $start > $total){$start = 0;}
if ($total < $start + $config_lifelist){ $end = $total; }
else {$end = $start + $config_lifelist; }
for ($i = $start; $i < $end; $i++){
	
$data = explode("|",$file[$i]);

echo '<div class=b>'.$data[1].'. <img src="../images/img/chel.gif" alt=""> ';

if($uz==$data[2]){
echo '<b><big><a href="../pages/anketa.php?uz='.$data[2].'&amp;'.SID.'"><font color="#FF0000">'.nickname($data[2]).'</font></a></big></b> ';
}else{	
echo '<b><a href="../pages/anketa.php?uz='.$data[2].'&amp;'.SID.'">'.nickname($data[2]).'</a></b> ';
}

echo user_online($data[2]).'</div>';
echo 'Провел на сайте: '.makestime($data[3]).'<br>';

$text = file(BASEDIR."local/profil/$data[2].prof"); 
if ($text!=""){
$uzdata = explode(":||:",$text[0]);
if ($uzdata[6]!="") {echo'Дата регистрации: '.date("j.m.Y",check($uzdata[6])).'<br>';} 
}


}

echo'<hr>'; 
if ($start != 0) {echo '<a href="lifelist.php?start='.($start - $config_lifelist).'&amp;'.SID.'">&lt;-Назад </a>';}else{echo'&lt;-Назад';}
echo' | '; 
if ($total > $start + $config_lifelist) {echo ' <a href="lifelist.php?start='.($start + $config_lifelist).'&amp;'.SID.'">Далее-&gt;</a>';}else{echo'Далее-&gt;';} 

if($total>0){

$ba=ceil($total/$config_lifelist);
$ba2=$ba*$config_lifelist-$config_lifelist;

echo '<br><hr>Страницы:';
$asd=$start-($config_lifelist*4);
$asd2=$start+($config_lifelist*5);

if($asd<$total && $asd>0){echo ' <a href="lifelist.php?start=0&amp;'.SID.'">1</a> ... ';}

for($i=$asd; $i<$asd2;){
	
if($i<$total && $i>=0){
$ii=floor(1+$i/$config_lifelist);

if ($start==$i) {
echo ' <b>('.$ii.')</b> ';
} else {
echo ' <a href="lifelist.php?start='.$i.'&amp;'.SID.'">'.$ii.'</a>';
}}


$i=$i+$config_lifelist;
}
if($asd2<$total){echo ' ... <a href="lifelist.php?start='.$ba2.'&amp;'.SID.'">'.$ba.'</a>';}
}


//-----------------------------------------------------------------//
if($uz==""){
echo '<hr><b>Поиск пользователя:</b><br>';
if($config_themes!="wml"){	
echo '<form action="lifelist.php?start='.$start.'&amp;'.SID.'" method="post">';
echo'<input name="uz" value="'.$log.'" /><br>';
echo '<input type="submit" value="Искать" /></form><hr>';

}else{

echo'<input name="uz" value="'.$log.'"/><br>';
echo'<anchor>Искать';
echo'<go href="lifelist.php?start='.$start.'&amp;'.SID.'" method="post">';
echo'<postfield name="uz" value="$(uz)"/>';
echo'</go></anchor><br>--------------------';
}
}else{
	

$file = file(BASEDIR."local/datatmp/lifelist.dat");
$total = count($file);	
for ($i = 0; $i < $total; $i++){ 
	
$data = explode("|",$file[$i]);	
if (trim($uz)==$data[2]){

$stranica = floor($i / $config_lifelist) * $config_lifelist;

if($start!=$stranica){ 
header ("Location: lifelist.php?start=$stranica&uz=$uz&".SID); 
}

$pos = $i + 1; 
echo '<hr><br><font color="#00FF00">Позиция в рейтинге:</font> <b>'.$pos.'</b><br>';	

break;
}}

if($pos==""){ echo '<hr><br><b><font color="#FF0000">Пользователь с таким логином не найден!</font></b><br>';}

echo '<br><a href="lifelist.php?start='.$start.'&amp;'.SID.'">Искать еще</a><br>';
}



echo '<br>Всего юзеров: <b>'.(int)$total.'</b><br><br>';
echo '<img src="../images/img/homepage.gif" alt=""> <a href="../index.php?'.SID.'">На главную</a>';
include_once "../themes/$config_themes/foot.php";
?>

