when i edit a customer when i edit the existing details and the existing device and save…
- User
when i edit a customer when i edit the existing details and the existing device and save the customer the changes apply , if i remove the device or add an extra one or remove and re-add and save then the changes do not apply please provide me the complete fixed code :
<div class="container"> <div class="content"> <h1 class="text-center mb-4">Διαχείριση Πελατών</h1> <?php if (isset($_GET['status']) && $_GET['status'] == 'success'): ?> <div class="alert alert-success">Η ενέργεια πελάτη ολοκληρώθηκε με επιτυχία!</div> <?php endif; ?> <!-- Κουμπί ενεργοποίησης modal --> <button type="button" class="btn btn-outline-danger mb-4" data-toggle="modal" data-target="#customerModal"> Προσθήκη Νέου Πελάτη </button> <!-- Modal για προσθήκη νέου πελάτη --> <div class="modal fade" id="customerModal" tabindex="-1" aria-labelledby="customerModalLabel" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="customerModalLabel">Προσθήκη Νέου Πελάτη</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <form action="customers.php" method="post"> <input type="hidden" name="action" value="add_customer"> <div class="form-group"> <label for="full_name">Ονοματεπώνυμο</label> <input type="text" class="form-control" id="full_name" name="full_name" required> </div> <div class="form-row"> <div class="form-group col-md-6"> <label for="landline_phone">Τηλέφωνο Σταθερό</label> <input type="text" class="form-control" id="landline_phone" name="landline_phone"> </div> <div class="form-group col-md-6"> <label for="cellphone_number">Αριθμός Κινητού</label> <input type="text" class="form-control" id="cellphone_number" name="cellphone_number"> </div> </div> <h3 class="mt-4">Συσκευές σε Κατοχή</h3> <div id="device_list"> <div class="device-item d-flex align-items-end"> <div class="form-group mr-2"> <label for="device_id">Επιλογή Συσκευής</label> <select class="form-control device-select" id="device_id" name="devices[0][device_id]" required onchange="toggleSerialInput(this)"> <option value="" selected disabled>Επιλέξτε συσκευή</option> <option value="none">Χωρίς συσκευή</option> <?php foreach ($devices as $device): ?> <option value="<?= $device['id'] ?>"><?= $device['type'] ?> - <?= $device['brand'] ?> - <?= $device['model'] ?></option> <?php endforeach; ?> </select> </div> <div class="form-group"> <label for="serial_number">Σειριακός Αριθμός</label> <input type="text" class="form-control serial-number" id="serial_number" name="devices[0][serial_number]" required> </div> <button type="button" class="close-btn ml-2" onclick="removeDevice(this)">×</button> </div> </div> <button type="button" class="btn btn-outline-danger mt-2" id="add_device">Προσθήκη Άλλης Συσκευής</button> <button type="submit" class="btn btn-outline-danger mt-2 ml-2">Προσθήκη Πελάτη</button> </form> </div> </div> </div> </div> <!-- Λίστα Πελατών --> <h2>Λίστα Πελατών</h2> <input type="text" id="customerSearch" class="form-control mb-3" placeholder="Αναζήτηση πελατών..."> <?php if (count($customers) > 0): ?> <table class="table table-bordered table-hover"> <thead class="thead-dark"> <tr> <th>ID</th> <th>Ονοματεπώνυμο</th> <th>Τηλέφωνο Σταθερό</th> <th>Αριθμός Κινητού</th> <th>Ημερομηνία Εγγραφής</th> <th>Ενέργειες</th> </tr> </thead> <tbody id="customerTable"> <?php foreach ($customers as $customer): ?> <tr> <td><?= htmlspecialchars($customer['id']) ?></td> <td><?= htmlspecialchars($customer['full_name']) ?></td> <td><?= htmlspecialchars($customer['landline_phone']) ?></td> <td><?= htmlspecialchars($customer['cellphone_number']) ?></td> <td><?= htmlspecialchars($customer['registration_date']) ?></td> <td> <!-- Προβολή, Επεξεργασία, Διαγραφή, Εκτύπωση --> <button class="btn btn-info btn-sm" data-toggle="modal" data-target="#viewCustomerModal<?= $customer['id'] ?>">Προβολή</button> <button class="btn btn-warning btn-sm" data-toggle="modal" data-target="#editCustomerModal<?= $customer['id'] ?>">Επεξεργασία</button> <button class="btn btn-danger btn-sm" data-toggle="modal" data-target="#deleteCustomerModal<?= $customer['id'] ?>">Διαγραφή</button> <button class="btn btn-secondary btn-sm" onclick="printCustomer(<?= $customer['id'] ?>)">Εκτύπωση</button> </td> </tr> <!-- Modal Προβολής Πελάτη --> <div class="modal fade" id="viewCustomerModal<?= $customer['id'] ?>" tabindex="-1" aria-labelledby="viewCustomerModalLabel<?= $customer['id'] ?>" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="viewCustomerModalLabel<?= $customer['id'] ?>">Προβολή Πελάτη</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <p><strong>Ονοματεπώνυμο:</strong> <?= htmlspecialchars($customer['full_name']) ?></p> <p><strong>Τηλέφωνο Σταθερό:</strong> <?= htmlspecialchars($customer['landline_phone']) ?></p> <p><strong>Αριθμός Κινητού:</strong> <?= htmlspecialchars($customer['cellphone_number']) ?></p> <p><strong>Ημερομηνία Εγγραφής:</strong> <?= htmlspecialchars($customer['registration_date']) ?></p> <h4>Συσκευές σε Κατοχή:</h4> <ul> <?php $customer_devices = fetchCustomerDevices($pdo, $customer['id']); foreach ($customer_devices as $device): ?> <li><?= htmlspecialchars($device['type']) ?> - <?= htmlspecialchars($device['brand']) ?> - <?= htmlspecialchars($device['model']) ?> (Σειριακός: <?= htmlspecialchars($device['serial_number']) ?>)</li> <?php endforeach; ?> </ul> </div> </div> </div> </div> <!-- Modal Επεξεργασίας Πελάτη --> <div class="modal fade" id="editCustomerModal<?= $customer['id'] ?>" tabindex="-1" aria-labelledby="editCustomerModalLabel<?= $customer['id'] ?>" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="editCustomerModalLabel<?= $customer['id'] ?>">Επεξεργασία Πελάτη</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <form action="customers.php" method="post"> <input type="hidden" name="action" value="edit_customer"> <input type="hidden" name="customer_id" value="<?= $customer['id'] ?>"> <div class="form-group"> <label for="full_name">Ονοματεπώνυμο</label> <input type="text" class="form-control" id="full_name" name="full_name" value="<?= htmlspecialchars($customer['full_name']) ?>" required> </div> <div class="form-row"> <div class="form-group col-md-6"> <label for="landline_phone">Τηλέφωνο Σταθερό</label> <input type="text" class="form-control" id="landline_phone" name="landline_phone" value="<?= htmlspecialchars($customer['landline_phone']) ?>"> </div> <div class="form-group col-md-6"> <label for="cellphone_number">Αριθμός Κινητού</label> <input type="text" class="form-control" id="cellphone_number" name="cellphone_number" value="<?= htmlspecialchars($customer['cellphone_number']) ?>"> </div> </div> <h3 class="mt-4">Συσκευές σε Κατοχή</h3> <div id="edit_device_list<?= $customer['id'] ?>"> <?php foreach ($customer_devices as $index => $device): ?> <div class="device-item d-flex align-items-end"> <div class="form-group mr-2"> <label for="device_id">Επιλογή Συσκευής</label> <select class="form-control device-select" id="device_id" name="devices[<?= $index ?>][device_id]" required onchange="toggleSerialInput(this)"> <option value="" disabled>Επιλέξτε συσκευή</option> <option value="none" <?= $device['device_id'] == 'none' ? 'selected' : '' ?>>Χωρίς συσκευή</option> <?php foreach ($devices as $d): ?> <option value="<?= $d['id'] ?>" <?= $d['id'] == $device['device_id'] ? 'selected' : '' ?>><?= $d['type'] ?> - <?= $d['brand'] ?> - <?= $d['model'] ?></option> <?php endforeach; ?> </select> </div> <div class="form-group"> <label for="serial_number">Σειριακός Αριθμός</label> <input type="text" class="form-control serial-number" id="serial_number" name="devices[<?= $index ?>][serial_number]" value="<?= htmlspecialchars($device['serial_number']) ?>" <?= $device['device_id'] == 'none' ? 'disabled' : '' ?>> </div> <button type="button" class="close-btn ml-2" onclick="removeDevice(this)">×</button> </div> <?php endforeach; ?> </div> <button type="button" class="btn btn-outline-danger mt-2" onclick="addDevice(<?= $customer['id'] ?>)">Προσθήκη Άλλης Συσκευής</button> <button type="submit" class="btn btn-outline-danger mt-2 ml-2">Αποθήκευση Αλλαγών</button> </form> </div> </div> </div> </div> <!-- Modal Διαγραφής Πελάτη --> <div class="modal fade" id="deleteCustomerModal<?= $customer['id'] ?>" tabindex="-1" aria-labelledby="deleteCustomerModalLabel<?= $customer['id'] ?>" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="deleteCustomerModalLabel<?= $customer['id'] ?>">Διαγραφή Πελάτη</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <p>Είστε σίγουροι ότι θέλετε να διαγράψετε τον πελάτη: <strong><?= htmlspecialchars($customer['full_name']) ?></strong>;</p> <form action="customers.php" method="post"> <input type="hidden" name="action" value="delete_customer"> <input type="hidden" name="customer_id" value="<?= $customer['id'] ?>"> <button type="submit" class="btn btn-danger">Διαγραφή</button> </form> </div> </div> </div> </div> <?php endforeach; ?> </tbody> </table> <?php else: ?> <p>Δεν βρέθηκαν πελάτες.</p> <?php endif; ?> </div> </div> <div class="footer"> <p>© 2024 Digihack. Όλα τα δικαιώματα διατηρούνται. από <a href="https://skypulse.uk" target="_blank">skypulse.uk</a></p> </div> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script> <script> $(document).ready(function() { $('.device-select').select2({ placeholder: 'Επιλέξτε συσκευή ή πληκτρολογήστε για αναζήτηση', allowClear: true }); $('.modal').on('shown.bs.modal', function () { $(this).find('.device-select').select2({ placeholder: 'Επιλέξτε συσκευή ή πληκτρολογήστε για αναζήτηση', allowClear: true }); }); }); function addDevice(customerId) { let index = document.querySelectorAll('#edit_device_list' + customerId + ' .device-item').length; let newDevice = ` <div class="device-item d-flex align-items-end"> <div class="form-group mr-2"> <label for="device_id">Επιλογή Συσκευής</label> <select class="form-control device-select" id="device_id" name="devices[${index}][device_id]" required onchange="toggleSerialInput(this)"> <option value="" selected disabled>Επιλέξτε συσκευή</option> <option value="none">Χωρίς συσκευή</option> <?php foreach ($devices as $device): ?> <option value="<?= $device['id'] ?>"><?= $device['type'] ?> - <?= $device['brand'] ?> - <?= $device['model'] ?></option> <?php endforeach; ?> </select> </div> <div class="form-group"> <label for="serial_number">Σειριακός Αριθμός</label> <input type="text" class="form-control serial-number" id="serial_number" name="devices[${index}][serial_number]" required> </div> <button type="button" class="close-btn ml-2" onclick="removeDevice(this)">×</button> </div>`; document.getElementById('edit_device_list' + customerId).insertAdjacentHTML('beforeend', newDevice); $('.device-select').select2({ placeholder: 'Επιλέξτε συσκευή ή πληκτρολογήστε για αναζήτηση', allowClear: true }); } document.getElementById('add_device').addEventListener('click', function() { let index = document.querySelectorAll('#device_list .device-item').length; let newDevice = ` <div class="device-item d-flex align-items-end"> <div class="form-group mr-2"> <label for="device_id">Επιλογή Συσκευής</label> <select class="form-control device-select" id="device_id" name="devices[${index}][device_id]" required onchange="toggleSerialInput(this)"> <option value="" selected disabled>Επιλέξτε συσκευή</option> <option value="none">Χωρίς συσκευή</option> <?php foreach ($devices as $device): ?> <option value="<?= $device['id'] ?>"><?= $device['type'] ?> - <?= $device['brand'] ?> - <?= $device['model'] ?></option> <?php endforeach; ?> </select> </div> <div class="form-group"> <label for="serial_number">Σειριακός Αριθμός</label> <input type="text" class="form-control serial-number" id="serial_number" name="devices[${index}][serial_number]" required> </div> <button type="button" class="close-btn ml-2" onclick="removeDevice(this)">×</button> </div>`; document.getElementById('device_list').insertAdjacentHTML('beforeend', newDevice); $('.device-select').select2({ placeholder: 'Επιλέξτε συσκευή ή πληκτρολογήστε για αναζήτηση', allowClear: true }); }); function toggleSerialInput(selectElement) { const serialInput = selectElement.closest('.device-item').querySelector('.serial-number'); if (selectElement.value === 'none') { serialInput.value = ''; serialInput.disabled = true; } else { serialInput.disabled = false; } } function removeDevice(button) { button.closest('.device-item').remove(); } document.getElementById('customerSearch').addEventListener('input', function() { let filter = this.value.toLowerCase(); document.querySelectorAll('#customerTable tr').forEach(row => { let text = row.textContent.toLowerCase(); row.style.display = text.includes(filter) ? '' : 'none'; }); }); function printCustomer(customerId) { window.open('generate_customer_pdf.php?id=' + customerId, '_blank'); } </script> - Assistant
- User
provide the complete fixed code
- Assistant
- User
- Assistant
- User
issue still persists
- Assistant