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 present the available options to administer a user
23 * @package GalleryCore
24 * @subpackage UserInterface
25 * @author Bharat Mediratta <bharat@menalto.com>
26 * @version $Revision: 17580 $
27 */
28class UserAdminView extends GalleryView {
29
30    /**
31     * @see GalleryView::loadTemplate
32     */
33    function loadTemplate(&$template, &$form) {
34	global $gallery;
35	$user = $gallery->getActiveUser();
36
37	/* Load the module list */
38	list ($ret, $moduleStatus) = GalleryCoreApi::fetchPluginStatus('module');
39	if ($ret) {
40	    return array($ret, null);
41	}
42
43	/* Get a list of all the admin views for each module */
44	$subViewChoices = array();
45	foreach ($moduleStatus as $moduleId => $status) {
46	    if (empty($status['active'])) {
47		continue;
48	    }
49
50	    /* Get the selected module's admin view */
51	    if (in_array('getUserAdminViews', explode('|', $status['callbacks']))) {
52		list ($ret, $module) = GalleryCoreApi::loadPlugin('module', $moduleId);
53		if ($ret) {
54		    if ($ret->getErrorCode() & ERROR_PLUGIN_VERSION_MISMATCH) {
55			continue;
56		    }
57		    return array($ret, null);
58		}
59
60		list ($ret, $moduleViews) = $module->getUserAdminViews($user);
61		if ($ret) {
62		    return array($ret, null);
63		}
64
65		$subViewChoices = array_merge($subViewChoices, $moduleViews);
66	    }
67	}
68
69	/* If we have a specific sub view, load it now */
70	$subViewName = GalleryUtilities::getRequestVariables('subView');
71	if ($subViewName == 'core.UserAdmin') {
72	    return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER), null);
73	}
74	if (empty($subViewName) && !empty($subViewChoices)) {
75	    $subViewName = $subViewChoices[0]['view'];
76	}
77
78	list ($ret, $isSiteAdmin) = GalleryCoreApi::isUserInSiteAdminGroup();
79	if ($ret) {
80	    return array($ret, null);
81	}
82
83	/* Our sub view may have set some hints, like the encoding type */
84	if ($template->hasVariable('UserAdmin')) {
85	    $UserAdmin =& $template->getVariableByReference('UserAdmin');
86	} else {
87	    $UserAdmin = array();
88	    $template->setVariableByReference('UserAdmin', $UserAdmin);
89	}
90
91	list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'core');
92	if ($ret) {
93	    return array($ret, null);
94	}
95
96	/* Set up my view parameters */
97	$UserAdmin['subViewChoices'] = $subViewChoices;
98	$UserAdmin['subViewName'] = $subViewName;
99	$UserAdmin['isSiteAdmin'] = $isSiteAdmin;
100
101	if (!empty($subViewName)) {
102	    list ($ret, $subView) = GalleryView::loadView($subViewName);
103	    if ($ret) {
104		return array($ret, null);
105	    }
106
107	    list ($ret, $results) = $subView->loadTemplate($template, $form);
108	    if ($ret) {
109		return array($ret, null);
110	    }
111
112	    if (isset($results['redirect'])) {
113		return array(null, $results);
114	    }
115
116	    $UserAdmin['viewBodyFile'] = $results['body'];
117	    $UserAdmin['viewL10Domain'] = $subView->getL10Domain();
118	}
119
120	$template->setVariable('UserAdmin', $UserAdmin);
121	$template->title($module->translate('Gallery User Administration'));
122	return array(null, array('body' => 'modules/core/templates/UserAdmin.tpl'));
123    }
124
125    /**
126     * @see GalleryView::isAllowedInMaintenance
127     */
128    function isAllowedInMaintenance() {
129	return (GalleryUtilities::getRequestVariables('subView') == 'core.UserLogin');
130    }
131
132    /**
133     * @see GalleryView::getViewDescription
134     */
135    function getViewDescription() {
136	global $gallery;
137
138	/* Get the description from the current subView */
139	$subViewName = GalleryUtilities::getRequestVariables('subView');
140	if (empty($subViewName)) {
141	    $subViewName = 'core.ItemEdit';
142	}
143	list ($ret, $subView) = GalleryView::loadView($subViewName);
144	if ($ret) {
145	    return array($ret, null);
146	}
147
148	list ($ret, $description) = $subView->getViewDescription();
149	if ($ret) {
150	    return array($ret, null);
151	}
152
153	return array(null, $description);
154    }
155
156    /**
157     * @see GalleryView::getViewType
158     */
159    function getViewType() {
160	return VIEW_TYPE_ADMIN;
161    }
162}
163?>
164