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
|
<?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' ] );
|