} elseif (!isUnderRoot($_POST['file_path'])) {
    $error = IMG_SAVE_PATH_DISALLOWED;
} else {
    if (!sizeof($lastestSessionImageInfo)) {
        $error = IMG_UNDO_NO_HISTORY_AVAIALBE;
    } else {
        //get the original image which is the lastest session image if any when the system is in demo
        $sessionImage = $session->getSessionDir() . $lastestSessionImageInfo['name'];
        $originalSessionImageInfo = $history->getOriginalImage();
        if (CONFIG_SYS_DEMO_ENABLE && sizeof($originalSessionImageInfo)) {
            $originalImage = $session->getSessionDir() . $originalSessionImageInfo['info']['name'];
        } else {
            $originalImage = $_POST['file_path'];
        }
        include_once CLASS_IMAGE;
        $image = new ImageAjaxFileManager();
        if ($image->loadImage($sessionImage)) {
            $imageInfo = $image->getOriginalImageInfo();
            if (!@copy($sessionImage, $originalImage)) {
                $error = IMG_UNDO_COPY_FAILED;
            } else {
                //remove the session image
                if (@unlink($sessionImage)) {
                    $history->restore();
                }
                //only one left, remove the session original if demo
                if ($history->getNumRestorable() == 0 && CONFIG_SYS_DEMO_ENABLE && sizeof($originalSessionImageInfo)) {
                    @unlink($session->getSessionDir() . $originalSessionImageInfo['info']['name']);
                    $originalImage = $_POST['file_path'];
                }
            }
if (!empty($_GET['path']) && file_exists($_GET['path']) && is_file($_GET['path']) && isUnderRoot($_GET['path'])) {
    $path = $_GET['path'];
} else {
    die(IMG_GEN_IMG_NOT_EXISTS);
}
require_once CLASS_HISTORY;
$history = new History($path, $session);
if (CONFIG_SYS_DEMO_ENABLE) {
    $sessionImageInfo = $history->getLastestRestorable();
    $originalSessionImageInfo = $history->getOriginalImage();
    if (sizeof($originalSessionImageInfo)) {
        $path = backslashToSlash($session->getSessionDir() . $originalSessionImageInfo['info']['name']);
    }
}
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "inc" . DIRECTORY_SEPARATOR . "class.image.php";
$image = new ImageAjaxFileManager();
$imageInfo = $image->getImageInfo($path);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="author" content="Logan Cai"/>
    <meta name="website" content="http://www.phpletter.com"/>
    <script type="text/javascript" src="jscripts/ajaximageeditor_c.js"></script>

    <!--<script type="text/javascript" src="jscripts/jquery.js"></script>
    <script type="text/javascript" src="jscripts/form.js"></script>
    <script type="text/javascript" src="jscripts/select.js"></script>
    <script type="text/javascript" src="jscripts/jqModal.js"></script>
    <script type="text/javascript" src="jscripts/rotate.js"></script>
<?php

/* For licensing terms, see /license.txt */
/**
 * ajax preview
 * @author Logan Cai (cailongqun [at] yahoo [dot] com [dot] cn)
 * @link www.phpletter.com
 * @since 22/April/2007
 *
 */
require_once '../../../../../../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH) . 'fckeditor/editor/plugins/ajaxfilemanager/inc/config.php';
$path = base64_decode($_GET['path']);
if (!empty($path) && file_exists($path) && is_file($path)) {
    require_once CLASS_IMAGE;
    $image = new ImageAjaxFileManager(true);
    if ($image->loadImage($path)) {
        if ($image->resize(CONFIG_IMG_THUMBNAIL_MAX_X, CONFIG_IMG_THUMBNAIL_MAX_Y, true, true)) {
            $image->showImage();
        } else {
            echo PREVIEW_NOT_PREVIEW . ".";
        }
    } else {
        echo PREVIEW_NOT_PREVIEW . "..";
    }
} else {
    echo PREVIEW_NOT_PREVIEW . "...";
}
}
initSessionHistory($_POST['path']);
echo "{";
$error = "";
$info = "";
if (empty($_POST['path'])) {
    $error = IMG_SAVE_EMPTY_PATH;
} elseif (!file_exists($_POST['path'])) {
    $error = IMG_SAVE_NOT_EXISTS;
} else {
    if (!isUnderRoot($_POST['path'])) {
        $error = IMG_SAVE_PATH_DISALLOWED;
    } else {
        if (!empty($_POST['mode'])) {
            include_once CLASS_IMAGE;
            $image = new ImageAjaxFileManager();
            $image->loadImage($_POST['path']);
            switch ($_POST['mode']) {
                case "resize":
                    if (!$image->resize($_POST['width'], $_POST['height'], !empty($_POST['constraint']) ? true : false)) {
                        $error = IMG_SAVE_RESIZE_FAILED;
                    }
                    break;
                case "crop":
                    if (!$image->cropToDimensions($_POST['x'], $_POST['y'], intval($_POST['x']) + intval($_POST['width']), intval($_POST['y']) + intval($_POST['height']))) {
                        $error = IMG_SAVE_CROP_FAILED;
                    }
                    break;
                case "flip":
                    if (!$image->flip($_POST['flip_angle'])) {
                        $error = IMG_SAVE_FLIP_FAILED;