function ModifySalesOrderHeader($OrderHeader, $user, $password) { $Errors = array(); $db = db($user, $password); if (gettype($db) == 'integer') { $Errors[0] = NoAuthorisation; return $Errors; } foreach ($OrderHeader as $key => $value) { $OrderHeader[$key] = DB_escape_string($value); } $Errors = VerifyOrderHeaderExists($OrderHeader['orderno'], sizeof($Errors), $Errors, $db); $Errors = VerifyDebtorExists($OrderHeader['debtorno'], sizeof($Errors), $Errors, $db); $Errors = VerifyBranchNoExists($OrderHeader['debtorno'], $OrderHeader['branchcode'], sizeof($Errors), $Errors, $db); if (isset($OrderHeader['customerref'])) { $Errors = VerifyCustomerRef($OrderHeader['customerref'], sizeof($Errors), $Errors); } if (isset($OrderHeader['buyername'])) { $Errors = VerifyBuyerName($OrderHeader['buyername'], sizeof($Errors), $Errors); } if (isset($OrderHeader['comments'])) { $Errors = VerifyComments($OrderHeader['comments'], sizeof($Errors), $Errors); } if (isset($OrderHeader['orddate'])) { $Errors = VerifyOrderDate($OrderHeader['orddate'], sizeof($Errors), $Errors, $db); } if (isset($OrderHeader['ordertype'])) { $Errors = VerifyOrderType($OrderHeader['ordertype'], sizeof($Errors), $Errors, $db); } if (isset($OrderHeader['shipvia'])) { $Errors = VerifyShipVia($OrderHeader['shipvia'], sizeof($Errors), $Errors, $db); } if (isset($OrderHeader['deladd1'])) { $Errors = VerifyAddressLine($OrderHeader['deladd1'], 40, sizeof($Errors), $Errors); } if (isset($OrderHeader['deladd2'])) { $Errors = VerifyAddressLine($OrderHeader['deladd2'], 40, sizeof($Errors), $Errors); } if (isset($OrderHeader['deladd3'])) { $Errors = VerifyAddressLine($OrderHeader['deladd3'], 40, sizeof($Errors), $Errors); } if (isset($OrderHeader['deladd4'])) { $Errors = VerifyAddressLine($OrderHeader['deladd4'], 40, sizeof($Errors), $Errors); } if (isset($OrderHeader['deladd5'])) { $Errors = VerifyAddressLine($OrderHeader['deladd5'], 20, sizeof($Errors), $Errors); } if (isset($OrderHeader['deladd6'])) { $Errors = VerifyAddressLine($OrderHeader['deladd6'], 15, sizeof($Errors), $Errors); } if (isset($OrderHeader['contactphone'])) { $Errors = VerifyPhoneNumber($OrderHeader['contactphone'], sizeof($Errors), $Errors); } if (isset($OrderHeader['contactemail'])) { $Errors = VerifyEmailAddress($OrderHeader['contactemail'], sizeof($Errors), $Errors); } if (isset($OrderHeader['deliverto'])) { $Errors = VerifyDeliverTo($OrderHeader['deliverto'], sizeof($Errors), $Errors); } if (isset($OrderHeader['deliverblind'])) { $Errors = VerifyDeliverBlind($OrderHeader['deliverblind'], sizeof($Errors), $Errors); } if (isset($OrderHeader['freightcost'])) { $Errors = VerifyFreightCost($OrderHeader['freightcost'], sizeof($Errors), $Errors); } if (isset($OrderHeader['fromstkloc'])) { $Errors = VerifyFromStockLocation($OrderHeader['fromstkloc'], sizeof($Errors), $Errors, $db); } if (isset($OrderHeader['deliverydate'])) { $Errors = VerifyDeliveryDate($OrderHeader['deliverydate'], sizeof($Errors), $Errors, $db); } if (isset($OrderHeader['quotation'])) { $Errors = VerifyQuotation($OrderHeader['quotation'], sizeof($Errors), $Errors); } global $SOH_DateFields; $sql = 'UPDATE salesorders SET '; foreach ($OrderHeader as $key => $value) { if (in_array($key, $SOH_DateFields)) { $value = FormatDateforSQL($value); } // Fix dates $sql .= $key . '="' . $value . '", '; } $sql = substr($sql, 0, -2) . ' WHERE orderno="' . $OrderHeader['orderno'] . '"'; if (sizeof($Errors) == 0) { $result = api_DB_Query($sql, $db); echo DB_error_no($db); if (DB_error_no($db) != 0) { $Errors[0] = DatabaseUpdateFailed; } else { $Errors[0] = 0; } } return $Errors; }
function ModifyBranch($BranchDetails, $user, $password) { $Errors = array(); $db = db($user, $password); if (gettype($db) == 'integer') { $Errors[0] = NoAuthorisation; return $Errors; } foreach ($BranchDetails as $key => $value) { $BranchDetails[$key] = DB_escape_string($value); } $Errors = VerifyBranchNoExists($BranchDetails['debtorno'], $BranchDetails['branchcode'], sizeof($Errors), $Errors, $db); $Errors = VerifyBranchName($BranchDetails['brname'], sizeof($Errors), $Errors, $db); if (isset($BranchDetails['address1'])) { $Errors = VerifyBranchAddressLine($BranchDetails['address1'], 40, sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['address2'])) { $Errors = VerifyBranchAddressLine($BranchDetails['address2'], 40, sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['address3'])) { $Errors = VerifyBranchAddressLine($BranchDetails['address3'], 40, sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['address4'])) { $Errors = VerifyBranchAddressLine($BranchDetails['address4'], 50, sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['address5'])) { $Errors = VerifyBranchAddressLine($BranchDetails['address5'], 20, sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['address6'])) { $Errors = VerifyBranchAddressLine($BranchDetails['address6'], 15, sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['lat'])) { $Errors = VerifyLatitude($BranchDetails['lat'], sizeof($Errors), $Errors); } if (isset($BranchDetails['lng'])) { $Errors = VerifyLongitude($BranchDetails['lng'], sizeof($Errors), $Errors); } if (isset($BranchDetails['estdeliverydays'])) { $Errors = VerifyEstDeliveryDays($BranchDetails['estdeliverydays'], sizeof($Errors), $Errors); } if (isset($BranchDetails['area'])) { $Errors = VerifyAreaCode($BranchDetails['area'], sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['salesman'])) { $Errors = VerifySalesmanCode($BranchDetails['salesman'], sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['fwddate'])) { $Errors = VerifyFwdDate($BranchDetails['fwddate'], sizeof($Errors), $Errors); } if (isset($BranchDetails['phoneno'])) { $Errors = VerifyPhoneNumber($BranchDetails['phoneno'], sizeof($Errors), $Errors); } if (isset($BranchDetails['faxno'])) { $Errors = VerifyFaxNumber($BranchDetails['faxno'], sizeof($Errors), $Errors); } if (isset($BranchDetails['contactname'])) { $Errors = VerifyContactName($BranchDetails['contactname'], sizeof($Errors), $Errors); } if (isset($BranchDetails['email'])) { $Errors = VerifyEmailAddress($BranchDetails['email'], sizeof($Errors), $Errors); } if (isset($BranchDetails['defaultlocation'])) { $Errors = VerifyDefaultLocation($BranchDetails['defaultlocation'], sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['taxgroupid'])) { $Errors = VerifyTaxGroupId($BranchDetails['taxgroupid'], sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['defaultshipvia'])) { $Errors = VerifyDefaultShipVia($BranchDetails['defaultshipvia'], sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['deliverblind'])) { $Errors = VerifyDeliverBlind($BranchDetails['deliverblind'], sizeof($Errors), $Errors); } if (isset($BranchDetails['disabletrans'])) { $Errors = VerifyDisableTrans($BranchDetails['disabletrans'], sizeof($Errors), $Errors); } if (isset($BranchDetails['brpostaddr1'])) { $Errors = VerifyBranchAddressLine($BranchDetails['brpostaddr1'], 40, sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['brpostaddr2'])) { $Errors = VerifyBranchAddressLine($BranchDetails['brpostaddr2'], 40, sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['brpostaddr3'])) { $Errors = VerifyBranchAddressLine($BranchDetails['brpostaddr3'], 30, sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['brpostaddr4'])) { $Errors = VerifyBranchAddressLine($BranchDetails['brpostaddr4'], 20, sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['brpostaddr5'])) { $Errors = VerifyBranchAddressLine($BranchDetails['brpostaddr5'], 20, sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['brpostaddr6'])) { $Errors = VerifyBranchAddressLine($BranchDetails['brpostaddr6'], 15, sizeof($Errors), $Errors, $db); } if (isset($BranchDetails['specialinstructions'])) { $Errors = VerifySpecialInstructions($BranchDetails['specialinstructions'], sizeof($Errors), $Errors); } if (isset($BranchDetails['custbranchcode'])) { $Errors = VerifyCustBranchCode($BranchDetails['custbranchcode'], sizeof($Errors), $Errors); } $FieldNames = ''; $FieldValues = ''; foreach ($BranchDetails as $key => $value) { $FieldNames .= $key . ', '; $FieldValues .= '"' . $value . '", '; } $sql = 'UPDATE custbranch SET '; foreach ($BranchDetails as $key => $value) { $sql .= $key . '="' . $value . '", '; } $sql = mb_substr($sql, 0, -2) . " WHERE debtorno='" . $BranchDetails['debtorno'] . "'\n AND branchcode='" . $BranchDetails['branchcode'] . "'"; if (sizeof($Errors) == 0) { $result = DB_Query($sql, $db); if (DB_error_no() != 0) { $Errors[0] = DatabaseUpdateFailed; } else { $Errors[0] = 0; } } return $Errors; }