From: <rc...@us...> - 2016-05-15 05:17:03
|
Revision: 7521 http://sourceforge.net/p/web-erp/reponame/7521 Author: rchacon Date: 2016-05-15 05:17:01 +0000 (Sun, 15 May 2016) Log Message: ----------- Fix use of Google Maps JavaScript API V3, unpaired html tags and other bugs. Modified Paths: -------------- trunk/SelectCustomer.php trunk/doc/Change.log Modified: trunk/SelectCustomer.php =================================================================== --- trunk/SelectCustomer.php 2016-05-13 16:11:48 UTC (rev 7520) +++ trunk/SelectCustomer.php 2016-05-15 05:17:01 UTC (rev 7521) @@ -1,18 +1,29 @@ <?php - /* $Id$*/ +/* Selection of customer - from where all customer related maintenance, transactions and inquiries start */ include('includes/session.inc'); $Title = _('Search Customers'); +$ViewTopic = 'AccountsReceivable'; +$BookMark = 'SelectCustomer'; include('includes/header.inc'); + +echo '<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme, + '/images/customer.png" title="',// Icon image. + _('Customer'), '" /> ',// Icon title. + _('Customers'), '</p>';// Page title. + include('includes/SQL_CommonFunctions.inc'); -if (isset($_GET['Select'])) { + +if(isset($_GET['Select'])) { $_SESSION['CustomerID'] = $_GET['Select']; } -if (!isset($_SESSION['CustomerID'])) { //initialise if not already done + +if(!isset($_SESSION['CustomerID'])) {// initialise if not already done $_SESSION['CustomerID'] = ''; } -if (isset($_GET['Area'])) { + +if(isset($_GET['Area'])) { $_POST['Area'] = $_GET['Area']; $_POST['Search'] = 'Search'; $_POST['Keywords'] = ''; @@ -21,14 +32,14 @@ $_POST['CustAdd'] = ''; $_POST['CustType'] = ''; } -echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/customer.png" title="' . _('Customer') . '" alt="" />' . ' ' . _('Customers') . '</p>'; -if (!isset($_SESSION['CustomerType'])) { //initialise if not already done + +if(!isset($_SESSION['CustomerType'])) {// initialise if not already done $_SESSION['CustomerType'] = ''; } -if (isset($_POST['JustSelectedACustomer']) ) { - if (isset ($_POST['SubmitCustomerSelection'])) { - foreach ($_POST['SubmitCustomerSelection'] AS $CustomerID=>$BranchCode) +if(isset($_POST['JustSelectedACustomer'])) { + if(isset ($_POST['SubmitCustomerSelection'])) { + foreach ($_POST['SubmitCustomerSelection'] as $CustomerID => $BranchCode) $_SESSION['CustomerID'] = $CustomerID; $_SESSION['BranchCode'] = $BranchCode; } else { @@ -36,140 +47,29 @@ } } -// only run geocode if integration is turned on AND customer has been selected -if ($_SESSION['geocode_integration'] == 1 AND $_SESSION['CustomerID'] != "") { - $sql = "SELECT * FROM geocode_param WHERE 1"; - $ErrMsg = _('An error occurred in retrieving the information'); - $result = DB_query($sql, $ErrMsg); - $myrow = DB_fetch_array($result); - $sql = "SELECT debtorsmaster.debtorno, - debtorsmaster.name, - custbranch.branchcode, - custbranch.brname, - custbranch.lat, - custbranch.lng, - braddress1, - braddress2, - braddress3, - braddress4 - FROM debtorsmaster LEFT JOIN custbranch - ON debtorsmaster.debtorno = custbranch.debtorno - WHERE debtorsmaster.debtorno = '" . $_SESSION['CustomerID'] . "' - AND custbranch.branchcode = '" . $_SESSION['BranchCode'] . "' - ORDER BY debtorsmaster.debtorno"; - $ErrMsg = _('An error occurred in retrieving the information'); - $result2 = DB_query($sql, $ErrMsg); - $myrow2 = DB_fetch_array($result2); - $Lat = $myrow2['lat']; - $Lng = $myrow2['lng']; - $API_Key = $myrow['geocode_key']; - $center_long = $myrow['center_long']; - $center_lat = $myrow['center_lat']; - $map_height = $myrow['map_height']; - $map_width = $myrow['map_width']; - $map_host = $myrow['map_host']; +$msg = ''; - if ($Lat == 0 && $myrow2["braddress1"] !='' && $_SESSION['BranchCode'] !='' ) { - $delay = 0; - $base_url = "https://" . $map_host . "/maps/api/geocode/xml?address="; - - $geocode_pending = true; - while ($geocode_pending) { - $address = urlencode($myrow2["braddress1"] . "," . $myrow2["braddress2"] . "," . $myrow2["braddress3"] . "," . $myrow2["braddress4"]); - $id = $myrow2["branchcode"]; - $debtorno =$myrow2["debtorno"]; - $request_url = $base_url . $address . ',&sensor=true'; - - $buffer = file_get_contents($request_url) or die("url not loading"); - $xml = simplexml_load_string($buffer); - //echo $xml->asXML(); - - $status = $xml->status; - if (strcmp($status, "OK") == 0) { - $geocode_pending = false; - - $Lat = $xml->result->geometry->location->lat; - $Lng = $xml->result->geometry->location->lng; - - $query = sprintf("UPDATE custbranch " . - " SET lat = '%s', lng = '%s' " . - " WHERE branchcode = '%s' " . - " AND debtorno = '%s' LIMIT 1;", - ($Lat), - ($Lng), - ($id), - ($debtorno)); - $update_result = DB_query($query); - - if ($update_result==1) { - prnMsg( _('GeoCode has been updated for CustomerID') . ': ' . $id . ' - ' . _('Latitude') . ': ' . $Lat . ' ' . _('Longitude') . ': ' . $Lng ,'info'); - } - } else { - $geocode_pending = false; - prnMsg(_('Unable to update GeoCode for CustomerID') . ': ' . $id . ' - ' . _('Received status') . ': ' . $status , 'error'); - } - usleep($delay); - } - } - - echo ' - <script src="https://' . $map_host . '/maps/api/js?v=3.exp&key=' . $API_Key . '" type="text/javascript"></script> - <script type="text/javascript"> - function initialize() { - var latlng = new google.maps.LatLng('.$Lat.','.$Lng.'); - var map = new google.maps.Map( - document.getElementById("map"), { - center: latlng, - zoom: 12, - mapTypeId: google.maps.MapTypeId.ROADMAP - }); - var marker = new google.maps.Marker({ - position: latlng, - map: map - }); - var contentString = - "<div style=\"overflow: auto;\">" + - "<div><b>'.$myrow2['brname'].'</b></div>" + - "<div>'.$myrow2['braddress1'].'</div>" + - "<div>'.$myrow2['braddress2'].'</div>" + - "<div>'.$myrow2['braddress3'].'</div>" + - "<div>'.$myrow2['braddress4'].'</div>" + - "</div>"; - - var infowindow = new google.maps.InfoWindow({ - content: contentString, - MaxWidth: 250 - }); - google.maps.event.addListener(marker, "click", function() { - infowindow.open(map,marker); - }); - } - google.maps.event.addDomListener(window, "load", initialize); - </script>'; - -} //end if geocode integration is turned on AND a customer is selected - -unset($result); -$msg = ''; -if (isset($_POST['Go1']) OR isset($_POST['Go2'])) { +if(isset($_POST['Go1']) OR isset($_POST['Go2'])) { $_POST['PageOffset'] = (isset($_POST['Go1']) ? $_POST['PageOffset1'] : $_POST['PageOffset2']); $_POST['Go'] = ''; } -if (!isset($_POST['PageOffset'])) { + +if(!isset($_POST['PageOffset'])) { $_POST['PageOffset'] = 1; } else { - if ($_POST['PageOffset'] == 0) { + if($_POST['PageOffset'] == 0) { $_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']) OR isset($_POST['CSV']) OR isset($_POST['Go']) OR isset($_POST['Next']) OR isset($_POST['Previous'])) { unset($_POST['JustSelectedACustomer']); - if (isset($_POST['Search'])) { + if(isset($_POST['Search'])) { $_POST['PageOffset'] = 1; } - 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 + 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, @@ -215,43 +115,48 @@ 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 there is no custbranch set, the phoneno in custbranch will be null, so we add IS NULL condition otherwise those debtors without custbranches setting will be no searchable and it will make a inconsistence with customer receipt interface. + OR debtorsmaster.address4 " . LIKE . " '%" . $_POST['CustAdd'] . "%')";// If there is no custbranch set, the phoneno in custbranch will be null, so we add IS NULL condition otherwise those debtors without custbranches setting will be no searchable and it will make a inconsistence with customer receipt interface. - if (mb_strlen($_POST['CustType']) > 0 AND $_POST['CustType'] != 'ALL') { + 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') { + + 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'] != '') { + + }// 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, $ErrMsg); - if (DB_num_rows($result) == 1) { + if(DB_num_rows($result) == 1) { $myrow = DB_fetch_array($result); $_SESSION['CustomerID'] = $myrow['debtorno']; $_SESSION['BranchCode'] = $myrow['branchcode']; unset($result); unset($_POST['Search']); - } elseif (DB_num_rows($result) == 0) { + } 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 +}// end of if search -if ($_SESSION['CustomerID'] != '' AND !isset($_POST['Search']) AND !isset($_POST['CSV'])) { - if (!isset($_SESSION['BranchCode'])) { +if($_SESSION['CustomerID'] != '' AND !isset($_POST['Search']) AND !isset($_POST['CSV'])) { + if(!isset($_SESSION['BranchCode'])) { $SQL = "SELECT debtorsmaster.name, - custbranch.phoneno + custbranch.phoneno, + custbranch.brname FROM debtorsmaster INNER JOIN custbranch ON debtorsmaster.debtorno=custbranch.debtorno WHERE custbranch.debtorno='" . $_SESSION['CustomerID'] . "'"; - } //!isset($_SESSION['BranchCode']) + }// !isset($_SESSION['BranchCode']) else { $SQL = "SELECT debtorsmaster.name, custbranch.phoneno, @@ -263,75 +168,98 @@ } $ErrMsg = _('The customer name requested cannot be retrieved because'); $result = DB_query($SQL, $ErrMsg); - if ($myrow = DB_fetch_array($result)) { + if($myrow = DB_fetch_array($result)) { $CustomerName = htmlspecialchars($myrow['name'], ENT_QUOTES, 'UTF-8', false); $PhoneNo = $myrow['phoneno']; $BranchName = $myrow['brname']; - } //$myrow = DB_fetch_array($result) + }// $myrow = DB_fetch_array($result) unset($result); - echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/customer.png" title="' . _('Customer') . '" alt="" />' . ' ' . _('Customer') . ' : ' . $_SESSION['CustomerID'] . ' - ' . $CustomerName . ' - ' . $PhoneNo . _(' has been selected') . '<br>'; - - echo '<div class="page_help_text">' . _('Select a menu option to operate using this customer') . '.</div><br />'; + echo '<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme, + '/images/customer.png" title="',// Icon image. + _('Customer'), '" /> ',// Icon title. + _('Customer'), ' : ', $_SESSION['CustomerID'], ' - ', $CustomerName, ' - ', $PhoneNo, _(' has been selected'), '</p>';// Page title. - echo '<table cellpadding="4" width="90%" class="selection"> + echo '<div class="page_help_text">', _('Select a menu option to operate using this customer'), '.</div> + <br /> + <table cellpadding="4" width="90%" class="selection"> + <thead> <tr> - <th style="width:33%">' . _('Customer Inquiries') . '</th> - <th style="width:33%">' . _('Customer Transactions') . '</th> - <th style="width:33%">' . _('Customer Maintenance') . '</th> - </tr>'; - echo '<tr><td valign="top" class="select">'; - /* Customer Inquiry Options */ - echo '<a href="' . $RootPath . '/CustomerInquiry.php?CustomerID=' . $_SESSION['CustomerID'] . '">' . _('Customer Transaction Inquiries') . '</a><br />'; - echo '<a href="' . $RootPath . '/CustomerAccount.php?CustomerID=' . $_SESSION['CustomerID'] . '">' . _('Customer Account statement on screen') . '</a><br />'; - echo '<a href="' . $RootPath . '/Customers.php?DebtorNo=' . $_SESSION['CustomerID'] . '&Modify=No">' . _('View Customer Details') . '</a><br />'; - echo '<a href="' . $RootPath . '/PrintCustStatements.php?FromCust=' . $_SESSION['CustomerID'] . '&ToCust=' . $_SESSION['CustomerID'] . '&PrintPDF=Yes">' . _('Print Customer Statement') . '</a><br />'; - echo '<a href="' . $RootPath . '/EmailCustStatements.php?FromCust=' . $_SESSION['CustomerID'] . '&ToCust=' . $_SESSION['CustomerID'] . '&PrintPDF=Yes">' . _('Email Customer Statement') . '</a><br />'; - echo '<a href="' . $RootPath . '/SelectCompletedOrder.php?SelectedCustomer=' . $_SESSION['CustomerID'] . '">' . _('Order Inquiries') . '</a><br />'; - echo '<a href="' . $RootPath . '/CustomerPurchases.php?DebtorNo=' . $_SESSION['CustomerID'] . '">' . _('Show purchases from this customer') . '</a><br />'; + <th style="width:33%">', _('Customer Inquiries'), '</th> + <th style="width:33%">', _('Customer Transactions'), '</th> + <th style="width:33%">', _('Customer Maintenance'), '</th> + </tr> + </thead> + <tbody> + <tr> + <td valign="top" class="select">'; + // Customer inquiries options: + echo '<a href="', $RootPath, '/CustomerInquiry.php?CustomerID=', urlencode($_SESSION['CustomerID']), '">' . _('Customer Transaction Inquiries') . '</a><br />'; + echo '<a href="', $RootPath, '/CustomerAccount.php?CustomerID=', urlencode($_SESSION['CustomerID']), '">' . _('Customer Account statement on screen') . '</a><br />'; + echo '<a href="', $RootPath, '/Customers.php?DebtorNo=', urlencode($_SESSION['CustomerID']), '&Modify=No">' . _('View Customer Details') . '</a><br />'; + echo '<a href="', $RootPath, '/PrintCustStatements.php?FromCust=', urlencode($_SESSION['CustomerID']), '&ToCust=', urlencode($_SESSION['CustomerID']), '&PrintPDF=Yes">' . _('Print Customer Statement') . '</a><br />'; + echo '<a href="', $RootPath, '/EmailCustStatements.php?FromCust=', urlencode($_SESSION['CustomerID']), '&ToCust=', urlencode($_SESSION['CustomerID']), '&PrintPDF=Yes">' . _('Email Customer Statement') . '</a><br />'; + echo '<a href="', $RootPath, '/SelectCompletedOrder.php?SelectedCustomer=', urlencode($_SESSION['CustomerID']), '">' . _('Order Inquiries') . '</a><br />'; + echo '<a href="', $RootPath, '/CustomerPurchases.php?DebtorNo=', urlencode($_SESSION['CustomerID']), '">' . _('Show purchases from this customer') . '</a><br />'; wikiLink('Customer', $_SESSION['CustomerID']); echo '</td><td valign="top" class="select">'; - echo '<a href="' . $RootPath . '/SelectSalesOrder.php?SelectedCustomer=' . $_SESSION['CustomerID'] . '">' . _('Modify Outstanding Sales Orders') . '</a><br />'; - echo '<a href="' . $RootPath . '/CustomerAllocations.php?DebtorNo=' . $_SESSION['CustomerID'] . '">' . _('Allocate Receipts OR Credit Notes') . '</a><br />'; - if (isset($_SESSION['CustomerID']) AND isset($_SESSION['BranchCode'])) { - echo '<a href="' . $RootPath . '/CounterSales.php?DebtorNo=' . $_SESSION['CustomerID'] . '&BranchNo=' . $_SESSION['BranchCode'] . '">' . _('Create a Counter Sale for this Customer') . '</a><br />'; + // Customer transactions options: + echo '<a href="', $RootPath, '/SelectSalesOrder.php?SelectedCustomer=', urlencode($_SESSION['CustomerID']), '">' . _('Modify Outstanding Sales Orders') . '</a><br />'; + echo '<a href="', $RootPath, '/CustomerAllocations.php?DebtorNo=', urlencode($_SESSION['CustomerID']), '">' . _('Allocate Receipts OR Credit Notes') . '</a><br />'; + if(isset($_SESSION['CustomerID']) AND isset($_SESSION['BranchCode'])) { + echo '<a href="', $RootPath, '/CounterSales.php?DebtorNo=', urlencode($_SESSION['CustomerID']), '&BranchNo=' . $_SESSION['BranchCode'] . '">' . _('Create a Counter Sale for this Customer') . '</a><br />'; } echo '</td><td valign="top" class="select">'; - echo '<a href="' . $RootPath . '/Customers.php?">' . _('Add a New Customer') . '</a><br />'; - echo '<a href="' . $RootPath . '/Customers.php?DebtorNo=' . $_SESSION['CustomerID'] . '">' . _('Modify Customer Details') . '</a><br />'; - echo '<a href="' . $RootPath . '/CustomerBranches.php?DebtorNo=' . $_SESSION['CustomerID'] . '">' . _('Add/Modify/Delete Customer Branches') . '</a><br />'; - echo '<a href="' . $RootPath . '/SelectProduct.php">' . _('Special Customer Prices') . '</a><br />'; - echo '<a href="' . $RootPath . '/CustEDISetup.php">' . _('Customer EDI Configuration') . '</a><br />'; - echo '<a href="' . $RootPath . '/CustLoginSetup.php">' . _('Customer Login Configuration') . '</a>'; - echo '</td>'; - echo '</tr></table><br />'; -} //$_SESSION['CustomerID'] != '' AND !isset($_POST['Search']) AND !isset($_POST['CSV']) -else { - echo '<table width="90%"> + // Customer maintenance options: + echo '<a href="', $RootPath, '/Customers.php">' . _('Add a New Customer') . '</a><br />'; + echo '<a href="', $RootPath, '/Customers.php?DebtorNo=', urlencode($_SESSION['CustomerID']), '">' . _('Modify Customer Details') . '</a><br />'; + echo '<a href="', $RootPath, '/CustomerBranches.php?DebtorNo=', urlencode($_SESSION['CustomerID']), '">' . _('Add/Modify/Delete Customer Branches') . '</a><br />'; + echo '<a href="', $RootPath, '/SelectProduct.php">' . _('Special Customer Prices') . '</a><br />'; + echo '<a href="', $RootPath, '/CustEDISetup.php">' . _('Customer EDI Configuration') . '</a><br />'; + echo '<a href="', $RootPath, '/CustLoginSetup.php">' . _('Customer Login Configuration'), '</a><br />'; + echo '<a href="', $RootPath, '/AddCustomerContacts.php?DebtorNo=', urlencode($_SESSION['CustomerID']), '">', _('Add a customer contact'), '</a><br />'; + echo '<a href="', $RootPath, '/AddCustomerNotes.php?DebtorNo=', urlencode($_SESSION['CustomerID']), '">', _('Add a note on this customer'), '</a>'; + echo '</td> + </tr> + <tbody> + </table>'; +} else { + echo '<table cellpadding="4" width="90%" class="selection"> + <thead> <tr> - <th style="width:33%">' . _('Customer Inquiries') . '</th> - <th style="width:33%">' . _('Customer Transactions') . '</th> - <th style="width:33%">' . _('Customer Maintenance') . '</th> - </tr>'; + <th style="width:33%">', _('Customer Inquiries'), '</th> + <th style="width:33%">', _('Customer Transactions'), '</th> + <th style="width:33%">', _('Customer Maintenance'), '</th> + </tr> + </thead> + <tbody>'; echo '<tr> <td class="select"></td> <td class="select"></td> <td class="select">'; - if (!isset($_SESSION['SalesmanLogin']) OR $_SESSION['SalesmanLogin'] == '') { - echo '<a href="' . $RootPath . '/Customers.php?">' . _('Add a New Customer') . '</a><br />'; + if(!isset($_SESSION['SalesmanLogin']) OR $_SESSION['SalesmanLogin'] == '') { + echo '<a href="', $RootPath, '/Customers.php">' . _('Add a New Customer') . '</a><br />'; } - echo '</td></tr></table>'; + echo '</td> + </tr> + <tbody> + </table>'; } -echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">'; -echo '<div>'; -echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; -if (mb_strlen($msg) > 1) { + +// Search for customers: +echo '<form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post">', + '<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 '<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme, + '/images/magnifier.png" title="',// Icon image. + _('Search'), '" /> ',// Icon title. + _('Search for Customers'), '</p>';// Page title. + echo '<table cellpadding="3" class="selection">'; echo '<tr><td colspan="2">' . _('Enter a partial Name') . ':</td><td>'; -if (isset($_POST['Keywords'])) { +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" />'; @@ -339,10 +267,10 @@ echo '</td> <td><b>' . _('OR') . '</b></td><td>' . _('Enter a partial Code') . ':</td> <td>'; -if (isset($_POST['CustCode'])) { - echo '<input type="text" name="CustCode" pattern="[\w-]*" value="' . $_POST['CustCode'] . '" size="15" maxlength="18" />'; +if(isset($_POST['CustCode'])) { + echo '<input maxlength="18" name="CustCode" pattern="[\w-]*" size="15" type="text" value="', $_POST['CustCode'], '" />'; } else { - echo '<input type="text" name="CustCode" pattern="[\w-]*" size="15" maxlength="18" />'; + echo '<input maxlength="18" name="CustCode" pattern="[\w-]*" size="15" type="text" />'; } echo '</td> </tr> @@ -350,30 +278,30 @@ <td><b>' . _('OR') . '</b></td> <td>' . _('Enter a partial Phone Number') . ':</td> <td>'; -if (isset($_POST['CustPhone'])) { - echo '<input type="tel" name="CustPhone" pattern="[0-9\-\s()+]*" value="' . $_POST['CustPhone'] . '" size="15" maxlength="18" />'; +if(isset($_POST['CustPhone'])) { + echo '<input maxlength="18" name="CustPhone" pattern="[0-9\-\s()+]*" size="15" type="tel" value="', $_POST['CustPhone'], '" />'; } else { - echo '<input type="tel" name="CustPhone" pattern="[0-9\-\s()+]*" size="15" maxlength="18" />'; + echo '<input maxlength="18" name="CustPhone" pattern="[0-9\-\s()+]*" size="15" type="tel" />'; } echo '</td>'; echo '<td><b>' . _('OR') . '</b></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" />'; +if(isset($_POST['CustAdd'])) { + echo '<input maxlength="25" name="CustAdd" size="20" type="text" value="', $_POST['CustAdd'], '" />'; } else { - echo '<input type="text" name="CustAdd" size="20" maxlength="25" />'; + echo '<input maxlength="25" name="CustAdd" size="20" type="text" />'; } echo '</td></tr>'; echo '<tr> <td><b>' . _('OR') . '</b></td> <td>' . _('Choose a Type') . ':</td> <td>'; -if (isset($_POST['CustType'])) { +if(isset($_POST['CustType'])) { // Show Customer Type drop down list $result2 = DB_query("SELECT typeid, typename FROM debtortype ORDER BY typename"); // Error if no customer types setup - if (DB_num_rows($result2) == 0) { + 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>'; @@ -382,21 +310,21 @@ echo '<select name="CustType"> <option value="ALL">' . _('Any') . '</option>'; while ($myrow = DB_fetch_array($result2)) { - if ($_POST['CustType'] == $myrow['typename']) { + if($_POST['CustType'] == $myrow['typename']) { echo '<option selected="selected" value="' . $myrow['typename'] . '">' . $myrow['typename'] . '</option>'; - } //$_POST['CustType'] == $myrow['typename'] + }// $_POST['CustType'] == $myrow['typename'] else { echo '<option value="' . $myrow['typename'] . '">' . $myrow['typename'] . '</option>'; } - } //end while loop + }// end while loop DB_data_seek($result2, 0); echo '</select></td>'; } -} else { //CustType is not set +} else {// CustType is not set // No option selected="selected" yet, so show Customer Type drop down list $result2 = DB_query("SELECT typeid, typename FROM debtortype ORDER BY typename"); // Error if no customer types setup - if (DB_num_rows($result2) == 0) { + 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>'; @@ -406,7 +334,7 @@ <option value="ALL">' . _('Any') . '</option>'; while ($myrow = DB_fetch_array($result2)) { echo '<option value="' . $myrow['typename'] . '">' . $myrow['typename'] . '</option>'; - } //end while loop + }// end while loop DB_data_seek($result2, 0); echo '</select></td>'; } @@ -417,7 +345,7 @@ <td>' . _('Choose an Area') . ':</td><td>'; $result2 = DB_query("SELECT areacode, areadescription FROM areas"); // Error if no sales areas setup -if (DB_num_rows($result2) == 0) { +if(DB_num_rows($result2) == 0) { $DataError = 1; echo '<a href="Areas.php" target="_parent">' . _('Setup Areas') . '</a>'; echo '<tr><td colspan="2">' . prnMsg(_('No Sales Areas defined'), 'error') . '</td></tr>'; @@ -426,47 +354,47 @@ 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']) { + if(isset($_POST['Area']) AND $_POST['Area'] == $myrow['areacode']) { echo '<option selected="selected" value="' . $myrow['areacode'] . '">' . $myrow['areadescription'] . '</option>'; } else { echo '<option value="' . $myrow['areacode'] . '">' . $myrow['areadescription'] . '</option>'; } - } //end while loop + }// end while loop DB_data_seek($result2, 0); echo '</select></td></tr>'; } echo '</table><br />'; echo '<div class="centre"> - <input type="submit" name="Search" value="' . _('Search Now') . '" /> - <input type="submit" name="CSV" value="' . _('CSV Format') . '" /> + <input name="Search" type="submit" value="', _('Search Now'), '" /> + <input name="CSV" type="submit" value="', _('CSV Format'), '" /> </div>'; -if (isset($_SESSION['SalesmanLogin']) AND $_SESSION['SalesmanLogin'] != '') { +if(isset($_SESSION['SalesmanLogin']) AND $_SESSION['SalesmanLogin'] != '') { prnMsg(_('Your account enables you to see only customers allocated to you'), 'warn', _('Note: Sales-person Login')); } -if (isset($result)) { +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) { + 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) { + 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) { + 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']) { + if($ListPage == $_POST['PageOffset']) { echo '<option value="' . $ListPage . '" selected="selected">' . $ListPage . '</option>'; } else { echo '<option value="' . $ListPage . '">' . $ListPage . '</option>'; @@ -479,121 +407,248 @@ <input type="submit" name="Next" value="' . _('Next') . '" />'; echo '</div>'; } - echo '<br /> - <table cellpadding="2" class="selection">'; - - echo '<tr> - <th class="ascending">' . _('Code') . '</th> - <th class="ascending">' . _('Customer Name') . '</th> - <th class="ascending">' . _('Branch') . '</th> - <th class="ascending">' . _('Contact') . '</th> - <th class="ascending">' . _('Type') . '</th> - <th class="ascending">' . _('Phone') . '</th> - <th class="ascending">' . _('Fax') . '</th> - <th class="ascending">' . _('Email') . '</th> - </tr>'; - $k = 0; //row counter to determine background colour + echo '<table cellpadding="2" class="selection"> + <thead> + <tr> + <th class="ascending">' . _('Code') . '</th> + <th class="ascending">' . _('Customer Name') . '</th> + <th class="ascending">' . _('Branch') . '</th> + <th class="ascending">' . _('Contact') . '</th> + <th class="ascending">' . _('Type') . '</th> + <th class="ascending">' . _('Phone') . '</th> + <th class="ascending">' . _('Fax') . '</th> + <th class="ascending">' . _('Email') . '</th> + </tr> + </thead>'; + $k = 0;// row counter to determine background colour $RowIndex = 0; - } //end if NOT producing a CSV file - if (DB_num_rows($result) <> 0) { - if (isset($_POST['CSV'])) { //producing a CSV file of customers - $FileName = $_SESSION['reports_dir'] . '/Customer_Listing_' . Date('Y-m-d') . '.csv'; + }// end if NOT producing a CSV file + if(DB_num_rows($result) <> 0) { + if(isset($_POST['CSV'])) {// producing a CSV file of customers + $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'] . ',' . $myrow2['email'] . "\n"); - } //end loop through customers returned - } //end if producing a CSV - if (!isset($_POST['CSV'])) { + }// end loop through customers returned + }// end if producing a CSV + if(!isset($_POST['CSV'])) { DB_data_seek($result, ($_POST['PageOffset'] - 1) * $_SESSION['DisplayRecordsMax']); } - $i = 0; //counter for input controls + $i = 0;// counter for input controls + echo '<tbody>'; while (($myrow = DB_fetch_array($result)) AND ($RowIndex <> $_SESSION['DisplayRecordsMax'])) { - if ($k == 1) { + if($k == 1) { echo '<tr class="EvenTableRows">'; $k = 0; } else { echo '<tr class="OddTableRows">'; $k = 1; } - echo '<td> - <button type="submit" name="SubmitCustomerSelection['.htmlspecialchars($myrow['debtorno'], ENT_QUOTES, 'UTF-8', false).']" value="' . htmlspecialchars($myrow['branchcode'], ENT_QUOTES, 'UTF-8', false) . '" >' . $myrow['debtorno'] . ' ' . $myrow['branchcode'] . '</button> - </td> - <td>' . htmlspecialchars($myrow['name'], ENT_QUOTES, 'UTF-8', false) . '</td> - <td>' . htmlspecialchars($myrow['brname'], ENT_QUOTES, 'UTF-8', false) . '</td> - <td>' . $myrow['contactname'] . '</td> - <td>' . $myrow['typename'] . '</td> - <td>' . $myrow['phoneno'] . '</td> - <td>' . $myrow['faxno'] . '</td> - <td>' . $myrow['email'] . '</td> + echo '<td><button type="submit" name="SubmitCustomerSelection[', htmlspecialchars($myrow['debtorno'], ENT_QUOTES, 'UTF-8', false), ']" value="', htmlspecialchars($myrow['branchcode'], ENT_QUOTES, 'UTF-8', false), '" >', $myrow['debtorno'], ' ', $myrow['branchcode'], '</button></td> + <td class="text">', htmlspecialchars($myrow['name'], ENT_QUOTES, 'UTF-8', false), '</td> + <td class="text">', htmlspecialchars($myrow['brname'], ENT_QUOTES, 'UTF-8', false), '</td> + <td class="text">', $myrow['contactname'], '</td> + <td class="text">', $myrow['typename'], '</td> + <td class="text">', $myrow['phoneno'], '</td> + <td class="text">', $myrow['faxno'], '</td> + <td class="text">', $myrow['email'], '</td> </tr>'; $i++; $RowIndex++; - //end of page full new headings if - } //end loop through customers + // end of page full new headings if + }// end loop through customers + echo '</tbody>'; echo '</table>'; echo '<input type="hidden" name="JustSelectedACustomer" value="Yes" />'; - } //end if there are customers to show -} //end if results to show + }// end if there are customers to show +}// end if results to show -if (!isset($_POST['CSV'])) { - if (isset($ListPageMax) AND $ListPageMax > 1) { +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']) { + if($ListPage == $_POST['PageOffset']) { echo '<option value="' . $ListPage . '" selected="selected">' . $ListPage . '</option>'; - } //$ListPage == $_POST['PageOffset'] + }// $ListPage == $_POST['PageOffset'] else { echo '<option value="' . $ListPage . '">' . $ListPage . '</option>'; } $ListPage++; - } //$ListPage <= $ListPageMax + }// $ListPage <= $ListPageMax echo '</select> <input type="submit" name="Go2" value="' . _('Go') . '" /> <input type="submit" name="Previous" value="' . _('Previous') . '" /> <input type="submit" name="Next" value="' . _('Next') . '" />'; echo '</div>'; - }//end if results to show + }// end if results to show } -echo '</div> - </form>'; +echo '</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) { +if(isset($_SESSION['CustomerID']) AND $_SESSION['CustomerID'] != '') { + + if($_SESSION['geocode_integration'] == 1) { + + $SQL = "SELECT * FROM geocode_param WHERE 1"; + $ErrMsg = _('An error occurred in retrieving the information'); + $result = DB_query($SQL, $ErrMsg); + if(DB_num_rows($result) == 0) { + prnMsg( _('You must first setup the geocode parameters') . ' ' . '<a href="' . $RootPath . '/GeocodeSetup.php">' . _('here') . '</a>', 'error'); + include('includes/footer.inc'); + exit; + } + $myrow = DB_fetch_array($result); + $API_key = $myrow['geocode_key']; + $center_long = $myrow['center_long']; + $center_lat = $myrow['center_lat']; + $map_height = $myrow['map_height']; + $map_width = $myrow['map_width']; + $map_host = $myrow['map_host']; + + $SQL = "SELECT + debtorsmaster.debtorno, + debtorsmaster.name, + custbranch.branchcode, + custbranch.brname, + custbranch.lat, + custbranch.lng, + custbranch.braddress1, + custbranch.braddress2, + custbranch.braddress3, + custbranch.braddress4 + FROM debtorsmaster + LEFT JOIN custbranch + ON debtorsmaster.debtorno = custbranch.debtorno + WHERE debtorsmaster.debtorno = '" . $_SESSION['CustomerID'] . "' + AND custbranch.branchcode = '" . $_SESSION['BranchCode'] . "' + ORDER BY debtorsmaster.debtorno"; + $ErrMsg = _('An error occurred in retrieving the information'); + $result2 = DB_query($SQL, $ErrMsg); + $myrow2 = DB_fetch_array($result2); + $Lat = $myrow2['lat']; + $Lng = $myrow2['lng']; + + if($Lat == 0 and $myrow2["braddress1"] != '' and $_SESSION['BranchCode'] != '') { + $delay = 0; + $base_url = "https://" . $map_host . "/maps/api/geocode/xml?address="; + + $geocode_pending = true; + while ($geocode_pending) { + $address = urlencode($myrow2["braddress1"] . "," . $myrow2["braddress2"] . "," . $myrow2["braddress3"] . "," . $myrow2["braddress4"]); + $id = $myrow2["branchcode"]; + $debtorno =$myrow2["debtorno"]; + $request_url = $base_url . $address . ',&sensor=true'; + + $buffer = file_get_contents($request_url)/* or die("url not loading")*/; + $xml = simplexml_load_string($buffer); + // echo $xml->asXML(); + + $status = $xml->status; + if(strcmp($status, "OK") == 0) { + $geocode_pending = false; + + $Lat = $xml->result->geometry->location->lat; + $Lng = $xml->result->geometry->location->lng; + + $query = sprintf("UPDATE custbranch " . + " SET lat = '%s', lng = '%s' " . + " WHERE branchcode = '%s' " . + " AND debtorno = '%s' LIMIT 1;", + ($Lat), + ($Lng), + ($id), + ($debtorno)); + $update_result = DB_query($query); + + if($update_result == 1) { + prnMsg( _('GeoCode has been updated for CustomerID') . ': ' . $id . ' - ' . _('Latitude') . ': ' . $Lat . ' ' . _('Longitude') . ': ' . $Lng ,'info'); + } + } else { + $geocode_pending = false; + prnMsg(_('Unable to update GeoCode for CustomerID') . ': ' . $id . ' - ' . _('Received status') . ': ' . $status , 'error'); + } + usleep($delay); + } + } + echo '<br />'; - if ($Lat == 0) { + if($Lat == 0) { echo '<div class="centre">' . _('Mapping is enabled, but no Mapping data to display for this Customer.') . '</div>'; } else { - echo '<tr> - <td colspan="2"> - <table style="width: 45%;" cellpadding="4"> - <tr> - <th style="width:auto">' . _('Customer Mapping') . '</th> - </tr> - </td> - <th valign="top"> - <div class="centre">' . _('Mapping is enabled, Map will display below.') . '</div> - <div class="center" id="map" style="width: ' . $map_width . 'px; height: ' . $map_height . 'px; margin: 0 auto;"></div> - <br /> - </th> + echo '<table cellpadding="4"> + <thead> + <tr> + <th style="width:auto">', _('Customer Mapping'), '</th> </tr> - </table>'; + <tr> + <th style="width:auto">', _('Mapping is enabled, Map will display below.'), '</th> + </tr> + </thead> + <tbody> + <tr> + <td><div class="center" id="map" style="height:', $map_height . 'px; margin: 0 auto; width:', $map_width, 'px;"></div></td> + </tr> + </tbody> + </table>'; + + // Reference: Google Maps JavaScript API V3, https://developers.google.com/maps/documentation/javascript/reference. + echo ' +<script type="text/javascript"> +var map; +function initMap() { + + var myLatLng = {lat: ', $Lat, ', lng: ', $Lng, '};', /* Fills with customer's coordinates. */' + + var map = new google.maps.Map(document.getElementById(\'map\'), {', /* Creates the map with the road map view. */' + center: myLatLng, + mapTypeId: google.maps.MapTypeId.ROADMAP, + zoom: 14 + }); + + var contentString =', /* Fills the content to be displayed in the InfoWindow. */' + \'<div style="overflow: auto;">\' + + \'<div><b>', $BranchName, '</b></div>\' + + \'<div>', $myrow2['braddress1'], '</div>\' + + \'<div>', $myrow2['braddress2'], '</div>\' + + \'<div>', $myrow2['braddress3'], '</div>\' + + \'<div>', $myrow2['braddress4'], '</div>\' + + \'</div>\'; + + var infowindow = new google.maps.InfoWindow({', /* Creates an info window to display the content of 'contentString'. */' + content: contentString, + maxWidth: 250 + }); + + var marker = new google.maps.Marker({', /* Creates a marker to identify a location on the map. */' + position: myLatLng, + map: map, + title: \'', $CustomerName, '\' + }); + + marker.addListener(\'click\', function() {', /* Creates the event clicking the marker to display the InfoWindow. */' + infowindow.open(map, marker); + }); +} +</script> +<script async defer src="https://maps.googleapis.com/maps/api/js?key=', $API_key, '&callback=initMap"></script>'; +/* echo '<script src="https://' . $map_host . '/maps/api/js?v=3.exp&key=' . $API_key . '" type="text/javascript"></script>';*/ } - - } //end if Geocode integration is turned on + + }// end if Geocode integration is turned on // Extended Customer Info only if selected in Configuration - if ($_SESSION['Extended_CustomerInfo'] == 1) { - if ($_SESSION['CustomerID'] != '') { - $sql = "SELECT debtortype.typeid, + if($_SESSION['Extended_CustomerInfo'] == 1) { + if($_SESSION['CustomerID'] != '') { + $SQL = "SELECT debtortype.typeid, debtortype.typename FROM debtorsmaster INNER JOIN debtortype ON debtorsmaster.typeid = debtortype.typeid WHERE debtorsmaster.debtorno = '" . $_SESSION['CustomerID'] . "'"; $ErrMsg = _('An error occurred in retrieving the information'); - $result = DB_query($sql, $ErrMsg); + $result = DB_query($SQL, $ErrMsg); $myrow = DB_fetch_array($result); $CustomerType = $myrow['typeid']; $CustomerTypeName = $myrow['typename']; @@ -619,74 +674,87 @@ AND type !=12"; $Total1Result = DB_query($SQL); $row = DB_fetch_array($Total1Result); - echo '<table style="width: 45%;" cellpadding="4">'; - echo '<tr><th style="width:auto" colspan="3">' . _('Customer Data') . '</th></tr>'; - echo '<tr><td valign="top" class="select">'; + echo '<table cellpadding="4" style="width: 45%;"> + <tr> + <th colspan="3" style="width:auto">', _('Customer Data'), '</th> + </tr> + <tr> + <td class="select" valign="top">'; /* Customer Data */ - if ($myrow['lastpaiddate'] == 0) { - echo _('No receipts from this customer.') . '</td> - <td class="select"></td> - <td class="select"></td> - </tr>'; + if($myrow['lastpaiddate'] == 0) { + echo _('No receipts from this customer.'), '</td> + <td class="select"> </td> + <td class="select"> </td> + </tr>'; } else { - echo _('Last Paid Date:') . '</td> - <td class="select"> <b>' . ConvertSQLDate($myrow['lastpaiddate']) . '</b> </td> - <td class="select">' . $myrow['lastpaiddays'] . ' ' . _('days') . '</td> - </tr>'; + echo _('Last Paid Date'), ':</td> + <td class="select"><b>' . ConvertSQLDate($myrow['lastpaiddate']), '</b></td> + <td class="select">', $myrow['lastpaiddays'], ' ', _('days'), '</td> + </tr>'; } - echo '<tr><td class="select">' . _('Last Paid Amount (inc tax):') . '</td> - <td class="select"> <b>' . locale_number_format($myrow['lastpaid'], $myrow['currdecimalplaces']) . '</b></td> - <td class="select"></td> + echo '<tr> + <td class="select">', _('Last Paid Amount (inc tax)'), ':</td> + <td class="select"><b>', locale_number_format($myrow['lastpaid'], $myrow['currdecimalplaces']), '</b></td> + <td class="select"> </td> + </tr>'; + echo '<tr> + <td class="select">', _('Customer since'), ':</td> + <td class="select"><b>', ConvertSQLDate($myrow['clientsince']), '</b></td> + <td class="select">', $myrow['customersincedays'], ' ', _('days'), '</td> + </tr>'; + if($row['total'] == 0) { + echo '<tr> + <td class="select"><b>', _('No Spend from this Customer.'), '</b></td> + <td class="select"> </td> + <td class="select"> </td> </tr>'; - echo '<tr><td class="select">' . _('Customer since:') . '</td> - <td class="select"> <b>' . ConvertSQLDate($myrow['clientsince']) . '</b> </td> - <td class="select">' . $myrow['customersincedays'] . ' ' . _('days') . '</td> - </tr>'; - if ($row['total'] == 0) { - echo '<tr> - <td class="select">' . _('No Spend from this Customer.') . '</b></td> - <td class="select"></td> - <td class="select"></td> - </tr>'; } else { echo '<tr> - <td class="select">' . _('Total Spend from this Customer (inc tax):') . ' </td> + <td class="select">' . _('Total Spend from this Customer (inc tax)') . ':</td> <td class="select"><b>' . locale_number_format($row['total'], $myrow['currdecimalplaces']) . '</b></td> <td class="select"></td> </tr>'; } echo '<tr> - <td class="select">' . _('Customer Type:') . ' </td> - <td class="select"><b>' . $CustomerTypeName . '</b></td> - <td class="select"></td> - </tr>'; + <td class="select">', _('Customer Type'), ':</td> + <td class="select"><b>', $CustomerTypeName, '</b></td> + <td class="select"> </td> + </tr>'; echo '</table>'; - } //end if $_SESSION['CustomerID'] != '' + }// end if $_SESSION['CustomerID'] != '' + // Customer Contacts - $sql = "SELECT * FROM custcontacts + $SQL = "SELECT * FROM custcontacts WHERE debtorno='" . $_SESSION['CustomerID'] . "' ORDER BY contid"; - $result = DB_query($sql); - - if (DB_num_rows($result) <> 0) { + $result = DB_query($SQL); + + if(DB_num_rows($result) <> 0) { echo '<br /><div class="centre"><img src="' . $RootPath . '/css/' . $Theme . '/images/group_add.png" title="' . _('Customer Contacts') . '" alt="" />' . ' ' . _('Customer Contacts') . '</div>'; - echo '<br /><table style="width: 45%;">'; - echo '<tr> - <th class="ascending">' . _('Name') . '</th> - <th class="ascending">' . _('Role') . '</th> - <th class="ascending">' . _('Phone Number') . '</th> - <th class="ascending">' . _('Email') . '</th> - <th>' . _('Notes') . '</th> - <th>' . _('Edit') . '</th> - <th>' . _('Delete') . '</th> - <th> <a href="AddCustomerContacts.php?DebtorNo=' . $_SESSION['CustomerID'] . '">' . _('Add New Contact') . '</a> </th> - </tr>'; - $k = 0; //row colour counter + echo '<br /><table width="45%"> + <thead> + <tr> + <th class="ascending">' . _('Name') . '</th> + <th class="ascending">' . _('Role') . '</th> + <th class="ascending">' . _('Phone Number') . '</th> + <th class="ascending">' . _('Email') . '</th> + <th class="text">', _('Notes'), '</th> + <th class="noprint">', _('Edit'), '</th> + <th class="noprint">' . _('Delete') . '</th> + </tr> + </thead> + <tfoot> + <tr> + <th colspan="7"><a href="AddCustomerContacts.php?DebtorNo=', urlencode($_SESSION['CustomerID']), '">', _('Add New Contact'), '</a></th> + </tr> + </tfoot> + <tbody>'; + $k = 0;// row colour counter while ($myrow = DB_fetch_array($result)) { - if ($k == 1) { + if($k == 1) { echo '<tr class="OddTableRows">'; $k = 0; - } //$k == 1 + }// $k == 1 else { echo '<tr class="EvenTableRows">'; $k = 1; @@ -699,17 +767,23 @@ <td><a href="AddCustomerContacts.php?Id=' . $myrow[0] . '&DebtorNo=' . $myrow[1] . '">' . _('Edit') . '</a></td> <td><a href="AddCustomerContacts.php?Id=' . $myrow[0] . '&DebtorNo=' . $myrow[1] . '&delete=1">' . _('Delete') . '</a></td> </tr>'; - } //END WHILE LIST LOOP + }// END WHILE LIST LOOP // Customer Branch Contacts if selected - if (isset ($_SESSION['BranchCode']) && $_SESSION['BranchCode'] != '') { - $sql = "SELECT branchcode, brname, contactname, phoneno, email FROM custbranch + if(isset ($_SESSION['BranchCode']) AND $_SESSION['BranchCode'] != '') { + $SQL = "SELECT + branchcode, + brname, + contactname, + phoneno, + email + FROM custbranch WHERE debtorno='" . $_SESSION['CustomerID'] . "' - AND branchcode='" . $_SESSION['BranchCode'] . "'"; - $result2 = DB_query($sql); + AND branchcode='" . $_SESSION['BranchCode'] . "'"; + $result2 = DB_query($SQL); $BranchContact = DB_fetch_row($result2); - - echo '<tr class="EvenTableRows"> + + echo '<tr class="EvenTableRows"> <td>' . $BranchContact[2] . '</td> <td>' . _('Branch Contact') . ' ' . $BranchContact[0] . '</td> <td>' . $BranchContact[3] . '</td> @@ -717,25 +791,27 @@ <td colspan="3"></td> </tr>'; } - echo '</table>'; - } //end if there are contact rows returned + echo '</tbody> + </table>'; + }// end if there are contact rows returned else { - if ($_SESSION['CustomerID'] != '') { - echo '<br /><div class="centre"><img src="' . $RootPath . '/css/' . $Theme . '/images/group_add.png" title="' . _('Customer Contacts') . '" alt="" /><a href="AddCustomerContacts.php?DebtorNo=' . $_SESSION['CustomerID'] . '">' . ' ' . _('Add New Contact') . '</a></div>'; + if($_SESSION['CustomerID'] != '') { + echo '<br /><div class="centre"><img src="' . $RootPath . '/css/' . $Theme . '/images/group_add.png" title="' . _('Customer Contacts') . '" alt="" /><a href="AddCustomerContacts.php?DebtorNo=', urlencode($_SESSION['CustomerID']), '">' . ' ' . _('Add New Contact') . '</a></div>'; } } // Customer Notes - $sql = "SELECT noteid, - debtorno, - href, - note, - date, - priority + $SQL = "SELECT + noteid, + debtorno, + href, + note, + date, + priority FROM custnotes WHERE debtorno='" . $_SESSION['CustomerID'] . "' ORDER BY date DESC"; - $result = DB_query($sql); - if (DB_num_rows($result) <> 0) { + $result = DB_query($SQL); + 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 style="width: 45%;">'; echo '<tr> @@ -745,14 +821,14 @@ <th class="ascending">' . _('Priority') . '</th> <th>' . _('Edit') . '</th> <th>' . _('Delete') . '</th> - <th> <a href="AddCustomerNotes.php?DebtorNo=' . $_SESSION['CustomerID'] . '">' . ' ' . _('Add New Note') . '</a> </th> + <th> <a href="AddCustomerNotes.php?DebtorNo=', urlencode($_SESSION['CustomerID']), '">' . ' ' . _('Add New Note') . '</a> </th> </tr>'; - $k = 0; //row colour counter + $k = 0;// row colour counter while ($myrow = DB_fetch_array($result)) { - if ($k == 1) { + if($k == 1) { echo '<tr class="OddTableRows">'; $k = 0; - } //$k == 1 + }// $k == 1 else { echo '<tr class="EvenTableRows">'; $k = 1; @@ -764,20 +840,20 @@ <td><a href="AddCustomerNotes.php?Id=' . $myrow['noteid'] . '&DebtorNo=' . $myrow['debtorno'] . '">' . _('Edit') . '</a></td> <td><a href="AddCustomerNotes.php?Id=' . $myrow['noteid'] . '&DebtorNo=' . $myrow['debtorno'] . '&delete=1">' . _('Delete') . '</a></td> </tr>'; - } //END WHILE LIST LOOP + }// END WHILE LIST LOOP echo '</table>'; - } //end if there are customer notes to display + }// end if there are customer notes to display else { - if ($_SESSION['CustomerID'] != '') { - echo '<br /><div class="centre"><img src="' . $RootPath . '/css/' . $Theme . '/images/note_add.png" title="' . _('Customer Notes') . '" alt="" /><a href="AddCustomerNotes.php?DebtorNo=' . $_SESSION['CustomerID'] . '">' . ' ' . _('Add New Note for this Customer') . '</a></div>'; + if($_SESSION['CustomerID'] != '') { + echo '<br /><div class="centre"><img src="' . $RootPath . '/css/' . $Theme . '/images/note_add.png" title="' . _('Customer Notes') . '" alt="" /><a href="AddCustomerNotes.php?DebtorNo=', urlencode($_SESSION['CustomerID']), '">' . ' ' . _('Add New Note for this Customer') . '</a></div>'; } } // Custome Type Notes - $sql = "SELECT * FROM debtortypenotes + $SQL = "SELECT * FROM debtortypenotes WHERE typeid='" . $CustomerType . "' ORDER BY date DESC"; - $result = DB_query($sql); - if (DB_num_rows($result) <> 0) { + $result = DB_query($SQL); + 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 style="width: 45%;">'; echo '<tr> @@ -789,9 +865,9 @@ <th>' . _('Delete') . '</th> <th><a href="AddCustomerTypeNotes.php?DebtorType=' . $CustomerType . '">' . _('Add New Group Note') . '</a></th> </tr>'; - $k = 0; //row colour counter + $k = 0;// row colour counter while ($myrow = DB_fetch_array($result)) { - if ($k == 1) { + if($k == 1) { echo '<tr class="OddTableRows">'; $k = 0; } else { @@ -805,15 +881,15 @@ <td><a href="AddCustomerTypeNotes.php?Id=' . $myrow[0] . '&DebtorType=' . $myrow[1] . '">' . _('Edit') . '</a></td> <td><a href="AddCustomerTypeNotes.php?Id=' . $myrow[0] . '&DebtorType=' . $myrow[1] . '&delete=1">' . _('Delete') . '</a></td> </tr>'; - } //END WHILE LIST LOOP + }// END WHILE LIST LOOP echo '</table>'; - } // end if there are customer group notes to display + }// end if there are customer group notes to display else { - if ($_SESSION['CustomerID'] != '') { + if($_SESSION['CustomerID'] != '') { echo '<br /><div class="centre"><img src="' . $RootPath . '/css/' . $Theme . '/images/folder_add.png" title="' . _('Customer Group Notes') . '" alt="" /><a href="AddCustomerTypeNotes.php?DebtorType=' . $CustomerType . '">' . ' ' . _('Add New Group Note') . '</a></div><br />'; } } - } //end if Extended_CustomerInfo is turned on -} //end if isset($_SESSION['CustomerID']) AND $_SESSION['CustomerID'] != '' + }// end if Extended_CustomerInfo is turned on +}// end if isset($_SESSION['CustomerID']) AND $_SESSION['CustomerID'] != '' include('includes/footer.inc'); ?> Modified: trunk/doc/Change.log =================================================================== --- trunk/doc/Change.log 2016-05-13 16:11:48 UTC (rev 7520) +++ trunk/doc/Change.log 2016-05-15 05:17:01 UTC (rev 7521) @@ -1,6 +1,7 @@ webERP Change Log -13/05/16 RChacon: In AddCustomerContacts.php, add classes to print and table heads. Clean up code. +14/05/16 RChacon: In SelectCustomer.php, fix use of Google Maps JavaScript API V3, unpaired html tags and other bugs. +13/05/16 RChacon: In AddCustomerContacts.php, add classes to print and table heads. Improve code. 12/05/16 RChacon: Fix blank line caused by reverse character RTL. Clean up code. 11/05/16 RChacon: Include translation to hebrew, thanks to Hagay Mandel. 09/05/16 Exson: Tidy Code Up to remove redundant code according to Tim's guide. |