3 * Copyright 2003 Mark O'Sullivan
4 * This file is part of Vanilla.
5 * Vanilla is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
6 * Vanilla is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
7 * You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8 * The latest source code for Vanilla is available at www.lussumo.com
9 * Contact Mark O'Sullivan at mark [at] lussumo [dot] com
11 * Description: File used by Dynamic Data Management object to change the order of categories
14 include('../appg/settings.php');
15 include('../appg/init_ajax.php');
17 $PostBackKey = ForceIncomingString('PostBackKey', '');
18 if ($PostBackKey == ''
19 ||
$PostBackKey !== $Context->Session
->GetCsrfValidationKey()
21 die($Context->GetDefinition('ErrPostBackKeyInvalid'));
24 if (!$Context->Session
->User
->Permission('PERMISSION_SORT_CATEGORIES')) {
25 die($Context->GetDefinition('ErrPermissionSortCategories'));
28 $Sql = 'update '. GetTableName('Category', $DatabaseTables, $Configuration["DATABASE_TABLE_PREFIX"])
29 . ' set ' . $DatabaseColumns['Category']['Priority'] . " = '//1' where "
30 . $DatabaseColumns['Category']['CategoryID'] ." = '//2';";
32 $SortOrder = ForceIncomingArray('CategoryID', array());
33 $ItemCount = count($SortOrder);
34 for ($i = 0; $i < $ItemCount; $i++
) {
35 $CatID = ForceInt($SortOrder[$i], null);
36 if ($CatID !== null) {
37 $ExecSql = str_replace(array('//1', '//2'), array($i, $CatID), $Sql);
38 $Context->Database
->Execute($ExecSql, 'AJAX', 'ReorderCategories', 'Failed to reorder categories', 0);