<?php
/**
  @licence GPL 2005-2010  The osCSS developers - osCSS Open Source E-commerce
  @package oscss-2 <www http://www.oscss.org>
  @version Rc-3
  @date  19/05/10, 09:10
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @author Ayatus <www http://www.ayatus.org>
  @encode UTF-8
*/



class base extends core {

  function definition(){

/** tableau des répertoires et fichiers contrôlés */
    $this->ctr=array(
               'conf_public'=>'includes/configure.php',
               'conf_admin'=>'admin/includes/configure.php',
//                'conf_db_admin'=>'admin/includes/database_tables.php',
//                'conf_f_admin'=>'admin/includes/filenames.php',
               'htacces_admin'=>'admin/.htaccess',
               'admin_back'=>'admin/backups/',
               'admin_cip'=>'admin/contributions/',
               'admin_image'=>'admin/images/',
               'admin_graph'=>'admin/images/graphs/',
               'admin_image'=>'admin/images/imagecache/',
               'admin_mod_a'=>'admin/includes/modules/account/',
               'admin_mod_c'=>'admin/includes/modules/categories/',
               'admin_mod_g'=>'admin/includes/modules/generic/',
               'admin_mod_p'=>'admin/includes/modules/products/',
               'admin_tmp'=>'admin/includes/tmp/',
               'admin_tmp_cache'=>'admin/includes/tmp/cache/',
               'admin_sessions'=>'admin/sessions/',
               'common'=>'common/',
               'common_classes'=>'common/classes/',
               'download'=>'download/',
               'images'=>'images/',
               'images'=>'images/imagecache/',
               'mod_a'=>'includes/modules/account/',
               'mod_g'=>'includes/modules/generic/',
               'mod_l'=>'includes/modules/listing/',
               'mod_o'=>'includes/modules/order_total/',
               'mod_py'=>'includes/modules/payment/',
               'mod_p'=>'includes/modules/products/',
               'mod_s'=>'includes/modules/shipping/',
               'oscss_data'=>'oscss_data/',
               'pub'=>'pub/',
               'sessions'=>'sessions/',
               'templates'=>'templates/'
              );




  }

  function draw_form_lang(){
    // Show available languages
    asort($this->available_languages);
    echo
    '<form id="language_form" action="" method="get">'."\n".
    '<p class="language">'.core::l10n('Language')."\n".
    '<select name="language" onchange="document.location = \''.basename($_SERVER['SCRIPT_NAME']).'?language=\'+this.options[this.selectedIndex].value;">'."\n";
    foreach ($this->available_languages as $language_code => $language_name)
    {
        echo '<option label="'.$language_name.'" value="'.$language_code.'" '.($language_code == DC_LOADER_LANG ? 'selected="selected"' : '').'>'.$language_name.'</option>'."\n";
    }
    echo '</select>'."\n"
    .'<input type="submit" id="langBt" class="submitBt" name="langBt" value="'.core::l10n('Valider').'" />'."\n"
    .'</p>'."\n".'</form>'."\n";

  }


  function draw_form(){
    if(!$this->err) :
    $this->PileMessage('succes',core::l10n("Tout est correct"));
    $this->writeMessage();
    echo '<form id="install" action="?etape='.$this->get_current_etape(1).'" method="post">'."\n";
    echo $this-> draw_button(true);
    $this->repet_post();
    echo '</form>'."\n";
    else :
    $this->PileMessage('alert',core::l10n("Corriger ces alertes pour continuer l'installation"));
    $this->writeMessage();
    endif;
  }


  function draw_message(){
    $path='../';
    $this->err=false;

   /** Contrôle écriture possible pour la suite */
    while ($r=each($this->ctr)){
        $type= (preg_match("#/$#i",$r['value'])) ?'rep' : 'file';
	if(!isset($_POST['WS_STORE_ADMIN']) && !empty($_POST['WS_STORE_ADMIN']))$r['value']=str_replace('admin', $_POST['WS_STORE_ADMIN'],$r['value']);
        if ($type=='file'){
            if (file_exists($path.$r['value'])) {
                if (!is_writable($path.$r['value'])){
                    $this->PileMessage('alert',core::l10n("Le fichier n'est pas accessible en écriture : ").$r['value']) ;
                    $this->err=true;
                }
            }else {
                $rep=preg_replace("#[a-z]*\.[a-z]*#i",'',$r['value']);
                if (!is_writable($path.$rep)){
                    $this->PileMessage('alert',core::l10n("Le répertoire n'est pas accessible en écriture : ").$rep);
                    $this->err=true;
                }
            }
        } else {
            chdir($path);
            if(!is_dir($r['value']) && !@mkdir($r['value'],0777)){
                $this->PileMessage('alert',core::l10n("Le répertoire n'existe pas et ne peut être créé : "). $r['value']);
                $this->err=true;
            }elseif (!is_writable($r['value'])){
               $this->PileMessage('alert',core::l10n("Le répertoire n'existe pas et ne peut être créé : "). $r['value']);
                $this->err=true;
            }
            chdir('install/');
        }
        unset($type);
    }

  }


  function draw(){
    $this->definition();
    if(!isset($_GET['language'])) $this->draw_form_lang();

    /**
      Recup courante configure
    */
    if($this->update_shop() == true){
    $this->get_server_conf();

      foreach($this->browse_rep($this->fs_document_root) as $item)
      if(is_dir($this->fs_document_root.$item['file'])&& preg_match('#(admin.*)#i',$item['file'] , $match)){
	$_POST['WS_STORE_ADMIN']=$item['file'];
      }
    }


    $this->draw_message();

    $this->draw_form();
  }
}
?>