<?php
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2007 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
GalleryCoreApi::requireOnce('modules/imageareas/classes/ImageAreasHelper.class');
GalleryCoreApi::requireOnce('modules/imageareas/classes/ImageAreasImage.class');
GalleryCoreApi::requireOnce('modules/imageareas/classes/ImageArea.class');
GalleryCoreApi::requireOnce('lib/JSON/JSON.php');
/**
* This view handles Ajax calls.
* @package ImageAreas
* @author Paul Hinze <paul [dot] t [dot] hinze [at] gmail [dot] com>
* @version $Revision: 1235 $
*/
class ImageAreasCallbackView extends GalleryView {
/**
* @see GalleryView::isImmediate
*/
function isImmediate() {
return true;
}
/**
* @see GalleryView::isControllerLike
*/
function isControllerLike() {
return true;
}
/**
* @see GalleryView::renderImmediate
*/
function renderImmediate($status, $error) {
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$ret = null;
$action = GalleryUtilities::getRequestVariables('action');
switch ($action) {
case 'display':
list($src,
$width,
$height,
$alt,
$itemId) =
GalleryUtilities::getRequestVariables('src','width','height','alt', 'itemId');
$img = new ImageAreasImage($src, $width, $height, $alt, $itemId);
list ($ret,
$html) = ImageAreasHelper::
getImageAreasUI($img);
if (!$ret) {
echo 'displayHTML##'.
$html.
'##';
}
break;
case 'add':
list($src,
$itemId,
$json_data) =
GalleryUtilities::getRequestVariables('src','itemId', 'data');
$data = $json->decode(ImageAreasHelper::xmldecode($json_data));
$area = new ImageArea($data['areaId'], $itemId, $data['areaTitle'],
$data['areaContent'], $data['areaBounds']);
list ($ret,
$newId) = ImageAreasHelper::
addArea($area);
$result['newId'] = $newId;
break;
case 'modify':
list($src,
$itemId,
$json_data) =
GalleryUtilities::getRequestVariables('src','itemId', 'data');
$data = $json->decode(ImageAreasHelper::xmldecode($json_data));
$area = new ImageArea($data['areaId'], $itemId, $data['areaTitle'],
$data['areaContent'], $data['areaBounds']);
$ret = ImageAreasHelper::updateArea($area);
break;
case 'delete':
list($src,
$itemId,
$json_data) =
GalleryUtilities::getRequestVariables('src','itemId', 'data');
$data = $json->decode(ImageAreasHelper::xmldecode($json_data));
$ret = ImageAreasHelper::deleteArea($data['areaId']);
break;
default:
$ret = GalleryCoreApi::error(ERROR_BAD_PARAMETER);
}
if ($ret) {
$result['status'] = 'error';
$result['ret'] = $ret->getAsText();
} else {
$result['status'] = 'success';
}
print $json->
encode($result);
return null;
}
}
?>