<?php  
if($_POST['MM_Insert']==1) { 
    try { 
        // including rating class 
        include_once('Xoriant_Ratings.php'); 
        $Ratings = new Xoriant_Ratings(); 
         
        // making array of results 
        $data['user_id'] = $_POST['user_id']; 
        $data['item_id'] = $_POST['item_id']; 
        $data['rating'] = $_POST['rating']; 
        $data['rating_ip'] = $_POST['rating_ip']; 
        $data['rating_date'] = $_POST['rating_date']; 
        $data['uniqueip'] = $_POST['uniqueip']; 
        $data['uniqueuser'] = $_POST['uniqueuser']; 
         
        // validating the data 
        $Ratings->validateData($data); 
        if($data['uniqueip']=="1") { 
            $count = $Ratings->checkRatingUniqueIp($data); 
            if($count>0) throw new Exception("Duplicate Ip"); 
        } 
        if($data['uniqueuser']=="1") { 
            $count = $Ratings->checkRatingUniqueUser($data); 
            if($count>0) throw new Exception("Duplicate User"); 
        } 
        // inserting data in table 
        $rating_id = $Ratings->phpinsert('xoriant_ratings', 'rating_id', $data); 
        // return message 
        $message = "Rating Submitted Successfully"; 
        $return = $Ratings->showRating($_POST['item_id']); 
    } catch (exception $e) {  
        $errorMessage = $e->getMessage(); 
        $message = $errorMessage; 
    } 
} 
?> 
<!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>Untitled Document</title> 
</head> 
 
<body> 
<form id="form1" name="form1" method="post" action=""> 
  <h1>Item</h1> 
  <?php echo $message; ?> 
  <p><?php for($i=1;$i<=10;$i++) { ?> 
    <input name="rating" type="radio" value="<?php echo $i; ?>" /> <?php echo $i; ?>  
    <?php } ?>  
  </p> 
  <p> 
    <input type="submit" name="Submit" value="Rate" /> 
  </p> 
  <p>User Id:  
    <input name="user_id" type="text" id="user_id" value="1" size="32" /> 
  </p> 
  <p>Item Id:  
    <input name="item_id" type="text" id="item_id" value="1" size="32" /> 
  </p> 
  <p>IP:  
    <input name="rating_ip" type="text" id="rating_ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" size="32" /> 
  </p> 
  <p>Date:  
    <input name="rating_date" type="text" id="rating_date" value="<?php echo date('Y-m-d H:i:s'); ?>" size="32" /> 
  </p> 
  <p>Unique IP: 
    <input name="uniqueip" type="radio" value="1" /> 
Yes 
<input name="uniqueip" type="radio" value="0" checked="checked" /> 
No </p> 
  <p>Unique User: 
    <input name="uniqueuser" type="radio" value="1" /> 
    Yes 
  <input name="uniqueuser" type="radio" value="0" checked="checked" /> 
    No </p> 
  <p> 
    <input name="MM_Insert" type="hidden" id="MM_Insert" value="1" /> 
  </p> 
  <?php if($_POST) { ?> 
  <p>Current Rating: <?php echo $return['avg_rating']; ?></p> 
  <?php } ?> 
  <p> </p> 
</form> 
</body> 
</html> 
 
 |