1
|
<?php
|
2
|
/**
|
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: move_to.php 1441 2011-04-09 23:04:22Z Luisehahne $
|
14
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/tags/2.8.3/wb/modules/jsadmin/move_to.php $
|
15
|
* @lastmodified $Date: 2011-04-10 01:04:22 +0200 (Sun, 10 Apr 2011) $
|
16
|
*
|
17
|
*/
|
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 = (int)$_GET['position'];
|
23
|
|
24
|
// Include WB admin wrapper script
|
25
|
$update_when_modified = true;
|
26
|
// Tells script to update when this page was last updated
|
27
|
require(WB_PATH.'/modules/admin.php');
|
28
|
|
29
|
if( isset($_GET['file_id']) || (isset($_GET['group_id'])) ) {
|
30
|
if(isset($_GET['group_id']) && is_numeric($_GET['group_id'])) {
|
31
|
$id = (int)$_GET['group_id'];
|
32
|
$id_field = 'group_id';
|
33
|
$table = TABLE_PREFIX.'mod_download_gallery_groups';
|
34
|
$common_field = 'section_id';
|
35
|
} else {
|
36
|
$id = (int)$_GET['file_id'];
|
37
|
$id_field = 'file_id';
|
38
|
$table = TABLE_PREFIX.'mod_download_gallery_files';
|
39
|
$common_field = 'group_id';
|
40
|
}
|
41
|
} elseif( isset($_GET['page_id']) || (isset($_GET['section_id'])) ) {
|
42
|
// Get common fields
|
43
|
if(isset($_GET['section_id']) && is_numeric($_GET['section_id'])) {
|
44
|
$page_id = (int)$_GET['page_id'];
|
45
|
$id = (int)$_GET['section_id'];
|
46
|
$id_field = 'section_id';
|
47
|
$common_field = 'page_id';
|
48
|
$table = TABLE_PREFIX.'sections';
|
49
|
} else {
|
50
|
$id = (int)$_GET['page_id'];
|
51
|
$id_field = 'page_id';
|
52
|
$common_field = 'parent';
|
53
|
$table = TABLE_PREFIX.'pages';
|
54
|
}
|
55
|
}
|
56
|
|
57
|
// Get current index
|
58
|
$sql = <<<EOT
|
59
|
SELECT $common_field, position FROM $table WHERE $id_field = $id
|
60
|
EOT;
|
61
|
echo "$sql<br>";
|
62
|
$rs = $database->query($sql);
|
63
|
if($row = $rs->fetchRow()) {
|
64
|
$common_id = $row[$common_field];
|
65
|
$old_position = $row['position'];
|
66
|
}
|
67
|
echo "$old_position<br>";
|
68
|
if($old_position == $position)
|
69
|
return;
|
70
|
|
71
|
// Build query to update affected rows
|
72
|
if($old_position < $position)
|
73
|
$sql = <<<EOT
|
74
|
UPDATE $table SET position = position - 1
|
75
|
WHERE position > $old_position AND position <= $position
|
76
|
AND $common_field = $common_id
|
77
|
EOT;
|
78
|
else
|
79
|
$sql = <<<EOT
|
80
|
UPDATE $table SET position = position + 1
|
81
|
WHERE position >= $position AND position < $old_position
|
82
|
AND $common_field = $common_id
|
83
|
EOT;
|
84
|
echo "<pre>$sql</pre>";
|
85
|
$database->query($sql);
|
86
|
|
87
|
// Build query to update specified row
|
88
|
$sql = <<<EOT
|
89
|
UPDATE $table SET position = $position
|
90
|
WHERE $id_field = $id
|
91
|
EOT;
|
92
|
echo "<pre>$sql</pre>";
|
93
|
$database->query($sql);
|
94
|
} else {
|
95
|
die("Missing parameters");
|
96
|
header("Location: index.php");
|
97
|
exit(0);
|
98
|
}
|