<?php
/*

Local:	H:\htdocs\mobile\etisalat\mypal.lk\ChatAPIServer\includes
Remote:	/var/www/mypal.lk/api.mypal.lk/html/includes

Consumer Key: NsMIRj34_lKTX3r5tkmSXZtvj88a
Consumer Secret: QGpIv2WHPgC2QX1KGYA30Zw6ppYa
Base64(NsMIRj34_lKTX3r5tkmSXZtvj88a:QGpIv2WHPgC2QX1KGYA30Zw6ppYa) = TnNNSVJqMzRfbEtUWDNyNXRrbVNYWnR2ajg4YTpRR3BJdjJXSFBnQzJRWDFLR1lBMzBadzZwcFlh

serviceID = 2833bee4-97b8-4f8f-96f9-c6202863991e
*/

date_default_timezone_set('Asia/Colombo');
$time = $requesttime = time();
$session_expiry_interval = time() - 30*24*60*60;//7-days, 24 hrs/day, 60 mins/hrs, 60 secs/min

$mypal_users="mingle_users";
$permissions_table="mingle_shared_permissions";
$mingle_fcm_token_table = "mingle_fcm_token";
$mingle_report_log_table = "mingle_report_log";
$base64_encoded_key_secret="TnNNSVJqMzRfbEtUWDNyNXRrbVNYWnR2ajg4YTpRR3BJdjJXSFBnQzJRWDFLR1lBMzBadzZwcFlh";
$service_name = "Mingle";
$max_previous_chat_user_buffer = 0;
$profile_image_path = "/var/www/mingle.eft.xyz/html/profiles/";
$profile_image_link_path = "https://mingle.eft.xyz/profiles/";

// $twilio_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTSzgxMzY0NjE2OTc4MGZhYjI0MmUyOGEwYjNjYjczM2EwLTE3NjA0MTUxNzgiLCJpc3MiOiJTSzgxMzY0NjE2OTc4MGZhYjI0MmUyOGEwYjNjYjczM2EwIiwic3ViIjoiQUM5Y2FjNjNhMGU3YzhkODM4OTFmOWE5MGM4ZmRjMjFhZCIsImV4cCI6MTc2MDQxODc3OCwiZ3JhbnRzIjp7ImlkZW50aXR5IjoidXNlci05M2Q2MWQ3OCIsInZpZGVvIjp7InJvb20iOiJtaW5nbGUtZGVmYXVsdCJ9fX0._R8fkmgNybDiX4JZgLAQ9sY3H4WgEGko4GzKSBlL470';
$twilio_tokens = [
	'68' => 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTSzgxMzY0NjE2OTc4MGZhYjI0MmUyOGEwYjNjYjczM2EwLTE3NjA0NjY3NDQiLCJpc3MiOiJTSzgxMzY0NjE2OTc4MGZhYjI0MmUyOGEwYjNjYjczM2EwIiwic3ViIjoiQUM5Y2FjNjNhMGU3YzhkODM4OTFmOWE5MGM4ZmRjMjFhZCIsImV4cCI6MTc2MDQ3MDM0NCwiZ3JhbnRzIjp7ImlkZW50aXR5IjoidXNlci1hMThiYzg2NiIsInZpZGVvIjp7InJvb20iOiJtaW5nbGUtZGVmYXVsdCJ9fX0.R_mkwVbcCce4YgdCfCNo-3fl15agKZt_m0Q31e0DR_c',
	'69' => 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTSzgxMzY0NjE2OTc4MGZhYjI0MmUyOGEwYjNjYjczM2EwLTE3NjA0NjY3NDYiLCJpc3MiOiJTSzgxMzY0NjE2OTc4MGZhYjI0MmUyOGEwYjNjYjczM2EwIiwic3ViIjoiQUM5Y2FjNjNhMGU3YzhkODM4OTFmOWE5MGM4ZmRjMjFhZCIsImV4cCI6MTc2MDQ3MDM0NiwiZ3JhbnRzIjp7ImlkZW50aXR5IjoidXNlci01OGJhZWM0NiIsInZpZGVvIjp7InJvb20iOiJtaW5nbGUtZGVmYXVsdCJ9fX0.gCZkblO4fTOoZtHvXpZa4WNFDl5B0dYgot_HOCYrEu4'
];

$twilio_room = 'mingle-default';
//Mingle
$serviceJsonPath = '/var/www/mingle.eft.xyz/fcm/mingle-ed148-firebase-adminsdk-fbsvc-cee44d35f2.json';
// $server_key = 'ya29.c.c0ASRK0GbuVl8Esd3K_UifFk1CheN1UpiAUAIQGTPwLxTp5Un-ygCWGL78RhyW3Lb1Uq0FbrbNAp-MrCYEmLpoTaE8vZr0wjdwD3rNyhEeo4q8E1g42eHm_fGiE80u_yhq47Qd2id4LkQw_1Uf9BxOrVaMYF7c9yAkqplOl9GbYdlQhOjyAKZ37gVn8hxfiJOkk8TQ4LxI6YgJsWW6yELM7FZWI7ZqYVoDh3t8t4KDuJLDgS_LKbvSemoUkntyUIBCuMY4xGdKeA1o2QLMSnrL-TbynVUj_7EO2RVCj5Ee6J1cAqR6Wmo_S947JouLpHlcL4u3D1xNPFmxRC0nouumO-ga11n02MzUI-TRt68-HkwwQdfwjN5hAQ8E384KXg5Qf2uio44YZnvS942vu2olla3Fq4szWwQblV4aqMWJUi7qWwIpdF_Z8MhlJmdegj9oXk6a0q55iUVpU-26wvwdt2-uj2xytMV1br0lydBayblf7M9mylBB5Vzvy70q8Wk6yuZ88lz4WqXg7sSvZ5eIwcBvzVooFjf6vgigU8o6Ihy6wUBl5kXzW1_d1tMyVI25VYjfp-92z5cSuFWVvFr8o4_-t-SkQqws9i84lzS8sxa92VuYi0zM5ni9JJ_MSxg4rltcX4cs_QeQyjSs07Wt-Wx67uSZzVYsY-Y2rzwqjx4q4yJb_QIW_ehJyy52lz9OXBlrQlzap26ucynkUvaz-VuYn14outlyMt98fek4xZSnVRW4yifiiW5SY80UF-eIQIywrp5dVoOlRt7kRdcb0JeBQWkF0fYhOi_25s-yssrbFZgMbWkoZB7o1wSXt78MMkcUB4pwiam8dVqVJzwunjk21y-X30zfbF770Buvr4Q8FitQvww-YMZIvydjdIQuxr58aXOI3puwuqBOkxzoem40Y10rsVUhz8qdOYUWXOJJ9stba8m0rYWixr3cwO-onFFVjYum1jX6nkbwBuV1r2ZxnJU1dBjYOc7psOoIYXZjgYegc-mJsqk';
$chat_history_limit = 5;
//{"nickname":"Guest","age":"hjuii","gender":"","location":"","lat":"","lon":""}
$profile_string_parameters = ['nickname','age','gender','location'];

$webrtc_manager = [
	'callInvite' => true,
	'callAccept' => true,
	'callDecline' => true,
	'callOffer' => true,
	'callAnswer' => true,
	// 'callIce' => false,
	'callCancel' => true,
	// 'callEnd' => true,
	// 'callTimeout' => true
];

/* 
	true -Testing mode
	false - Live mode
*/

$trialMode = true; //true - will bypass subscription checks. Considers subscribed for all numbers 
// $trialMode = false; //false - live subscription check in place 					

$testingMode = false; 
//$testingMode = true; // true - will bypass subscription checks, will not send actual sms

// $subscribeOnSignup = true;  // true - Call PIN subscription if not subscribed and SMS subscription OTP to phone
$subscribeOnSignup = false; // false - Not call PIN subscription and SMS login p/w to mobile

$sendMessageEndPoint = "https://api.mypal.lk/messageSender.php";

$inputlogfile = "logs/input.log";
$outputlogfile = "logs/output.log";
$errorlog = "logs/error.log";
$sqllog	= "logs/sql.log";
$ideabizlog = "logs/ideabiz.log";
$debuglog = "logs/debug.log";
$pushmessagelog = "logs/pushmessagelog.log";
$twilio_token_url = "https://minglertc.eft.xyz/getToken.php";

$messageSenderSecret = "Snj&%%kLJ";

