3
3
* $RCSfile: ItemDeleteSingle.inc,v $
5
5
* Gallery - a web based photo album viewer and editor
6
* Copyright (C) 2000-2005 Bharat Mediratta
6
* Copyright (C) 2000-2006 Bharat Mediratta
8
8
* This program is free software; you can redistribute it and/or modify
9
9
* it under the terms of the GNU General Public License as published by
48
48
if (isset($form['action']['delete'])) {
49
49
/* Get the root album id, so we don't try to delete it */
50
list ($ret, $rootId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.rootAlbum');
51
if ($ret->isError()) {
50
list ($ret, $rootId) =
51
GalleryCoreApi::getPluginParameter('module', 'core', 'id.rootAlbum');
52
53
return array($ret->wrap(__FILE__, __LINE__), null);
55
56
/* The view shouldn't let us get this far if we don't have delete permission */
56
57
$ret = GalleryCoreApi::assertHasItemPermission($itemId, 'core.delete');
57
if ($ret->isError()) {
58
59
return array($ret->wrap(__FILE__, __LINE__), null);
61
62
list ($ret, $item) = GalleryCoreApi::loadEntitiesById($itemId);
62
if ($ret->isError()) {
63
64
return array($ret->wrap(__FILE__, __LINE__), null);
66
67
/* The view shouldn't let us try to delete the root album, either */
67
68
if ($itemId == $rootId) {
68
return array(GalleryStatus::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__,
69
return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__,
69
70
"Can't delete the root album"), null);
72
73
$ret = GalleryCoreApi::deleteEntityById($itemId);
73
if ($ret->isError()) {
74
75
return array($ret->wrap(__FILE__, __LINE__), null);
77
list ($ret, $success) = GalleryCoreApi::guaranteeAlbumHasThumbnail($item->getParentId());
78
if ($ret->isError()) {
78
list ($ret, $success) =
79
GalleryCoreApi::guaranteeAlbumHasThumbnail($item->getParentId());
79
81
return array($ret->wrap(__FILE__, __LINE__), null);
81
83
/* What do we do if we weren't successful? No thumbnail, I guess */
97
99
$results['status'] = $status;
98
100
$results['error'] = $error;
100
return array(GalleryStatus::success(), $results);
102
return array(null, $results);
125
127
list($ret, $item) = GalleryCoreApi::loadEntitiesById($itemId);
126
if ($ret->isError()) {
127
129
return array($ret->wrap(__FILE__, __LINE__), null);
130
132
/* Get child counts */
131
133
list ($ret, $childCountTable) = GalleryCoreApi::fetchDescendentCounts(array($itemId));
132
if ($ret->isError()) {
133
135
return array($ret->wrap(__FILE__, __LINE__), null);
135
137
$childCount = isset($childCountTable[$itemId]) ? $childCountTable[$itemId] : 0;
141
143
$template->setVariable('controller', 'core.ItemDeleteSingle');
142
144
$template->setVariable('ItemDeleteSingle', $ItemDeleteSingle);
144
return array(GalleryStatus::success(),
145
147
array('body' => 'modules/core/templates/ItemDeleteSingle.tpl'));
152
154
function getViewDescription() {
153
155
list ($ret, $core) = GalleryCoreApi::loadPlugin('module', 'core');
154
if ($ret->isError()) {
155
157
return array($ret->wrap(__FILE__, __LINE__), null);
158
160
list ($ret, $item) = $this->_getItem();
159
if ($ret->isError()) {
160
162
return array($ret->wrap(__FILE__, __LINE__), null);
163
165
$itemTypeNames = $item->itemTypeName(true);
165
return array(GalleryStatus::success(), $core->translate(array('text' => 'delete %s',
166
'arg1' => $itemTypeNames[1])));
167
return array(null, $core->translate(array('text' => 'delete %s',
168
'arg1' => $itemTypeNames[1])));