<?php
/*******************************************************************************
 *   Functions Install
 *******************************************************************************
 *   GuppY PHP Script - version 6.0
 *   CeCILL Copyright (C) 2004-2020 by Laurent Duveau
 *   Initiated by Laurent Duveau and Nicolas Alves
 *   Web site = https://www.freeguppy.org/
 *   e-mail   = guppy@freeguppy.org
 *   V6 developed by Lud Bienaimé
 *      with the participation of the GuppY Team
 *******************************************************************************
 *   Latest Changes :
 * v6.00.00 (December 15, 2020) : initial release
 ******************************************************************************/

if (stristr($_SERVER['SCRIPT_NAME'], 'func_install.php')) {
  header('location:../index.php');
  die();
}

function DisplayHeader($refreshUrl = NULL) {
	global $meskin, $clean, $charset;
	echo '
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>'.$clean[1].'</title>
<meta http-equiv="content-type" content="text/html; charset='.$charset.'" />';
    if (isset($refreshUrl) && '' != $refreshUrl) {
        echo '
<meta http-equiv="Refresh" content="2;URL='.str_replace('&', '&amp;', $refreshUrl).'">';
    }
	if (file_exists($meskin."style.css")) {
		echo '
<link type="text/css" rel="stylesheet" href="'.$meskin.'style.css" />';
	}
	else {
		echo '
<link type="text/css" rel="stylesheet" href="no_skin/style.css" />';
	}
	echo '
<link rel="stylesheet" href="'.CHEMIN.'inc/lang/flags.css" />
<link rel="stylesheet" href="'.CHEMIN.'inc/img/general/general.css" />
</head>
<body bgcolor="#FFFFFF">
<p style="text-align:center;"><i class="gen-gylogo"></i></p>';
}

function DisplayFooter() {
	echo '
<p style="text-align:center;">&nbsp;</p>
<p style="text-align:center;">GuppY v'.MP_VERSION.'<br />CeCILL free Licence - © '.MP_COPYRIGHT.'</p>
</body>
</html>';
}

function DisplayTitre($titre, $texte) {
	echo '
<div style="text-align:center;"><h3>'.$titre.'</h3></div>
<div style="width:1024px;margin:auto;">
  <table style="width:90%;margin:auto;">
    <tr>
	  <td class="quest"><br />'.$texte.'<br /></td>
	</tr>
  </table>
</div>
<br />';
}

function DisplayProcess($titre, $processus, $resultat) {
	DisplayTitre($titre, $processus);
	echo '
<p style="text-align:center;">&nbsp;</p>
<table style="width:480px;margin:auto;">
  <tr><td bgcolor="#FF9933" style="padding-left:10px;"><br />'.$resultat.'<br /></td></tr>
</table>';
}

function EraseInstall() {
	$dossier = opendir(CHEMIN.'install/');
	while ($fichier = readdir($dossier)) {
		if (is_file(CHEMIN.'install/'.$fichier)) {
			SetChmod(CHEMIN.'install/'.$fichier);
			@unlink(CHEMIN.'install/'.$fichier);
		}
	}
	closedir($dossier);
	SetChmod(CHEMIN.'install');
	SetChmod(CHEMIN.'install');
	@rmdir(CHEMIN.'install');
	if (file_exists(CHEMIN.'data/chk_install.dtb')) {
		SetChmod(CHEMIN.'data/chk_install.dtb');
		@unlink(CHEMIN.'data/chk_install.dtb');
	}
	if (file_exists(CHEMIN.'data/config/chk_install.dtb')) {
		SetChmod(CHEMIN.'data/config/chk_install.dtb');
		@unlink(CHEMIN.'data/config/chk_install.dtb');
	}
}

function CleanDataRep() {
	set_time_limit(0);
	
	RecursiveDeleteDir(CACHEREP);
	RecursiveDeleteDir(DOCSREP);
	RecursiveDeleteDir(STATSREP);
	$files = scandir(PHOTOREP);
	foreach ($files as $file) {
		if (substr($file, 0, 4) == 'gal_') {
			RecursiveRemoteDir(PHOTOREP.$file); 
		}
	}
}

