Commit 36ab2512 authored by sylvieg's avatar sylvieg

[MOD]fgal quota: alllows to limit the volume that is uploaded globally to the...

[MOD]fgal quota: alllows to limit the volume that is uploaded globally to the fgals or locally to a fgal
parent dfd35c0b
......@@ -1228,6 +1228,7 @@ installer/schema/20091023_bookmarks_name_lengthen_tiki.sql -text
installer/schema/20091023_nul_categ_tiki.sql -text
installer/schema/20091023_report_tiki.sql -text
installer/schema/20091027_multiple_session_handler_tiki.sql -text
installer/schema/20091028_quota_tiki.sql -text
installer/shell.php -text
installer/tiki-installer.php -text
lang/.htaccess -text
......
......@@ -731,6 +731,7 @@ CREATE TABLE `tiki_file_galleries` (
`show_path` char(1) default NULL,
`show_slideshow` char(1) default NULL,
`default_view` varchar(20) default NULL,
`quota` int(8) default 0,
PRIMARY KEY (`galleryId`)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
......
alter table `tiki_file_galleries` add column `quota` int(8) default 0;
\ No newline at end of file
......@@ -194,6 +194,7 @@ class FileGalLib extends TikiLib {
if (!isset($fgal_info['show_modified'])) $fgal_info['show_modified'] = 'n';
if (!isset($fgal_info['show_creator'])) $fgal_info['show_creator'] = 'n';
if (!isset($fgal_info['show_author'])) $fgal_info['show_author'] = 'n';
if (!isset($fgal_info['quota'])) $fgal_info['quota'] = 0;
// if the user is admin or the user is the same user and the gallery exists
// then replace if not then create the gallary if the name is unused.
......@@ -212,7 +213,7 @@ class FileGalLib extends TikiLib {
`user`=?, `lockable`=?, `show_lockedby`=?, `archives`=?, `sort_mode`=?,
`show_modified`=?, `show_creator`=?, `show_author`=?, `subgal_conf`=?,
`show_last_user`=?, `show_comment`=?, `show_files`=?, `show_explorer`=?,
`show_path`=?, `show_slideshow`=?, `default_view`=? where `galleryId`=?";
`show_path`=?, `show_slideshow`=?, `default_view`=?, `quota`=? where `galleryId`=?";
$bindvars=array(trim($fgal_info['name']), (int) $fgal_info['maxRows'],
$fgal_info['description'], (int) $this->now, $fgal_info['public'],
......@@ -228,7 +229,7 @@ class FileGalLib extends TikiLib {
$fgal_info['show_last_user'], $fgal_info['show_comment'],
$fgal_info['show_files'], $fgal_info['show_explorer'],
$fgal_info['show_path'], $fgal_info['show_slideshow'],
$fgal_info['default_view'], (int)$fgal_info['galleryId']);
$fgal_info['default_view'], $fgal_info['quota'], (int)$fgal_info['galleryId']);
$result = $this->query($query,$bindvars);
......@@ -246,8 +247,8 @@ class FileGalLib extends TikiLib {
`show_hits`, `max_desc`, `type`, `parentId`, `lockable`, `show_lockedby`,
`archives`, `sort_mode`, `show_modified`, `show_creator`, `show_author`,
`subgal_conf`, `show_last_user`, `show_comment`, `show_files`,
`show_explorer`, `show_path`, `show_slideshow`, `default_view`)
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
`show_explorer`, `show_path`, `show_slideshow`, `default_view`, `quota`)
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$bindvars=array($fgal_info['name'], $fgal_info['description'], (int)
$this->now, $fgal_info['user'], (int) $this->now, (int)
......@@ -262,7 +263,7 @@ class FileGalLib extends TikiLib {
$fgal_info['subgal_conf'], $fgal_info['show_last_user'],
$fgal_info['show_comment'], $fgal_info['show_files'],
$fgal_info['show_explorer'], $fgal_info['show_path'],
$fgal_info['show_slideshow'], $fgal_info['default_view']);
$fgal_info['show_slideshow'], $fgal_info['default_view'], $fgal_info['quota']);
$result = $this->query($query,$bindvars);
$galleryId = $this->getOne("select max(`galleryId`) from
......@@ -303,7 +304,7 @@ class FileGalLib extends TikiLib {
}
function process_batch_file_upload($galleryId, $file, $user, $description) {
global $prefs;
global $prefs, $smarty;
include_once ('lib/pclzip/pclzip.lib.php');
include_once ('lib/mime/mimelib.php');
......@@ -321,23 +322,40 @@ class FileGalLib extends TikiLib {
$savedir=$prefs['fgal_use_dir'];
}
// check filters
$upl = 1;
$errors = array();
while (($file = readdir($h)) !== false) {
if ($file != '.' && $file != '..' && is_file($extract_dir.'/'.$file)) {
$files[] = $file;
// check filters
$upl = 1;
if (!empty($prefs['fgal_match_regex'])) {
if (!preg_match('/'.$prefs['fgal_match_regex'].'/', $file, $reqs))
if (!preg_match('/'.$prefs['fgal_match_regex'].'/', $file, $reqs)) {
$errors[] = tra('Invalid filename (using filters for filenames)') . ': ' . $file;
$upl = 0;
}
}
if (!empty($prefs['fgal_nmatch_regex'])) {
if (preg_match('/'.$prefs['fgal_nmatch_regex'].'/', $file, $reqs))
if (preg_match('/'.$prefs['fgal_nmatch_regex'].'/', $file, $reqs)) {
$errors[] = tra('Invalid filename (using filters for filenames)') . ': ' . $file;
$upl = 0;
}
}
if ($this->checkQuota(filesize($extract_dir.$file), $galleryId, $error)) {
$errors[] = $error;
$upl = 0;
}
}
}
if (!$upl) {
$smarty->assign('msg', implode('<br />', $errors));
$smarty->display('error.tpl');
die;
}
while (($file = readdir($h)) !== false) {
if ($file != '.' && $file != '..' && is_file($extract_dir.'/'.$file)) {
if (!($fp = fopen($extract_dir.$file, "rb"))) {
$smarty->assign('msg', tra('Cannot open this file:'). "temp/$file");
$smarty->display("error.tpl");
......@@ -798,7 +816,6 @@ class FileGalLib extends TikiLib {
}
}
}
// Get a tree or a list of a gallery children ids, optionnally under a specific parentId
// To avoid a query to the database for each node, this function retrieves all gallery ids and recursively build the tree using this info
function getGalleryChildrenIds( &$subtree, $parentId = -1, $format = 'tree' ) {
......@@ -934,5 +951,112 @@ class FileGalLib extends TikiLib {
}
}
}
// get the size in k used in a fgal and its children
function getUsedSize($galleryId=0) {
$query = 'select sum(`filesize`) from `tiki_files`';
$bindvars = array();
if (!empty($galleryId)) {
$this->getGalleryIds( $bindvars, $galleryId, 'list' );
$query .= 'where `galleryId` in ('.implode(',', array_fill(0, count($bindvars), '?')).')';
}
$size = $this->getOne($query, $bindvars);
return $size;
}
// get the min quota in M of a fgal and its parents
function getQuota($galleryId=0) {
global $prefs;
if (empty($galleryId) || $prefs['fgal_quota_per_fgal'] == 'n') {
return $prefs['fgal_quota'];
}
$list = $this->getGalleryParentsColumns($galleryId, array('galleryId', 'quota'));
$quota = $prefs['fgal_quota'];
foreach($list as $fgal) {
if (empty($fgal['quota'])) {
continue;
}
$quota = min($quota, $fgal['quota']);
}
return $quota;
}
// get the max quota in M of the children of a fgal
function getMaxQuotaDescendants($galleryId=0) {
if (empty($galleryId)) {
return 0;
}
$this->getGalleryChildrenIds($subtree, $galleryId, 'list');
if (is_array($subtree)) {
$query = 'select max(`quota`) from `tiki_file_galleries` where `galleryId` in ('.implode(',', array_fill(0, count($subtree), '?')).')';
return $this->getOne($query, $subtree);
} else {
return 0;
}
}
// check quota is smaller than parent quotas and bigger than children quotas
// return -1: too small, 0: ok, +1: too big
function checkQuotaSetting($quota, $galleryId=0, $parentId=0) {
if (empty($quota)) {
return 0;
}
$limit = $this->getQuota($parentId);
if (!empty($limit) && $quota > $limit) {
return 1;// too big
}
if (!empty($galleryId)) {
$limit = $this->getMaxQuotaDescendants($galleryId);
if (!empty($limit) && $quota < $limit) {
return -1;//too small
}
}
return 0;
}
// get specific columns for a gallery and its parents
function getGalleryParentsColumns($galleryId, $columns) {
foreach ($columns as $col) {// artificial size column unitl it is in the database
if ($col != 'size') {
$cols[] = $col;
}
}
if (!in_array('galleryId', $cols)) $cols[] = 'galleryId';
if (!in_array('parentId', $cols)) $cols[] = 'parentId';
$query = 'select `'.implode($cols, '`, `').'` from `tiki_file_galleries`';
$all = $this->fetchAll($query);
$list = array();
$this->_getGalleryParentsColumns($all, $list, $galleryId, $columns);
return $list;
}
function _getGalleryParentsColumns($all, &$list, $galleryId, $columns=array()) {
foreach ($all as $fgal) {
if ($fgal['galleryId'] == $galleryId) {
if (in_array('size', $columns)) { // to be optimized
$fgal['size'] = $this->getUsedSize($galleryId);
}
$list[] = $fgal;
$this->_getGalleryParentsColumns($all, $list, $fgal['parentId'], $columns);
return;
}
}
}
// check a size in K can be added to a gallery
function checkQuota($size, $galleryId, &$error) {
global $prefs;
if (!empty($prefs['fgal_quota'])) {
$use = $this->getUsedSize();
if ($use + $size > $prefs['fgal_quota']*1024*1024) {
$error = tra('The global quota has been reached');
return false;
}
}
if ($prefs['fgal_quota_per_fgal'] == 'y') {
$list = $this->getGalleryParentsColumns($galleryId, array('galleryId', 'quota', 'size', 'name'));
//echo '<pre>';print_r($list);echo '</pre>';
foreach ($list as $fgal) {
if (!empty($fgal['quota']) && $fgal['size'] + $size > $fgal['quota']*1024*1024) {
$error = tra('The quota has been reached in:').' '.$fgal['name'];
return false;
}
}
}
return true;
}
}
$filegallib = new FileGalLib;
......@@ -7,6 +7,7 @@ function prefs_fgal_list() {
'type' => 'text',
'help' => 'File+Gallery+Config',
'size' => 50,
'hint' => tra('The server must be able to read/write the directory.').' '.tra('Required for podcasts.'),
),
'fgal_use_dir' => array(
'name' => tra('Path'),
......@@ -16,8 +17,9 @@ function prefs_fgal_list() {
'fgal_batch_dir' => array(
'name' => tra('Path'),
'type' => 'text',
'help' => 'File+Gallery',
'help' => 'File+Gallery+config',
'size' => 50,
'hint' => tra('If you enable Directory Batch Loading, you need to setup a web-readable directory (outside of your web space is better). Then setup a way to upload files in that dir, either by scp, ftp, or other protocols').' '.tra('The server must be able to read the directory.').' '. tra('The directory can be outside the web space.'),
),
'fgal_prevent_negative_score' => array(
'name' => tra('Prevent download if score becomes negative'),
......@@ -54,5 +56,40 @@ function prefs_fgal_list() {
'name' => tra('Cannot match'),
'type' => 'text',
'size' => 50,
), );
),
'fgal_quota' => array (
'name' => tra('Quota for all the files and archives'),
'shorthint' => tra('Mb').' '.tra('(0 for illimitted)'),
'type' => 'text',
'size' => 7,
),
'fgal_quota_per_fgal' => array (
'name' => tra('Quota can be defined for each file gallery'),
'type' => 'flag',
),
'fgal_quota_default' => array (
'name' => tra('Default quota for each new gallery'),
'shorthint' => tra('Mb').' '.tra('(0 for illimitted)'),
'type' => 'text',
'size' => 7,
),
'fgal_quota_show' => array (
'name' => tra('Show quota bar in the list page'),
'type' => 'flag',
),
/*
'fgal_use_db' => array(
'type' => 'radio',
'options' => array(
'n' => tra('Store in directory'),
'y' => tra('Store in database'),
),
),
'fgal_use_dir' => array(
'name' => tra('Path'),
'type' => 'text',
'size' => 50,
),
*/
);
}
\ No newline at end of file
......@@ -509,6 +509,10 @@ function get_default_prefs() {
'fgal_default_view' => 'list',
'fgal_limit_hits_per_file' => 'n',
'fgal_prevent_negative_score' => 'n',
'fgal_quota' => 0,
'fgal_quota_per_fgal' => 'n',
'fgal_quota_default' => 0,
'fgal_quota_show' => 'y',
// imagegals
'feature_galleries' => 'n',
......@@ -871,6 +875,21 @@ function get_default_prefs() {
'rss_calendar' => 'n',
'rss_mapfiles' => 'n',
'rss_cache_time' => '0', // 0 = disabled (default)
'title_rss_forums' => '',
'title_rss_forum' => '',
'title_rss_directories' => '',
'title_rss_articles' => '',
'title_rss_blogs' => '',
'title_rss_image_galleries' => '',
'title_rss_file_galleries' => '',
'title_rss_wiki' => '',
'title_rss_image_gallery' => '',
'title_rss_file_gallery' => '',
'title_rss_blog' => '',
'title_rss_tracker' => '',
'title_rss_trackers' => '',
'title_rss_calendar' => '',
'title_rss_mapfiles' => '',
'max_rss_forums' => 10,
'max_rss_forum' => 10,
'max_rss_directories' => 10,
......
......@@ -2306,28 +2306,6 @@ class TikiLib extends TikiDb_Bridge {
}
$result = $this->fetchAll($query, $bindvars);
if ( $with_subgals_size ) {
if (!function_exists('galsize')) {
function galsize($id, &$db) {
$return = 0;
$result = $db->query('SELECT `fileId`,`filesize` FROM `tiki_files` WHERE `galleryId`=?', array($id));
while ( $res = $result->fetchRow() ) {
$return += $res['filesize'];
}
unset($result);
$result = $db->query('SELECT `galleryId` FROM `tiki_file_galleries` WHERE `parentId`=?', array($id));
while ( $res = $result->fetchRow() ) {
$return += galsize($res['galleryId'], $db);
}
unset($result);
return $return;
}
}
}
$ret = array();
$gal_size_order = array();
$cant = 0;
......@@ -2363,7 +2341,7 @@ class TikiLib extends TikiDb_Bridge {
if ( $need_everything || $maxRecords == -1 || $cant < $maxRecords ) {
$ret[$cant] = $res;
if ( $with_subgals_size && $res['isgal'] == 1 ) {
$ret[$cant]['size'] = (string)galsize($res['id'], $this);
$ret[$cant]['size'] = (string)$filegallib->getUsedSize($res['id']);
$ret[$cant]['filesize'] = $ret[$cant]['size']; /// Obsolete
if ( $keep_subgals_together ) {
$gal_size_order[$cant] = $ret[$cant]['size'];
......@@ -2495,7 +2473,8 @@ class TikiLib extends TikiDb_Bridge {
'visible' => 'y',
'archives' => -1,
'type' => 'default',
'description' => ''
'description' => '',
'quota' => $prefs['fgal_quota_default'],
);
}
......
......@@ -62,6 +62,18 @@
</select>
</td></tr>
{if $prefs.fgal_quota_per_fgal eq 'y'}
<tr>
<td class="formcolor">{tr}Quota{/tr}</td>
<td class="formcolor">
<input type="text" id="quota" name="quota" value="{$gal_info.quota}" size="5" />{tr}Mb{/tr} <i>{tr}(0 for illimitted){/tr}</i>{if $gal_info.usedSize}<br />{tr}Used:{/tr} {$gal_info.usedSize|kbsize}{/if}
{if !empty($gal_info.quota)}{capture name='use'}{math equation="round((100*x)/(1024*1024*y))" x=$gal_info.usedSize y=$gal_info.quota}{/capture}{quotabar length='100' value=`$smarty.capture.use`}{/if}
{if !empty($gal_info.maxQuota)}<br />{tr}Max:{/tr} {$gal_info.maxQuota} {tr}Mb{/tr}{/if}
{if !empty($gal_info.minQuota)}<br />{tr}Min:{/tr} {$gal_info.minQuota} {tr}Mb{/tr}{/if}
</td>
</tr>
{/if}
{if $prefs.feature_groupalert eq 'y'}
<tr>
<td class="formcolor">{tr}Group of users alerted when file gallery is modified{/tr}</td>
......@@ -79,6 +91,7 @@
<td class="formcolor">{tr}Allows to select each user for small groups{/tr}</td>
<td class="formcolor"><input type="checkbox" name="showeachuser" {if $showeachuser eq 'y'}checked="checked"{/if}/ ></td>
</tr>
{/if}
{/if}
......
<div style="text-align: left;">
<label for="{$p.id|escape}">{$p.name|escape}:</label>
<input name="{$p.preference|escape}" id="{$p.id|escape}" value="{$p.value|escape}" size="{$p.size|default:80|escape}" type="text" />
{$p.detail|escape}
{include file=prefs/shared-flags.tpl}
{if $p.shorthint}
<em>{$p.shorthint|escape}</em>
{/if}
{if $p.hint}
<br/><em>{$p.hint|escape}</em>
{/if}
......
......@@ -32,6 +32,12 @@
</div>
</div>
{*
{preference name='fgal_use_db'}
<div class="adminoptionboxchild" id="fgal_use_db_childcontainer_1">
{preference name='fgal_use_dir'}
</div>
*}
<div class="adminoptionbox">
<div class="adminoptionlabel"><input type="radio" id="fgal_use_db1" name="fgal_use_db" value="y"
......@@ -47,7 +53,6 @@
</div>
{preference name='fgal_podcast_dir'}
<br /><em>{tr}The server must be able to read/write the directory.{/tr} {tr}Required for podcasts.{/tr}</em>
<input type="hidden" name="filegalfeatures" />
......@@ -56,8 +61,6 @@
{preference name='feature_file_galleries_rankings'}
<input type="hidden" name="filegalcomprefs" />
{preference name='feature_file_galleries_comments'}
<div class="adminoptionboxchild" id="feature_file_galleries_comments_childcontainer">
{preference name='file_galleries_comments_per_page'}
......@@ -75,13 +78,25 @@
{preference name='feature_file_galleries_batch'}
<div class="adminoptionboxchild" id="feature_file_galleries_batch_childcontainer">
{tr}If you enable Directory Batch Loading, you need to setup a web-readable directory (outside of your web space is better). Then setup a way to upload files in that dir, either by scp, ftp, or other protocols{/tr}
{preference name='fgal_batch_dir'}
<br /><em>{tr}The server must be able to read the directory.{/tr} {tr}The directory can be outside the web space.{/tr}</em>
</div>
{preference name='feature_file_galleries_author'}
{preference name='feature_file_galleries_author'}
</fieldset>
<fieldset>
<legend>{tr}Quota{/tr}{if $prefs.feature_help eq 'y'} {help url="File+Gallery+Config#Quota"}{/if}</legend>
{preference name='fgal_quota'}{tr}Used:{/tr} {$usedSize|kbsize}
<div class="adminoptionboxchild" id="fgal_quota_childcontainer">
{if !empty($prefs.fgal_quota)}
{capture name='use'}{math equation="round((100*x)/(1024*1024*y))" x=$usedSize y=$prefs.fgal_quota}{/capture}
{quotabar length='100' value='$smarty.capture.use'}
{/if}
</div>
{preference name='fgal_quota_per_fgal'}
<div class="adminoptionboxchild" id="fgal_quota_per_fgal_childcontainer">
{preference name='fgal_quota_default'}
</div>
</fieldset>
<fieldset>
......@@ -110,6 +125,7 @@
</div>
</div>
</div>
{preference name='fgal_quota_show'}
<div class="adminoptionbox">
<div class="adminoptionlabel">{tr}Select which items to display when listing galleries: {/tr}:</div>
......
......@@ -194,6 +194,13 @@ if (getCookie("fgalKeepOpen")) {
{if $files or ($find ne '')}
{include file='find.tpl' find_show_num_rows = 'y'}
{/if}
{if $prefs.fgal_quota_show eq 'y' && $gal_info['quota']}
<div style="float:right">
{capture name='use'}{math equation="round((100*x)/(1024*1024*y))" x=$gal_info['usedSize'] y=$gal_info['quota']}{/capture}
{quotabar length='100' value='$smarty.capture.use'}
</div>
{/if}
{include file='list_file_gallery.tpl'}
{if $galleryId gt 0
......
......@@ -30,6 +30,10 @@ if (isset($_REQUEST["filegalfeatures"])) {
simple_set_value("fgal_use_dir");
simple_set_value("fgal_podcast_dir");
simple_set_value("fgal_batch_dir");
if (!empty($_REQUEST['fgal_quota']) && !empty($_REQUEST['fgal_quota_default']) && $_REQUEST['fgal_quota_default'] > $_REQUEST['fgal_quota']) {
$_REQUEST['fgal_quota_default'] = $_REQUEST['fgal_quota'];
}
simple_set_value('fgal_quota_default');
}
if (isset($_REQUEST["filegallistprefs"])) {
check_ticket('admin-inc-fgal');
......@@ -39,7 +43,7 @@ if (isset($_REQUEST["filegallistprefs"])) {
simple_set_value('fgal_list_description');
simple_set_value('fgal_list_size');
simple_set_value('fgal_list_created');
simple_set_value('fgal_list_lastmodif');
simple_set_value('fgal_list_lastModif');
simple_set_value('fgal_list_creator');
simple_set_value('fgal_list_author');
simple_set_value('fgal_list_last_user');
......@@ -56,13 +60,19 @@ if (isset($_REQUEST["filegallistprefs"])) {
simple_set_value('fgal_default_view');
}
$usedSize = $filegallib->getUsedSize();
$smarty->assign_by_ref('usedSize', $usedSize);
if (isset($_REQUEST["filegalhandlers"])) {
check_ticket('admin-inc-fgal');
$mimes = $_REQUEST["mimes"];
foreach($mimes as $mime => $cmd) {
$mime = trim($mime);
if (empty($cmd)) $filegallib->delete_file_handler($mime);
else $filegallib->change_file_handler($mime, $cmd);
if (!empty($_REQUEST['mimes'])) {
$mimes = $_REQUEST['mimes'];
foreach($mimes as $mime => $cmd) {
$mime = trim($mime);
if (empty($cmd))
$filegallib->delete_file_handler($mime);
else
$filegallib->change_file_handler($mime, $cmd);
}
}
if (!empty($_REQUEST['newMime']) && !empty($_REQUEST['newCmd'])) {
$filegallib->change_file_handler($_REQUEST['newMime'], $_REQUEST['newCmd']);
......
......@@ -30,6 +30,8 @@ if ( empty($_REQUEST['galleryId']) && isset($_REQUEST['parentId']) ) {
// Initialize listing fields with default values (used for the main gallery listing)
$gal_info = $tikilib->get_file_gallery();
$gal_info['usedSize'] = 0;
$gal_info['maxQuota'] = $filegallib->getQuota($_REQUEST['parentId'], true);
} else {
if ( ! isset($_REQUEST['galleryId']) ) {
......@@ -47,6 +49,9 @@ if ( empty($_REQUEST['galleryId']) && isset($_REQUEST['parentId']) ) {
$smarty->display('error.tpl');
die;
}
$gal_info['usedSize'] = $filegallib->getUsedSize($_REQUEST['galleryId']);
$gal_info['maxQuota'] = $filegallib->getQuota($gal_info['parentId']);
$gal_info['minQuota'] = $filegallib->getMaxQuotaDescendants($_REQUEST['galleryId']);
}
$galleryId = $_REQUEST['galleryId'];
......@@ -315,7 +320,7 @@ if (isset($_REQUEST['edit'])) {
}
}
// Everything is ok so we proceed to edit the file or gallery
$request_vars = array('name', 'fname', 'description', 'fdescription', 'max_desc', 'fgal_type', 'maxRows', 'rowImages', 'thumbSizeX', 'thumbSizeY', 'parentId', 'creator');
$request_vars = array('name', 'fname', 'description', 'fdescription', 'max_desc', 'fgal_type', 'maxRows', 'rowImages', 'thumbSizeX', 'thumbSizeY', 'parentId', 'creator', 'quota');
foreach($request_vars as $v) {
if (isset($_REQUEST[$v])) {
$smarty->assign_by_ref($v, $_REQUEST[$v]);
......@@ -334,8 +339,16 @@ if (isset($_REQUEST['edit'])) {
$fid = $filegallib->replace_file($_REQUEST['fileId'], $_REQUEST['fname'], $_REQUEST['fdescription'], $info['filename'], $info['data'], $info['filesize'], $info['filetype'], $info['user'], $info['path'], $info['galleryId']);
$smarty->assign('edit_mode', 'n');
} else {
if ($prefs['fgal_quota_per_fgal'] != 'y') {
$_REQUEST['quota'] = 0;
}
if ($test = $filegallib->checkQuotaSetting($_REQUEST['quota'], $galleryId, $_REQUEST['parentId'])) {
$smarty->assign('msg', ($test > 0)?tra('Quota too big'):tra('Quota too small'));
$smarty->display('error.tpl');
die;
}
$old_gal_info = $filegallib->get_file_gallery_info($galleryId);
$gal_info = array('galleryId' => $galleryId, 'name' => $_REQUEST['name'], 'description' => $_REQUEST['description'], 'user' => $_REQUEST['user'], 'maxRows' => $_REQUEST['maxRows'], 'public' => $public, 'visible' => $visible, 'show_id' => $_REQUEST['fgal_list_id'], 'show_icon' => $_REQUEST['fgal_list_type'], 'show_name' => $_REQUEST['fgal_list_name'], 'show_size' => $_REQUEST['fgal_list_size'], 'show_description' => $_REQUEST['fgal_list_description'], 'show_created' => $_REQUEST['fgal_list_created'], 'show_hits' => $_REQUEST['fgal_list_hits'], 'max_desc' => $_REQUEST['max_desc'], 'type' => $_REQUEST['fgal_type'], 'parentId' => $_REQUEST['parentId'], 'lockable' => $lockable, 'show_lockedby' => $_REQUEST['fgal_list_lockedby'], 'archives' => $_REQUEST['archives'], 'sort_mode' => $_REQUEST['sortorder'] . '_' . $_REQUEST['sortdirection'], 'show_modified' => $_REQUEST['fgal_list_lastmodif'], 'show_creator' => $_REQUEST['fgal_list_creator'], 'show_author' => $_REQUEST['fgal_list_author'], 'subgal_conf' => $_REQUEST['subgal_conf'], 'show_last_user' => $_REQUEST['fgal_list_last_user'], 'show_comment' => $_REQUEST['fgal_list_comment'], 'show_files' => $_REQUEST['fgal_list_files'], 'show_explorer' => (isset($_REQUEST['fgal_show_explorer']) ? 'y' : 'n'), 'show_path' => (isset($_REQUEST['fgal_show_path']) ? 'y' : 'n'), 'show_slideshow' => (isset($_REQUEST['fgal_show_slideshow']) ? 'y' : 'n'), 'default_view' => $_REQUEST['fgal_default_view']);
$gal_info = array('galleryId' => $galleryId, 'name' => $_REQUEST['name'], 'description' => $_REQUEST['description'], 'user' => $_REQUEST['user'], 'maxRows' => $_REQUEST['maxRows'], 'public' => $public, 'visible' => $visible, 'show_id' => $_REQUEST['fgal_list_id'], 'show_icon' => $_REQUEST['fgal_list_type'], 'show_name' => $_REQUEST['fgal_list_name'], 'show_size' => $_REQUEST['fgal_list_size'], 'show_description' => $_REQUEST['fgal_list_description'], 'show_created' => $_REQUEST['fgal_list_created'], 'show_hits' => $_REQUEST['fgal_list_hits'], 'max_desc' => $_REQUEST['max_desc'], 'type' => $_REQUEST['fgal_type'], 'parentId' => $_REQUEST['parentId'], 'lockable' => $lockable, 'show_lockedby' => $_REQUEST['fgal_list_lockedby'], 'archives' => $_REQUEST['archives'], 'sort_mode' => $_REQUEST['sortorder'] . '_' . $_REQUEST['sortdirection'], 'show_modified' => $_REQUEST['fgal_list_lastModif'], 'show_creator' => $_REQUEST['fgal_list_creator'], 'show_author' => $_REQUEST['fgal_list_author'], 'subgal_conf' => $_REQUEST['subgal_conf'], 'show_last_user' => $_REQUEST['fgal_list_last_user'], 'show_comment' => $_REQUEST['fgal_list_comment'], 'show_files' => $_REQUEST['fgal_list_files'], 'show_explorer' => (isset($_REQUEST['fgal_show_explorer']) ? 'y' : 'n'), 'show_path' => (isset($_REQUEST['fgal_show_path']) ? 'y' : 'n'), 'show_slideshow' => (isset($_REQUEST['fgal_show_slideshow']) ? 'y' : 'n'), 'default_view' => $_REQUEST['fgal_default_view'], 'quota' => $_REQUEST['quota']);
if ($prefs['fgal_show_slideshow'] != 'y') {
$gal_info['show_slideshow'] = $old_gal_info['show_slideshow'];
}
......
......@@ -68,8 +68,9 @@ if (empty($_REQUEST['fileId']) && $tiki_p_upload_files != 'y' && $tiki_p_admin_f
if (isset($_REQUEST['galleryId'][1])) {
foreach($_REQUEST['galleryId'] as $i => $gal) {
if (!$i) continue;
$perms = $tikilib->get_perm_object($_REQUEST['galleryId'][$key], 'file gallery', $gal_info, false);
if ($perm['tiki_p_upload_files'] != 'y') {
// TODO get the ggod gal_info
$perms = $tikilib->get_perm_object($_REQUEST['galleryId'][$i], 'file gallery', $gal_info, false);
if ($perms['tiki_p_upload_files'] != 'y') {
$smarty->assign('errortype', 401);
$smarty->assign('msg', tra("Permission denied"));
$smarty->display('error.tpl');
......@@ -159,8 +160,12 @@ if (isset($_REQUEST["upload"])) {
}
$formId = $_REQUEST['formId'];
$smarty->assign("FormId", $_REQUEST['formId']);
if (empty($_REQUEST['galleryId'][$key])) continue;
if (!isset($_REQUEST['comment'][$key])) $_REQUEST['comment'][$key] = '';
if (empty($_REQUEST['galleryId'][$key])) {
continue;
}
if (!isset($_REQUEST['comment'][$key])) {
$_REQUEST['comment'][$key] = '';
}
// We process here file uploads
if (!empty($_FILES["userfile"]["name"][$key])) {
// Were there any problems with the upload? If so, report here.
......@@ -194,6 +199,10 @@ if (isset($_REQUEST["upload"])) {
continue;
}
}
if (!$filegallib->checkQuota($_FILES['userfile']['size'][$key], $_REQUEST['galleryId'][$key], $error)) {
$errors[] = $error;
continue;
}
$file_name = $_FILES["userfile"]["name"][$key];
$file_tmp_name = $_FILES["userfile"]["tmp_name"][$key];
$tmp_dest = $prefs['tmpDir'] . "/" . $file_name . ".tmp";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment