diff --git a/_get_instance_details.php b/_get_instance_details.php index cdf1440..68eed9c 100644 --- a/_get_instance_details.php +++ b/_get_instance_details.php @@ -62,47 +62,10 @@ $instance = $engine->getInstanceByDefId($person_id, $process_definition_id); Obecny status: . - - -""" +start_str = " const instanceModalElement = document.getElementById('instanceModal');\n if (instanceModalElement) {\n instanceModalElement.addEventListener('click', function(event) {\n const btn = event.target.closest('#startProcessBtn');\n if (!btn) return;" +end_str = " });\n }" -content = content.replace("});\n", patch_code) - -with open('index.php', 'w') as f: - f.write(content) - -print("Patched index.php") +start_idx = content.find(start_str) +if start_idx != -1: + end_idx = content.find(end_str, start_idx) + if end_idx != -1: + end_idx += len(end_str) + + replacement = " const instanceModalElement = document.getElementById('instanceModal');\n if (instanceModalElement) {\n instanceModalElement.addEventListener('click', function(event) {\n const startBtn = event.target.closest('#startProcessBtn');\n const restartBtn = event.target.closest('#restartProcessBtn');\n const btn = startBtn || restartBtn;\n if (!btn) return;\n \n event.preventDefault();\n event.stopPropagation();\n \n const isRestart = !!restartBtn;\n \n const personId = btn.dataset.personId;\n const processId = btn.dataset.processId;\n const processCode = btn.dataset.processCode;\n \n if (!personId) {\n alert('Brak ID osoby');\n return;\n }\n if (isRestart && !processCode) {\n alert('Brak kodu procesu');\n return;\n }\n if (!isRestart && !processId) {\n alert('Brak ID procesu');\n return;\n }\n \n const originalText = btn.innerHTML;\n btn.disabled = true;\n btn.innerHTML = '...';\n \n const formData = new FormData();\n formData.append('person_id', personId);\n \n if (isRestart) {\n formData.append('process_code', processCode);\n formData.append('mode', 'create_new_run');\n } else {\n formData.append('process_id', processId);\n }\n \n if (instanceModalElement && processId) {\n instanceModalElement.dataset.lastPersonId = personId;\n instanceModalElement.dataset.lastProcessId = processId;\n }\n \n fetch('_init_single_instance.php', {\n method: 'POST',\n body: formData\n })\n .then(async response => {\n let data;\n try {\n data = await response.json();\n } catch (e) {\n throw new Error(`Błąd serwera (HTTP ${response.status}): Nieoczekiwany błąd (invalid JSON)`);\n }\n \n if (!response.ok || !data.success) {\n let errMsg = data?.error?.message || data?.error || 'Nieznany błąd';\n if (data?.correlation_id) {\n errMsg += ` (ID błędu: ${data.correlation_id})`;\n }\n throw new Error(errMsg);\n }\n return data;\n })\n .then(data => {\n const modalBody = instanceModalElement.querySelector('.modal-body');\n modalBody.innerHTML = '

Ładowanie...

';\n \n const refreshProcessId = data.process_definition_id || processId || instanceModalElement.dataset.lastProcessId;\n if (refreshProcessId) {\n instanceModalElement.dataset.lastProcessId = refreshProcessId;\n }\n \n fetch(`_get_instance_details.php?person_id=${personId}&process_id=${refreshProcessId}`)\n .then(r => r.text())\n .then(html => {\n modalBody.innerHTML = html;\n window.matrixNeedsRefresh = true;\n });\n })\n .catch(err => {\n console.error(err);\n alert(err.message || 'Błąd sieci');\n btn.disabled = false;\n btn.innerHTML = originalText;\n });\n });\n }" + + new_content = content[:start_idx] + replacement + content[end_idx:] + with open('index.php', 'w', encoding='utf-8') as f: + f.write(new_content) + print("Replaced index.php block successfully.") + else: + print("End string not found.") +else: + print("Start string not found.") diff --git a/patch_modal.py b/patch_modal.py index 853538d..b6cfaab 100644 --- a/patch_modal.py +++ b/patch_modal.py @@ -1,73 +1,17 @@ import re -with open('_get_instance_details.php', 'r') as f: +with open('_get_instance_details.php', 'r', encoding='utf-8') as f: content = f.read() -patch_code = """ - - -
-
- - Obecny status: . -
- \s*
\s*' +replacement = r''' - - - - ''' -content = content.replace( - """ -