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 * This controller adjusts relative toolkit priorities 23 * @package GalleryCore 24 * @subpackage UserInterface 25 * @author Alan Harder <alan.harder@sun.com> 26 * @version $Revision: 17580 $ 27 */ 28class AdminToolkitPriorityController 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 = array(); 40 if (isset($form['action']['save'])) { 41 list ($ret, $list) = GalleryCoreApi::getRedundantToolkitPriorities(); 42 if ($ret) { 43 return array($ret, null); 44 } 45 foreach ($form['priority'] as $priority => $toolkit) { 46 if ($priority != $list[$toolkit]) { 47 $ret = GalleryCoreApi::updateMapEntry( 48 'GalleryToolkitOperationMimeTypeMap', 49 array('toolkitId' => $toolkit), array('priority' => $priority)); 50 if ($ret) { 51 return array($ret, null); 52 } 53 } 54 } 55 GalleryDataCache::removeByPattern('GalleryToolkitHelper::'); 56 $status['saved'] = 1; 57 } /* else $form['action']['reset'] */ 58 59 $results['return'] = 0; 60 $results['redirect']['view'] = 'core.SiteAdmin'; 61 $results['redirect']['subView'] = 'core.AdminToolkitPriority'; 62 $results['status'] = $status; 63 $results['error'] = array(); 64 65 return array(null, $results); 66 } 67} 68 69/** 70 * This view will show toolkits and their relative priorities 71 */ 72class AdminToolkitPriorityView extends GalleryView { 73 74 /** 75 * @see GalleryView::loadTemplate 76 */ 77 function loadTemplate(&$template, &$form) { 78 $ret = GalleryCoreApi::assertUserIsSiteAdministrator(); 79 if ($ret) { 80 return array($ret, null); 81 } 82 83 if ($form['formName'] != 'AdminToolkitPriority') { 84 $form['formName'] = 'AdminToolkitPriority'; 85 } 86 87 list ($ret, $list) = GalleryCoreApi::getRedundantToolkitPriorities(); 88 if ($ret) { 89 return array($ret, null); 90 } 91 asort($list); 92 /* Reset all priorities to start of managed-priority window; ensure we break any ties */ 93 $priority = 20; 94 foreach ($list as $toolkit => $tmp) { 95 $list[$toolkit] = $priority++; 96 } 97 98 $AdminToolkitPriority = array('list' => $list, 'count' => count($list)); 99 $template->setVariable('AdminToolkitPriority', $AdminToolkitPriority); 100 $template->setVariable('controller', 'core.AdminToolkitPriority'); 101 102 return array(null, array('body' => 'modules/core/templates/AdminToolkitPriority.tpl')); 103 } 104} 105?> 106