{*******************************************************} { } { Responsive Software http://www.responsive.co.nz } { } { Copyright (c) 2003-2006 Responsive Software Limited } { } {*******************************************************} unit HTTPResponder; interface uses IBDatabase, Classes; function GetHTTPResponse (Method : string; URI : string; Version : string; MessageHeaders : TStringList; MessageBody : string) : string; implementation uses SyncObjs, Forms, Windows, Graphics, Chart, Series, TeEngine, Jpeg, SysUtils, Utilities, HTTPUtilities, HTTPServerCommunicatorUnit, GeneralUtilities, Globals, DatabaseObjects, DatabaseManager; {***** General formatting utilities *******************************************} var // set this global variable to false before calling a procedure which // modifies the contents of a file by replacing tags // and then test to see whether or not any were actually replaced TagReplaced : boolean; procedure ReplaceTag (Tag : string; Value : string; var Content : string); begin if Pos(Tag,Content) <> 0 then begin Content := ReplaceSubstring(Tag,Value,Content); TagReplaced := true; end; end; function GetFileName (URI : string; Host : string) : string; var QuestionMarkPos : integer; begin QuestionMarkPos := Pos('?',URI); if QuestionMarkPos > 0 then Result := Copy(URI,1,QuestionMarkPos-1) else Result := URI; Result := AppendBackslash(GlobalConfiguration.WebsiteContentDirectory) + Host + Result; Result := ReplaceChar('/','\',Result); Result := ReplaceSubstring('%20',' ',Result); end; {***** Methods that must be synchronized with the main VCL thread *************} function ConvertChartToJPG (Chart : TChart) : string; var StringStream : TStringStream; Bitmap : TBitmap; JPEGImage : TJPEGImage; begin StringStream := TStringStream.Create(''); Bitmap := TBitmap.Create; JPEGImage := TJPEGImage.Create; try JPEGImage.CompressionQuality := 65; Bitmap.Width := Chart.Width; Bitmap.Height := Chart.Height; Chart.Draw(Bitmap.Canvas,Rect(0,0,Chart.Width,Chart.Height)); JPEGImage.Assign(Bitmap); Bitmap.Dormant; // transfer jpeg image data to string JPEGImage.SaveToStream(StringStream); // extract result from data string Result := StringStream.DataString; finally JPEGImage.Free; Bitmap.Free; StringStream.Free; end; end; {***** Original HTML Response routines ****************************************} const Spacer = ' '; {***** Main Screen ************************************************************} function CreateMainScreen : string; begin // header Result := HTMLPageHeader; // details if GlobalConfiguration.POS then Result := Result + '
Items
'; Result := Result + '| ' + Item.Name + ' | ' + ConvertDoubleToString(Item.Price) + ' | ' + ImageStr + ' |
Sales for period ' + FormatDate(BeginDate) + ' to ' + FormatDate(EndDate) + '
'; if SalespersonId <> 0 then Result := Result + 'Salesperson: ' + SalespersonName(SalespersonId) + '
'; Result := Result + '| Date | ' + 'Time | ' + 'Salesperson | ' + 'Total Price | ' + 'Items | ' + 'Payment Type | ' + '
| ' + Format('%-8.8s',[ShortFormatDate(Sale.Date)]) + ' | ' + '' + FormatDateTime('hh:mm:ss',Sale.Time) + ' | ' + '' + Format('%-15.15s ',[SalespersonName(Sale.SalespersonId)]) + ' | ' + '' + Format(' %15.15s',[FormatCurrencyForDisplay(Sale.TotalPrice)]) + ' | ' + '' + Format(' %-35.35s ',[Sale.SaleItemsAsString]) + ' | ' + '' + Format(' %-25.25s ',[Sale.PaymentItemsAsString]) + ' | ' + '
| ' + ' | ' + ' | TOTAL | ' + '' + Format(' %15.15s',[FormatCurrencyForDisplay(TotalTotalPrice)]) + ' | ' + '' + ' | ' + ' |