<?php
 /***************************************************************************
 *   Copyright (C) 2008 by oscim   Project lossim                          *
 *   a@oscim.fr                                                            *
 *       [created : 14.03.2008, 17:53:41] @oscim                           *

 ***************************************************************************/
## PREPA Htaccess
$tmp=" # Fix certain PHP values
# (commented out by default to prevent errors occuring on certain
# servers)

## [modifie : 27.02.2008, 09:31:38] par a@oscim.fr Aurelien imhof
# AP URL Rewriting
RewriteEngine on
RewriteBase ".$_POST['chemin_du_site']."
RewriteRule ^(admin/.+)$ $1 [L]
RewriteRule ([0-9A-Za-z_&=-]*)(\.html)$  ?$1.html [L]
";
## PREPA Htaccess admin
$tmp_admin=" # Fix certain PHP values
# (commented out by default to prevent errors occuring on certain
# servers)

## [modifie : 27.02.2008, 09:31:38] par a@oscim.fr Aurelien imhof
# AP URL Rewriting
RewriteEngine on
RewriteBase ".$_POST['chemin_du_site']."/admin/

## prise en charge des page admin
RewriteCond %{REQUEST_URI}  admin.php [OR]
RewriteCond %{REQUEST_URI}  config_modules.php [OR]
RewriteCond %{REQUEST_URI}  creer_une_page.php [OR]
RewriteCond %{REQUEST_URI}  deconnexion.php [OR]
RewriteCond %{REQUEST_URI}  edit_config.php [OR]
RewriteCond %{REQUEST_URI}  edit_file_lang.php [OR]
RewriteCond %{REQUEST_URI}  edit_revision.php [OR]
RewriteCond %{REQUEST_URI}  edit_template.php [OR]
RewriteCond %{REQUEST_URI}  gestion_users.php [OR]
RewriteCond %{REQUEST_URI}  config_modules.php [OR]
RewriteCond %{REQUEST_URI}  menu.php [OR]
RewriteCond %{REQUEST_URI}  rubriques.php [OR]
RewriteCond %{REQUEST_URI}  modifier_un_fichier.php [OR]
RewriteCond %{REQUEST_URI}  module.php [OR]
# RewriteCond %{REQUEST_URI}  pop_insert_links.php [OR]
RewriteCond %{REQUEST_URI}  test.php [NC]
# RewriteCond %{REQUEST_URI}  xmedia.php [OR]
# RewriteCond %{REQUEST_URI}  xmedia_custom_img.php [OR]
# RewriteCond %{REQUEST_URI}  xmedia_full.php [NC]
RewriteRule ([0-9A-Za-z_&=-]*)(.php)?(.*)$  admin_central.php?page_admin=$1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_URI}  index.php [NC]
RewriteRule ([0-9A-Za-z_&=-]*)(.php)?(.*)$  login.php?%{QUERY_STRING} [L]
";
## Prepa Rss
$txt ='<?xml version="1.0" encoding="UTF-8"?>
  <rss version="2.0">
    <channel>
      <title>'.$_POST['nom_du_site'].'</title>
      <description>'.$_POST['slogan_du_site'].'</description>
      <link>'.$_POST['url_du_site'].'</link>
      <lastBuildDate>Tue, 22nd Apr 2008 19:04:39</lastBuildDate>
    </channel>
   </rss>
';
 $error='';
 ## Creation des fichie de confgig
 if (!file_exists("../admin/config/sys_config.php")){
 $handle=fopen("../admin/config/sys_config.php",'w');
 fclose($handle);
 @chmod($handle,0777);
 }
