#include "wsubformHTML.h"	//サブフォーム専用ヘッダファイルをインクルードする。
#include <fcgi_stdio.h>

extern char gridtitles[MAX_POS][MAX_LEN];	//wsubformHTMLが利用するgridのタイトル。

extern TextBox	 *begin;	//textboxで使用する連鎖ポインタの開始位置
extern TextBox	 *tp;	//textboxで使用する連鎖ポインタ

typedef struct stat Dir;	//ファイル操作用
static Dir dirptr;
static Dir  *fptr = &dirptr;

char tmp[MAX_STR];
static int sqlcode = 0;	//PostgreSQLの返すコード

int DBcount[MAX_FORM];	//wsubformHTMLで利用するDBの現在の最大行数
extern char KEY[256][MAX_STR];	//INSERTとUPDATEが使用する更新項目
char COMMANDNAME[256];	//実行するCGI自身の名前

int DBConnect(void)
{
	// DB接続用変数宣言です。DB名、ユーザ名、パスワードを設定してください。
	EXEC SQL BEGIN DECLARE SECTION;
		char dbname[12];
		char user[12];
		char passwd[12];
	EXEC SQL END DECLARE SECTION;

	strcpy(dbname,"apsch");
	strcpy(user,"cms");
	strcpy(passwd,"cms");

#ifdef DEBUG
	// ECPGデバッグ文出力
	ECPGdebug (0, stderr);
#endif

	// 接続
	memset (sqlca.sqlstate, '0', 5);
	EXEC SQL CONNECT TO :dbname AS dbConnection user :user USING :passwd;
	if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"CONNECT エラー。終了します。:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		exit (EXIT_FAILURE);
	}
}

