<?php
//connect to site database
    
	include ('../includes/db1config.php');
	include('db1.php');
//connect to site database
/*
$host = 'localhost'; 
$username = 'restaura_taste';
include('db1.php');
$password = 'Daughters2'; 
*/	
include ('../includes/mysql_connect.php');

	
function formspecialchars($var) 
    { 
        $pattern = '/&(#)?[a-zA-Z0-9]{0,};/'; 
        if (is_array($var)) {   
            $out = array();      
            foreach ($var as $key => $v) {      
                $out[$key] = formspecialchars($v);         
           } 
        } else { 
            $out = $var; 
            while (preg_match($pattern,$out) > 0) { 
                $out = htmlspecialchars_decode($out,ENT_QUOTES);       
            }                             
            $out = htmlspecialchars(stripslashes(trim($out)), ENT_QUOTES,'UTF-8',true);    
        } 
        return $out; 
    } 



	
//$c = mysql_connect("localhost", "restaura_taste", "Daughters2"); 
//$db = mysql_select_db("restaura_activetest", $c);
mysql_query("SET NAMES 'utf8'");
date_default_timezone_set('US/Central');
/*
$rating = "1"; $rating=formspecialchars($rating);
$review = "TEST";  $review=formspecialchars($review);
$email = "apicton@apnetworking.com"; $email=formspecialchars($email);
$ip = "192.168.0.1"; 
*/
$rating = $_POST["rating"]; $rating=formspecialchars($rating);
$review = $_POST["review"];  $review=formspecialchars($review);
$email = $_POST["email"]; $email=formspecialchars($email);
$ip = $_SERVER["REMOTE_ADDR"]; 


$dateposted = date("Y-M-d")." ".date("h:i A"); 
$timestamp = time(); 
//if(($rating!="")&&($review!="")&&($email!="")){
if((!empty($rating))&&(!empty($review))&&(!empty($email))){
mysql_query("INSERT INTO reviews_store (rating,review,email,ip,dateposted,timestamp,approved) VALUES ('$rating', '$review', '$email', '$ip', '$dateposted', '$timestamp',0)");
	$adminmail=mysql_query("select email from admin where review_manager='1'");
	$adminmail=mysql_result($adminmail,0,'email'); 
	$subject = "New STORE review";
	$message = "You have received a new STORE review from http://$_SERVER[HTTP_HOST]";
	//$message = "We have received a new STORE review from http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
	$message = wordwrap($message, 70, "\r\n");
	mail($adminmail, $subject, $message);
}
//echo "TEST";
?>