<?php
#-----------------------------------------------------#
#          ********* WAP-MOTORS *********             #
#             Made by   :  VANTUZ                     #
#               E-mail  :  vsem@pizdec.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/maincore.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";

require_once"../template/isset.php";

$text = file("../local/profil/$log.prof"); 

if ($text!=""){
$udata = explode(":||:",$text[0]);
$provlog=trim($udata[0]);
$provpar=trim($udata[1]);
$dostup=trim($udata[7]);
$privat=trim($udata[10]);}

$locked=check($_POST['locked']);

if (!$_SESSION['log']=="" && !md5($_SESSION['par'])=="" && md5($_SESSION['par'])==$provpar && $_SESSION['log']==$provlog ) {
if ($dostup==101){
$date=date("d.m"); 
$time=date("H:i"); 
echo'<img src="../images/img/menu.gif" alt=""> <b>Перенос тем</b><br>';





################перемещение тем#############
if ($event=="remtema") { 

if ($dostup!=="101")
{echo '<b>Пошел на хуй</b><br>'; 
include_once"../themes/$config_themes/foot.php"; 
exit;}


$new_fid=check($_POST['new_fid']);
$newfor=check($_POST['newfor']);
$rmv=check($_POST['rmv']);
if ($rmv == "") { 
echo '<b>Вернитесь назад и введите ТЕМУ!</b><br>'; 
include_once"../themes/$config_themes/foot.php"; 
exit;}

$time_p=time();
$file=file("../local/tmpforum/$rmv.dat");
$file=array_reverse($file);
$tex= explode("|", $file[0]);
$realfid=$tex[8];
$realfor=$tex[11];
$total=count($file);
$new_mainf=$total;
for ($i=0; $i<$total; $i++)
{
$post= explode("|", $file[$i]);
$post[10]=preg_replace ("|[\r\n]+|si","",$post[10]);

$file[$i]=$post[0] .'|'. $post[1] .'|'. $post[2] .'|'. $post[3] .'|'. $post[4] .'|'. $post[5] .'|'. $post[6] .'|'. $time_p .'|'. $new_fid .'|'. $post[9] .'|'. $post[10].'|'.$newfor;

}
$new_team=$file[0];
$fp=fopen("../local/dataforum/$time_p.dat","w");
flock ($fp,LOCK_EX);
$file=array_reverse($file);
for ($i=0; $i<$total; $i++)
{
fputs($fp,$file[$i]."\r\n");

}
flock ($fp,LOCK_UN);
fclose($fp);
chmod($fp, 0777); 

$file=file("../local/tmpforum/$rmv.dat");
$file=array_reverse($file);
$post=explode('|',$file[0]);
$zag=$post[3];


$fp=fopen("../local/dataforum/topic$new_fid-$newfor.dat","a+");
flock ($fp,LOCK_EX);                                                              
fputs($fp,$new_team."\r\n");
flock ($fp,LOCK_UN);
fclose($fp);

$mainlines = file("../local/dataforum/mainforum$newfor.dat"); $i=count($mainlines);
do {$i--; $dt=explode("|", $mainlines[$i]);
if ($dt[0]==$new_fid) {$reallfid=$i;}
} while($i>0);



$lines=file("../local/dataforum/mainforum$newfor.dat");
$dt=explode("|", $lines[$reallfid]);
$dt[4]++;
$dt[5]+=$new_mainf;

$txtdat="$dt[0]|$dt[1]|$new_fid|$time_p|$dt[4]|$dt[5]|$log|$date|$time|$time_p|$zag|";
$fp=fopen("../local/dataforum/mainforum$newfor.dat","a+");
flock ($fp,LOCK_EX);
ftruncate ($fp,0);
for ($i=0;$i<=(sizeof($lines)-1);$i++) {if ($i==$reallfid) {fputs($fp,"$txtdat\r\n");} else {fputs($fp,$lines[$i]);}}
fflush ($fp);
flock ($fp,LOCK_UN);
fclose($fp);
@chmod("$fp", 0777);
@chmod("../local/dataforum/mainforum$newfor.dat", 0777);
unlink("../local/tmpforum/$rmv.dat");


header ("Location: remove.php?".SID); 
}

$post=$config_forumpost;
$dir = opendir ("../local/tmpforum"); 
while ($file = readdir ($dir)) 
{if (ereg (".dat$", $file) && !ereg("^top", $file)&& !ereg("^main", $file)) 
{$a[]=$file;}} 
closedir ($dir); 		
closedir ($dir); 
$total = count($a); 

$a=str_replace(".dat","",$a);		
for ($i = 0; $i < $total; $i++){
$tex = file("../local/tmpforum/$a[$i].dat");
$lines=array_reverse($tex);
$data=explode("|", $lines[0]);
$last=trim($data[9]);
if ($last=="CLOSED") {$data1=explode("|", $lines[1]); $last=trim($data1[9]);}

$dat_total[]=$last;
$dat_count[]=$a[$i];
}

arsort($dat_total);

foreach($dat_total as $k=>$v)
{
$tex = file("../local/tmpforum/$dat_count[$k].dat");
$fs=count($tex)-1;
$data = explode("|",$tex[$fs]);	
	
if(!$dat_count[$k]==""){$vk++;
$file = @file("../local/tmpforum/$dat_count[$k].dat");
$pagg=count($file);
$str=$pagg/$config_forumpost;
$str=(int)$str;
$page=$str*$config_forumpost;
if ($pagg==$page) $page=$page-$config_forumpost;


$dat_ball2[]='<div class="b"><img src="../images/img/files.gif" alt=""> <b>'.$vk.'. '.$data[3].'</b> <a href="remove.php?fid='.$data[8].'&amp;rmv='.$data[7].'&amp;'.SID.'">[rem]</a></div>Всего сообщений: '.$pagg.'<br>Посл. сообщение: '.$data[0].' ('.$data[5].'/'.$data[6].')<br>

';}	}

if (empty($start))
{$start = 0;}
$start = intval($start);
if ($start < 0){$start = 0;}
if ($total < $start + $post){ $end = $total; }
else {$end = $start + $post; }

for ($i = $start; $i < $end; $i++){

echo $dat_ball2[$i];
}

print "<center><hr>";
if ($start != 0){print "<A href=remove.php?action=list&amp;start=".($start - $post).">&lt;-Назад </A>";} else{echo'&lt;-Назад ';}
echo'|'; 
if ($total > $start + $post){print "<A href=remove.php?action=list&amp;start=".($start + $post)."> Далее-&gt;</A> \n";} else{echo' Далее-&gt;';}
if ($total < $start + $post){ $end = $total; }
else {$end = $start + $post; }

print "</center><hr>";





















//---------------------------- Перемещение темы --------------------------------//
if (isset($_GET['rmv'])) { 
if ($_GET['rmv'] !="")  { 
$rmv=$_GET['rmv']; 

$newfor=check($newfor);
echo '<hr>Перемещение темы в раздел<br>';
if ($newfor=="")
{echo 'Выберите новый подраздел форума:<br>';
$file=file("../local/forum.dat");
$craz=count($file);
echo '<form action="remove.php?fid='.$fid.'&amp;rmv='.$rmv.'&amp;'.SID.'" method="post">';
echo '<select name=newfor size=1>';
for($i=0; $i<$craz; $i++)
{$xxx = explode("|", $file[$i]);
$newfor=trim($xxx[0]);
$imya=trim($xxx[1]);
if(file_exists("../local/dataforum/mainforum$newfor.dat")){
echo '<option value='.$newfor.'>'.$imya.'</option>';}}
echo '</select>';
echo '<input type="submit" value="Изменить" /></form>';
}
else {$file=file("../local/dataforum/mainforum$newfor.dat");
$craz=count($file);
echo '<form action="remove.php?event=remtema&amp;'.SID.'" method="post">';
echo '<select name=new_fid size=1>';
for($i=0; $i<$craz; $i++)
{$xxx = explode("|", $file[$i]);
$new_fid=trim($xxx[0]);
$imya=trim($xxx[1]);
echo '<option value='.$new_fid.'>'.$imya.'</option>';}
echo '</select>';
echo '<input type="hidden" name="rmv" value="'.$rmv.'" />';
echo '<input type="hidden" name="newfor" value="'.$newfor.'" />';
echo '<input type="submit" value="Изменить" /></form>';
}
}}
	
//--------------------- Конец ----------------------//

echo'<br><br><img src="../images/img/edit.gif" alt=""> <a href="../forum/index.php?'.SID.'">На форум</a><br>';
echo'<img src="../images/img/panel.gif" alt=""> <a href="index.php?'.SID.'">В админку</a><br>';
echo'<img src="../images/img/homepage.gif" alt=""> <a href="../index.php?'.SID.'">На главную</a><br>';

} else {header ("Location: ../index.php?error&".SID);}
} else {header ("Location: ../index.php?error&".SID);}

include_once"../themes/$config_themes/foot.php";
?>

