<?php

	// Dismiss Session
	PHPVC_SESSION::VAR_STOP();
	
	// Perform Login
    $SHORTCODE_STATUS = PHPCUS_SHORTCODE::CUS_QUICK_LOGIN();
	
	// Check nonce
	if($SHORTCODE_STATUS == false)
    {
		PHPCUS_PARAM::CUS_REQUIRES_NONCE();
	}
	
	// Check array size
	PHPCUS_PARAM::CUS_ARRAY_TOO_LARGE();
	
	// Check already authenticated
	PHPCUS_PARAM::CUS_REQUIRES_AUTHENTICATION();
	
	// Check access rights
	PHPCUS_PARAM::CUS_HAS_PERMISSION(PHPCUS_SYSTEM::AUTHORITY_VIEW_EDIT_DELETE, 'record_inventory');
	
	if
	(
			PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
			(
					[
							'PARAM_REC_INVENTORY_ID'
					], True
			)
	)
	{
		Try
		{
			// Read params
			// ------------------------------------------------------------------
			$PARAM_REC_INVENTORY_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_INVENTORY_ID', true);		
			
			
			$PARAM_ARRAY_COUNT = count($PARAM_REC_INVENTORY_ID);
				
			
			// Prepare PDO Handler
			// ------------------------------------------------------------------
			$FULL_DATA_SET = [];
			$ARRAY_CTR = 0;
				
			$PDO_HANDLE = PHPRC_PDO_MYSQL::REF_CONNECT();
			PHPRC_PDO_MYSQL::REF_TRANSACTION_BEGIN($PDO_HANDLE);

					
			// Execute Stored Procedure
			// ------------------------------------------------------------------
			Try
			{
				while($ARRAY_CTR < $PARAM_ARRAY_COUNT)
				{
					$DATA_SET = PHPCUS_RECORD_INVENTORY::CUS_DELETE
					(
							$PARAM_REC_INVENTORY_ID[$ARRAY_CTR],
							
							true,
							$PDO_HANDLE
					);
					$ARRAY_CTR ++;
				}	
			}
			Catch(Exception $PDO_ERR)
			{
				PHPRC_PDO_MYSQL::REF_TRANSACTION_ROLLBACK($PDO_HANDLE);
				PHPCUS_PARAM::CUS_JSON_ERROR($PDO_ERR);
			}			
			PHPRC_PDO_MYSQL::REF_TRANSACTION_COMMIT($PDO_HANDLE);
			
			
			// Return JSON response
			// ------------------------------------------------------------------
			PHPCUS_PARAM::CUS_JSON_SUCCESS('');
		}
		Catch(Exception $ERR)
		{
			PHPCUS_PARAM::CUS_JSON_ERROR($ERR);
		}
	}
	else
	{
		PHPCUS_PARAM::CUS_JSON_ERROR('Missing parameters');
	}

?>