| 1 | 
        
            601
         | 
        
            doc
         | 
        <?php
  | 
      
      
        | 2 | 
        
         | 
        
         | 
        
  | 
      
      
        | 3 | 
        
         | 
        
         | 
        // $Id$
  | 
      
      
        | 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 | 
        
            915
         | 
        
            Ruebenwurz
         | 
         Copyright (C) 2004-2009, Ryan Djurovich
  | 
      
      
        | 15 | 
        
            601
         | 
        
            doc
         | 
        
  | 
      
      
        | 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 | 
        
         | 
        
         | 
        require('../../config.php');
 | 
      
      
        | 33 | 
        
         | 
        
         | 
        
  | 
      
      
        | 34 | 
        
            677
         | 
        
            thorn
         | 
         if(isset($_GET['page_id']) AND is_numeric($_GET['page_id']) AND is_numeric(@$_GET['position'])) {
 | 
      
      
        | 35 | 
        
            601
         | 
        
            doc
         | 
        	$position = $_GET['position'];
  | 
      
      
        | 36 | 
        
         | 
        
         | 
        
  | 
      
      
        | 37 | 
        
            679
         | 
        
            thorn
         | 
        	// Include WB admin wrapper script
  | 
      
      
        | 38 | 
        
         | 
        
         | 
        	$update_when_modified = true; // Tells script to update when this page was last updated
  | 
      
      
        | 39 | 
        
         | 
        
         | 
        	require(WB_PATH.'/modules/admin.php');
  | 
      
      
        | 40 | 
        
         | 
        
         | 
        
  | 
      
      
        | 41 | 
        
            601
         | 
        
            doc
         | 
        	// Get common fields
  | 
      
      
        | 42 | 
        
         | 
        
         | 
        	if(isset($_GET['section_id']) AND is_numeric($_GET['section_id'])) {
 | 
      
      
        | 43 | 
        
         | 
        
         | 
        		$page_id = $_GET['page_id'];
  | 
      
      
        | 44 | 
        
         | 
        
         | 
        		$id = $_GET['section_id'];
  | 
      
      
        | 45 | 
        
         | 
        
         | 
        		$id_field = 'section_id';
  | 
      
      
        | 46 | 
        
         | 
        
         | 
        		$common_field = 'page_id';
  | 
      
      
        | 47 | 
        
         | 
        
         | 
        		$table = TABLE_PREFIX.'sections';
  | 
      
      
        | 48 | 
        
         | 
        
         | 
        	} else {
 | 
      
      
        | 49 | 
        
         | 
        
         | 
        		$id = $_GET['page_id'];
  | 
      
      
        | 50 | 
        
         | 
        
         | 
        		$id_field = 'page_id';
  | 
      
      
        | 51 | 
        
         | 
        
         | 
        		$common_field = 'parent';
  | 
      
      
        | 52 | 
        
         | 
        
         | 
        		$table = TABLE_PREFIX.'pages';
  | 
      
      
        | 53 | 
        
         | 
        
         | 
        	}
  | 
      
      
        | 54 | 
        
         | 
        
         | 
        
  | 
      
      
        | 55 | 
        
         | 
        
         | 
        	// Get current index
  | 
      
      
        | 56 | 
        
         | 
        
         | 
        	$sql = <<<EOT
  | 
      
      
        | 57 | 
        
         | 
        
         | 
        SELECT $common_field, position FROM $table WHERE $id_field = $id
  | 
      
      
        | 58 | 
        
         | 
        
         | 
        EOT;
  | 
      
      
        | 59 | 
        
         | 
        
         | 
        	echo "$sql<br>";
  | 
      
      
        | 60 | 
        
         | 
        
         | 
        	$rs = $database->query($sql);
  | 
      
      
        | 61 | 
        
         | 
        
         | 
        	if($row = $rs->fetchRow()) {
 | 
      
      
        | 62 | 
        
         | 
        
         | 
        		$common_id = $row[$common_field];
  | 
      
      
        | 63 | 
        
         | 
        
         | 
        		$old_position = $row['position'];
  | 
      
      
        | 64 | 
        
         | 
        
         | 
        	}
  | 
      
      
        | 65 | 
        
         | 
        
         | 
        	echo "$old_position<br>";
  | 
      
      
        | 66 | 
        
         | 
        
         | 
        	if($old_position == $position)
  | 
      
      
        | 67 | 
        
         | 
        
         | 
        		return;
  | 
      
      
        | 68 | 
        
         | 
        
         | 
        
  | 
      
      
        | 69 | 
        
         | 
        
         | 
        	// Build query to update affected rows
  | 
      
      
        | 70 | 
        
         | 
        
         | 
        	if($old_position < $position)
  | 
      
      
        | 71 | 
        
         | 
        
         | 
        		$sql = <<<EOT
  | 
      
      
        | 72 | 
        
         | 
        
         | 
        UPDATE $table SET position = position - 1
  | 
      
      
        | 73 | 
        
         | 
        
         | 
        	WHERE position > $old_position AND position <= $position
  | 
      
      
        | 74 | 
        
         | 
        
         | 
        		AND $common_field = $common_id
  | 
      
      
        | 75 | 
        
         | 
        
         | 
        EOT;
  | 
      
      
        | 76 | 
        
         | 
        
         | 
        	else
  | 
      
      
        | 77 | 
        
         | 
        
         | 
        		$sql = <<<EOT
  | 
      
      
        | 78 | 
        
         | 
        
         | 
        UPDATE $table SET position = position + 1
  | 
      
      
        | 79 | 
        
         | 
        
         | 
        	WHERE position >= $position AND position < $old_position
  | 
      
      
        | 80 | 
        
         | 
        
         | 
        		AND $common_field = $common_id
  | 
      
      
        | 81 | 
        
         | 
        
         | 
        EOT;
  | 
      
      
        | 82 | 
        
         | 
        
         | 
        	echo "<pre>$sql</pre>";
  | 
      
      
        | 83 | 
        
         | 
        
         | 
        	$database->query($sql);
  | 
      
      
        | 84 | 
        
         | 
        
         | 
        
  | 
      
      
        | 85 | 
        
         | 
        
         | 
        	// Build query to update specified row
  | 
      
      
        | 86 | 
        
         | 
        
         | 
        	$sql = <<<EOT
  | 
      
      
        | 87 | 
        
         | 
        
         | 
        UPDATE $table SET position = $position
  | 
      
      
        | 88 | 
        
         | 
        
         | 
        	WHERE $id_field = $id
  | 
      
      
        | 89 | 
        
         | 
        
         | 
        EOT;
  | 
      
      
        | 90 | 
        
         | 
        
         | 
        	echo "<pre>$sql</pre>";
  | 
      
      
        | 91 | 
        
         | 
        
         | 
        	$database->query($sql);
  | 
      
      
        | 92 | 
        
         | 
        
         | 
        } else {
 | 
      
      
        | 93 | 
        
         | 
        
         | 
        	die("Missing parameters");
 | 
      
      
        | 94 | 
        
         | 
        
         | 
        	header("Location: index.php");
 | 
      
      
        | 95 | 
        
         | 
        
         | 
        	exit(0);
  | 
      
      
        | 96 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 97 | 
        
         | 
        
         | 
        ?>
  |