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 Movies
23 * @package GalleryCore
24 * @subpackage UserInterface
25 * @author Bharat Mediratta <bharat@menalto.com>
26 * @version $Revision: 17580 $
27 */
28class ItemEditMovie 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	    /* Missing values get set to 0 */
43	    if (isset($form['width']) && $form['width'] < 0) {
44		$error[] = 'form[error][width][invalid]';
45	    } else {
46		$form['width'] = (int)$form['width'];
47	    }
48
49	    if (isset($form['height']) && $form['height'] < 0) {
50		$error[] = 'form[error][height][invalid]';
51	    } else {
52		$form['height'] = (int)$form['height'];
53	    }
54
55	    if (empty($error)) {
56		list ($ret, $lock) = GalleryCoreApi::acquireWriteLock($item->getId());
57		if ($ret) {
58		    return array($ret, null, null, null);
59		}
60
61		list ($ret, $item) = $item->refresh();
62		if ($ret) {
63		    GalleryCoreApi::releaseLocks($lock);
64		    return array($ret, null, null, null);
65		}
66
67		$item->setWidth($form['width']);
68		$item->setHeight($form['height']);
69		$item->setSerialNumber($form['serialNumber']);
70		$ret = $item->save();
71		if ($ret) {
72		    GalleryCoreApi::releaseLocks($lock);
73		    return array($ret, null, null, null);
74		}
75
76		$ret = GalleryCoreApi::releaseLocks($lock);
77		if ($ret) {
78		    return array($ret, null, null, null);
79		}
80
81		/* Prepare our status message */
82		list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'core');
83		if ($ret) {
84		    return array($ret, null, null, null);
85		}
86
87		$status = $module->translate('Changes saved successfully');
88	    }
89	}
90
91	return array(null, $error, $status, false);
92    }
93
94    /**
95     * @see ItemEditPlugin::loadTemplate
96     */
97    function loadTemplate(&$template, &$form, $item, $thumbnail) {
98	global $gallery;
99
100	if ($form['formName'] != 'ItemEditMovie') {
101	    /* First time around, load the form with item data */
102	    $form['width'] = $item->getWidth();
103	    $form['height'] = $item->getHeight();
104	    $form['formName'] = 'ItemEditMovie';
105	}
106
107	$ItemEditMovie = array();
108
109	$template->setVariable('ItemEditMovie', $ItemEditMovie);
110	$template->setVariable('controller', 'core.ItemEditMovie');
111	return array(null,
112		     'modules/core/templates/ItemEditMovie.tpl', 'modules_core');
113    }
114
115    /**
116     * @see ItemEditPlugin::isSupported
117     */
118    function isSupported($item, $thumbnail) {
119	return (GalleryUtilities::isA($item, 'GalleryMovieItem'));
120    }
121
122    /**
123     * @see ItemEditPlugin::getTitle
124     */
125    function getTitle() {
126	list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'core');
127	if ($ret) {
128	    return array($ret, null);
129	}
130
131	return array(null, $module->translate('Movie Size'));
132    }
133}
134?>
135