1
|
<?php
|
2
|
|
3
|
// $Id: move_to.php 603 2008-01-26 16:02:19Z Ruebenwurzel $
|
4
|
|
5
|
// JsAdmin module for Website Baker
|
6
|
// Copyright (C) 2006, Stepan Riha
|
7
|
// www.nonplus.net
|
8
|
|
9
|
// modified by Swen Uth for Website Baker 2.7
|
10
|
|
11
|
/*
|
12
|
|
13
|
Website Baker Project <http://www.websitebaker.org/>
|
14
|
Copyright (C) 2004-2008, Ryan Djurovich
|
15
|
|
16
|
Website Baker is free software; you can redistribute it and/or modify
|
17
|
it under the terms of the GNU General Public License as published by
|
18
|
the Free Software Foundation; either version 2 of the License, or
|
19
|
(at your option) any later version.
|
20
|
|
21
|
Website Baker is distributed in the hope that it will be useful,
|
22
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
23
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
24
|
GNU General Public License for more details.
|
25
|
|
26
|
You should have received a copy of the GNU General Public License
|
27
|
along with Website Baker; if not, write to the Free Software
|
28
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
29
|
|
30
|
*/
|
31
|
|
32
|
require('../../config.php');
|
33
|
|
34
|
if(isset($_GET['page_id']) AND is_numeric($_GET['page_id']) AND is_numeric(@$_GET['position'])) {
|
35
|
$position = $_GET['position'];
|
36
|
|
37
|
// Get common fields
|
38
|
if(isset($_GET['section_id']) AND is_numeric($_GET['section_id'])) {
|
39
|
$page_id = $_GET['page_id'];
|
40
|
$id = $_GET['section_id'];
|
41
|
$id_field = 'section_id';
|
42
|
$common_field = 'page_id';
|
43
|
$table = TABLE_PREFIX.'sections';
|
44
|
} else {
|
45
|
$id = $_GET['page_id'];
|
46
|
$id_field = 'page_id';
|
47
|
$common_field = 'parent';
|
48
|
$table = TABLE_PREFIX.'pages';
|
49
|
}
|
50
|
|
51
|
// Get current index
|
52
|
$sql = <<<EOT
|
53
|
SELECT $common_field, position FROM $table WHERE $id_field = $id
|
54
|
EOT;
|
55
|
echo "$sql<br>";
|
56
|
$rs = $database->query($sql);
|
57
|
if($row = $rs->fetchRow()) {
|
58
|
$common_id = $row[$common_field];
|
59
|
$old_position = $row['position'];
|
60
|
}
|
61
|
echo "$old_position<br>";
|
62
|
if($old_position == $position)
|
63
|
return;
|
64
|
|
65
|
// Build query to update affected rows
|
66
|
if($old_position < $position)
|
67
|
$sql = <<<EOT
|
68
|
UPDATE $table SET position = position - 1
|
69
|
WHERE position > $old_position AND position <= $position
|
70
|
AND $common_field = $common_id
|
71
|
EOT;
|
72
|
else
|
73
|
$sql = <<<EOT
|
74
|
UPDATE $table SET position = position + 1
|
75
|
WHERE position >= $position AND position < $old_position
|
76
|
AND $common_field = $common_id
|
77
|
EOT;
|
78
|
echo "<pre>$sql</pre>";
|
79
|
$database->query($sql);
|
80
|
|
81
|
// Build query to update specified row
|
82
|
$sql = <<<EOT
|
83
|
UPDATE $table SET position = $position
|
84
|
WHERE $id_field = $id
|
85
|
EOT;
|
86
|
echo "<pre>$sql</pre>";
|
87
|
$database->query($sql);
|
88
|
} else {
|
89
|
die("Missing parameters");
|
90
|
header("Location: index.php");
|
91
|
exit(0);
|
92
|
}
|
93
|
?>
|