<?php

/**
 *
 * INDEXU
 * Copyright(C), Nicecoder, 2000-2006, All Rights Reserved.
 *
 * INDEXU(tm) is protected by Indonesia and International copyright laws.
 * Unauthorized use or distribution of INDEXU(tm) is strictly prohibited,
 * violators will be prosecuted. To obtain a license for using INDEXU(tm),
 * please register at Nicecoder home page at http://www.nicecoder.com
 *
 * Author:
 *    Dody Rachmat Wicaksono (dody@nicecoder.com)
 *    M. Zuber (zubby@nicecoder.com)
 *
 */

  /*===================================================
    ShowFormSetDefaultPrice()
  ===================================================*/

  function ShowFormSetDefaultPrice() {

    // vars global configuration
    global $admin_template_path;

    // vars url & form
    global $cat;

    // vars messages
    global $msg;

    // vars template
    
    DisplayTemplate($admin_template_path . "cat_set_default_price_form.html");
  }


  /*===================================================
    ProcessFormSetDefaultPrice()
  ===================================================*/

  function ProcessFormSetDefaultPrice() {

    // vars global configuration
    global $dbConn, $admin_template_path;

    // vars url & form
    global $sponsored_price, $premium_price, $basic_price, $override;

    // vars messages
    global $msg;

    // vars template
    global $message, $back;

    // verify input
    
    $query = "select category_id, sponsored_price, premium_price, basic_price 
              from idx_category";
    $result = $dbConn->Execute($query);

    while ($row = $result->FetchRow()) {
      if ($override) {
        $query = "update idx_category
                  set sponsored_price = '$sponsored_price', 
                      premium_price = '$premium_price',
                      basic_price = '$basic_price'
                  where category_id = '$row[category_id]'";
      }
      else {
        $new_sponsored_price = ($row['sponsored_price']) ? $row['sponsored_price'] : $sponsored_price;
        $new_premium_price = ($row['premium_price']) ? $row['premium_price']: $premium_price;
        $new_basic_price = ($row['basic_price']) ? $row['basic_price']: $basic_price;
        $query = "update idx_category
                  set sponsored_price = '$new_sponsored_price', 
                      premium_price = '$new_premium_price',
                      basic_price = '$new_basic_price'
                  where category_id = '$row[category_id]'";
      }
      $dbConn->Execute($query);
    }

    $message = $msg["20052"];
    $back = "<a href=cat_set_default_price.php>Back</a>";

    DisplayTemplate($admin_template_path . "message.html", "\$message,\$back");
  }


  /*===================================================
    main
  ===================================================*/

  include "../application.php";
  
  RunPreFilter(__FILE__);

  DisplayTemplate($admin_template_path . "header.html");
  if (empty($pflag)) {
    ShowFormSetDefaultPrice();
  }
  elseif($pflag=='set') {
    ProcessFormSetDefaultPrice();
  }
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>