1 |
1380
|
Luisehahne
|
<?php
|
2 |
1383
|
FrankH
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category modules
|
5 |
|
|
* @package JsAdmin
|
6 |
|
|
* @author WebsiteBaker Project, modified by Swen Uth for Website Baker 2.7
|
7 |
|
|
* @copyright (C) 2006, Stepan Riha
|
8 |
|
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
9 |
|
|
* @link http://www.websitebaker2.org/
|
10 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
11 |
|
|
* @platform WebsiteBaker 2.8.x
|
12 |
|
|
* @requirements PHP 5.2.2 and higher
|
13 |
|
|
* @version $Id$
|
14 |
|
|
* @filesource $HeadURL$
|
15 |
|
|
* @lastmodified $Date$
|
16 |
|
|
*
|
17 |
1380
|
Luisehahne
|
*/
|
18 |
|
|
|
19 |
|
|
require('../../config.php');
|
20 |
|
|
|
21 |
|
|
if(isset($_GET['page_id']) AND is_numeric($_GET['page_id']) AND is_numeric(@$_GET['position'])) {
|
22 |
|
|
$position = $_GET['position'];
|
23 |
|
|
|
24 |
|
|
// Include WB admin wrapper script
|
25 |
|
|
$update_when_modified = true; // Tells script to update when this page was last updated
|
26 |
|
|
require(WB_PATH.'/modules/admin.php');
|
27 |
|
|
|
28 |
|
|
// Get common fields
|
29 |
|
|
if(isset($_GET['section_id']) AND is_numeric($_GET['section_id'])) {
|
30 |
|
|
$page_id = $_GET['page_id'];
|
31 |
|
|
$id = $_GET['section_id'];
|
32 |
|
|
$id_field = 'section_id';
|
33 |
|
|
$common_field = 'page_id';
|
34 |
|
|
$table = TABLE_PREFIX.'sections';
|
35 |
|
|
} else {
|
36 |
|
|
$id = $_GET['page_id'];
|
37 |
|
|
$id_field = 'page_id';
|
38 |
|
|
$common_field = 'parent';
|
39 |
|
|
$table = TABLE_PREFIX.'pages';
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
// Get current index
|
43 |
|
|
$sql = <<<EOT
|
44 |
|
|
SELECT $common_field, position FROM $table WHERE $id_field = $id
|
45 |
|
|
EOT;
|
46 |
|
|
echo "$sql<br>";
|
47 |
|
|
$rs = $database->query($sql);
|
48 |
|
|
if($row = $rs->fetchRow()) {
|
49 |
|
|
$common_id = $row[$common_field];
|
50 |
|
|
$old_position = $row['position'];
|
51 |
|
|
}
|
52 |
|
|
echo "$old_position<br>";
|
53 |
|
|
if($old_position == $position)
|
54 |
|
|
return;
|
55 |
|
|
|
56 |
|
|
// Build query to update affected rows
|
57 |
|
|
if($old_position < $position)
|
58 |
|
|
$sql = <<<EOT
|
59 |
|
|
UPDATE $table SET position = position - 1
|
60 |
|
|
WHERE position > $old_position AND position <= $position
|
61 |
|
|
AND $common_field = $common_id
|
62 |
|
|
EOT;
|
63 |
|
|
else
|
64 |
|
|
$sql = <<<EOT
|
65 |
|
|
UPDATE $table SET position = position + 1
|
66 |
|
|
WHERE position >= $position AND position < $old_position
|
67 |
|
|
AND $common_field = $common_id
|
68 |
|
|
EOT;
|
69 |
|
|
echo "<pre>$sql</pre>";
|
70 |
|
|
$database->query($sql);
|
71 |
|
|
|
72 |
|
|
// Build query to update specified row
|
73 |
|
|
$sql = <<<EOT
|
74 |
|
|
UPDATE $table SET position = $position
|
75 |
|
|
WHERE $id_field = $id
|
76 |
|
|
EOT;
|
77 |
|
|
echo "<pre>$sql</pre>";
|
78 |
|
|
$database->query($sql);
|
79 |
|
|
} else {
|
80 |
|
|
die("Missing parameters");
|
81 |
|
|
header("Location: index.php");
|
82 |
|
|
exit(0);
|
83 |
|
|
}
|
84 |
|
|
?>
|