<?php
define('NTLCMS', 1);
include ('../system/start.php');
include ('../system/function.php');
include ('../system/antidos.php');
include ('../system/head.php');
include ('../system/pclzip.class.php');

################################################################################
if ($active && $_USER['admin'] == '1'){
################################################################################
echo '<div class="title"><center>Backup сайта</center></div>';
################################################################################

$files_dir = rtrim(FOLDER, '/');
$files_to_arch = array();

for ($d = @opendir($files_dir); $file = @readdir($d);){      
if ($file != '.' && $file != '..' && $file != 'backup'){
//$files_to_arch[] = $files_dir.'/'.$file;
$files_to_arch[] = $file;
}
}

chdir($files_dir);


$nam_backup = strtoupper($_SERVER['HTTP_HOST']).'_'.date('d.m.Y_H:i', TIME).'.zip';

$archive = new PclZip(FOLDER.'/backup/'.$nam_backup);
$v_list = $archive -> create(implode(',', $files_to_arch));


if ($v_list == 0){
echo '<div class="post"><center>! Error: '.$archive -> errorInfo(true).'</center></div>';
} else {
echo '<div class="post"><center>!Бекап сайта успешно создан!</center></div>';
}


echo '<div class="block">>> <a href="'.URL.'/cabinet">В кабинет</a> | <a href="'.URL.'/_control">Админ-Панель</a></div>';

################################################################################
} else {
echo '<div class="title"><center>Проверка прав доступа</center></div>';
echo '<div class="menu"><center>! Доступ запрещен!</center></div>';
echo '<div class="block">! '.(isset($active) ? '<a href="'.URL.'/cabinet">В кабинет</a>' : '<a href="'.URL.'">На главную</a>').'</div>';
}

include ('../system/foot.php');

?>