3 require_once 'Twig-1.3.0/lib/Twig/Autoloader.php'; |
3 require_once 'Twig-1.3.0/lib/Twig/Autoloader.php'; |
4 Twig_Autoloader::register(); |
4 Twig_Autoloader::register(); |
5 $twig = new Twig_Environment(new Twig_Loader_Filesystem("templates")); |
5 $twig = new Twig_Environment(new Twig_Loader_Filesystem("templates")); |
6 |
6 |
7 const FILE = "var/abook.txt"; |
7 const FILE = "var/abook.txt"; |
|
8 |
|
9 // stop on any error! |
|
10 set_error_handler(create_function('$a, $b, $c, $d', |
|
11 'if (error_reporting()) throw new ErrorException($b, 0, $a, $c, $d);'), -1); |
8 |
12 |
9 if (isset($_REQUEST['action'])) { |
13 if (isset($_REQUEST['action'])) { |
10 require 'addressbook.class.php'; |
14 require 'addressbook.class.php'; |
11 |
15 |
12 try { |
16 try { |
22 echo $twig->render("add.html", array()); |
26 echo $twig->render("add.html", array()); |
23 exit; |
27 exit; |
24 break; |
28 break; |
25 |
29 |
26 // Suchen… |
30 // Suchen… |
27 case 'search': $entries = $abook->search_entries($_REQUEST['pattern']); |
31 case 'search': $entries = null; |
|
32 $error = null; |
|
33 try { |
|
34 $entries = $abook->search_entries($_REQUEST['pattern']); |
|
35 } |
|
36 catch (Address_Book_Exception $e) { |
|
37 $error = $e->getMessage(); |
|
38 } |
|
39 |
28 if (@$_REQUEST['format'] == 'table') { |
40 if (@$_REQUEST['format'] == 'table') { |
29 if (is_numeric($_REQUEST['max'])) { |
41 if (is_numeric($_REQUEST['max'])) { |
30 $left = count($entries) - $_REQUEST['max']; |
42 $left = count($entries) - $_REQUEST['max']; |
31 if ($left > 0) |
43 if ($left > 0) |
32 $entries = array_slice($entries, 0, $_REQUEST['max']); |
44 $entries = array_slice($entries, 0, $_REQUEST['max']); |
33 else |
45 else |
34 $left = NULL; |
46 $left = NULL; |
35 } |
47 } |
36 echo $twig->render("results.html", |
48 echo $twig->render("results.html", |
37 array('entries' => $entries, 'left' => $left)); |
49 array('entries' => $entries, |
|
50 'left' => $left, 'error' => $error)); |
38 exit; |
51 exit; |
39 } |
52 } |
40 echo $twig->render("search.html", array('entries' => $entries)); |
53 echo $twig->render("search.html", |
|
54 array('entries' => $entries, 'error' => $error)); |
41 exit; |
55 exit; |
42 break; |
56 } |
43 } |
57 break; |
44 |
58 |
45 } |
59 } |
46 catch (Address_Book_Exception $e) { |
60 catch (Address_Book_Exception $e) { |
47 header("Content-Type: text/plain; charset=utf-8"); |
61 header("Content-Type: text/plain; charset=utf-8"); |
48 print "Address Book Exception: " . $e->getMessage(); |
62 print "Address Book Exception: " . $e->getMessage(); |
49 exit; |
63 exit; |
50 } |
64 } |
51 catch (Exception $e) { |
65 catch (Exception $e) { |
52 header("Content-Type: text/plain; charset=utf-8"); |
66 header("Content-Type: text/plain; charset=utf-8"); |
53 print "Ohoh\n\n" .$e->getMessage(); |
67 print "Ohoh\n\n" . $e; |
54 exit; |
68 exit; |
55 } |
69 } |
56 } |
70 } |
57 |
71 |
58 echo $twig->render("search.html", array()); |
72 echo $twig->render("search.html", array()); |