function CreateInitStruct($meskin) {
    $mettre = '<?php
if (stristr($_SERVER["SCRIPT_NAME"], "confweb.inc")) {
    header("location:../index.php");
    die();
}

$site[4]  = stripslashes("1");  // Nouvelles sur la page d\'accueil
$site[20] = stripslashes("2"); // Messages Forum sur la page d\'accueil
// site[21] = stripslashes(""); // Inutilisé
$site[29] = stripslashes("80"); // Hauteur en pixels des nouvelles en page d\'accueil
$site[33] = stripslashes("80"); // Hauteur en pixels des billets en page d\'accueil
$site[34] = stripslashes("80"); // Hauteur en pixels des posts du forum en direct
$site[31] = stripslashes("1"); // Billets du blog sur la page d\'accueil

$serviz[28]  = stripslashes("on");  // Préférences visiteurs
$serviz[38]  = stripslashes("on");  // RSS News ON / OFF
$serviz[74]  = stripslashes("on"); // Cacher les boîtes en page d\'accueil

// Configurations accueil et pages secondaires
// $xposbox["E"][LS]
$xposbox["E"]["LS"][0] = stripslashes("");
$xposbox["E"]["LS"][1] = stripslashes("");
$xposbox["E"]["LS"][2] = stripslashes("");

// $xposbox["E"][L]
$xposbox["E"]["L"][0] = stripslashes("");
$xposbox["E"]["L"][1] = stripslashes("");
$xposbox["E"]["L"][2] = stripslashes("");

// $xposbox["E"][C]
$xposbox["E"]["C"][0] = stripslashes("");
$xposbox["E"]["C"][1] = stripslashes("");
$xposbox["E"]["C"][2] = stripslashes("");

// $xposbox["E"][R]
$xposbox["E"]["R"][0] = stripslashes("");
$xposbox["E"]["R"][1] = stripslashes("");
$xposbox["E"]["R"][2] = stripslashes("");

// $xposbox["E"][RS]
$xposbox["E"]["RS"][0] = stripslashes("");
$xposbox["E"]["RS"][1] = stripslashes("");
$xposbox["E"]["RS"][2] = stripslashes("");

// $xposbox["B"][L]
$xposbox["B"]["L"][0] = stripslashes("||fbox_blogcat");
$xposbox["B"]["L"][1] = stripslashes("||fbox_bloglast");
$xposbox["B"]["L"][2] = stripslashes("||fbox_blogcom");
$xposbox["B"]["L"][3] = stripslashes("||fbox_blogcal");
$xposbox["B"]["L"][4] = stripslashes("");
$xposbox["B"]["L"][5] = stripslashes("");

// $xposbox["B"][R]
$xposbox["B"]["R"][0] = stripslashes("");
$xposbox["B"]["R"][1] = stripslashes("");
$xposbox["B"]["R"][2] = stripslashes("");
$xposbox["B"]["R"][3] = stripslashes("");
$xposbox["B"]["R"][4] = stripslashes("");
$xposbox["B"]["R"][5] = stripslashes("");

// NE PAS SUPPRIMER $templates[0]
$templates[0] = stripslashes("Principale");
//////////////////// Principale ////////////////////
// $xposbox[Principale][L]
$xposbox[0]["L"][0] = stripslashes("");
$xposbox[0]["L"][1] = stripslashes("");
$xposbox[0]["L"][2] = stripslashes("");
$xposbox[0]["L"][3] = stripslashes("");
$xposbox[0]["L"][4] = stripslashes("");
$xposbox[0]["L"][5] = stripslashes("");
$xposbox[0]["L"][6] = stripslashes("");
$xposbox[0]["L"][7] = stripslashes("");
$xposbox[0]["L"][8] = stripslashes("");

// $xposbox[Principale][R]
$xposbox[0]["R"][0] = stripslashes("");
$xposbox[0]["R"][1] = stripslashes("");
$xposbox[0]["R"][2] = stripslashes("");
$xposbox[0]["R"][3] = stripslashes("");
$xposbox[0]["R"][4] = stripslashes("");
$xposbox[0]["R"][5] = stripslashes("");
$xposbox[0]["R"][6] = stripslashes("");
$xposbox[0]["R"][7] = stripslashes("");
$xposbox[0]["R"][8] = stripslashes("");

// $xposbox[Principale][A]
$xposbox[0]["A"][0] = stripslashes("");
$xposbox[0]["A"][1] = stripslashes("");

// $xposbox[Principale][U]
$xposbox[0]["U"][0] = stripslashes("");
$xposbox[0]["U"][1] = stripslashes("");

// $xposbox[Principale][T][LS]
$xposbox[0]["T"]["LS"][0] = stripslashes("||fbox_empty||W3");
$xposbox[0]["T"]["LS"][1] = stripslashes("");
$xposbox[0]["T"]["LS"][2] = stripslashes("");
$xposbox[0]["T"]["LS"][3] = stripslashes("");
$xposbox[0]["T"]["LS"][4] = stripslashes("");

// $xposbox[Principale][T][L]
$xposbox[0]["T"]["L"][0] = stripslashes("");
$xposbox[0]["T"]["L"][1] = stripslashes("");
$xposbox[0]["T"]["L"][2] = stripslashes("");
$xposbox[0]["T"]["L"][3] = stripslashes("");
$xposbox[0]["T"]["L"][4] = stripslashes("");

// $xposbox[Principale][T][C]
$xposbox[0]["T"]["C"][0] = stripslashes("||fbox_empty||W4");
$xposbox[0]["T"]["C"][1] = stripslashes("");
$xposbox[0]["T"]["C"][2] = stripslashes("");
$xposbox[0]["T"]["C"][3] = stripslashes("");
$xposbox[0]["T"]["C"][4] = stripslashes("");

// $xposbox[Principale][T][R]
$xposbox[0]["T"]["R"][0] = stripslashes("");
$xposbox[0]["T"]["R"][1] = stripslashes("");
$xposbox[0]["T"]["R"][2] = stripslashes("");
$xposbox[0]["T"]["R"][3] = stripslashes("");
$xposbox[0]["T"]["R"][4] = stripslashes("");

// $xposbox[Principale][T][RS]
$xposbox[0]["T"]["RS"][0] = stripslashes("||fbox_sidemenu||W5");
$xposbox[0]["T"]["RS"][1] = stripslashes("");
$xposbox[0]["T"]["RS"][2] = stripslashes("");
$xposbox[0]["T"]["RS"][3] = stripslashes("");
$xposbox[0]["T"]["RS"][4] = stripslashes("");

// $xposbox[Principale][B][LS]
$xposbox[0]["B"]["LS"][0] = stripslashes("");
$xposbox[0]["B"]["LS"][1] = stripslashes("");
$xposbox[0]["B"]["LS"][2] = stripslashes("");

// $xposbox[Principale][B][L]
$xposbox[0]["B"]["L"][0] = stripslashes("");
$xposbox[0]["B"]["L"][1] = stripslashes("");
$xposbox[0]["B"]["L"][2] = stripslashes("");

// $xposbox[Principale][B][C]
$xposbox[0]["B"]["C"][0] = stripslashes("");
$xposbox[0]["B"]["C"][1] = stripslashes("");
$xposbox[0]["B"]["C"][2] = stripslashes("");

// $xposbox[Principale][B][R]
$xposbox[0]["B"]["R"][0] = stripslashes("");
$xposbox[0]["B"]["R"][1] = stripslashes("");
$xposbox[0]["B"]["R"][2] = stripslashes("");

// $xposbox[Principale][B][RS]
$xposbox[0]["B"]["RS"][0] = stripslashes("");
$xposbox[0]["B"]["RS"][1] = stripslashes("");
$xposbox[0]["B"]["RS"][2] = stripslashes("");

?>
';
    WriteFullDB($meskin.'confweb.inc', $mettre);
}

