<?php
session_start();
include("include/dbconnect.php");
include("include/Stemmer.php");
extract($_POST);
$uname=$_SESSION['uname'];
$msg="";


$ip = $_SERVER['REMOTE_ADDR'];
//////MAC Address////////
ob_start();
//Get the ipconfig details using system commond
system('ipconfig /all');

// Capture the output into a variable
$mycom=ob_get_contents();
// Clean (erase) the output buffer
ob_clean();

$findme = "Physical";
//Search the "Physical" | Find the position of Physical text
$pmac = strpos($mycom, $findme);

// Get Physical Address
$mac=substr($mycom,($pmac+36),17);
////////////////////////////////////////////


$pid=$_REQUEST['pid'];
$orderid=$_SESSION['purchase_id'];
$mqry=mysql_query("select max(id) as maxid from product_review");
$mrow=mysql_fetch_array($mqry);
$id1 = $mrow['maxid'];
$id2 = $id1+1;	
$dis=0;


$q1=mysql_query("select * from register where username='$uname'");
$r1=mysql_fetch_array($q1);
$mac2=$r1['macaddress'];
	if(isset($btn))
	{
	$review=$_REQUEST['review'];
	$q2=mysql_query("select * from product_review where uname='$uname' && pid=$pid && orderid=$orderid");
	$n2=mysql_num_rows($q2);
		if($n2==0 && $mac==$mac2)
		{
	//$r2=mysql_fetch_array($q2);
	//$rid=$r2['id'];
		//		$dis=$id1-$rid;
				
		//}
	
		//if($dis>=10 || $n2==0)
		//{
		
	///////////////
		$title=$txt_post;
 $stop_words = array("the", "and", "a", "to", "of", "in", "i", "is",
                         "that", "it", "on", "you", "this", "for", "but",
                         "with", "are", "have", "be", "at", "or", "as",
                         "was", "so", "if", "out", "not");
 
    $words = explode(" ", $title);
 
    foreach($words as $word) {
        $stem = PorterStemmer::Stem($word);
 
        /* Remove stop words */
        if(!in_array($stem, $stop_words)) {
            $stem_words[] = $stem;
        }
    }
$sword=@implode(" ",$stem_words);
		/////////////////////////////////////////////////////////
$kq1=mysql_query("select * from keyword_pos");
while($kr1=mysql_fetch_array($kq1))
{
$key=$kr1['keyword'];
$pos=strpos($sword,$key);
	if($pos===false)
	{
	$st1=0;
	}	
	else
	{
	$pst=0;
	$st1=1;
	mysql_query("update product_review set pos_cnt=pos_cnt+1 where id=$id");
	
	break;
	}
	
}

/////////////////////////////////////////////////////////////
$kq2=mysql_query("select * from keyword_neg");
while($kr2=mysql_fetch_array($kq2))
{
$key2=$kr2['keyword'];
$pos2=strpos($sword,$key2);
	if($pos2===false)
	{
	$st2=0;
	}	
	else
	{
	$pst=1;
	$st2=1;
	mysql_query("update product_review set neg_cnt=neg_cnt+1 where id=$id");
	
	break;
	}
	
}
		
		
		
	////////////
	$comment=$_REQUEST['comment'];
	
			$n =mysql_query("insert into product_review(id,orderid,uname,pid,star,review) values(".$id2.",'$orderid','$uname','".$pid."','".$review."','".$comment."')"); 
		
	$msg="<span class=msg2>Rating Addedd Successfully....</span>";	
		
		}
		else
		{
		$msg="<span class=style1>Your Rating was Fake!!!</span>";
		}		
		
	
	}//btn

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Rating</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
<form name="form1" method="post" action="">
<table width="382" height="114" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" class="hd3">
  <tr>
    <td width="372"><span class="txt1"><?php echo $rs['hotel']; ?></span></td>
  </tr>
  
  <tr>
    <td class="msg2">Your Review </td>
  </tr>
  <tr>
    <td><textarea name="comment" cols="40" rows="5"></textarea></td>
  </tr>
  <tr>
    <td align="center"><input type="submit" name="btn" value="Submit" />    </td>
  </tr>
  <tr>
    <td align="center"><?php echo $msg; ?></td>
  </tr>
  <tr>
    <td align="center">
	<a href="rate_view.php?orderid=<?php echo $_REQUEST['orderid']; ?>">Back</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<a href="javascript:window.close()">Close</a></td>
  </tr>
</table>
</form>
</body>
</html>
