verifyPackage( 'pigeonholes' ); $gBitSystem->verifyPermission( 'p_pigeonholes_insert_member' ); include_once( PIGEONHOLES_PKG_INCLUDE_PATH.'lookup_pigeonholes_inc.php' ); $feedback = ''; $gBitSmarty->assign( 'feedback', $feedback ); $contentTypes = [ '' => KernelTools::tra( 'All Content' ) ]; foreach( $gLibertySystem->mContentTypes as $cType ) { if( $cType['content_type_guid'] != PIGEONHOLES_CONTENT_TYPE_GUID ) { $contentTypes[$cType['content_type_guid']] = $gLibertySystem->getContentTypeName( $cType['content_type_guid'] ); } } $gBitSmarty->assign( 'contentTypes', $contentTypes ); $gBitSmarty->assign( 'contentSelect', $contentSelect = !isset( $_REQUEST['content_type'] ) ? null : $_REQUEST['content_type'] ); $listHash = [ 'find' => ( empty( $_REQUEST['find'] ) ? null : $_REQUEST['find'] ), 'sort_mode' => ( empty( $_REQUEST['sort_mode'] ) ? null : $_REQUEST['sort_mode'] ), 'max_records' => ( BitBase::verifyId( $_REQUEST['max_records'] ) ) ? $_REQUEST['max_records'] : 10, 'include_members' => ( ( !empty( $_REQUEST['include'] ) && $_REQUEST['include'] == 'members' ) ? true : false ), 'content_type' => $contentSelect, ]; // We need to handle insert and next where we are NOT actually doing an insert if( !empty( $_REQUEST['insert_content'] ) || !empty( $_REQUEST['insert_content_and_next'] )) { $listHash['list_page'] = ( empty( $_REQUEST['list_page'] ) ? 2 : $_REQUEST['list_page'] + 1 ); } else { $listHash['list_page'] = ( empty( $_REQUEST['list_page'] ) ? null : $_REQUEST['list_page'] ); } $assignableContent = $gContent->getAssignableContent( $listHash ); if(( !empty( $_REQUEST['insert_content'] ) || !empty( $_REQUEST['insert_content_and_next'] ))) { // here we need to limit all killing to the selected structure $deletableParentIds = []; if( empty( $gStructure ) && BitBase::verifyId( $_REQUEST['root_structure_id'] ) ) { $gStructure = new LibertyStructure(); $struct = $gStructure->getStructure( $_REQUEST ); foreach( $struct as $node ) { $deletableParentIds[] = $node['content_id']; } } // make an array that can be stored foreach( $assignableContent as $item ) { if( !empty( $_REQUEST['pigeonhole'][$item['content_id']] ) ) { foreach( $_REQUEST['pigeonhole'][$item['content_id']] as $parent_id ) { $memberHash[$parent_id][] = [ 'parent_id' => $parent_id, 'content_id' => $item['content_id'], ]; } } if( !empty( $_REQUEST['include'] ) && $_REQUEST['include'] == 'members' ) { if( !empty( $item['content_id'] ) && !$gContent->expungePigeonholeMember( [ 'member_id' => $item['content_id'], 'deletables' => $deletableParentIds ] ) ) { $feedback['error'] = 'The content could not be deleted before insertion.'; } } } if( empty( $feedback['error'] ) && !empty( $memberHash )) { foreach( $memberHash as $memberStore ) { if( $gContent->insertPigeonholeMember( $memberStore ) ) { $feedback['success'] = 'The content was successfully inserted into the respective categories.'; } else { $feedback['error'] = 'The content could not be inserted into the categories.'; } } } // we need to reload the assignableContent, since settings have changed // reuse previous listhash since display settings aren't changed if( !empty( $_REQUEST['insert_content_and_next'] )) { $listHash['offset'] = $listHash['listInfo']['offset'] + $listHash['listInfo']['max_records']; unset( $listHash['list_page'] ); unset( $listHash['listInfo'] ); } $assignableContent = $gContent->getAssignableContent( $listHash ); } $gBitSmarty->assign( 'listInfo', $listHash['listInfo'] ); $listHash = [ 'load_only_root' => true, 'max_records' => -1, 'parse_data' => true, ]; $pigeonRootData = $gContent->getList( $listHash ); $pigeonRoots[0] = 'All'; foreach( $pigeonRootData as $root ) { $pigeonRoots[$root['root_structure_id']] = $root['title']; } $gBitSmarty->assign( 'pigeonRoots', !empty( $pigeonRoots ) ? $pigeonRoots : null ); $listHash = [ 'root_structure_id' => ( !empty( $_REQUEST['root_structure_id'] ) ? $_REQUEST['root_structure_id'] : null ), 'force_extras' => true, 'max_records' => -1, 'sort_mode' => 'ls.`parent_id_asc`', 'parse_data' => true, ]; if( $gBitSystem->isFeatureActive( 'pigeonholes_allow_forbid_insertion' )) { $listHash['insertable'] = true; } $pigeonList = $gContent->getList( $listHash ); $gBitSmarty->assign( 'pigeonList', $pigeonList ); $gBitSmarty->assign( 'assignableContent', $assignableContent ); $gBitSmarty->assign( 'contentCount', count( $assignableContent ) ); // Display the template $gBitSystem->display( 'bitpackage:pigeonholes/assign_content.tpl', KernelTools::tra( 'Assign Content to Categories' ) , [ 'display_mode' => 'display' ]); ?>