<?php
header('Content-Type: text/html; charset=windows-1251');
?>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>RESTORATION</title>
</head>
<body background="../d~e~f/bkg.gif" leftMargin=0 id=bod topMargin=0 style="overflow:hidden;" width=100% height=100% >
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
include "../f.php";   // 

if (isset($_GET['typ']))
{$typ=$_GET['typ'];}
else
{$typ="";}
//////////////////////////////
// 
//////////////////////////////
if ($typ=="5" or $typ=="55" )
{ini_set('max_execution_time', 900);
echo '<table height=100% width=100%><tr><td valign=center align=center>';
if ($typ=="5")
{$zip2='../../pages.zip';
}
else
{$zip2='../../pages2.zip';
}
//*******************************************************************
if  (strstr(" ".php_uname(), 'Windows')) // 
//*******************************************************************
{if (file_exists($zip2))
{if ($typ=="5")
{if (file_exists('../pages'))
{full_del_dir ('../pages'); 
}
}
$zip = new ZipArchive;
if ($zip->open($zip2) === TRUE) 
{$zip->extractTo('../');
 $zip->close();
if ($typ=="5")
{	copy('../pages/page.txt','../otd/page.txt'); 
	copy('../pages/pages.txt','../menu/pages.txt'); 
    unlink ('../pages/page.txt');
	unlink ('../pages/pages.txt');
echo '<h2 style=color:red;text-align:center>Structure files otd/page.txt, menu/pages.txt and ALL PAGES RESTORED from pages.zip file </h2> ';
echo '<center> Execute: Change structure -> Save -> Accept changed structure</center><br>';
}	
else
{echo '<h2 style=color:red;text-align:center>SELECTED PAGES RESTORED from pages2.zip file.</h2>';
echo '<center>If the restored pages are missing in the structure, enter them in the structure!</center><br>';
}}
else
{echo '<h2 style=color:red;text-align:center>ERROR PAGES NOT RESTORED, MAYBE NO ARCHIVE FILE.</h2>'; 
}
}
else
{echo '<h2 style="color:red">Archive file '. $zip2.' absent ! Restore is IMPOSSIBLE!</h2>';
}}
//************************************************
else   // 
//************************************************
{$pathdir=str_replace('otd','',getcwd());
$pathdir2=str_replace('/gidra','',$pathdir);
if ($typ=="5")
{$zip2='../../pages.tar.gz';
}
else
{$zip2='../../pages2.tar';
}
if (file_exists($zip2))
{if ($typ=="5")
{if (file_exists('../pages'))
{full_del_dir ('../pages'); 
}}
try {
    $phar = new PharData($zip2);
    $phar->extractTo($pathdir,null,true);    // extract all files
if ($typ=="5")
{	copy('../pages/page.txt','../otd/page.txt'); 
	copy('../pages/pages.txt','../menu/pages.txt'); 
    unlink ('../pages/page.txt');
	unlink ('../pages/pages.txt');
echo '<h2 style=color:red;text-align:center>Structure files otd/page.txt, menu/pages.txt and ALL PAGES RESTORED from pages.tar.gz file</h2>';
echo '<center>Execute: Modify structure -> Save -> Accept modified structure.</center><br>';
}	
else
{echo '<h2 style=color:red;text-align:center>SELECTED PAGES RESTORED from pages2.tar file.</h2>';
echo '<center>If the restored pages are missing in the structure, enter them in the structure!</center><br>';
}
} catch (Exception $e) 
{echo $e;
}}
else
{echo '<h2 style="color:red">Archive file '. $zip2.' absent ! Recovery is IMPOSSIBLE!</h2>';
}}

echo '</td></tr></table>';
if (copy('../pages/page.txt','../otd/page.txt')) 
{unlink ('../pages/page.txt');
}
else
{echo "<b>Error copying otd/page.txt.</b>";}
}
echo '</body></html>';