[Weberp-svn] SF.net SVN: weberp:[8656] trunk
Brought to you by:
sotandeka,
tim_schofield
From: <tim...@us...> - 2012-04-26 13:49:59
|
Revision: 8656 http://weberp.svn.sourceforge.net/weberp/?rev=8656&view=rev Author: tim_schofield Date: 2012-04-26 13:49:49 +0000 (Thu, 26 Apr 2012) Log Message: ----------- Extract customer search code into separate file Modified Paths: -------------- trunk/SelectCustomer.php Added Paths: ----------- trunk/includes/CustomerSearch.php Modified: trunk/SelectCustomer.php =================================================================== --- trunk/SelectCustomer.php 2012-04-25 19:42:33 UTC (rev 8655) +++ trunk/SelectCustomer.php 2012-04-26 13:49:49 UTC (rev 8656) @@ -5,6 +5,7 @@ $title = _('Search Customers'); include ('includes/header.inc'); include ('includes/SQL_CommonFunctions.inc'); +include ('includes/CustomerSearch.php'); if (isset($_GET['Select'])) { $_SESSION['CustomerID'] = $_GET['Select']; } @@ -90,86 +91,7 @@ $_POST['PageOffset'] = 1; } } -if (isset($_POST['Search']) OR isset($_POST['CSV']) OR isset($_POST['Go']) OR isset($_POST['Next']) OR isset($_POST['Previous'])) { - if (isset($_POST['Search'])) { - $_POST['PageOffset'] = 1; - } - if ($_POST['Keywords'] AND (($_POST['CustCode']) OR ($_POST['CustPhone']) OR ($_POST['CustType']))) { - $_POST['Keywords'] = mb_strtoupper($_POST['Keywords']); - } - if (($_POST['Keywords'] == '') AND ($_POST['CustCode'] == '') AND ($_POST['CustPhone'] == '') AND ( $_POST['CustType'] == 'ALL') AND ($_POST['Area'] == 'ALL') AND ($_POST['CustAdd'] == '')) { - //no criteria set then default to all customers - $SQL = "SELECT debtorsmaster.debtorno, - debtorsmaster.name, - debtorsmaster.address1, - debtorsmaster.address2, - debtorsmaster.address3, - debtorsmaster.address4, - custbranch.branchcode, - custbranch.brname, - custbranch.contactname, - debtortype.typename, - custbranch.phoneno, - custbranch.faxno - FROM debtorsmaster LEFT JOIN custbranch - ON debtorsmaster.debtorno = custbranch.debtorno - INNER JOIN debtortype - ON debtorsmaster.typeid = debtortype.typeid"; - } else { - $SearchKeywords = mb_strtoupper(trim(str_replace(' ', '%', $_POST['Keywords']))); - $_POST['CustCode'] = mb_strtoupper(trim($_POST['CustCode'])); - $_POST['CustPhone'] = trim($_POST['CustPhone']); - $_POST['CustAdd'] = trim($_POST['CustAdd']); - $SQL = "SELECT debtorsmaster.debtorno, - debtorsmaster.name, - debtorsmaster.address1, - debtorsmaster.address2, - debtorsmaster.address3, - debtorsmaster.address4, - custbranch.branchcode, - custbranch.brname, - custbranch.contactname, - debtortype.typename, - custbranch.phoneno, - custbranch.faxno - FROM debtorsmaster INNER JOIN debtortype - ON debtorsmaster.typeid = debtortype.typeid - LEFT JOIN custbranch - ON debtorsmaster.debtorno = custbranch.debtorno - WHERE debtorsmaster.name " . LIKE . " '%" . $SearchKeywords . "%' - AND debtorsmaster.debtorno " . LIKE . " '%" . $_POST['CustCode'] . "%' - AND custbranch.phoneno " . LIKE . " '%" . $_POST['CustPhone'] . "%' - AND (debtorsmaster.address1 " . LIKE . " '%" . $_POST['CustAdd'] . "%' - OR debtorsmaster.address2 " . LIKE . " '%" . $_POST['CustAdd'] . "%' - OR debtorsmaster.address3 " . LIKE . " '%" . $_POST['CustAdd'] . "%' - OR debtorsmaster.address4 " . LIKE . " '%" . $_POST['CustAdd'] . "%')"; - - if (mb_strlen($_POST['CustType']) > 0 AND $_POST['CustType']!='ALL') { - $SQL .= " AND debtortype.typename = '" . $_POST['CustType'] . "'"; - } - if (mb_strlen($_POST['Area']) > 0 AND $_POST['Area']!='ALL') { - $SQL .= " AND custbranch.area = '" . $_POST['Area'] . "'"; - } - } //one of keywords or custcode or custphone was more than a zero length string - if ($_SESSION['SalesmanLogin'] != '') { - $SQL.= " AND custbranch.salesman='" . $_SESSION['SalesmanLogin'] . "'"; - } - $SQL.= ' ORDER BY debtorsmaster.name'; - $ErrMsg = _('The searched customer records requested cannot be retrieved because'); - - $result = DB_query($SQL, $db, $ErrMsg); - if (DB_num_rows($result) == 1) { - $myrow = DB_fetch_array($result); - $_SESSION['CustomerID'] = $myrow['debtorno']; - $_SESSION['BranchID'] = $myrow['branchcode']; - unset($_POST['Search']); - unset($result); - } elseif (DB_num_rows($result) == 0) { - prnMsg(_('No customer records contain the selected text') . ' - ' . _('please alter your search criteria and try again'), 'info'); - echo '<br />'; - } -} //end of if search - +$result=CustomerSearchSQL($db); if (isset($_POST['JustSelectedACustomer']) and empty($_SESSION['CustomerID'])){ /*Need to figure out the number of the form variable that the user clicked on */ for ($i=0; $i< count($_POST); $i++){ //loop through the returned customers @@ -233,7 +155,7 @@ echo '</td>'; echo '</tr></table><br />'; } else { - echo '<table width="90%"><tr><th width="33%">' . _('Customer Inquiries') . '</th> + echo '<table width="90%" class="selection"><tr><th width="33%">' . _('Customer Inquiries') . '</th> <th width=33%>' . _('Customer Transactions') . '</th> <th width=33%>' . _('Customer Maintenance') . '</th></tr>'; echo '<tr><td class="select">'; @@ -244,223 +166,13 @@ } echo '</td></tr></table>'; } -echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">'; -echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; if (mb_strlen($msg)>1){ prnMsg($msg, 'info'); } -echo '<p class="page_title_text"><img src="' . $rootpath . '/css/' . $theme . '/images/magnifier.png" title="' . _('Search') . '" alt="" />' . ' ' . _('Search for Customers').'</p>'; -echo '<table cellpadding="3" class="selection">'; -echo '<tr><td colspan="2">' . _('Enter a partial Name') . ':</td><td>'; -if (isset($_POST['Keywords'])) { - echo '<input type="text" name="Keywords" value="' . $_POST['Keywords'] . '" size="20" maxlength="25" />'; -} else { - echo '<input type="text" name="Keywords" size="20" maxlength="25" />'; -} -echo '</td><td><font size="3"><b>' . _('OR') . '</b></font></td><td>' . _('Enter a partial Code') . ':</td><td>'; -if (isset($_POST['CustCode'])) { - echo '<input type="text" name="CustCode" value="' . $_POST['CustCode'] . '" size="15" maxlength="18" />'; -} else { - echo '<input type="text" name="CustCode" size="15" maxlength="18" />'; -} -echo '</td></tr><tr><td><font size="3"><b>' . _('OR') . '</b></font></td><td>' . _('Enter a partial Phone Number') . ':</td><td>'; -if (isset($_POST['CustPhone'])) { - echo '<input type="text" name="CustPhone" value="' . $_POST['CustPhone'] . '" size="15" maxlength="18" />'; -} else { - echo '<input type="text" name="CustPhone" size="15" maxlength="18" />'; -} -echo '</td>'; -echo '<td><font size="3"><b>' . _('OR') . '</b></font></td><td>' . _('Enter part of the Address') . ':</td><td>'; -if (isset($_POST['CustAdd'])) { - echo '<input type="text" name="CustAdd" value="' . $_POST['CustAdd'] . '" size="20" maxlength="25" />'; -} else { - echo '<input type="text" name="CustAdd" size="20" maxlength="25" />'; -} -echo '</td></tr>'; -/* End addded search feature. Gilles Deacur */ -echo '<tr><td><font size="3"><b>' . _('OR') . '</b></font></td><td>' . _('Choose a Type') . ':</td><td>'; -if (isset($_POST['CustType'])) { - // Show Customer Type drop down list - $result2 = DB_query("SELECT typeid, typename FROM debtortype", $db); - // Error if no customer types setup - if (DB_num_rows($result2) == 0) { - $DataError = 1; - echo '<a href="CustomerTypes.php?" target="_parent">Setup Types</a>'; - echo '<tr><td colspan="2">' . prnMsg(_('No Customer types defined'), 'error') . '</td></tr>'; - } else { - // If OK show select box with option selected - echo '<select name="CustType">'; - echo '<option value="ALL">' . _('Any') . '</option>'; - while ($myrow = DB_fetch_array($result2)) { - if ($_POST['CustType'] == $myrow['typename']) { - echo '<option selected="True" value="' . $myrow['typename'] . '">' . $myrow['typename'] . '</option>'; - } else { - echo '<option value="' . $myrow['typename'] . '">' . $myrow['typename'] . '</option>'; - } - } //end while loop - DB_data_seek($result2, 0); - echo '</select></td>'; - } -} else { - // No option selected yet, so show Customer Type drop down list - $result2 = DB_query("SELECT typeid, typename FROM debtortype", $db); - // Error if no customer types setup - if (DB_num_rows($result2) == 0) { - $DataError = 1; - echo '<a href="CustomerTypes.php?" target="_parent">Setup Types</a>'; - echo '<tr><td colspan="2">' . prnMsg(_('No Customer types defined'), 'error') . '</td></tr>'; - } else { - // if OK show select box with available options to choose - echo '<select name="CustType">'; - echo '<option value="ALL">' . _('Any'). '</option>'; - while ($myrow = DB_fetch_array($result2)) { - echo '<option value="' . $myrow['typename'] . '">' . $myrow['typename'] . '</option>'; - } //end while loop - DB_data_seek($result2, 0); - echo '</select></td>'; - } -} - -/* Option to select a sales area */ -echo '<td><font size="3"><b>' . _('OR') . '</b></font></td><td>' . _('Choose an Area') . ':</td><td>'; -$result2 = DB_query("SELECT areacode, areadescription FROM areas", $db); -// Error if no sales areas setup -if (DB_num_rows($result2) == 0) { - $DataError = 1; - echo '<a href="Areas.php?" target="_parent">Setup Types</a>'; - echo '<tr><td colspan="2">' . prnMsg(_('No Sales Areas defined'), 'error') . '</td></tr>'; -} else { - // if OK show select box with available options to choose - echo '<select name="Area">'; - echo '<option value="ALL">' . _('Any') . '</option>'; - while ($myrow = DB_fetch_array($result2)) { - if (isset($_POST['Area']) and $_POST['Area']==$myrow['areacode']) { - echo '<option selected="True" value="' . $myrow['areacode'] . '">' . $myrow['areadescription'] . '</option>'; - } else { - echo '<option value="' . $myrow['areacode'] . '">' . $myrow['areadescription'] . '</option>'; - } - } //end while loop - DB_data_seek($result2, 0); - echo '</select></td></tr>'; -} - -echo '</td></tr></table><br />'; -echo '<div class="centre"><input type="submit" name="Search" value="' . _('Search Now') . '" /><input type="submit" name="CSV" value="' . _('CSV Format') . '" /></div>'; -if (isset($_SESSION['SalesmanLogin']) and $_SESSION['SalesmanLogin'] != '') { - prnMsg(_('Your account enables you to see only customers allocated to you'), 'warn', _('Note: Sales-person Login')); -} +ShowCustomerSearchFields($rootpath, $theme, $db); if (isset($result)) { - unset($_SESSION['CustomerID']); - $ListCount = DB_num_rows($result); - $ListPageMax = ceil($ListCount / $_SESSION['DisplayRecordsMax']); - if (!isset($_POST['CSV'])) { - if (isset($_POST['Next'])) { - if ($_POST['PageOffset'] < $ListPageMax) { - $_POST['PageOffset'] = $_POST['PageOffset'] + 1; - } - } - if (isset($_POST['Previous'])) { - if ($_POST['PageOffset'] > 1) { - $_POST['PageOffset'] = $_POST['PageOffset'] - 1; - } - } - echo '<input type="hidden" name="PageOffset" value="' . $_POST['PageOffset'] . '" />'; - if ($ListPageMax > 1) { - echo '<br /><div class="centre"> ' . $_POST['PageOffset'] . ' ' . _('of') . ' ' . $ListPageMax . ' ' . _('pages') . '. ' . _('Go to Page') . ': '; - echo '<select name="PageOffset1">'; - $ListPage = 1; - while ($ListPage <= $ListPageMax) { - if ($ListPage == $_POST['PageOffset']) { - echo '<option value=' . $ListPage . ' selected>' . $ListPage . '</option>'; - } else { - echo '<option value=' . $ListPage . '>' . $ListPage . '</option>'; - } - $ListPage++; - } - echo '</select> - <input type="submit" name="Go1" value="' . _('Go') . '" /> - <input type="submit" name="Previous" value="' . _('Previous') . '" /> - <input type="submit" name="Next" value="' . _('Next') . '" />'; - echo '</div>'; - } - echo '<br /><table cellpadding="2" class="selection">'; - $TableHeader = '<tr> - <th>' . _('Code') . '</th> - <th>' . _('Customer Name') . '</th> - <th>' . _('Branch') . '</th> - <th>' . _('Contact') . '</th> - <th>' . _('Type') . '</th> - <th>' . _('Phone') . '</th> - <th>' . _('Fax') . '</th> - </tr>'; - echo $TableHeader; - $j = 1; - $k = 0; //row counter to determine background colour - $RowIndex = 0; - } - if (DB_num_rows($result) <> 0) { - if (isset($_POST['CSV'])) { - $FileName = $_SESSION['reports_dir'] . '/Customer_Listing_' . Date('Y-m-d') . '.csv'; - echo '<br /><p class="page_title_text"><a href="' . $FileName . '">' . _('Click to view the csv Search Result') . '</p>'; - $fp = fopen($FileName, 'w'); - while ($myrow2 = DB_fetch_array($result)) { - fwrite($fp, $myrow2['debtorno'] . ',' . str_replace(',', '', $myrow2['name']) . ',' . str_replace(',', '', $myrow2['address1']) . ',' . str_replace(',', '', $myrow2['address2']) . ',' . str_replace(',', '', $myrow2['address3']) . ',' . str_replace(',', '', $myrow2['address4']) . ',' . str_replace(',', '', $myrow2['contactname']) . ',' . str_replace(',', '', $myrow2['typename']) . ',' . $myrow2['phoneno'] . ',' . $myrow2['faxno'] . "\n"); - } - echo '</div>'; - } - if (!isset($_POST['CSV'])) { - DB_data_seek($result, ($_POST['PageOffset'] - 1) * $_SESSION['DisplayRecordsMax']); - } - $i=0; //counter for input controls - while (($myrow = DB_fetch_array($result)) AND ($RowIndex <> $_SESSION['DisplayRecordsMax'])) { - if ($k == 1) { - echo '<tr class="EvenTableRows">'; - $k = 0; - } else { - echo '<tr class="OddTableRows">'; - $k = 1; - } - echo '<td><font size="1"><input type="submit" name="SubmitCustomerSelection' . $i .'" value="' . htmlentities($myrow['debtorno'].' '.$myrow['branchcode'],ENT_QUOTES,'UTF-8') . '" /></font></td> - <input type="hidden" name="SelectedCustomer' . $i .'" value="'.$myrow['debtorno'].'" /> - <input type="hidden" name="SelectedBranch' . $i .'" value="'. $myrow['branchcode'].'" /> - <td><font size="1">' . $myrow['name'] . '</font></td> - <td><font size="1">' . $myrow['brname'] . '</font></td> - <td><font size="1">' . $myrow['contactname'] . '</font></td> - <td><font size="1">' . $myrow['typename'] . '</font></td> - <td><font size="1">' . $myrow['phoneno'] . '</font></td> - <td><font size="1">' . $myrow['faxno'] . '</font></td></tr>'; - $i++; - $j++;//row counter - //end of page full new headings if - - } - //end of while loop - echo '</table>'; - echo '<input type="hidden" name="JustSelectedACustomer" value="Yes" />'; - } + ShowReturnedCustomers($result); } -//end if results to show -if (!isset($_POST['CSV'])) { - if (isset($ListPageMax) and $ListPageMax > 1) { - echo '<br /><div class="centre"> ' . $_POST['PageOffset'] . ' ' . _('of') . ' ' . $ListPageMax . ' ' . _('pages') . '. ' . _('Go to Page') . ': '; - echo '<select name="PageOffset2">'; - $ListPage = 1; - while ($ListPage <= $ListPageMax) { - if ($ListPage == $_POST['PageOffset']) { - echo '<option value=' . $ListPage . ' selected>' . $ListPage . '</option>'; - } else { - echo '<option value=' . $ListPage . '>' . $ListPage . '</option>'; - } - $ListPage++; - } - echo '</select> - <input type="submit" name="Go2" value="' . _('Go') . '" /> - <input type="submit" name="Previous" value="' . _('Previous') . '" /> - <input type="submit" name="Next" value="' . _('Next') . '" />'; - } - //end if results to show - echo '</div></form>'; -} // Only display the geocode map if the integration is turned on, and there is a latitude/longitude to display if (isset($_SESSION['CustomerID']) and $_SESSION['CustomerID'] != "") { if ($_SESSION['geocode_integration'] == 1) { @@ -469,7 +181,7 @@ echo '<div class="centre">' . _('Mapping is enabled, but no Mapping data to display for this Customer.') . '</div>'; } else { echo '<tr><td colspan="2">'; - echo '<table width="45%" cellpadding="4">'; + echo '<table width="45%" cellpadding="4" class="selection">'; echo '<tr><th width="33%">' . _('Customer Mapping') . '</th></tr>'; echo '</td><td valign="top">'; /* Mapping */ echo '<div class="centre">' . _('Mapping is enabled, Map will display below.') . '</div>'; @@ -558,7 +270,7 @@ ORDER BY contid"; $result = DB_query($sql, $db); if (DB_num_rows($result) <> 0) { - echo '<table width="45%">'; + echo '<table width="45%" class="selection">'; echo '<br /><th colspan="7"><img src="' . $rootpath . '/css/' . $theme . '/images/group_add.png" title="' . _('Customer Contacts') . '" alt="" />' . ' ' . _('Customer Contacts') . '</th>'; echo '<tr> <th>' . _('Name') . '</th> @@ -605,7 +317,7 @@ $result = DB_query($sql, $db); if (DB_num_rows($result) <> 0) { echo '<br /><div class="centre"><img src="' . $rootpath . '/css/' . $theme . '/images/note_add.png" title="' . _('Customer Notes') . '" alt="" />' . ' ' . _('Customer Notes') . '</div><br />'; - echo '<table width="45%">'; + echo '<table width="45%" class+"selection">'; echo '<tr> <th>' . _('date') . '</th> <th>' . _('note') . '</th> @@ -651,7 +363,7 @@ $result = DB_query($sql, $db); if (DB_num_rows($result) <> 0) { echo '<br /><div class="centre"><img src="' . $rootpath . '/css/' . $theme . '/images/folder_add.png" title="' . _('Customer Type (Group) Notes') . '" alt="" />' . ' ' . _('Customer Type (Group) Notes for:' . '<b> ' . $CustomerTypeName . '</b>') . '</div><br />'; - echo '<table width="45%">'; + echo '<table width="45%" class="selection">'; echo '<tr> <th>' . _('date') . '</th> <th>' . _('note') . '</th> Added: trunk/includes/CustomerSearch.php =================================================================== --- trunk/includes/CustomerSearch.php (rev 0) +++ trunk/includes/CustomerSearch.php 2012-04-26 13:49:49 UTC (rev 8656) @@ -0,0 +1,302 @@ +<?php + +function ShowCustomerSearchFields($rootpath, $theme, $db) { + echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">'; + echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; + echo '<p class="page_title_text"><img src="' . $rootpath . '/css/' . $theme . '/images/magnifier.png" title="' . _('Search') . '" alt="" />' . ' ' . _('Search for Customers').'</p>'; + echo '<table cellpadding="3" class="selection">'; + echo '<tr><td colspan="2">' . _('Enter a partial Name') . ':</td><td>'; + if (isset($_POST['Keywords'])) { + echo '<input type="text" name="Keywords" value="' . $_POST['Keywords'] . '" size="20" maxlength="25" />'; + } else { + echo '<input type="text" name="Keywords" size="20" maxlength="25" />'; + } + echo '</td><td><font size="3"><b>' . _('OR') . '</b></font></td><td>' . _('Enter a partial Code') . ':</td><td>'; + if (isset($_POST['CustCode'])) { + echo '<input type="text" name="CustCode" value="' . $_POST['CustCode'] . '" size="15" maxlength="18" />'; + } else { + echo '<input type="text" name="CustCode" size="15" maxlength="18" />'; + } + echo '</td></tr><tr><td><font size="3"><b>' . _('OR') . '</b></font></td><td>' . _('Enter a partial Phone Number') . ':</td><td>'; + if (isset($_POST['CustPhone'])) { + echo '<input type="text" name="CustPhone" value="' . $_POST['CustPhone'] . '" size="15" maxlength="18" />'; + } else { + echo '<input type="text" name="CustPhone" size="15" maxlength="18" />'; + } + echo '</td>'; + echo '<td><font size="3"><b>' . _('OR') . '</b></font></td><td>' . _('Enter part of the Address') . ':</td><td>'; + if (isset($_POST['CustAdd'])) { + echo '<input type="text" name="CustAdd" value="' . $_POST['CustAdd'] . '" size="20" maxlength="25" />'; + } else { + echo '<input type="text" name="CustAdd" size="20" maxlength="25" />'; + } + echo '</td></tr>'; + /* End addded search feature. Gilles Deacur */ + echo '<tr><td><font size="3"><b>' . _('OR') . '</b></font></td><td>' . _('Choose a Type') . ':</td><td>'; + if (isset($_POST['CustType'])) { + // Show Customer Type drop down list + $result2 = DB_query("SELECT typeid, typename FROM debtortype", $db); + // Error if no customer types setup + if (DB_num_rows($result2) == 0) { + $DataError = 1; + echo '<a href="CustomerTypes.php?" target="_parent">Setup Types</a>'; + echo '<tr><td colspan="2">' . prnMsg(_('No Customer types defined'), 'error') . '</td></tr>'; + } else { + // If OK show select box with option selected + echo '<select name="CustType">'; + echo '<option value="ALL">' . _('Any') . '</option>'; + while ($myrow = DB_fetch_array($result2)) { + if ($_POST['CustType'] == $myrow['typename']) { + echo '<option selected="True" value="' . $myrow['typename'] . '">' . $myrow['typename'] . '</option>'; + } else { + echo '<option value="' . $myrow['typename'] . '">' . $myrow['typename'] . '</option>'; + } + } //end while loop + DB_data_seek($result2, 0); + echo '</select></td>'; + } + } else { + // No option selected yet, so show Customer Type drop down list + $result2 = DB_query("SELECT typeid, typename FROM debtortype", $db); + // Error if no customer types setup + if (DB_num_rows($result2) == 0) { + $DataError = 1; + echo '<a href="CustomerTypes.php?" target="_parent">Setup Types</a>'; + echo '<tr><td colspan="2">' . prnMsg(_('No Customer types defined'), 'error') . '</td></tr>'; + } else { + // if OK show select box with available options to choose + echo '<select name="CustType">'; + echo '<option value="ALL">' . _('Any'). '</option>'; + while ($myrow = DB_fetch_array($result2)) { + echo '<option value="' . $myrow['typename'] . '">' . $myrow['typename'] . '</option>'; + } //end while loop + DB_data_seek($result2, 0); + echo '</select></td>'; + } + } + + /* Option to select a sales area */ + echo '<td><font size="3"><b>' . _('OR') . '</b></font></td><td>' . _('Choose an Area') . ':</td><td>'; + $result2 = DB_query("SELECT areacode, areadescription FROM areas", $db); + // Error if no sales areas setup + if (DB_num_rows($result2) == 0) { + $DataError = 1; + echo '<a href="Areas.php?" target="_parent">Setup Types</a>'; + echo '<tr><td colspan="2">' . prnMsg(_('No Sales Areas defined'), 'error') . '</td></tr>'; + } else { + // if OK show select box with available options to choose + echo '<select name="Area">'; + echo '<option value="ALL">' . _('Any') . '</option>'; + while ($myrow = DB_fetch_array($result2)) { + if (isset($_POST['Area']) and $_POST['Area']==$myrow['areacode']) { + echo '<option selected="True" value="' . $myrow['areacode'] . '">' . $myrow['areadescription'] . '</option>'; + } else { + echo '<option value="' . $myrow['areacode'] . '">' . $myrow['areadescription'] . '</option>'; + } + } //end while loop + DB_data_seek($result2, 0); + echo '</select></td></tr>'; + } + + echo '</td></tr></table><br />'; + echo '<div class="centre"><button type="submit" name="Search">' . _('Search Now') . '</button> + <button type="submit" name="CSV">' . _('CSV Format') . '</button></div>'; + if (isset($_SESSION['SalesmanLogin']) and $_SESSION['SalesmanLogin'] != '') { + prnMsg(_('Your account enables you to see only customers allocated to you'), 'warn', _('Note: Sales-person Login')); + } +} + +function CustomerSearchSQL($db) { + if (isset($_POST['Search']) OR isset($_POST['CSV']) OR isset($_POST['Go']) OR isset($_POST['Next']) OR isset($_POST['Previous'])) { + if (isset($_POST['Search'])) { + $_POST['PageOffset'] = 1; + } + if ($_POST['Keywords'] AND (($_POST['CustCode']) OR ($_POST['CustPhone']) OR ($_POST['CustType']))) { + $_POST['Keywords'] = mb_strtoupper($_POST['Keywords']); + } + if (($_POST['Keywords'] == '') AND ($_POST['CustCode'] == '') AND ($_POST['CustPhone'] == '') AND ( $_POST['CustType'] == 'ALL') AND ($_POST['Area'] == 'ALL') AND ($_POST['CustAdd'] == '')) { + //no criteria set then default to all customers + $SQL = "SELECT debtorsmaster.debtorno, + debtorsmaster.name, + debtorsmaster.address1, + debtorsmaster.address2, + debtorsmaster.address3, + debtorsmaster.address4, + custbranch.branchcode, + custbranch.brname, + custbranch.contactname, + debtortype.typename, + custbranch.phoneno, + custbranch.faxno + FROM debtorsmaster + LEFT JOIN custbranch + ON debtorsmaster.debtorno = custbranch.debtorno + INNER JOIN debtortype + ON debtorsmaster.typeid = debtortype.typeid"; + } else { + $SearchKeywords = mb_strtoupper(trim(str_replace(' ', '%', $_POST['Keywords']))); + $_POST['CustCode'] = mb_strtoupper(trim($_POST['CustCode'])); + $_POST['CustPhone'] = trim($_POST['CustPhone']); + $_POST['CustAdd'] = trim($_POST['CustAdd']); + $SQL = "SELECT debtorsmaster.debtorno, + debtorsmaster.name, + debtorsmaster.address1, + debtorsmaster.address2, + debtorsmaster.address3, + debtorsmaster.address4, + custbranch.branchcode, + custbranch.brname, + custbranch.contactname, + debtortype.typename, + custbranch.phoneno, + custbranch.faxno + FROM debtorsmaster + INNER JOIN debtortype + ON debtorsmaster.typeid = debtortype.typeid + LEFT JOIN custbranch + ON debtorsmaster.debtorno = custbranch.debtorno + WHERE debtorsmaster.name " . LIKE . " '%" . $SearchKeywords . "%' + AND debtorsmaster.debtorno " . LIKE . " '%" . $_POST['CustCode'] . "%' + AND custbranch.phoneno " . LIKE . " '%" . $_POST['CustPhone'] . "%' + AND (debtorsmaster.address1 " . LIKE . " '%" . $_POST['CustAdd'] . "%' + OR debtorsmaster.address2 " . LIKE . " '%" . $_POST['CustAdd'] . "%' + OR debtorsmaster.address3 " . LIKE . " '%" . $_POST['CustAdd'] . "%' + OR debtorsmaster.address4 " . LIKE . " '%" . $_POST['CustAdd'] . "%')"; + + if (mb_strlen($_POST['CustType']) > 0 AND $_POST['CustType']!='ALL') { + $SQL .= " AND debtortype.typename = '" . $_POST['CustType'] . "'"; + } + if (mb_strlen($_POST['Area']) > 0 AND $_POST['Area']!='ALL') { + $SQL .= " AND custbranch.area = '" . $_POST['Area'] . "'"; + } + } //one of keywords or custcode or custphone was more than a zero length string + if ($_SESSION['SalesmanLogin'] != '') { + $SQL.= " AND custbranch.salesman='" . $_SESSION['SalesmanLogin'] . "'"; + } + $SQL.= " ORDER BY debtorsmaster.name"; + $ErrMsg = _('The searched customer records requested cannot be retrieved because'); + + $result = DB_query($SQL, $db, $ErrMsg); + if (DB_num_rows($result) == 0) { + prnMsg(_('No customer records contain the selected text') . ' - ' . _('please alter your search criteria and try again'), 'info'); + echo '<br />'; + } + return $result; + } //end of if search +} + +function ShowReturnedCustomers($result) { + unset($_SESSION['CustomerID']); + $ListCount = DB_num_rows($result); + $ListPageMax = ceil($ListCount / $_SESSION['DisplayRecordsMax']); + if (!isset($_POST['CSV'])) { + if (isset($_POST['Next'])) { + if ($_POST['PageOffset'] < $ListPageMax) { + $_POST['PageOffset'] = $_POST['PageOffset'] + 1; + } + } + if (isset($_POST['Previous'])) { + if ($_POST['PageOffset'] > 1) { + $_POST['PageOffset'] = $_POST['PageOffset'] - 1; + } + } + echo '<input type="hidden" name="PageOffset" value="' . $_POST['PageOffset'] . '" />'; + if ($ListPageMax > 1) { + echo '<br /><div class="centre"> ' . $_POST['PageOffset'] . ' ' . _('of') . ' ' . $ListPageMax . ' ' . _('pages') . '. ' . _('Go to Page') . ': '; + echo '<select name="PageOffset1">'; + $ListPage = 1; + while ($ListPage <= $ListPageMax) { + if ($ListPage == $_POST['PageOffset']) { + echo '<option value=' . $ListPage . ' selected>' . $ListPage . '</option>'; + } else { + echo '<option value=' . $ListPage . '>' . $ListPage . '</option>'; + } + $ListPage++; + } + echo '</select> + <button type="submit" name="Go1">' . _('Go') . '</button> + <button type="submit" name="Previous">' . _('Previous') . '</button> + <button type="submit" name="Next">' . _('Next') . '</button>'; + echo '</div>'; + } + echo '<br /><table cellpadding="2" class="selection">'; + $TableHeader = '<tr> + <th>' . _('Code') . '</th> + <th>' . _('Customer Name') . '</th> + <th>' . _('Branch') . '</th> + <th>' . _('Contact') . '</th> + <th>' . _('Type') . '</th> + <th>' . _('Phone') . '</th> + <th>' . _('Fax') . '</th> + </tr>'; + echo $TableHeader; + $j = 1; + $k = 0; //row counter to determine background colour + $RowIndex = 0; + } + if (DB_num_rows($result) <> 0) { + if (isset($_POST['CSV'])) { + $FileName = $_SESSION['reports_dir'] . '/Customer_Listing_' . Date('Y-m-d') . '.csv'; + echo '<br /><p class="page_title_text"><a href="' . $FileName . '">' . _('Click to view the csv Search Result') . '</p>'; + $fp = fopen($FileName, 'w'); + while ($myrow2 = DB_fetch_array($result)) { + fwrite($fp, $myrow2['debtorno'] . ',' . str_replace(',', '', $myrow2['name']) . ',' . str_replace(',', '', $myrow2['address1']) . ',' . str_replace(',', '', $myrow2['address2']) . ',' . str_replace(',', '', $myrow2['address3']) . ',' . str_replace(',', '', $myrow2['address4']) . ',' . str_replace(',', '', $myrow2['contactname']) . ',' . str_replace(',', '', $myrow2['typename']) . ',' . $myrow2['phoneno'] . ',' . $myrow2['faxno'] . "\n"); + } + echo '</div>'; + } + if (!isset($_POST['CSV'])) { + DB_data_seek($result, ($_POST['PageOffset'] - 1) * $_SESSION['DisplayRecordsMax']); + } + $i=0; //counter for input controls + while (($myrow = DB_fetch_array($result)) AND ($RowIndex <> $_SESSION['DisplayRecordsMax'])) { + if ($k == 1) { + echo '<tr class="EvenTableRows">'; + $k = 0; + } else { + echo '<tr class="OddTableRows">'; + $k = 1; + } + echo '<td><button type="submit" name="SubmitCustomerSelection' . $i .'" value="' . htmlentities($myrow['debtorno'].' '.$myrow['branchcode'],ENT_QUOTES,'UTF-8') . '">' . htmlentities($myrow['debtorno'].' '.$myrow['branchcode'],ENT_QUOTES,'UTF-8') . '</button></td> + <input type="hidden" name="SelectedCustomer' . $i .'" value="'.$myrow['debtorno'].'" /> + <input type="hidden" name="SelectedBranch' . $i .'" value="'. $myrow['branchcode'].'" /> + <td><font size="1">' . $myrow['name'] . '</font></td> + <td><font size="1">' . $myrow['brname'] . '</font></td> + <td><font size="1">' . $myrow['contactname'] . '</font></td> + <td><font size="1">' . $myrow['typename'] . '</font></td> + <td><font size="1">' . $myrow['phoneno'] . '</font></td> + <td><font size="1">' . $myrow['faxno'] . '</font></td></tr>'; + $i++; + $j++;//row counter + //end of page full new headings if + + } + //end of while loop + echo '</table>'; + echo '<input type="hidden" name="JustSelectedACustomer" value="Yes" />'; + } + + //end if results to show + if (!isset($_POST['CSV'])) { + if (isset($ListPageMax) and $ListPageMax > 1) { + echo '<br /><div class="centre"> ' . $_POST['PageOffset'] . ' ' . _('of') . ' ' . $ListPageMax . ' ' . _('pages') . '. ' . _('Go to Page') . ': '; + echo '<select name="PageOffset2">'; + $ListPage = 1; + while ($ListPage <= $ListPageMax) { + if ($ListPage == $_POST['PageOffset']) { + echo '<option value=' . $ListPage . ' selected>' . $ListPage . '</option>'; + } else { + echo '<option value=' . $ListPage . '>' . $ListPage . '</option>'; + } + $ListPage++; + } + echo '</select> + <button type="submit" name="Go2">' . _('Go') . '</button> + <button type="submit" name="Previous">' . _('Previous') . '</button> + <button type="submit" name="Next">' . _('Next') . '</button>'; + } + //end if results to show + echo '</div></form>'; + } +} + +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |