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,2009-2012, WebsiteBaker Org. e.V.
|
8
|
* @link http://www.websitebaker2.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: move_to.php 1835 2012-12-10 18:39:34Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/jsadmin/move_to.php $
|
14
|
* @lastmodified $Date: 2012-12-10 19:39:34 +0100 (Mon, 10 Dec 2012) $
|
15
|
*
|
16
|
*/
|
17
|
|
18
|
// Include config file
|
19
|
if(!defined('WB_URL'))
|
20
|
{
|
21
|
$config_file = realpath('../../config.php');
|
22
|
if(file_exists($config_file) && !defined('WB_URL'))
|
23
|
{
|
24
|
require($config_file);
|
25
|
}
|
26
|
}
|
27
|
|
28
|
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
|
29
|
$admin = new admin('##skip##');
|
30
|
if(isset($_GET['page_id']) AND is_numeric($_GET['page_id']) AND is_numeric(@$_GET['position'])) {
|
31
|
$position = (int)$_GET['position'];
|
32
|
$bModified = true;
|
33
|
$bDebug = false;
|
34
|
// Include WB admin wrapper script
|
35
|
// $update_when_modified = true;
|
36
|
// Tells script to update when this page was last updated
|
37
|
// require(WB_PATH.'/modules/admin.php');
|
38
|
|
39
|
if( isset($_GET['file_id']) || (isset($_GET['group_id'])) ) {
|
40
|
if(isset($_GET['group_id']) && is_numeric($_GET['group_id'])) {
|
41
|
$id = (int)$_GET['group_id'];
|
42
|
$id_field = 'group_id';
|
43
|
$table = TABLE_PREFIX.'mod_download_gallery_groups';
|
44
|
$common_field = 'section_id';
|
45
|
} else {
|
46
|
$id = (int)$_GET['file_id'];
|
47
|
$id_field = 'file_id';
|
48
|
$table = TABLE_PREFIX.'mod_download_gallery_files';
|
49
|
$common_field = 'group_id';
|
50
|
}
|
51
|
} elseif( isset($_GET['page_id']) || (isset($_GET['section_id'])) ) {
|
52
|
// Get common fields
|
53
|
if(isset($_GET['section_id']) && is_numeric($_GET['section_id'])) {
|
54
|
$page_id = (int)$_GET['page_id'];
|
55
|
$id = (int)$_GET['section_id'];
|
56
|
$id_field = 'section_id';
|
57
|
$common_field = 'page_id';
|
58
|
$table = TABLE_PREFIX.'sections';
|
59
|
} else {
|
60
|
$id = (int)$_GET['page_id'];
|
61
|
$id_field = 'page_id';
|
62
|
$common_field = 'parent';
|
63
|
$table = TABLE_PREFIX.'pages';
|
64
|
}
|
65
|
}
|
66
|
$bModified = ($id_field == 'page_id') ? $bModified : false;
|
67
|
|
68
|
$iPageId = intval($_GET['page_id']);
|
69
|
// Get current index
|
70
|
$sql = 'SELECT `'.$common_field.'`,`position` FROM `'.$table.'` WHERE `'.$id_field.'` ='.(int)$id; //.' AND page_id='.$iPageId;
|
71
|
if($oRes=$database->query($sql)) {
|
72
|
if($aPage = $oRes->fetchRow(MYSQL_ASSOC)){
|
73
|
$common_id = intval($aPage[$common_field]);
|
74
|
$old_position = intval($aPage['position']);
|
75
|
}
|
76
|
}
|
77
|
|
78
|
/*
|
79
|
// Get current index
|
80
|
$sql = <<<EOT
|
81
|
SELECT `$common_field`, `position` FROM `$table` WHERE `$id_field` = $id
|
82
|
EOT;
|
83
|
echo "$sql<br>";
|
84
|
$rs = $database->query($sql);
|
85
|
if($row = $rs->fetchRow()) {
|
86
|
$common_id = $row[$common_field];
|
87
|
$old_position = $row['position'];
|
88
|
}
|
89
|
echo "$old_position<br>";
|
90
|
if($old_position == $position)
|
91
|
return;
|
92
|
*/
|
93
|
|
94
|
// all echos with <pre> coded for looking in firebug console
|
95
|
$sSqlModify = ($bModified == true) ? ',`modified_when` = '.time().',`modified_by` = '.$admin->get_user_id().' ' : '';
|
96
|
if($old_position != $position) {
|
97
|
}
|
98
|
echo $output = ($bDebug == false) ? "\n" : "<pre>$sql</pre>\n";
|
99
|
// Build query to update affected rows
|
100
|
if($old_position < $position)
|
101
|
$sql = <<<EOT
|
102
|
UPDATE `$table` SET `position` = `position` - 1
|
103
|
WHERE `position` > $old_position AND `position` <= $position
|
104
|
AND `$common_field` = $common_id
|
105
|
EOT;
|
106
|
else
|
107
|
$sql = <<<EOT
|
108
|
UPDATE `$table` SET `position` = `position` + 1
|
109
|
WHERE `position` >= $position AND `position` < $old_position
|
110
|
AND `$common_field` = $common_id
|
111
|
EOT;
|
112
|
echo $output = ($bDebug == false) ? "\n" : "<pre>$sql</pre>\n";
|
113
|
$database->query($sql);
|
114
|
// Build query to update specified row
|
115
|
$sql = <<<EOT
|
116
|
UPDATE `$table` SET `position` = $position$sSqlModify
|
117
|
WHERE `$id_field` = $id
|
118
|
EOT;
|
119
|
echo $output = ($bDebug == false) ? "\n" : "<pre>$sql</pre>\n";
|
120
|
$database->query($sql);
|
121
|
if(!class_exists('order', false)){ include(WB_PATH.'/framework/class.order.php'); }
|
122
|
$order = new order($table, 'position', $id_field, $common_field);
|
123
|
$order->clean($common_id);
|
124
|
echo $output = ($bDebug == false) ? "\n" : "<pre>$table,'position','$id_field','$common_field'</pre>\n";
|
125
|
echo $output = ($bDebug == false) ? "\n" : "<pre>$common_id</pre>\n";
|
126
|
|
127
|
} else {
|
128
|
die("Missing parameters");
|
129
|
header("Location: index.php");
|
130
|
exit(0);
|
131
|
}
|