$session_key_based_operators = array(
									 	"unsubscribe" => array("userID"),
										"getProfile" => array("userID"),
										"setProfile" => array("userID"),
										"friendFind" => array("userID"),
										"getWho" => array("userID"),
										"chatMessage" => array("userID"),
										"stopChat" => array("userID"),
										"addFriend" => array("userID"),
										"getFriends" => array("userID"),
										"removeFriend" => array("userID"),
										"submitSubscriptionOTP" => array("userID"),
										"changePassword" => array("userID"),
										"connectFriend" => array("userID"),
										"getPushMessages" => array("userID"),
										"acceptFriend" => array("userID"),
										"rejectFriend" => array("userID"),
										"withdrawRequest" => array("userID"),
										"clearHistory" => array("userID"),
										"reverseGeoCode" => array("userID"),
										"reportUser" => array("userID"),
										"setProfilePhoto" => array("userID"),
										"deleteProfilePhoto" => array("userID"),
										"callInvite" => array("userID"),
										"callAccept" => array("userID"),
										"callDecline" => array("userID"),
										"callOffer" => array("userID"),
										"callAnswer" => array("userID"),
										"callIce" => array("userID"),
										"callEnd" => array("userID"),
										"callTimeout" => array("userID"),
										"callFetch" => array("userID"),
										"disableCalling" => array("userID"),
										"callCancel" => array("userID"),
									 );
$subscription_check_bypass_operators = array("submitSubscriptionOTP","changePassword","stopChat","unsubscribe");
$sessionkey_optional_operators = array("submitSubscriptionOTP");

$subscriptionStatusValues = array(
	"SUBSCRIBED" => array("SUBSCRIBED"),
	"UNSUBSCRIBED" => array("UNSUBSCRIBED","NOT_SUBSCRIBED","PENDING_AUTH")
);

	//$requestmessage = file_get_contents('php://input');
	//$value = json_decode($requestmessage, true);

$number_validations = array(
								"9" => array(
											 	"prefixes" => array("77","76","74","70","71","72","73","75","78","79"),//777332307
												"length" => 2,
												"trim_lengh" => 0
											),
								"10" => array(
											 	"prefixes" => array("077","076","074","070","071","072","073","075","078","079"),//0777332307
												"length" => 3,
												"trim_lengh" => 1
											)
							);

$friend_types = array(
					  	"Approved" => array(
												"fieldName" => "friends_approved",
												"enabled" => true
											),
						"RequestSent" => array(
												"fieldName" => "friends_requests_sent",
												"enabled" => true
											),
						"RequestReceived" => array(
												"fieldName" => "friends_requests_received",
												"enabled" => true
											)					
					  );

$profile_data_variables = array(
									"nickname" => true,
									"age" => true,
									"gender" => true,
									"location" => true,
									"lat" => false,
									"lon" => false,
									"image" => false
								);

$friend_status_handling = array(
									"free" => array(
													 false => array(//not connected to each other
																	"chatConnect" => true,
																	"displayStatus" => "Free",
																	"notifyFriend" => true,
																	"respCode" => "0027"//"You are connected with a user"
																  )
													),
									"searching" => array(
														 false => array(//not connected to each other
																		"chatConnect" => true,
																		"displayStatus" => "Free",
																		"notifyFriend" => true,
																		"respCode" => "0027"//"You are connected with a user"
																	  )
													),
									"connected" => array(
														 true => array(//connected to each other
																		"chatConnect" => false,
																		"displayStatus" => "Connected",
																		"notifyFriend" => false,
																		"respCode" => "0041"//"You are already connected with the friend"
																	   ),
														 false => array(//not connected to each other
																		"chatConnect" => false,
																		"displayStatus" => "Busy",
																		"notifyFriend" => true,
																		"respCode" => "0038"//"Chat request sent to user"
																	   ),
														 ),
									"unavailable" => array(
														   false => array(////not connected to each other
																		"chatConnect" => false,
																		"displayStatus" => "Unavailable",
																		"notifyFriend" => false,
																		"respCode" => "0040"//"User is currently unavailable"
																		)
														   )
								);

