summaryrefslogtreecommitdiff
path: root/edit_structure_inc.php
blob: cef5c9cd990a322363e3cd5a4e9d6f2de94c8191 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
 * edit_structure_inc
 *
 * @author   Christian Fowler>
 * @version  $Revision: 1.18 $
 * @package  liberty
 * @subpackage functions
 */

// Copyright (c) 2004, Christian Fowler, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.

/**
 * required setup
 */
require_once( '../bit_setup_inc.php' );
include_once( LIBERTY_PKG_PATH.'LibertyStructure.php');
$gBitSmarty->assign_by_ref( 'feedback', $feedback = array() );

if( !@BitBase::verifyId( $_REQUEST["structure_id"] ) ) {
	$gBitSystem->fatalError( "No structure indicated" );
} else {
	global $gStructure;
	$gStructure = new LibertyStructure( $_REQUEST["structure_id"] );
	$gStructure->load();

	// order matters for these conditionals
	if( empty( $gStructure ) || !$gStructure->isValid() ) {
		$gBitSystem->fatalError( 'Invalid structure' );
	}

	if( $gStructure->mInfo['root_structure_id'] == $gStructure->mInfo['structure_id'] ) {
		$rootStructure = &$gStructure;
	} else {
		$rootStructure = new LibertyStructure( $gStructure->mInfo['root_structure_id'] );
		$rootStructure->load();
		$rootStructure->loadNavigation();
		$rootStructure->loadPath();
	}

	if( ( $gBitUser->mUserId != $rootStructure->mInfo['user_id'] ) ) {
		$gBitSystem->verifyPermission( !empty( $verifyStructurePermission ) ? $verifyStructurePermission : 'p_admin' );
	}
	$gBitSmarty->assign_by_ref( 'gStructure', $gStructure );
	$gBitSmarty->assign('structureInfo', $gStructure->mInfo);

	// Store the actively stored structure name
	$gBitUser->storePreference( 'edit_structure_name', $rootStructure->mInfo['title'] );
	$gBitUser->storePreference( 'edit_structure_id', $rootStructure->mStructureId );

	if( !$gBitSystem->isFeatureActive( 'wikibook_hide_add_content' ) ) {
		include_once( LIBERTY_PKG_PATH.'get_content_list_inc.php' );
		foreach( $contentList['data'] as $cItem ) {
			$cList[$contentTypes[$cItem['content_type_guid']]][$cItem['content_id']] = $cItem['title'].' [id: '.$cItem['content_id'].']';
		}
		$gBitSmarty->assign( 'contentList', $cList );
		$gBitSmarty->assign( 'contentSelect', $contentSelect );
		$gBitSmarty->assign( 'contentTypes', $contentTypes );

		$subpages = $gStructure->getStructureNodes($_REQUEST["structure_id"]);
		$max = count($subpages);
		$gBitSmarty->assign_by_ref('subpages', $subpages);
		if ($max != 0) {
			$last_child = $subpages[$max - 1];
			$gBitSmarty->assign('insert_after', $last_child["structure_id"]);
		}
	}

	if( ( isset( $_REQUEST["action"] ) && ( $_REQUEST["action"] == 'remove' ) ) || !empty( $_REQUEST["confirm"] ) ) {
		if( $_REQUEST["action"] == 'remove' && !empty( $_REQUEST["confirm"] ) ) {
			if( $gStructure->removeStructureNode( $_REQUEST["structure_id"], false ) ) {
				header( "Location: ".$_SERVER['PHP_SELF'].'?structure_id='.$gStructure->mInfo["parent_id"] );
				die;
			} else {
				vd( $gStructure->mErrors );
			}
		} elseif( $_REQUEST["action"] == 'remove' ) {
			$gBitSystem->setBrowserTitle( 'Confirm removal of '.$gContent->getTitle() );
			$formHash['action'] = 'remove';
			$formHash['remove'] = TRUE;
			$formHash['structure_id'] = $_REQUEST['structure_id'];
			$msgHash = array(
				'label' => 'Remove content from Structure',
				'confirm_item' => $gContent->getTitle().'<br />and any subitems',
				'warning' => 'This will remove the content from the structure but will <strong>not</strong> modify or remove the content itself.',
			);
			$gBitSystem->confirmDialog( $formHash,$msgHash );
		}
	} elseif (isset($_REQUEST["move_node"])) {
		if ($_REQUEST["move_node"] == '1') {
			$gStructure->moveNodeWest();
		} elseif ($_REQUEST["move_node"] == '2') {
			$gStructure->moveNodeNorth();
		}	elseif ($_REQUEST["move_node"] == '3') {
			$gStructure->moveNodeSouth();
		} elseif ($_REQUEST["move_node"] == '4') {
			$gStructure->moveNodeEast();
		}
		header( "Location: ".$_SERVER['PHP_SELF'].'?structure_id='.$gStructure->mInfo["structure_id"] );
		die;
	} elseif( !empty( $_REQUEST['submit_structure'] ) ) {
		if( $gStructure->storeStructure( $_REQUEST ) ) {
			$feedback['success'] = tra( "Your changes were successfully saved." );
		} else {
			$feedback['error'] = $gStructure->mErrors;
		}
	} elseif (isset($_REQUEST["create"])) {
//		if (isset($_REQUEST["pageAlias"]))	{
//			$gStructure->set_page_alias($_REQUEST["structure_id"], $_REQUEST["pageAlias"]);
//		}

		$structureHash['root_structure_id'] = $rootStructure->mStructureId;
		$structureHash['parent_id'] = $_REQUEST['structure_id'];

		$after = null;
		if (isset($_REQUEST['after_ref_id'])) {
			$structureHash['after_ref_id'] = $_REQUEST['after_ref_id'];
		}
		if (!(empty($_REQUEST['name']))) {
			$gStructure->s_create_page($_REQUEST["structure_id"], $after, $_REQUEST["name"], '');
		} elseif(!empty($_REQUEST['content'])) {
			foreach ($_REQUEST['content'] as $conId ) {
				$structureHash['content_id'] = $conId;
				$new_structure_id = $gStructure->storeNode( $structureHash );
				$structureHash['after_ref_id'] = $new_structure_id;
			}
		}
	}

	$gBitSmarty->assign('subtree', $rootTree = $rootStructure->getSubTree( $rootStructure->mStructureId ));
}

?>