<?php

/*======================================================================*\
|| #################################################################### ||
|| # Drag'nDrop Shop 1.8                                              # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright 2014 JAKWEB All Rights Reserved.                       # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| #   ----------- Drag'nDrop Shop IS NOT FREE SOFTWARE -----------   # ||
|| #                      http://www.jakweb.ch                        # ||
|| #################################################################### ||
\*======================================================================*/

// Check if the file is accessed only via index.php if not stop the script from running
if (!defined('JAK_ADMIN_PREVENT_ACCESS')) die('You cannot access this file directly.');

// Check if the user has access to this file
if (!JAK_USERID || !JAK_SUPERADMINACCESS) jak_redirect(BASE_URL);

include_once('../class/class.dbie.php');

$dbimpexp = new dbimpexp();

// Flag to select step
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $defaults = $_POST;
    
if (isset($defaults['delCache'])) {
	
	// Now let us delete the all the cache file
	$cacheallfiles = '../'.JAK_CACHE_DIRECTORY.'/';
	$msfi = glob($cacheallfiles."*.php");
	if ($msfi) foreach ($msfi as $filen) {
	    if (file_exists($filen)) unlink($filen);
	}
	
	jak_redirect(BASE_URL.'index.php?p=success');

}

// Execute Optinos
if (isset($defaults['download'])) {

    $dbimpexp->addValue('download_path', '')->addValue('download', true)->addValue('file_name', 'shop_db_file.xml')->export();
    
}

if (isset($defaults['import'])) {
    
    	$xmlfiledb = $_FILES['uploaddb']['tmp_name'];
    	
    	$filename = $_FILES['uploaddb']['name']; // original filename
    	$ls_xtension = end(explode(".", $filename));
    	
    	if ($xmlfiledb && $ls_xtension == "xml") {
    	
    		$dbimpexp->addValue('import_path', $xmlfiledb)->import();
    		
    		// Now let us delete the define cache file
    		$cachedefinefile = '../'.JAK_CACHE_DIRECTORY.'/define.php';
    		if (file_exists($cachedefinefile)) {
    			unlink($cachedefinefile);
    		}
    		
    		$success['s'] = $tl['general']['g111'];
    		$success = $success;
    		
    	} else {
    		
    		$errors['e'] = $tl['error']['e39'];
    		$errors = $errors;
    	
    	}
}

		if (isset($defaults['optimize'])) {
			
			$dbimpexp->optimize();
			
			$success['s'] = $tl['general']['g113'];
			$success = $success;
		
		}

}

// Call the template
$template = 'backupdb.php';

?>