using UnityEngine; using UnityEngine.UI; using System.Collections; using System.Text; using TMPro; [RequireComponent(typeof(Button))] public class Send : MonoBehaviour { public Text yournote; // ou TMP_Text si tu utilises TextMeshPro: public TMP_Text yournote; public Text designer; // idem : public TMP_Text designer; public InputField ClientName; public InputField ClientAddress; public InputField ClientEmail; public InputField ClientPhone; public InputField ClientNote; public InputField SendEmail; public void SaveWEB() { // 1) Construire le XML (si tu en as besoin) _G.Form.Clear(); _G.Form.Add(ClientName); _G.Form.Add(ClientAddress); _G.Form.Add(ClientEmail); _G.Form.Add(ClientPhone); _G.Form.Add(ClientNote); if (CheckAllInput()) { Measure.goTHANKS(_G.Form[0].text, _G.Form[2].text,SendEmail.text, "Email Send"); } else { print("----------Not All Input Feild-------------------"); } // --- (Optionnel) Envoi serveur en parallèle pour journaliser --- // StartCoroutine(SendTextToFile(xmls, this.name)); } public void OpenEmailSender() { byte[] bytes = SaveXML.BuildXmlBytes(); string xmls = Encoding.UTF8.GetString(bytes); _G.FileName = _G.Form != null && _G.Form.Count > 2 ? _G.Form[2].text : "client"; // 2) Préparer message FR/EN string note = (_G.L == 1) ? "Hi, this is a client request from the measurement tool Ukitchenit?" : "Bonjour, voici une demande client provenant de l'outil de mesure Ukitchenit?"; if (this.name == "software") {note = (_G.L == 1) ? "Hi, this is a client who opened a design?" : "Bonjour, voici un client qui a ouvert un design?";} if (yournote != null && !string.IsNullOrEmpty(yournote.text)) {note = yournote.text; }// respecte ce que l’utilisateur a saisi // 3) Destinataire string to = (designer != null && !string.IsNullOrEmpty(designer.text)) ? designer.text.Trim() : "hb@udesignit.ca"; // 4) Sujet & corps string subject = (_G.L == 1) ? "Ukitchenit client request" : "Demande client Ukitchenit"; string body = BuildEmailBody(note, xmls); Save_WEB.SaveWEB(_G.Form[2].text, xmls); OpenMailClient(to, subject, body); } private static string CleanInput(string s) { if (s == null) return ""; // Retire quelques “invisibles” courants + trim return s .Replace("\u200B", "") // zero-width space .Replace("\u00A0", " ") // no-break space -> espace normal .Trim(); } public bool CheckAllInput() { bool hasRequiredField = false; foreach (var input in _G.Form) { Debug.Log($"{input.name} text=[{input.text}] len={input.text?.Length}"); if (input == null) continue; // ✅ Exclure la note par référence (pas par nom) if (input == ClientNote) continue; hasRequiredField = true; Transform indicator = input.transform.Find("T_Indicator"); string value = CleanInput(input.text); bool filled = value.Length > 0; if (indicator != null) indicator.gameObject.SetActive(!filled); if (!filled) return false; } return hasRequiredField; } // Construit un corps lisible avec les infos disponibles private string BuildEmailBody(string note, string xml) { string CLIENT_INFO =ToUnicodeSansSerifBold(TRANS.This("T_Client Info").ToUpperInvariant()); string PREFERENCES=ToUnicodeSansSerifBold(TRANS.This("T_Preferences").ToUpperInvariant()); string NOTES=ToUnicodeSansSerifBold(TRANS.This("T_Note").ToUpperInvariant()); string SOFTWARELINK=ToUnicodeSansSerifBold(TRANS.This("T_ClickLink").ToUpperInvariant()); var sb = new StringBuilder(); sb.AppendLine(note); sb.AppendLine(); sb.AppendLine($"{CLIENT_INFO} ;");//Informations client sb.AppendLine("- "+TRANS.This("T_Name") +":"+ _G.Form[0].text);//Name sb.AppendLine("- "+TRANS.This("T_Address") +":"+ _G.Form[1].text);//Adress sb.AppendLine("- "+TRANS.This("T_Email") +":"+ _G.Form[2].text);//Adress sb.AppendLine("- "+TRANS.This("T_Phone") +":"+ _G.Form[3].text);//Phone sb.AppendLine(); //string STYLE="Country,Scandinave"; string STYLE = string.Join(" / ", _G.Style); string DOORMODEL = string.Join(" / ", _G.DoorModel); string COUNTERTOP = string.Join(" / ", _G.CounterTop); string WALLCOLOR = string.Join(" / ", _G.RoomColor); string FLOOR = string.Join(" / ", _G.FloorStyle); string ISLAND = string.Join(" / ", _G.Island); sb.AppendLine($"{PREFERENCES} ;");//Preferences sb.AppendLine( "- "+TRANS.This("T_Style")+ " : " + STYLE);//Kitchen style sb.AppendLine( "- "+TRANS.This("T_DoorModel")+ " : " + DOORMODEL); sb.AppendLine( "- "+TRANS.This("T_CounterTop")+ " : " + COUNTERTOP); sb.AppendLine( "- "+TRANS.This("T_WallColor")+ " : " + WALLCOLOR); sb.AppendLine( "- "+TRANS.This("T_Floor")+ " : " + FLOOR ); sb.AppendLine( "- "+TRANS.This("T_Island")+ " : " + ISLAND); sb.AppendLine(); sb.AppendLine($"{NOTES} ;"); sb.AppendLine(_G.Form[4].text); sb.AppendLine(); sb.AppendLine($"{SOFTWARELINK} ; "); sb.AppendLine($"https://ukitchenit.com/free/?mt_{_G.Form[2].text}"); return sb.ToString(); } // Ouvre le mailto avec encodage sûr private void OpenMailClient(string to, string subject, string body) { string enc(string s) => System.Uri.EscapeDataString(s ?? string.Empty); // Normaliser les retours à la ligne subject = subject?.Replace("\r\n", "\n").Replace("\r", "\n"); body = body?.Replace("\r\n", "\n").Replace("\r", "\n"); body = body?.Replace("\n", "\r\n"); string url = $"mailto:{to}?subject={enc(subject)}&body={enc(body)}"; Application.OpenURL(url); } public static string ToUnicodeSansSerifBold(string input) { if (string.IsNullOrEmpty(input)) return input; var sb = new StringBuilder(input.Length * 2); foreach (char c in input) { if (c >= 'A' && c <= 'Z') { // Mathematical Sans-Serif Bold Capital Letters int codePoint = 0x1D5D4 + (c - 'A'); // 𝗔..𝗭 sb.Append(char.ConvertFromUtf32(codePoint)); } else if (c >= 'a' && c <= 'z') { int codePoint = 0x1D5EE + (c - 'a'); // 𝗮..𝗹 sb.Append(char.ConvertFromUtf32(codePoint)); } else if (c >= '0' && c <= '9') { int codePoint = 0x1D7EC + (c - '0'); // 𝟬..𝟵 sb.Append(char.ConvertFromUtf32(codePoint)); } else { sb.Append(c); } } return sb.ToString(); } }