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 view will show an error message when an item cannot be displayed
23 * @package GalleryCore
24 * @subpackage UserInterface
25 * @author Bharat Mediratta <bharat@menalto.com>
26 * @version $Revision: 17580 $
27 */
28class ShowItemErrorView extends GalleryView {
29
30    /**
31     * @see GalleryView::loadTemplate
32     */
33    function loadTemplate(&$template, &$form) {
34	global $gallery;
35
36	list ($ret, $item, $wasSpecified) = $this->getItem();
37	if ($ret) {
38	    return array($ret, null);
39	}
40
41	$problem = GalleryUtilities::getRequestVariables('problem');
42
43	switch ($problem) {
44	case 'missingTheme':
45	    if ($wasSpecified) {
46		list ($ret, $themeId) = GalleryCoreApi::fetchThemeId($item);
47		if ($ret) {
48		    return array($ret, null);
49		}
50
51		if (GalleryUtilities::isA($item, 'GalleryDataItem')) {
52		    $targetId = $item->getParentId();
53		} else {
54		    $targetId = $item->getId();
55		}
56
57		list ($ret, $canEdit) = GalleryCoreApi::hasItemPermission($targetId, 'core.edit');
58		if ($ret) {
59		    return array($ret, null);
60		}
61	    } else {
62		list ($ret, $themeId) =
63		    GalleryCoreApi::getPluginParameter('module', 'core', 'default.theme');
64		if ($ret) {
65		    return array($ret, null);
66		}
67
68		$targetId = null;
69		$canEdit = false;
70	    }
71
72	    list ($ret, $isAdmin) = GalleryCoreApi::isUserInSiteAdminGroup();
73	    if ($ret) {
74		return array($ret, null);
75	    }
76
77	    $template->setVariable('ShowItemError',
78				   array('itemId' => $targetId,
79					 'themeId' => $themeId,
80					 'canEdit' => $canEdit,
81					 'isAdmin' => $isAdmin));
82	    return array(null,
83			 array('body' => 'modules/core/templates/ShowItemError.tpl'));
84
85	default:
86	    /*
87	     * We know of no other problems!   Returning an empty result will
88	     * throw up a security violation page.
89	     */
90	    return array(null, array());
91	}
92    }
93
94    /**
95     * @see GalleryView::getViewType
96     */
97    function getViewType() {
98	return VIEW_TYPE_ADMIN;
99    }
100}
101?>
102