#include <macro.h>
/*
	
	file: fn_newMsg.sqf
	Author: Silex
	
*/

private["_to","_type","_playerData","_msg"];
disableSerialization;

_type = [_this,0,-1] call BIS_fnc_param;
_playerData = [_this,1,-1] call BIS_fnc_param;
_msg = [_this,2,"",[""]] call BIS_fnc_param;

_display = findDisplay 88888;
_cPlayerList = _display displayCtrl 88881;
_cMessageEdit = _display displayCtrl 88884;

switch(_type) do
{
	case 0:
	{
		life_smartphoneTarget = call compile format["%1",_playerData];
		ctrlSetText[88886, format["Nachricht an: %1",name life_smartphoneTarget]];
		if((__GETC__(life_adminlevel) < 1)) then
		{
			ctrlShow[888897,false];
		};
	};
	//normal message
	case 1:
	{
		if(isNUll life_smartphoneTarget) exitWith {hintSilent format["Keine Person ausgwählt!"];};
		ctrlShow[88885, false];
		if(_msg == "") exitWith {hintSilent "Du musst eine Nachricht eingeben!";ctrlShow[88885, true];};
		[[life_smartphoneTarget,_msg,player,0],"TON_fnc_handleMessages",false] spawn life_fnc_MP;
		hintSilent format["You sent %1 a message: %2",name life_smartphoneTarget,_msg];	
		ctrlShow[88885, true];
		closeDialog 88883;
	};
	//copmessage
	case 2:
	{
		if(({side _x == west} count playableUnits) == 0) exitWith {hintSilent format["Die Polizei ist derzeit nicht zu erreichen. Bitte versuchen Sie es später nochmal."];};
		ctrlShow[888895,false];
		if(_msg == "") exitWith {hintSilent "Du musst eine Nachricht eingeben!";ctrlShow[888895,true];};
		[[ObjNull,_msg,player,1],"TON_fnc_handleMessages",false] spawn life_fnc_MP;
		_to = "The Police";
		hintSilent format["Du hast %1 folgende Nachricht gesendet: %2",_to,_msg];
		ctrlShow[888895,true];
		closeDialog 887890;
		
			_marker = createMarkerLocal [format[""%1_marker"",_req],visiblePosition _req];
			_marker setMarkerColorLocal ""ColorBlue"";
			_marker setMarkerTypeLocal ""Mil_dot"";
			_marker setMarkerTextLocal format[""%1 Requesting 911 Emergency"", _req getVariable[""realname"",name _req]];
			
			[format[""%1_marker"",_req]] spawn {
				_marName = [_this,0,"""",[""""]] call BIS_fnc_param;
				sleep 300;
				deleteMarkerLocal _marName;
			};
	};
	//msgadmin
	case 3:
	{
		ctrlShow[888896,false];
		if(_msg == "") exitWith {hintSilent "Du musst eine Nachricht eingeben!";ctrlShow[888896,true];};
		[[ObjNull,_msg,player,2],"TON_fnc_handleMessages",false] spawn life_fnc_MP;
		_to = "The Admins";
		hintSilent format["Du hast %1 folgende Nachricht gesendet: %2",_to,_msg];
		ctrlShow[888896,true];
		closeDialog 887890;
	};
	//emsrequest
	case 4:
	{
		if(({side _x == independent} count playableUnits) == 0) exitWith {hintSilent format["Zurzeit ist kein Feuerwehrmann im Dienst. Bitte probiere es später nochmal."];};
		ctrlShow[888899,false];
		if(_msg == "") exitWith {hintSilent "Du musst eine Nachricht eingeben!";ctrlShow[888899,true];};
		[[ObjNull,_msg,player,3],"TON_fnc_handleMessages",false] spawn life_fnc_MP;
		hintSilent format["Du hast der Feuerwehr einen Notruf geschickt!",_msg];
		ctrlShow[888899,true];
		closeDialog 887890;
	};
	//adminToPerson
	case 5:
	{
		if((call life_adminlevel) < 1) exitWith {hintSilent "Du bist kein Admin!";};
		if(isNULL life_smartphoneTarget) exitWith {hintSilent format["Keine Person ausgwählt!"];};
		if(_msg == "") exitWith {hintSilent "Du musst eine Nachricht eingeben!";};
		[[life_smartphoneTarget,_msg,player,4],"TON_fnc_handleMessages",false] spawn life_fnc_MP;
		hintSilent format["Admin Nachricht gesendet an: %1 - Nachricht: %2",name life_smartphoneTarget,_msg];
		closeDialog 88883;
	};
	//emergencyloading
	case 6:
	{
		if((__GETC__(life_adminlevel) < 1)) then
		{
			ctrlShow[888898,false];
			ctrlShow[888896,true];
		} else {
			ctrlShow[888898,true];
			ctrlShow[888896,false];
		};
		
		if((__GETC__(life_coplevel)) < 1) then
		{
			ctrlEnable[888905,false]; //CopToAll
			ctrlShow[888905,false];	  //CopToAll
			ctrlEnable[888895,true];  //CopRequest
		} else {
			ctrlEnable[888905,true];  //CopToAll
			ctrlEnable[888895,false]; //CopRequest
			ctrlShow[888895,false];	  //CopRequest
		};
	};
	//adminMsgAll
	case 7:
	{
		if((call life_adminlevel) < 1) exitWith {hintSilent "Du bist kein Admin!";};
		if(_msg == "") exitWith {hintSilent "Du musst eine Nachricht eingeben!";};
		[[ObjNull,_msg,player,5],"TON_fnc_handleMessages",false] spawn life_fnc_MP;
		hintSilent format["Adminnachricht an Alle: %1",_msg];
		closeDialog 887890;
	};
	//adacrequest
	case 8:
	{
		if(({side _x == independent} count playableUnits) == 0) exitWith {hintSilent format["Zurzeit ist kein ADAC im Dienst. Bitte probiere es später nochmal."];};
		ctrlShow[888900,false];
		if(_msg == "") exitWith {hintSilent "Du musst eine Nachricht eingeben!";ctrlShow[888900,true];};
		[[ObjNull,_msg,player,6],"TON_fnc_handleMessages",false] spawn life_fnc_MP;
		hintSilent format["Notruf wurde abgesetzt.",_msg];
		ctrlShow[888900,true];
		closeDialog 887890;
	};
		//PoliceMsgAll
	case 9:
	{
		if((call life_coplevel) < 1) exitWith {hint "Du bist kein Polizist!";};
		if(_msg == "") exitWith {hint "Eine Nachricht eingeben zum Senden!";};
		[[ObjNull,_msg,player,7],"TON_fnc_handleMessages",false] spawn life_fnc_MP;
		hint format["Polizeimeldung: %1",_msg];
		closeDialog 887890;
	};
};