function preprocess() { // set variable ahead of time // so we know if lookup found no one // vs. lookup didn't happen $this->temp_num_rows = -1; $entered = ""; if (isset($_REQUEST['idSearch']) && strlen($_REQUEST['idSearch']) > 0) { $entered = $_REQUEST['idSearch']; } elseif (isset($_REQUEST['search'])) { $entered = strtoupper(trim($_REQUEST["search"])); $entered = str_replace("'", "''", $entered); } else { return True; } if (substr($entered, -2) == "ID") { $entered = substr($entered, 0, strlen($entered) - 2); } $personNum = 1; $selected_name = False; // Values of memlist items are "CardNo::personNum" if (strstr($entered, "::") !== False) { $tmp = explode("::", $entered); $entered = $tmp[0]; $personNum = $tmp[1]; $selected_name = True; } // No input available, stop if (!$entered || strlen($entered) < 1 || $entered == "CL") { $this->change_page($this->page_url . "gui-modules/memlist_cards.php"); return False; } $memberID = $entered; $db_a = Database::pDataConnect(); if (!is_numeric($entered)) { $query = "select CardNo,personNum,LastName,FirstName from custdata \n where LastName like '" . $entered . "%' order by LastName, FirstName"; } else { $query = "select CardNo,personNum,LastName,FirstName,CashBack,Balance,Discount,\n ChargeOk,WriteChecks,StoreCoupons,Type,memType,staff,\n SSI,Purchases,NumberOfChecks,memCoupons,blueLine,Shown,id from custdata \n where CardNo = '" . $entered . "' order by personNum"; } $result = $db_a->query($query); $num_rows = $db_a->num_rows($result); // if theres only 1 match don't show the memlist if ($num_rows == 1) { $selected_name = True; $personNum = 1; } // if there's one result and either // a. it's the default nonmember account or // b. it's been confirmed in the select box // then set the member number // proceed/return to the appropriate next page if ($num_rows == 1 && $entered == CoreLocal::get("defaultNonMem") || is_numeric($entered) && is_numeric($personNum) && $selected_name) { $row = $db_a->fetch_array($result); // Don't want to affect the current trans. Will it still work? // PrehLib::setMember($row["CardNo"], $personNum); // WEFC_Toronto: If a Member Card # was entered when the choice from the list was made, // add the memberCards record. if (CoreLocal::get('store') == "WEFC_Toronto") { $mmsg = ""; if (isset($_REQUEST['memberCard']) && $_REQUEST['memberCard'] != "") { $memberCard = $_REQUEST['memberCard']; $upc = sprintf("00401229%05d", $memberCard); $card_no = $row['CardNo']; // Get the Member Card # from CiviCRM. // By looking up card_no in Civi members to get the contact id and use contact_id to get mcard. // Can't do that because MySQL on Civi will only allow access from pos and posdev. // Have to get op to enter mcard# again. if (!is_numeric($memberCard) || strlen($memberCard) > 5 || $memberCard == 0) { $mmsg .= "<br />Bad Member Card# format >{$memberCard}<"; } else { /* Check that it isn't already in use, perhaps for someone else. */ $masterLane = CoreLocal::get('laneno'); $currentLane = $masterLane; $mQ = "SELECT card_no FROM memberCards where card_no = {$card_no}"; $mResult = $db_a->query($mQ); $mNumRows = $db_a->num_rows($mResult); if ($mNumRows > 0) { $mmsg .= "<br />On lane {$currentLane} {$row['CardNo']} is already associated with a Member Card"; } else { $mQ = "INSERT INTO memberCards (card_no, upc) VALUES ({$row['CardNo']}, '{$upc}')"; $mResult = $db_a->query($mQ); if (!$mResult) { $mmsg .= "<br />On lane {$currentLane} linking membership to Member Card failed."; } } // Do other lane. $otherLane = $masterLane == 1 ? 2 : 1; $currentLane = $otherLane; $isLAN = 1; if ($isLAN) { $LANE = "10.0.0.6{$otherLane}"; $LANE_PORT = "3306"; } else { $LANE = "wefc.dyndns.org"; $LANE_PORT = "5066{$otherLane}"; } $LANE_USER = "******"; $LANE_PW = "wefc1229"; $LANE_DB = "opdata"; $db_b = new mysqli("{$LANE}", "{$LANE_USER}", "{$LANE_PW}", "{$LANE_DB}", "{$LANE_PORT}"); if ($db_b->connect_error != "") { $mmsg .= "<br />Connection to lane {$currentLane} failed >" . $db_b->connect_error . "<"; } else { $mQ = "SELECT card_no FROM memberCards where card_no = {$card_no}"; $mResult = $db_b->query("{$mQ}"); $mNumRows = $mResult->{$num_rows}; if ($mNumRows > 0) { $mmsg .= "<br />On lane {$currentLane} member {$card_no} is already associated with a Member Card"; } else { $mQ = "INSERT INTO memberCards (card_no, upc) VALUES ({$card_no}, '{$upc}')"; $mResult = $db_b->query($mQ); if (!$mResult) { $mmsg .= "<br />On lane {$currentLane} linking membership to Member Card failed."; } } } $db_b->close(); } } else { $mmsg .= "<br />Member Card# absent or empty."; } if ($mmsg != "") { // Prepare to display the error. $this->temp_result = $result; $this->temp_num_rows = $num_rows; $this->entered = $entered; $this->db = $db_a; $this->temp_message = preg_replace("/^<br />/", "", $mmsg); return True; } // /WEFC_Toronto bit. } if ($entered != CoreLocal::get("defaultNonMem") && PrehLib::check_unpaid_ar($row["CardNo"])) { $this->change_page($this->page_url . "gui-modules/UnpaidAR.php"); } else { $this->change_page($this->page_url . "gui-modules/memlist_cards.php"); } return False; } // Prepare to display the memlist (list to choose from). $this->temp_result = $result; $this->temp_num_rows = $num_rows; $this->entered = $entered; $this->db = $db_a; $this->temp_message = ""; return True; }
function preprocess() { $entered = ""; if (isset($_REQUEST['idSearch']) && strlen($_REQUEST['idSearch']) > 0) { $entered = $_REQUEST['idSearch']; } elseif (isset($_REQUEST['search'])) { $entered = strtoupper(trim($_REQUEST["search"])); $entered = str_replace("'", '', $entered); } else { return true; } if (substr($entered, -2) == "ID") { $entered = substr($entered, 0, strlen($entered) - 2); } // No input available, stop if (!$entered || strlen($entered) < 1 || $entered == "CL") { $this->change_page($this->page_url . "gui-modules/pos2.php"); return false; } $personNum = false; $memberID = false; $this->submitted = true; if (strstr($entered, "::") !== false) { // User selected a :: delimited item from the list interface list($memberID, $personNum) = explode("::", $entered, 2); } else { // search for the member $lookups = AutoLoader::ListModules('MemberLookup', True); foreach ($lookups as $class) { if (!class_exists($class)) { continue; } $obj = new $class(); if (is_numeric($entered) && !$obj->handle_numbers()) { continue; } else { if (!is_numeric($entered) && !$obj->handle_text()) { continue; } else { if (is_numeric($entered)) { $chk = $obj->lookup_by_number($entered); if ($chk['url'] !== false) { $this->change_page($chk['url']); return false; } foreach ($chk['results'] as $key => $val) { $this->results[$key] = $val; } } elseif (!is_numeric($entered)) { $chk = $obj->lookup_by_text($entered); if ($chk['url'] !== false) { $this->change_page($chk['url']); return false; } foreach ($chk['results'] as $key => $val) { $this->results[$key] = $val; } } } } } if (count($this->results) == 1 && (CoreLocal::get('verifyName') == 0 || $entered == CoreLocal::get('defaultNonMem'))) { $members = array_keys($this->results); $match = $members[0]; list($memberID, $personNum) = explode('::', $match, 2); } } // we have exactly one row and // don't need to confirm any further if ($memberID !== false && $personNum !== false) { $callback = $this->getCallbackAction($memberID); if ($callback != false) { $callback->apply(); } if ($memberID == CoreLocal::get('defaultNonMem')) { $personNum = 1; } PrehLib::setMember($memberID, $personNum); if (CoreLocal::get('store') == "WEFC_Toronto") { $error_msg = $this->wefcCardCheck($memberID); if ($error_msg !== true) { $this->temp_message = $error_msg; return true; } } // don't bother with unpaid balance check if there is no balance if ($memberID != CoreLocal::get("defaultNonMem") && CoreLocal::get('balance') > 0) { $unpaid = PrehLib::check_unpaid_ar($memberID); if ($unpaid) { $this->change_page($this->page_url . "gui-modules/UnpaidAR.php"); } else { $this->change_page($this->page_url . "gui-modules/pos2.php"); } } else { $this->change_page($this->page_url . "gui-modules/pos2.php"); } return false; } return true; }