$files_uninstall="../admin/config/sys_uninstall.php";
 ## Creation des fichie de confgig
 if (!file_exists($files_uninstall)){
 $handle=fopen($files_uninstall,'w');
  fclose($handle);
  copy($_PX_config['chemin']."data/sys_uninstall.php-dist",$files_uninstall);
 @chmod($handle,0777);
 }
  if (!file_exists("../include/sys_config.php")){
  $handle=fopen("../include/sys_config.php",'w');
 fclose($handle);
 }
 ## Creation des fichie de confgig
 if (!file_exists("../admin/config/sys_path.php")){
copy($_PX_config['chemin']."data/admin_sys_path.php-dist","../admin/config/sys_path.php");
 }

  if (!file_exists("../include/sys_path.php")){
copy($_PX_config['chemin']."data/sys_path.php-dist","../include/sys_path.php");
 }
  $error='';
 if ($_POST['install']=='i') { // si onstal neuve

 	$handle=fopen("../admin/config/sys_index_lang.php",'w');	 fclose($handle);
	copy($_PX_config['chemin']."data/sys_index_lang.php-dist","../admin/config/sys_index_lang.php");

	$handle=fopen("../include/sys_tbl_sql.php",'w');	 fclose($handle);
	copy($_PX_config['chemin']."data/sys_tbl_sql.php-dist","../include/sys_tbl_sql.php");

	$handle=fopen("../include/lib_ext.php",'w');	 fclose($handle);
	copy($_PX_config['chemin']."data/lib_ext.php-dist","../include/lib_ext.php");

	$handle=fopen("../include/config/index_links.inc",'w');	 fclose($handle);
	copy($_PX_config['chemin']."data/index_links.inc-dist","../include/config/index_links.inc");

	$handle=fopen("../include/config/module_dependance.inc",'w');	 fclose($handle);
	copy($_PX_config['chemin']."data/module_dependance.inc-dist","../include/config/module_dependance.inc");

	$handle=fopen("../include/config/lib_int_contraintes.inc",'w');	 fclose($handle);
	copy($_PX_config['chemin']."data/lib_int_contraintes.inc-dist","../include/config/lib_int_contraintes.inc");

	$handle=fopen("../include/config/lib_interne.inc",'w'); fclose($handle);
	copy($_PX_config['chemin']."data/lib_interne.inc-dist","../include/config/lib_interne.inc");

	$handle=fopen("../include/config/tbl_parserbalise.inc",'w'); fclose($handle);
	copy($_PX_config['chemin']."data/tbl_parserbalise.inc-dist","../include/config/tbl_parserbalise.inc");

	$handle=fopen("../include/config/config_general.inc",'w');	 fclose($handle);
	copy($_PX_config['chemin']."data/config_general.inc-dist","../include/config/config_general.inc");

 	if ( (!empty($_POST['activ_rss']))AND (PHP>5) ) {
		## BASE RSS
		 $handle=fopen("../rss/feeds.xml",'w');
		 fwrite($handle, $txt);
		 fclose($handle);
	}
	if (!empty($_POST['activ_htaccess'])) {
		## BASE HTACCESS + REWRTITE
		$handle=fopen(".htaccess",'w');
		fwrite ($handle, $tmp);
		fclose($handle);
		## BASE HTACCESS + REWRTITE
		$handle=fopen("../admin/.htaccess",'w');
		fwrite ($handle, $tmp_admin);
		fclose($handle);
	}
	if ( (!empty($_POST['activ_mod']))  ){
		$handle=fopen("../include/sys_config_modules.php",'w');
		fclose($handle);
		copy($_PX_config['chemin']."data/sys_config_modules.php-dist","../include/sys_config_modules.php");
	 }
	  $handle=fopen("../include/config/lang.inc",'w+');
	 fclose($handle);
	 copy($_PX_config['chemin']."data/lang.php-dist","../include/config/lang.inc");
 ## CREATION REP LANG
	 include('data/lang.php-dist');
	$cp_nbr_lang=0;
	$handle_lg=fopen("../include/config/lang.inc",'w+');
	fwrite ($handle_lg, "<?php\n");
	while ($r=each($lg)) {
		if ($_POST['choix_lang']==$r['key']) {
			if ( (!file_exists('../xml/'.$r['key']))AND(mkdir('../xml/'.$r['key'], 0777)) ) print '<p class="preinstall">'.ALERT_DIR." /xml/".$r['key']."/</p>";
			## AJout d'une page sommaire de base
		  	$handle=fopen('../xml/'.$r['key'].'/sommaire.xml','w+');
		 	fclose($handle);
		 	copy($_PX_config['chemin']."data/exemple.xml-dist",'../xml/'.$r['key'].'/sommaire.xml');
			## renseignement du fichier d'index !!!!
			$cp_nbr_lang++;
			## construct tableau de langue disponible sur sytheme
			fwrite ($handle_lg, "\$lg['".$r['key']."']['txt']='".$r['value']['txt']."'; \n ");
			fwrite ($handle_lg, "\$lg['".$r['key']."']['lang']='".$r['value']['lang']."'; \n ");
		}
	}
	fwrite ($handle_lg, "\n?>");
	fclose($handle_lg);

}


