<?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  14/11/10, 15:13
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/
?>
<!-- body //-->
<h3><?php echo HEADING_TITLE; ?></h3>
<div class="box_left">
<!-- body_text //-->
  <table style="width:100%" class="dataTable2">
    <thead>
      <tr>
        <th><?php echo TABLE_HEADING_MODULES; ?></th>
        <th class="tcenter">
          <table style="width:100%">
            <tr >
              <th class="tcenter" colspan="<?php echo count($code_inistalletd_array); ?>"><?php echo TABLE_HEADING_STATUS; ?></th>
            </tr>
            <tr>
              <?php foreach($code_inistalletd_array as $k2=>$v2):?>
              <th style="width:70px"><?php echo $k2 ?></th>
              <?php endforeach; ?>
            </tr>
          </table>
        </th>
        <th><?php echo TABLE_HEADING_ACTION; ?></th>
      </tr>
    </thead>
    <tbody>
<?php
  $installed_modules = array();
  $repliq=$code_inistalletd_array;

  /**
    Boucle sur les modules trouvé dans les repertoire public et admin
  */
  foreach($modules_full  as $key2=>$vae2){
    $class = $key2;
    $class_s="";

    /**
      Charge la class
      1 class par modules
    */
    if  (isset($_GET['class']) && $class==$_GET['class']) {
        if(is_array($repliq[$set])){
        $v2=$repliq[$set];

        if(file_exists(DIR_FS_ADMIN.DIR_WS_MODULES.$v2['module_directory'].$class.'.php')){
          $module_directory=DIR_FS_ADMIN.DIR_WS_MODULES.$v2['module_directory'];
          $module_language=(isset($v2['module_language'])? $v2['module_language'].$language.'/modules/'.$set.'/':DIR_FS_CATALOG_LANGUAGES.$language.'/modules/'.$set.'/' );
        }elseif(file_exists(DIR_FS_CATALOG_MODULES.$v2['module_directory'].$class.'.php') /*&& !in_array($v2['module_directory'],array('listing/','shipping/','order_total/','payment/'))*/){
          $module_directory=DIR_FS_CATALOG_MODULES.$v2['module_directory'];
          $module_language=(isset($v2['module_language'])? $v2['module_language'].$language.'/modules/'.$set.'/':DIR_FS_CATALOG_LANGUAGES.$language.'/modules/'.$set.'/' );
        }

      }
      reset($repliq);
      if(file_exists($module_language.$class.'.php')) include_once($module_language.$class.'.php');
      require_once($module_directory.$class.'.php');

      if (tep_class_exists($class)) {
        $module = new $class;

        if(!$module->check()){
          $module->remove();
          $module->install();
        }


        $module_keys = $module->keys();
        $keys_extra = array();
        for ($j=0, $k=sizeof($module_keys); $j<$k; $j++) {
          $key_value_query = tep_db_query("select configuration_title, configuration_value, configuration_description, use_function, set_function from " . TABLE_CONFIGURATION . " where configuration_key = '" . $module_keys[$j] . "'");
          $key_value = tep_db_fetch_array($key_value_query);

          $keys_extra[$module_keys[$j]]['title'] = $key_value['configuration_title'];
          $keys_extra[$module_keys[$j]]['value'] = $key_value['configuration_value'];
          $keys_extra[$module_keys[$j]]['description'] = $key_value['configuration_description'];
          $keys_extra[$module_keys[$j]]['use_function'] = $key_value['use_function'];
          $keys_extra[$module_keys[$j]]['set_function'] = $key_value['set_function'];
        }

        $module_info['title'] = $module->title;
        $module_info['status'] = $module->check();
        $module_info['description'] = $module->description ;
        $module_info['code'] = $module->code;
        $module_info['keys'] = $keys_extra;
        $mInfo = new objectInfo($module_info);
      }

      if (isset($mInfo) && is_object($mInfo) && ($class == $mInfo->code) ) $class_s=" Selected";
    }
?>
          <tr class="view parent dataTableRow <?php echo $class_s ?>">
            <td><?php echo $class; ?></td>
            <td>
 <table style="width:100%">
            <tr >
              <?php foreach($repliq as $k2=>$v2):  ?>
                  <td style="width:70px" class='tcenter'>
                  <?php if (isset($modules_array[$k2][$class]['path'])):  $set_view=$k2;  ?>
                    <?php echo '[FO] '.status_flag(in_array($modules_array[$k2][$class]['file'],explode(';',$v2['value'])),'manager='.$manager.'&amp;action=setflag&amp;set='.$k2.'&amp;class='.$class); ?>
                    <?php if(!isset($modules_array[$k2][$class]['path_BO'])): ?>
                      <span class="view fils fleft"><?php echo ' <a class="buttonimg" href="' . tep_href_link(FILENAME_MODULES, 'manager='.$manager.'&amp;set='.$k2.'&amp;class='.$class . '&amp;action=edit' ) . '">' .  tep_image(DIR_WS_ICONS . 'icon_edit.png', IMAGE_EDIT ) . '</a>'; ?></span>
                    <?php endif; ?>
                  <?php endif; if(isset($modules_array[$k2][$class]['path_BO'])): $set_view=$k2; ?>
                    <br /><br /><?php echo '[BO] '.status_flag(in_array($modules_array[$k2][$class]['file'],explode(';',$v2['value_BO'])) ,'manager='.$manager.'&amp;action=setflag&amp;set='.$k2.'&amp;class='.$class.'&amp;core=BO'); ?>
                    <span class="view fils fleft"><?php echo ' <a class="buttonimg" href="' . tep_href_link(FILENAME_MODULES, 'manager='.$manager.'&amp;set='.$k2.'&amp;class='.$class . '&amp;action=edit'.'&amp;core=BO') . '">' .  tep_image(DIR_WS_ICONS . 'icon_edit.png', IMAGE_EDIT ) . '</a>'; ?></span>
                  <?php endif; ?>
                </td>
              <?php /*}*/ endforeach; ?>
                </tr>
                </table>
              </td>
              <td><?php echo '<a href="' . tep_href_link(FILENAME_MODULES,'manager='.$manager.'&amp;set='.$set_view.'&amp;class='.$class.'&amp;action=view' ) . '">' . tep_image(DIR_WS_ICONS . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>';  ?></td>
              </tr>
  <?php } ?>
      </tbody>
    </table>
</div>

<div class="box_right">
<?php
  $heading = array();
  $contents = array();

  switch ($action) {
    case 'edit':
    if(!isset($_GET['core']))@include_once(DIR_FS_CATALOG_LANGUAGES . $language . '/modules/' . $_GET['set'] . '/' . $modules_array[$_GET['set']][$_GET['class']]['file']);
    elseif(!@include_once(DIR_FS_ADMIN.DIR_WS_LANGUAGES . $language . '/modules/' . $_GET['set'] . '/' . $modules_array[$_GET['set']][$_GET['class']]['file']))@include_once(DIR_FS_CATALOG_LANGUAGES . $language . '/modules/' . $_GET['set'] . '/' . $modules_array[$_GET['set']][$_GET['class']]['file']);

    if(!isset($_GET['core'])) require_once($modules_array[$_GET['set']][$_GET['class']]['path'].$modules_array[$_GET['set']][$_GET['class']]['file']);
    else require_once($modules_array[$_GET['set']][$_GET['class']]['path_BO'].$modules_array[$_GET['set']][$_GET['class']]['file']);


      $module = new $_GET['class'];

      if(!$module->check()){
          $module->remove();
          $module->install();
      }

      $module_info = array('code' => $module->code,
                      'title' => $module->title,
                      'description' => $module->description,
                      'status' => $module->check());
      $keys = '';
       $module_keys = $module->keys();

        $keys_extra = array();
        for ($j=0, $k=sizeof($module_keys); $j<$k; $j++) {
          $key_value_query = tep_db_query("select configuration_title, configuration_value, configuration_description, use_function, set_function from " . TABLE_CONFIGURATION . " where configuration_key = '" . $module_keys[$j] . "'");
          $key_value = tep_db_fetch_array($key_value_query);

          $keys_extra[$module_keys[$j]]['title'] = $key_value['configuration_title'];
          $keys_extra[$module_keys[$j]]['value'] = $key_value['configuration_value'];
          $keys_extra[$module_keys[$j]]['description'] = $key_value['configuration_description'];
          $keys_extra[$module_keys[$j]]['use_function'] = $key_value['use_function'];
          $keys_extra[$module_keys[$j]]['set_function'] = $key_value['set_function'];
        }

        $module_info['keys'] = $keys_extra;

        $mInfo = new objectInfo($module_info);

      $keys = configUtility::FormatEditAuto(array('array'=>$keys_extra));

      $heading[] = array('text' => '['.$_GET['set'].']'.$mInfo->title );

      $contents = array('form' => tep_draw_form('modules', FILENAME_MODULES, 'manager='.$manager.'&amp;set='.$set_view.'&amp;class='.$class.'&amp;action=save'));
      $contents[] = array('class' => 'block_input','text' => $keys);
      $contents[] = array('class' => 'button_nav', 'text' => tep_image_submit('button_update.gif', IMAGE_UPDATE) . ' <a class="button" href="' . tep_href_link(FILENAME_MODULES) . '">' .  IMAGE_CANCEL . '</a>');
    break;
    default:
      if(isset($mInfo) && is_object($mInfo)) {
        $heading[] = array('text' => $mInfo->title );

        if ($mInfo->status == '1') {
          $keys = '';
          reset($mInfo->keys);
          while (list(, $value) = each($mInfo->keys)) {
            $keys .= '<strong>' . $value['title'] . '</strong><br />';
            if ($value['use_function']) {
              $use_function = $value['use_function'];
              $set_function =(isset($value['set_function'])) ? $value['set_function'] : $class_method[1];
              if (preg_match('/->/', $use_function)) {
                $class_method = explode('->', $use_function);
                if ( isset(${$class_method[0]}) && !is_object(${$class_method[0]})) {
                  include_once(DIR_WS_CLASSES . $class_method[0] . '.php');
                  ${$class_method[0]} = new $class_method[0]();
                }
                $keys .= tep_call_function($set_function, $value['value'], ${$class_method[0]});
              } else {
                $keys .= tep_call_function($use_function, $value['value']);
              }
            } else {
              $keys .= $value['value'];
            }
            $keys .= '<br /><br />';
          }
          $keys = substr($keys, 0, strrpos($keys, '<br /><br />'));

          $contents[] = array('text' => $mInfo->description);
          $contents[] = array('text' => $keys);
        } else {
          $contents[] = array('text' => $mInfo->description);
        }
      }
      break;
  }

  if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
    $box = new box;
    echo $box->infoBox($heading, $contents);
  }
?>
</div>
<!-- body_text_eof //-->
<!-- body_eof //-->