document.getElementById('customerForm').addEventListener('submit', function(e) { e.preventDefault(); let tarikhLbi3a = document.getElementById('tarikh').value; let modaSelect = document.getElementById('lmoda').value; const newCustomer = { id: Date.now().toString(), smiya: document.getElementById('smiya').value, lmoda: modaSelect, email: document.getElementById('email').value, nemra: document.getElementById('nemra').value, note: document.getElementById('note').value, taman: document.getElementById('taman').value, tarikh: tarikhLbi3a, expiryDate: calculateExpiry(tarikhLbi3a, modaSelect), secret_key: "Makhass_7ta_Wa7ed_Y3ref_Had_Lmot_De_Passe_123!!" }; const scriptURL = 'https://crm.camly.store/save_client.php'; const submitBtn = this.querySelector('button[type="submit"]'); let originalText = submitBtn.innerText; submitBtn.innerText = '⏳ Kaytsift...'; submitBtn.disabled = true; fetch(scriptURL, { method: 'POST', body: JSON.stringify(newCustomer), headers: { "Content-Type": "application/json" } }) .then(response => response.json()) .then(data => { if(data.status === "success") { // Lma3loumat dakhlo l database b naja7 customers.push({ ...newCustomer, renewals: 0 }); saveData(); addLog(`Added new client: ${newCustomer.smiya}`); document.getElementById('customerForm').reset(); tarikhInput.valueAsDate = new Date(); tamanInput.value = prices["1 Month"]; lmodaSelect.value = "1 Month"; alert("✅ Lkliyane tzad w tsauvegarda f Database!"); updateDashboard(); } else { // Ila 9raha php w l9a mochkil (bhal l-mot de passe ghalta) alert("❌ Erreur men serveur: " + data.message); } }) .catch(error => { console.error('Error!', error); alert("❌ W9e3 mochkil. T2ked bli derti upload l fichier save_client.php f Hostinger f blasto s7i7a."); }) .finally(() => { submitBtn.innerText = originalText; submitBtn.disabled = false; }); });