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

  /*===================================================
    ShowFormAddCategory()
  ===================================================*/

  function ShowFormAddCategory() {

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

    // vars url & form
    global $cat;

    // vars messages
    global $msg;

    // vars template
    global $related, $parent, $visible, $permission, $registered_only,
             $price_sponsored, $price_premium, $price_basic;
    
    $category_obj = new clsCategory;

    $category_obj->table_name = "idx_category";
    $category_obj->separator = $category_separator;

    $parent = $category_obj->DisplayCategoryListBox(0,false,1);
    $related = str_replace("<select name=\"cat\">","<select name=\"related\">",$category_obj->DisplayCategoryListBox(0,false,1));
    $related = str_replace("Main Category","Have no relation",$related);

    $visible = ShowRadioButton("visible",$msg["20011"],$msg["20012"],1);
    $permission = ShowDropDown("permission",$msg["20013"],$msg["20014"],1);
    $registered_only = ShowRadioButton("registered_only",$msg["20015"],$msg["20016"],0);

    DisplayTemplate($admin_template_path . "cat_add_form.html",
      "\$parent,\$visible,\$permission,\$registered_only,\$related");
  }


  /*===================================================
    ProcessFormAddCategory()
  ===================================================*/

  function ProcessFormAddCategory() {

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

    // vars url & form
    global $name, $cat, $description, $image, $content, $visible, $permission,
             $meta_keyword, $meta_description, $registered_only, $header, 
             $footer, $related, $page_title, $price_sponsored, $price_premium,
             $price_basic;

    // vars messages
    global $msg;

    // vars template
    global $message, $back;

    // verify input

    if(empty($name)) $error_msg = $msg["20021"];

    if(empty($error_msg)) {

      $category_obj = new clsCategory;
      $category_obj->table_name = "idx_category";
      $category_obj->separator = $category_separator;
      $parent_id = $cat;
      $category_obj->Add($name, $parent_id, $description, $image, $content, 
                           $visible, $permission, $meta_keyword, 
                           $meta_description, $registered_only, $header, 
                           $footer, $related, $page_title, $price_sponsored, 
                           $price_premium, $price_basic);

      $message = $msg["20017"] . $msg["30016"];
      $back = "<a href=cat_add.php>Back</a>";
    }
    else $message = $error_msg;

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

  }


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

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

  DisplayTemplate($admin_template_path . "header.html");
  if (empty($pflag)) {
    ShowFormAddCategory();
  }
  elseif($pflag == 'add') {
    ProcessFormAddCategory();
  }
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>