. */ require_once(__DIR__ . '/../index.php'); require_once(__DIR__ . '/../login.php'); require(__DIR__ . '/../header.php'); ?>
View information of the contact with id // ?delete= Delete the contact with id //------------------------------------------------------------------------------ // The header of the page $header = 'Contacts'; // Whether or not to show an individual contact in the end (false if not, or the id if yes) $show_individual = false; // View contact if (isset($_GET['id'])) { $id = (int) $_GET['id']; try { $contact = new Contact($_pdo, $id); $header = "Contacts / {$contact->name}"; $show_individual = $id; } catch (PDOException $e) { $alert = "
The contact with id $id could not be found.
"; } catch (Exception $e) { $alert = "
The contact with id $id could not be found.
"; } } // Show the header echo "

$header

"; if (isset($alert)) echo "
$alert
"; // Delete contact if (isset($_GET['delete'])) { echo "
"; $id = (int) $_GET['delete']; try { $contact = new Contact($_pdo, $id); if ($contact->delete()) { echo "
The contact with name {$contact->name} has been removed.
"; } else { echo "
The contact with name {$contact->name} could not be removed. Perhaps it's already removed?
"; } } catch (PDOException $e) { echo "
The contact could not be removed due to a PDO error.
"; } catch (Exception $e) { echo "
The contact with id {$id} could not be found.
"; } echo "
"; } if ($show_individual !== false) { $_id = $show_individual; require('contacts-view.php'); } else { require('contacts-overview.php'); } ?>