<?php 
include('includes/db_config.php');
include('includes/class.helper.php');
$helper = new Helper();

$contentdetails=$helper->select("tbl_documents","documentid,memberid,expiredate,title",array());
foreach($contentdetails as $details){
				  $expirydate  =date_create($details['expiredate']);
                  $current_date =date_create(date("Y-m-d"));
                //$date_to_compare = date("Y-m-d",time()+86400); //1 day later
                  $diff=date_diff($current_date,$expirydate);
                 // echo $expirestatus=$diff->format("%a");
				    $expirestatus=intval($diff->format("%R%a"));
				   //echo "<br/>";
				   $helper->update("tbl_documents",array("daystoexpire"=>$expirestatus),array("documentid"=>$details['documentid']),$required);
				   if($expirestatus<46){
					 $memberdetails=$helper->select("tbl_members","*",array("memberid"=>$details['memberid'])); 
					 $to = $memberdetails[0]['email'];
					 $message="<p style='direction:rtl;'>العزيز ".$memberdetails[0]['firstname']." ".$memberdetails[0]['middlename']." ".$memberdetails[0]['lastname'].",</p>";
					 $message.="<p style='direction:rtl;'>فإن مستندك المسمى ".$details['title']." سينتهي في ".$details['expiredate']."</p>";
					 $message.="<p style='direction:rtl;'>الرجاء محاولة تجديد المستندات قبل تاريخ الانتهاء</p>";					 
					  $subject = "تذكير تجديد المستند";
					  $from ="info@hamdanfd.ae";
					  $headers = "From:" . $from."\r\n";
					  $headers.= "Reply-to: " .$from."\r\n";
					  $headers .= "Content-type: text/html\r\n"; 
					  #$headers .= 'Cc: alex@infobahnworld.com' . "\r\n"; 
					  mail($to,$subject,$message,$headers);
					  
					?>
                    
                    
                    <?php
					//echo  $message; 
				   }
				   
				  /*if($expirestatus<0){
					  echo "expired";
					  echo"<br/>";
				  }
				   if($expirestatus>0){
					  echo "not expired";
					   echo"<br/>";
				  }*/
}
?>
                      