$tit=$det=$error_mess='';
if( (file_exists("../admin/config/sys_config.php")) AND (file_exists("../include/sys_config.php")) ) {
	if(is_writable("../admin/config/sys_config.php") OR OS_DU_SERVEUR == "windows") {

		copy("data/admin_sys_config.php-dist","../admin/config/sys_config.php");

		$error = false;
		$error_mess = '';

	$_POST['nom_du_site']=utf8_encode($_POST['nom_du_site']) ;
	$_POST['slogan_du_site']=utf8_encode($_POST['slogan_du_site']) ;

		$cfg_admin = new configfile('../admin/config/sys_config.php');
		$cfg_admin->prefix = '_PX_config';

	$cfg_admin->editVar('os_serveur',OS_DU_SERVEUR);

	if (!empty($_POST['url_du_site'])) $cfg_admin->editVar('url_du_site',(string)$_POST['url_du_site']);
	if (!empty($_POST['chemin_du_site'])) $cfg_admin->editVar('chemin_du_site',(string)$_POST['chemin_du_site']);
	$cfg_admin->editVar('url_admin',(string)$_POST['url_du_site']."admin/");
	 $cfg_admin->editVar('chemin_admin',(string)$_POST['chemin_du_site']."admin/");
	if (!empty($_POST['nom_du_site'])) $cfg_admin->editVar('nom_du_site',(string)utf8_encode($_POST['nom_du_site']));
	if (!empty($_POST['select_template'])) $cfg_admin->editVar('nom_du_theme',(string)utf8_encode($_POST['select_template']));
	if (!empty($_POST['base_css'])) $cfg_admin->editVar('nom_styles_css',(string)utf8_encode($_POST['base_css']));



			if (!$cfg_admin->saveFile()) {
				 $error_mess .= 'Error: Impossible to create the configuration file. pour \$cfg_admin';
				$error = true;
			}
			else  $error_mess .= 'Ok. pour cfg_admin <br /> ';

	} else { $tit=NOT_WRITE; $det=NOT_WRITE_DETAIL; }
echo "<h2>$tit</h2>\n<p>$det</p>\n<p>$error_mess</p>\n";

	if(is_writable("../include/sys_config.php") OR OS_DU_SERVEUR == "windows") {
		copy("data/sys_config.php-dist","../include/sys_config.php");

		$error = false;
		$error_mess = '';

		$cfg_public = new configfile('../include/sys_config.php');

	$cfg_public->prefix = '_PX_config';


	if (!empty($_POST['mail_webm'])) $cfg_public->editVar('email_webmaster',$_POST['mail_webm']);
	if (!empty($_POST['mail_contact'])) $cfg_public->editVar('email_contact',(string)$_POST['mail_contact']);
	if (!empty($_POST['url_du_site'])) $cfg_public->editVar('url_du_site',(string)$_POST['url_du_site']);
	if (!empty($_POST['chemin_du_site'])) $cfg_public->editVar('chemin_du_site',(string)$_POST['chemin_du_site']);
	if (!empty($_POST['nom_du_site'])) $cfg_public->editVar('nom_du_site',(string)utf8_encode($_POST['nom_du_site']));
	if (!empty($_POST['slogan_du_site'])) $cfg_public->editVar('slogan_du_site',(string)utf8_encode($_POST['slogan_du_site']));
	if (!empty($_POST['select_template'])) $cfg_public->editVar('nom_du_theme',(string)utf8_encode($_POST['select_template']));
	if (!empty($_POST['base_css'])) $cfg_public->editVar('nom_styles_css',(string)utf8_encode($_POST['base_css']));
// 	if (!empty($_POST['activ_rss'])) {


	if ( (!empty($_POST['activ_rss']))AND (PHP>5) )
		## BASE RSS
		 $cfg_public->editVar('rss','true');

	if (!empty($_POST['activ_htaccess']))
		## BASE HTACCESS + REWRTITE
		$cfg_public->editVar('url_format',(string)'mod_rewrite');

	if ( (!empty($_POST['activ_mod'])) AND  (!file_exists("../include/sys_config_modules.php")) )
		$cfg_public->editVar('modules','true');


	if (!$cfg_public->saveFile()) {
		 $error_mess .= 'Error: Impossible to create the configuration file. pour cfg_public';
		$error = true;
	} else  $error_mess .= 'Ok. pour cfg_public ';

	} else { $tit=NOT_WRITE; $det=NOT_WRITE_DETAIL; }
}else { $tit=NOT_EXIST; $det=NOT_EXIST_DETAIL; }
echo "<h2>$tit</h2>\n<p>$det</p>\n<p>$error_mess</p>\n";
$tit=$det=$error_mess='';
if( (file_exists("../admin/config/sys_path.php")) AND (file_exists("../include/sys_path.php")) ) {
	if(is_writable("../admin/config/sys_path.php") OR OS_DU_SERVEUR == "windows") {
		$error = false;
		$error_mess = '';
		$cfg_admin = new configfile('../admin/config/sys_path.php');
		$cfg_admin->prefix = '_PX_config';
	$cfg_admin->editVar('url_du_site',(string)$_POST['url_du_site']);
	$cfg_admin->editVar('chemin_du_site',(string)$_POST['chemin_du_site']);
	$cfg_admin->editVar('url_admin',(string)$_POST['url_du_site']."admin/");
	$cfg_admin->editVar('chemin_admin',(string)$_POST['chemin_du_site']."admin/");
	if (!$cfg_admin->saveFile()) {
		 $error_mess .= 'Error: Impossible to create the configuration file. pour cfg_path_admin';
		$error = true;
	}else  $error_mess .= 'Ok. pour cfg_path_admin <br /> ';
	} else { $tit=NOT_WRITE; $det=NOT_WRITE_DETAIL; }
	echo "<h2>$tit</h2>\n<p>$det</p>\n<p>$error_mess</p>\n";

	if(is_writable("../include/sys_path.php") OR OS_DU_SERVEUR == "windows") {
	$error = false;
	$error_mess = '';
	$cfg_public = new configfile('../include/sys_path.php');
	$cfg_public->prefix = '_PX_config';
	$cfg_public->editVar('url_du_site',(string)$_POST['url_du_site']);
	$cfg_public->editVar('chemin_du_site',(string)$_POST['chemin_du_site']);
	if (!$cfg_public->saveFile()) {
		 $error_mess .= 'Error: Impossible to create the configuration file. pour cfg_path_public';
		$error = true;
	} else  $error_mess .= 'Ok. pour cfg_path_public ';
	} else { $tit=NOT_WRITE; $det=NOT_WRITE_DETAIL; }
}else { $tit=NOT_EXIST; $det=NOT_EXIST_DETAIL; }
echo "<h2>$tit</h2>\n<p>$det</p>\n<p>$error_mess</p>\n";



?>
<form name='formt' enctype="multipart/form-data" action='setup.php?etape=2' Method='POST'>
	<?php post_hidden($_POST) ?>
	<?php if($error == false) print"<input type='hidden' name='success_base' value='1' />";?>
	<input type='submit' name='boutton' value='La Suite'>
</form>