From a5f369fe00077f8941cbf4e75ba9f6337614e191 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 23 Jun 2018 14:19:47 -0600 Subject: [PATCH] Add date search ability to action.php transactionsearch --- action.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/action.php b/action.php index 79477d5..9aca2b9 100644 --- a/action.php +++ b/action.php @@ -328,16 +328,25 @@ switch ($VARS['action']) { break; case "transactionsearch": header("Content-Type: application/json"); - if (!is_empty($VARS['q'])) { + $where = []; + if (!empty($VARS['q'])) { $where["AND"]["OR"] = [ "txid" => $VARS['q'], "name[~]" => $VARS['q'], "email[~]" => $VARS['q'], "phone[~]" => $VARS['q'] ]; - } else { - exit(json_encode(["status" => "ERROR", "transactions" => false])); } + $start = date('Y-m-d H:i:s', 946684800); // Jan 1 2000 + $end = date('Y-m-d H:i:s'); + if (!empty($VARS['start']) && strtotime($VARS['start']) !== FALSE) { + $start = date('Y-m-d H:i:s', strtotime($VARS['start'])); + } + if (!empty($VARS['end']) && strtotime($VARS['end']) !== FALSE) { + $end = date('Y-m-d H:i:s', strtotime($VARS['end'])); + } + $where["AND"]['txdate[>=]'] = $start; + $where["AND"]['txdate[<=]'] = $end; $where["LIMIT"] = 50; $transactions = $database->select('transactions', [