From 0c52a01e4ac4334a614da358b8fb1b479db481a4 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Tue, 21 Nov 2017 09:03:31 -0500 Subject: [PATCH] Search by telephone. --- lib/contact.php | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/lib/contact.php b/lib/contact.php index ee9f3e0..971a9c2 100644 --- a/lib/contact.php +++ b/lib/contact.php @@ -30,7 +30,7 @@ } } else if ($_POST['search_contact']) { - header(sprintf("Location: http%s://%s/%s/search/%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($_POST['search_contact']))); + header(sprintf("Location: http%s://%s/%s/search/%s%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, $_POST['search_by_phone'] ? "phone/" : "", urlencode($_POST['search_contact']))); exit; } else if ($_POST['show_in_area']) { @@ -82,11 +82,13 @@ else echo " none"; } - function search_contacts($search) { + function search_contacts($search, $phone = false) { list($first_page, $per_page) = pagination(); $q = new ContactQuery; - $contacts = $q->filterByDisplayname("%$search%")->orderByForename()->orderBySurname()->orderById('desc')->paginate($first_page, $per_page); - echo "

Contacts matching '" . htmlspecialchars($search) . "':"; + if ($phone) $q->filterByTelephone1("%$search%")->_or()->filterByTelephone2("%$search%"); + else $q->filterByDisplayname("%$search%"); + $contacts = $q->orderByForename()->orderBySurname()->orderById('desc')->paginate($first_page, $per_page); + echo "

Contacts matching " . ($phone ? "telephone " : "") . "'" . htmlspecialchars($search) . "':"; if (count($contacts)) { foreach ($contacts as $contact) show_contact_summary($contact); show_pagination($contacts); @@ -95,19 +97,21 @@ echo "

\n"; $address_ids = array(); - $q = new AddressQuery; - $addresses = $q->filterByLine("%$search%")->find(); - foreach ($addresses as $address) $address_ids[] = $address->getId(); - $q = new AddressQuery; - $addresses = $q->filterByPostcode("%$search%")->find(); - foreach ($addresses as $address) $address_ids[] = $address->getId(); + if (! $phone) { + $q = new AddressQuery; + $addresses = $q->filterByLine("%$search%")->find(); + foreach ($addresses as $address) $address_ids[] = $address->getId(); + $q = new AddressQuery; + $addresses = $q->filterByPostcode("%$search%")->find(); + foreach ($addresses as $address) $address_ids[] = $address->getId(); - $q = new ContactQuery; - $contacts = $q->filterByAddressId($address_ids)->orderByForename()->orderBySurname()->orderById('desc')->paginate($first_page, $per_page); - echo "

Contacts in address '" . htmlspecialchars($search) . "':"; - if (count($contacts)) { - foreach ($contacts as $contact) show_contact_summary($contact); - show_pagination($contacts); + $q = new ContactQuery; + $contacts = $q->filterByAddressId($address_ids)->orderByForename()->orderBySurname()->orderById('desc')->paginate($first_page, $per_page); + echo "

Contacts in address '" . htmlspecialchars($search) . "':"; + if (count($contacts)) { + foreach ($contacts as $contact) show_contact_summary($contact); + show_pagination($contacts); + } } else echo "none"; echo "

\n"; @@ -199,7 +203,10 @@ function show_contact_search_form() { echo "

Search for contacts:"; input("search_contact"); + echo ""; + echo "\n"; echo "\n"; + echo "

\n"; } function show_contact_forms($city_id) { @@ -598,7 +605,8 @@ } } else if ($parameters[0] == "search") { - search_contacts(urldecode($parameters[1])); + if ($parameters[1] == "phone") search_contacts(urldecode($parameters[2]), true); + else search_contacts(urldecode($parameters[1])); } } list($name, $id, $args) = parse_parameters($parameters); -- 2.20.1