1
|
<?php
|
2
|
|
3
|
// $Id: move_to.php 677 2008-02-08 23:29:50Z thorn $
|
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
|
// prevent this file from being accessed directly
|
33
|
if(!defined('WB_PATH')) { exit('Cannot access this file directly'); }
|
34
|
require('../../config.php');
|
35
|
|
36
|
if(isset($_GET['page_id']) AND is_numeric($_GET['page_id']) AND is_numeric(@$_GET['position'])) {
|
37
|
$position = $_GET['position'];
|
38
|
|
39
|
// Get common fields
|
40
|
if(isset($_GET['section_id']) AND is_numeric($_GET['section_id'])) {
|
41
|
$page_id = $_GET['page_id'];
|
42
|
$id = $_GET['section_id'];
|
43
|
$id_field = 'section_id';
|
44
|
$common_field = 'page_id';
|
45
|
$table = TABLE_PREFIX.'sections';
|
46
|
} else {
|
47
|
$id = $_GET['page_id'];
|
48
|
$id_field = 'page_id';
|
49
|
$common_field = 'parent';
|
50
|
$table = TABLE_PREFIX.'pages';
|
51
|
}
|
52
|
|
53
|
// Get current index
|
54
|
$sql = <<<EOT
|
55
|
SELECT $common_field, position FROM $table WHERE $id_field = $id
|
56
|
EOT;
|
57
|
echo "$sql<br>";
|
58
|
$rs = $database->query($sql);
|
59
|
if($row = $rs->fetchRow()) {
|
60
|
$common_id = $row[$common_field];
|
61
|
$old_position = $row['position'];
|
62
|
}
|
63
|
echo "$old_position<br>";
|
64
|
if($old_position == $position)
|
65
|
return;
|
66
|
|
67
|
// Build query to update affected rows
|
68
|
if($old_position < $position)
|
69
|
$sql = <<<EOT
|
70
|
UPDATE $table SET position = position - 1
|
71
|
WHERE position > $old_position AND position <= $position
|
72
|
AND $common_field = $common_id
|
73
|
EOT;
|
74
|
else
|
75
|
$sql = <<<EOT
|
76
|
UPDATE $table SET position = position + 1
|
77
|
WHERE position >= $position AND position < $old_position
|
78
|
AND $common_field = $common_id
|
79
|
EOT;
|
80
|
echo "<pre>$sql</pre>";
|
81
|
$database->query($sql);
|
82
|
|
83
|
// Build query to update specified row
|
84
|
$sql = <<<EOT
|
85
|
UPDATE $table SET position = $position
|
86
|
WHERE $id_field = $id
|
87
|
EOT;
|
88
|
echo "<pre>$sql</pre>";
|
89
|
$database->query($sql);
|
90
|
} else {
|
91
|
die("Missing parameters");
|
92
|
header("Location: index.php");
|
93
|
exit(0);
|
94
|
}
|
95
|
?>
|