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

  /*===================================================
    UpdateCategoryPath()
  ===================================================*/

  function UpdateCategoryPath() {

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

    // vars messages
    global $msg;

    // vars template
    global $message;
    
    global $dbConn;

    $query = "delete from idx_category_path";
    $result = $dbConn->Execute($query);
      
    $category_obj = new clsCategory;

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

    $query = "select category_id from idx_category";
    $result = $dbConn->Execute($query);
    if($result) $total = $result->RecordCount();

    $i = 0;
    while($i<$total) {
      $val = $result->Fields("category_id");
      $result->MoveNext();

      $path = addslashes($category_obj->CalculateCategoryPath($val));
      $arr = explode('<----break---->',$path);
      $path = $arr[0];
      $path_with_url = $arr[1];
      $parents = $arr[2];

      $query = "insert into idx_category_path values
        ($val,'$path','$path_with_url','$parents')";
      $result2 = $dbConn->Execute($query);

      $i++;
    }

    $message = $msg['20492'];
    
    DisplayTemplate($admin_template_path . "message.html", "\$message");
  }


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

  include "../application.php";
  ini_set("max_execution_time", "3600");
  
  RunPreFilter(__FILE__);

  DisplayTemplate($admin_template_path . "header.html");
  UpdateCategoryPath();
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>