<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 
/**
* @version $Id: product.product_price_form.php,v 1.5 2005/01/27 19:34:03 soeren_nb Exp $
* @package mambo-phpShop
* @subpackage HTML
* Contains code from PHPShop(tm):
* 	@copyright (C) 2000 - 2004 Edikon Corporation (www.edikon.com)
*	Community: www.phpshop.org, forums.phpshop.org
* Conversion to Mambo and the rest:
* 	@copyright (C) 2004-2005 Soeren Eberhardt
*
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* mambo-phpShop is Free Software.
* mambo-phpShop comes with absolute no warranty.
*
* www.mambo-phpshop.net
*/
mm_showMyFileName( __FILE__ );

?>

<h2><?php echo $PHPSHOP_LANG->_PHPSHOP_PRICE_FORM_LBL ?></h2>
  <?php
require_once(CLASSPATH.'ps_shopper_group.php');
$ps_shopper_group = new ps_shopper_group;
require_once(CLASSPATH.'ps_vendor.php');
$ps_vendor = new ps_vendor;

$product_id = mosgetparam($_REQUEST, 'product_id', 0);
$product_price_id = mosgetparam($_REQUEST, 'product_price_id', 0);
$product_parent_id = mosgetparam($_REQUEST, 'product_parent_id', 0);

$product_parent_id = !empty($product_parent_id) ? $product_parent_id : "";

$db = new ps_DB;
/* If Updating a Price */
if (!empty($product_price_id)) {
  /* Get field values for update */
  $q  = "SELECT * FROM #__pshop_product_price ";
  $q .= "WHERE product_price_id='$product_price_id' ";
  $db->query($q); 
  $db->next_record();
} 
/* If Adding a new Price */
elseif (empty($vars["error"])) {
  /* Set default currency for product price */
  $default["product_currency"] = $ps_vendor->get_field($ps_vendor_id,"vendor_currency");
}

if (!empty($vars["product_price_id"])) {
  $product_price_id = $vars["product_price_id"];
  if (empty($product_parent_id)) {
    echo $PHPSHOP_LANG->_PHPSHOP_PRICE_FORM_UPDATE_FOR_PRODUCT . " ";
  } else {
    echo $PHPSHOP_LANG->_PHPSHOP_PRICE_FORM_UPDATE_FOR_ITEM . " ";
  }
}
else {
  if (empty($product_parent_id)) {
    echo $PHPSHOP_LANG->_PHPSHOP_PRICE_FORM_NEW_FOR_PRODUCT . " ";
  } else {
    echo $PHPSHOP_LANG->_PHPSHOP_PRICE_FORM_NEW_FOR_ITEM . " ";
  }
}

$url = $_SERVER['PHP_SELF'] . "?page=$modulename.product_form&product_id=$product_id&product_parent_id=$product_parent_id";
echo "<a href=\"" . $sess->url($url) . "\">";
echo $ps_product->get_field($product_id,"product_name");
echo "</a>"; 
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" name="adminForm" >
  <table width="100%" border="0" cellpadding="2" cellspacing="0">
    <tr> 
      <td valign="top" colspan="2"> 
        </td>
    </tr>
    <tr> 
      <td width="23%" height="20" valign="middle" > 
        <div align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_PRICE_FORM_PRICE ?>:</div>
      </td>
      <td width="77%" height="20" > 
        <input type="text" class="inputbox" name="product_price" value="<?php $db->sp("product_price"); ?>" size="10" maxlength="10" />
      </td>
    </tr>
    <tr> 
      <td width="23%" height="10" valign="middle" > 
        <div align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_PRICE_FORM_CURRENCY ?>:</div>
      </td>
      <td width="77%" height="10" > 
        <?php $ps_html->list_currency("product_currency",$db->sf("product_currency")) ?>
      </td>
    </tr>
    <tr> 
      <td width="23%" height="10" valign="middle" > 
        <div align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_PRICE_FORM_GROUP ?>:</div>
      </td>
      <td width="77%" height="10" >
          <?php 
          if (empty($product_price_id)) {
              $db_sg = new ps_DB;
              $q = "SELECT shopper_group_id FROM #__pshop_product_price ";
              $q .= "WHERE product_id = '$product_id' ";
              $db_sg->query( $q );
              
              echo "<select class=\"inputbox\" name=\"shopper_group_id\">\n";
              
              $q = "SELECT shopper_group_id, shopper_group_name";
              $q .= " FROM `#__pshop_shopper_group` ";
              $q .= " WHERE 1 = 1 ";
              while( $db_sg->next_record() ) {
                  $q .= "AND shopper_group_id != '".$db_sg->f("shopper_group_id")."'";
              }
              $db_sg->query( $q );
             
              while( $db_sg->next_record() ) {
                echo "<option value=\"".$db_sg->f("shopper_group_id")."\">".$db_sg->f("shopper_group_name")."</option>";
              }
              echo "</select>";
          }
          else {
            $ps_shopper_group->list_shopper_groups("shopper_group_id", $db->sf("shopper_group_id"),$db->sf("product_id"));
          } 
          ?>
      </td>
    </tr>
    <tr> 
      <td colspan="2" height="2">&nbsp;</td>
    </tr>
    <tr> 
      <td colspan="2" height="22">&nbsp;</td>
    </tr>
  </table>
  <input type="hidden" name="product_id" value="<?php echo !empty($product_price_id) ? $db->sp("product_id") : $product_id; ?>" />
  <input type="hidden" name="product_price_id" value="<?php echo !empty($product_price_id) ? $product_price_id : ""; ?>" />
  <input type="hidden" name="func" value="<?php echo !empty($product_price_id) ? "productPriceUpdate" : "productPriceAdd" ?>" />
  <input type="hidden" name="page" value="<?php echo $modulename ?>.product_price_list" />
  <input type="hidden" name="return_args" value="<?php echo $return_args; ?>" />
  <input type="hidden" name="option" value="com_phpshop" />
  <input type="hidden" name="task" value="" />
  <?php $limitstart = mosgetparam( $_REQUEST, 'limitstart'); ?>
  <input type="hidden" name="limitstart" value="<?php echo $limitstart ?>" />
</form>
