<?php
/**
  @licence GPL 2005-2011  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  29/04/11, 23:11
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/

error_reporting(E_ALL);
/**
  @interface ExtModConfig
  @brief interface for module content abstract level config in extra module conf
*/
Interface ExtModConfig {

}

/**
  @interface IntModTwo
  @brief new interface module for next generation module
*/
Interface IntModTwo {

  /**
    @remarks Use in listing dataTable call by ajax
  */

  public static function GetConf();
  /**
    @brief return FILENAME Const defined in class Child
  */
  public static function GetFILENAME();
  /**
    @brief return DB value adapted for current action
  */
  public static function GetDBValue();
  /**
    @brief return DB value adapted for current action
  */
  public static function tep_get_list($page=1,$rowbyp=10,$sOrder='',$sWhere='',$options='');

}


/**
  @class ModTwo Abstract
  @brief abstarct class for module type pages
	  Replace Interface ExtModPage
*/
Abstract Class ModTwo
  Implements IntModTwo
  {
  /**
    @var Folder Master Gabarit
  */
  const MASTER = 'MGabCont';
  /**
    @var current class string name
  */
  public static $code;
  /**
    @var current action by GET var
  */
  public static $action;
  /**
    @var array for use init module
  */
  public static $InitInfo=array();

  /**
    @var array $modules
  */
  public static $modules;




  /**
    @brief standart class exe action in module
	  If use "action" in var (POST or GET), this function is loaded
  */
  abstract protected function check_action($actions);


  /**
    @brief correspondance type / code in file xml template/data
  */
  private static function MenuAdjustType($type){
    switch($type){
// 	case 'link':
// 	break;
      case 'link':
      default:
	return 'getLink';
    }
  }

  private static function ActionCheckAcl(){
  }


  /**
    @brief Load , adjust and define var environement exe for module
	    This function replace the module constructor method .
  */
  public static function GetConf(){}
  /**
    @brief return FILENAME Const defined in class Child
  */
  public static function GetFILENAME(){}
  /**
    @brief return DB value adapted for current action
  */
  public static function GetDBValue(){}
//    abstract protected static function DTheaderTable();
  /**
    @brief return DB value adapted for current action
  */
  public static function tep_get_list($page=1,$rowbyp=10,$sOrder='',$sWhere='',$options=''){}
  /**
    @brief return array for display menu
  */
//   public static function tep_get_list($page=1,$rowbyp=10,$sOrder='',$sWhere='',$options=''){}

  /**
    @brief Standard
  */
  public function get_header(){}

  /**
    @brief Standard call display view
  */
  public function display_view(){
    MGabCont::SetCurrentClass($this);
    return MGabCont::CallGab(self::$action,__FUNCTION__,'MGabCont');
  }

  /**
    @brief Base tfoot table , for display table
    @param $multi
    @return array
	      0 => array
		    txt => string text display
		    class => string class css
		    colspan => int
		    width => value width th balise
  */
  public static function DTFootTable($mutli=false){
    /**
      @remarks No tfoot specific,use equal theader
    */
     return array( 1 => self::DTheaderTable());
  }

  /**
    @brief Use in listing dataTable call by ajax Base theader table , for display table
    @return array
	      0 => array
		    txt => string text display
		    class => string class css
		    colspan => int
		    width => value width th balise
  */
  public static function DTheaderTable(){
    $action=(empty(self::$action)? 'listing' :self::$action);
    return self::$InitInfo['theader'][$action];
  }

  /**
    @brief Use in listing dataTable call by ajax Base theader table , for display table
    @return array
	      0 => array
		    txt => string text display
		    class => string class css
		    colspan => int
		    width => value width th balise
  */
  public static function DMenuModule(){
    $action=(empty(self::$action)? 'listing' :self::$action);
    $s=array();
    if(isset(self::$InitInfo['MenuModule']) && is_array(self::$InitInfo['MenuModule']))
    foreach(self::$InitInfo['MenuModule'] as $item){
      $fct=self::MenuAdjustType($item['type']);

      $s[]= sprintf(CsrtAction::$fct($item['format'], $item['title'], @$item['image']), @$item['cssclass'],  $item['url'] ,'' );
    }

    return $s;
  }

  /**
  */
  public static function tep_get_modele(){
//     call_user_func(array(self::$code, 'GetConf'));

    $action=(empty(self::$action)? 'listing' :self::$action);

    return (isset(self::$InitInfo['modele'][$action]) ? self::$InitInfo['modele'][$action] : array() );
  }

  /**
    @brief This function is public call methode for create listing

  */
//   public static function tep_get_list($page=1,$rowbyp=10,$sOrder='',$sWhere='',$options=''){
// // var_dump(__FUNCTION__,$rowbyp);
//     return  self::ListingArray( $page,$rowbyp,$sOrder,$sWhere,$options); // call_user_func(array(self::$code, 'ListingArray'), $page,$rowbyp,$sOrder,$sWhere,$options);
// // var_dump(call_user_func_array(array(self::$code, 'ListingArray'),array( $page,$rowbyp,$sOrder,$sWhere,$options) ));
//   }

  /**
    @brief return classs name
  */
  public static function GetClassName(){
    return self::$code;
  }

  /**
    @brief Check result or return array ('&nbsp;',...)
  */
  public static function CheckResult($result){
    $li=$res=array();
    foreach($result as $item){
      foreach(call_user_func(array(self::$code, 'tep_get_modele')) as $k=>$v) $li[$k]=(tep_not_null($item[$k]) ? $item[$k] : '&nbsp;');
      $res[]=$li;
    }

    if(count($res)==0){
      foreach(call_user_func(array(self::$code, 'tep_get_modele')) as $k=>$v) $li[$k]= '&nbsp;';
      $res[]=$li;
    }
    return $res;
  }

  /**
    @brief public methode load value in db
  */
  public static function load_db_values($ID=''){

    call_user_func(array(self::$code, 'GetConf'));

    if(!empty($ID) && is_array($ID)) self::$InitInfo['adjust']=$ID;
    elseif(!empty($ID)) self::$InitInfo['adjust']=array_merge((array)self::$InitInfo['adjust'], array('ID'=>$ID) );

    return call_user_func(array(self::$code, 'GetDBValue'),$ID);
  }


  public static function ButtonRowsActions($item){
    $FileName=call_user_func(array(self::$code, 'GetFILENAME'));
    return  sprintf(CsrtAction::getFormat('row_action'),
		      '',
		      sprintf(CsrtAction::getLink('row_action_right', IMAGE_EDIT, 'edit'), '',  tep_href_link($FileName,  'iID=' . $item['id'] . '&amp;action=edit') ,'' ).
		      sprintf(CsrtAction::getLink('row_action_right', IMAGE_DELETE, 'delete'), 'fancy',  tep_href_link($FileName,  'iID=' . $item['id'] . '&amp;action=delete') ,'' )
		  );
  }



}


?>