<?php
include "chkuser.php"; 
include "includefilemng.php";
set_time_limit(0);
?>

<html>
<head>
<title>control panel </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="ssi.css" rel="stylesheet" type="text/css">
<script language="javascript" src="includenp/functions.js"></script>


<style type="text/css">
<!--
.style2 {color: #000000}
-->
</style>
</head>
<body>
<table width="98%" border="0" cellspacing="0" cellpadding="2" align="center">
  <tr>
    <td width="1%"   bgcolor="#C9C9C9"></td>
	<td width="98%"><?php include_once "top.php";?></td>
	<td width="1%"   bgcolor="#C9C9C9"></td>
  </tr>
  <tr>
   <td width="1%"   bgcolor="#C9C9C9"></td>
    <td width="98%"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="centertable">
      <tr>
        <td><table width="80%"  border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height="50" class="bigblackTxt">&nbsp;</td>
          </tr>
          <tr>
            <td class="errFont"><?php
		if(isset($rmsg))
		{echo display_error_msg($rmsg);
		   	}
		?></td>
          </tr>
          <tr>
            <td>
            
              <table width="100%"  border="0" align="center" cellpadding="0" cellspacing="4">
                <form action="addimporteddata.php" method="POST" enctype="multipart/form-data" name="SaveForm" ID="SaveForm" >
                
				
                  <tr>
                    <td colspan="2" class="bigblackTxt"></td>
                  </tr>
				  <tr>
                    <td height="24" colspan="2" class="errFont">&nbsp;</td>
                  </tr>
				                
                 
                   
                                        
				  <tr>
                    <td colspan="2" class="bluebold"><?php
$file = $_FILES['file']['tmp_name'];
$filetype = $_FILES['file']['type'];

if ($filetype <> "text/plain")
{
	$rmsg = "WARNING: Please upload only text files";
}
else
{
	$filem = "uploads/" . $_FILES['file']['name'];
	copy($file,$filem);
	unlink($file); 
	
	include "conn.php"; 
	$curchar = "";
	$curchars = "";
	$totmails = 0;
	$totmailentered = 0;
	$filetoread = $filem;
	if(!$file = fopen($filetoread,'r'))
	{
		$rmsg ="Unable to read from file";
	}
	else
	{
	while(!feof($file))
	{
		//read a char
		$curchar = fgetc($file);
		//store chars read
		if ($curchar <> "\n")
		   {
  			$curchars = $curchars . $curchar;
		   }
		
		
				if ($curchar == "\n")
				{
					//counter to count number of total mails
					$totmails = $totmails + 1;
					$proceed = 0;		
					/*	 			
					//proceed to enter data in DB
					if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $curchars))  
					{
					$proceed = 0;		
					echo $proceed;
					}
					else
					{
					$proceed = 1;
					echo $proceed;
					}
					*/
					
		
				//if $proceed is < 1 then enter data
				
				if($proceed < 1)
				{
				$qid =("INSERT INTO subscribedusers(email)VALUES('curchars')");
				$updateresult = mysql_query($qid,$eclipse);
				echo mysql_error();
				$totmailentered = $totmailentered + 1;
				}
			
			$curchar = "";
			$curchars = "";
		}
	}
	$rmsg ="Import from file complete " . "<br>" . $totmailentered ." email id imported from " . $totmails . " emails";
	fclose($file);
	//delete the uploaded file
	unlink($filetoread); 
	}
}
echo $rmsg;
?></td>
                    </tr>
				
				  <tr>
                    <td width="26%" class="bluebold">&nbsp;</td>
                    <td width="74%">&nbsp;</td>
				  </tr>
				  <tr>
                    <td align="right">&nbsp;</td>
                    <td>                      <span class="normalTxt"><span class="bigblackTxt">
                    
                      </span></span></td>
                  </tr>
                  <tr>
                    <td colspan="2">&nbsp;</td>
                  </tr>
                </form>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
    <td width="1%"   bgcolor="#C9C9C9"></td>
  </tr>
  <tr>
    <td   bgcolor="#C9C9C9" width="1%"></td>
	<td><?php include_once "footer.php";?></td>
	<td width="1%"   bgcolor="#C9C9C9"></td>
  </tr>
</table>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="ssi.css" rel="stylesheet" type="text/css">
</head>

<body>
<p align="center" class="normalBoldTxt">
<?php
$file = $_FILES['file']['tmp_name'];
$filetype = $_FILES['file']['type'];

if ($filetype <> "text/plain")
{
	$rmsg = "WARNING: Please upload only text files";
}
else
{
	$filem = "uploads/" . $_FILES['file']['name'];
	copy($file,$filem);
	unlink($file); 
	
	include "conn.php"; 
	$curchar = "";
	$curchars = "";
	$totmails = 0;
	$totmailentered = 0;
	$filetoread = $filem;
	if(!$file = fopen($filetoread,'r'))
	{
		$rmsg ="Unable to read from file";
	}
	else
	{
	while(!feof($file))
	{
		//read a char
		$curchar = fgetc($file);
		//store chars read
		if ($curchar <> "\n")
		   {
  			$curchars = $curchars . $curchar;
		   }
		
		
				if ($curchar == "\n")
				{
					//counter to count number of total mails
					$totmails = $totmails + 1;
					$proceed = 0;		
					/*	 			
					//proceed to enter data in DB
					if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $curchars))  
					{
					$proceed = 0;		
					echo $proceed;
					}
					else
					{
					$proceed = 1;
					echo $proceed;
					}
					*/
					
		
				//if $proceed is < 1 then enter data
				
				if($proceed < 1)
				{
				$qid =("INSERT INTO subscribedusers(email)VALUES('curchars')");
				$updateresult = mysql_query($qid,$eclipse);
				echo mysql_error();
				$totmailentered = $totmailentered + 1;
				}
			
			$curchar = "";
			$curchars = "";
		}
	}
	$rmsg ="Import from file complete " . "<br>" . $totmailentered ." email id imported from " . $totmails . " emails";
	fclose($file);
	//delete the uploaded file
	unlink($filetoread); 
	}
}
echo $rmsg;
?>
</p>

</body>
</html>
