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
|
<?php
/**
* $Header: /cvsroot/bitweaver/_bit_pigeonholes/Attic/servicefunctions_inc.php,v 1.1 2005/08/21 16:22:39 squareing Exp $
*
* Copyright ( c ) 2004 bitweaver.org
* 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
*
* @package pigeonholes
* @subpackage functions
*/
/**
* Pigeonhole display service
*/
function display_pigeonholes( &$pObject ) {
global $gBitSmarty, $gBitUser;
if( $gBitUser->hasPermission( 'bit_p_view_pigeonholes' ) ) {
require_once( PIGEONHOLES_PKG_PATH.'Pigeonholes.php' );
$pigeonholes = new Pigeonholes( NULL, NULL, FALSE );
if( $pigeons = $pigeonholes->getPigeonholesFromContentId( $pObject->mContentId ) ) {
foreach( $pigeons as $pigeon ) {
$pigeonholes->mContentId = $pigeon['content_id'];
$pigeonholes->load( TRUE );
$pigeonData[] = $pigeonholes->mInfo;
}
$gBitSmarty->assign( 'pigeonData', !empty( $pigeonData ) ? $pigeonData : FALSE );
}
}
}
/**
* Pigeonhole edit template service
*/
function pigeonholes_input_content( $pObject=NULL ) {
global $gBitSmarty, $gBitUser;
$pigeonPathList = array();
if( $gBitUser->hasPermission( 'bit_p_insert_pigeonhole_member' ) ) {
require_once( PIGEONHOLES_PKG_PATH.'Pigeonholes.php' );
$pigeonholes = new Pigeonholes( NULL, NULL, FALSE );
// get pigeonholes path list
if( $pigeonPathList = $pigeonholes->getPigeonholesPathList( !empty( $pObject->mContentId ) ? $pObject->mContentId : NULL ) ) {
$gBitSmarty->assign( 'pigeonPathList', $pigeonPathList );
}
}
}
/**
* Pigeonhole preview service
* when we hit preview, we make the selections persistent
*/
function pigeonholes_preview_content() {
global $gBitSmarty, $gBitUser;
$pigeonPathList = array();
if( $gBitUser->hasPermission( 'bit_p_insert_pigeonhole_member' ) ) {
require_once( PIGEONHOLES_PKG_PATH.'Pigeonholes.php' );
$pigeonholes = new Pigeonholes( NULL, NULL, FALSE );
// get pigeonholes path list
if( $pigeonPathList = $pigeonholes->getPigeonholesPathList() ) {
foreach( $pigeonPathList as $key => $path ) {
if( !empty( $_REQUEST['pigeonholes']['pigeonhole'] ) && in_array( $key, $_REQUEST['pigeonholes']['pigeonhole'] ) ) {
$pigeonPathList[$key][0]['selected'] = TRUE;
} else {
$pigeonPathList[$key][0]['selected'] = FALSE;
}
}
$gBitSmarty->assign( 'pigeonPathList', $pigeonPathList );
}
}
}
/**
* Pigeonhole store service
* store the content in any pigeonhole it wants
*/
function pigeonholes_store_content( $pObject, $pParamHash ) {
global $gBitSmarty, $gBitUser;
if( $gBitUser->hasPermission( 'bit_p_insert_pigeonhole_member' ) ) {
require_once( PIGEONHOLES_PKG_PATH.'Pigeonholes.php' );
if( !empty( $pParamHash['content_id'] ) ) {
if( is_object( $pObject ) && empty( $pParamHash['content_id'] ) ) {
$pParamHash['content_id'] = $pObject->mContentId;
}
$pigeonholes = new Pigeonholes( NULL, NULL, FALSE );
$pigeonPathList = $pigeonholes->getPigeonholesPathList( $pParamHash['content_id'] );
// here we need to work out if we need to save at all
// get all originally selected items
$selectedItem = array();
foreach( $pigeonPathList as $path ) {
if( !empty( $path[0]['selected'] ) ) {
$pathItem = array_pop( $path );
$selectedItem[] = $pathItem['content_id'];
}
}
// quick and dirty check to start off with
if( empty( $_REQUEST['pigeonholes'] ) || count( $_REQUEST['pigeonholes']['pigeonhole'] ) != count( $selectedItem ) ) {
$modified = TRUE;
} else {
// more thorough check
foreach( $selectedItem as $item ) {
if( !in_array( $item, $_REQUEST['pigeonholes']['pigeonhole'] ) ) {
$modified = TRUE;
}
}
}
if( !empty( $modified ) ) {
// first remove all entries with this content_id
if( $pigeonholes->expungePigeonholeMember( NULL, $pParamHash['content_id'] ) && !empty( $_REQUEST['pigeonholes'] ) ) {
// insert the content into the desired pigeonholes
foreach( $_REQUEST['pigeonholes']['pigeonhole'] as $p_id ) {
$memberHash[] = array(
'parent_id' => $p_id,
'content_id' => $pParamHash['content_id']
);
}
if( !$pigeonholes->insertPigeonholeMember( $memberHash ) ) {
$gBitSmarty->assign( 'msg', tra( "There was a problem inserting the content into the pigeonholes." ) );
$gBitSystem->display( 'error.tpl' );
die;
}
}
}
}
}
}
?>
|