<?php
header('Content-Type: text/html; charset=windows-1251');
?>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>SAVING PAGES</title>
</head>
<body background="../d~e~f/bkg.gif" leftMargin=0 id=bod topMargin=0 style="overflow:hidden;" width=100% height=100% >
<table height=100% width=100% ><tr><td valign=center align=center>
<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);
include "../f.php";   //


//*****************************************************************************************
// 
//*****************************************************************************************
// 
function full_dir ($directory)
{global $zip;
$dir = opendir($directory);
  while (($file = readdir($dir)) !== false)
  {if ( is_file ($directory."/".$file))
   {$directory2=str_replace("../","",$directory);
$zip -> addFile($directory."/".$file, $directory2."/".$file);
  }
   else if ( is_dir ($directory."/".$file) && ($file != ".") && ($file != ".."))
    {$directory2=str_replace("../","",$directory);
	$zip->addEmptyDir($directory2."/".$file);
	full_dir ($directory."/".$file);
	}
  }
 }
//********************************************************************************************
//echo "<table height=100% width=100% ><tr><td valign=center align=center>";
if (isset($_REQUEST['add']))
{$add=$_REQUEST['add'];
}
else
{$add="";}
if (isset ($_REQUEST['spv']))      //
{$spv=trim($_REQUEST['spv']);
}
else
{$spv=trim($_GET['spv']);}
if ($add=="all")
{echo "<h3>Save full.</h3> ";
}
else
{if ($add=="0")
{echo "<h3>Selective saving</h3> ";
}
else
{echo "<h3>Selective addition</h3> ";
}}
if ($add=="all" )        /// 
{//*******************************************************************************
 if (strstr(" ".php_uname(), 'Windows'))   // 
 //*******************************************************************************
 {$pathdir="../pages";
 $nameArhive = '../../pages.zip';                  //
 if (file_exists($nameArhive))
 {unlink($nameArhive);
 }
$zip = new ZipArchive;                            // 
ini_set('max_execution_time', 900);
if ($zip -> open($nameArhive, ZipArchive::CREATE) === TRUE)
{
full_dir ($pathdir);
// 
$directory3="../otd/page.txt";
$directory4="pages/page.txt";
$zip -> addFile($directory3,$directory4);
$directory3="../menu/pages.txt";
$directory4="pages/pages.txt";
$zip -> addFile($directory3,$directory4);
$zip -> close();                                    //
echo '<h2 style=color:red;text-align:center>Structure files otd/page.txt, nenu/pages.txt and ALL PAGES ARE SAVED IN ARCHIVE pages.zip
</h2>';
}
else           
{
echo '<b style=color:brown>An error occurred while creating an archive in WINDOWS.</b>';
}}
//***************************************************
else        // 
//***************************************************
{$nameArhive = '../../pages.tar.gz';   
 if (file_exists($nameArhive))
{unlink($nameArhive);
}
$pathdir=str_replace('otd','',getcwd());
$pathdir2=str_replace('/gidra','',$pathdir);
copy('../otd/page.txt','../pages/page.txt'); 
copy('../menu/pages.txt','../pages/pages.txt'); 
exec('tar -cvzf '.$nameArhive.' ../pages');
unlink ('../pages/page.txt');
unlink ('../pages/pages.txt');
echo '<h2 style=color:red;text-align:center>The structure files otd/page.txt, menu/pages.txt and ALL PAGES ARE SAVED IN THE ARCHIVE pages.tar.gz</h2>';
}
}
else
{
//********************************************************************************************
 if (strstr(" ".php_uname(), 'Windows'))   // 
 //*******************************************************************************************
 {$pathdir="../pages";
$nameArhive = '../../pages2.zip';                  //
if ($add==0)
{ if (file_exists($nameArhive))
{unlink ($nameArhive);
}}
$zip = new ZipArchive;                            // 
ini_set('max_execution_time', 900);
if($zip -> open($nameArhive, ZipArchive::CREATE) === TRUE)
{
$mdi2= explode(";",$spv);
for ($i = 0; $i <= count($mdi2)-2; $i++) 
{
$zip -> addFile("../pages/".$mdi2[$i].".php", "pages/".$mdi2[$i].".php");
full_dir ("../pages/".$mdi2[$i]);
}
$zip -> close();                                    // 
if ($add==0)
{
echo '<b style=color:red>OLD ARCHIVE OF SELECTED PAGES REMOVED! NEW ARCHIVE OF SELECTED PAGES pages2.zip CREATED!</b><br>';
}
else
{
echo '<b style=color:red>ARCHIVE OF SELECTED PAGES pages2.zip UPDATED!</b><br>';
}
}
}
//**************************************************
else        // 
//**************************************************
{$nameArhive = '../../pages2.tar';   
if ($add==0)
{if (file_exists($nameArhive))
{unlink($nameArhive);
}}
$mdi2= explode(";",$spv);
for ($i = 0; $i <= count($mdi2)-2; $i++) 
{if ($i==0 and $add==0)
{exec('tar -cvf  '.$nameArhive.' ../pages/'.$mdi2[$i]);
}
else
{exec('tar -rvf '.$nameArhive.' ../pages/'.$mdi2[$i]);
}
exec('tar -rvf '.$nameArhive.' ../pages/'.$mdi2[$i].".php");
}
echo '<h2 style=color:red;text-align:center>SELECTED PAGES SAVED IN ARCHIVE pages2.tar</h2>';
}}
?>
</td></tr></table></tbody></body></html>