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 will handle the deletion of a group
23 * @package GalleryCore
24 * @subpackage UserInterface
25 * @author Bharat Mediratta <bharat@menalto.com>
26 * @version $Revision: 17580 $
27 */
28class AdminDeleteGroupController 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	$results = $status = $error = array();
40	$groupId = GalleryUtilities::getRequestVariables('groupId');
41
42	if (isset($form['action']['cancel'])) {
43
44	    /* Go back to the AdminGroups view */
45	    $redirect['view'] = 'core.SiteAdmin';
46	    $redirect['subView'] = 'core.AdminGroups';
47
48	} else if (isset($form['action']['delete'])) {
49
50	    /* Only allow users to delete GROUP_NORMAL groups. */
51	    list ($ret, $group) = GalleryCoreApi::loadEntitiesById($groupId, 'GalleryGroup');
52	    if ($ret) {
53		return array($ret, null);
54	    }
55
56	    $ret = GalleryCoreApi::deleteEntityById($group->getId(), 'GalleryGroup');
57	    if ($ret) {
58		return array($ret, null);
59	    }
60
61	    /* Request a redirect to the confirmation screen */
62	    $redirect['view'] = 'core.SiteAdmin';
63	    $redirect['subView'] = 'core.AdminGroups';
64	    $status['deletedGroup'] = $group->getGroupName();
65	}
66
67	if (!empty($redirect)) {
68	    $results['redirect'] = $redirect;
69	} else {
70	    $results['delegate']['view'] = 'core.SiteAdmin';
71	    $results['delegate']['subView'] = 'core.AdminDeleteGroup';
72	}
73	$results['status'] = $status;
74	$results['error'] = $error;
75
76	return array(null, $results);
77    }
78}
79
80/**
81 * This view will prompt for confirmation to delete a group
82 */
83class AdminDeleteGroupView extends GalleryView {
84
85    /**
86     * @see GalleryView::loadTemplate
87     */
88    function loadTemplate(&$template, &$form) {
89	$ret = GalleryCoreApi::assertUserIsSiteAdministrator();
90	if ($ret) {
91	    return array($ret, null);
92	}
93
94	$groupId = GalleryUtilities::getRequestVariables('groupId');
95	list ($ret, $group) = GalleryCoreApi::loadEntitiesById($groupId, 'GalleryGroup');
96	if ($ret) {
97	    return array($ret, null);
98	}
99
100	if ($form['formName'] != 'AdminDeleteGroup') {
101	    /* First time around initialize our form */
102	    $form['groupName'] = $group->getGroupName();
103	    $form['formName'] = 'AdminDeleteGroup';
104	}
105
106	$AdminDeleteGroup = array();
107	$AdminDeleteGroup['group'] = (array)$group;
108
109	/* Render the HTML body */
110	$template->setVariable('AdminDeleteGroup', $AdminDeleteGroup);
111	$template->setVariable('controller', 'core.AdminDeleteGroup');
112
113	return array(null,
114		     array('body' => 'modules/core/templates/AdminDeleteGroup.tpl'));
115    }
116}
117?>
118