<?php

include('config.backup.php');
include('class.backup.php');
define("ADMIN_DATABASE",RPATH_ROOT.$temporary_directory.DB_ADMIN);
define("ADMIN_LOGS",RPATH_ROOT.$temporary_directory.DB_LOG_FILE);	
	// Log report	
		$line = "<span class=\"log_date\">$date</span><span class=\"log_event\"><b>admin</b> has backed up the webmail.</span><br>\n";
		$file = fopen(ADMIN_LOGS, 'a+');
		fwrite($file, $line);
		fclose($file);


$createZip = new createZip;
if (isset($configBackup) && is_array($configBackup) && count($configBackup)>0)
{
    // Lets backup any files or folders if any
foreach ($configBackup as $dir)
{
$basename = basename($dir);
    // dir basename
if (is_file($dir))
{
$fileContents = file_get_contents($dir);
 $createZip->addFile($fileContents,$basename);
}
else
{
$createZip->addDirectory($basename."/");
$files = directoryToArray($dir,true);
$files = array_reverse($files);
foreach ($files as $file)
{
$zipPath = explode($dir,$file);
$zipPath = $zipPath[1];
      // skip any if required
$skip =  false;
foreach ($configSkip as $skipObject)
{
if (strpos($file,$skipObject) === 0)
{
$skip = true;
break;
}
}
if ($skip) {
continue;
}
if (is_dir($file))
{
$createZip->addDirectory($basename."/".$zipPath);
}
else
{
$fileContents = file_get_contents($file);
$createZip->addFile($fileContents,$basename."/".$zipPath);
}}}}}
$fileName = $configBackupDir.$backupName;
$fd = fopen ($fileName, "wb");
$out = fwrite ($fd, $createZip -> getZippedfile());
fclose ($fd);