RE: Only allow customer to write a review once for any product

VegasVik <[email protected]> 12 Sep 2003 02:37:47 -0000
Newsgroups gmane.comp.web.oscommerce.tips
Message-ID <71d68dddb63a5b87b520c9bb6c42c77d@osCommerce-Forums>
This message was sent from: Tips and Tricks
http://forums.oscommerce.com/viewtopic.php?p=228199#228199
----------------------------------------------------------------

Here's that section of code.  Forgive my ignorance.  I'm very new to php.

[code]
<?php
/*
  $Id: product_reviews_write.php,v 1.48 2002/07/21 23:38:57 hpdl Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2002 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

  if (!tep_session_is_registered('customer_id')) {
    $navigation->set_snapshot();
    tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  }

  if (@$HTTP_GET_VARS['action'] == 'process') {
  
	$Temp1 = $HTTP_GET_VARS['products_id']; 
	$Temp2 = (int)$customer_id; 
	$unique_query = tep_db_query("select customers_id from reviews where products_id = " . $Temp1 . " and customers_id = " . $Temp2); 
	$Temp3 = tep_db_fetch_array($unique_query); 
	if ($Temp3[customers_id] == $customer_id ) 
	{
	$error = true; 
	$messageStack->add('review', 'Only one entry allowed.'); 
	}
else {

  
    $customer = tep_db_query("select customers_firstname, customers_lastname from " . TABLE_CUSTOMERS . " where customers_id = '" . $customer_id . "'");
    $customer_values = tep_db_fetch_array($customer);
    $date_now = date('Ymd');
    tep_db_query("insert into " . TABLE_REVIEWS . " (products_id, customers_id, customers_name, reviews_rating, date_added) values ('" . $HTTP_GET_VARS['products_id'] . "', '" . $customer_id . "', '" . addslashes($customer_values['customers_firstname']) . ' ' . addslashes($customer_values['customers_lastname']) . "', '" . $HTTP_POST_VARS['rating'] . "', now())");
    $insert_id = tep_db_insert_id();
    tep_db_query("insert into " . TABLE_REVIEWS_DESCRIPTION . " (reviews_id, languages_id, reviews_text) values ('" . $insert_id . "', '" . $languages_id . "', '" . $HTTP_POST_VARS['review'] . "')");

    tep_redirect(tep_href_link(FILENAME_PRODUCT_REVIEWS, $HTTP_POST_VARS['get_params'], 'NONSSL'));
  }
  }


// lets retrieve all $HTTP_GET_VARS keys and values..
  $get_params = tep_get_all_get_params();
  $get_params_back = tep_get_all_get_params(array('reviews_id')); // for back button
  $get_params = substr($get_params, 0, -1); //remove trailing &
  if ($get_params_back != '') {
    $get_params_back = substr($get_params_back, 0, -1); //remove trailing &
  } else {
    $get_params_back = $get_params;
  }

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_REVIEWS_WRITE);

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_PRODUCT_REVIEWS, $get_params, 'NONSSL'));

  $product = tep_db_query("select pd.products_name, p.products_image from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . $languages_id . "'");
  $product_info_values = tep_db_fetch_array($product);

  $customer = tep_db_query("select customers_firstname, customers_lastname from " . TABLE_CUSTOMERS . " where customers_id = '" . $customer_id . "'");
  $customer_values = tep_db_fetch_array($customer);
?>
[/code]