int otodoke_Insert(int no)
{
	static char DBbuff[MAX_STR];
	int i = 0;
	char *qs;
	int qcount;
	char *poststr;	//POSTメソッド用のポインタ
	char *ps;
	int len;
	int n;
	char *env1,*env2;

	DBConnect();

	memset (sqlca.sqlstate, '0', 5);

	EXEC SQL BEGIN DECLARE SECTION;
		int rec_count;
		int rec_max;
		char	 key[256][MAX_STR];
		int	No;	//TEXT
		char	yubinNo[7 + 1];	//TEXT
		char	todofuken[24 + 1];	//TEXT
		char	jusho1[96 + 1];	//TEXT
		char	jusho2[96 + 1];	//TEXT
		char	shimei1[96 + 1];	//TEXT
		char	shimei_f1[192 + 1];	//TEXT
		char	shimei2[96 + 1];	//TEXT
		char	shimei_f2[200 + 1];	//TEXT
		char	TEL[13 + 1];	//TEXT
		char	hinmei[90 + 1];	//TEXT
		int		hinsyu;		//NUMERIC
		char	yoryo[5 + 1];	//TEXT
		char	hm_kubun[2 + 1];	//TEXT
		char	grade[144 + 1];	//TEXT
		char	size[10 + 1];	//TEXT
		int		kingaku;		//NUMERIC
		unsigned char		jikankibou;		//BOOL
		int		takuhai_s;		//NUMERIC
		unsigned char		tuchi;		//BOOL
		char	denNo[13 + 1];	//TEXT
		unsigned char		tokui;		//BOOL
		char	uketukeDATE[10 + 1];	//TEXT
		char	expDATE[10 + 1];	//TEXT
		char	hopeDATE[10 + 1];	//TEXT
		char	bikou[256 + 1];	//TEXT
		char	hassoCD[5 + 1];	//TEXT
		char	hatutenCD[7 + 1];	//TEXT
		unsigned char		hatuEND;		//BOOL
		unsigned char		prEND;		//BOOL
		int		denNUM;		//NUMERIC
		int		hakoNUM;		//NUMERIC
		char	memo[1024 + 1];	//TEXT
		unsigned char		reserve;		//BOOL
		char	resDATE[10 + 1];	//TEXT
		unsigned char		print;		//BOOL
		int		prNUM;		//NUMERIC
		char	daitaiCD[15 + 1];	//TEXT
		unsigned char		daitai;		//BOOL
		char	FAX[13 + 1];	//TEXT
		char	keitaiTEL[13 + 1];	//TEXT
		int		hopeTIME;		//NUMERIC
		int		hopeTIME2;		//NUMERIC
		int		hopeTIME3;		//NUMERIC
		unsigned char		umu;		//BOOL
		int		soryo;		//NUMERIC
		int		hatu_kosuu;		//NUMERIC
		int		hakodai;		//NUMERIC
		char	chitai[60 + 1];	//TEXT
		char	mail[50 + 1];	//TEXT
		int		tesuu;		//NUMERIC
		int		tac;		//NUMERIC
		unsigned char		reitou;		//BOOL
		char	YahooID[32 + 1];	//TEXT
		char	shiwakeCD[13 + 1];	//TEXT
		unsigned char		kariseikyu;		//BOOL
		int		cc_kingaku;		//NUMERIC
		int		st_kingaku;		//NUMERIC
		int		base_soryo;		//NUMERIC
		unsigned char		seikyuEND;		//BOOL
		int		den_hakoNUM;		//NUMERIC
		int		soukin_tesuuryo;		//NUMERIC
	EXEC SQL END DECLARE SECTION;

	sqlcode = 0;


	if((qs = getenv("REQUEST_METHOD")) != (char *)NULL)
	{
		if(!strcmp(qs,"GET"))
		{
			if((qs = getenv("QUERY_STRING")) != (char *)NULL)
			{
			//	デバッグの場合必要に応じて以下の関数をコメントを外して使用して下さい。
				len = strlen(qs);
				qcount = query_postHTML(qs,'&',len);
			//	qcount = query_getHTML(qs,'&');
				sf_tbegin();
				for(i=0;i < qcount;i++)
				{
					if(strlen(decodeUTF(qt.get[i])) > tp->len)
					{
						strncpy(key[i],decodeUTF(qt.get[i]),tp->len);
					}
					else
					{
						sprintf(key[i],"%s",decodeUTF(qt.get[i]));
					}
					sf_tnext();
				}
			}
		}
		else if(!strcmp(qs,"POST"))
		{
			if((ps = getenv("CONTENT_LENGTH")) != (char *)NULL)
			{
				len = atoi(ps);
				poststr = malloc(len+1);
				n = fread(poststr,1,len,stdin);
				qcount = query_postHTML(poststr,'&',len);
			//	qcount = query_getHTML(poststr,'&');
				sf_tbegin();
				for(i=0;i < qcount;i++)
				{
					if(strlen(decodeUTF(qt.get[i])) > tp->len)
					{
						strncpy(key[i],decodeUTF(qt.get[i]),tp->len);
					}
					else
					{
						sprintf(key[i],"%s",decodeUTF(qt.get[i]));
					}
					sf_tnext();
				}
			}
		}
	}
	else
	{
		sprintf(key[0],"NONE");
		printf("%s<br>\n",key[0]);
	}

	for(i=0;i<qcount;i++)
		sprintf(KEY[i],"%s",key[i]);
	sf_tgetDBallHTML(0);

	// Noの最大数を取得
	EXEC SQL 
	SELECT 
	COUNT(*)
	INTO :rec_count
	FROM	otodoke
	WHERE hassoCD= :key[26];

	// SELECTエラー 
	if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"SELECT COUNTエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1) ;
	}

	if(rec_count == 0)
	{
		sprintf(hassoCD,"%s",key[26]);
		rec_max = 0;
	}
	else
	{
		// 以下の項目はユニークな項目を利用してインサート時の項目番号等を増加するために利用します
		// 利用する場合はコメントを外して下さい。
		// あるDB項目の最大数を取得
		EXEC SQL 
		SELECT 
		MAX(No)
		INTO :rec_max
		FROM	otodoke;
	//	WHERE	hassoCD = :key[26];

		// SELECTエラー 
		if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
		{
			sprintf(tmp,"%s->SELECT MAX()エラー:%d - %s",COMMANDNAME,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
		//	logmsg(tmp);
			return(-1) ;
		}
	}

	// インサート
	// テーブル項目をsplitbDBbuff[]からDB配列にセットする
	sf_assputDB(no,0,DBbuff,5 + 1);
	No = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,1,yubinNo,7 + 1);
	sf_assputDB(no,2,todofuken,24 + 1);
	sf_assputDB(no,3,jusho1,96 + 1);
	sf_assputDB(no,4,jusho2,96 + 1);
	sf_assputDB(no,5,shimei1,96 + 1);
	sf_assputDB(no,6,shimei_f1,192 + 1);
	sf_assputDB(no,7,shimei2,96 + 1);
	sf_assputDB(no,8,shimei_f2,200 + 1);
	sf_assputDB(no,9,TEL,13 + 1);
	sf_assputDB(no,10,hinmei,90 + 1);
	sf_assputDB(no,11,DBbuff,3 + 1);
	hinsyu = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,12,yoryo,5 + 1);
	sf_assputDB(no,13,hm_kubun,2 + 1);
	sf_assputDB(no,14,grade,144 + 1);
	sf_assputDB(no,15,size,10 + 1);
	sf_assputDB(no,16,DBbuff,5 + 1);
	kingaku = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,17,DBbuff,3 + 1);
	jikankibou = (unsigned char)DBbuff[0];	//文字(char)をBOOL型(unsigned char)に入れ替える。
	sf_assputDB(no,18,DBbuff,3 + 1);
	takuhai_s = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,19,DBbuff,3 + 1);
	tuchi = (unsigned char)DBbuff[0];	//文字(char)をBOOL型(unsigned char)に入れ替える。
	sf_assputDB(no,20,denNo,13 + 1);
	sf_assputDB(no,21,DBbuff,3 + 1);
	tokui = (unsigned char)DBbuff[0];	//文字(char)をBOOL型(unsigned char)に入れ替える。
	sf_assputDB(no,22,uketukeDATE,10 + 1);
	sf_assputDB(no,23,expDATE,10 + 1);
	sf_assputDB(no,24,hopeDATE,10 + 1);
	sf_assputDB(no,25,bikou,256 + 1);
	sf_assputDB(no,26,hassoCD,5 + 1);
	sf_assputDB(no,27,hatutenCD,7 + 1);
	sf_assputDB(no,28,DBbuff,3 + 1);
	hatuEND = (unsigned char)DBbuff[0];	//文字(char)をBOOL型(unsigned char)に入れ替える。
	sf_assputDB(no,29,DBbuff,3 + 1);
	prEND = (unsigned char)DBbuff[0];	//文字(char)をBOOL型(unsigned char)に入れ替える。
	sf_assputDB(no,30,DBbuff,3 + 1);
	denNUM = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,31,DBbuff,3 + 1);
	hakoNUM = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,32,memo,1024 + 1);
	sf_assputDB(no,33,DBbuff,2 + 1);
	reserve = (unsigned char)DBbuff[0];	//文字(char)をBOOL型(unsigned char)に入れ替える。
	sf_assputDB(no,34,resDATE,10 + 1);
	sf_assputDB(no,35,DBbuff,2 + 1);
	print = (unsigned char)DBbuff[0];	//文字(char)をBOOL型(unsigned char)に入れ替える。
	sf_assputDB(no,36,DBbuff,3 + 1);
	prNUM = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,37,daitaiCD,15 + 1);
	sf_assputDB(no,38,DBbuff,2 + 1);
	daitai = (unsigned char)DBbuff[0];	//文字(char)をBOOL型(unsigned char)に入れ替える。
	sf_assputDB(no,39,FAX,13 + 1);
	sf_assputDB(no,40,keitaiTEL,13 + 1);
	sf_assputDB(no,41,DBbuff,3 + 1);
	hopeTIME = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,42,DBbuff,2 + 1);
	hopeTIME2 = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,43,DBbuff,3 + 1);
	hopeTIME3 = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,44,DBbuff,3 + 1);
	umu = (unsigned char)DBbuff[0];	//文字(char)をBOOL型(unsigned char)に入れ替える。
	sf_assputDB(no,45,DBbuff,4 + 1);
	soryo = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,46,DBbuff,4 + 1);
	hatu_kosuu = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,47,DBbuff,4 + 1);
	hakodai = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,48,chitai,60 + 1);
	sf_assputDB(no,49,mail,50 + 1);
	sf_assputDB(no,50,DBbuff,4 + 1);
	tesuu = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,51,DBbuff,4 + 1);
	tac = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,52,DBbuff,2 + 1);
	reitou = (unsigned char)DBbuff[0];	//文字(char)をBOOL型(unsigned char)に入れ替える。
	sf_assputDB(no,53,YahooID,32 + 1);
	sf_assputDB(no,54,shiwakeCD,13 + 1);
	sf_assputDB(no,55,DBbuff,3 + 1);
	kariseikyu = (unsigned char)DBbuff[0];	//文字(char)をBOOL型(unsigned char)に入れ替える。
	sf_assputDB(no,56,DBbuff,4 + 1);
	cc_kingaku = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,57,DBbuff,4 + 1);
	st_kingaku = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,58,DBbuff,4 + 1);
	base_soryo = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,59,DBbuff,3 + 1);
	seikyuEND = (unsigned char)DBbuff[0];	//文字(char)をBOOL型(unsigned char)に入れ替える。
	sf_assputDB(no,60,DBbuff,3 + 1);
	den_hakoNUM = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。
	sf_assputDB(no,61,DBbuff,4 + 1);
	soukin_tesuuryo = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。

	// 以下の項目はユニークな項目を利用してインサート時の項目番号等を増加するために利用します
	// 利用する場合はコメントを外して下さい。
	No = rec_max+1;

	// 対象レコードをADD
	EXEC SQL INSERT INTO otodoke
	(
		No,
		yubinNo,
		todofuken,
		jusho1,
		jusho2,
		shimei1,
		shimei_f1,
		shimei2,
		shimei_f2,
		TEL,
		hinmei,
		hinsyu,
		yoryo,
		hm_kubun,
		grade,
		size,
		kingaku,
		jikankibou,
		takuhai_s,
		tuchi,
		denNo,
		tokui,
		uketukeDATE,
		expDATE,
		hopeDATE,
		bikou,
		hassoCD,
		hatutenCD,
		hatuEND,
		prEND,
		denNUM,
		hakoNUM,
		memo,
		reserve,
		resDATE,
		print,
		prNUM,
		daitaiCD,
		daitai,
		FAX,
		keitaiTEL,
		hopeTIME,
		hopeTIME2,
		hopeTIME3,
		umu,
		soryo,
		hatu_kosuu,
		hakodai,
		chitai,
		mail,
		tesuu,
		tac,
		reitou,
		YahooID,
		shiwakeCD,
		kariseikyu,
		cc_kingaku,
		st_kingaku,
		base_soryo,
		seikyuEND,
		den_hakoNUM,
		soukin_tesuuryo
	)
	VALUES
	(
		:No,
		coalesce(:yubinNo,' ','0'),
		coalesce(:todofuken,' ','0'),
		coalesce(:jusho1,' ','0'),
		coalesce(:jusho2,' ','0'),
		coalesce(:shimei1,' ','0'),
		coalesce(:shimei_f1,' ','0'),
		coalesce(:shimei2,' ','0'),
		coalesce(:shimei_f2,' ','0'),
		coalesce(:TEL,' ','0'),
		coalesce(:hinmei,' ','0'),
		:hinsyu,
		coalesce(:yoryo,' ','0'),
		coalesce(:hm_kubun,' ','0'),
		coalesce(:grade,' ','0'),
		coalesce(:size,' ','0'),
		:kingaku,
		:jikankibou,
		:takuhai_s,
		:tuchi,
		coalesce(:denNo,' ','0'),
		:tokui,
		coalesce(:uketukeDATE,' ','0'),
		coalesce(:expDATE,' ','0'),
		coalesce(:hopeDATE,' ','0'),
		coalesce(:bikou,' ','0'),
		coalesce(:hassoCD,' ','0'),
		coalesce(:hatutenCD,' ','0'),
		:hatuEND,
		:prEND,
		:denNUM,
		:hakoNUM,
		coalesce(:memo,' ','0'),
		:reserve,
		coalesce(:resDATE,' ','0'),
		:print,
		:prNUM,
		coalesce(:daitaiCD,' ','0'),
		:daitai,
		coalesce(:FAX,' ','0'),
		coalesce(:keitaiTEL,' ','0'),
		:hopeTIME,
		:hopeTIME2,
		:hopeTIME3,
		:umu,
		:soryo,
		:hatu_kosuu,
		:hakodai,
		coalesce(:chitai,' ','0'),
		coalesce(:mail,' ','0'),
		:tesuu,
		:tac,
		:reitou,
		coalesce(:YahooID,' ','0'),
		coalesce(:shiwakeCD,' ','0'),
		:kariseikyu,
		:cc_kingaku,
		:st_kingaku,
		:base_soryo,
		:seikyuEND,
		:den_hakoNUM,
		:soukin_tesuuryo
	);

	// 登録エラー
	if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		// ロールバック
		env1 = getenv("REMOTE_ADDR");
		env2 = getenv("HTTP_USER_AGENT");
		sprintf(tmp,"INSERTエラー:%d - %s:%s:%s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc,env1,env2);
		logmsg(tmp);
		EXEC SQL ROLLBACK WORK;
		EXEC SQL END;
		return(-1);
	}

	// コミット
	EXEC SQL COMMIT;
	EXEC SQL END;

	// 結果チェック
	if (sqlca.sqlcode == 0)
	{
		sprintf(tmp,"INSERT結果チェック:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
	}

	// Noの最大数を取得
	EXEC SQL 
	SELECT 
	COUNT(*)
	INTO :rec_count
	FROM	otodoke
	WHERE hassoCD= :key[26];

	// SELECTエラー 
	if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"SELECT COUNTエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1) ;
	}

	DBcount[no] = rec_count;

	// 切断
	sqlca.sqlcode = 0;
	EXEC SQL DISCONNECT dbConnection;
	return(0);
}