function PrepareDataRep() {
    include CONFIG;
	set_time_limit(0);
	
	$index = array(ADMNOTES, NEWSLET_LIST, NEWSLET_WAIT, GROUPS, MEMBERS, GROUPSNWL, MEMBERSNWL, GROUPSCOL, MEMBERSCOL, 
                   DOCID, DOCDATES, CHILDREN, DBAGENDA, DBART, DBBLOG, DBNEWS, DBDNLOAD, DBFAQ, DBFORUMCAT, 
                   DBFORUM, DBTHREAD, DBLINKS, DBPHOTO, DBREACT, DBREBLOG, DBRSS, DBBSS, DBFREEBOX, DBMENUBOX, DBOPTMENU, 
				   DBMENUICO, DBSOCNET, DOCIDARCH, DBAGENDAARCHDATE, DBAGENDAARCH, DBBLOGARCHDATE, DBBLOGARCH, 
				   DBREBLOGARCH, DBNEWSARCHDATE, DBNEWSARCH, DBFORUMARCHDATE, DBFORUMARCH, DBTHREADARCH, 
				   DBIPSTATS, DBLOGBOOK, DBKEYWORDS, DBDDMENUBOX, DBOPTDDMENU);

	foreach($index as $idx) WriteFullDB($idx, '');
    
    CreateInitStruct('../skins/'.$page[14].'/');
	
	WriteFullDB(DBLOGDATE, date('d/m/y'));
	WriteFullDB(DBLOGSTATS, date('d/m/y').';0;');
	
	WriteCounter(NEXTID, 0);
	WriteCounter(NEXTIDBK, 0);
	WriteCounter(DBFORUMCOUNTER, 0);
	WriteCounter(DBCOUNTER, 0);
	WriteCounter(DBSTATS, 1);
	WriteCounter(DBSTATSBK, 1);

	$dbt = array();
	$dbt = InitDBlog(1);
	$dbt[0][0] = (integer) date("H");
	WriteDBFields(DBLOGH,$dbt);
	$dbt = array();
	$dbt = InitDBlog(24);
	$dbt[0][0] = (integer) date("d");
	WriteDBFields(DBLOGD,$dbt);
	$dbt = array();
	$dbt = InitDBlog(31);
	$dbt[0][0] = (integer) date("m");
	WriteDBFields(DBLOGM,$dbt);
	$dbt = array();
	$dbt = InitDBlog(12);
	$dbt[0][0] = (integer) date("Y");
	WriteDBFields(DBLOGY,$dbt);
}

?>