<?php
ob_start();
date_default_timezone_set('Asia/Calcutta');
if(isset($_SESSION['msg']) ){?>
<div class="alert alert-info">                
<h4>Info!</h4>
<?php echo $_SESSION['msg']; unset($_SESSION['msg']); ?>
</div> <?php } 	
?>
<?php include_once("fckeditor/fckeditor.php") ; ?>
<div class="row-fluid" >
    <div class="span12">
        <div class="head clearfix">
            <div class="isw-ok"></div>
            <h1>Add Old Attendence</h1>
        </div>
        <div class="block-fluid">
            <form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
              <fieldset>              
<?php
$st		= array();
$sql_st	= mysql_query("SELECT * FROM `state` where `state_name` IN(SELECT distinct `state` FROM `tbl_emp_records` where 1 ) ORDER BY `state_name` ASC ")or die(mysql_error());
while($row_st= mysql_fetch_array($sql_st))
{
	$key    = $row_st['state_name'];
	$ccc    = $row_st['backend_mail'];
?>
<div class="row-form clearfix">
<div class="span2">
    <label><?php echo $key;?></label>
    <input type="checkbox" name="state[]" value="<?php echo $key;?>" />
</div>  
<div class="span6">
    <label>Cc Mail</label>
    <input type="text" name="<?php echo $key;?>_cc" value="<?php echo $ccc;?>" />
</div>
</div>
<?php
		}
	?>
                     <div class="row-form clearfix">
                    <div class="span2"><label>Email Subject</label></div>							  	
                    <div class="span6"><input type="text" name="subject" required />
                    </div>
                </div>
                	<div class="row-form clearfix">
                    <div class="span2"><label>Email Description</label></div>							  	
                    <div class="span6">
						<?php
                        $oFCKeditor = new FCKeditor('FCKeditor1');
                        
                        $oFCKeditor->BasePath = 'fckeditor/';
                        
                        //set the EnterMode to "br" (overwrites the default configuration from fckconfig.js)
                        
                        $oFCKeditor->Config['EnterMode'] = 'br';
                        
                        $oFCKeditor->Value = "";
                        if(isset($_REQUEST['page_id'])){
                        $oFCKeditor->Value = "";
                        }
                        
                        $oFCKeditor->Create() ; 
                        ?>
                    </div>
                </div>
                     <div class="row-form clearfix">
                     <div class="span2">
                    	<label>&nbsp;</label>
                        <input type="submit" value="Send Mail" name="Send" />
                        </div>
                     </div>
                     
              </fieldset>
            </form>  
        </div> 
    </div>
</div>
<?php
if(isset($_POST['Send']))
{
	$state_arr			= $_POST['state'];
	$details            = mysql_real_escape_string($_POST['FCKeditor1']);
	$subject            = mysql_real_escape_string($_POST['subject']);
	$i					= 0;
	foreach($state_arr as $key )
	{
		$state			= $key;
		$cc				= $_POST[$key.'_cc'];
		$message		= "";
		$message		= '<html><head><title>Rudraansh Holding LLP</title><head><style>body{background:#fff;color:#000;font-size:14px; font-family:Verdana, Geneva, sans-serif; margin:0; padding:0;}div.mailerwrapper{margin:auto;width:600px; border-bottom:#000 solid 2px;}.top_line{background: #000 none repeat scroll 0 0;height: 4px;}.dear{ padding:20px 0; font-size:14px;}.dear h2{margin:0; color:#000; font-size:17px;  padding-bottom:5px; font-weight:normal;}.products_items{padding:0; font-size:14px;}.orderid{margin:0; color:#fa903a; font-size:17px;  padding-bottom:5px; font-weight:normal;}.products_items{ border-bottom:#000 solid 1px; border-right:#000 solid 1px;}.products_items tr td{ border:#000 solid 1px; border-bottom:none; border-right:none; padding:5px;}.customer_detals{ background:#efefef; padding:5px 20px 0px 20px; margin:10px 0;}.customer_detals h2{ margin:0; color:#fa903a; font-size:16px; font-weight:normal; padding-bottom:8px;}.customer_detals ul{ list-style:none; padding:0; margin:0;}.customer_detals ul li{padding:0 0 0 35px;}.name{ background:url(http://revateam.com/suresh/rd_cons/admin/images/man.png.ppp.png) 0 0 no-repeat; display:block; line-height:30px; }.mail{ background:url(http://revateam.com/suresh/rd_cons/admin/images/mail.png) 0 0 no-repeat; display:block; line-height:30px; }.phone{ background:url(http://revateam.com/suresh/rd_cons/admin/images/phone.png) 0 0 no-repeat; display:block; line-height:30px; }.copy_rt{ text-align:center; font-size:13px; padding:5px 0 15px 0;}</style></head><body>	
		<div class="mailerwrapper">
	<div class="top_line">&nbsp;</div>
	<div class="banner"><img src="http://revateam.com/suresh/rd_cons/admin/images/banner_top.jpg" /></div>
	<div class="dear">
	'.str_replace('\r\n','',$details).
	'
	</div>
	<!--<div class="orderid">//  Rudraansh //</div>-->
	';
	$message .='<div class="customer_detals"><h2>Contact details </h2><ul><li class="name"><strong><em>Deepak Singh Shekhawat</em></strong></li><li class="mail">backend@renesolutions.com</li><li class="phone">+91 9252999978</li></ul></div><div class="copy_rt">All Rights Reserved. Rudraansh Holding LLP © Copyright 2017 </div></div></body></html>';
	
	$sql_2				= mysql_query(" SELECT * FROM `tbl_admin` WHERE `post` like '%".$state."%' order by `id` ")or die(mysql_error());
	$row_2				= mysql_fetch_array($sql_2);
	////Mail Content
		$to 	  = $row_2['email'];
		if(!empty($cc))
		{
			$to   = $to.",".$cc;///"revateamdoc@gmail.com";//;//;;//	
		}
		$from     = 'backend@renesolutions.com';
		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		$headers .= 'Cc:ashish.tiwari@rsplgroup.com\r\n';
		//$headers .= 'Cc: ashish.tiwari@rsplgroup.com\r\n';
		$headers .= 'From: '.$from."\r\n".'Reply-To: '.$from."\r\n" .'X-Mailer: PHP/' . phpversion();	 
		// Sending email
		mail($to, $subject, $message, $headers);
		///Insert Data
		mysql_query("INSERT INTO `tbl_mail_entry` SET `user_id`='4',`date`=NOW(),`to`='$to',`from`='$from',`subject`='$subject',`message`='$message',`attachment`='' ")or die(mysql_error());
		$i++;
	}
	$_SESSION['msg']= 'Attendence mail has been sent successfully.';
	header("location:home.php?page=salary_mail_send");
}
?> 