--- a/index.php Wed Oct 26 00:15:59 2011 +0200
+++ b/index.php Wed Oct 26 00:37:13 2011 +0200
@@ -8,36 +8,50 @@
if (isset($_REQUEST['action'])) {
require 'addressbook.class.php';
- $abook = new Address_Book_File(FILE);
- switch (@$_REQUEST['action']) {
- // Nach dem Eintragen bleiben wir auf der Eintragsseite,
- // aber wir verhindern Duplikate, die mit RELOAD passieren
- case 'add': if ($abook->add_entry($_REQUEST)) {
- header("Location: $_SERVER[PHP_SELF]?action=add");
- exit(0);
- }
- echo $twig->render("add.html", array());
- exit;
- break;
+ try {
+ $abook = new Address_Book_File(FILE);
- // Suchen…
- case 'search': $entries = $abook->search_entries($_REQUEST['pattern']);
- if (@$_REQUEST['format'] == 'table') {
- if (is_numeric($_REQUEST['max'])) {
- $left = count($entries) - $_REQUEST['max'];
- if ($left > 0)
- $entries = array_slice($entries, 0, $_REQUEST['max']);
- else
- $left = NULL;
- }
- echo $twig->render("results.html",
- array('entries' => $entries, 'left' => $left));
- exit;
+ switch (@$_REQUEST['action']) {
+ // Nach dem Eintragen bleiben wir auf der Eintragsseite,
+ // aber wir verhindern Duplikate, die mit RELOAD passieren
+ case 'add': if ($abook->add_entry($_REQUEST)) {
+ header("Location: $_SERVER[PHP_SELF]?action=add");
+ exit(0);
}
- echo $twig->render("search.html", array('entries' => $entries));
+ echo $twig->render("add.html", array());
exit;
break;
+
+ // Suchen…
+ case 'search': $entries = $abook->search_entries($_REQUEST['pattern']);
+ if (@$_REQUEST['format'] == 'table') {
+ if (is_numeric($_REQUEST['max'])) {
+ $left = count($entries) - $_REQUEST['max'];
+ if ($left > 0)
+ $entries = array_slice($entries, 0, $_REQUEST['max']);
+ else
+ $left = NULL;
+ }
+ echo $twig->render("results.html",
+ array('entries' => $entries, 'left' => $left));
+ exit;
+ }
+ echo $twig->render("search.html", array('entries' => $entries));
+ exit;
+ break;
+ }
+
+ }
+ catch (Address_Book_Exception $e) {
+ header("Content-Type: text/plain; charset=utf-8");
+ print "Address Book Exception: " . $e->getMessage();
+ exit;
+ }
+ catch (Exception $e) {
+ header("Content-Type: text/plain; charset=utf-8");
+ print "Ohoh\n\n" .$e->getMessage();
+ exit;
}
}