<?php
namespace App\Traits;
if (!defined('BASEURL')) {
    define('BASEURL', 'https://www.steelmint.com/');
}
use DB;
trait ReferenceData
{
	 function getReferenceData($resourceType='app', $itemType='', $section='', $place='', $otherCondition='', $deviceType, $app_type='SM')
	{
		
		/* $activePackages = DB::table('tbl_region_commodity_situations as si')
					->select('si.f_platform', 'si.f_name', 'si.level_selection_level_except_steel_commodity', 'si.level_selection_level_for_steel_commodity', 'si.level_selection_level_except_india_china__region', 'si.level_selection_level_for_india_china__region', 's.section', 'm.ID', 'm.itemType', 'm.itemName', 'm.parentID', 'm.grandParentID', 'm.back_ground_image')
					->leftJoin('tbl_region_commodity_sections as s', 'si.f_section', '=', 's.section')					->leftJoin('tbl_region_commodity_master as m', 's.master_id', '=', 'm.ID')
					->where('tbl_region_commodity_sections.section' , '<>' , '')
					->orderBy('tbl_region_commodity_sections.master_id' , 'asc')
					->first(); */			
		$_cond=" AND f_platform='$resourceType' ";
		if($section!=''){
			$_cond .= " AND si.f_section='$section' ";
		}
		
		$_cond .= " AND si.forCompany='$app_type' ";
		
		if($itemType!=''){
			$_cond .= " AND m.itemType='$itemType' ";
		}
		
		if($place!=''){
			$_cond .= " AND si.f_name='$place' ";
		}
		
		if($otherCondition!=''){
			$_cond .= $otherCondition;
		}
		
		$sql= "SELECT si.f_platform, si.f_name, si.level_selection_level_except_steel_commodity, si.level_selection_level_for_steel_commodity,si.level_selection_level_except_india_china__region, si.level_selection_level_for_india_china__region			,s.section,m.ID,m.itemType,m.itemName,m.parentID, m.grandParentID, m.index_folder_image, m.back_ground_image, si.txt_selection_level_for_india_china_region			, m.web_url
		FROM `tbl_region_commodity_situations` as si 			LEFT OUTER JOIN `tbl_region_commodity_sections` as s			ON si.f_section=s.section			LEFT OUTER JOIN `tbl_region_commodity_master` as m 			ON s.master_id=m.ID  			WHERE section<>''	$_cond	
		ORDER BY `si`.`f_platform` ASC, f_name, s.section, m.f_order_by";	
		//ORDER BY `si`.`f_platform` ASC, f_name, s.section, m.parentID, m.grandParentID, m.orderBy";		
		$referenceData = DB::select($sql);	
		
		//print_r($referenceData);
		
		$itemID=array();
		$parentID=array();
		$grandParentID=array();
		foreach($referenceData as $data){
			$key_type = "others";
			if($data['itemType']=='commodity'){
				if($data['ID']==413 || $data['parentID']==413 || $data['grandParentID']==413)
					$isSelectableLevel = $data['level_selection_level_for_steel_commodity'];
				else
					$isSelectableLevel = $data['level_selection_level_except_steel_commodity'];
				
				//$sub["sub_commodity"] = array();
				$key_type = "sub_commodity";
				
			}elseif($data['itemType']=='region'){
				/* if($data['ID']==413 || $data['parentID']==413 || $data['grandParentID']==413)
					$isSelectableLevel = $data['level_selection_level_for_india_china__region'];
				else */if(strpos($data['txt_selection_level_for_india_china_region'],$data['itemName']) !== false)
					$isSelectableLevel = $data['level_selection_level_for_india_china__region'];
				else
					$isSelectableLevel = $data['level_selection_level_except_india_china__region'];
				
				//$sub["sub_region"] = array();
				$key_type = "sub_region";
			}
			
			if(strtolower($app_type) == 'cm' && $data['index_folder_image']!='')
				$data['index_folder_image'] =str_replace("https://www.steelmint.com/app_home_img/images","https://www.steelmint.com/app_home_img/images/coalmint", $data['index_folder_image']);
			
			if(strtolower($app_type) == 'cm' && $data['back_ground_image']!='')
				$data['back_ground_image'] =str_replace("https://www.steelmint.com/app_home_img/images","https://www.steelmint.com/app_home_img/images/coalmint", $data['back_ground_image']);
			//if($data['itemType']=='region')
			//	echo '-<Br>'.$data['parentID'];
			if($data['parentID']==0){
				$level = 1;
				$itemID[$data['f_name']][$data['section']][$data['itemType']][$data['ID']] =  array(
						"id" => $data['ID'],
						"name" => $data['itemName'],						
						//$sub,
						"isSelectable" => $isSelectableLevel==1 || strtolower($data['itemName'])=="all"?"y":'n',
						"bgImage"	=>	(($data['section']=='index' || $data['f_name']=='WEB_INDEX_PRE') && $data['index_folder_image']!='')?$data['index_folder_image']:$data['back_ground_image'],
						"web_url"	=>	strtolower($data['f_platform'])=='web'?$data['web_url']:'',
						$key_type => array()
					);//BASEURL ."api/public/assets/app/iron_ore_1.png",
			}else{
				if($data['grandParentID']==0){
					$level = 2;
					if($isSelectableLevel==2){
						$parentID[$data['f_name']][$data['section']][$data['itemType']][$data['parentID']][] =  array(
							"id" => $data['ID'],
							"name" => $data['itemName'],
							"isSelectable" => $isSelectableLevel==2?"y":'n',
							"bgImage"	=>	$data['back_ground_image'],
							"web_url"	=>	strtolower($data['f_platform'])=='web'?$data['web_url']:''
						);
					}
				}else{
					$level = 3;
					if($isSelectableLevel==3){ 
						$grandParentID[$data['f_name']][$data['section']][$data['itemType']][$data['grandParentID']][$data['parentID']][] =  array(
							"id" => $data['ID'],
							"name" => $data['itemName'],
							"isSelectable" => $isSelectableLevel==3?"y":'n',
							"bgImage"	=>	$data['back_ground_image'],
							"web_url"	=>	strtolower($data['f_platform'])=='web'?$data['web_url']:''
						);
					}
				}
			}
			
			$all[$data['f_name']][$data['section']][$data['itemType']][$data['ID']] =  array(
						"id" => $data['ID'],
						"name" => $data['itemName'],
						"isSelectable" => $isSelectableLevel==$level?"y":'n',
						"bgImage"	=>	(($data['section']=='index' || $data['f_name']=='WEB_INDEX_PRE') && $data['index_folder_image']!='')?$data['index_folder_image']:$data['back_ground_image'],
						"web_url"	=>	strtolower($data['f_platform'])=='web'?$data['web_url']:''
					);
		}
		
		$referenceArr=array();
		$grandParentIDArr=array();
		foreach($itemID as $f_name=>$f_name_items){//$ID
			$referenceArr[$f_name] = array();
			foreach($f_name_items as $section=>$sections){
				$referenceArr[$f_name][$section] = array();
				foreach($sections as $itemType=>$itemTypes){
					$referenceArr[$f_name][$section][$itemType] = array();
					foreach($itemTypes as $ID=>$items){
						if(isset($grandParentID[$f_name][$section][$itemType][$ID])){//$ID=>grandParentID
							$grandParentIDArr[] = $ID;
							$referenceArr[$f_name][$section][$itemType][$ID] = $all[$f_name][$section][$itemType][$ID];
							$i=0;
							foreach($grandParentID[$f_name][$section][$itemType][$ID] as $PID=>$parent_items){///$i=>$PID
								$referenceArr[$f_name][$section][$itemType][$ID]['sub_'.$itemType][$i] = $all[$f_name][$section][$itemType][$PID];
								$referenceArr[$f_name][$section][$itemType][$ID]['sub_'.$itemType][$i]['sub_commodity'] = $parent_items;
								$i++;
							}
						}elseif(isset($parentID[$f_name][$section][$itemType][$ID])){//$ID=>ParentID
							$referenceArr[$f_name][$section][$itemType][$ID] = $all[$f_name][$section][$itemType][$ID];
							$referenceArr[$f_name][$section][$itemType][$ID]['sub_'.$itemType] = $parentID[$f_name][$section][$itemType][$ID];
						}else{
							$referenceArr[$f_name][$section][$itemType][$ID] = $items;
						}
					}
				}
			}
		}
		
		$grandParentIDArr = array_unique($grandParentIDArr);
		$finalResult=array();
		$finalResult1=array();
		foreach($referenceArr as $kname=>$arr_name){
			foreach($arr_name as $ksection=>$arr_section){
				foreach($arr_section as $itemType=>$arr_itemType){
					//$finalResult[$kname][$ksection][$itemType] = array_values($arr_itemType);
					$finalResult[$kname][$itemType] = array_values($arr_itemType);
					
					/* foreach($arr_itemType as $pid=> $arr){
						//$finalResult[$kname][$ksection][$itemType][]= $pid;						
						if(in_array($pid, $grandParentIDArr)){
							foreach($arr as $pid=> $arr1){
								
							}
						}else{
							$finalResult[$kname][$ksection][$itemType][] = $arr;
							//$finalResult[$kname][$ksection][$itemType] = array_values($arr_itemType);
						}
					} */
					/*$finalResult1[$kname][$ksection][$itemType] = array_values($finalResult[$kname][$ksection][$itemType]); */
				}
			}
		}
		if($otherCondition==''){
			$dbresult = DB::table('tbl_companytype')
					->select('id','short_comptype as name' )				
					->get();
			foreach($dbresult as $cType){
				$finalResult['companyType'][$cType["id"]] = $cType["name"];
			}
		}
		
		if($otherCondition==''){
			
			$dbresult = DB::table('tbl_country')
					->select('currency_code','currency_symbol', 'section', 'country' )
					->where('section','<>',"")
					->groupBy("currency_code")
					->orderByRaw(
						 "CASE 
							WHEN currency_code='USD' THEN 1
							WHEN currency_code='INR' THEN 2
							WHEN currency_code='JPY' THEN 3
							WHEN currency_code='CNY' THEN 4
							WHEN currency_code='EUR' THEN 5
							WHEN currency_code='GBP' THEN 6
							WHEN currency_code='RUB' THEN 7
							WHEN currency_code='IDR' THEN 8						 
							ELSE 99 
						 END")
					->get();
					
			foreach($dbresult as $cType){
				if(strpos($cType["section"],'package') !== false){
					$finalResult['currencyConvertor']['packages'][] = array(
						"name" => $cType["country"],
						"code" => $cType["currency_code"],
						"symbol" => $cType["currency_symbol"],
					);
				}
				
				if(strpos($cType["section"],'price') !== false){
					$finalResult['currencyConvertor']['prices'][] = array(
						"name" => $cType["country"],
						"code" => $cType["currency_code"],
						"symbol" => $cType["currency_symbol"],
					);
				}
			}
			
			/*$finalResult['currencyConvertor'] = array(
				'packages'=>array(
					array(
						"name" => "INDIA",
						"code" => 'INR',
						"symbol" => '20B9'
					),
					array(
						"name" => "Doller",
						"code" => 'USD',
						"symbol" => '0024'
					),
					array(
						"name" => "Japanese Yen",
						"code" => 'YEN',
						"symbol" => '00A5'
					),
					array(
						"name" => "Russian ruble",
						"code" => 'RUB',
						"symbol" => '20BD'
					),
					array(
						"name" => "Renminbi, Chinese Yuan",
						"code" => 'RMB',
						"symbol" => '00A5'
					),
					array(
						"name" => "Indonesian Rupiah",
						"code" => 'IDR',
						"symbol" => '0052,0070'
					)
				),
				'prices'=>array(
					array(
						"name" => "INDIA",
						"code" => 'INR',
						"symbol" => '20B9'
					),
					array(
						"name" => "Doller",
						"code" => 'USD',
						"symbol" => '0024'
					),
					array(
						"name" => "EURO",
						"code" => 'EUR',
						"symbol" => '20AC'
					),
					array(
						"name" => "Japanese Yen",
						"code" => 'YEN',
						"symbol" => '00A5'
					),
					array(
						"name" => "Russian ruble",
						"code" => 'RUB',
						"symbol" => '20BD'
					),
					array(
						"name" => "Renminbi, Chinese Yuan",
						"code" => 'RMB',
						"symbol" => '00A5'
					),
					array(
						"name" => "Indonesian Rupiah",
						"code" => 'IDR',
						"symbol" => '0052,0070'
					)
				)				
			);*/
			
			if( ($deviceType == '' || $deviceType == 'android' || strtolower($app_type) == 'cm') && $deviceType != 'ios' ){
				$finalResult['tradeType']=array(
						""=>"All",
						"export"=>"Export",
						"import"=>"Import",
						"domestic"=>"Regional"
					);
				$finalResult['timeLine']=array(
						""=>"All",
						"2d"=>"Two Days Ago",
						"1w"=>"One week Ago",
						"2w"=>"Two week Ago"
					);
				
			} else {
				$finalResult['tradeType']=array(
						array("key" => ''	, "value"				=>			"All"),
						array("key" => 'export'	, "value"				=>			"Export"),
						array("key" => 'import'	, "value"				=>			"Import"),
						array("key" => 'domestic'	, "value"				=>			"Regional")
					);
				$finalResult['timeLine']=array(
						array("key" => ''	, "value"				=>			"All"),
						array("key" => '2d'	, "value"				=>			"Two Days Ago"),
						array("key" => '1w'	, "value"				=>			"One week Ago"),
						array("key" => '2w'	, "value"				=>			"Two week Ago")
					);
			}
			$finalResult['dataType']=array(
					""=>"All",
					"prices"=>"Prices",
					"insight"=>"Insight",
					"tenders"=>"Tenders",
					"reports"=>"Reports",
					"statistics"=>"Statistics",
					"events"=>"Events"
				);
			$finalResult['reportType']=array(
					""=>"All",
					"special"=>"Special",
					"regular"=>"Regular",
					"knowledge"=>"Knowledge"
				);
			$finalResult['eventType']=array(
					"upcoming"=>"Upcoming",
					"archieved"=>"Archieved"
				);
			$finalResult['packageTenure']=array(
					"3m"=>"3 Months",
					"6m"=>"6 Months",
					"9m"=>"9 Months",
					"1y"=>"1 Year"
				);
			//YKV 14 August 2021	
			if(strtolower($app_type) == 'cm'){	
				$finalResult['staticPagesLink']=array(
					"termsNCondition"=>"https://www.coalmint.com/termConditions?mobile=1",
					"privacyPolicy"=>"https://www.coalmint.com/privacyPolicy?mobile=1",
					"aboutUs"=>"https://www.coalmint.com/aboutUs?mobile=1",
					"methodology"=>"https://www.coalmint.com/methodology?mobile=1", 
					"logistics"=>"https://www.coalmint.com/logistics?mobile=1",
					"videoTutorialUrl"=>"https://www.youtube.com/watch?reload=9&v=X5W_3LELrAs",
					"logisticsSectionStatus"=>"active"
					/* "termsNCondition"=>"https://www.steelmint.com/app_static_pages/app_t_n_c.php",
					"privacyPolicy"=>"https://www.steelmint.com/app_static_pages/app_privacy_policy.php",
					"aboutUs"=>"https://www.steelmint.com/app_static_pages/app_about_us.html",
					"methodology"=>"http://www.steelmint.com/nw/methodology?mobile=1", 
					"logistics"=>"http://www.steelmint.com/nw/logistics?mobile=1",
					"videoTutorialUrl"=>"https://www.youtube.com/watch?reload=9&v=X5W_3LELrAs",
					"logisticsSectionStatus"=>"active" */ //used in ios to show upgrade button below webview / dont show any button below webview if logsiticssection is accessible to him
					
				);
			}else{	
				$finalResult['staticPagesLink']=array(
					"termsNCondition"=>"https://www.steelmint.com/termConditions?mobile=1",
					"privacyPolicy"=>"https://www.steelmint.com/privacyPolicy?mobile=1",
					"aboutUs"=>"https://www.steelmint.com/aboutUs?mobile=1",
					"methodology"=>"https://www.steelmint.com/methodology?mobile=1", 
					"logistics"=>"https://www.steelmint.com/logistics?mobile=1",
					"videoTutorialUrl"=>"https://www.youtube.com/watch?reload=9&v=X5W_3LELrAs",
					"logisticsSectionStatus"=>"active"
					/* "termsNCondition"=>"https://www.steelmint.com/app_static_pages/app_t_n_c.php",
					"privacyPolicy"=>"https://www.steelmint.com/app_static_pages/app_privacy_policy.php",
					"aboutUs"=>"https://www.steelmint.com/app_static_pages/app_about_us.html",
					"methodology"=>"http://www.steelmint.com/nw/methodology?mobile=1", 
					"logistics"=>"http://www.steelmint.com/nw/logistics?mobile=1",
					"videoTutorialUrl"=>"https://www.youtube.com/watch?reload=9&v=X5W_3LELrAs",
					"logisticsSectionStatus"=>"active" */ //used in ios to show upgrade button below webview / dont show any button below webview if logsiticssection is accessible to him
					
				);
			}				
			if(strtolower($app_type) == 'cm'){
				$finalResult['exploreBookmarks']=array(
					array(
					    "section"=>"Insights",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/coalmint/Insight.jpg"
					),
					array(
					    "section"=>"Tenders",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/coalmint/Tender.jpg"
					),
					array(
					    "section"=>"Reports",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/coalmint/Report.jpg"
					),
					array(
					    "section"=>"Events",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/coalmint/Ironore.jpg"
					),
					// YKV 07 Feb 2023 Added infographic bookmark for CM app
					array(
					    "section"=>"Infographics", 
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/coalmint/Infographic.jpg"
					)
					/*, YKV 14 August 2021 commented to remove Steel360 bookmark from CM app
					array(
					    "section"=>"360 Magazine",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/coalmint/Steel360.jpg"
					)*/
				);
			}else{
				
				$finalResult['exploreBookmarks']=array(
					array(
					    "section"=>"Insights",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/Insight.jpg"
					),
					array(
					    "section"=>"Tenders",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/Tender.jpg"
					),
					array(
					    "section"=>"Reports",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/Report.jpg"
					),
					array(
					    "section"=>"Events",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/Ironore.jpg"
					)
					,
					array(
					    "section"=>"360 Magazine",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/Steel360.jpg"
					),
					array(
					    "section"=>"Infographics", 
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/Infographic.jpg"
					)
				);
				
			}
				if( $app_type == 'SM' )
				    $comm = "iron ore";
				else    
				    $comm = "coal";
				
				$finalResult['preLoginStatsInputs']=array(
					"resourceType"	=> "web",
					"region"	=> "india",
					"dataType"	=> "production",//"capacity",
					"commodity"	=> $comm,//"Ferro Silicon",
					"columnNameOfRegion"	=> "country",
					"columnNameOfCommodity"	=> "commodity_new"//"subCommodity",
				);
				
				$finalResult['ExplorePricesOption']=array(
				    
					array("key" => 'Spot_Prices',       "value"				=>			"Spot Prices","url"=>'prices'),
					array("key" => 'Future_Prices',     "value"				=>			"Futures","url"=>'prices'),
					//array("key" => 'Indices_Prices',    "value"				=>			"Indices","url"=>'prices'),
					array("key" => 'Currency',          "value"				=>			"Forex","url"=>'prices')
					
				);
				
				$finalResult['sliderTextMap']=array(
					"region"=>"region Text",
					"commodity"=>"commodity Text",
					"homeslider3"=>"homeslider3 Text",
					"homeslider4"=>"homeslider4 Text",
				);
		}
		return $finalResult;
	}
		
	function getReferenceDataFilter($resourceType='web', $itemType='', $section='', $place='', $otherCondition='')
	{
		$sql = "SELECT * FROM `tbl_region_commodity_master` WHERE itemType<>'' ";
		if($resourceType=='web'){
			if($place=='footer'){
				$sql.= " AND parentID=0 AND ((itemType='commodity' and index_folder_image<>'') OR itemType='region')";
			}
			
			if($itemType=='region'){
				$sql.= " AND parentID=0 ";
			}
			
			if($itemType!=''){
				$sql.= " AND itemType='$itemType'";
			}else{
				$sql.= " AND itemType in ('region', 'commodity')";
			}				
		}		
		
		$sql.=" Order By itemType, parentID desc, itemName";
		$referenceData = DB::select($sql);
		//dd(DB::getQueryLog());	
		//print_r($referenceData);
		$result = array();
		$resultChild = array();
		foreach($referenceData as $data){
			
			
			if($data['parentID']==0){
				$result[$data["itemType"]][] = array(
						"id" => $data['ID'],
						"name" => $data['itemName'],
						//"isSelectable" => $isSelectableLevel==$level?"y":'n',
						"bgImage"	=>	$data['index_folder_image']!=''?$data['index_folder_image']:$data['back_ground_image'],
						"sub_".$data["itemType"].""	=>	$resultChild[$data['ID']]
					);
			}elseif($data['parentID']!=413){
				$parentID  = $data['parentID'];
				if($data['grandParentID']==413){
					$parentID  = $data['grandParentID'];
				}
				
				$resultChild[$parentID][] = array(
						"id" => $data['ID'],
						"name" => $data['itemName'],
						//"isSelectable" => $isSelectableLevel==$level?"y":'n',
						"bgImage"	=>	$data['index_folder_image']!=''?$data['index_folder_image']:$data['back_ground_image']
					);
			}
		}	
		
		return $result;
	}
	
	public $referenceDataArr = array(
		'home'=>array(
			"commodity" => array(
				array(
					"id" => 1,
					"name" => "Iron Ore",
					"sub_commodity" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	BASEURL ."api/public/assets/app/iron_ore_1.png"
				),
				array(
					"id" => 2,
					"name" => "Coal",
					"sub_commodity" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	BASEURL ."api/public/assets/app/coal_1.png"
				),
				array(
					"id" => 3,
					"name" => "Scrap & Metallics",
					"sub_commodity" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	BASEURL ."api/public/assets/app/scraps_1.png"
				),
				array(
					"id" => 4,
					"name" => "Steel",
					"sub_commodity" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	BASEURL ."api/public/assets/app/steel_1.png"
				),
				array(
					"id" => 5,
					"name" => "Ferro Alloy",
					"sub_commodity" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	BASEURL ."api/public/assets/app/ferro_alloy_1.png"
				),
				array(
					"id" => 6,
					"name" => "Logistics",
					"sub_commodity" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	BASEURL ."api/public/assets/app/steel_1.png"
				),
				array(
					"id" => 7,
					"name" => "Ship Breaking",
					"sub_commodity" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	BASEURL ."api/public/assets/app/ship_breakings_1.png"
				)
),
"region"=>array(
				array(
					"id" => 1,
					"name" => "Americas",
					"sub_region" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	"https://public-v2links.adobecc.com/6ac9b0eb-50df-4ac9-73b0-75f755ebd66c/component?params=component_id:3078006e-a353-4e2d-a9b7-f82d472c83bd&params=version:0&token=1561694501_da39a3ee_e2c49f341799157df98ae5cc6b712f302fef7955&api_key=CometServer1"
				),
				array(
					"id" => 2,
					"name" => "UK, Europe",
					"sub_region" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	"https://public-v2links.adobecc.com/6ac9b0eb-50df-4ac9-73b0-75f755ebd66c/component?params=component_id:88b4078f-959f-4be3-a5f0-84b9a8684c57&params=version:0&token=1561694501_da39a3ee_e2c49f341799157df98ae5cc6b712f302fef7955&api_key=CometServer1"
				),
				array(
					"id" => 3,
					"name" => "South East Asia",
					"sub_region" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	"https://public-v2links.adobecc.com/6ac9b0eb-50df-4ac9-73b0-75f755ebd66c/component?params=component_id:3078006e-a353-4e2d-a9b7-f82d472c83bd&params=version:0&token=1561694501_da39a3ee_e2c49f341799157df98ae5cc6b712f302fef7955&api_key=CometServer1"
				),
				array(
					"id" => 4,
					"name" => "South Asia",
					"sub_region" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	"https://public-v2links.adobecc.com/6ac9b0eb-50df-4ac9-73b0-75f755ebd66c/component?params=component_id:88b4078f-959f-4be3-a5f0-84b9a8684c57&params=version:0&token=1561694501_da39a3ee_e2c49f341799157df98ae5cc6b712f302fef7955&api_key=CometServer1"
				),
				array(
					"id" => 5,
					"name" => "MEA (Middle East Africa)",
					"sub_region" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	"https://public-v2links.adobecc.com/6ac9b0eb-50df-4ac9-73b0-75f755ebd66c/component?params=component_id:3078006e-a353-4e2d-a9b7-f82d472c83bd&params=version:0&token=1561694501_da39a3ee_e2c49f341799157df98ae5cc6b712f302fef7955&api_key=CometServer1"
				),
				array(
					"id" => 6,
					"name" => "Far East Aisa",
					"sub_region" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	"https://public-v2links.adobecc.com/6ac9b0eb-50df-4ac9-73b0-75f755ebd66c/component?params=component_id:3078006e-a353-4e2d-a9b7-f82d472c83bd&params=version:0&token=1561694501_da39a3ee_e2c49f341799157df98ae5cc6b712f302fef7955&api_key=CometServer1"
				),
				array(
					"id" => 7,
					"name" => "CIS Nations",
					"sub_region" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	"https://public-v2links.adobecc.com/6ac9b0eb-50df-4ac9-73b0-75f755ebd66c/component?params=component_id:3078006e-a353-4e2d-a9b7-f82d472c83bd&params=version:0&token=1561694501_da39a3ee_e2c49f341799157df98ae5cc6b712f302fef7955&api_key=CometServer1"
				),
				array(
					"id" => 8,
					"name" => "Ocenia",
					"sub_region" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	"https://public-v2links.adobecc.com/6ac9b0eb-50df-4ac9-73b0-75f755ebd66c/component?params=component_id:3078006e-a353-4e2d-a9b7-f82d472c83bd&params=version:0&token=1561694501_da39a3ee_e2c49f341799157df98ae5cc6b712f302fef7955&api_key=CometServer1"
				),
				array(
					"id" => 9,
					"name" => "India",
					"sub_region" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	"https://public-v2links.adobecc.com/6ac9b0eb-50df-4ac9-73b0-75f755ebd66c/component?params=component_id:88b4078f-959f-4be3-a5f0-84b9a8684c57&params=version:0&token=1561694501_da39a3ee_e2c49f341799157df98ae5cc6b712f302fef7955&api_key=CometServer1"
				),
				array(
					"id" => 10,
					"name" => "China",
					"sub_region" => array(),
					"isSelectable" => "y",
					"bgImage"	=>	"https://public-v2links.adobecc.com/6ac9b0eb-50df-4ac9-73b0-75f755ebd66c/component?params=component_id:9a814cd4-8120-4b69-8763-299ab2b691fb&params=version:0&token=1561694501_da39a3ee_e2c49f341799157df98ae5cc6b712f302fef7955&api_key=CometServer1"
				)
)
						),
						'insights' =>	array(
"commodity" => array(
				array(
					"id" => 1,
					"name" => "Iron Ore",
					"sub_commodity" => array(
						array(
							"id" => 11,
							"name" => "Fines, Lumps",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 12,
							"name" => "Pellets",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "n"
				),
				array(
					"id" => 2,
					"name" => "Coal",
					"sub_commodity" => array(
						array(
							"id" => 21,
							"name" => "Coking coal",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 22,
							"name" => "Met Coke",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 23,
							"name" => "Non Coking coal",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 24,
							"name" => "Pet Coke",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 3,
					"name" => "Scrap & Metallics",
					"sub_commodity" => array(
						array(
							"id" => 31,
							"name" => "Melting Scrap",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 32,
							"name" => "Mill Scale",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 33,
							"name" => "Pig Iron",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 34,
							"name" => "Sponge Iron",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 4,
					"name" => "Steel",
					"sub_commodity" => array(
						array(
							"id" => 41,
							"name" => "Semi Finished",
							"sub_commodity" => array(
								array(
									"id" => 411,
									"name" => "Billet, Ingot, Slabs",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								)
							),
							"isSelectable" => "y"
						),
						array(
							"id" => 42,
							"name" => "Finish Long",
							"sub_commodity" => array(
								array(
									"id" => 421,
									"name" => "Rebar",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 422,
									"name" => "Pipes",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 423,
									"name" => "Structure",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 424,
									"name" => "Wire Rod",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								)
							),
							"isSelectable" => "y"
						),
						array(
							"id" => 43,
							"name" => "Finish Flat",
							"sub_commodity" => array(
								array(
									"id" => 431,
									"name" => "HRC",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 432,
									"name" => "CRC",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 433,
									"name" => "HR Plate",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 434,
									"name" => "GP",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 435,
									"name" => "PPGI",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								)
							),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 5,
					"name" => "Ferro Alloy",
					"sub_commodity" => array(
						array(
							"id" => 51,
							"name" => "Silico Manganese",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 52,
							"name" => "Ferro Manganese",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 53,
							"name" => "Ferro Chrome",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 54,
							"name" => "Ferro Silicon",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 55,
							"name" => "Manganese Ore",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 56,
							"name" => "Chrome Ore",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 6,
					"name" => "Logistics",
					"sub_commodity" => array(),
					"isSelectable" => "y"
				),
				array(
					"id" => 7,
					"name" => "Ship Breaking",
					"sub_commodity" => array(),
					"isSelectable" => "y"
				)
),
"region"=>array(
				array(
					"id" => 1,
					"name" => "Americas",
					"sub_region" => array(
						array(
							"id" => 11,
							"name" => "United states of america",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 12,
							"name" => "Canada",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 13,
							"name" => "Brazil",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 14,
							"name" => "Colombia",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "n"
				),
				array(
					"id" => 2,
					"name" => "UK, Europe",
					"sub_region" => array(
						array(
							"id" => 21,
							"name" => "United kingdom",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 22,
							"name" => "Sweden",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 23,
							"name" => "Czech Republic",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 24,
							"name" => "Italy",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 3,
					"name" => "South East Asia",
					"sub_region" => array(
						array(
							"id" => 31,
							"name" => "Thailand",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 32,
							"name" => "Philippines",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 33,
							"name" => "Indonesia",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 34,
							"name" => "Vietnam",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 35,
							"name" => "Singapore",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 4,
					"name" => "South Asia",
					"sub_region" => array(
						array(
							"id" => 41,
							"name" => "Nepal",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 42,
							"name" => "Sri Lanka",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 43,
							"name" => "Bangladesh",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 44,
							"name" => "Pakistan",
							"sub_region" => array(),
							"isSelectable" => "y"
						)						
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 5,
					"name" => "MEA (Middle East Africa)",
					"sub_region" => array(
						array(
							"id" => 51,
							"name" => "South Africa",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 52,
							"name" => "Iran",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 53,
							"name" => "Bahrain",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 54,
							"name" => "Dubai",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 55,
							"name" => "UAE",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 56,
							"name" => "Saudi Arabia",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 57,
							"name" => "Kazakhstan",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 6,
					"name" => "Far East Aisa",
					"sub_region" => array(
						array(
							"id" => 61,
							"name" => "Japan",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 62,
							"name" => "Korea (south korea)",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 63,
							"name" => "Taiwan",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 7,
					"name" => "CIS Nations",
					"sub_region" => array(
						array(
							"id" => 71,
							"name" => "Ukraine",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 72,
							"name" => "Turkey",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 73,
							"name" => "Russia",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 74,
							"name" => "Mongolia",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 8,
					"name" => "Ocenia",
					"sub_region" => array(
						array(
							"id" => 81,
							"name" => "Australia",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 82,
							"name" => "Newzealand",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 9,
					"name" => "India",
					"sub_region" => array(),
					"isSelectable" => "y"
				),
				array(
					"id" => 10,
					"name" => "China",
					"sub_region" => array(),
					"isSelectable" => "y"
				)
)
						),
						'tenders' => array(
"commodity" => array(
				array(
					"id" => 1,
					"name" => "Iron Ore",
					"sub_commodity" => array(
						array(
							"id" => 11,
							"name" => "Fines, Lumps",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 12,
							"name" => "Pellets",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "n"
				),
				array(
					"id" => 2,
					"name" => "Coal",
					"sub_commodity" => array(
						array(
							"id" => 21,
							"name" => "Coking coal",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 22,
							"name" => "Met Coke",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 23,
							"name" => "Non Coking coal",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 24,
							"name" => "Pet Coke",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 3,
					"name" => "Scrap & Metallics",
					"sub_commodity" => array(
						array(
							"id" => 31,
							"name" => "Melting Scrap",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 32,
							"name" => "Mill Scale",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 33,
							"name" => "Pig Iron",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 34,
							"name" => "Sponge Iron",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 4,
					"name" => "Steel",
					"sub_commodity" => array(
						array(
							"id" => 41,
							"name" => "Semi Finished",
							"sub_commodity" => array(
								array(
									"id" => 411,
									"name" => "Billet, Ingot, Slabs",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								)
							),
							"isSelectable" => "y"
						),
						array(
							"id" => 42,
							"name" => "Finish Long",
							"sub_commodity" => array(
								array(
									"id" => 421,
									"name" => "Rebar",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 422,
									"name" => "Pipes",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 423,
									"name" => "Structure",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 424,
									"name" => "Wire Rod",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								)
							),
							"isSelectable" => "y"
						),
						array(
							"id" => 43,
							"name" => "Finish Flat",
							"sub_commodity" => array(
								array(
									"id" => 431,
									"name" => "HRC",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 432,
									"name" => "CRC",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 433,
									"name" => "HR Plate",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 434,
									"name" => "GP",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 435,
									"name" => "PPGI",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								)
							),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 5,
					"name" => "Ferro Alloy",
					"sub_commodity" => array(
						array(
							"id" => 51,
							"name" => "Silico Manganese",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 52,
							"name" => "Ferro Manganese",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 53,
							"name" => "Ferro Chrome",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 54,
							"name" => "Ferro Silicon",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 55,
							"name" => "Manganese Ore",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 56,
							"name" => "Chrome Ore",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 6,
					"name" => "Logistics",
					"sub_commodity" => array(),
					"isSelectable" => "y"
				),
				array(
					"id" => 7,
					"name" => "Ship Breaking",
					"sub_commodity" => array(),
					"isSelectable" => "y"
				)
),
"region"=>array(
				array(
					"id" => 1,
					"name" => "Americas",
					"sub_region" => array(
						array(
							"id" => 11,
							"name" => "United states of america",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 12,
							"name" => "Canada",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 13,
							"name" => "Brazil",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 14,
							"name" => "Colombia",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "n"
				),
				array(
					"id" => 2,
					"name" => "UK, Europe",
					"sub_region" => array(
						array(
							"id" => 21,
							"name" => "United kingdom",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 22,
							"name" => "Sweden",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 23,
							"name" => "Czech Republic",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 24,
							"name" => "Italy",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 3,
					"name" => "South East Asia",
					"sub_region" => array(
						array(
							"id" => 31,
							"name" => "Thailand",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 32,
							"name" => "Philippines",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 33,
							"name" => "Indonesia",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 34,
							"name" => "Vietnam",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 35,
							"name" => "Singapore",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 4,
					"name" => "South Asia",
					"sub_region" => array(
						array(
							"id" => 41,
							"name" => "Nepal",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 42,
							"name" => "Sri Lanka",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 43,
							"name" => "Bangladesh",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 44,
							"name" => "Pakistan",
							"sub_region" => array(),
							"isSelectable" => "y"
						)						
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 5,
					"name" => "MEA (Middle East Africa)",
					"sub_region" => array(
						array(
							"id" => 51,
							"name" => "South Africa",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 52,
							"name" => "Iran",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 53,
							"name" => "Bahrain",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 54,
							"name" => "Dubai",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 55,
							"name" => "UAE",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 56,
							"name" => "Saudi Arabia",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 57,
							"name" => "Kazakhstan",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 6,
					"name" => "Far East Aisa",
					"sub_region" => array(
						array(
							"id" => 61,
							"name" => "Japan",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 62,
							"name" => "Korea (south korea)",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 63,
							"name" => "Taiwan",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 7,
					"name" => "CIS Nations",
					"sub_region" => array(
						array(
							"id" => 71,
							"name" => "Ukraine",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 72,
							"name" => "Turkey",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 73,
							"name" => "Russia",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 74,
							"name" => "Mongolia",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 8,
					"name" => "Ocenia",
					"sub_region" => array(
						array(
							"id" => 81,
							"name" => "Australia",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 82,
							"name" => "Newzealand",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 9,
					"name" => "India",
					"sub_region" => array(),
					"isSelectable" => "y"
				),
				array(
					"id" => 10,
					"name" => "China",
					"sub_region" => array(),
					"isSelectable" => "y"
				)
)
						),
						'prices' => array(
"commodity" => array(
				array(
					"id" => 1,
					"name" => "Iron Ore",
					"sub_commodity" => array(
						array(
							"id" => 11,
							"name" => "Fines, Lumps",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 12,
							"name" => "Pellets",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "n"
				),
				array(
					"id" => 2,
					"name" => "Coal",
					"sub_commodity" => array(
						array(
							"id" => 21,
							"name" => "Coking coal",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 22,
							"name" => "Met Coke",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 23,
							"name" => "Non Coking coal",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 24,
							"name" => "Pet Coke",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 3,
					"name" => "Scrap & Metallics",
					"sub_commodity" => array(
						array(
							"id" => 31,
							"name" => "Melting Scrap",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 32,
							"name" => "Mill Scale",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 33,
							"name" => "Pig Iron",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 34,
							"name" => "Sponge Iron",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 4,
					"name" => "Steel",
					"sub_commodity" => array(
						array(
							"id" => 41,
							"name" => "Semi Finished",
							"sub_commodity" => array(
								array(
									"id" => 411,
									"name" => "Billet, Ingot, Slabs",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								)
							),
							"isSelectable" => "y"
						),
						array(
							"id" => 42,
							"name" => "Finish Long",
							"sub_commodity" => array(
								array(
									"id" => 421,
									"name" => "Rebar",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 422,
									"name" => "Pipes",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 423,
									"name" => "Structure",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 424,
									"name" => "Wire Rod",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								)
							),
							"isSelectable" => "y"
						),
						array(
							"id" => 43,
							"name" => "Finish Flat",
							"sub_commodity" => array(
								array(
									"id" => 431,
									"name" => "HRC",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 432,
									"name" => "CRC",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 433,
									"name" => "HR Plate",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 434,
									"name" => "GP",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								),
								array(
									"id" => 435,
									"name" => "PPGI",
									"sub_commodity" => array(),
									"isSelectable" => "y"
								)
							),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 5,
					"name" => "Ferro Alloy",
					"sub_commodity" => array(
						array(
							"id" => 51,
							"name" => "Silico Manganese",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 52,
							"name" => "Ferro Manganese",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 53,
							"name" => "Ferro Chrome",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 54,
							"name" => "Ferro Silicon",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 55,
							"name" => "Manganese Ore",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 56,
							"name" => "Chrome Ore",
							"sub_commodity" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 6,
					"name" => "Logistics",
					"sub_commodity" => array(),
					"isSelectable" => "y"
				),
				array(
					"id" => 7,
					"name" => "Ship Breaking",
					"sub_commodity" => array(),
					"isSelectable" => "y"
				)
),
"region"=>array(
				array(
					"id" => 1,
					"name" => "Americas",
					"sub_region" => array(
						array(
							"id" => 11,
							"name" => "United states of america",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 12,
							"name" => "Canada",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 13,
							"name" => "Brazil",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 14,
							"name" => "Colombia",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "n"
				),
				array(
					"id" => 2,
					"name" => "UK, Europe",
					"sub_region" => array(
						array(
							"id" => 21,
							"name" => "United kingdom",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 22,
							"name" => "Sweden",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 23,
							"name" => "Czech Republic",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 24,
							"name" => "Italy",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 3,
					"name" => "South East Asia",
					"sub_region" => array(
						array(
							"id" => 31,
							"name" => "Thailand",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 32,
							"name" => "Philippines",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 33,
							"name" => "Indonesia",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 34,
							"name" => "Vietnam",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 35,
							"name" => "Singapore",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 4,
					"name" => "South Asia",
					"sub_region" => array(
						array(
							"id" => 41,
							"name" => "Nepal",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 42,
							"name" => "Sri Lanka",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 43,
							"name" => "Bangladesh",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 44,
							"name" => "Pakistan",
							"sub_region" => array(),
							"isSelectable" => "y"
						)						
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 5,
					"name" => "MEA (Middle East Africa)",
					"sub_region" => array(
						array(
							"id" => 51,
							"name" => "South Africa",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 52,
							"name" => "Iran",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 53,
							"name" => "Bahrain",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 54,
							"name" => "Dubai",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 55,
							"name" => "UAE",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 56,
							"name" => "Saudi Arabia",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 57,
							"name" => "Kazakhstan",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 6,
					"name" => "Far East Aisa",
					"sub_region" => array(
						array(
							"id" => 61,
							"name" => "Japan",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 62,
							"name" => "Korea (south korea)",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 63,
							"name" => "Taiwan",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 7,
					"name" => "CIS Nations",
					"sub_region" => array(
						array(
							"id" => 71,
							"name" => "Ukraine",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 72,
							"name" => "Turkey",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 73,
							"name" => "Russia",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 74,
							"name" => "Mongolia",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 8,
					"name" => "Ocenia",
					"sub_region" => array(
						array(
							"id" => 81,
							"name" => "Australia",
							"sub_region" => array(),
							"isSelectable" => "y"
						),
						array(
							"id" => 82,
							"name" => "Newzealand",
							"sub_region" => array(),
							"isSelectable" => "y"
						)
					),
					"isSelectable" => "y"
				),
				array(
					"id" => 9,
					"name" => "India",
					"sub_region" => array(),
					"isSelectable" => "y"
				),
				array(
					"id" => 10,
					"name" => "China",
					"sub_region" => array(),
					"isSelectable" => "y"
				)
)
						),
				'currencyConvertor'=>array(
					array(
					"name" => "INDIA",
					"code" => 'INR',
					"symbol" => 'u\20B9'
					),
					array(
					"name" => "Doller",
					"code" => 'EUR',
					"symbol" => 'u\0024'
					),
					array(
					"name" => "Japanese Yen",
					"code" => 'YEN',
					"symbol" => 'u\00A5'
					),
					array(
					"name" => "Russian ruble",
					"code" => 'RUB',
					"symbol" => 'u\20BD'
					),
					array(
					"name" => "Renminbi, Chinese Yuan",
					"code" => 'RMB',
					"symbol" => 'u\00A5'
					),
					array(
					"name" => "Indonesian Rupiah",
					"code" => 'IDR',
					"symbol" => 'u\0052,u\0070'
					)
				),
				'tradeType'=>array(
					"all"=>"All",
					"domestic"=>"Domestic",
					"import"=>"Import",
					"export"=>"Export"
				),
				'timeLine'=>array(
					""=>"All",
					"2d"=>"Two Days Ago",
					"1w"=>"One week Ago",
					"2w"=>"Two week Ago"
				),
				'dataType'=>array(
					"all"=>"All",
					"prices"=>"Prices",
					"insight"=>"Insight",
					"tenders"=>"Tenders",
					"reports"=>"Reports",
					"statistics"=>"Statistics",
					"events"=>"Events"
				),
				'reportType'=>array(
					"all"=>"All",
					"special"=>"Special",
					"regular"=>"Regular",
					"knowledge"=>"Knowledge"
				),
				'packageTenure'=>array(
					"3m"=>"3 Months",
					"6m"=>"6 Months",
					"9m"=>"9 Months",
					"1y"=>"1 Year"
				),
	);
	
    function getReferenceDataBM($resourceType='app', $itemType='', $section='', $place='', $otherCondition='', $deviceType, $app_type='SM')
	{			
		$_cond=" AND f_platform='$resourceType' ";
		if($section!=''){
			$_cond .= " AND si.f_section='$section' ";
		}
		
		$_cond .= " AND si.forCompany='$app_type' ";
		
		if($itemType!=''){
			$_cond .= " AND m.itemType='$itemType' ";
		}
		
		if($place!=''){
			$_cond .= " AND si.f_name='$place' ";
		}
		
		if($otherCondition!=''){
			$_cond .= $otherCondition;
		}
		
		$sql= "SELECT si.f_platform, si.f_name, si.level_selection_level_except_steel_commodity, si.level_selection_level_for_steel_commodity,si.level_selection_level_except_india_china__region, si.level_selection_level_for_india_china__region			,s.section,m.ID,m.itemType,m.itemName,m.parentID, m.grandParentID, m.index_folder_image, m.back_ground_image, si.txt_selection_level_for_india_china_region			, m.web_url, m.f_market
		FROM `tbl_region_commodity_situations` as si 			LEFT OUTER JOIN `tbl_region_commodity_sections` as s			ON si.f_section=s.section			LEFT OUTER JOIN `tbl_region_commodity_master` as m 			ON s.master_id=m.ID  			WHERE section<>''	$_cond	
		ORDER BY `si`.`f_platform` ASC, f_name, s.section, m.f_order_by";	
		//ORDER BY `si`.`f_platform` ASC, f_name, s.section, m.parentID, m.grandParentID, m.orderBy";		
		$referenceData = DB::select($sql);	
		
		//print_r($referenceData);
		
		 $itemID=array();
		$parentID=array();
		$grandParentID=array();
		$market_master =
		array (
            'ferrous' => 'Ferrous Metals',
            'non-ferrous' => 'Non Ferrous',
            'coal' => 'Coal & Energy',
            'scrap-recycling' => 'Scrap Recycling',
			'agriculture' => 'Agriculture'
        );
		foreach($referenceData as $data){
			$key_type = "others";
			if($data['itemType']=='commodity'){
				if($data['ID']==413 || $data['parentID']==413 || $data['grandParentID']==413)
					$isSelectableLevel = $data['level_selection_level_for_steel_commodity'];
				else
					$isSelectableLevel = $data['level_selection_level_except_steel_commodity'];
				
				//$sub["sub_commodity"] = array();
				$key_type = "sub_commodity";
				
			}elseif($data['itemType']=='region'){
				/* if($data['ID']==413 || $data['parentID']==413 || $data['grandParentID']==413)
					$isSelectableLevel = $data['level_selection_level_for_india_china__region'];
				else */if(strpos($data['txt_selection_level_for_india_china_region'],$data['itemName']) !== false)
					$isSelectableLevel = $data['level_selection_level_for_india_china__region'];
				else
					$isSelectableLevel = $data['level_selection_level_except_india_china__region'];
				
				//$sub["sub_region"] = array();
				$key_type = "sub_region";
			}
			
			if(strtolower($app_type) == 'cm' && $data['index_folder_image']!='')
				$data['index_folder_image'] =str_replace("https://www.steelmint.com/app_home_img/images","https://www.steelmint.com/app_home_img/images/coalmint", $data['index_folder_image']);
			
			if(strtolower($app_type) == 'cm' && $data['back_ground_image']!='')
				$data['back_ground_image'] =str_replace("https://www.steelmint.com/app_home_img/images","https://www.steelmint.com/app_home_img/images/coalmint", $data['back_ground_image']);
			//if($data['itemType']=='region')
			//	echo '-<Br>'.$data['parentID'];
			if($data['itemType']=='region')
                $f_market_arr = array('ferrous','non-ferrous', 'coal','scrap-recycling','agriculture');
			else{
                if($data['parentID']==0 && $data['ID']==972 && $data['itemType']=='commodity' && $resourceType=='app'){
                    $f_market_arr  = array_filter(array_unique(array_map('trim',explode(",",$data['f_market'].",scrap-recycling"))));
                }else{
                    $f_market_arr  = array_filter(array_map('trim',explode(",",$data['f_market'])));
                }
            }
			if($data['parentID']==0){
				$level = 1;
				foreach($f_market_arr as $f_market){
                    $itemID[$data['f_name']][$data['section']][$data['itemType']][$f_market][$data['ID']] =  array(
                            "id" => $data['ID'],
                            "name" => $data['itemName'],						
                            //$sub,
                            "isSelectable" => $isSelectableLevel==1 || strtolower($data['itemName'])=="all"?"y":'n',
                            "bgImage"	=>	(($data['section']=='index' || $data['f_name']=='WEB_INDEX_PRE') && $data['index_folder_image']!='')?$data['index_folder_image']:$data['back_ground_image'],
                            "web_url"	=>	strtolower($data['f_platform'])=='web'?$data['web_url']:'',
                            $key_type => array()
                        );//BASEURL ."api/public/assets/app/iron_ore_1.png",
                       //adding the non-ferrous as commodity in scrap market for commodity only  
                    /*if($data['ID']==972 && $f_market=='non-ferrous' && $data['itemType']=='commodity' && $resourceType=='app'){
                         $itemID[$data['f_name']][$data['section']][$data['itemType']]['scrap-recycling'][$data['ID']] =  array(
                            "id" => $data['ID'],
                            "name" => $data['itemName'],						
                            //$sub,
                            "isSelectable" => $isSelectableLevel==1 || strtolower($data['itemName'])=="all"?"y":'n',
                            "bgImage"	=>	(($data['section']=='index' || $data['f_name']=='WEB_INDEX_PRE') && $data['index_folder_image']!='')?$data['index_folder_image']:$data['back_ground_image'],
                            "web_url"	=>	strtolower($data['f_platform'])=='web'?$data['web_url']:'',
                            $key_type => array()
                        );
                    }*/
                }
			}else{
				if($data['grandParentID']==0){
					$level = 2;
					if($isSelectableLevel==2){
                        foreach($f_market_arr as $f_market){
                            $parentID[$data['f_name']][$data['section']][$data['itemType']][$f_market][$data['parentID']][] =  array(
                                "id" => $data['ID'],
                                "name" => $data['itemName'],
                                "isSelectable" => $isSelectableLevel==2?"y":'n',
                                "bgImage"	=>	$data['back_ground_image'],
                                "web_url"	=>	strtolower($data['f_platform'])=='web'?$data['web_url']:''
                            );
						}
					}
				}else{
					$level = 3;
					if($isSelectableLevel==3){ 
                        foreach($f_market_arr as $f_market){
                            $grandParentID[$data['f_name']][$data['section']][$data['itemType']][$f_market][$data['grandParentID']][$data['parentID']][] =  array(
                                "id" => $data['ID'],
                                "name" => $data['itemName'],
                                "isSelectable" => $isSelectableLevel==3?"y":'n',
                                "bgImage"	=>	$data['back_ground_image'],
                                "web_url"	=>	strtolower($data['f_platform'])=='web'?$data['web_url']:''
                            );
                        }
					}
				}
			}
			foreach($f_market_arr as $f_market){
                $all[$data['f_name']][$data['section']][$data['itemType']][$f_market][$data['ID']] =  array(
                    "id" => $data['ID'],
                    "name" => $data['itemName'],
                    "isSelectable" => $isSelectableLevel==$level?"y":'n',
                    "bgImage"	=>	(($data['section']=='index' || $data['f_name']=='WEB_INDEX_PRE') && $data['index_folder_image']!='')?$data['index_folder_image']:$data['back_ground_image'],
                    "web_url"	=>	strtolower($data['f_platform'])=='web'?$data['web_url']:''
                );
            }
		}
		if($_REQUEST['debug']==1){
            echo "<pre>";            
            echo json_encode($itemID);
            echo "</pre>";
		}
		$referenceArr=array();
		$grandParentIDArr=array();
		foreach($itemID as $f_name=>$f_name_items){//$ID
			$referenceArr[$f_name] = array();
			foreach($f_name_items as $section=>$sections){
				$referenceArr[$f_name][$section] = array();
				foreach($sections as $itemType=>$itemTypes){
					$referenceArr[$f_name][$section][$itemType] = array();
					foreach($itemTypes as $market=>$markets){
                        $referenceArr[$f_name][$section][$itemType][$market]= array();
                        foreach($markets as $ID=>$items){
                            if(isset($grandParentID[$f_name][$section][$itemType][$market][$ID])){//$ID=>grandParentID
                                $grandParentIDArr[] = $ID;
                                $referenceArr[$f_name][$section][$itemType][$market][$ID] = $all[$f_name][$section][$itemType][$market][$ID];
                                $i=0;
                                foreach($grandParentID[$f_name][$section][$itemType][$market][$ID] as $PID=>$parent_items){///$i=>$PID
                                    $referenceArr[$f_name][$section][$itemType][$market][$ID]['sub_'.$itemType][$i] = $all[$f_name][$section][$itemType][$market][$PID];
                                    $referenceArr[$f_name][$section][$itemType][$market][$ID]['sub_'.$itemType][$i]['sub_commodity'] = $parent_items;
                                    $i++;
                                }
                            }elseif(isset($parentID[$f_name][$section][$itemType][$market][$ID])){//$ID=>ParentID
                                $referenceArr[$f_name][$section][$itemType][$market][$ID] = $all[$f_name][$section][$itemType][$market][$ID];
                                $referenceArr[$f_name][$section][$itemType][$market][$ID]['sub_'.$itemType] = $parentID[$f_name][$section][$itemType][$market][$ID];
                            }else{
                                $referenceArr[$f_name][$section][$itemType][$market][$ID] = $items;
                            }
                        }
                    }
				}
			}
		}		
		$grandParentIDArr = array_unique($grandParentIDArr);
		$finalResult=array();
		$finalResult1=array();
		
        $region_merged=array();
		foreach($referenceArr as $kname=>$arr_name){
			foreach($arr_name as $ksection=>$arr_section){
				foreach($arr_section as $itemType=>$arr_itemType){
                    foreach($arr_itemType as $market=>$arr_market){
                        //$finalResult[$kname][$ksection][$itemType] = array_values($arr_itemType);
                            /*if($itemType=='region'){
                                 $finalResult[$kname][$itemType] = array_values($arr_market);
                            }else*/{
                                $finalResult[$kname][$itemType][] = 
                                array(
                                    //"id" => $market,
                                    "market_id" => $market,
                                    "name"=> $market_master[$market],
                                    "data" => array_values($arr_market)
                                );
                            }
                        
                        /* foreach($arr_itemType as $pid=> $arr){
                            //$finalResult[$kname][$ksection][$itemType][]= $pid;						
                            if(in_array($pid, $grandParentIDArr)){
                                foreach($arr as $pid=> $arr1){
                                    
                                }
                            }else{
                                $finalResult[$kname][$ksection][$itemType][] = $arr;
                                //$finalResult[$kname][$ksection][$itemType] = array_values($arr_itemType);
                            }
                        } */
                        /*$finalResult1[$kname][$ksection][$itemType] = array_values($finalResult[$kname][$ksection][$itemType]); */
                    }
                }
			}
		}
		
		
		if($resourceType=='app'){
            $finalResult_temp=$finalResult;
            foreach($finalResult_temp as $key=>$val){
                foreach($val as $key1=>$val1){
                    foreach($market_master as $mkt_key=>$key_val){
                        foreach($val1 as $a=>$b){
                            if($mkt_key==$b['market_id']){
                                $finalResult1[$key][$key1][] = $b;
                                break;
                            }
                        }
                    }
                }
            }
            $finalResult = array();
            $finalResult = $finalResult1;
            if(isset($finalResult['APP_INDEX']['region'][0]['data'])){
                $app_index_region_arr = array();
                foreach($finalResult['APP_INDEX']['region'][0]['data'] as $region_val){
                    $mkt_arr =array();
                    foreach($market_master as $key=>$name){
                        $mkt_arr[] =   array( 
                                            
                                            "market_id" => $key,
                                        // "id" => $key,
                                            "name"=> $name                                  
                                        );
                    }
                    $region_val += array("market"=>$mkt_arr);
                    $app_index_region_arr[] = $region_val;
                }
                $finalResult['APP_INDEX']['region']=$app_index_region_arr;
            }
            
            //adding the non-ferrous commodity in scrap and recycling list
//             if($finalResult['APP_HOME']['commodity'][1]['market_id']=='non-ferrous' && $finalResult['APP_HOME']['commodity'][3]['market_id']=='scrap-recycling'){            
//                 array_push($finalResult['APP_HOME']['commodity'][3]['data'], $finalResult['APP_HOME']['commodity'][1]['data'][0]);
//             }
            
            
            //adding new key in app_home for region 
            if(isset($finalResult['APP_HOME']['region'])){
                $finalResult['APP_HOME']['region_market_wise'] = $finalResult['APP_HOME']['region'];
                $finalResult['APP_HOME']['region'] = $finalResult['APP_HOME']['region'][0]['data'];
            }
            
            //adding market inside region for app_home
            if(isset($finalResult['APP_HOME']['region'])){
                $app_home_region_arr = array();
                foreach($finalResult['APP_HOME']['region'] as $region_val){
                    $mkt_arr =array();
                    foreach($market_master as $key=>$name){
                        $mkt_arr[] =   array( 
                                            
                                            "market_id" => $key,
                                        // "id" => $key,
                                            "name"=> $name                                 
                                        );
                    }
                    $region_val += array("market"=>$mkt_arr);
                    $app_home_region_arr[] = $region_val;
                }
                $finalResult['APP_HOME']['region']=$app_home_region_arr;
            }
            $non_ferrous_sub = array();
            $non_ferrous_sub_1 = array();
            if(isset($finalResult['APP_PRICE_LANDING_LISTING_CMBBOX']['commodity'])){
                foreach($finalResult['APP_PRICE_LANDING_LISTING_CMBBOX']['commodity'] as $ind_key=>$dd){
                    if($dd['market_id']=='non-ferrous' && $dd['data'][0]['id']==972)
                    {
                        foreach( $dd['data'][0]['sub_commodity'] as $sub_key => $sub_val){
                            //$sub_val['bgImage']= $dd['data'][0]['bgImage'];
                            $sub_val['sub_commodity'] = array();
                            $non_ferrous_sub[$sub_key]= $sub_val;
                            unset($sub_val['sub_commodity']);
                            $sub_val['sub_commodity'][] = $sub_val;
                            $sub_val['isSelectable']= $dd['data'][0]['isSelectable'];
                            $non_ferrous_sub_1[$sub_key]= $sub_val;
                        }
                        //$finalResult['APP_PRICE_LANDING_LISTING_CMBBOX']['commodity'][$ind_key] = $non_ferrous_sub;
                    }
                    
                }
            }
            
            //adding market inside commodity for app_home
            if(isset($finalResult['APP_HOME']['commodity'])){
                $app_home_commodity_arr = array();
                $addedIDs=array();
                foreach($finalResult['APP_HOME']['commodity'] as $ind_key => $commodity_val){
                    foreach($commodity_val['data'] as $key=>$val){
                        if(!in_array($val['id'],$addedIDs)){
                            $app_home_commodity_arr[] = $val;                     
                            $addedIDs[] =  $val['id'];
                        }
                    }
                    //shifting non-ferrous sub_commodity to commodity level in app home
                    if($commodity_val['market_id']=='non-ferrous'){
                        $finalResult['APP_HOME']['commodity'][$ind_key]=
                          array(
                                            
                                "market_id" => $commodity_val['market_id'],
                            // "id" => $key,
                                "name"=> $commodity_val['name'],
                                "data"=> $non_ferrous_sub
                            );
                        
                    }
                    
                }
                $finalResult['APP_HOME_PREFERENCES']['commodity']=$app_home_commodity_arr;
            }
            if($_REQUEST['debug']){
                print_r($app_home_commodity_arr);die;
            }
            if(isset($finalResult['APP_HOME']['region'])){               
                $finalResult['APP_HOME_PREFERENCES']['region']=$finalResult['APP_HOME']['region'];
            }
            
            //copy APP_PRICE_LANDING_LISTING_CMBBOX and creating new APP_PRICE_LANDING_LISTING_CMBBOX_NEW            
            if(isset($finalResult['APP_PRICE_LANDING_LISTING_CMBBOX'])){
                $finalResult['APP_PRICE_LANDING_LISTING_CMBBOX_NEW']=$finalResult['APP_PRICE_LANDING_LISTING_CMBBOX'];
                if(isset($finalResult['APP_PRICE_LANDING_LISTING_CMBBOX']['region'][0]['data'])){
                    $app_price_region_arr = array();
                    foreach($finalResult['APP_PRICE_LANDING_LISTING_CMBBOX']['region'][0]['data'] as $region_val){
                        if($region_val['name']!='All'){
                            $mkt_arr =array();
                            foreach($market_master as $key=>$name){
                                $comm  = array();
                                foreach($finalResult['APP_PRICE_LANDING_LISTING_CMBBOX']['commodity'] as $c_data){
                                    if ($c_data['market_id'] === $key) {
                                        $comm =  $c_data['data'];
                                        break;
                                    }
                                }
                                $mkt_arr[] =   array( 
                                                    
                                                    "market_id" => $key,
                                                // "id" => $key,
                                                    "name"=> $name,
                                                    "data"=>$comm
                                                );
                            }
                            $region_val += array("commodity"=>$mkt_arr);
                            $app_price_region_arr[] = $region_val;
                            
                            $finalResult['APP_PRICE_LANDING_LISTING_CMBBOX_NEW']['region']=$app_price_region_arr;
                        }
                    }                    
                }
                
                 //shifting non-ferrous sub_commodity to commodity level in app APP_PRICE_LANDING_LISTING_CMBBOX_NEW
                if(isset($finalResult['APP_PRICE_LANDING_LISTING_CMBBOX_NEW']['commodity'])){
                    foreach($finalResult['APP_PRICE_LANDING_LISTING_CMBBOX_NEW']['commodity'] as $ind_key => $commodity_val){                           
                        //shifting non-ferrous sub_commodity to commodity level in app home
                        if($commodity_val['market_id']=='non-ferrous'){
                            $finalResult['APP_PRICE_LANDING_LISTING_CMBBOX_NEW']['commodity'][$ind_key]=
                            array(                                                
                                    "market_id" => $commodity_val['market_id'],                              
                                    "name"=> $commodity_val['name'],
                                    "data"=> $non_ferrous_sub_1
                                );
                             $finalResult['APP_PRICE_LANDING_LISTING_CMBBOX']['commodity'][$ind_key]=
                            array(                                                
                                    "market_id" => $commodity_val['market_id'],                              
                                    "name"=> $commodity_val['name'],
                                    "data"=> $non_ferrous_sub_1
                                );
                        }
                    }
                }
            }
            
            if(isset($finalResult['APP_REPORT_LANDING_LISTING_CMBBOX'])){                                    
                foreach($finalResult['APP_REPORT_LANDING_LISTING_CMBBOX']['commodity'] as $key_r=>$val_r) {                    
                    if(!empty($val_r['data'])){                    
                        // New array to add as the first child for all in report array
                        $newChildArray = array(
                                        "id" => 709,
                                        "name" => "All",
                                        "isSelectable" => "y",
                                        "bgImage" => "",
                                        "web_url" => "",
                                        "sub_commodity" => array()
                                    );
                        
                        array_unshift($finalResult['APP_REPORT_LANDING_LISTING_CMBBOX']['commodity'][$key_r]['data'], $newChildArray);                        
                    }                   
                }  
            }
        }
		//resourceType check condition ends here
		if($otherCondition==''){
			$dbresult = DB::table('tbl_companytype')
					->select('id','short_comptype as name' )				
					->get();
			foreach($dbresult as $cType){
				$finalResult['companyType'][$cType["id"]] = $cType["name"];
			}
		}
		
		if($otherCondition==''){
			
			$dbresult = DB::table('tbl_country')
					->select('currency_code','currency_symbol', 'section', 'country' )
					->where('section','<>',"")
					->groupBy("currency_code")
					->orderByRaw(
						 "CASE 
							WHEN currency_code='USD' THEN 1
							WHEN currency_code='INR' THEN 2
							WHEN currency_code='JPY' THEN 3
							WHEN currency_code='CNY' THEN 4
							WHEN currency_code='EUR' THEN 5
							WHEN currency_code='GBP' THEN 6
							WHEN currency_code='RUB' THEN 7
							WHEN currency_code='IDR' THEN 8						 
							ELSE 99 
						 END")
					->get();
					
			foreach($dbresult as $cType){
				if(strpos($cType["section"],'package') !== false){
					$finalResult['currencyConvertor']['packages'][] = array(
						"name" => $cType["country"],
						"code" => $cType["currency_code"],
						"symbol" => $cType["currency_symbol"],
					);
				}
				
				if(strpos($cType["section"],'price') !== false){
					$finalResult['currencyConvertor']['prices'][] = array(
						"name" => $cType["country"],
						"code" => $cType["currency_code"],
						"symbol" => $cType["currency_symbol"],
					);
				}
			}
			
			/*$finalResult['currencyConvertor'] = array(
				'packages'=>array(
					array(
						"name" => "INDIA",
						"code" => 'INR',
						"symbol" => '20B9'
					),
					array(
						"name" => "Doller",
						"code" => 'USD',
						"symbol" => '0024'
					),
					array(
						"name" => "Japanese Yen",
						"code" => 'YEN',
						"symbol" => '00A5'
					),
					array(
						"name" => "Russian ruble",
						"code" => 'RUB',
						"symbol" => '20BD'
					),
					array(
						"name" => "Renminbi, Chinese Yuan",
						"code" => 'RMB',
						"symbol" => '00A5'
					),
					array(
						"name" => "Indonesian Rupiah",
						"code" => 'IDR',
						"symbol" => '0052,0070'
					)
				),
				'prices'=>array(
					array(
						"name" => "INDIA",
						"code" => 'INR',
						"symbol" => '20B9'
					),
					array(
						"name" => "Doller",
						"code" => 'USD',
						"symbol" => '0024'
					),
					array(
						"name" => "EURO",
						"code" => 'EUR',
						"symbol" => '20AC'
					),
					array(
						"name" => "Japanese Yen",
						"code" => 'YEN',
						"symbol" => '00A5'
					),
					array(
						"name" => "Russian ruble",
						"code" => 'RUB',
						"symbol" => '20BD'
					),
					array(
						"name" => "Renminbi, Chinese Yuan",
						"code" => 'RMB',
						"symbol" => '00A5'
					),
					array(
						"name" => "Indonesian Rupiah",
						"code" => 'IDR',
						"symbol" => '0052,0070'
					)
				)				
			);*/
			
			if( ($deviceType == '' || $deviceType == 'android' || strtolower($app_type) == 'cm') && $deviceType != 'ios' ){
				$finalResult['tradeType']=array(
						""=>"All",
						"export"=>"Export",
						"import"=>"Import",
						"domestic"=>"Regional"
					);
				$finalResult['timeLine']=array(
						""=>"All",
						"2d"=>"Two Days Ago",
						"1w"=>"One week Ago",
						"2w"=>"Two week Ago"
					);
				
			} else {
				$finalResult['tradeType']=array(
						array("key" => ''	, "value"				=>			"All"),
						array("key" => 'export'	, "value"				=>			"Export"),
						array("key" => 'import'	, "value"				=>			"Import"),
						array("key" => 'domestic'	, "value"				=>			"Regional")
					);
				$finalResult['timeLine']=array(
						array("key" => ''	, "value"				=>			"All"),
						array("key" => '2d'	, "value"				=>			"Two Days Ago"),
						array("key" => '1w'	, "value"				=>			"One week Ago"),
						array("key" => '2w'	, "value"				=>			"Two week Ago")
					);
			}
			$finalResult['dataType']=array(
					""=>"All",
					"prices"=>"Prices",
					"insight"=>"Insight",
					"tenders"=>"Tenders",
					"reports"=>"Reports",
					"statistics"=>"Statistics",
					"events"=>"Events"
				);
			$finalResult['reportType']=array(
					""=>"All",
					"special"=>"Special",
					"regular"=>"Regular",
					"knowledge"=>"Knowledge"
				);
			$finalResult['eventType']=array(
					"upcoming"=>"Upcoming",
					"archieved"=>"Archieved"
				);
			$finalResult['packageTenure']=array(
					"3m"=>"3 Months",
					"6m"=>"6 Months",
					"9m"=>"9 Months",
					"1y"=>"1 Year"
				);
			//YKV 14 August 2021	
			if(strtolower($app_type) == 'cm'){	
				$finalResult['staticPagesLink']=array(
					"termsNCondition"=>"https://www.coalmint.com/termConditions?mobile=1",
					"privacyPolicy"=>"https://www.coalmint.com/privacyPolicy?mobile=1",
					"aboutUs"=>"https://www.coalmint.com/aboutUs?mobile=1",
					"methodology"=>"https://www.coalmint.com/methodology?mobile=1", 
					"logistics"=>"https://www.coalmint.com/logistics?mobile=1",
					"videoTutorialUrl"=>"https://www.youtube.com/watch?reload=9&v=X5W_3LELrAs",
					"logisticsSectionStatus"=>"active"
					/* "termsNCondition"=>"https://www.steelmint.com/app_static_pages/app_t_n_c.php",
					"privacyPolicy"=>"https://www.steelmint.com/app_static_pages/app_privacy_policy.php",
					"aboutUs"=>"https://www.steelmint.com/app_static_pages/app_about_us.html",
					"methodology"=>"http://www.steelmint.com/nw/methodology?mobile=1", 
					"logistics"=>"http://www.steelmint.com/nw/logistics?mobile=1",
					"videoTutorialUrl"=>"https://www.youtube.com/watch?reload=9&v=X5W_3LELrAs",
					"logisticsSectionStatus"=>"active" */ //used in ios to show upgrade button below webview / dont show any button below webview if logsiticssection is accessible to him
					
				);
			}else{	
				$finalResult['staticPagesLink']=array(
					"termsNCondition"=>"https://www.bigmint.co/terms-and-conditions?mobile=1",
					"privacyPolicy"=>"https://www.bigmint.co/privacy-policy?mobile=1",
					"aboutUs"=>"https://www.bigmint.co/aboutUs?mobile=1",
					"methodology"=>"https://www.bigmint.co/methodology?mobile=1", 
					"logistics"=>"https://www.bigmint.co/logistics?mobile=1",
					"videoTutorialUrl"=>"https://www.youtube.com/watch?reload=9&v=X5W_3LELrAs",
					"logisticsSectionStatus"=>"active"
					/* "termsNCondition"=>"https://www.steelmint.com/app_static_pages/app_t_n_c.php",
					"privacyPolicy"=>"https://www.steelmint.com/app_static_pages/app_privacy_policy.php",
					"aboutUs"=>"https://www.steelmint.com/app_static_pages/app_about_us.html",
					"methodology"=>"http://www.steelmint.com/nw/methodology?mobile=1", 
					"logistics"=>"http://www.steelmint.com/nw/logistics?mobile=1",
					"videoTutorialUrl"=>"https://www.youtube.com/watch?reload=9&v=X5W_3LELrAs",
					"logisticsSectionStatus"=>"active" */ //used in ios to show upgrade button below webview / dont show any button below webview if logsiticssection is accessible to him
					
				);
			}				
			if(strtolower($app_type) == 'cm'){
				$finalResult['exploreBookmarks']=array(
					array(
					    "section"=>"Insights",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/coalmint/Insight.jpg"
					),
					array(
					    "section"=>"Tenders",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/coalmint/Tender.jpg"
					),
					array(
					    "section"=>"Reports",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/coalmint/Report.jpg"
					),
					array(
					    "section"=>"Events",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/coalmint/Ironore.jpg"
					),
					// YKV 07 Feb 2023 Added infographic bookmark for CM app
					array(
					    "section"=>"Infographics", 
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/coalmint/Infographic.jpg"
					)
					/*, YKV 14 August 2021 commented to remove Steel360 bookmark from CM app
					array(
					    "section"=>"360 Magazine",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/coalmint/Steel360.jpg"
					)*/
				);
			}else{
				
				$finalResult['exploreBookmarks']=array(
					array(
					    "section"=>"Insights",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/Insight.jpg"
					),
					array(
					    "section"=>"Tenders",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/Tender.jpg"
					),
					array(
					    "section"=>"Reports",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/Report.jpg"
					),
					array(
					    "section"=>"Events",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/Ironore.jpg"
					)
					,
					array(
					    "section"=>"360 Magazine",
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/Steel360.jpg"
					),
					array(
					    "section"=>"Infographics", 
					    "bgImage"=>BASEURL ."api/public/assets/app/exploreBookmarks/Infographic.jpg"
					)
				);
				
			}
				if( $app_type == 'SM' )
				    $comm = "iron ore";
				else    
				    $comm = "coal";
				
				$finalResult['preLoginStatsInputs']=array(
					"resourceType"	=> "web",
					"region"	=> "india",
					"dataType"	=> "production",//"capacity",
					"commodity"	=> $comm,//"Ferro Silicon",
					"columnNameOfRegion"	=> "country",
					"columnNameOfCommodity"	=> "commodity_new"//"subCommodity",
				);
				
				$finalResult['ExplorePricesOption']=array(
				    
					array("key" => 'Spot_Prices',       "value"				=>			"Spot Prices","url"=>'prices'),
					array("key" => 'Future_Prices',     "value"				=>			"Futures","url"=>'prices'),
					//array("key" => 'Indices_Prices',    "value"				=>			"Indices","url"=>'prices'),
					array("key" => 'Currency',          "value"				=>			"Forex","url"=>'prices')
					
				);
				
				$finalResult['ExploreMarketOption']=array(
                    array("key" => 'ferrous', "value"=>"Ferrous Metals"),
                    array("key" =>'non-ferrous',  "value"=> 'Non Ferrous'),
                    array("key" => 'coal' ,  "value"=> 'Coal & Energy'),
                    array("key" =>'scrap-recycling' ,  "value"=> 'Scrap Recycling'),
					array("key" =>'agriculture' ,  "value"=> 'Agriculture'),														  
                    array("key" =>'future_prices' ,  "value"=> 'Futures'),
//                     array("key" =>'future_prices=ferrous' ,  "value"=> 'Futures Ferrous Metals'),
//                     array("key" =>'future_prices=non-ferrous' ,  "value"=> 'Futures Non Ferrous'),
//                     array("key" =>'future_prices=coal' ,  "value"=> 'Futures Coal & Energy'),
//                     array("key" =>'future_prices=scrap-recycling' ,  "value"=> 'Futures Scrap Recycling'),
                    array("key" =>'Currency' ,  "value"=> 'Forex')
				);
				
				$finalResult['sliderTextMap']=array(
					"region"=>"What's happening in different regions?",
					"commodity"=>"Choose your market",
					"homeslider3"=>"homeslider3 Text",
					"homeslider4"=>"homeslider4 Text",
				);
				
               $finalResult['logoPath']=array(
                //"logo_dark"=>"https://www.steelmint.com/images/logo.png",
                "logo_dark"=>"https://www.steelmint.com/images/new_logo_trans.png",
                "logo_light"=>"https://www.steelmint.com/images/new_logo_trans.png",
                //"logo_light"=>"https://d2trl8b0ch55hj.cloudfront.net/public/bm/new-images/bm_white_logo.png",
               );
               $finalResult['marketList']=array(
                    array("key" => 'ferrous', "value"=>"Ferrous Metals"),
                    array("key" =>'non-ferrous',  "value"=> 'Non Ferrous'),
                    array("key" => 'coal' ,  "value"=> 'Coal & Energy'),
                    array("key" =>'scrap-recycling' ,  "value"=> 'Scrap Recycling'),
					array("key" =>'agriculture' ,  "value"=> 'Agriculture')
				);
               
		}
		return $finalResult;
	}
}
