📁 Folder Navigator
Position:
Root
/
apphome
/
admin
/
contacts
/
orders
Create
Folders
No folders here.
Files
📄 adminlist.php
📄 index.php
📄 list.php
📄 listdata.json
📝 File Editor
Editing:
adminlist.php
<?php $dataFile = 'listdata.json'; // Initialize data file if it doesn't exist if (!file_exists($dataFile)) { file_put_contents($dataFile, json_encode([])); } // Helper functions function getContacts($dataFile) { return json_decode(file_get_contents($dataFile), true) ?: []; } function saveContacts($dataFile, $contacts) { file_put_contents($dataFile, json_encode($contacts, JSON_PRETTY_PRINT)); } // Create & Update Logic if ($_SERVER['REQUEST_METHOD'] === 'POST') { $contacts = getContacts($dataFile); if (isset($_POST['action']) && $_POST['action'] === 'save') { $newContact = [ 'id' => empty($_POST['id']) ? time() : intval($_POST['id']), 'name' => htmlspecialchars($_POST['name']), 'email' => htmlspecialchars($_POST['email']), 'phone' => htmlspecialchars($_POST['phone']) ]; if (empty($_POST['id'])) { $contacts[] = $newContact; // Create } else { foreach ($contacts as &$c) { // Update if ($c['id'] == $_POST['id']) { $c = $newContact; break; } } } saveContacts($dataFile, $contacts); header('Location: list.php'); exit; } } // Delete Logic if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) { $contacts = getContacts($dataFile); $contacts = array_filter($contacts, fn($c) => $c['id'] != $_GET['id']); saveContacts($dataFile, array_values($contacts)); header('Location: list.php'); exit; } // Read & Search Logic $contacts = getContacts($dataFile); $searchQuery = ''; if (isset($_GET['search'])) { $searchQuery = strtolower(trim($_GET['search'])); $contacts = array_filter($contacts, fn($c) => strpos(strtolower($c['name']), $searchQuery) !== false || strpos(strtolower($c['email']), $searchQuery) !== false || strpos(strtolower($c['phone']), $searchQuery) !== false ); } // Edit Contact Pre-population $editContact = null; if (isset($_GET['action']) && $_GET['action'] === 'edit' && isset($_GET['id'])) { $allContacts = getContacts($dataFile); foreach ($allContacts as $c) { if ($c['id'] == $_GET['id']) { $editContact = $c; break; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ORDERS AND INVITES</title> <link href="https://jsdelivr.net" rel="stylesheet"> </head> <body class="bg-light mt-5"> <div class="container"> <h1 class="mb-4 text-center">ORDERS & INVITES MANAGER</h1> <div class="row"> <!-- Form --> <div class="col-md-4 mb-4"> <div class="card"> <div class="card-header"> <?= $editContact ? 'Edit Contact' : 'Add Contact' ?> </div> <div class="card-body"> <form method="POST" action=""> <input type="hidden" name="action" value="save"> <input type="hidden" name="id" value="<?= $editContact['id'] ?? '' ?>"> <div class="mb-3"> <label class="form-label">Name</label> <input type="text" name="name" class="form-control" value="<?= $editContact['name'] ?? '' ?>" required> </div> <div class="mb-3"> <label class="form-label">Email</label> <input type="email" name="email" class="form-control" value="<?= $editContact['email'] ?? '' ?>" required> </div> <div class="mb-3"> <label class="form-label">Phone</label> <input type="text" name="phone" class="form-control" value="<?= $editContact['phone'] ?? '' ?>" required> </div> <button type="submit" class="btn btn-primary w-100"><?= $editContact ? 'Update' : 'Save' ?></button> <?php if ($editContact): ?> <a href="list.php" class="btn btn-secondary w-100 mt-2">Cancel Edit</a> <?php endif; ?> </form> </div> </div> </div> <!-- Listing and Searching --> <div class="col-md-8"> <!-- Search Bar --> <form method="GET" action="" class="mb-3 d-flex"> <input type="text" name="search" class="form-control me-2" placeholder="Search by name, email, or phone..." value="<?= htmlspecialchars($_GET['search'] ?? '') ?>"> <button type="submit" class="btn btn-outline-secondary">Search</button> <?php if (!empty($_GET['search'])): ?> <a href="list.php" class="btn btn-outline-danger ms-2">Reset</a> <?php endif; ?> </form> <!-- Data Table --> <div class="card"> <div class="card-body p-0"> <table class="table table-striped mb-0"> <thead> <tr> <th>Name</th> <th>Email</th> <th>Phone</th> <th class="text-center">Actions</th> </tr> </thead> <tbody> <?php if (empty($contacts)): ?> <tr> <td colspan="4" class="text-center">No contacts found.</td> </tr> <?php else: ?> <?php foreach ($contacts as $contact): ?> <tr> <td><?= $contact['name'] ?></td> <td><?= $contact['email'] ?></td> <td><?= $contact['phone'] ?></td> <td class="text-center"> <a href="?action=edit&id=<?= $contact['id'] ?>" class="btn btn-sm btn-warning">Edit</a> <a href="?action=delete&id=<?= $contact['id'] ?>" class="btn btn-sm btn-danger" onclick="return confirm('Delete this contact?')">Delete</a> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> </div> </div> </div> </div> </body> </html>
💾 Save Changes