<?php
/*******************************************************************************
 *   Migrate from previous version 5
 *******************************************************************************
 *   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.17 (December 14, 2024) : modify migration copy selected skins
 ******************************************************************************/

header("Pragma: no-cache");
define('CHEMIN', '../');
$selskin = 'no_skin';
include CHEMIN.'inc/includes.inc';
include $lng.'-install.inc';
include 'func_install.php';

$form    = import('form');
$doing   = import('doing');
$step    = import('step');
$dossier = import('dossier');
$nskin   = import('nskin');

if (empty($form)) {
	if (empty($doing)) {
        DisplayHeader();
        DisplayTitre($clean[26], $clean[29]);
        echo '
<form name="instal0" action="migrate50.php?lng='.$lng.'&amp;doing=1" method="post">
  <div style="text-align:center;">'.SubmitButton($clean[25]).'
    <button type="reset" style="cursor:pointer;" title="'.$clean[0].'" onclick="window.location=\'install.php?lng='.$lng.'&form=1\';">'.$clean[0].'</button>
  </div>
</form>';
	} elseif ($doing == '1') {
        DisplayHeader();
        DisplayTitre($clean[26], $clean[29]);
        echo '
<form name="instal1" action="migrate50.php?lng='.$lng.'&doing=2" method="post">
  <div style="text-align:center;">'.$clean[31].'</div>
  <div style="text-align:center;"><input typ="text" name="dossier" class="form-control texte" size="45" /></div>
  <div style="text-align:center;">'.$clean[36].'</div>
  <div style="text-align:center;"><input typ="text" name="nskin" class="form-control texte" size="25" /></div>
  <div style="text-align:center;">'.SubmitButton($clean[25]).'
    <button type="reset" style="cursor:pointer;" title="'.$clean[0].'" onclick="window.location=\'install.php?lng='.$lng.'&form=1\';">'.$clean[0].'</button>
  </div>
</form>';
	} 
    elseif (is_dir($dossier)) {
        set_time_limit(0);
        if ($doing == '2') {
            DisplayHeader('migrate50.php?lng='.$lng.'&dossier='.$dossier.'&doing=3');
            @RecursiveDeleteDir(CHEMIN.'admin/plugins');
            @recursiveCopy($dossier.'admin/plugins', CHEMIN.'admin/plugins');
            DisplayProcess($clean[26], $clean[30], $clean[33]);
        }
        elseif ($doing == '3') {
            DisplayHeader('migrate50.php?lng='.$lng.'&dossier='.$dossier.'&doing=4');
            @RecursiveDeleteDir(CHEMIN.'data/dbdocs');
            @recursiveCopy($dossier.'data/dbdocs', CHEMIN.'data/dbdocs');
            DisplayProcess($clean[26], $clean[30], $clean[33].$clean[35]);
        }
        elseif ($doing == '4') {
            DisplayHeader('migrate50.php?lng='.$lng.'&dossier='.$dossier.'&doing=5');
            @RecursiveDeleteDir(CHEMIN.'data/plugins');
            @recursiveCopy($dossier.'data/plugins', CHEMIN.'data/plugins');
            DisplayProcess($clean[26], $clean[30], $clean[33].$clean[35].$clean[37]);
        }
        elseif ($doing == '5') {
            DisplayHeader('migrate50.php?lng='.$lng.'&dossier='.$dossier.'&doing=6');
            @RecursiveDeleteDir(CHEMIN.'data/users');
            @recursiveCopy($dossier.'data/users', CHEMIN.'data/users');
            DisplayProcess($clean[26], $clean[30], $clean[33].$clean[35].$clean[37].$clean[38]);
        }
        elseif ($doing == '6') {
            DisplayHeader('migrate50.php?lng='.$lng.'&dossier='.$dossier.'&doing=7');        
            @RecursiveDeleteDir(CHEMIN.'documentation/plugins');
            @recursiveCopy($dossier.'documentation/plugins', CHEMIN.'documentation/plugins');
            DisplayProcess($clean[26], $clean[30], $clean[33].$clean[35].$clean[37].$clean[38].$clean[39]);
        }
        elseif ($doing == '7') {
            DisplayHeader('migrate50.php?lng='.$lng.'&dossier='.$dossier.'&doing=8');        
            if (file_exists(CHEMIN.'file')) @RecursiveDeleteDir(CHEMIN.'file');
			if (file_exists($dossier.'file')) @recursiveCopy($dossier.'file', CHEMIN.'file');
            DisplayProcess($clean[26], $clean[30], $clean[33].$clean[35].$clean[37].$clean[38].$clean[39].$clean[43]);
        }
        elseif ($doing == '8') {
            DisplayHeader('migrate50.php?lng='.$lng.'&dossier='.$dossier.'&doing=9');        
            @RecursiveDeleteDir(CHEMIN.'img');
            @recursiveCopy($dossier.'img', CHEMIN.'img');
            DisplayProcess($clean[26], $clean[30], $clean[33].$clean[35].$clean[37].$clean[38].$clean[39].$clean[43].$clean[44]);
        }
        elseif ($doing == '9') {
            DisplayHeader('migrate50.php?lng='.$lng.'&dossier='.$dossier.'&doing=10');        
            @RecursiveDeleteDir(CHEMIN.'pages');
            @recursiveCopy($dossier.'pages', CHEMIN.'pages');
            DisplayProcess($clean[26], $clean[30], $clean[33].$clean[35].$clean[37].$clean[38].$clean[39].$clean[43].$clean[44].$clean[45]);
        }
        elseif ($doing == '10') {
            DisplayHeader('migrate50.php?lng='.$lng.'&dossier='.$dossier.'&doing=11');        
            @RecursiveDeleteDir(CHEMIN.'photo');
            @recursiveCopy($dossier.'photo', CHEMIN.'photo');
            DisplayProcess($clean[26], $clean[30], $clean[33].$clean[35].$clean[37].$clean[38].$clean[39].$clean[43].$clean[44].$clean[45].$clean[46]);
        }
        elseif ($doing == '11') {
            DisplayHeader('migrate50.php?lng='.$lng.'&dossier='.$dossier.'&doing=12');        
            @RecursiveDeleteDir(CHEMIN.'plugins');
            @recursiveCopy($dossier.'plugins', CHEMIN.'plugins');
            DisplayProcess($clean[26], $clean[30], $clean[33].$clean[35].$clean[37].$clean[38].$clean[39].$clean[43].$clean[44].$clean[45].$clean[46].$clean[47]);
        }
        elseif ($doing == '12') {
            DisplayHeader('migrate50.php?lng='.$lng.'&dossier='.$dossier.'&doing=13');        
//            @recursiveCopy($dossier.'skins', CHEMIN.'skins');
			$files = scandir($dossier.'skins');
			foreach ($files as $file) {
				if (!file_exists(CHEMIN.'skins/'.$file)) {
					@recursiveCopy($dossier.'skins/'.$file, CHEMIN.'skins/'.$file); 
				}
			}
            if (@is_dir(CHEMIN.'skins/'.$nskin)) {
                include_once CONFIG;
                $page[14] = $nskin;
                include CHEMIN.'admin/inc/confupdt.inc';
            }
            $meskin = CHEMIN.'skins/';
			if (!isset($page[14]))  $page[14] = 'no_skin';
			if ($page[14] != '')  $meskin .= $page[14].'/';
			else $meskin .= 'no_skin/';
            if (is_dir($meskin)) {
                include $meskin.'confweb.inc';
                foreach (array('fbox_poll', 'fbox_news') as $fbox) {
                    foreach ($templates as $key=>$tmpl) {
                        foreach (array(BOX_LEFT, BOX_RIGHT, BOX_ABOVE, BOX_UNDER) as $subarray) {
                            for ($i = 0; $i < count($xposbox[$key][$subarray]) - 1; $i++) {
                                $str = $xposbox[$key][$subarray][$i];
                                $xposbox[$key][$subarray][$i] = (1 == preg_match('!^'.$fbox.'!', $str) ? '' : $str);
                            }
                        }
                        foreach (array(BOX_TOP, BOX_BOTTOM) as $array) {
                            foreach (array(BOX_LSIDE, BOX_LEFT, BOX_CENTER, BOX_RIGHT, BOX_RSIDE) as $subarray) {
                                for ($i = 0; $i < count($xposbox[$key][$array][$subarray]) - 1; $i++) {
                                    $str = $xposbox[$key][$array][$subarray][$i];
                                    $xposbox[$key][$array][$subarray][$i] = (1 == preg_match('!^'.$fbox.'!', $str) ? '' : $str);
                                }
                            }
                        }
                    }
                }
                @include CHEMIN.'admin/inc/confweb.inc';
            }
            DisplayProcess($clean[26], $clean[30], $clean[33].$clean[35].$clean[37].$clean[38].$clean[39].$clean[43].$clean[44].$clean[45].$clean[46].$clean[47].$clean[48]);
        } 
        elseif ($doing == '13') {
            DisplayTitre($clean[26], $clean[34]);
            echo '
<form name="instal2" action="install.php?lng='.$lng.'&amp;form=1" method="post">
  <div style="text-align:center;">'.SubmitButton($clean[25]).'</div>
</form>';
        }
    } 
    else {
        DisplayTitre($clean[26], $clean[49]);
        echo '
<form name="instal2" action="install.php?lng='.$lng.'&amp;form=1" method="post">
  <div style="text-align:center;">'.SubmitButton($clean[25]).'</div>
</form>';
    }
}

DisplayFooter();
?>