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

  /*===================================================
    ViewCategory()
  ===================================================*/

  function ViewCategory() {

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

    // vars url & form
    global $cat;

    // vars messages
    global $msg;

    // vars template
    global $chk_box, $name, $cat_id, $dark_light, $category, $cat_path, $num_rows, $param, $editor;
    
    $links_obj = new clsLink;
    $links_obj->table_name = "idx_link";
    $links_obj->category_table_name = "idx_category";
    $links_obj->editor_table_name = "idx_editor";
    $links_obj->user_table_name = "idx_users";

    if(empty($cat)) $cat = 0;
    
    // category's path
    
    $category_obj = new clsCategory;
    $category_obj->table_name = "idx_category";
    $category_obj->separator = $category_separator;
    if($cat==0) $cat_path = $msg["20031"];
    else $cat_path = $msg["20031"].$category_separator.$category_obj->GetCategoryPath($cat, TRUE);
    
    // generate listing
    
    $query = "select * from idx_category where visible=0";
    $result = $dbConn->Execute($query);
    $total = $result->RecordCount();
    
    $num_rows = $total;

    $i = 0;
    while (!$result->EOF) {
      $cat_id = $result->Fields('category_id');
      $name = $result->Fields('name');
      $name = $category_obj->GetCategoryPath($cat_id);

      // get editor
      
      $editor = "<b>Editor: </b>";
      $editor_list = $links_obj->GetEditor($cat_id);
      $j = 0;
      $count_editor_list = @count($editor_list);
      while ($j < $count_editor_list) {
        $username = $editor_list[$j];
        $editor .= "<a href=editor_delete.php?username=$username&cat=$cat_id>$username</a>";
        if($j!=$count_editor_list-1) $editor .= ", ";
        $j++;
      }
      if($count_editor_list==0) $editor = "";    

      if($i%2==0) $dark_light = "tbl_light";
      else $dark_light = "tbl_light2";
      
      $number = $i+1;
      $chk_box = "<input type=checkbox name=chkbox_$number value=$cat_id>";

      $category .= EvalTemplate($admin_template_path . "cat_view_hidden_rows.html",
        "\$name,\$cat_id,\$dark_light,\$chk_box,\$editor");
      
      $i++;

      $result->MoveNext();
    }

    $param = "cat=$cat";
    
    DisplayTemplate($admin_template_path . "cat_view_hidden.html",
      "\$category,\$cat_path,\$num_rows,\$param");
  }


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

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

  DisplayTemplate($admin_template_path . "header.html");
  ViewCategory();
  DisplayTemplate($admin_template_path . "footer.html");
  
  RunPostFilter(__FILE__);

?>