<?php
/**
  @licence GPL 2005-2010  The osCSS developers - osCSS Open Source E-commerce
  @portion code Copyright (c) 2002 osCommerce
  @package osCSS-2 <www http://www.oscss.org>
  @version 2.1.0
  @date  19/12/10, 19:49
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/

/**
  Return a navigation links name
*/
function oscss_get_navlink_name($nav_link_id, $language_id = 0) {
    global $languages_id;

    if ($language_id == 0) $language_id = $languages_id;
    $nav_link_query = tep_db_query("select nav_name from " . TABLE_NAVIGATION_LINKS_DESCRIPTION . " where nav_link_id = '" . (int)$nav_link_id . "' and language_id = '" . (int)$language_id . "'");
    $nav_link = tep_db_fetch_array($nav_link_query);

    return $nav_link['nav_name'];
}

/**
  Sets the status of a navigation link
*/
function oscss_set_nav_status($nav_link_id, $status) {
  if ($status == '1')  return tep_db_query("update " . TABLE_NAVIGATION_LINKS . " set nav_link_status = '1' where nav_link_id = '" . (int)$nav_link_id . "'");
  elseif ($status == '0')  return tep_db_query("update " . TABLE_NAVIGATION_LINKS . " set nav_link_status = '0' where nav_link_id = '" . (int)$nav_link_id . "'");
  else  return -1;
}

/**
  Tableau des item présent, et prepa pour tep_draw_pull_down_menu
  @param
    @a array tableau des lien a exclure, par nav_link_id
*/
function parent_item_nav($exclude=false){
  global $languages_id;
  $tab=array();$ind='';
    $arry_navlink=list_item_order_niv();
    foreach($arry_navlink as $nav_links ){
      if ((is_array($exclude) && !in_array($nav_links['nav_link_id'],$exclude)) || !$exclude ){
        $ind=tep_decal($nav_links['niveau']);
        $tab[]=array('id'=>$nav_links['nav_link_id'], 'text'=> $ind.oscss_get_navlink_name($nav_links['nav_link_id']));
      }
    }
  return $tab;
}


/**
  Function construction du tableau des liens, appel hierarchise.
  Appel recursif
  @param
    @a int parent_id l'id root
    @a boolean false par defaut, true mode recursif
*/
function list_item_order_niv($parent_id=0,$recursif='false'){
    global $NAVLINK_CONDITION;
    $arry_navlink=array();
    $nav_links_query = tep_db_query($sql="SELECT * from ".TABLE_NAVIGATION_LINKS ." nv where parent_id ='".(int)$parent_id."' order by ".((isset($_GET['sort_by'])) ? $_GET['sort_by'] : ' parent_id, nav_sort_order ASC'));
    $niveau=($recursif !='false')? ((int)$recursif) : 0 ;

    while($nav_links = tep_db_fetch_array($nav_links_query)) {


      if ($nav_links['nav_link_status'] == '1')  $status_image = tep_image(DIR_WS_ICONS . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN) . '<a href="' . tep_href_link(FILENAME_NAVIGATION_LINKS, 'action=setflag&amp;flag=0&amp;nID=' . $nav_links['nav_link_id']) . '">' . tep_image(DIR_WS_ICONS . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 16, 16) . '</a>';
      else  $status_image = '<a href="' . tep_href_link(FILENAME_NAVIGATION_LINKS, 'action=setflag&amp;flag=1&amp;nID=' . $nav_links['nav_link_id']) . '">' . tep_image(DIR_WS_ICONS . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT) . '</a>' . tep_image(DIR_WS_ICONS . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 16, 16);


      $arry_navlink[]=array_merge($nav_links, array('condition'=>$NAVLINK_CONDITION[$nav_links['customers_status']],'status_image'=>$status_image,'niveau'=> $niveau) );

      $isd=list_item_order_niv($nav_links['nav_link_id'],($niveau+1));

      if(count($isd) >0 ){
        $niveau++;
        $arry_navlink =array_merge($arry_navlink,$isd);
        $niveau--;
      }
    }

    return $arry_navlink;
}

?>