<?php class importacao_rapida
{
function ListarClientes()
{
$Select = mysql_query("SELECT * FROM email_users;");
while($result = mysql_fetch_object($Select)){
if($result->userid == $_REQUEST['Userid'])	{
echo "<option selected=\"selected\" value=\"index.php?Pagina=escolher_cliente&Userid=".$result->userid."\">".$result->username."</option>";
}
else
echo "<option value=\"index.php?Pagina=escolher_cliente&Userid=".$result->userid."\">".$result->username."</option>";
}
}
function ProprietarioLista()
{
$Select = mysql_query("SELECT * FROM email_users WHERE userid = ".$_REQUEST['Userid']."");
if($result = mysql_fetch_object($Select))
echo $result->emailaddress;
}
function BounceAddress()
{
$Select = mysql_query("SELECT * FROM email_config_settings 
		  WHERE area = 'BOUNCE_ADDRESS'");
if($resultado = mysql_fetch_object($Select)) 
echo $resultado->areavalue;
}
function CriarLista()
{
mysql_query("INSERT INTO email_lists  
		( 
		name, ownername, owneremail, bounceemail, replytoemail, bounceserver, bounceusername, bouncepassword, extramailsettings, companyname, companyaddress, companyphone, format, notifyowner, imapaccount, createdate,  subscribecount, unsubscribecount, bouncecount, processbounce, agreedelete, agreedeleteall, visiblefields, ownerid
		 )  
		VALUES (
		'".$_POST['nome_lista']."', 
		'proprietario', 
		'".$_POST['email_proprietario_lista']."', 
		'".$_POST['email_devolvidos']."', 
		'".$_POST['email_resposta']."',
		'localhost',
		'return',
		'cmV0dXJuKnA1MzQ4KnZpcA==',
		'/novalidate-cert',
		'',
		'',
		'',
		 'b',
		 1,
		 0,
		 1332958473,
		 0,
		 0, 
		 0, 
		 1, 
		 1, 
		 0, 
		 'emailaddress',
		  ".$_POST['Userid']." )") or die ('ERRO:'.mysql_error());
$Id = mysql_query("SELECT max(listid) as listid FROM email_lists");
if($pega = mysql_fetch_object($Id))
$NovoID = $pega->listid;
header('Location:index.php?Pagina=escolher_lista_emails&listid='.$NovoID.'');
}
function ImportarListaEmail()
{
ini_set('max_execution_time','3000');
$contador_erro = 0;
$dhinicial = date('H:i:s');
$NomeArquivo = $_FILES['FormEmail']['name'];
move_uploaded_file($_FILES['FormEmail']['tmp_name'],$NomeArquivo);
$listid = $_POST['listid'];
$fh = fopen("txt_formatado/".$NomeArquivo."",'a') or die("Não foi possível abrir o arquivo...");
$arquivo = file($NomeArquivo);
for($i = 0;$i <count($arquivo);$i++)  
{
$email = $arquivo[$i];
$email = str_replace(" ' ","",$email);
$email = str_replace(" '' ","",$email);
$email = str_replace(" ,' ",".",$email);
$email = str_replace(" \n ","",$email);
$Arroba = stripos($email,'@');
if($Arroba === false)
{
$contador_erro++;
}
else{
$code = md5(uniqid(rand(),true));
$SegundaParte = explode("@",$email);
$final = "@".$SegundaParte[1];
if($final == ''){
$final = '@variavelvazia.com.br';
}
$inclui = "{$listid};{$email};{$final};h;1;{$code} \n";
$inclui = str_replace("\r","",$inclui);
$inclui = str_replace("\n","",$inclui);
$inclui = str_replace("\t","",$inclui);
$inclui = preg_replace("/(<br.*?>)/i","",$inclui);
$inclui = $inclui."\n";
fwrite($fh,$inclui);
}
}
fclose($fh);
$query = mysql_query("LOAD DATA LOCAL INFILE 'txt_formatado/".$NomeArquivo."'   INTO TABLE email_list_subscribers
		   FIELDS TERMINATED BY ';'
		   LINES TERMINATED BY '\n'
		   (listid, emailaddress, domainname, format, confirmed, confirmcode) ")  or die ('ERRO'.mysql_error());
$QueryTotal = mysql_query("SELECT count(listid) as listid FROM  email_list_subscribers WHERE listid = ".$_REQUEST['listid']."");
if($total = mysql_fetch_object($QueryTotal))
$Total = $total->listid;
mysql_query("UPDATE email_lists SET subscribecount = ".$Total." WHERE listid = ".$_REQUEST['listid']."  ");
$arquivo = $NomeArquivo;
$ArquivoFormatado = "txt_formatado/".$NomeArquivo;
if(unlink($arquivo) &&(unlink($ArquivoFormatado))){
}
else{
}
$dhfinal = date('H:i:s');
echo "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>";
echo "<br>";
echo "Total Emails Imported: ".$Total;
echo "<br>";
echo "Total Emails Not Imported: ".$contador_erro;
echo "<br>";
echo "Date and Start Time: ".$dhinicial;
echo "<br>";
echo "Date and Final Time: ".$dhfinal;
echo "<br>";
$ex_hrini = explode(':',$dhinicial);
$ex_hrfim = explode(':',$dhfinal);
$H = $ex_hrini[0] -$ex_hrfim[0];
$i = $ex_hrini[1] -$ex_hrfim[1];
$s = $ex_hrini[2] -$ex_hrfim[2];
$data_inicial = mktime($ex_hrini[0],$ex_hrini[1],$ex_hrini[2]);
$data_final = mktime($ex_hrfim[0],$ex_hrfim[1],$ex_hrfim[2]);
$segundos = $data_final -$data_inicial;
echo "Elapsed Time: ".gmdate("H:i:s",$segundos);
echo "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>";
echo "<p><font size=6><b>To import into the same list, just click back on your browser</b></font></p>";
}
}
; ?>
