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 * Controller to select the album to add photos to. 23 * Allows the user to select the album that should have the photos added in to it. Also lets the 24 * user select a parent album and go to the new album page should the user wish to first create a 25 * new album. 26 * 27 * @package PublishXp 28 * @subpackage UserInterface 29 * @author Timothy Webb <tiwebb@cisco.com> 30 * @version $Revision: 17580 $ 31 */ 32class SelectAlbumController extends GalleryController { 33 34 /** 35 * @see GalleryController:handleRequest 36 */ 37 function handleRequest($form) { 38 $results = $error = $status = array(); 39 40 /* 41 * We merely provide a redirection service here. Permission checks will be 42 * handled by the target views. 43 */ 44 if (isset($form['action']['newAlbum'])) { 45 /* Redirect to the new album page. */ 46 if (isset($form['albumId'])) { 47 $redirect['view'] = 'publishxp.NewAlbum'; 48 $redirect['parentId'] = $form['albumId']; 49 } else { 50 $error[] = 'form[error][albumId][missing]'; 51 } 52 } else if (isset($form['action']['select'])) { 53 /* Redirect to the options page */ 54 if (isset($form['albumId'])) { 55 $redirect['view'] = 'publishxp.Options'; 56 $redirect['albumId'] = $form['albumId']; 57 } else { 58 $error[] = 'form[error][albumId][missing]'; 59 } 60 } 61 62 $results['status'] = $status; 63 $results['error'] = $error; 64 if (!empty($redirect)) { 65 $results['redirect'] = $redirect; 66 } else { 67 $results['delegate']['view'] = 'publishxp.SelectAlbum'; 68 } 69 return array(null, $results); 70 } 71} 72 73/** 74 * View to select the album to add photos to. 75 * Allows the user to select the album that should have the photos added in to it. Also lets the 76 * user select a parent album and go to the new album page should the user wish to first create a 77 * new album. 78 */ 79class SelectAlbumView extends GalleryView { 80 /** 81 * Prepares any additional data before rendering the template. 82 * 83 * @see GalleryController:loadTemplate 84 */ 85 function loadTemplate(&$template, &$form) { 86 if ($form['formName'] != 'SelectAlbum') { 87 $form['formName'] = 'SelectAlbum'; 88 $form['albumId'] = GalleryUtilities::getRequestVariables('albumId'); 89 } else { 90 /* 91 * In case they didn't select an album in the prior page (they're going 92 * to get an error message, but we require form[albumId] to be set in the template). 93 */ 94 if (!isset($form['albumId'])) { 95 $form['albumId'] = null; 96 } 97 } 98 99 /* Get ids of all all albums where we can add new data items */ 100 list ($ret, $albumIds['addDataItem']) = 101 GalleryCoreApi::fetchAllItemIds('GalleryAlbumItem', 'core.addDataItem'); 102 if ($ret) { 103 return array($ret, null); 104 } 105 106 /* Get ids of all all albums where we can add new album items */ 107 list ($ret, $albumIds['addAlbumItem']) = 108 GalleryCoreApi::fetchAllItemIds('GalleryAlbumItem', 'core.addAlbumItem'); 109 if ($ret) { 110 return array($ret, null); 111 } 112 113 /* Merge them together to get the master list of ids */ 114 $albumIds['allIds'] = 115 array_unique(array_merge($albumIds['addDataItem'], $albumIds['addAlbumItem'])); 116 117 if (!empty($albumIds['allIds'])) { 118 /** @todo Use fetchAllItemIds with multiple permissions once the API is available */ 119 list ($ret, $permissions) = 120 GalleryCoreApi::fetchPermissionsForItems($albumIds['allIds']); 121 if ($ret) { 122 return array($ret, null); 123 } 124 $filteredIds = array(); 125 foreach ($albumIds['allIds'] as $id) { 126 if (!empty($permissions[$id]['core.view'])) { 127 $filteredIds[] = $id; 128 } 129 } 130 $albumIds['allIds'] = $filteredIds; 131 } 132 133 $albums = array(); 134 if (!empty($albumIds['allIds'])) { 135 /* Load all the album entities */ 136 list ($ret, $albums) = 137 GalleryCoreApi::loadEntitiesById($albumIds['allIds'], 'GalleryAlbumItem'); 138 if ($ret) { 139 return array($ret, null); 140 } 141 } 142 143 $SelectAlbum = array(); 144 $SelectAlbum['albumTree'] = GalleryUtilities::createAlbumTree($albums); 145 146 list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'publishxp'); 147 if ($ret) { 148 return array($ret, null); 149 } 150 151 $template->title($module->translate('Windows Publishing Wizard')); 152 $template->setVariable('SelectAlbum', $SelectAlbum); 153 $template->setVariable('controller', 'publishxp.SelectAlbum'); 154 $template->head('modules/publishxp/templates/Head.tpl'); 155 156 return array(null, array('body' => 'modules/publishxp/templates/SelectAlbum.tpl', 157 'useFullScreen' => true)); 158 } 159} 160?> 161