Browse Source

Closes #69 adding word search capability for transaction_log.

devel
Jonathan Rosenbaum 7 years ago
parent
commit
d0828bc80b
  1. 22
      Connections/database_functions.php
  2. 37
      transaction_log.php

22
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_EDIT_LOCATION", "/location_add_edit.php");
define("PAGE_SELECT_LOCATION", "/location_add_edit_select.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 = "<span style='color:black; background:#ffeb3bc7; box-shadow:2px 0 #ffeb3bc7, -2px 0 0 #ffeb3bc7; padding: 0px 0;'>$wordsAry[$i]</span>";
$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 //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) function generate_list($querySQL,$list_value,$list_text, $form_name, $default_value, $color)
{ {

37
transaction_log.php

@ -89,6 +89,19 @@ if($_GET['contact_id_search']=='everyone'){
$contact_id_state = '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) //record_count (SQL or state)
if($_GET['record_count']>0){ if($_GET['record_count']>0){
$record_count = $_GET['record_count']; $record_count = $_GET['record_count'];
@ -99,6 +112,7 @@ if($_GET['record_count']>0){
// create a string to remember state // create a string to remember state
$search_state_array = array( $search_state_array = array(
"search" => $search_state,
"contact_id_search" => $contact_id_state, "contact_id_search" => $contact_id_state,
"trans_date" => $trans_date_state, "trans_date" => $trans_date_state,
"trans_type" => $trans_type_state, "trans_type" => $trans_type_state,
@ -132,7 +146,7 @@ LEFT(IF(show_startdate, CONCAT(' [',
FROM transaction_log FROM transaction_log
LEFT JOIN contacts ON transaction_log.sold_to=contacts.contact_id 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 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()); $Recordset1 = mysql_query($query_Recordset1, $YBDB) or die(mysql_error());
$totalRows_Recordset1 = mysql_num_rows($Recordset1); $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 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")) { 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 header(sprintf("Location: %s",$editFormAction )); //$editFormAction
} }
@ -702,8 +716,17 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ChangeDate")) {
$row_Recordset1['full_name'] . "</a>"; $row_Recordset1['full_name'] . "</a>";
} }
?>&nbsp;</td> ?>&nbsp;</td>
<?php
// Highlight search results in Description
$description = $row_Recordset1['description_with_locations'];
if(!empty($_GET["search"])) {
$description = highlightKeywords($row_Recordset1['description_with_locations'],$_GET["search"]);
}
?>
<td <?php echo "title='Description: " . htmlspecialchars($row_Recordset1['description_with_locations'], ENT_QUOTES) . "'"; ?> ><?php echo $row_Recordset1['description_with_locations']; ?>&nbsp;</td> <td <?php echo "title='Description: " . htmlspecialchars($row_Recordset1['description_with_locations'], ENT_QUOTES) . "'"; ?> ><?php echo $description; ?>&nbsp;</td>
<td><?php echo $row_Recordset1['payment_type']; ?>&nbsp;</td> <td><?php echo $row_Recordset1['payment_type']; ?>&nbsp;</td>
<td <?php <td <?php
$history = json_decode($row_Recordset1['history']); $history = json_decode($row_Recordset1['history']);
@ -860,9 +883,11 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ChangeDate")) {
<option value="Sunday">Sunday</option> <option value="Sunday">Sunday</option>
</select> </select>
transaction type <?php list_transaction_types_withheader('trans_type', 'all_types'); ?> by transaction type <?php list_transaction_types_withheader('trans_type', 'all_types'); ?> by
<?php list_contacts_select_contact(contact_id_search, $_GET['contact_id_search']);?> <br \> with these words
<?php list_contacts_select_contact(contact_id_search, $_GET['contact_id_search']);?> <input type="text" name="search" value="<?php echo $_GET[search]; ?>" />
<input type="submit" name="Submit" value="Submit" /> <input type="submit" name="Submit" value="Submit" />

Loading…
Cancel
Save