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 * Settings for Webcam images 23 * @package WebCam 24 * @subpackage UserInterface 25 * @author Alan Harder <alan.harder@sun.com> 26 * @version $Revision: 17580 $ 27 */ 28class WebCamSiteAdminController extends GalleryController { 29 30 /** 31 * @see GalleryController::handleRequest 32 */ 33 function handleRequest($form) { 34 $ret = GalleryCoreApi::assertUserIsSiteAdministrator(); 35 if ($ret) { 36 return array($ret, null); 37 } 38 39 $status = $error = array(); 40 if (isset($form['action']['save'])) { 41 if (!isset($form['fromweb']) 42 || !in_array($form['fromweb'], array('on', 'off', 'admin'))) { 43 return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER), null); 44 } 45 46 if (isset($form['duration'])) { 47 /* Accept input for locales that use comma as fraction separator */ 48 $form['duration'] = str_replace(',', '.', $form['duration']); 49 } 50 if (!isset($form['duration']) || !is_numeric($form['duration'])) { 51 $error[] = 'form[error][duration]'; 52 } else { 53 $ret = GalleryCoreApi::setPluginParameter( 54 'module', 'webcam', 'duration', round($form['duration'] * 60)); 55 if ($ret) { 56 return array($ret, null); 57 } 58 $ret = GalleryCoreApi::setPluginParameter( 59 'module', 'webcam', 'fromweb', $form['fromweb']); 60 if ($ret) { 61 return array($ret, null); 62 } 63 $status['saved'] = 1; 64 } 65 } 66 67 $method = empty($error) ? 'redirect' : 'delegate'; 68 $results[$method]['view'] = 'core.SiteAdmin'; 69 $results[$method]['subView'] = 'webcam.WebCamSiteAdmin'; 70 $results['status'] = $status; 71 $results['error'] = $error; 72 73 return array(null, $results); 74 } 75} 76 77/** 78 * Settings for Webcam images 79 */ 80class WebCamSiteAdminView extends GalleryView { 81 82 /** 83 * @see GalleryView::loadTemplate 84 */ 85 function loadTemplate(&$template, &$form) { 86 $ret = GalleryCoreApi::assertUserIsSiteAdministrator(); 87 if ($ret) { 88 return array($ret, null); 89 } 90 91 list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'webcam'); 92 if ($ret) { 93 return array($ret, null); 94 } 95 96 if ($form['formName'] != 'WebCamSiteAdmin') { 97 $form['formName'] = 'WebCamSiteAdmin'; 98 foreach (array('fromweb', 'duration') as $key) { 99 list ($ret, $form[$key]) = $module->getParameter($key); 100 if ($ret) { 101 return array($ret, null); 102 } 103 } 104 /* String conversion here may use comma as fraction separator, based on locale */ 105 $form['duration'] = (string)round($form['duration'] / 60, 2); 106 } 107 108 $WebCamSiteAdmin = array( 109 'optionList' => array( 110 'on' => $module->translate('Available to all users with permission to add items'), 111 'admin' => $module->translate('Site Admins only'), 112 'off' => $module->translate('Disabled'))); 113 114 $template->setVariable('WebCamSiteAdmin', $WebCamSiteAdmin); 115 $template->setVariable('controller', 'webcam.WebCamSiteAdmin'); 116 return array(null, array('body' => 'modules/webcam/templates/WebCamSiteAdmin.tpl')); 117 } 118} 119?> 120