<?php
#----0000------------------------------------#
#----00--00----------------------------------#
#----00---000----000000-----000000-#
#----00---0000--00----00----00---00--#
#----00---0000--00-----------00---------#
#----00---0000--000000----00000--#
#----00---000---00-----------00---------#
#----00--00-----00---00-----00---------#
#----0000-------000000----00--------#
#-----------------------------------------------------------#
#     Загруз центр вер. 1.00 для Wap Motor       #
#                            Зделано  def                            #
#                            ICQ: 4627473                          #
#        Site of the project: http://wapruk.ru         #
#------------------------------------------------------------#
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";

include_once("inc/func.inc");
include_once("inc/conf.inc");

extract($HTTP_GET_VARS);
extract($HTTP_POST_VARS);

$text = file("../local/profil/$log.prof");
if ($text!=""){
$udata = explode(":||:",$text[0]);
$provlog=trim($udata[0]);
$provpar=trim($udata[1]);
$privat=trim($udata[10]);
$uz_mail=trim($udata[4]);}

/////////////////////////////удаление временных файлов/////////////////////////////////
$odir = opendir("temp");
while ($files = readdir($odir)){
if (($files!==".")&&($files!=="..")){
$ftime = filectime("temp/$files");
$ttime = time();
if ($ttime >= $ftime+$f_temp*60){
unlink("temp/$files");
}}}
closedir($odir);
///////////////////////////////////////////////////////////////////////////////////////////
if($f_mail=='on'){
/////////////////////////////
$did=str_replace("../","",$did);
$did=str_replace("./","",$did);
$did=str_replace("..","",$did);
$did=str_replace(".","",$did);
if (is_dir("files$did")==false or is_file("files$did/$fid")==false){
echo "<center><font color=\"red\">FACK!!! =))))</font></center><br /><br />";
echo "</div><div>[<a href='index.php?'>К разделам</a>]<br>";
echo "</div><div>[<a href='../index.php'>На главную</a>]";
include_once"../themes/$config_themes/foot.php";
exit;}
/////////////////////////////

echo '</div><div class="b">Отправка файла на E-mail</div><div>';

if ($_SESSION['log']!="" && md5($_SESSION['par'])!="" && md5($_SESSION['par'])==$provpar && $_SESSION['log']==$provlog ) {
if($udata[10]>0){
echo'<img src="../images/img/mail.gif" alt=""> <b><a href="../pages/privat.php?'.SID.'"><font color="red">Приватное сообщение! ('.$privat.')</font></a></b><br>';}

$Host=preg_replace('/:\d+/s','',getenv('HTTP_HOST'));
$user = $brow;
$file="files$did/$fid";

$maxfile=$m_file*1024;

while($file[0]=='/')
$sd=substr($file,1,strlen($file));
$dirname=dirname($file);
$basename=basename($file);
$filesize=@filesize($file);

if($filesize>1024)
$filesize=round($filesize/1024,2).' Кб';
else
$filesize=$filesize.' бт';
if(!strstr($dirname,"..") and file_exists($file) and filesize($file)<=$maxfile)
{
print "<br/>Папка: $did<br/>";
print "Файл: $fid<br/>";
print "Размер: $filesize<br/>";
	class Mail
{
	var $sendto = array();
	var $acc = array();
	var $abcc = array();
	var $aattach = array();
	var $xheaders = array();
	var $priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
	var $charset = "utf-8";
	var $ctencoding = "7bit";
	var $receipt = 0;

function Mail()
{
	$this->autoCheck( true );
	$this->boundary= "--" . md5( uniqid("myboundary") );
}

function autoCheck( $bool )
{
	if( $bool )
		$this->checkAddress = true;
	else
		$this->checkAddress = false;
}

function Subject( $subject )
{
	$this->xheaders['Subject'] = strtr( $subject, "\r\n" , "  " );
}

function From( $from )
{
	if( ! is_string($from) ) {
		echo "Class Mail: error, From is not a string";
		exit;
	}
	$this->xheaders['From'] = $from;
}

function ReplyTo( $address )
{
	if( ! is_string($address) ) 
		return false;	
	$this->xheaders["Reply-To"] = $address;		
}

function Receipt()
{
	$this->receipt = 1;
}

function To( $to )
{
	if( is_array( $to ) )
		$this->sendto= $to;
	else 
		$this->sendto[] = $to;

	if( $this->checkAddress == true )
		$this->CheckAdresses( $this->sendto );

}

function Cc( $cc )
{
	if( is_array($cc) )
		$this->acc= $cc;
	else 
		$this->acc[]= $cc;
		
	if( $this->checkAddress == true )
		$this->CheckAdresses( $this->acc );	
}

function Bcc( $bcc )
{
	if( is_array($bcc) ) {
		$this->abcc = $bcc;
	} else {
		$this->abcc[]= $bcc;
	}
	if( $this->checkAddress == true )
		$this->CheckAdresses( $this->abcc );
}

function Body( $body, $charset="" )
{
	$this->body = $body;
	
	if( $charset != "" ) {
		$this->charset = strtolower($charset);
		if( $this->charset != "us-ascii" )
			$this->ctencoding = "8bit";
	}
}

function Organization( $org )
{
	if( trim( $org != "" )  )
		$this->xheaders['Organization'] = $org;
}

function Priority( $priority )
{
	if( ! intval( $priority ) )
		return false;
		
	if( ! isset( $this->priorities[$priority-1]) )
		return false;

	$this->xheaders["X-Priority"] = $this->priorities[$priority-1];	
	return true;	
}

function Attach( $filename, $filetype = "", $disposition = "inline" )
{
	if( $filetype == "" )
		$filetype = "application/x-unknown-content-type";
		
	$this->aattach[] = $filename;
	$this->actype[] = $filetype;
	$this->adispo[] = $disposition;
}

function BuildMail()
{
	$this->headers = "";

	if( count($this->acc) > 0 )
		$this->xheaders['CC'] = implode( ", ", $this->acc );
	
	if( count($this->abcc) > 0 ) 
		$this->xheaders['BCC'] = implode( ", ", $this->abcc );
	
	if( $this->receipt ) {
		if( isset($this->xheaders["Reply-To"] ) )
			$this->xheaders["Disposition-Notification-To"] = $this->xheaders["Reply-To"];
		else 
			$this->xheaders["Disposition-Notification-To"] = $this->xheaders['From'];
	}
	
	if( $this->charset != "" ) {
		$this->xheaders["Mime-Version"] = "1.0";
		$this->xheaders["Content-Type"] = "text/plain; charset=$this->charset";
		$this->xheaders["Content-Transfer-Encoding"] = $this->ctencoding;
	}

	$this->xheaders["X-Mailer"] = "Php/libMailv1.3";
	if( count( $this->aattach ) > 0 ) {
		$this->_build_attachement();
	} else {
		$this->fullBody = $this->body;
	}

	reset($this->xheaders);
	while( list( $hdr,$value ) = each( $this->xheaders )  ) {
		if( $hdr != "Subject" )
			$this->headers .= "$hdr: $value\n";
	}
}

function Send()
{
	$this->BuildMail();
	$this->strTo = implode( ", ", $this->sendto );
	$res = @mail( $this->strTo, $this->xheaders['Subject'], $this->fullBody, $this->headers );
}

function Get()
{
	$this->BuildMail();
	$mail = "To: " . $this->strTo . "\n";
	$mail .= $this->headers . "\n";
	$mail .= $this->fullBody;
	return $mail;
}

function ValidEmail($address)
{
	if( ereg( ".*<(.+)>", $address, $regs ) ) {
		$address = $regs[1];
	}
 	if(ereg( "^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int|ru|ua|eu)\$",$address) ) 
 		return true;
 	else
 		return false;
}

function CheckAdresses( $aad )
{
	for($i=0;$i< count( $aad); $i++ ) {
		if( ! $this->ValidEmail( $aad[$i]) ) {
			echo "Class Mail, method Mail : invalid address $aad[$i]";	
			exit;
		}
	}
}

function _build_attachement()
{
	$this->xheaders["Content-Type"] = "multipart/mixed;\n boundary=\"$this->boundary\"";

	$this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\n";
	$this->fullBody .= "Content-Type: text/plain; charset=$this->charset\nContent-Transfer-Encoding: $this->ctencoding\n\n" . $this->body ."\n";
	
	$sep= chr(13) . chr(10);
	
	$ata= array();
	$k=0;
	for( $i=0; $i < count( $this->aattach); $i++ ) {
		
		$filename = $this->aattach[$i];
		$basename = basename($filename);
		$ctype = $this->actype[$i];	// content-type
		$disposition = $this->adispo[$i];
		
		if( ! file_exists( $filename) ) {
			echo "Class Mail, method attach : file $filename can't be found"; exit;
		}
		$subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$basename\"\nContent-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n  filename=\"$basename\"\n";
		$ata[$k++] = $subhdr;

		$linesz= filesize( $filename)+1;
		$fp= fopen( $filename, 'r' );
		$ata[$k++] = chunk_split(base64_encode(fread( $fp, $linesz)));
		fclose($fp);
	}
	$this->fullBody .= implode($sep, $ata);
}
} //class mail

if(!$act)
	{
	print "
	<br/><form action=\"mail.php?act=nar&amp;did=$did&fid=$fid&id=$id\" method=\"post\">
	E-mail: ";
	if ($mail_uz=="off"){
	echo $uz_mail.'<br>'; 
	$mail = $uz_mail;
	}else{
	print "<br/><input name=\"mail\" maxlength=\"25\" value=\"\" size=40 /><br/>";}
	
	print "Комментарий:<br/>
	<textarea name=\"komm\" maxlength=\"450\" rows=5 cols=20></textarea><br/>
	<input type=\"submit\" name=\"a\" value=\"Отправить\"/>
	</form>";

	}
	else
	{
$odir = opendir("temp");
while ($filess = readdir($odir)){
if ($filess==$provlog.'.txt'){
echo "<br><font color='red'>Ошибка!!! Вы не можете отправлять файл чаше чем раз в ".$f_temp." минут.</font><br>";

echo "<br>[<a href='index.php?did=$did&fid=$fid&act=desc'>К файлу</a>]<br>";
echo "<div>[<a href='index.php?did=$did'>К категории</a>]<br>";
echo "</div><div>[<a href='index.php?'>К разделам</a>]<br>";
echo "</div><div>[<a href='../index.php'>На главную</a>]";

include_once"../themes/$config_themes/foot.php";
exit;}
}
	if ($mail_uz=="off"){$mail = $uz_mail;}	
	$err='';
	if(0==preg_match("/^[0-9a-z\-._]+@[0-9a-z_\-.]+\.[a-z]{2,3}$/si", $mail))
	$err.='<br/><font color="red">Ошибка!Введите адрес e-mail в виде login@server.com</font><br/>';
	if($err)
	print $err;
	else
		{
		$format=format($fid);
		if($format==".txt")$o="text/plain";
if($format=="gif")$o="image/gif";
if($format=="jpg" || $format=="jpeg")$o="image/jpeg";
if($format=="png")$o="image/png";
if($format=="zip")$o="archive/zip";
if($format=="rar")$o="archive/rar";
if($format=="mid")$o="media/midi";
if($format=="mmf")$o="media/mmf";
if($format=="jar")$o="application/java-archive";
if($format=="jad")$o="archive/jar";
if($format=="thm")$o="archive/vnd.eri";
if($format=="nth")$o="archive/vnh.nth";
if($format=="3gp")$o="video/3gpp";
if($format=="avi")$o="video/avi";
if($format=="mp3")$o="media/mp3";
if($format=="sdt")$o="application/vnd.siemens-mp.theme";
if($format=="scs")$o="application/vnd.siemens-mp.skin";
if($format=="sis")$o="application/vnd.symbian.install";
$subj="Вам файл от $provlog с сайта $Host";
$mess='Вы получили это письмо потому что кто-то, возможно Вы, указал этот E-mail в качестве получателя файла отосланого с сайта http://'.$Host.' . Если это было сделано по ошибке, то пожалуйста удалите это сообщение. С уважением Администрация сайта: "'.$Host.'"

Комментарий к файлу:  '.$komm;

$m=new Mail;
$m->From("files@$Host");
$m->To("$mail");
$m->Subject("$subj");
$m->Body($mess);
$m->Priority(3);
$m->Attach(@realpath("$file"),"$o");
$m->Send();
print '<br/><font color="red">Ваше сообщение успешно отправлено</font><br/>';

		$fp = fopen('temp/'.$provlog.'.txt','w');
		fputs($fp,$mail);
		fclose($fp);
		
///////////////////////запись счетчика отправок/////////////////////////
if (is_file("files$did/$fid")){
$dik=str_replace("/", "", $did);
if (is_file("baze/$dik.baz")){
$fn=file("baze/$dik.baz");
$fp=fopen("baze/$dik.baz","a+");
flock ($fp,LOCK_EX);
ftruncate ($fp,0);
	foreach ($fn as $n=>$f){
		$data = explode("|",$fn[$n]);
		if ($data[0]==$id and $data[11]=="$did/$fid"){$kol=$data[2]+1;
		$zap="$data[0]|$data[1]|$kol|$data[3]|$data[4]|$data[5]|$data[6]|$data[7]|$data[8]|$data[9]|$data[10]|$data[11]|\r\n";
		fputs($fp,"$zap");}
		else{fputs($fp,$fn[$n]);}
		fflush ($fp);
	}
flock ($fp,LOCK_UN);
fclose($fp);
@chmod("$fp", 0666);	
}}		
/////////////////////////////////////////////////////////////////////		
		
		}
	}
}
else
{
print '<br/><font color="red"><b><blink>Ошибка!</blink></b>  Неверно указан файл, или его размер превышает лимит!</font><br/>';
}
$t=explode('/',dirname($file));
$t[0]='';
//unset($t[0]);
}else echo "<br/><font color='red'>Этот сервис доступен только зарегестрированным пользователям сайта!!!</font>";
}
echo "<br>[<a href='index.php?did=$did&fid=$fid&act=desc'>К файлу</a>]<br>";
echo "<div>[<a href='index.php?did=$did'>К категории</a>]<br>";
echo "</div><div>[<a href='index.php?'>К разделам</a>]<br>";
echo "</div><div>[<a href='../index.php'>На главную</a>]";

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

?>