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 |
1831
|
Luisehahne
|
* @copyright (C) 2006, Stepan Riha,2009-2012, WebsiteBaker Org. e.V.
|
8 |
1383
|
FrankH
|
* @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$
|
13 |
|
|
* @filesource $HeadURL$
|
14 |
|
|
* @lastmodified $Date$
|
15 |
|
|
*
|
16 |
1831
|
Luisehahne
|
*/
|
17 |
1380
|
Luisehahne
|
|
18 |
1831
|
Luisehahne
|
// 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 |
1380
|
Luisehahne
|
|
28 |
1831
|
Luisehahne
|
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
|
29 |
|
|
$admin = new admin('##skip##');
|
30 |
1441
|
Luisehahne
|
if(isset($_GET['page_id']) AND is_numeric($_GET['page_id']) AND is_numeric(@$_GET['position'])) {
|
31 |
|
|
$position = (int)$_GET['position'];
|
32 |
1831
|
Luisehahne
|
$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 |
1380
|
Luisehahne
|
|
39 |
1831
|
Luisehahne
|
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 |
1835
|
Luisehahne
|
$bModified = ($id_field == 'page_id') ? $bModified : false;
|
67 |
1380
|
Luisehahne
|
|
68 |
1831
|
Luisehahne
|
$iPageId = intval($_GET['page_id']);
|
69 |
|
|
// Get current index
|
70 |
1835
|
Luisehahne
|
$sql = 'SELECT `'.$common_field.'`,`position` FROM `'.$table.'` WHERE `'.$id_field.'` ='.(int)$id; //.' AND page_id='.$iPageId;
|
71 |
1831
|
Luisehahne
|
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 |
1380
|
Luisehahne
|
|
78 |
1831
|
Luisehahne
|
/*
|
79 |
1380
|
Luisehahne
|
// Get current index
|
80 |
|
|
$sql = <<<EOT
|
81 |
1831
|
Luisehahne
|
SELECT `$common_field`, `position` FROM `$table` WHERE `$id_field` = $id
|
82 |
1380
|
Luisehahne
|
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 |
1831
|
Luisehahne
|
*/
|
93 |
1835
|
Luisehahne
|
|
94 |
1831
|
Luisehahne
|
// 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 |
1835
|
Luisehahne
|
}
|
98 |
1831
|
Luisehahne
|
echo $output = ($bDebug == false) ? "\n" : "<pre>$sql</pre>\n";
|
99 |
1380
|
Luisehahne
|
// Build query to update affected rows
|
100 |
|
|
if($old_position < $position)
|
101 |
|
|
$sql = <<<EOT
|
102 |
1831
|
Luisehahne
|
UPDATE `$table` SET `position` = `position` - 1
|
103 |
|
|
WHERE `position` > $old_position AND `position` <= $position
|
104 |
|
|
AND `$common_field` = $common_id
|
105 |
1380
|
Luisehahne
|
EOT;
|
106 |
|
|
else
|
107 |
|
|
$sql = <<<EOT
|
108 |
1831
|
Luisehahne
|
UPDATE `$table` SET `position` = `position` + 1
|
109 |
|
|
WHERE `position` >= $position AND `position` < $old_position
|
110 |
|
|
AND `$common_field` = $common_id
|
111 |
1380
|
Luisehahne
|
EOT;
|
112 |
1831
|
Luisehahne
|
echo $output = ($bDebug == false) ? "\n" : "<pre>$sql</pre>\n";
|
113 |
1380
|
Luisehahne
|
$database->query($sql);
|
114 |
|
|
// Build query to update specified row
|
115 |
|
|
$sql = <<<EOT
|
116 |
1831
|
Luisehahne
|
UPDATE `$table` SET `position` = $position$sSqlModify
|
117 |
|
|
WHERE `$id_field` = $id
|
118 |
1380
|
Luisehahne
|
EOT;
|
119 |
1831
|
Luisehahne
|
echo $output = ($bDebug == false) ? "\n" : "<pre>$sql</pre>\n";
|
120 |
1380
|
Luisehahne
|
$database->query($sql);
|
121 |
1835
|
Luisehahne
|
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 |
1380
|
Luisehahne
|
} else {
|
128 |
|
|
die("Missing parameters");
|
129 |
|
|
header("Location: index.php");
|
130 |
|
|
exit(0);
|
131 |
|
|
}
|