unit POIPost1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  dxCore, dxButtons, StdCtrls, TFlatMemoUnit, TFlatComboBoxUnit,
  TFlatEditUnit, dxCheckCtrls;

type
  TForm2 = class(TForm)
    btn_summit: TdxButton;
    ed_user: TFlatEdit;
    Label5: TLabel;
    GroupBox1: TGroupBox;
    Label4: TLabel;
    ed_name: TFlatEdit;
    cb_type: TFlatComboBox;
    Label3: TLabel;
    Label2: TLabel;
    ed_zone: TFlatEdit;
    ed_pathloc: TFlatEdit;
    Label1: TLabel;
    chk_nodesc: TdxCheckbox;
    ed_desc: TFlatMemo;
    dxButton1: TdxButton;
    procedure FormCreate(Sender: TObject);
    procedure btn_summitClick(Sender: TObject);
    procedure ed_userChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
     summituser : string;
     iniFile : string;
     procedure loadINI;
     procedure saveINI;
     procedure SetType(Name : string);
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses comobj, inifiles;

var
        summiturl : string = 'http://maps.eq2interface.com/submitpoi.php';

{$R *.DFM}

procedure summitdata(const URL, iname, itype, izone, iloc, nodesc, idesc, user : string);
var
 WebBrowser1: Variant;
 VPostData, VFlags, VFrame, VHeaders: OleVariant;
 iLoop: Integer;
 PostData: string;
begin
 PostData := 'name='+iname+'&type='+itype+'&zone='+izone+'&loc='+iloc+'&nodescription='+nodesc+'&description='+idesc+
        '&submitting=1&username='+user+'&summit=Submit this POI';
 WebBrowser1 := CreateOleObject('InternetExplorer.Application');

 if Length(PostData)> 0 then
 begin
  VHeaders := 'Content-Type: application/x-www-form-urlencoded'+ #10#13#0;
  VPostData := VarArrayCreate([0, Length(PostData)], varByte);
  for iLoop := 0 to Length(PostData)- 1 do
  begin
    VPostData[iLoop] := Ord(PostData[iLoop+ 1]);
  end;
  VPostData[Length(PostData)] := 0;
  TVarData(VPostData).vType := varArray;
 end;

 VFlags := 0;
 WebBrowser1.Navigate2(url, VFlags, VFrame, VPostData, VHeaders);
 WebBrowser1.Visible := True;
end;

procedure TForm2.loadINI;
var
        inif : TInifile;
        buf : TStringList;
        i : integer;
begin
        try
        if fileexists(inifile) then begin
        inif := TIniFile.Create(inifile);
        try
                summituser := inif.ReadString('CONFIG','USER','');
                ed_user.Text := summituser;
                summiturl := inif.ReadString('CONFIG','POIURL','http://maps.eq2interface.com/submitpoi.php');
                if inif.SectionExists('MAPTYPES') then begin
                        buf := TStringList.Create;
                        try
                        inif.ReadSectionValues('MAPTYPES',buf);
                        if buf.Count>0 then begin
                        cb_type.Clear;
                        for i:=0 to pred(buf.Count) do
                                cb_type.Items.Add(copy(buf.Strings[i],pos('=',buf.Strings[i])+1,32767));
                        end;
                        finally
                                buf.free;
                        end;
                end;
        finally
                inif.free;
        end;
        end;
        except
        on e:exception do Showmessage(e.message);
        end;
end;

procedure TForm2.saveINI;
var
        inif : TIniFile;
begin
        try
        inif := TiniFile.Create(inifile);
        try
                inif.WriteString('CONFIG','USER',summituser);
        finally
                inif.free;
        end;
        except
        on e:exception do showmessage(e.message);
        end;
end;

procedure TForm2.SetType(Name : string);
var
        i, ix : integer;
begin
        ix := -1;
        if Name = 'NAME' then Name := 'NAMED';
        if cb_type.Items.Count>0 then
        for i:=0 to pred(cb_type.Items.count) do begin
                if pos(Name,cb_type.items.strings[i])=1 then begin
                        ix := i;
                        break;
                end;
        end;
        cb_type.ItemIndex := ix;
end;

procedure TForm2.FormCreate(Sender: TObject);
var
        ix : integer;
begin
        ix := GetSystemDefaultLangID;
        if lo(ix)<>LANG_KOREAN then begin
                Font.Name := 'MS Sans Serif';
                Font.Size := 8;
                btn_summit.Caption := 'Summit';
                dxbutton1.Caption := '&Close';
                chk_nodesc.Caption := 'No description';
        end;
        inifile := changefileext(application.exename,'.ini');
        loadINI;
end;

procedure TForm2.btn_summitClick(Sender: TObject);
var
        nodesc : string;
begin
        try
        if chk_nodesc.Checked then nodesc := 'true' else nodesc := 'false';
        summitdata(summiturl,ed_name.text,cb_type.text,ed_zone.text,ed_pathloc.text,nodesc,ed_desc.text,summituser);
        except
        on e: exception do Showmessage(e.message);
        end;
end;

procedure TForm2.ed_userChange(Sender: TObject);
begin
        summituser := ed_user.Text;
end;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
        saveINI;
end;

end.
