<?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)
 *
 */

  /*===================================================
    DeleteCategory()
  ===================================================*/

  function DeleteCategory() {

    // vars global configuration
    global $admin_template_path;

    // vars url & form
    global $num_rows;

    // vars messages
    global $msg;

    // vars template
    global $message, $back;

    $tpl = new Template();

    $category_obj = new clsCategory;
    $category_obj->table_name = "idx_category";
    $category_obj->link_table_name = "idx_link";

    $i=1;
    while($i<=$num_rows){
      $var = "chkbox_$i";
      $cat = $GLOBALS["$var"];

      if(!empty($cat)) {
        $name = $category_obj->GetCategoryName($cat);
        $delete_result = $category_obj->Delete($cat);

        if($delete_result==0) $message .= $msg["20041"];
        elseif($delete_result==1) $message .= $msg["20042"];

        $tpl->assign('category', $name);
        $message = $tpl->fetch('var:' . $message);
      }
      $i++;
    }

    if(!empty($message))
      $message = $message.$msg["30016"];
    else
      $message = $msg["20043"];

    $back = "<a href=$back>Back</a>";

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


  /*===================================================
    SetOrderPricing()
  ===================================================*/

  function SetOrderPricing() {

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

    // vars messages
    global $msg;

    // get all cat id
    $query = "select category_id from idx_category";
    $result = $dbConn->Execute($query);

    while ($val = $result->FetchRow()) {
      $var = "order_$val[category_id]";
      if (isset($GLOBALS["$var"])) {
        $var = "order_$val[category_id]";
        $order = $GLOBALS["$var"];

        $var = "price_basic_$val[category_id]";
        $price_basic = $GLOBALS["$var"];

        $var = "price_premium_$val[category_id]";
        $price_premium = $GLOBALS["$var"];

        $var = "price_sponsored_$val[category_id]";
        $price_sponsored = $GLOBALS["$var"];

        $query = "update idx_category
                   set order_num = '$order',
                       basic_price = '$price_basic',
                       premium_price = '$price_premium',
                       sponsored_price = '$price_sponsored'
                  where category_id = $val[category_id]";
        $dbConn->Execute($query);
      }
    }

    $message = $msg['20491'];

    $back = "<a href=cat_view.php>Back</a>";

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


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

  include "../application.php";

  RunPreFilter(__FILE__);

  DisplayTemplate($admin_template_path . "header.html");
  if ($pflag == "delete") {
    DeleteCategory();
  }
  elseif ($pflag == "orderpricing") {
    SetOrderPricing();
  }
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>