1<?php
2/*
3 * Gallery - a web based photo album viewer and editor
4 * Copyright (C) 2000-2008 Bharat Mediratta
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21/**
22 * Plugin for editing Animations
23 * @package GalleryCore
24 * @subpackage UserInterface
25 * @author Bharat Mediratta <bharat@menalto.com>
26 * @version $Revision: 17580 $
27 */
28class ItemEditAnimation extends ItemEditPlugin {
29
30    /**
31     * @see ItemEditPlugin::handleRequest
32     */
33    function handleRequest($form, &$item, &$preferred) {
34	global $gallery;
35
36	$status = null;
37	$error = array();
38
39	/* Figure out which command we're taking */
40	if (isset($form['action']['save'])) {
41
42	    if (isset($form['width']) && $form['width'] < 0) {
43		$error[] = 'form[error][width][invalid]';
44	    } else {
45		$form['width'] = (int)$form['width'];
46	    }
47
48	    if (isset($form['height']) && $form['height'] < 0) {
49		$error[] = 'form[error][height][invalid]';
50	    } else {
51		$form['height'] = (int)$form['height'];
52	    }
53
54	    if (empty($error)) {
55		list ($ret, $lock) = GalleryCoreApi::acquireWriteLock($item->getId());
56		if ($ret) {
57		    return array($ret, null, null, null);
58		}
59
60		list ($ret, $item) = $item->refresh();
61		if ($ret) {
62		    GalleryCoreApi::releaseLocks($lock);
63		    return array($ret, null, null, null);
64		}
65
66		$item->setWidth($form['width']);
67		$item->setHeight($form['height']);
68		$item->setSerialNumber($form['serialNumber']);
69		$ret = $item->save();
70		if ($ret) {
71		    GalleryCoreApi::releaseLocks($lock);
72		    return array($ret, null, null, null);
73		}
74
75		$ret = GalleryCoreApi::releaseLocks($lock);
76		if ($ret) {
77		    return array($ret, null, null, null);
78		}
79
80		/* Prepare our status message */
81		list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'core');
82		if ($ret) {
83		    return array($ret, null, null, null);
84		}
85
86		$status = $module->translate('Changes saved successfully');
87	    }
88	}
89
90	return array(null, $error, $status, false);
91    }
92
93    /**
94     * @see ItemEditPlugin::loadTemplate
95     */
96    function loadTemplate(&$template, &$form, $item, $thumbnail) {
97	global $gallery;
98
99	if ($form['formName'] != 'ItemEditAnimation') {
100	    /* First time around, load the form with item data */
101	    $form['width'] = $item->getWidth();
102	    $form['height'] = $item->getHeight();
103	    $form['formName'] = 'ItemEditAnimation';
104	}
105
106	$ItemEditAnimation = array();
107	$template->setVariable('ItemEditAnimation', $ItemEditAnimation);
108	$template->setVariable('controller', 'core.ItemEditAnimation');
109	return array(null,
110		     'modules/core/templates/ItemEditAnimation.tpl', 'modules_core');
111    }
112
113    /**
114     * @see ItemEditPlugin::isSupported
115     */
116    function isSupported($item, $thumbnail) {
117	return (GalleryUtilities::isA($item, 'GalleryAnimationItem'));
118    }
119
120    /**
121     * @see ItemEditPlugin::getTitle
122     */
123    function getTitle() {
124	list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'core');
125	if ($ret) {
126	    return array($ret, null);
127	}
128
129	return array(null, $module->translate('Animation Size'));
130    }
131}
132?>
133