קוד להוספה מהירה של נקודות דרך הדפדפן, ועוד.
-
לתועלת המשתמשים מצורף כאן קוד PHP להוספה מהירה של נקודות,
וכך זה נראה:

לתשומת לב:
- הקוד נבנה לצורך משתמשים שמזוהים (לגבי צבירת הנקודות) ע"י מספר סידורי,
אך באופן שהמשתמשים מזוהים ע"י הטלפון המחייג, או ת"ז וכו' - לא בדקתי האם גם שם הקוד יעבוד תקין, אם לאו, ויתכן שלזה יצטרכו תיקון קטן-
בפוקציית "בדיקת נקודות" חובה למלא שדה מזהה.
-
בפונקצייית "איפוס כל המזהים" חובה למלא לפחות שדה מזהה 1, ואז הקוד מפעיל איפוס על כל המזהים הקיימים.
-
אפשר כמובן גם להוריד נקודות למשתמש ע"י מינוס (לדוגמא: -100)
-
חשוב מאוד!! יש לשים לב, שכאשר המשתמש מוסיף לעצמו נקודות דרך הטלפון, אזי הקובץ points_total.ini אינו מתעדכן באתר באופן מיידי בשינויים שנעשו ע"י הטלפון, אלא זה אורך לפעמים 5 דקות ולפעמים שעה (ואולי גם יותר), - ולכן חשוב לדעת שאם תבצעו הוספת נקודות דרך הדפדפן, השינויים יחולו רק לפי הנתונים שבקובץ points_total.ini שנמצא באותו רגע באתר, וכאמור לפעמים הוא לא מעודכן.
כמדומה שאפשר לבדוק האם הקובץ כבר התעדכן בשינויים שנעשו ע"י הטלפון או עדיין לא, ע"י בדיקה האם הקובץ ini הנ"ל חדש יותר מהקובץ: points_total.ymgr שאז זה אומר שה ini כבר מעודכן - אבל אינני לוקח אחריות בענייןאפשר גם לעשות שלוחה מובנית מראש שתוסיף נקודות למשתמשים מרובים ע"פ בחירה, דוגמא בספויילר.
type=api api_link=http://164.XXXXXXXX/hosafat_nekudot.php api_hangup_send=no title=לינק להוספת נקודות api_end_goto=/ טוקן api_add_0=token=07777777:123456 נתיב api_add_1=filePath=ivr2:/Points/Split/points_total.ini מזון ונקיון api_add_2=updates[id][0]=1 סכום api_add_3=updates[points][0]=-764 ביגוד api_add_4=updates[id][1]=2 סכום api_add_5=updates[points][1]=-188 כלי בית, תחזוקה, צעצועים ושונות api_add_6=updates[id][2]=3 סכום api_add_7=updates[points][2]=-133 שונות api_add_8=updates[id][3]=4 סכום api_add_9=updates[points][3]=-22להלן הקוד:
<?php // --- הגדרת משתנים להודעות --- // $success = ''; $error = ''; // --- פונקציות API --- // function downloadFile($token, $filePath) { $apiUrl = 'https://www.call2all.co.il/ym/api/GetTextFile'; $ch = curl_init($apiUrl); $postData = http_build_query([ 'token' => $token, 'what' => $filePath, ]); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postData, ]); $response = curl_exec($ch); curl_close($ch); // ננסה לפרש את התשובה כ-JSON $data = json_decode($response, true); if (is_array($data) && isset($data['responseStatus'])) { if ($data['responseStatus'] !== 'OK') { return [ 'status' => 'error', 'message' => 'שגיאה בהורדת הקובץ: ' . ($data['message'] ?? 'לא ידוע'), ]; } // כאן התוכן האמיתי של הקובץ (השורות digits-1-...) $contents = $data['contents'] ?? ''; return [ 'status' => 'ok', 'content' => $contents, ]; } // אם זו לא תשובת JSON – נחזיר כטקסט גולמי return [ 'status' => 'ok', 'content' => $response, ]; } function uploadFile($token, $filePath, $content) { $apiUrl = 'https://www.call2all.co.il/ym/api/UploadTextFile'; $ch = curl_init($apiUrl); $postData = http_build_query([ 'token' => $token, 'what' => $filePath, 'contents' => $content, // רק הטקסט של הקובץ ]); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postData, ]); $response = curl_exec($ch); curl_close($ch); $data = json_decode($response, true); if (is_array($data) && isset($data['responseStatus']) && $data['responseStatus'] === 'OK') { return ['status' => 'ok']; } $msg = is_array($data) && isset($data['message']) ? $data['message'] : 'תגובה לא תקינה מהשרת'; return ['status' => 'error', 'message' => 'שגיאה בהעלאת הקובץ: ' . $msg]; } // --- לוגיקה ראשית --- // if ($_SERVER['REQUEST_METHOD'] === 'POST' || !empty($_GET)) { do { $source = $_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : $_GET; // פעולה: בדיקה / עדכון / איפוס נבחרים / איפוס הכל $action = $source['action'] ?? 'update'; // פרמטרים $token = trim($source['token'] ?? ''); $filePath = trim($source['filePath'] ?? ''); $updates = $source['updates'] ?? null; if (empty($token) || empty($filePath)) { $error = 'יש למלא TOKEN ונתיב קובץ.'; break; } // באקשנים שקשורים ל-IDים (update / reset_selected) אנחנו צריכים לפחות מזהה אחד if (in_array($action, ['update', 'reset_selected'], true)) { if (empty($updates) || !is_array($updates['id'])) { $error = 'יש להזין לפחות מזהה אחד.'; break; } } $updateIds = isset($updates['id']) ? $updates['id'] : []; $updatePoints = isset($updates['points']) ? $updates['points'] : []; // ולידציה בסיסית למזהים – רק כשיש IDs if (!empty($updateIds)) { foreach ($updateIds as $id) { $id = trim($id); if ($id === '' || !is_numeric($id)) { $error = 'נמצאו מזהים לא חוקיים. אנא בדוק את כל שדות ה-ID.'; break 2; } } } // לוגיקת עדכון $updatesToProcess = []; if ($action === 'update') { if (!is_array($updatePoints) || count($updateIds) !== count($updatePoints)) { $error = 'שגיאה פנימית: מספר המזהים אינו תואם למספר ערכי הנקודות.'; break; } foreach ($updateIds as $index => $id) { $points = $updatePoints[$index] ?? ''; $id = trim($id); $points = trim($points); if ($points === '' || !is_numeric($points)) { $error = 'נמצאו ערכי נקודות לא חוקיים. אנא בדוק את כל השדות.'; break 2; } $updatesToProcess[$id] = ($updatesToProcess[$id] ?? 0) + (float)$points; } if (empty($updatesToProcess)) { $error = 'לא נמצאו עדכונים חוקיים לעיבוד.'; break; } } // 2. הורדת הקובץ $downloadResult = downloadFile($token, $filePath); if ($downloadResult['status'] === 'error') { $error = $downloadResult['message']; break; } $fileContent = $downloadResult['content']; $lines = preg_split('/\r\n|\n|\r/', $fileContent); $newContentArray = []; $updatedIds = []; // 3. מצבים שונים לפי action if ($action === 'reset_all') { // איפוס כל המזהים לקובץ foreach ($lines as $line) { if (preg_match('/^(digits-\d+-points_total=)([-.0-9]+)$/', $line, $m)) { $prefix = $m[1]; $newContentArray[] = $prefix . '0'; } else { $newContentArray[] = $line; } } $newContent = implode("\n", $newContentArray); $uploadResult = uploadFile($token, $filePath, $newContent); if ($uploadResult['status'] === 'error') { $error = $uploadResult['message']; break; } $success = 'כל המזהים אופסו לנקודות 0.'; break; } if ($action === 'reset_selected') { // איפוס רק למזהים שנבחרו $idsToReset = array_map('trim', $updateIds); $idsToReset = array_values(array_filter($idsToReset, 'strlen')); $resetFound = []; foreach ($lines as $line) { if (preg_match('/^digits-(\d+)-points_total=([-.0-9]+)$/', $line, $m)) { $currentId = $m[1]; $prefix = "digits-{$currentId}-points_total="; if (in_array($currentId, $idsToReset, true)) { $newContentArray[] = $prefix . '0'; $resetFound[] = $currentId; } else { $newContentArray[] = $line; } } else { $newContentArray[] = $line; } } $newContent = implode("\n", $newContentArray); $uploadResult = uploadFile($token, $filePath, $newContent); if ($uploadResult['status'] === 'error') { $error = $uploadResult['message']; break; } if (!empty($resetFound)) { $success = 'המזהים הבאים אופסו לנקודות 0: ' . implode(', ', $resetFound) . '.'; } else { $error = 'אף אחד מהמזהים שבחרת לא נמצא בקובץ.'; } break; } if ($action === 'check') { // בדיקה בלבד – לא משנים את הקובץ $statusMessages = []; // אם לא הוזן אף מזהה – מציגים את כל המזהים מהקובץ $hasAnyId = false; foreach ($updateIds as $rawId) { if (trim($rawId) !== '') { $hasAnyId = true; break; } } if (!$hasAnyId) { // כל המזהים foreach ($lines as $line) { if (preg_match('/^digits-(\d+)-points_total=([-.0-9]+)$/', $line, $m)) { $id = $m[1]; $points = $m[2]; $statusMessages[] = "מזהה {$id}: נקודות נוכחיות = {$points}"; } } if (!empty($statusMessages)) { $success = implode(' | ', $statusMessages); } else { $error = 'לא נמצאו מזהים בקובץ.'; } break; } // יש מזהים מסוימים – מציגים רק אותם foreach ($updateIds as $id) { $id = trim($id); if ($id === '') { continue; } $found = false; $points = null; foreach ($lines as $line) { if (preg_match('/^digits-(' . preg_quote($id, '/') . ')-points_total=([-.0-9]+)$/', $line, $m)) { $found = true; $points = $m[2]; break; } } if ($found) { $statusMessages[] = "מזהה {$id}: נקודות נוכחיות = {$points}"; } else { $statusMessages[] = "מזהה {$id}: לא נמצא בקובץ."; } } if (!empty($statusMessages)) { $success = implode(' | ', $statusMessages); } else { $error = 'לא נמצאו מזהים חוקיים או תואמים בקובץ.'; } break; } // action === 'update' – עדכון נקודות רגיל foreach ($lines as $line) { if (preg_match('/^digits-(\d+)-points_total=/', $line, $matches)) { $currentId = $matches[1]; if (isset($updatesToProcess[$currentId])) { $pointsToAdd = $updatesToProcess[$currentId]; if (preg_match('/^(digits-\d+-points_total=)([-.0-9]+)$/', $line, $valueMatches)) { $prefix = $valueMatches[1]; $currentValue = $valueMatches[2]; $newValue = (float)$currentValue + (float)$pointsToAdd; $newContentArray[] = $prefix . $newValue; $updatedIds[] = $currentId; unset($updatesToProcess[$currentId]); } else { $newContentArray[] = $line; } continue; } } $newContentArray[] = $line; } $newContent = implode("\n", $newContentArray); $uploadResult = uploadFile($token, $filePath, $newContent); if ($uploadResult['status'] === 'error') { $error = $uploadResult['message']; break; } $successMessage = ''; if (!empty($updatedIds)) { $successMessage = 'הקובץ עודכן. מזהים שעודכנו: ' . implode(', ', $updatedIds) . '.'; } $errorMessage = ''; if (!empty($updatesToProcess)) { $notFoundIds = array_keys($updatesToProcess); $errorMessage = 'המזהים הבאים לא נמצאו בקובץ או שהפורמט שלהם שגוי: ' . implode(', ', $notFoundIds) . '.'; } if (!empty($successMessage) && !empty($errorMessage)) { $success = $successMessage . ' ' . $errorMessage; } elseif (!empty($successMessage)) { $success = $successMessage; } else { $error = $errorMessage ?: 'לא בוצעו עדכונים. ייתכן שהמזהים שהוזנו לא קיימים בקובץ.'; } } while (false); } ?> <!DOCTYPE html> <html lang="he"> <head> <meta charset="UTF-8"> <title>ניהול נקודות בקובץ - ימות המשיח</title> <style> body { font-family: Arial, sans-serif; direction: rtl; padding: 20px; max-width: 700px; margin: auto; background-color: #f4f4f4; } h2 { text-align: center; color: #333; } form { background: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); } label { display: block; margin-top: 15px; font-weight: bold; color: #555; } input[type="text"], input[type="number"] { width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #ddd; border-radius: 4px; box-sizing: border-box; } button[type="submit"], button[type="button"] { padding: 10px 15px; font-size: 14px; border: none; border-radius: 4px; cursor: pointer; } .submit-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; } .btn-check { background-color: #6c757d; color: #fff; flex: 1; } .btn-check:hover { background-color: #5a6268; } .btn-update { background-color: #007bff; color: #fff; flex: 1; } .btn-update:hover { background-color: #0056b3; } .btn-reset-selected { background-color: #ffc107; color: #212529; flex: 1; } .btn-reset-selected:hover { background-color: #e0a800; } .btn-reset-all { background-color: #dc3545; color: #fff; flex: 1; } .btn-reset-all:hover { background-color: #c82333; } .msg { margin-top: 20px; padding: 15px; border-radius: 4px; font-weight: bold; text-align: center; } .error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; } .success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; } .update-pair { display: flex; gap: 10px; margin-bottom: 10px; align-items: center; } .update-pair input { flex: 1; } #add-update-field { width: auto; padding: 8px 15px; font-size: 14px; background-color: #28a745; margin-top: 10px; border: none; border-radius: 4px; color: white; cursor: pointer; } #add-update-field:hover { background-color: #218838; } .remove-field { background-color: #dc3545; color: white; border: none; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; font-weight: bold; line-height: 24px; text-align: center; padding: 0; } .remove-field:hover { background-color: #c82333; } small.hint { color: #777; display: block; margin-top: 4px; } </style> <script> document.addEventListener('DOMContentLoaded', function() { const container = document.getElementById('update-fields-container'); function addField() { const newPair = document.createElement('div'); newPair.className = 'update-pair'; newPair.innerHTML = ` <input type="number" name="updates[id][]" placeholder="מזהה ID"> <input type="number" name="updates[points][]" step="any" placeholder="נקודות (לעדכון בלבד)"> <button type="button" class="remove-field">X</button> `; container.appendChild(newPair); } document.getElementById('add-update-field').addEventListener('click', addField); container.addEventListener('click', function(e) { if (e.target && e.target.classList.contains('remove-field')) { if (container.children.length > 1) { e.target.closest('.update-pair').remove(); } } }); function setRequiredForIdPoints(required) { const idInputs = container.querySelectorAll('input[name="updates[id][]"]'); const pointInputs = container.querySelectorAll('input[name="updates[points][]"]'); idInputs.forEach(inp => inp.required = required); pointInputs.forEach(inp => inp.required = required); } const btnCheck = document.querySelector('button[name="action"][value="check"]'); const btnUpdate = document.querySelector('button[name="action"][value="update"]'); const btnResetSelected = document.querySelector('button[name="action"][value="reset_selected"]'); const btnResetAll = document.querySelector('button[name="action"][value="reset_all"]'); if (btnCheck) { btnCheck.addEventListener('click', function() { // בדיקה בלבד – לא נדרש למלא מזהים setRequiredForIdPoints(false); }); } if (btnUpdate) { btnUpdate.addEventListener('click', function() { setRequiredForIdPoints(true); }); } if (btnResetSelected) { btnResetSelected.addEventListener('click', function() { setRequiredForIdPoints(true); }); } if (btnResetAll) { btnResetAll.addEventListener('click', function() { setRequiredForIdPoints(false); }); } }); </script> </head> <body> <h2>עדכון / בדיקה / איפוס נקודות בימות המשיח</h2> <form method="post"> <label for="token">TOKEN:</label> <input type="text" id="token" name="token" required> <label for="filePath">נתיב קובץ מלא (למשל, ivr2:/Points/Split/points_total.ini):</label> <input type="text" id="filePath" name="filePath" required> <label>מזהים (לבדיקה, עדכון או איפוס נבחרים):</label> <small class="hint">באיפוס כללי (איפוס כל המזהים) או בבדיקת כל המזהים אין חובה למלא מזהים.</small> <div id="update-fields-container"> <div class="update-pair"> <input type="number" name="updates[id][]" placeholder="מזהה ID"> <input type="number" name="updates[points][]" step="any" placeholder="נקודות (לעדכון בלבד)"> </div> </div> <button type="button" id="add-update-field">הוסף שדה מזהה/נקודות</button> <div class="submit-row"> <button type="submit" name="action" value="check" class="btn-check">בדוק מצב נקודות</button> <button type="submit" name="action" value="update" class="btn-update">בצע עדכון נקודות</button> <button type="submit" name="action" value="reset_selected" class="btn-reset-selected">איפוס מזהים נבחרים</button> <button type="submit" name="action" value="reset_all" class="btn-reset-all" onclick="return confirm('למחוק את כל הנקודות לכל המזהים? פעולה זו בלתי הפיכה.');">איפוס כל המזהים</button> </div> </form> <?php if (!empty($error)): ?> <div class="msg error"> <?= htmlspecialchars($error) ?> </div> <?php elseif (!empty($success)): ?> <div class="msg success"> <?= htmlspecialchars($success) ?> </div> <?php endif; ?> </body> </html>בהצלחה!