// DBから入出力(画面)ウインドウに書き込みます。
void otodoke_Insert_text_writeHTML(int no, int post, int line,int maxcol, char **db_titles)
{
	int i;
	char s[MAX_TMP];

	printf("Content-type: text/html\n\n");
	printf("<html>\n");
	printf("<head>\n");
	printf("<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n"); 
	printf("<title>form text_writeHTML page</title>\n");
	printf("</head>\n");
	printf("<body>\n");
	printf("<center>\n");
	printf("<br>\n");
	printf("<table border=0>\n");
	printf("<tr bgcolor=#ffffff>\n");
	printf("<a href=\"#\" onClick=\"history.back(); return false;\">戻る</a>\n");
//	printf("<form method=\"get\"  action=\"/cgi-bin/kokyaku_Fetch.fcgi\">\n");
//	printf("<form method=\"get\"  action=\"/cgi-bin/kokyaku_Fetch.fcgi?field00=%s&amp;field01=%s\">\n",KEY[26],"#form00012");
	printf("<form method=\"post\"  action=\"/cgi-bin/kokyaku_Fetch.fcgi?field00=%s&amp;field01=#form%05d\">\n",KEY[26],DBcount[no]-1);
//	printf("<input type=\"hidden\" name=\"field00\" size=\"1\" value=\"%s\" maxlength=\"1\" ><br>\n",KEY[26]);
//	printf("<input type=\"hidden\" name=\"field01\" size=\"1\" value=\"%s\" maxlength=\"1\" ><br>\n","#form00012");
	printf("</tr>");
	printf("<input type=\"submit\" value=\"INSERTが完了しました。戻ります\">\n");
	printf("</form>\n");
	printf("</center>\n");
}

