verifyPackage( 'stock' ); global $gBitSystem, $gBitSmarty, $gBitDb; $stgrp = !empty( $_REQUEST['stgrp'] ) ? trim( $_REQUEST['stgrp'] ) : null; $X = BIT_DB_PREFIX; $bindVars = []; $whereSql = "AND lc.`content_type_guid` IN ('stockassembly','stockcomponent')"; if( $stgrp ) { $whereSql .= " AND EXISTS (SELECT 1 FROM `{$X}liberty_xref` sx WHERE sx.`content_id` = lc.`content_id` AND sx.`item` = ?)"; $bindVars[] = $stgrp; $groupTitle = $gBitDb->getOne( "SELECT `cross_ref_title` FROM `{$X}liberty_xref_item` WHERE `item` = ? AND `x_group` = 'stgrp'", [ $stgrp ] ); } else { $whereSql .= " AND EXISTS (SELECT 1 FROM `{$X}liberty_xref` sx INNER JOIN `{$X}liberty_xref_item` xi ON xi.`item` = sx.`item` AND xi.`x_group` = 'stgrp' WHERE sx.`content_id` = lc.`content_id`)"; $groupTitle = null; } $listHash = $_REQUEST; BitBase::prepGetList( $listHash ); $maxRecords = $listHash['max_records']; $offset = $listHash['offset']; $totalCount = (int)$gBitDb->getOne( "SELECT COUNT(*) FROM `{$X}liberty_content` lc WHERE 1=1 $whereSql", $bindVars ); $rs = $gBitDb->query( "SELECT lc.`content_id`, lc.`title`, lc.`data`, lc.`format_guid`, lc.`content_type_guid`, (SELECT FIRST 1 x.`xkey` FROM `{$X}liberty_xref` x WHERE x.`content_id` = lc.`content_id` AND x.`item` = 'KLID') AS klid, (SELECT FIRST 1 x.`xkey` FROM `{$X}liberty_xref` x WHERE x.`content_id` = lc.`content_id` AND x.`item` = 'KLPR') AS klpr FROM `{$X}liberty_content` lc WHERE 1=1 $whereSql ORDER BY lc.`title`", $bindVars, $maxRecords, $offset ); $items = []; while( $row = $rs->fetchRow() ) { $parseHash = [ 'data' => $row['data'], 'format_guid' => $row['format_guid'] ?? 'bithtml' ]; $row['parsed_data'] = LibertyContent::parseDataHash( $parseHash ); $items[] = $row; } $listHash['cant'] = $totalCount; $listHash['page_records'] = count( $items ); if( $stgrp ) { $listHash['listInfo']['parameters']['stgrp'] = $stgrp; } BitBase::postGetList( $listHash ); $gBitSmarty->assign( 'kitlockerItems', $items ); $gBitSmarty->assign( 'stgrp', $stgrp ); $gBitSmarty->assign( 'groupTitle', $groupTitle ); $gBitSmarty->assign( 'listInfo', $listHash['listInfo'] ); $pageTitle = $groupTitle ?: KernelTools::tra( 'Kitlocker' ); $gBitSystem->setBrowserTitle( $pageTitle ); $gBitSystem->display( 'bitpackage:stock/list_kitlocker.tpl', null, [ 'display_mode' => 'list' ] );