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

/**
  Type possible des attribut de produits
  NOTE:
    Les type sont fixé en dur, il ets possile dans a jouter, cependant il faut mieux ne pas modifier l'ordre des 5 permiers .
*/
function draw_optiontype_pulldown() {
  return tep_get_status_array('attribute_optiontype');
}

/**
  Type possible des attribut de produits
  NOTE:
    Les type sont fixé en dur, il ets possile dans a jouter, cependant il faut mieux ne pas modifier l'ordre des 5 permiers .
*/
function translate_type_to_name($opt_type) {
  foreach(tep_get_status_array('attribute_optiontype') as $v)
    if ((int)$opt_type == $v['id']) return  $v['text'];
  return 'Error ' . $opt_type;
}


/**
  Calcul list des options dispo
  @author oscim <mail oscim@oscss.org> <www http://www.oscim.fr>
*/
function attr__GetArray_ListOption(){
  global $languages_id;

  $options = "select * from " . TABLE_PRODUCTS_OPTIONS . " where language_id = '" . (int)$languages_id . "' order by products_options_sort_order DESC, products_options_name ASC";
  $options_split = new splitPageResults($option_page, MAX_ROW_LISTS_OPTIONS, $options, $options_query_numrows);
  $list = array();
  $res=tep_db_query($options);
  if(tep_db_num_rows($res)>0 )
  while($ele=tep_db_fetch_array($res))$list[]=$ele;
  return $list;
}

/**
  Calcul list des Valeur options dispo
  @author oscim <mail oscim@oscss.org> <www http://www.oscim.fr>
  @param int $poID $_GET['poID']
*/
function attr__GetArray_ListValueOption($poID){
  global $languages_id;

  $options = "select pov.* from " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov, ".TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS." pov2po where language_id = '" . (int)$languages_id . "' and pov.products_options_values_id = pov2po.products_options_values_id  and pov2po.products_options_id='".(int)$poID."' order by pov.products_options_values_id";
//   $options_split = new splitPageResults($option_page, MAX_ROW_LISTS_OPTIONS, $options, $options_query_numrows);
  $list = array();
  $options = tep_db_query($options);
  if(tep_db_num_rows($options)>0 )
    while ($options_values = tep_db_fetch_array($options)) $list[]=$options_values;

  return $list;
}

/**
  Calcul list des Valeur options dispo
  @author oscim <mail oscim@oscss.org> <www http://www.oscim.fr>
  @param
    @a string
    @a int $flag
    @a int $poID
*/
function attr__UpExe_SetOption($action,$flag,$poID){
  if($action=='setimg') $col='products_options_images_enabled';
  elseif($action=='setstock') $col='products_options_track_stock';
  elseif($action=='setsort') $col='products_options_sort_order';
  elseif($action=='setcond') $col='products_options_condition';
  else return;

  $value= tep_db_prepare_input($flag);
  $options = "update " . TABLE_PRODUCTS_OPTIONS . " set ".$col."='".tep_db_input($value)."' where products_options_id = '" . (int)tep_db_input($_GET['poID']) . "' LIMIT 1";
  if($res=tep_db_query($options) !=false) return true;
  return false;
}

?>