verifyPackage( 'contact' ); $gBitSystem->verifyPermission( 'p_contact_update' ); include_once CONTACT_PKG_INCLUDE_PATH . 'lookup_contact_inc.php'; if (!empty( $gContent->mInfo )) { $formInfo = $gContent->mInfo; $formInfo['edit'] = !empty( $gContent->mInfo['data'] ) ? $gContent->mInfo['data'] : ''; } $cat_type = BITPAGE_CONTENT_TYPE_GUID; if (isset( $_REQUEST["preview"] )) { // get files from all packages that process this data further foreach ( $gBitSystem->getPackageIntegrationFiles( 'form_processor_inc.php', true ) as $package => $file ) { if ($gBitSystem->isPackageActive( $package )) { include_once $file; } } $gBitSmarty->assign( 'preview', 1 ); $gBitSmarty->assign( 'title', $_REQUEST["title"] ); $parsed = $gContent->parseData( $formInfo['edit'], !empty( $_REQUEST['format_guid'] ) ? $_REQUEST['format_guid'] : ( $gContent->mInfo['format_guid'] ?? 'tikiwiki' ), ); $gBitSmarty->assign('parsed', $parsed); $gContent->invokeServices( 'content_preview_function' ); } else { $gContent->invokeServices( 'content_edit_function' ); } // Pro if( !empty( $_REQUEST['expunge'] ) && $gContent->isValid() ) { $gBitSystem->verifyPermission( 'p_contact_expunge' ); $gContent->expunge(); KernelTools::bit_redirect( CONTACT_PKG_URL . 'list_contacts.php' ); } elseif (isset($_REQUEST["fCancel"])) { if( !empty( $gContent->mContentId ) ) { KernelTools::bit_redirect( $gContent->getDisplayUrl() ); } else { KernelTools::bit_redirect( CONTACT_PKG_URL ); } } elseif (isset($_REQUEST["fSaveContact"])) { if( $gContent->store( $_REQUEST ) ) { KernelTools::bit_redirect( $gContent->getDisplayUrl() ); } else { $formInfo = $_REQUEST; $formInfo['data'] = &$_REQUEST['edit']; } } // formInfo might be set due to a error on submit if( empty( $formInfo ) ) { $formInfo = &$gContent->mInfo; } $isPerson = $gContent instanceof \Bitweaver\Contact\ContactPerson; $gContent->loadXrefInfo(); $gBitSmarty->assign( 'gXrefInfo', $gContent->mXrefInfo ); $gBitSmarty->assign( 'isPerson', $isPerson ); // Build type toggle list: available options from schema (or hard-coded pre-upgrade fallback), // checked state from contact_types (currently set items in liberty_xref). $setItems = []; foreach ( $gContent->mInfo['contact_types'] ?? [] as $ct ) { if ( !empty( $ct['content_id'] ) ) { $setItems[ $ct['item'] ] = true; } } $typeToggle = []; foreach ( $gContent->getAvailableTypeItems() as $m ) { $typeToggle[] = [ 'item' => $m['item'], 'name' => $m['name'], 'checked' => isset( $setItems[ $m['item'] ] ), ]; } $gContent->mInfo['contact_type_list'] = $typeToggle; $gBitSmarty->assign( 'pageInfo', $formInfo ); $gBitSmarty->assign( 'errors', $gContent->mErrors ); $gBitSmarty->assign( (!empty( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : 'body').'TabSelect', 'tdefault' ); $gBitSmarty->assign('show_page_bar', 'y'); $gBitSystem->display( 'bitpackage:contact/edit.tpl', 'Edit: ' , [ 'display_mode' => 'edit' ]);