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; } } } } } } ?>