# HG changeset patch # User Heiko Schlittermann (IT Trainingshaus) # Date 1319632550 -7200 # Node ID 2a05edf9dc87f0b3c303ba0ab6cad10b03414732 # Parent c734249d905021adf688077ead22a082d2762a7e OOP diff -r c734249d9050 -r 2a05edf9dc87 index.php --- a/index.php Wed Oct 26 10:30:00 2011 +0200 +++ b/index.php Wed Oct 26 14:35:50 2011 +0200 @@ -1,79 +1,37 @@ add_entry($_REQUEST); + break; + case 'search': $entries = $abook->search_entries($_REQUEST['pattern']); + break; } - flock($fh, LOCK_EX); - fputs($fh, join(FS, $new) . RS); - flock($fh, LOCK_UN); - header("Location: $_SERVER[PHP_SELF]?action=add"); +} +catch (ErrorException $e) { + print "INTERNAL ERROR: " . $e->getMessage(); +} +catch (Exception $e) { + print "Application error: " . $e->getMessage(); exit; } -function search_entries($fh, $pattern) { - fseek($fh, 0, SEEK_SET); - $entries = array(); - while ($line = stream_get_line($fh, 0, RS)) { - if ($line === FALSE) break; - if (!preg_match("/$pattern/i", $line)) continue; - $entry = explode(FS, $line); - $entries[] = array('name' => $entry[0], - 'tel' => $entry[1], - 'mail' => $entry[2]); - } - return $entries; -} - - -$abook = open_db(FILE); - -switch ($_REQUEST['action']) { - case 'add': add_entry($abook, $_REQUEST); - break; - case 'search': $entries = search_entries($abook, $_REQUEST['pattern']); - break; -} - - ?> @@ -84,7 +42,7 @@ - + [ Home ] [ Add Entries ] @@ -92,7 +50,7 @@

Adressbuch

- +

@@ -113,7 +71,7 @@
- +
NameTelefonMail