<?php
include_once('../../../config.php');
include_once ("../path.php");
include_once ("helpers.php");

$zipFile = $global_backup_path . $backup_file;
$folders = scandir($json_instance_path);

echo "<div style='$SCRIPT_STYLE'>";
echo "Backup all content for <b>" . strtoupper($instance_name) . "...</b> <br>";

$zip = new ZipArchive();
$zip->open($zipFile, ZipArchive::CREATE);
foreach ($folders as $f)
{
    $path = $json_instance_path . $f;

    if ($f === '.' || $f === '..' || !is_dir($path)) continue;

    addToArchive($zip, $path, $f, $model_data_file);
    addToArchive($zip, $path, $f, $preview_file);
    addToArchive($zip, $path, $f, $mask_file);
    addToArchive($zip, $path, $f . $drawings_dir, $drawings_dir);
    addToArchive($zip, $path, $f . $images_dir, $images_dir);

    echo strtoupper($f).", ";
}
$zip->close();

download_button($zipFile);
echo '</div>';


exit;

