summaryrefslogtreecommitdiff
path: root/edit_pigeonholes.php
blob: cb30965bc6cb5b92ec9a49b8fab367762352e23a (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/**
 * $Header: /cvsroot/bitweaver/_bit_pigeonholes/edit_pigeonholes.php,v 1.19 2006/04/11 13:07:41 squareing Exp $
 *
 * Copyright ( c ) 2004 bitweaver.org
 * Copyright ( c ) 2003 tikwiki.org
 * Copyright ( c ) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, 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
 *
 * $Id: edit_pigeonholes.php,v 1.19 2006/04/11 13:07:41 squareing Exp $
 * @package pigeonholes
 * @subpackage functions
 */

/**
 * required setup
 */
require_once( '../bit_setup_inc.php' );

$gBitSystem->verifyPackage( 'pigeonholes' );
$gBitSystem->verifyPermission( 'p_pigeonholes_edit' );

include_once( LIBERTY_PKG_PATH.'LibertyStructure.php' );
include_once( PIGEONHOLES_PKG_PATH.'lookup_pigeonholes_inc.php' );

// include edit structure file only when structure_id is known
if( !empty( $_REQUEST["structure_id"] ) && ( empty( $_REQUEST['action'] ) || $_REQUEST['action'] != 'remove' ) ) {
	$verifyStructurePermission = 'p_pigeonholes_edit';
	include_once( LIBERTY_PKG_PATH.'edit_structure_inc.php' );

	// get all the nodes in this structure
	foreach( $rootTree as $node ) {
		$pigeonStructure[$node['structure_id']] = str_repeat( '-', $node['level'] ).' '.$node['title'];
	}
	$gBitSmarty->assign( 'pigeonStructure', $pigeonStructure );
}

global $gStructure;
// store the form if we need to
if( !empty( $_REQUEST['pigeonhole_store'] ) ) {
	if( ( empty( $_REQUEST['pigeonhole']['title'] ) ) ) {
		$gBitSmarty->assign( 'msg', tra( "You must specify a title." ) );
		$gBitSystem->display( 'error.tpl' );
		die;
	}

	// we need to get the root structure id
	$_REQUEST['pigeonhole']['root_structure_id'] = !empty( $rootStructure->mStructureId ) ?  $rootStructure->mStructureId : NULL;
	// store the pigeonhole
	$pigeonStore = new Pigeonholes();
	$pigeonStore->mContentId = !empty( $_REQUEST['content_id'] ) ? $_REQUEST['content_id'] : NULL;
	$pigeonStore->load();
	if( $pigeonStore->store( $_REQUEST['pigeonhole'] ) ) {
		header( "Location: ".$_SERVER['PHP_SELF'].'?structure_id='.$pigeonStore->mStructureId.( !empty( $_REQUEST['action'] ) ? '&action='.$_REQUEST['action'] : '' )."&success=".urlencode( tra( "The category was successfully stored" ) ) );
	} else {
		vd( $gContent->mErrors );
		$gBitSmarty->assign( 'msg', tra( "There was a problem trying to store the pigeonhole." ) );
		$gBitSystem->display( 'error.tpl' );
		die;
	}
}

// if we are just changing the content that is being displayed, we treat it like a preview.
if( !empty( $_REQUEST['search_objects'] ) ) {
	$pigeonInfo['parent_id'] = !empty( $_REQUEST['pigeonhole']['parent_id'] ) ? $_REQUEST['pigeonhole']['parent_id'] : NULL;
	$pigeonInfo['title'] = !empty( $_REQUEST['pigeonhole']['title'] ) ? $_REQUEST['pigeonhole']['title'] : NULL;
	$pigeonInfo['data'] = !empty( $_REQUEST['pigeonhole']['edit'] ) ? $_REQUEST['pigeonhole']['edit'] : NULL;
	$pigeonInfo['selected_members'] = !empty( $_REQUEST['pigeonhole']['members'] ) ? $_REQUEST['pigeonhole']['members'] : NULL;
	$gBitSmarty->assign( 'pigeonInfo', !empty( $pigeonInfo ) ? $pigeonInfo : NULL );
} elseif( !empty( $_REQUEST['action'] ) || isset( $_REQUEST["confirm"] ) ) {
	// if we need to edit, show the information
	if( $_REQUEST['action'] == 'edit' ) {
		$pigeonInfo = $gContent->mInfo;
		$gContent->loadPreferences();

		// create usable array for selected items in content listing
		if( !empty( $pigeonInfo['members'] ) ) {
			foreach( $pigeonInfo['members'] as $member ) {
				if( $pigeonInfo['content_id'] == $member['parent_id'] ) {
					$pigeonInfo['selected_members'][] = $member['content_id'];
				}
			}
		}
	}

	if( $_REQUEST['action'] == 'edit' || $_REQUEST['action'] == 'create' ) {
		$gBitSmarty->assign( 'pigeonInfo', !empty( $pigeonInfo ) ? $pigeonInfo : NULL );
	}

	if( $_REQUEST["action"] == 'remove' || isset( $_REQUEST["confirm"] ) ) {
		if( isset( $_REQUEST["confirm"] ) ) {
			if( $gContent->expunge( $_REQUEST["structure_id"] ) ) {
				header( "Location: ".$_SERVER['PHP_SELF'].'?structure_id='.$gContent->mInfo["parent_id"] );
				die;
			} else {
				vd( $gContent->mErrors );
			}
		}
		$gBitSystem->setBrowserTitle( 'Confirm removal of '.$gContent->mInfo['title'] );
		$formHash['remove'] = TRUE;
		$formHash['structure_id'] = $_REQUEST['structure_id'];
		$formHash['action'] = 'remove';
		$msgHash = array(
			'label' => 'Remove Pigeonhole',
			'confirm_item' => $gContent->mInfo['title'].'<br />'.tra( 'and any subcategories' ),
			'warning' => 'This will remove the pigeonhole but will <strong>not</strong> modify or remove the content itself.',
		);
		$gBitSystem->confirmDialog( $formHash, $msgHash );
	}

	if( $_REQUEST['action'] == 'dismember' && !empty( $_REQUEST['content_id'] ) && !empty( $_REQUEST['parent_id'] ) ) {
		if( $gContent->expungePigeonholeMember( array( 'parent_id' => $_REQUEST['content_id'], 'member_id' => $_REQUEST['parent_id'] ) ) ) {
			$feedback['success'] = tra( 'The item was successfully removed' );
		} else {
			$feedback['error'] = tra( 'The item could not be removed' );
		}
		// used to avoid displaying edit form
		unset( $_REQUEST['action'] );
	}
}

if( !empty( $_REQUEST['success'] ) ) {
	$feedback['success'] = $_REQUEST['success'];
}

// get all available perms only when the admin is visiting here.
if ( $gBitSystem->isFeatureActive( 'pigeonholes_permissions' ) ) {
	if( $gBitUser->isAdmin() ) {
		$tmpPerms = $gBitUser->getGroupPermissions();
	} else {
		$tmpPerms = $gBitUser->mPerms;
	}

	$perms[''] = tra( 'None' );
	foreach( $tmpPerms as $perm => $info ) {
		$perms[$info['package']][$perm] = $perm;
	}
	$gBitSmarty->assign( 'perms', $perms );
}

// get available groups ready that we can assign the pigoenhole to one of them
if ( $gBitSystem->isFeatureActive( 'pigeonholes_groups' ) ) {
	$groups[''] = tra( 'None' );
	foreach( $gBitUser->mGroups as $group_id => $group ) {
		$groups[$group_id] = $group['group_name'];
	}
	$gBitSmarty->assign( 'groups', $groups );
}

// get 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 );

$listHash['root_structure_id'] = !empty( $gContent->mInfo['root_structure_id'] ) ? $gContent->mInfo['root_structure_id'] : NULL;
$listHash['force_extras'] = TRUE;
$pigeonList = $gContent->getList( $listHash );
$gBitSmarty->assign( 'pigeonList', $pigeonList );
$gBitSmarty->assign( 'feedback', !empty( $feedback ) ? $feedback : NULL );

// Get list of available styles
if ( $gBitSystem->isFeatureActive( 'pigeonholes_themes' ) ) {
	$styles = $gBitThemes->getStyles( NULL, TRUE );
	$gBitSmarty->assign( 'styles', $styles );
}

// Display the template
if ( !empty( $gStructure ) ) {
	$gBitSystem->display( 'bitpackage:pigeonholes/edit_pigeonholes.tpl', !empty( $gStructure->mInfo['title'] ) ? tra( 'Edit Pigeonhole' ).': '.$gStructure->mInfo["title"] : tra( 'Create Pigeonhole' ) );
} else {
	$gBitSystem->display( 'bitpackage:pigeonholes/edit_pigeonholes.tpl', tra( 'Create Pigeonhole' ) );
}
?>