<?php
/*
  osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare 

Released under the GNU General Public License 
*/

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();

  function tep_show_events_category($counter) {
    global $tree, $events_categories_string, $ecPath_array;

    for ($i=0; $i<$tree[$counter]['level']; $i++) {
      $events_categories_string .= "&nbsp;&nbsp;";
    }

    $events_categories_string .= '<a href="';

    if ($tree[$counter]['parent'] == 0) {
      $ecPath_new = 'ecPath=' . $counter;
    } else {
      $ecPath_new = 'ecPath=' . $tree[$counter]['path'];
    }

    $events_categories_string .= tep_href_link(FILENAME_DEFAULT, $ecPath_new) . '">';

    if (isset($ecPath_array) && in_array($counter, $ecPath_array)) {
      $events_categories_string .= '<b>';
    }

// display category name
    $events_categories_string .= $tree[$counter]['name'];

    if (isset($ecPath_array) && in_array($counter, $ecPath_array)) {
      $events_categories_string .= '</b>';
    }

    if (tep_has_events_category_subcategories($counter)) {
      $events_categories_string .= '-&gt;';
    }

    $events_categories_string .= '</a>';

    if (SHOW_COUNTS == 'true') {
      $events_in_events_category = tep_count_events_in_events_category($counter);
      if ($events_products_in_category > 0) {
        $events_categories_string .= '&nbsp;(' . $events_in_events_category . ')';
      }
    }

    $events_categories_string .= '<br>';

    if ($tree[$counter]['next_id'] != false) {
      tep_show_events_category($tree[$counter]['next_id']);
    }
  }
?>
<!-- categories //-->
          <tr>
            <td>
<?php
  $info_box_contents = array();
  $info_box_contents[] = array('text' => 'test');//BOX_HEADING_EVENTS_CATEGORIES);

  new infoBoxHeading($info_box_contents, true, false);

  $events_categories_string = '';
  $tree = array();

  $events_categories_query = tep_db_query("select ec.events_categories_id, ecd.events_categories_name, ec.parent_id from " . TABLE_EVENTS_CATEGORIES . " ec, " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ecd where ec.parent_id = '0' and ec.events_categories_id = ecd.events_categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, ecd.events_categories_name");
  while ($events_categories = tep_db_fetch_array($events_categories_query))  {
    $tree[$events_categories['events_categories_id']] = array('name' => $events_categories['events_categories_name'],
                                                'parent' => $events_categories['parent_id'],
                                                'level' => 0,
                                                'path' => $events_categories['events_categories_id'],
                                                'next_id' => false);

    if (isset($parent_id)) {
      $tree[$parent_id]['next_id'] = $events_categories['events_categories_id'];
    }

    $parent_id = $events_categories['events_categories_id'];

    if (!isset($first_element)) {
      $first_element = $events_categories['events_categories_id'];
    }
  }
  //------------------------
  if (tep_not_null($ecPath)) {
    $new_path = '';
    reset($ecPath_array);
    while (list($key, $value) = each($ecPath_array)) {
      unset($parent_id);
      unset($first_id);
      $events_categories_query = tep_db_query("select ec.events_categories_id, ecd.events_categories_name, ec.parent_id from " . TABLE_EVENTS_CATEGORIES . " ec, " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ecd where ec.parent_id = '" . (int)$value . "' and ec.events_categories_id = ecd.events_categories_id and ecd.language_id='" . (int)$languages_id ."' order by sort_order, ecd.events_categories_name");
      if (tep_db_num_rows($events_categories_query)) {
        $new_path .= $value;
        while ($row = tep_db_fetch_array($events_categories_query)) {
          $tree[$row['events_categories_id']] = array('name' => $row['events_categories_name'],
                                               'parent' => $row['parent_id'],
                                               'level' => $key+1,
                                               'path' => $new_path . '_' . $row['events_categories_id'],
                                               'next_id' => false);

          if (isset($parent_id)) {
            $tree[$parent_id]['next_id'] = $row['events_categories_id'];
          }

          $parent_id = $row['events_categories_id'];

          if (!isset($first_id)) {
            $first_id = $row['events_categories_id'];
          }

          $last_id = $row['events_categories_id'];
        }
        $tree[$last_id]['next_id'] = $tree[$value]['next_id'];
        $tree[$value]['next_id'] = $first_id;
        $new_path .= '_';
      } else {
        break;
      }
    }
  }
  tep_show_events_category($first_element); 

  $info_box_contents = array();
  $info_box_contents[] = array('text' => $events_categories_string);

  new infoBox($info_box_contents);
?>
            </td>
          </tr>
<!-- categories_eof //-->