$ResponseCodeDesc = array(
						  "0000" => "Subscription to Mypal Created Successfully",
						  "1000" => "Operation processed successfully",
						  "0001" => "Subscription OTP Sent to Mobile <mobile>. Rs.5+tax per day applicable",
						  //"0002" => "Request sent to Mobile <mobile>. Please confirm by replying 'yes' to the request. And then click 'Ok' to proceed",
						  "0003" => "Insufficient Credit in Mobile <mobile> to complete the transaction",
						  "0004" => "Invalid Number <mobile>. Need to be 'Dialog' or 'Mobitel' numbers in 7xx xxxxxx format",
						  "0005" => "Invalid OTP. Re-enter and Submit or click [X] to close window",
						  "0006" => "Transaction Timed out. Click 'Retry' to try again or 'Cancel' to close window",
						  "0007" => "Charging Unsuccessful or Pending user confirmation. Click 'Retry' to try again or 'Cancel' to close window",
						  "0008" => "Invalid Operation",
						  "0009" => "Authorization failure",
						  "0010" => "One or more Mandatory Parameters are missing",
						  "0011" => "Invalid Transaction Reference",
						  "0012" => "Cannot Process due to System Error. Please Try again soon",
						  "0013" => "Mobile <mobile> already subscribed to \"<service>\"",
						  "0014" => "Mobile <mobile> unsubscribed successfully from \"<service>\"",
						  "0015" => "Mobile <mobile> not subscribed to \"<service>\"",
						  "0016" => "Mobile <mobile> not allowed to subscribe to \"<service>\"",
						  //"0017" => "PackageID <package_id> not defined",
						  //"0018" => "Request sent to Mobile <mobile>. Please confirm by replying '1' to the request. And then click 'Ok' to proceed",
						  //"0019" => "Pending user confirmation. Click 'Retry' to try again or 'Cancel' to close window",
						  "0020" => "Mobile <mobile> not subscribed to any package",
						  "0021" => "Password Sent to Mobile <mobile>",
						  "0022" => "Error sending password to <mobile>. Please try again later",
						  "0023" => "User logged in successfully",
						  "0024" => "Incorrect Password",
						  "0025" => "Session expired, Please relogin",
						  "0026" => "Mobile <mobile> already registered. Please login with <mobile> and password",
						  "0027" => "You are connected with <party2details>",
						  "0028" => "You are not connected with any user",
						  "0029" => "You have not set a Profile",
						  "0030" => "Profile data sent successfully",
						  "0031" => "Mobile <mobile> not signup up. Please signup 1st to login",
						  "0032" => "Incorrect Old password. Please retry",
						  "0033" => "Password updated successfully",
						  "0034" => "Friends list sent successfully",
						  "0035" => "Friend request sent to user",
						  "0036" => "Friend removed successfully",
						  "0037" => "Wait till we find a friend to chat",
						  "0038" => "Chat request sent to <party2details>",
						  "0039" => "User is not in your friend list",
						  "0040" => "User is currently unavailable",
						  "0041" => "You are already connected with the friend",
						  "0042" => "Chat message sent successfully",
						  "0043" => "You have stopped chatting",
						  "0044" => "You have no friend requests from the user",
						  "0045" => "User added to your friends list",
						  "0046" => "Invalid Profile photo format. Please upload in jpg, jpeg, gif, png or bmp formats",
						  "0047" => "Friend request rejected",
						  "0048" => "Your Friend has left",
						  "0049" => "User is already in your friends list",
						  "0050" => "TnC returned successfully",
						  "0051" => "Privacy policy returned successfully",
						  "0052" => "Friend request withdrawn",
						  "0053" => "You have no friend requests sent to this user",
						  "0054" => "Chat history cleared successfully",
						  "0055" => "Friend request already sent to user. Wait till user accepts or rejects it.",
						  "0056" => "You need to set your profile first before starting to chat.",
						  "0057" => "reverse geo coded the location successfully.",
						  "0058" => "User reported successfully.",
						  "0059" => "Profile photo uploaded successfully.",
						  "0060" => "Profile photo upload failure.",
						  "0061" => "Profile photo deleted successfully",
						  "0062" => "Voice calling the other party",
						  "0063" => "Video calling the other party",
						//   "0064" => "callInvite successful",
						  "0065" => "callAccept successful",
						  "0066" => "callDecline successful",
						  "0067" => "callOffer successful",
						  "0068" => "callAnswer successful",
						  "0069" => "callFetch successful",
						  "0070" => "callIce successful",
						  "0071" => "callEnd successful",
						  "0072" => "callTimeout successful",
						  "0073" => "twilioToken returned successful",
						  "00740" => "voice/video calling enabled",
						  "00741" => "voice/video calling disabled",
						  "0075" => "other party has disabled calling",
						  "0076" => "about me updated successfully",
						  "0077" => "callCancel successful"
						  );

