6 |
6 |
7 const FILE = "var/abook.txt"; |
7 const FILE = "var/abook.txt"; |
8 |
8 |
9 if (isset($_REQUEST['action'])) { |
9 if (isset($_REQUEST['action'])) { |
10 require 'addressbook.class.php'; |
10 require 'addressbook.class.php'; |
11 $abook = new Address_Book_File(FILE); |
|
12 |
11 |
13 switch (@$_REQUEST['action']) { |
12 try { |
14 // Nach dem Eintragen bleiben wir auf der Eintragsseite, |
13 $abook = new Address_Book_File(FILE); |
15 // aber wir verhindern Duplikate, die mit RELOAD passieren |
|
16 case 'add': if ($abook->add_entry($_REQUEST)) { |
|
17 header("Location: $_SERVER[PHP_SELF]?action=add"); |
|
18 exit(0); |
|
19 } |
|
20 echo $twig->render("add.html", array()); |
|
21 exit; |
|
22 break; |
|
23 |
14 |
24 // Suchen… |
15 switch (@$_REQUEST['action']) { |
25 case 'search': $entries = $abook->search_entries($_REQUEST['pattern']); |
16 // Nach dem Eintragen bleiben wir auf der Eintragsseite, |
26 if (@$_REQUEST['format'] == 'table') { |
17 // aber wir verhindern Duplikate, die mit RELOAD passieren |
27 if (is_numeric($_REQUEST['max'])) { |
18 case 'add': if ($abook->add_entry($_REQUEST)) { |
28 $left = count($entries) - $_REQUEST['max']; |
19 header("Location: $_SERVER[PHP_SELF]?action=add"); |
29 if ($left > 0) |
20 exit(0); |
30 $entries = array_slice($entries, 0, $_REQUEST['max']); |
|
31 else |
|
32 $left = NULL; |
|
33 } |
|
34 echo $twig->render("results.html", |
|
35 array('entries' => $entries, 'left' => $left)); |
|
36 exit; |
|
37 } |
21 } |
38 echo $twig->render("search.html", array('entries' => $entries)); |
22 echo $twig->render("add.html", array()); |
39 exit; |
23 exit; |
40 break; |
24 break; |
|
25 |
|
26 // Suchen… |
|
27 case 'search': $entries = $abook->search_entries($_REQUEST['pattern']); |
|
28 if (@$_REQUEST['format'] == 'table') { |
|
29 if (is_numeric($_REQUEST['max'])) { |
|
30 $left = count($entries) - $_REQUEST['max']; |
|
31 if ($left > 0) |
|
32 $entries = array_slice($entries, 0, $_REQUEST['max']); |
|
33 else |
|
34 $left = NULL; |
|
35 } |
|
36 echo $twig->render("results.html", |
|
37 array('entries' => $entries, 'left' => $left)); |
|
38 exit; |
|
39 } |
|
40 echo $twig->render("search.html", array('entries' => $entries)); |
|
41 exit; |
|
42 break; |
|
43 } |
|
44 |
|
45 } |
|
46 catch (Address_Book_Exception $e) { |
|
47 header("Content-Type: text/plain; charset=utf-8"); |
|
48 print "Address Book Exception: " . $e->getMessage(); |
|
49 exit; |
|
50 } |
|
51 catch (Exception $e) { |
|
52 header("Content-Type: text/plain; charset=utf-8"); |
|
53 print "Ohoh\n\n" .$e->getMessage(); |
|
54 exit; |
41 } |
55 } |
42 } |
56 } |
43 |
57 |
44 echo $twig->render("search.html", array()); |
58 echo $twig->render("search.html", array()); |
45 |
59 |