3
* $RCSfile: DiskQuotaOption.inc,v $
5
* Gallery - a web based photo album viewer and editor
6
* Copyright (C) 2000-2005 Bharat Mediratta
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or (at
11
* your option) any later version.
13
* This program is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
23
* @version $Revision: 1.5 $ $Date: 2005/08/23 03:49:49 $
25
* @subpackage UserInterface
26
* @author Robert Balousek <volksport@users.sf.net>
30
* This ItemAddOption enforces disk quotas
33
* @subpackage UserInterface
36
class DiskQuotaOption extends ItemAddOption {
39
* @see ItemAddOption::isAppropriate
41
function isAppropriate() {
42
return array(GalleryStatus::success(), true);
46
* @see ItemAddOption::handleRequestAfterAdd
48
function handleRequestAfterAdd($form, $items) {
49
GalleryCoreApi::relativeRequireOnce('modules/quotas/classes/GalleryQuotasHelper.class');
55
/* user's disk quota in KB */
56
list ($ret, $quotaExists, $userDiskQuota) =
57
GalleryQuotasHelper::getUserDiskQuota($gallery->getActiveUserId());
58
if ($ret->isError()) {
59
return array($ret->wrap(__FILE__, __LINE__), null, null);
62
/* if user has a quota */
64
$excludedIds = array();
65
for ($j = 0; $j < count($items); $j++) {
66
$excludedIds[] = $items[$j]->getId();
68
list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'quotas');
69
if ($ret->isError()) {
70
return array($ret->wrap(__FILE__, __LINE__), null, null);
72
for ($i = 0; $i < count($items); $i++) {
73
$warnings[$i] = array();
75
/* we should come here only if we are adding a data item, not sub-album */
76
$albumId = $items[$i]->getParentId();
78
/* calculate the item ids of the newly added items */
79
array_shift($excludedIds);
81
/* user's disk usage in Bytes */
82
list ($ret, $userDiskUsage) = GalleryQuotasHelper::getUserDiskUsage(
83
$gallery->getActiveUserId(), $excludedIds);
84
if ($ret->isError()) {
85
return array($ret->wrap(__FILE__, __LINE__), null, null);
88
/* make disk usage into KB */
89
$userDiskUsage /= 1024.00;
91
if ($userDiskUsage > $userDiskQuota) {
92
list ($ret, $userDiskQuotaHumanReadable, $userDiskQuotaHumanReadableUnit) =
93
GalleryQuotasHelper::humanReadableFromKilobytes($userDiskQuota);
94
if ($ret->isError()) {
95
return array($ret->wrap(__FILE__, __LINE__), null, null);
97
$warnings[$i][] = $module->translate(
98
array('text' => 'Warning: You have reached your disk quota (%s %s), this item will not be added.',
99
'arg1' => $userDiskQuotaHumanReadable,
100
'arg2' => $userDiskQuotaHumanReadableUnit));
102
$gallery->addShutdownAction(
103
array('GalleryCoreApi', 'deleteEntityById'), array($items[$i]->getId()));
105
list ($ret, $userDiskQuotaHumanReadable, $userDiskQuotaHumanReadableUnit) =
106
GalleryQuotasHelper::humanReadableFromKilobytes($userDiskQuota);
107
if ($ret->isError()) {
108
return array($ret->wrap(__FILE__, __LINE__), null, null);
110
list ($ret, $userDiskUsageHumanReadable, $userDiskUsageHumanReadableUnit) =
111
GalleryQuotasHelper::humanReadableFromKilobytes($userDiskUsage);
112
if ($ret->isError()) {
113
return array($ret->wrap(__FILE__, __LINE__), null, null);
116
$warnings[$i][] = $module->translate(
117
array('text' => 'You are using %s %s of your allotted %s %s.',
118
'arg1' => $userDiskUsageHumanReadable,
119
'arg2' => $userDiskUsageHumanReadableUnit,
120
'arg3' => $userDiskQuotaHumanReadable,
121
'arg4' => $userDiskQuotaHumanReadableUnit));
125
return array(GalleryStatus::success(), $errors, $warnings);