int subformHTML(void)
{
	int i;
	char s[MAX_STR];

	int startline;

	int line;
	setlocale(LC_ALL,"");

//------------------------------------------------------------------------
//下ののハイフンのラインまでの以下の関数はDBと画面の設計を実際のフォームに適用します。
//これらの関数が無い場合は設計情報はDB設計以外は反映されません。

	static int xcol = 242;
	static int rows = 73;

//for label
	static int label_length[] = {0};
	static int label_no[] = {0};
	static int label_align[] = {0};
	static char *label_text[1][128] = {""};
	static int label_x[] = {0};
	static int label_y[] = {0};
//for textbox
	static int textbox_length[] = {5,7,24,96,96,96,192,96,200,13,90,5,5,2,144,10,15,3,3,3,13,3,10,10,10,209,5,7,3,3,5,5,209,2,10,2,5,15,2,13,13,3,2,3,3,15,6,15,60,50,15,15,2,32,13,3,15,15,15,3,5,15,0};
	static int textbox_no[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,0};
	static int textbox_align[] = {2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,1,2,1,2,2,2,2,2,2,2,2,2,2,2,1,1,2,2,2,2,1,2,2,2,2,1,1,1,2,1,1,1,2,2,1,1,2,2,2,2,1,1,1,2,1,1,0};
	static int textbox_action[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static int textbox_skipstep[] = {1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0};
	static int textbox_field[] = {2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,4,3,2,3,1,3,1,1,1,1,1,1,3,3,2,2,1,3,1,3,2,1,3,1,1,1,1,1,3,4,4,4,1,1,4,4,3,1,1,3,4,4,4,3,2,4,0};
	static int textbox_x[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static int textbox_y[] = {6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,0};


//for grid
	static int cell_length[] = {2,2,2,2,2,2,3,3,3,3,3,2,2,2,2,2,5,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,2,3,2,3,2,2,3,3,3,2,3,3,4,4,4,3,3,4,4,2,3,3,3,4,4,4,3,3,4,0};
	static int cell_align[] = {2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,1,2,1,2,2,2,2,2,2,2,2,2,2,2,1,1,2,2,2,2,1,2,2,2,2,1,1,1,2,1,1,1,2,2,1,1,2,2,2,2,1,1,1,2,1,1,0};
	static int cell_action[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static int grid_field[] = {2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,4,3,2,3,1,3,1,1,1,1,1,1,3,3,2,2,1,3,1,3,2,1,3,1,1,2,2,2,3,4,4,4,1,1,4,4,3,1,1,3,4,4,4,3,2,4,0};
	static int grid_skipstep[] = {1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0};
	char *grid_titles[63][128] = {"Grid_1","Grid_2","Grid_3","Grid_4","Grid_5","Grid_6","Grid_7","Grid_8","Grid_9","Grid_10","Grid_11","Grid_12","Grid_13","Grid_14","Grid_15","Grid_16","Grid_17","Grid_18","Grid_19","Grid_20","Grid_21","Grid_22","Grid_23","Grid_24","Grid_25","Grid_26","Grid_27","Grid_28","Grid_29","Grid_30","Grid_31","Grid_32","Grid_33","Grid_34","Grid_35","Grid_36","Grid_37","Grid_38","Grid_39","Grid_40","Grid_41","Grid_42","Grid_43","Grid_44","Grid_45","Grid_46","Grid_47","Grid_48","Grid_49","Grid_50","Grid_51","Grid_52","Grid_53","Grid_54","Grid_55","Grid_56","Grid_57","Grid_58","Grid_59","Grid_60","Grid_61","Grid_62",""};
	static char *db_titles[63][128] = {"No","yubinNo","todofuken","jusho1","jusho2","shimei1","shimei_f1","shimei2","shimei_f2","TEL","hinmei","hinsyu","yoryo","hm_kubun","grade","size","kingaku","jikankibou","takuhai_s","tuchi","denNo","tokui","uketukeDATE","expDATE","hopeDATE","bikou","hassoCD","hatutenCD","hatuEND","prEND","denNUM","hakoNUM","memo","reserve","resDATE","print","prNUM","daitaiCD","daitai","FAX","keitaiTEL","hopeTIME","hopeTIME2","hopeTIME3","umu","soryo","hatu_kosuu","hakodai","chitai","mail","tesuu","tac","reitou","YahooID","shiwakeCD","kariseikyu","cc_kingaku","st_kingaku","base_soryo","seikyuEND","den_hakoNUM","soukin_tesuuryo",0};
	static int grid_sx = 0;
	static int grid_ex = 239;
	static int grid_sy = 4;
	static int grid_ey = 4;

	static int maxtext;
	static int no = 0;

	char **gt;
	char **lt;

	gt = (char **)&grid_titles;

	xcol = MakeWsubFormHTML(no,xcol,rows,0,2,grid_sx,grid_sy,grid_ex,grid_ey,cell_length,cell_align,cell_action,grid_field,grid_skipstep,gt,62);

	lt = (char **)&label_text;

//	以下の関数は<SELECT>でコンボボックスを作成する場合、一つのCGIで重複して利用出来ませんのでどちらかを削除してください。
	maxtext = MakeTextBoxHTML(no,0,2,xcol,rows,label_no,lt,label_x,label_y,label_length,textbox_no,textbox_x,textbox_y,textbox_length,textbox_align,textbox_action,textbox_field,textbox_skipstep, 62);

//------------------------------------------------------------------------


	if(otodoke_Insert(0) != -1)
	{
		otodoke_Insert_text_writeHTML(no,0,0,maxtext,*db_titles);
	}
	else
	{
		printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n"); 
		printf("<title>DB-ERROR</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("<br>\n");
		printf("<table border=0>\n");
		printf("<tr bgcolor=#ffffff>\n");
		printf("INSERTが失敗しました。<br>\n");
		printf("<a href=\"#\" onClick=\"history.back(); return false;\">戻る</a>\n");
		printf("</form>\n");
		printf("</tr>\n");
		printf("</form>\n");
	}
}

int main(int argc, char *argv[])
{
	sprintf(COMMANDNAME,"%s",argv[0]);
	while (FCGI_Accept() >= 0) {
		subformHTML();
	}
}

