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

function block_category_jump($params) {
  global $dbConn, $site_url, $cat, $category_separator;

  if (!$params['template']) {
    $params['template'] = 'block.category_jump.html';
  }

  $tpl = new Template;

  $query_filter = "";
  if ($params['type'] == 'main') {
    $query_filter = "and a.parent_id = '0'";
  }
  if ($params['type'] == 'sub') {
    $query_filter = "and b.parents like '%;$cat;%'";
  }
  if ($params['type'] == 'all') {
    $query_filter = "";
  }

  $query = "select a.category_id, b.path, b.path_with_url
            from idx_category a
                 left join idx_category_path b on (a.category_id = b.category_id)
            where visible = 1 $query_filter
            order by b.path asc";
  $result = $dbConn->Execute($query);

  while ($row = $result->FetchRow()) {
    preg_match_all('|<a href="(.*?)"|msi', $row['path_with_url'], $match);
    $row['path_with_url'] = $match[1][@count($match[1]) - 1];
    $paths = explode($category_separator, $row['path']);
    $row['path'] = str_repeat('&nbsp; ', (@count($paths) - 1) * 3).$paths[@count($paths) - 1];
    $categories[] = $row;
  }
  
  $tpl->assign('cat', $cat);
  $tpl->assign('categories', $categories);
  $tpl->display("blocks/" . $params['template']);
}

?>
