diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-05-22 15:44:44 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-05-22 15:44:44 +0100 |
| commit | 572b562f433532429423a5ccace64838efec93c7 (patch) | |
| tree | 2c7a9dbe8570578a58d5b396a15388243628ffda /admin | |
| parent | 825ce764d0e6bcdcaccad653a346e03a25cd267f (diff) | |
| download | liberty-572b562f433532429423a5ccace64838efec93c7.tar.gz liberty-572b562f433532429423a5ccace64838efec93c7.tar.bz2 liberty-572b562f433532429423a5ccace64838efec93c7.zip | |
Add generic xref group/source admin pages to liberty
LibertyXrefType: add getContentTypeGuids() and getGroupList() static methods.
New admin pages with package filter (session-persisted content_type_guid
dropdown): admin_xref_groups.php manages liberty_xref_type rows;
admin_xref_sources.php manages liberty_xref_source rows. Both support
add and delete (delete guarded by entry/source count). Wired into
menu_liberty_admin.tpl as Xref Groups / Xref Sources links.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'admin')
| -rw-r--r-- | admin/admin_xref_groups.php | 62 | ||||
| -rw-r--r-- | admin/admin_xref_sources.php | 71 |
2 files changed, 133 insertions, 0 deletions
diff --git a/admin/admin_xref_groups.php b/admin/admin_xref_groups.php new file mode 100644 index 0000000..8d4ae58 --- /dev/null +++ b/admin/admin_xref_groups.php @@ -0,0 +1,62 @@ +<?php +/** + * Admin page for managing liberty_xref_type groups across all packages. + * @package liberty + */ + +use Bitweaver\Liberty\LibertyXrefType; +use Bitweaver\KernelTools; + +require_once '../../kernel/includes/setup_inc.php'; + +$gBitSystem->verifyPermission( 'p_admin' ); + +// Persist selected content_type_guid in session +if ( isset( $_REQUEST['content_type_guid'] ) ) { + $_SESSION['liberty_xref_admin_guid'] = $_REQUEST['content_type_guid']; +} +$activeGuid = $_SESSION['liberty_xref_admin_guid'] ?? ''; + +// Add a new group +if ( !empty( $_REQUEST['fAddGroup'] ) ) { + $xrefType = trim( $_REQUEST['xref_type'] ?? '' ); + $guid = trim( $_REQUEST['new_content_type_guid'] ?? $activeGuid ); + $title = trim( $_REQUEST['title'] ?? '' ); + $sortOrder = (int)( $_REQUEST['sort_order'] ?? 0 ); + $roleId = (int)( $_REQUEST['role_id'] ?? 3 ); + if ( $xrefType && $guid && $title ) { + $gBitDb->query( + "INSERT INTO `".BIT_DB_PREFIX."liberty_xref_type` (`xref_type`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`) VALUES (?,?,?,?,?,'')", + [ $xrefType, $guid, $title, $sortOrder, $roleId ] + ); + } +} + +// Delete a group (only if no sources are attached) +if ( !empty( $_REQUEST['fDeleteGroup'] ) ) { + $xrefType = $_REQUEST['xref_type'] ?? ''; + $guid = $_REQUEST['del_content_type_guid'] ?? ''; + if ( $xrefType && $guid ) { + $count = $gBitDb->getOne( + "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."liberty_xref_source` WHERE `xref_type` = ? AND `content_type_guid` = ?", + [ $xrefType, $guid ] + ); + if ( $count == 0 ) { + $gBitDb->query( + "DELETE FROM `".BIT_DB_PREFIX."liberty_xref_type` WHERE `xref_type` = ? AND `content_type_guid` = ?", + [ $xrefType, $guid ] + ); + } else { + $gBitSmarty->assign( 'deleteError', "Cannot delete '$xrefType' — $count source(s) still attached." ); + } + } +} + +$guidList = LibertyXrefType::getContentTypeGuids(); +$groups = LibertyXrefType::getGroupList( $activeGuid ? [ 'content_type_guid' => $activeGuid ] : [] ); + +$gBitSmarty->assign( 'activeGuid', $activeGuid ); +$gBitSmarty->assign( 'guidList', $guidList ); +$gBitSmarty->assign( 'xref_groups', $groups ); + +$gBitSystem->display( 'bitpackage:liberty/admin_xref_groups.tpl', KernelTools::tra( 'Xref Groups' ), [ 'display_mode' => 'admin' ] ); diff --git a/admin/admin_xref_sources.php b/admin/admin_xref_sources.php new file mode 100644 index 0000000..c86b0d3 --- /dev/null +++ b/admin/admin_xref_sources.php @@ -0,0 +1,71 @@ +<?php +/** + * Admin page for managing liberty_xref_source entries across all packages. + * @package liberty + */ + +use Bitweaver\Liberty\LibertyXrefType; +use Bitweaver\KernelTools; + +require_once '../../kernel/includes/setup_inc.php'; + +$gBitSystem->verifyPermission( 'p_admin' ); + +// Persist selected content_type_guid in session +if ( isset( $_REQUEST['content_type_guid'] ) ) { + $_SESSION['liberty_xref_admin_guid'] = $_REQUEST['content_type_guid']; +} +$activeGuid = $_SESSION['liberty_xref_admin_guid'] ?? ''; + +// Add a new source +if ( !empty( $_REQUEST['fAddSource'] ) ) { + $source = trim( $_REQUEST['source'] ?? '' ); + $guid = trim( $_REQUEST['new_content_type_guid'] ?? $activeGuid ); + $xrefType = trim( $_REQUEST['xref_type'] ?? '' ); + $title = trim( $_REQUEST['cross_ref_title'] ?? '' ); + $template = trim( $_REQUEST['template'] ?? '' ); + $href = trim( $_REQUEST['cross_ref_href'] ?? '' ); + $multi = (int)( $_REQUEST['multi'] ?? 0 ); + $roleId = (int)( $_REQUEST['role_id'] ?? 3 ); + if ( $source && $guid && $xrefType && $title ) { + $gBitDb->query( + "INSERT INTO `".BIT_DB_PREFIX."liberty_xref_source` (`source`,`content_type_guid`,`xref_type`,`cross_ref_title`,`multi`,`role_id`,`cross_ref_href`,`template`,`data`) VALUES (?,?,?,?,?,?,?,?,NULL)", + [ $source, $guid, $xrefType, $title, $multi, $roleId, $href, $template ] + ); + } +} + +// Delete a source (only if no xref records use it) +if ( !empty( $_REQUEST['fDeleteSource'] ) ) { + $source = $_REQUEST['source'] ?? ''; + $guid = $_REQUEST['del_content_type_guid'] ?? ''; + if ( $source && $guid ) { + $count = $gBitDb->getOne( + "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."liberty_xref` WHERE `source` = ?", + [ $source ] + ); + if ( $count == 0 ) { + $gBitDb->query( + "DELETE FROM `".BIT_DB_PREFIX."liberty_xref_source` WHERE `source` = ? AND `content_type_guid` = ?", + [ $source, $guid ] + ); + } else { + $gBitSmarty->assign( 'deleteError', "Cannot delete '$source' — $count xref record(s) still use it." ); + } + } +} + +$guidList = LibertyXrefType::getContentTypeGuids(); +$sources = LibertyXrefType::getXrefTypeList( $activeGuid ? [ 'content_type_guid' => $activeGuid ] : [] ); + +// Build group list for the add-form dropdown, filtered to active guid +$groups = $activeGuid + ? LibertyXrefType::getGroupList( [ 'content_type_guid' => $activeGuid ] ) + : []; + +$gBitSmarty->assign( 'activeGuid', $activeGuid ); +$gBitSmarty->assign( 'guidList', $guidList ); +$gBitSmarty->assign( 'xref_sources', $sources ); +$gBitSmarty->assign( 'xref_groups', $groups ); + +$gBitSystem->display( 'bitpackage:liberty/admin_xref_sources.tpl', KernelTools::tra( 'Xref Sources' ), [ 'display_mode' => 'admin' ] ); |
