<?php 
//error_reporting(E_ALL);
require_once('../config/config.php');
require_once(CLASS_DIR.'dbClass.php');
$cupage = 'news';
$send =0;
$fail = 0;
$obj = new DBClass();
$obj2 = new DBClass();
set_time_limit(7200);

if(isset($_GET['send'])){
		$info[] = $_GET['send']. ' Mail has been send sucessfully and '.$_GET['fail'].' mail failed to send';
}

if(isset($_POST['submit'])) {

$first = $_REQUEST['first'];
$last = $_REQUEST['last'];


	$message = "Dear Sir, <br><br>Have a nice day <br><br><b>Coal News on ".date("d-m-Y")."</b>  please click the link to read the full news.<br><br>";
	
	$sql = "SELECT * FROM news WHERE added_date = '".date("Y-m-d")."' order by added_date DESC";
	$rs = $obj->executeQry($sql,$link);
	$rownum = $obj->getrow();
	
	if($obj->getrow()>0) {
		
		while($row = $obj->fetchrow()) { 
			$id = $row['title'];

			$message	.= "<a href='http://www.coalbazaar.com/news.php?title=".$id."'>".$row['title']."</a><br><br>";
		}
		
 $message	.= "<br><br><b style='font-size:18px;'>हिंदी में समाचार पढ़ने के लिए</b><br><a href='http://www.coalbazaar.com/hindi/news.php' style='font-size:16px;'>यहाँ क्लिक करें</a><br><br>";
	  
	  $message  .=  "<br><br><strong style='font-size:18px;'>Thanks and Regards</strong><br><strong>Shrinetra Infotech</strong><br>62, Sch. No. 114, Part 1<br>Near ICICI Bank ATM,<br>Indore, (M.P) 452010<br><br><strong>Phone &nbsp;&nbsp;:</strong> 0731-2012323<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+91-9993299974-78 (sales)<br><strong>Fax &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </strong><br><strong>Email Id:</strong> shrinetrainfotech@gmail.com<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><strong>Website:</strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;www.coalbazaar.com<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;www.coalmandi.com<br>";

/*	  echo "SELECT * FROM `news_subscribr` LIMIT '$first','$last'";
	  exit;*/
	  		$sql2 = "SELECT * FROM `news_subscribr` order by id LIMIT $first,$last";
			$rs2 = $obj2->executeQry($sql2,$link);
			while($row2 = $obj2->fetchrow()) { 
						
				$to        	= 	$row2['email']; 
//				$to 			= "pradosh.soni@gmail.com";
				$subject	=	"Coal News";
				$headers  = 'MIME-Version: 1.0' . "\r\n";
				$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";				
				$headers .= "From: coalbazaar@coalbazaar.com \r\n";
				$sended=@mail($to, $subject, $message, $headers);		
				if($sended) 
					$send++;
				else 
					$fail++;		
			}
			$ino = $send. 'Mail has been send sucessfully and '.$fail.' mail failed to send';
		@header('Location: newsmail.php?send='.$send.'&fail='.$fail);
		exit;
	}
}

?>
<?php require_once(INCLUDES_DIR.ADMHEADER); ?>
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="29" align="center" class="submenu"><a href="add_news.php">Manage News</a></td>
	<td align="center" class="submenu">Send News</td>
	
  </tr>
</table>
<table width="1000" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="17"></td>
  </tr>
  <tr>
    <td><table width="910" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td class="pagehead"><table width="900" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="315" height="35">Manage NEWS</td>
            <td width="391">&nbsp;</td>
            <td width="63"><!--Sort By:--></td>
            <td width="131" height="35" style="float:right;margin-right:30px;"><?php $sql = "SELECT * FROM news_subscribr"; $res = mysql_query($sql); echo mysql_num_rows($res); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td valign="top" bgcolor="#FFFFFF"><table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height="25" class="error"><?php ShowError($error); ShowInfo($info);?></td>
          </tr>
          <!--<tr>
            <td class="bg_message"><table width="800" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="39"><img src="images/icon_mess.jpg" width="39" height="26" /></td>
                <td><?php ShowInfo($info);?></td>
              </tr>
            </table></td>
          </tr>-->
          <tr>
            <td height="9"></td>
          </tr>
          <tr>
            <td></td>
          </tr>
	
          <tr>
            <td class="bdr1"><table width="801" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="8" class="bg1" ><img src="../images/bg1.PNG" width="7" height="8" /></td>
              </tr>
              <tr>
                <td><table width="500" border="0" cellpadding="5" cellspacing="5" class="main" align="center">
				<form action="" method="post">
					<tr>
						<td colspan="2" align="center">Select limt of E-mail</td>
					</tr>
                  <tr>	
				  	<td align="right">First list</td>
					<td><input type="text" name="first"></td>
				  </tr>
				  <tr>	
				  	<td align="right">Last Limit</td>
					<td><input type="text" name="last"></td>
				  </tr>
				  <tr>	
				  	
					<td><input type="submit" name="submit" value="send email"></td>
				  </tr>
				  </form>
                  </table></td>
              </tr>
              <tr>
                <td height="2" class="bg2"><img src="../images/bg2.PNG" width="12" height="2" /></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          </table></td>
      </tr>
      <tr>
        <td valign="top" class="bg_innerfoot"><table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td align="right" class="footer_num"></td>
            </tr>
          </table></td>
      </tr>
      </table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>

<?php require_once(INCLUDES_DIR.ADMFOOTER); ?>