fixes #403 configuration of new album position

This commit is contained in:
jeremydurand
2016-06-13 17:37:55 +02:00
parent 4d75cf35b5
commit ba940dd503
2 changed files with 21 additions and 1 deletions

View File

@@ -1364,9 +1364,26 @@ function create_virtual_category($category_name, $parent_id=null, $options=array
return array('error' => l10n('The name of an album must not be empty'));
}
$rank = 0;
if ('last' == $conf['newcat_default_position'])
{
//what is the current higher rank for this parent?
$query = '
SELECT MAX(rank) AS max_rank
FROM '. CATEGORIES_TABLE .'
WHERE id_uppercat '.(empty($parent_id) ? 'IS NULL' : '= '.$parent_id).'
;';
$row = pwg_db_fetch_assoc(pwg_query($query));
if (is_numeric($row['max_rank']))
{
$rank = $row['max_rank'] + 1;
}
}
$insert = array(
'name' => $category_name,
'rank' => 0,
'rank' => $rank,
'global_rank' => 0,
);