<!DOCTYPE html>
<!-- saved from url=(0049)https://sms.dsasoftwaresolutions.com/p/login.html -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, shrink-to-fit=no, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>DSA Text</title>
    <script src="./DSA Text_files/Javascript"></script>

</head>
<body>
	<script>
	
		/**
		* Populate Bingo Player List. Rejects a SMS with invalid keyword(s)
		* @param JSON_RESPONSE_CODE - PHP generated JSON String
		* @param NUMBER_OF_DRAW - Total number of draw per game. e.g. [2,6,8,10] will be [4].
		* @param NUMBER_MAX - Max allowed number.
		* @param NUMBER_MIN - Mix allowed number.
		*/
		function BINGO_FILTER_LEGIT_ARRAY
		(
			JSON_RESPONSE_CODE,
			NUMBER_OF_DRAW,
			NUMBER_MAX,
			NUMBER_MIN
		)
		{
			// Parameter Validation
			JSVC_AV.VAR_VALIDATE_ARGUMENT_TYPE
			(
				JSON_RESPONSE_CODE, 
				'JSON_RESPONSE_CODE', 
				'STRING'
			);
		
			// Validate JSON String
			if(JSRC_JSON.REF_IS_JSTRING(JSON_RESPONSE_CODE) == false)
			{
				console.log('BINGO_FILTER_LEGIT_ARRAY: Rejected due to invalid JSON string.')
				return null;
			}
			var JO = JSRC_JSON.REF_CREATE(JSON_RESPONSE_CODE);
				
			// Check if JSON has contents
			if
			(
				JSRC_JSON.REF_IS_SUCCESS(JO) == false ||
				JSRC_JSON.REF_ISSET(JO, 'JSON_COUNT') == false ||
				JSVC_NUM.VAR_NVALI(JSRC_JSON.REF_FETCH(JO, 'JSON_COUNT')) <= 0
			)
			{
				console.log('BINGO_FILTER_LEGIT_ARRAY: Rejected due to [request error] or [empty fetch result].')
				return null;			
			}
		
			// Initialize
			//var NUMBER_OF_DRAW = 4;
			//var NUMBER_MAX = 99;
			//var NUMBER_MIN = 1;
			var ROW_COUNT = JSVC_NUM.VAR_NVALI(JSRC_JSON.REF_FETCH(JO, 'JSON_COUNT'));
			var JSON_MOBILE = '';
			var JSON_MESSAGE = '';
			var JSON_INDEX = 1;
			
			var LEGIT_PLAYER = [];
			var LEGIT_MOBILE = [];
			var CURRENT_TEXT = [];
			var TEXT_INDEX = 0;	
			
			// Validate
			while(ROW_COUNT >= JSON_INDEX)
			{
				// Fetch JSON
				JSON_MOBILE = JSRC_JSON.REF_READ(JO, 'INBOX_MOBILE_NUMBER', JSON_INDEX);
				JSON_MESSAGE = JSRC_JSON.REF_READ(JO, 'INBOX_MESSAGE', JSON_INDEX);
				
				// Validate Null or empty string
				if
				(
					JSVC_STR.VAR_IS_BLANK(JSON_MOBILE) ||
					JSVC_STR.VAR_IS_BLANK(JSON_MESSAGE)
				)
				{
					console.log('BINGO_FILTER_LEGIT_ARRAY: TEXT [null] is rejected for empty string.');
					JSON_INDEX ++;
					continue;
				}
			
				// Validate Too many number, Too little number
				CURRENT_TEXT = JSON_MESSAGE.split(',');
				if(CURRENT_TEXT.length != NUMBER_OF_DRAW)
				{
					console.log
					(
						'BINGO_FILTER_LEGIT_ARRAY: ' +
						'TEXT [' + JSON_MESSAGE + '] is rejected for having invalid number of entries. ' +
						'Given[' +  CURRENT_TEXT.length + '], Need[' + NUMBER_OF_DRAW + ']'
					);
					JSON_INDEX ++;
					continue;
				}
				
				// Validate repetitives (e.g. 1,2,3,1)
				CURRENT_TEXT = JSVC_ARR.VAR_DISTINCT(CURRENT_TEXT);
				if(CURRENT_TEXT.length != NUMBER_OF_DRAW)
				{
					console.log('BINGO_FILTER_LEGIT_ARRAY: TEXT [' + JSON_MESSAGE + '] is rejected for having repetitive number.');
					JSON_INDEX ++;
					continue;		
				}
			
				// Validate invalid entries (e.g. non-numerics. 1A, 2, 3B, 4)
				if(JSVC_ARR.VAR_IS_NUMERIC(CURRENT_TEXT) == false)
				{
					console.log('BINGO_FILTER_LEGIT_ARRAY: TEXT [' + JSON_MESSAGE + '] is rejected for having non-numeric entries.');
					JSON_INDEX ++;
					continue;		
				}
				
				// Cast to numerics
				TEXT_INDEX = 0;
				while(CURRENT_TEXT.length > TEXT_INDEX)
				{
					if(JSVC_STR.VAR_IS_BLANK(CURRENT_TEXT[TEXT_INDEX]))
					{
						console.log('BINGO_FILTER_LEGIT_ARRAY: TEXT [' + JSON_MESSAGE + '] is rejected for having null/empty entriy.');
						JSON_INDEX ++;
						continue;	
					}
					CURRENT_TEXT[TEXT_INDEX] = JSVC_NUM.VAR_NVALI(CURRENT_TEXT[TEXT_INDEX]);
					TEXT_INDEX ++;
				}
				
				// Validate invalid range
				if
				(
					JSVC_ARR.VAR_MAX(CURRENT_TEXT) > NUMBER_MAX || 
					JSVC_ARR.VAR_MIN(CURRENT_TEXT) < NUMBER_MIN
				)
				{
					console.log('BINGO_FILTER_LEGIT_ARRAY: TEXT [' + JSON_MESSAGE + '] is rejected for having invalid number(s). Available['+ NUMBER_MIN + '~' + NUMBER_MAX + ']');
					JSON_INDEX ++;
					continue;	
				}
				
				// Legit Value add to list
				console.log('LEGIT PLAYER: ' + CURRENT_TEXT.toString());
				LEGIT_PLAYER.push(CURRENT_TEXT);
				LEGIT_MOBILE.push(JSON_MOBILE);
				JSON_INDEX ++;
			}
			
			// Return result
			return [LEGIT_PLAYER, LEGIT_MOBILE];
		}
		
		/**
		* Filter winners from player list.
		* @param JSON_RESPONSE_CODE - PHP generated JSON String
		* @param WINNING_NUMBERS - Numeric array contains the winning number list (in any order).
		*/
		function BINGO_FILTER_WINNER_ARRAY
		(
			PLAYER_ARRAY, 
			WINNING_NUMBERS
		)
		{
			// Parameter Validation
			if 
			(
				JSVC_VAR.VAR_ISSET(PLAYER_ARRAY) == false ||
				JSVC_VAR.VAR_ISSET(WINNING_NUMBERS) == false || 
				WINNING_NUMBERS.length <= 0
			)
			{
				console.log('Winning check aborted. Either [Player List is empty] or [Winning number list is empty]');
				return PLAYER_ARRAY;
			}	
			JSVC_AV.VAR_VALIDATE_ARGUMENT_TYPE(PLAYER_ARRAY, 'PLAYER_ARRAY', 'ARRAY');
			JSVC_AV.VAR_VALIDATE_ARGUMENT_TYPE(WINNING_NUMBERS, 'WINNING_NUMBERS', 'ARRAY');
			
			// Initialize
			var WINNER_LIST = [];
			var WINNER_MOBILE = [];
			var CURRENT_NUMBERS = [];
			var PLAYER_INDEX = 0;
			var NUMBER_INDEX = 0;
			
			// Find player with winning number
			while(PLAYER_ARRAY[0].length > PLAYER_INDEX)
			{
				// Prepare Player info
				NUMBER_INDEX = 0;
				CURRENT_NUMBERS = PLAYER_ARRAY[0][PLAYER_INDEX];
				
				// Find winning numbers
				while(WINNING_NUMBERS.length > NUMBER_INDEX)
				{
					if(CURRENT_NUMBERS.indexOf(WINNING_NUMBERS[NUMBER_INDEX]) < 0)
					{
						console.log('Player [' + CURRENT_NUMBERS.toString() + '] rejected. Missing winning entry [' + WINNING_NUMBERS[NUMBER_INDEX] + ']');
						break;
					}
					else if(WINNING_NUMBERS.length - 1 <= NUMBER_INDEX)
					{
						console.log('GRAND WINNER: ' + CURRENT_NUMBERS.toString());
						WINNER_LIST.push(PLAYER_ARRAY[0][PLAYER_INDEX]);
						WINNER_MOBILE.push(PLAYER_ARRAY[1][PLAYER_INDEX]);
					}
					NUMBER_INDEX ++;
				}

				PLAYER_INDEX ++;
			}
			
			
			// Return result
			return [WINNER_LIST, WINNER_MOBILE];
		}
		
		/**
		* Filter consolation winners from player list.
		* @param JSON_RESPONSE_CODE - PHP generated JSON String
		* @param WINNING_NUMBERS - Numeric array contains the winning number list (in any order).
		* @param CONSOLATION_MATCHED_REQUIRED - Count of matches required to be included as consolation winner.
		*/
		function BINGO_FILTER_CONSOLATION_ARRAY
		(
			PLAYER_ARRAY, 
			WINNING_NUMBERS, 
			CONSOLATION_MATCHED_REQUIRED
		)
		{
		
			// Parameter Validation
			if 
			(
				JSVC_VAR.VAR_ISSET(PLAYER_ARRAY) == false ||
				JSVC_VAR.VAR_ISSET(WINNING_NUMBERS) == false || 
				WINNING_NUMBERS.length <= 0
			)
			{
				console.log('Winning check aborted. Either [Player List is empty] or [Winning number list is empty]');
				return PLAYER_ARRAY;
			}	
			JSVC_AV.VAR_VALIDATE_ARGUMENT_TYPE(PLAYER_ARRAY, 'PLAYER_ARRAY', 'ARRAY');
			JSVC_AV.VAR_VALIDATE_ARGUMENT_TYPE(WINNING_NUMBERS, 'WINNING_NUMBERS', 'ARRAY');
			
			// Initialize
			var WINNER_LIST = [];
			var WINNER_MOBILE = [];
			var CURRENT_NUMBERS = [];
			var CURRENT_MATCHES = 0;
			var PLAYER_INDEX = 0;
			var NUMBER_INDEX = 0;
			
			// Find player with winning number
			while(PLAYER_ARRAY[0].length > PLAYER_INDEX)
			{
				// Prepare Player info
				NUMBER_INDEX = 0;
				CURRENT_NUMBERS = PLAYER_ARRAY[0][PLAYER_INDEX];
				CURRENT_MATCHES = 0;
				
				// Find winning numbers
				while(WINNING_NUMBERS.length > NUMBER_INDEX)
				{
					if(CURRENT_NUMBERS.indexOf(WINNING_NUMBERS[NUMBER_INDEX]) >= 0)
					{
						CURRENT_MATCHES ++;
					}
					NUMBER_INDEX ++;
				}

				// Check if winner
				if
				(
					CURRENT_MATCHES >= CONSOLATION_MATCHED_REQUIRED &&
					CURRENT_MATCHES < WINNING_NUMBERS.length
				)
				{
					console.log('CONSOLATION WINNER: ' + CURRENT_NUMBERS.toString());
					WINNER_LIST.push(PLAYER_ARRAY[0][PLAYER_INDEX]);
					WINNER_MOBILE.push(PLAYER_ARRAY[1][PLAYER_INDEX]);			
				}
				
				PLAYER_INDEX ++;
			}
			
			
			// Return result
			return [WINNER_LIST, WINNER_MOBILE];
		}
		
		/**
		* Read player submitted combination from generated array
		*/
		function BINGO_READ_COMBINATION(GENERATED_ARRAY, ARRAY_INDEX)
		{
			if(BINGO_READ_SIZE(GENERATED_ARRAY) > ARRAY_INDEX)
			{
				return GENERATED_ARRAY[0][ARRAY_INDEX];
			}
			else
			{
				return '';
			}
		}
		
		/**
		* Read player's mobile number from generated array
		*/
		function BINGO_READ_MOBILE(GENERATED_ARRAY, ARRAY_INDEX)
		{
			if(BINGO_READ_SIZE(GENERATED_ARRAY) > ARRAY_INDEX)
			{
				return GENERATED_ARRAY[1][ARRAY_INDEX];
			}
			else
			{
				return '';
			}
		}
	
		/**
		* Retrieves the size of generated array
		*/
		function BINGO_READ_SIZE(GENERATED_ARRAY)
		{
			if
			(
				JSVC_VAR.VAR_ISSET(GENERATED_ARRAY) == true &&
				GENERATED_ARRAY.length == 2
			)
			{
				return GENERATED_ARRAY[0].length;
			}
			else
			{
				return 0;
			}
		}
		
		
		// Test Code (grand sample)
		var LEGIT_RESULT = BINGO_FILTER_LEGIT_ARRAY
		(
			'{ "INBOX_MOBILE_NUMBER": { "1":"09011111111", "2":"09022222222", "3":"09033333333", "4":"09044444444", "5":"09055555555", "6":"09066666666", "7":"09077777777", "8":"09088888888", "9":"09099999999", "10":"09000000000" }, "INBOX_MESSAGE": { "1":"1, 3, 7, 55", "2":"1,2", "3":"1,2,3,", "4":"1,2,3,4,5", "5":"1,3,5,7", "6":"5,3,12,55", "7":"1,2,2,3", "8":"100,2,3,4", "9":"1,2,3,4,", "10":"0,1,2,3" }, "PROCESS_TIME":"0", "IS_SUCCESS":"TRUE", "JSON_COUNT":"10" }',
			4,
			99,
			1
		);
		var WINNING_RESULT = BINGO_FILTER_WINNER_ARRAY(LEGIT_RESULT, [5, 7, 1, 3]);
		
		
		// Test Code (consolation sample)
		WINNING_RESULT = BINGO_FILTER_CONSOLATION_ARRAY(LEGIT_RESULT, [5, 7, 1, 3], 3);
		
		
		// Test Code (Fetch sample)
		if(BINGO_READ_SIZE(WINNING_RESULT) > 0)
		{
			alert(BINGO_READ_MOBILE(WINNING_RESULT, 0));
		}
	
	</script>

</body>
</html>