//Notification codes
$notificationCodeDesc = array(
								"0001" => "Your friend has left. Click \"Find\" to find a new friend!", //GetProfileToString(FormatProfile($userqueryarray["user_profile"]))." has left. Click \"Find\" to find a new friend!
																										//GetProfileToString(FormatProfile($userqueryarray["user_profile"]))." has left. Click \"Find\" to find a new friend!"
								"0002" => "You are connected with a Friend", //You are connected with ".GetProfileToString(FormatProfile($userqueryarray["user_profile"])).". Type a message to chat.
								"0003" => "User has sent a Friend request",	//GetProfileToString(FormatProfile($userqueryarray["user_profile"]))." have sent a Friend request
								"0004" => "User has accepted your Friend request", //GetProfileToString(FormatProfile($userqueryarray["user_profile"]))." has accepted your friend request!
								"0005" => "User has rejected your Friend request",//GetProfileToString(FormatProfile($userqueryarray["user_profile"]))." has rejected your friend request!
								"0006" => "User has removed you as a Friend", //GetProfileToString(FormatProfile($userqueryarray["user_profile"]))." has removed you as a friend
								"0007" => "Friend has sent a Chat Invite. Click \"Accept\" to chat", //GetProfileToString(FormatProfile($userqueryarray["user_profile"]))." has sent a Chat Invite. Click \"Accept\" to chat"
								"0008" => "User has sent a Chat message", //"type" => "chatMessage"
							);

$package_id_mapping = array(
								100 => array(
												"name" => "MyPal Daily Pack",
												"amount" => 5,//5
												"mode-1" => array(
																	"serviceID" => "2833bee4-97b8-4f8f-96f9-c6202863991e",	//ideabiz service ID - MyPal Daily Pack
																	"clientID"  => "n/a"
																  ),
												"mode-2" => array(
																	"productID" => "1181",	//inzpire Product ID - ECON By Kumara Wagasinghe
																	"clientID"  => "e1ce1bd2-2d48-4e17-87ef-44d30a8c49fa"
																 )
											 )											
							);

$pushNotificationTemplate=array(
									"title" => "Mingle",
									"icon" => "Icon",
									"body"=> "",
									"message"=> array(
														"addFriend" =>  array(
																				"url" =>  "RequestScreen",	/* 
																												When A-party clicks “Add friend” B-Party will get a push notification. 
																											*/																				
														),
														"acceptFriend" => array(
																				"url" =>  "ChatScreen",		/* 
																												When A-party sends a friend request to B-party and later when 
																												B-party accepts the request, A-party will get a notification.
																											*/																				
														), 
														"rejectFriend" => array(
																				"url" =>  "ChatScreen",		/* 
																												When A-party sends a friend request to B-party and later when 
																												B-party rejects the request, A-party will get a notification.
																											*/																				
														),
														"removeFriend" => array(
																				"url" => "ChatScreen",		/*
																												When A-party removes B-party as a friend, B-party will get a push notification.
																											*/																				
														),
														"friendFind" => array(
																				"a" => array(
																							"url" => "ChatDetailScreen", /* 
																															a)	When A-party searches a friend and if B-party is instantly connected, 
																																then B-party will get a push notification that he is connected with A-party.
																															b)	When A-party searches and no user is found and later when B-party searches 
																																a user and connects A-party then A-party will get a push notification.  
																														*/																							
																				),
																				"c" => array(
																							"url" => "ChatScreen",		/*
																															c)	When A-party searches a friend while already connected with C-party, 
																																then C-party will get a notification that A-party has left.
																														*/																							
																				) 
														),	
														"connectFriend" => array(
																				"a" => array(
																							"url" => "ChatDetailScreen", /*
																																a)	When A-party connects with B-party (who is in A’s friends list), 
																																	B-party will get a notification that A-party is connected.
																														*/																							
																				),
																				"b" => array(
																							"url" => "ChatScreen", /*
																													b)	When A-party connects with B-party (who is in A’s friends list), while connected with C-party, 
																														then C-party will get a notification that A-party has left.
																													c)	When A-party tries to connect with B-party while B-party already is connected with some other party, 
																														B-party will get a notification that A-party has sent a chat invite.
																												*/																							
																				)
														),			
														"chatMessage" => array(
																			   "url" => "ChatDetailScreen",	/*
																												   a)	When A-party is connected with B-party and when A-party sends a message 
																														to B-party (A -> B), B-party will get a notification.
																												   b)	When A-party is connected with B-party and when B-party sends a message 
																												   		to A-party (B -> A), A-party will get a notification.
																											*/
																			   "info" => "ChatMessage"
														),
														"stopChat" => array(
																			"url" => "ChatScreen",																			
														)
													)
								);




?>