diff --git a/Connections/database_functions.php b/Connections/database_functions.php index e30ee0d..02823cb 100644 --- a/Connections/database_functions.php +++ b/Connections/database_functions.php @@ -324,6 +324,28 @@ define("PAGE_SALE_LOG", "/transaction_log.php"); define("PAGE_EDIT_LOCATION", "/location_add_edit.php"); define("PAGE_SELECT_LOCATION", "/location_add_edit_select.php"); +// Highlight search results in transaction_log +function highlightKeywords($text, $keyword) { + + $wordsAry = explode(" ", $keyword); + $wordsCount = count($wordsAry); + + // Using REGEXP so remove regex from search + $find = array('/\*/', '/\./', '/\$/', '/\^/', '/\?/', '/\+/', '/\[/', '/\]/', '/\|/', '/\(/', '/\)/', '/\,/', '/\{/', '/\}/', '/\:/', '/\\\/'); + $replace = array('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); + + for($i=0;$i<$wordsCount;$i++) { + + $wordsAry[$i] = preg_replace($find, $replace, $wordsAry[$i]); + $highlighted_text = "$wordsAry[$i]"; + $text = str_ireplace($wordsAry[$i], $highlighted_text, $text); + //$text = str_replace($wordsAry[$i], $highlighted_text, $text); + + } + + return $text; +} + //This is a general function to generate the contents of a list box based on a MySQL query. All necessary parameters for the query are passed function generate_list($querySQL,$list_value,$list_text, $form_name, $default_value, $color) { diff --git a/transaction_log.php b/transaction_log.php index 279f7e0..68a02c7 100644 --- a/transaction_log.php +++ b/transaction_log.php @@ -89,6 +89,19 @@ if($_GET['contact_id_search']=='everyone'){ $contact_id_state = 'everyone'; } +if($_GET['search']==''){ + $search = ''; + $search_state = ''; +} elseif(isset($_GET['search'])) { + $search = "AND description REGEXP" . "'" . $_GET['search'] . "'"; + //$search = "AND description LIKE" . "'%" . $_GET['search'] . "%'"; + $search_state = $_GET['search']; +} else { + $search = ''; + $search_state = ''; +} + + //record_count (SQL or state) if($_GET['record_count']>0){ $record_count = $_GET['record_count']; @@ -99,6 +112,7 @@ if($_GET['record_count']>0){ // create a string to remember state $search_state_array = array( + "search" => $search_state, "contact_id_search" => $contact_id_state, "trans_date" => $trans_date_state, "trans_type" => $trans_type_state, @@ -132,7 +146,7 @@ LEFT(IF(show_startdate, CONCAT(' [', FROM transaction_log LEFT JOIN contacts ON transaction_log.sold_to=contacts.contact_id LEFT JOIN transaction_types ON transaction_log.transaction_type=transaction_types.transaction_type_id -WHERE 1=1 {$trans_date} {$shop_dayname} {$trans_type} {$contact_id} ORDER BY transaction_id DESC LIMIT 0, $record_count;"; +WHERE 1=1 {$trans_date} {$shop_dayname} {$trans_type} {$contact_id} {$search} ORDER BY transaction_id DESC LIMIT 0, $record_count;"; $Recordset1 = mysql_query($query_Recordset1, $YBDB) or die(mysql_error()); $totalRows_Recordset1 = mysql_num_rows($Recordset1); @@ -330,9 +344,9 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ConfirmDelete") && header(sprintf("Location: %s", PAGE_SALE_LOG . "?trans_id={$delete_trans_id}&" . $search_state )); //$editFormAction } -//Change Date & Search isset($_POST["MM_update"]) ========================================================= +//Change Date & Transaction Search isset($_POST["MM_update"]) ========================================================= if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ChangeDate")) { - $editFormAction = "?trans_date={$_POST['trans_date']}&trans_type={$_POST['trans_type']}&shop_dayname={$_POST['dayname']}&record_count={$_POST['record_count']}&contact_id_search={$_POST['contact_id_search']}"; + $editFormAction = "?trans_date={$_POST['trans_date']}&trans_type={$_POST['trans_type']}&shop_dayname={$_POST['dayname']}&record_count={$_POST['record_count']}&contact_id_search={$_POST['contact_id_search']}&search={$_POST['search']}"; header(sprintf("Location: %s",$editFormAction )); //$editFormAction } @@ -702,8 +716,17 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ChangeDate")) { $row_Recordset1['full_name'] . ""; } ?>  + + - >  + >    Sunday - transaction type by + transaction type by + +
with these words - +