Login   Register  
PHP Classes
elePHPant
Icontem

File: example_yesno.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Manish Khanchandani  >  Ratings  >  example_yesno.php  >  Download  
File: example_yesno.php
Role: Example script
Content type: text/plain
Description: Example
Class: Ratings
Store and retrieve ratings of products in MySQL
Author: By
Last change:
Date: 2009-07-20 06:45
Size: 2,643 bytes
 

Contents

Class file image Download
<?php 

$item_id 
$_GET['item_id'];
if(!
$item_id$item_id 100;
// including rating class
include_once('Xoriant_Ratings.php');
$Ratings = new Xoriant_Ratings();
try {
    if(
$_POST['MM_Insert']==1) {        
            
// 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";
    }
} catch (
exception $e) { 
    
$errorMessage $e->getMessage();
    
$message $errorMessage;
}
try {
    
$return $Ratings->showRating($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>Rating Demo</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <h1>Rate for Item <?php echo $item_id?></h1>
  <?php echo $message?>
    <p><input name="rating" type="radio" value="1" /> Yes <input name="rating" type="radio" value="0" /> No
  </p>
  <p>
    <input type="submit" name="Submit" value="Rate" />
    <input name="user_id" type="hidden" id="user_id" value="1" size="32" />
    <input name="item_id" type="hidden" id="item_id" value="<?php echo $item_id?>" size="32" />
    <input name="rating_ip" type="hidden" id="rating_ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" size="32" />
    <input name="rating_date" type="hidden" id="rating_date" value="<?php echo date('Y-m-d H:i:s'); ?>" size="32" />
    <input name="uniqueip" type="hidden" id="uniqueip" value="0" size="32" />
    <input name="uniqueuser" type="hidden" id="uniqueuser" value="0" size="32" />
    <input name="MM_Insert" type="hidden" id="MM_Insert" value="1" />
  </p>
  <p>Current rating for this Item:  <?php echo $return['avg_rating']; ?></p>
</form>
</body>
</html>