Project

General

Profile

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 1831 2012-12-04 22:42:12Z 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-04 23:42:12 +0100 (Tue, 04 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

    
67
    $iPageId = intval($_GET['page_id']);
68
	// Get current index
69
    $sql = 'SELECT `'.$common_field.'`,`position`,`page_id` FROM `'.$table.'` WHERE `'.$id_field.'` ='.(int)$id; //.' AND page_id='.$iPageId;
70
    if($oRes=$database->query($sql)) {
71
        if($aPage = $oRes->fetchRow(MYSQL_ASSOC)){
72
    		$common_id = intval($aPage[$common_field]);
73
    		$old_position = intval($aPage['position']);
74
    		$iPageId = intval($aPage['page_id']);
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
// all echos with <pre> coded for looking in firebug console
94
$sSqlModify =  ($bModified == true) ? ',`modified_when` = '.time().',`modified_by` = '.$admin->get_user_id().' ' : '';
95
if($old_position != $position) {
96
	echo $output = ($bDebug == false) ? "\n" : "<pre>$sql</pre>\n";
97
	// Build query to update affected rows
98
	if($old_position < $position)
99
		$sql = <<<EOT
100
UPDATE `$table` SET `position` = `position` - 1
101
	WHERE `position` > $old_position AND `position` <= $position
102
		AND `$common_field` = $common_id
103
EOT;
104
	else
105
		$sql = <<<EOT
106
UPDATE `$table` SET `position` = `position` + 1
107
	WHERE `position` >= $position AND `position` < $old_position
108
		AND `$common_field` = $common_id
109
EOT;
110
	echo $output = ($bDebug == false) ? "\n" : "<pre>$sql</pre>\n";
111
	$database->query($sql);
112
	// Build query to update specified row
113
	$sql = <<<EOT
114
UPDATE `$table` SET `position` = $position$sSqlModify
115
	WHERE `$id_field` = $id
116
EOT;
117
	echo $output = ($bDebug == false) ? "\n" : "<pre>$sql</pre>\n";
118
	$database->query($sql);
119
}
120
} else {
121
	die("Missing parameters");
122
	header("Location: index.php");
123
	exit(0);
124
}
(9-9/13)