@אa זה קוד תכניס נתיב כולל שם הקובץ טוקן אקסל שעמודה A שם עמודה B טלפון וזה אמור להעלות במנה תקין לי זה עובד
זה מוחק את כל מה שיש בקובץ זהירות!!
<!DOCTYPE html>
<html lang="he" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>מעלה קבצי INI מעובדים לימות המשיח</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<style>
body { font-family: Arial, sans-serif; margin: 20px; line-height: 1.6; text-align: right; }
.container { max-width: 500px; margin: auto; border: 1px solid #ccc; padding: 20px; border-radius: 8px; box-shadow: 2px 2px 10px #eee; }
input, button { width: 100%; padding: 10px; margin: 10px 0; border-radius: 4px; border: 1px solid #ddd; box-sizing: border-box; }
button { background-color: #28a745; color: white; cursor: pointer; border: none; font-weight: bold; }
button:hover { background-color: #218838; }
.status { margin-top: 15px; font-weight: bold; text-align: center; }
</style>
</head>
<body>
<div class="container">
<h2>יצירת קובץ INI (ניקוי מספרים)</h2>
<label>טוקן (Token):</label>
<input type="text" id="token" placeholder="הכנס טוקן">
<label>נתיב להעלאה:</label>
<input type="text" id="path" placeholder="ivr2:5/PhoneIndex.ini">
<label>בחירת קובץ אקסל:</label>
<input type="file" id="excelFile" accept=".xlsx, .xls, .csv">
<button onclick="processAndUpload()">נקה מספרים והעלה</button>
<div id="status" class="status"></div>
</div>
<script>
// פונקציה לניקוי והכנת מספר הטלפון
function formatPhoneNumber(phone) {
if (!phone) return "";
// הפיכה למחרוזת והסרת מקפים, רווחים ותווים שאינם מספרים
let cleaned = String(phone).replace(/\D/g, '');
// אם המספר מתחיל ב-5 (ללא 0) והוא באורך של מספר סלולרי ישראלי חסר
if (cleaned.startsWith('5') && cleaned.length === 9) {
cleaned = '0' + cleaned;
}
// אם המספר מתחיל בקידומת בינלאומית 972, נחליף ל-0
if (cleaned.startsWith('972')) {
cleaned = '0' + cleaned.substring(3);
}
return cleaned;
}
async function processAndUpload() {
const token = document.getElementById('token').value;
const path = document.getElementById('path').value;
const fileInput = document.getElementById('excelFile');
const statusDiv = document.getElementById('status');
if (!token || !path || !fileInput.files[0]) {
alert("נא למלא את כל השדות");
return;
}
statusDiv.innerText = "מעבד נתונים ומנקה מספרים...";
statusDiv.style.color = "blue";
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = async function(e) {
try {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
const worksheet = workbook.Sheets[workbook.SheetNames[0]];
const json = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
let iniContent = "";
// דילוג על שורת כותרת אם קיימת (אופציונלי - כאן הוא עובר על הכל)
json.forEach(row => {
let name = row[0];
let rawPhone = row[1];
if (name && rawPhone) {
let cleanPhone = formatPhoneNumber(rawPhone);
iniContent += `${cleanPhone}=${name}\n`;
}
});
if (!iniContent) {
statusDiv.innerText = "לא נמצאו נתונים תקינים באקסל";
return;
}
uploadFile(iniContent, token, path);
} catch (err) {
statusDiv.innerText = "שגיאה בפענוח הקובץ";
console.error(err);
}
};
reader.readAsArrayBuffer(file);
}
async function uploadFile(content, token, path) {
const statusDiv = document.getElementById('status');
const apiUrl = `https://www.call2all.co.il/ym/api/UploadFile?token=${token}&path=${path}`;
const formData = new FormData();
const blob = new Blob([content], { type: 'text/plain; charset=utf-8' });
formData.append('file', blob, 'file.ini');
try {
const response = await fetch(apiUrl, { method: 'POST', body: formData });
const result = await response.json();
if (result.responseStatus === "OK") {
statusDiv.innerText = "הקובץ נוקה והועלה בהצלחה!";
statusDiv.style.color = "green";
} else {
statusDiv.innerText = "שגיאה: " + result.message;
statusDiv.style.color = "red";
}
} catch (error) {
statusDiv.innerText = "שגיאת תקשורת (וודא שאין חסימת CORS)";
statusDiv.style.color = "red";
}
}
</script>
</body>
</html>