Zmiana widoku checkboksów

This commit is contained in:
Flatlogic Bot 2026-03-02 17:43:41 +00:00
parent 6d5f26a42c
commit 45d975adbf
4 changed files with 140 additions and 21 deletions

View File

@ -98,7 +98,7 @@ $instance = $engine->getActiveInstanceForSubject($process['code'], $subject_type
$instanceData = $instance['data_json'] ? json_decode($instance['data_json'], true) : []; $instanceData = $instance['data_json'] ? json_decode($instance['data_json'], true) : [];
?> ?>
<?php if ($isChecklist): ?> <?php if ($isChecklist): ?>
<?php <?php
$tasks = $definition['tasks'] ?? []; $tasks = $definition['tasks'] ?? [];
?> ?>
@ -108,10 +108,10 @@ $instance = $engine->getActiveInstanceForSubject($process['code'], $subject_type
<?php foreach ($tasks as $task): <?php foreach ($tasks as $task):
$isChecked = !empty($instanceData[$task['code']]); $isChecked = !empty($instanceData[$task['code']]);
?> ?>
<div class="form-check"> <div class="form-check mb-2" style="font-size: 1.15rem;">
<input class="form-check-input task-checkbox-modal" type="checkbox" value="" <input class="form-check-input task-checkbox-modal" type="checkbox" value="" style="cursor: pointer; border-radius: 0.25em;"
data-task-code="<?= $task['code'] ?>" <?= $isChecked ? 'checked' : '' ?>> data-task-code="<?= htmlspecialchars($task['code']) ?>" <?= $isChecked ? 'checked' : '' ?> id="chk_<?= htmlspecialchars($task['code']) ?>">
<label class="form-check-label" title="<?= htmlspecialchars($task['name']) ?>"> <label class="form-check-label pt-1" for="chk_<?= htmlspecialchars($task['code']) ?>" title="<?= htmlspecialchars($task['name']) ?>" style="cursor: pointer;">
<?= htmlspecialchars($task['name']) ?> <?= htmlspecialchars($task['name']) ?>
</label> </label>
</div> </div>
@ -173,22 +173,33 @@ $instance = $engine->getActiveInstanceForSubject($process['code'], $subject_type
$currentNode = $all_nodes[$currentNodeId] ?? null; $currentNode = $all_nodes[$currentNodeId] ?? null;
if ($currentNode && isset($currentNode['ui_hints']['form_schema'])): if ($currentNode && isset($currentNode['ui_hints']['form_schema'])):
?> ?>
<form id="transition-form"> <form id="transition-form">
<?php foreach ($currentNode['ui_hints']['form_schema'] as $field): ?> <?php foreach ($currentNode['ui_hints']['form_schema'] as $field):
<div class="mb-3"> $fieldName = $field['name'];
<label for="<?= $field['name'] ?>" class="form-label"><?= $field['label'] ?></label> $currentValue = $instanceData[$fieldName] ?? null;
<?php if ($field['type'] === 'textarea'): ?> ?>
<textarea id="<?= $field['name'] ?>" name="<?= $field['name'] ?>" class="form-control"></textarea> <?php if ($field['type'] === 'checkbox'): ?>
<?php elseif ($field['type'] === 'select'): ?> <div class="form-check mb-3" style="font-size: 1.15rem;">
<select id="<?= $field['name'] ?>" name="<?= $field['name'] ?>" class="form-select"> <input type="hidden" name="<?= htmlspecialchars($fieldName) ?>" value="0">
<?php foreach ($field['options'] as $option): ?> <input type="checkbox" id="<?= htmlspecialchars($fieldName) ?>" name="<?= htmlspecialchars($fieldName) ?>" class="form-check-input" value="1" style="cursor: pointer; border-radius: 0.25em;" <?= (!empty($currentValue) || (!isset($instanceData[$fieldName]) && !empty($field['default']))) ? 'checked' : '' ?>/>
<option value="<?= $option['value'] ?>"><?= $option['label'] ?></option> <label for="<?= htmlspecialchars($fieldName) ?>" class="form-check-label pt-1" style="cursor: pointer;"><?= htmlspecialchars($field['label']) ?></label>
<?php endforeach; ?> </div>
</select> <?php else: ?>
<?php else: ?> <div class="mb-3">
<input type="<?= $field['type'] ?>" id="<?= $field['name'] ?>" name="<?= $field['name'] ?>" class="form-control" value="<?= ($field['default'] ?? '') === 'now' ? date('Y-m-d\\TH:i') : '' ?>"> <label for="<?= htmlspecialchars($fieldName) ?>" class="form-label"><?= htmlspecialchars($field['label']) ?></label>
<?php endif; ?> <?php if ($field['type'] === 'textarea'): ?>
</div> <textarea id="<?= htmlspecialchars($fieldName) ?>" name="<?= htmlspecialchars($fieldName) ?>" class="form-control"><?= htmlspecialchars($currentValue ?? '') ?></textarea>
<?php elseif ($field['type'] === 'select'): ?>
<select id="<?= htmlspecialchars($fieldName) ?>" name="<?= htmlspecialchars($fieldName) ?>" class="form-select">
<?php foreach ($field['options'] as $option): ?>
<option value="<?= htmlspecialchars($option['value']) ?>" <?= $currentValue == $option['value'] ? 'selected' : '' ?>><?= htmlspecialchars($option['label']) ?></option>
<?php endforeach; ?>
</select>
<?php else: ?>
<input type="<?= htmlspecialchars($field['type']) ?>" id="<?= htmlspecialchars($fieldName) ?>" name="<?= htmlspecialchars($fieldName) ?>" class="form-control" value="<?= htmlspecialchars((string)($currentValue ?? (($field['default'] ?? '') === 'now' ? date('Y-m-d\TH:i') : ($field['default'] ?? '')))) ?>">
<?php endif; ?>
</div>
<?php endif; ?>
<?php endforeach; ?> <?php endforeach; ?>
</form> </form>
<?php endif; ?> <?php endif; ?>

72
patch_script.py Normal file
View File

@ -0,0 +1,72 @@
import re
with open('_get_instance_details.php', 'r', encoding='utf-8') as f:
content = f.read()
checklist_replacement = """ <?php if ($isChecklist): ?>
<?php
$tasks = $definition['tasks'] ?? [];
?>
<div class="checklist-modal-container" data-instance-id="<?= $instanceId ?>">
<h5>Zadania do wykonania</h5>
<div class="checklist-container">
<?php foreach ($tasks as $task):
$isChecked = !empty($instanceData[$task['code']]);
?>
<div class="form-check mb-2" style="font-size: 1.15rem;">
<input class="form-check-input task-checkbox-modal" type="checkbox" value="" style="cursor: pointer; border-radius: 0.25em;"
data-task-code="<?= htmlspecialchars($task['code']) ?>" <?= $isChecked ? 'checked' : '' ?> id="chk_<?= htmlspecialchars($task['code']) ?>">
<label class="form-check-label pt-1" for="chk_<?= htmlspecialchars($task['code']) ?>" title="<?= htmlspecialchars($task['name']) ?>" style="cursor: pointer;">
<?= htmlspecialchars($task['name']) ?>
</label>
</div>
<?php endforeach; ?>
</div>
</div>"""
content = re.sub(
r"<\?php if \(\$isChecklist\): \?>.*?</div>\s*</div>",
lambda m: checklist_replacement,
content,
flags=re.DOTALL
)
form_replacement = """ <form id="transition-form">
<?php foreach ($currentNode['ui_hints']['form_schema'] as $field):
$fieldName = $field['name'];
$currentValue = $instanceData[$fieldName] ?? null;
?>
<?php if ($field['type'] === 'checkbox'): ?>
<div class="form-check mb-3" style="font-size: 1.15rem;">
<input type="checkbox" id="<?= htmlspecialchars($fieldName) ?>" name="<?= htmlspecialchars($fieldName) ?>" class="form-check-input" value="1" style="cursor: pointer; border-radius: 0.25em;" <?= (!empty($currentValue) || (!isset($instanceData[$fieldName]) && !empty($field['default']))) ? 'checked' : '' ?>/>
<label for="<?= htmlspecialchars($fieldName) ?>" class="form-check-label pt-1" style="cursor: pointer;"><?= htmlspecialchars($field['label']) ?></label>
</div>
<?php else: ?>
<div class="mb-3">
<label for="<?= htmlspecialchars($fieldName) ?>" class="form-label"><?= htmlspecialchars($field['label']) ?></label>
<?php if ($field['type'] === 'textarea'): ?>
<textarea id="<?= htmlspecialchars($fieldName) ?>" name="<?= htmlspecialchars($fieldName) ?>" class="form-control"><?= htmlspecialchars($currentValue ?? '') ?></textarea>
<?php elseif ($field['type'] === 'select'): ?>
<select id="<?= htmlspecialchars($fieldName) ?>" name="<?= htmlspecialchars($fieldName) ?>" class="form-select">
<?php foreach ($field['options'] as $option): ?>
<option value="<?= htmlspecialchars($option['value']) ?>" <?= $currentValue == $option['value'] ? 'selected' : '' ?>><?= htmlspecialchars($option['label']) ?></option>
<?php endforeach; ?>
</select>
<?php else: ?>
<input type="<?= htmlspecialchars($field['type']) ?>" id="<?= htmlspecialchars($fieldName) ?>" name="<?= htmlspecialchars($fieldName) ?>" class="form-control" value="<?= htmlspecialchars((string)($currentValue ?? (($field['default'] ?? '') === 'now' ? date('Y-m-d\\TH:i') : ($field['default'] ?? '')))) ?>">
<?php endif; ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
</form>"""
content = re.sub(
r"<form id=\"transition-form\">.*?</form>",
lambda m: form_replacement,
content,
flags=re.DOTALL
)
with open('_get_instance_details.php', 'w', encoding='utf-8') as f:
f.write(content)
print("File _get_instance_details.php patched successfully.")

23
patch_script2.py Normal file
View File

@ -0,0 +1,23 @@
import re
with open('_get_instance_details.php', 'r', encoding='utf-8') as f:
content = f.read()
def replace_checkbox(m):
block = m.group(0)
return re.sub(
r'<input type="checkbox" id="<\?= htmlspecialchars\(\$fieldName\) \?>"',
r'<input type="hidden" name="<?= htmlspecialchars($fieldName) ?>" value="0">\n <input type="checkbox" id="<?= htmlspecialchars($fieldName) ?>" name="<?= htmlspecialchars($fieldName) ?>"',
block
)
content = re.sub(
r"<\?php if \(\$field\['type'\] === 'checkbox'\): \?>.*?<\?php else: \?>",
replace_checkbox,
content,
flags=re.DOTALL
)
with open('_get_instance_details.php', 'w', encoding='utf-8') as f:
f.write(content)
print("Hidden inputs added.")

13
patch_script3.py Normal file
View File

@ -0,0 +1,13 @@
import re
with open('_get_instance_details.php', 'r', encoding='utf-8') as f:
content = f.read()
content = content.replace('name="<?= htmlspecialchars($fieldName) ?>" name="<?= htmlspecialchars($fieldName) ?>"', 'name="<?= htmlspecialchars($fieldName) ?>"')
# Also fix the trailing slash from my earlier mistake `<input ... />` just to make it clean `>`
content = content.replace('<?= (!empty($currentValue) || (!isset($instanceData[$fieldName]) && !empty($field["default"])) ? "checked" : "" ?>/>', '<?= (!empty($currentValue) || (!isset($instanceData[$fieldName]) && !empty($field["default"])) ? "checked" : "" ?>>')
with open('_get_instance_details.php', 'w', encoding='utf-8') as f:
f.write(content)
print("Cleaned up duplicates.")