<?php
//	$mp_list_arg = array();
//	$mp_list_arg['account_id']		: 
//	$mp_list_arg['table_name_view']		: 
//	$mp_list_arg['table_name_edit']		: 
//	$mp_list_arg['table_name_update']	: 
//	$mp_list_arg['id_item']			: データベースID項目
//	$mp_list_arg['must_item']		: データベース更新必須項目
//	$mp_list_arg['add_filter']		: 追加フィルタ(.php)		※ add_where_create()コールバック(?)
//	$mp_list_arg['template_view']		: リスト形式テンプレート(.php)
//	$mp_list_arg['edit_list_all']		: リスト形式編集有無 "yes"(default) / "no"
//	$mp_list_arg['add_list']		: リスト形式追加 "yes" / "no"(default)
//	$mp_list_arg['edit_button_item']	: 修正ボタン表示項目
//	$mp_list_arg['input_new']		: 新規ボタン有無 "yes"(default) / "no"
//	$mp_list_arg['input_php']		: 新規/修正ページ(.php) (default:"input.php")
//	$mp_list_arg['list_filter']		: フィルタ有無 "yes"(default) / "no"(ページ分割もなし)
//	$mp_list_arg['list_edit_right_add_html']: 一覧編集でページ右側に追加表示するHTML(.php/.htm)
//	$mp_list_arg['filter_keysel_break']	: キーワード検索フィルタを改行する "no"(default) / "yes"
//	$mp_list_arg['view_description']	: 一覧画面説明
//	$mp_list_arg['edit_description']	: 一括修正画面説明
//	$mp_list_arg['use_privacy']		: c_privacy機能使用
//
//	$mp_list_arg['sql_for_view']		: 一覧用SQLの直接渡し ('table_name_view'を使わない)
//	$mp_list_arg['sql_for_edit']		: 一覧用SQLの直接渡し ('table_name_view'を使わない)
//
//	$mp_list_arg['sql_create_callback']	: SQL作成に、mp_list_sql_createの代わりの関数をコールバック
//	$mp_list_arg['list_option_callback']	: 頁行数の後のオプション用関数コールバック
//
//	$item_tbl = array();
//	$item_tbl[] = array(	"表示名"=>""
//				"列名"=>""
//				"type"=>"text","textarea","select","date","time"
//				      =>"no_edit"				:編集なし
//				      =>"no_edit_no_col"			:編集なし＆編集一覧での列表示もなし
//				"cols"=>10
//				"rows"=>2
//				"size"=>20
//				"width"=>"80"					:テーブル<th width='80'>
//				"ime-mode"=>"active","inactive","disabled"
//				"http_arg_GET名"=>"cat"
//				"select_num_min"=>1				:編集select数値(最少)
//				"select_num_max"=>10				:編集select数値(最大)
//				"参照テーブル"=>"m_category"
//				"参照テーブル表示色"=>"c_categoryDisplayColor"
//				"参照テーブル表示列"=>"c_categoryName"
//				"参照テーブル表示順"=>"c_categoryDisplayOrder"
//				"参照テーブルユーザー"=>"共有"			:参照テーブルが全ユーザー共有の場合
//				"カラー表示列名"=>"c_categoryDisplayColor",
//				"イメージ表示列名"=>"c_iconImage",
//				"文字検索"=>"Y"
//				"toInt"=>"Y"					:整数に変換
//				"a_tag"=>"Y"					:<a href..変換
//				"htmlScript"=>"Y"				:HTML<script>許可(textareaのみ)
//				"date_http_arg_y"=>"selY"			:type=dateの追加行デフォルト年$_GET名
//				"date_http_arg_m"=>"selM"			:type=dateの追加行デフォルト月$_GET名
//				"date_http_arg_d"=>"selD"			:type=dateの追加行デフォルト日$_GET名
//				"filter_type"=>"radio"				:カテゴリフィルタタイプ(デフォルト：select)
//				"firstYear"=>1980				:"date"の編集時のselect開始年
//				"toYear"=>10					:"date"の編集時のselect最終年(当年からN年後)
//				"filter_use"=>"Y"				:"select"以外の項目でフィルタを付ける
//				"filter_c_delete"=>"no"				:フィルタ用のテーブル、ビューにc_deleteが無い場合
//	$order_tbl = array();
//	$order_tbl[] = array(   "表示名"=>"登録最新順"				:配列1個目がデフォルト
//				"get_order_name"=>"new",				:uri GET変数名
//				"order_by"=>"id_schedule desc"
//
// ****************************************************************
function mp_list_view($arg, $item_tbl, $order_tbl, $http_arg) {
// ****************************************************************
	$account_id	= $arg['account_id']."";
	$table_name	= $arg['table_name_view']."";
	$id_item	= $arg['id_item']."";
	$add_filter	= $arg['add_filter']."";
	$template	= $arg['template_view']."";
	$edit_list_all	= $arg['edit_list_all']."";
	$add_list	= $arg['add_list']."";
	$edit_button_item	= $arg['edit_button_item']."";
	$input_new	= $arg['input_new']."";
	$list_filter	= $arg['list_filter']."";
	$filter_keysel_break	= $arg['filter_keysel_break']."";
	$use_privacy	= $arg['use_privacy']."";
	$sql_for_view	= $arg['sql_for_view']."";
	$sql_create_callback	= $arg['sql_create_callback']."";
	$list_option_callback	= $arg['list_option_callback']."";
	$view_description = $arg['view_description'];
	$add_row_use	= $arg['add_row_use']."";

	if ($arg['input_php']."" <> "") {
		$input_php = $arg['input_php']."";
	} else {
		$input_php = "input.php";	// default
	}
	if ($add_filter <> "") {
		require($add_filter);
		$add_where = add_where_create($http_arg);
	}
	$con = my_mysql_connect(_DB_SCHEMA);
	$sortorder = $http_arg['sort'];
	if ($sortorder."" == "") {
		$sortorder = $order_tbl[0]['get_order_name'];
	}
	$keystring = keystr_fix($http_arg['key']);
	$pageline = $http_arg['pl'];
	$sel_filter = array();
	foreach ($item_tbl as $id=>$item) {
		if ($item['http_arg_GET名'] <> '') {
			$sel_filter[] = array("arg"=>$item['http_arg_GET名'], "colname"=>$item['列名'], "data"=>$http_arg[$item['http_arg_GET名']]);
		}
	}
?>
<div id="mp_list_body">
<table><!-- ### -->
<tr><td nowrap style="white-space:nowrap">
<?php
	if ($list_filter <> "no") {
		mp_list_filter($pageline, $keystring, $item_tbl, $sel_filter, $account_id, $table_name, $http_arg, $add_filter, $add_where, $filter_keysel_break, $list_option_callback);
	} else {
		$add_where = "";
	}
	if ($sql_create_callback <> "") {
		$sql = $sql_create_callback($account_id, $table_name, $item_tbl, $order_tbl, $sortorder, $keystring, $sel_filter, $use_privacy, $add_where);
	} elseif ($sql_for_view <> "") {
		$sql = mp_list_sql_add_create($sql_for_view, $table_name, $item_tbl, $order_tbl, $sortorder, $keystring, $sel_filter, $add_where);
	} else {
		$sql = mp_list_sql_create($account_id, $table_name, $item_tbl, $order_tbl, $sortorder, $keystring, $sel_filter, $use_privacy, $add_where);
	}
	$rs = my_mysql_query_debug_print($sql);
	$rowcnt = mysql_num_rows($rs);
	mp_list_get_page_start_end($pageline, $rowcnt, $page, $startline, $endline, $pagemax, $list_filter);
?>

</td></tr>
<tr><td nowrap style="white-space:nowrap">

<span id="mp_list_option">
<span id="mp_list_sort_menu">
	<ul>
<?php
	foreach ($order_tbl as $id=>$item) {
?>
		<li<?php if ($item['get_order_name'] == $sortorder) echo ' id="mp_list_sort_menu_current"' ?>><a href="?sort=<?= $item['get_order_name'] ?>&<?= query_from_http_arg_pool($http_arg, 'sort') ?>"><?= $item['表示名'] ?></a></li>
<?php
	}
?>
	</ul>
</span><!-- id="mp_list_sort_menu" -->
<?php if (is_write_permit() == True) {	// ******************** 書込権限チェック (始まり) ******************* ?>
<span id="mp_list_edit_new_button">
	<ul>
<?php
	if ($input_new <> "no") {
?>
		<li><a id="mp_list_new_button" href="<?= $input_php ?>?uid=<?= $account_id ?>&<?= query_from_http_arg_pool($http_arg, 'sort') ?>">新規登録</a></li>
<?php
	}
	if ($edit_list_all <> "no") {
?>
		<li><a id="mp_list_new_button" href="<?= $_SERVER['SCRIPT_NAME'] ?>?edit=y&<?= $_SERVER['QUERY_STRING'] ?>">一括修正/<?= $add_row_use <> 'no'? '追加/' : '' ?>削除</a></li>
<?php
	}
	if ($add_list == "yes") {
		$qry_ary = explode('&', $_SERVER['QUERY_STRING']);
		$add_qry = '';
		foreach ($qry_ary as $query) {
			if (strncmp($query, 'page=', 5) != 0 and strncmp($query, 'sort=', 5) != 0) {
				if ($add_qry <> '') $add_qry .= '&';
				$add_qry .= $query;
			}
		}
?>
		<li><a id="mp_list_new_button" href="<?= $_SERVER['SCRIPT_NAME'] ?>?edit=a&<?= $add_qry ?>&sort=new">一括追加</a></li>
<?php
	}
?>
	</ul>
</span><!-- id="mp_list_edit_new_button" -->
<?php }				// ******************** 書込権限チェック (終わり) ******************* ?>
</span><!-- id="mp_list_option" -->
<!--
</span>
-->
</td></tr>
</table><!-- ### -->
<div id="mp_list_main">
<?php
	if ($rowcnt > 0) {
		mp_list_for_view($rs, $item_tbl, $id_item, $rowcnt, $pageline, $startline, $endline, $page, $pagemax, $order_tbl, $keystring, $http_arg, $template, $edit_button_item, $input_php, $list_filter, $view_description);
	} else {
		error_msg ("＊＊＊ 該当データがありません。");
	}
?>
</div><!-- id="mp_list_main" -->
</div><!-- id="mp_list_body" -->
<?php
	$con = mysql_close($con);
	return $sql;
}
// ****************************************************************
function mp_list_edit($arg, $item_tbl, $order_tbl, $http_arg) {
// ****************************************************************
	if (is_write_permit() != True) return;

	$account_id	= $arg['account_id']."";
	$table_name	= $arg['table_name_edit']."";
	$id_item	= $arg['id_item']."";
	$add_filter	= $arg['add_filter']."";
	$list_filter	= $arg['list_filter']."";
	$use_privacy	= $arg['use_privacy']."";
	$list_edit_right_add_html = $arg['list_edit_right_add_html'];
	$sql_for_edit	= $arg['sql_for_edit']."";
	$sql_create_callback	= $arg['sql_create_callback']."";
	$template	= $arg['template_edit']."";
	$edit_description = $arg['edit_description'];
	$add_row_use	= $arg['add_row_use']."";
	if ($add_filter <> "") {
		require($add_filter);
		$add_where = add_where_create($http_arg);
	}
	$con = my_mysql_connect(_DB_SCHEMA);
	$sortorder = $http_arg['sort'];
	if ($sortorder."" == "") {
		$sortorder = $order_tbl[0]['get_order_name'];
	}
	$keystring = keystr_fix($http_arg['key']);
	$pageline = $http_arg['pl'];
	$sel_filter = array();
	foreach ($item_tbl as $id=>$item) {
		if ($item['http_arg_GET名'] <> '') {
			$sel_filter[] = array("arg"=>$item['http_arg_GET名'], "colname"=>$item['列名'], "data"=>$http_arg[$item['http_arg_GET名']]);
		}
	}
?>
<div id="mp_list_body">
<?php
	if ($sql_create_callback <> "") {
		$sql = $sql_create_callback($account_id, $table_name, $item_tbl, $order_tbl, $sortorder, $keystring, $sel_filter, $use_privacy, $add_where);
	} elseif ($sql_for_edit <> "") {
		$sql = mp_list_sql_add_create($sql_for_edit, $table_name, $item_tbl, $order_tbl, $sortorder, $keystring, $sel_filter, $add_where);
	} else {
		$sql = mp_list_sql_create($account_id, $table_name, $item_tbl, $order_tbl, $sortorder, $keystring, $sel_filter, $use_privacy, $add_where);
	}
	$rs = my_mysql_query_debug_print($sql);
	$rowcnt = mysql_num_rows($rs);
	mp_list_get_page_start_end($pageline, $rowcnt, $page, $startline, $endline, $pagemax, $list_filter);
?>
<div id="mp_list_main">
	<table><tr>
	<td>
<?php
	mp_list_for_edit($rs, $item_tbl, $id_item, $startline, $endline, $account_id, $rowcnt, $http_arg, $use_privacy, $template, $edit_description, $add_row_use);
?>
	</td>
<?php	if ($list_edit_right_add_html <> "") { ?>
	<td id='list_edit_right_add'>
	<?php
		require($list_edit_right_add_html);
	?>
	</td>
<?php	} ?>
	</tr></table>
</div><!-- id="mp_list_main" -->
</div><!-- id="mp_list_body" -->
<?php
	$con = mysql_close($con);
}
// ****************************************************************
function mp_list_get_page_start_end($pageline, $rowcnt, &$page, &$startline, &$endline, &$pagemax, $list_filter) {
// ****************************************************************
	if ($list_filter <> "no" && defined("PAGE_LINE_SELECT") && PAGE_LINE_SELECT <> '') {
		if (isset($_GET['page'])) {
			$page = $_GET['page'];
			if ($page < 1) {
				$page = 1;
			}
		} else {
			$page = 1;
		}
		$startline = ($page - 1) * $pageline;				//開始行を算出
		$endline = $page * $pageline -1;				//終了行を算出
		$pagemax = ceil($rowcnt / $pageline);				//取得した行数から最終頁を算出
	} else {
		$page = 1;							//ページ分割なし
		$startline = 0;
		$endline = 1000000;
		$pagemax = 1;
	}
}
// ****************************************************************
function mp_list_update($arg, $item_tbl, $order_tbl, $http_arg) {
// ****************************************************************
	if (is_write_permit() != True) return;

	$account_id	= $arg['account_id']."";
	if ($arg['table_name_update']."" <> "") {
		$table_name	= $arg['table_name_update']."";
	} else {
		$table_name	= $arg['table_name_edit']."";
	}
	$id_item = $arg['id_item']."";
	$must_item = $arg['must_item']."";
	$update_redirect = $arg['update_redirect']."";
	$update_after_callback = $arg['update_after_callback']."";
	$use_privacy = $arg['use_privacy']."";

	$con = my_mysql_connect(_DB_SCHEMA);
	mp_list_db_update($account_id, $table_name, $item_tbl, $id_item, $must_item, $use_privacy, $arg);
	$con = mysql_close($con);
	if ($update_after_callback <> "") {
		call_user_func_array($update_after_callback, '');			// コールバック関数コール
	}
	if ($update_redirect <> "") {
		redirect($update_redirect."?".$_SERVER['QUERY_STRING']);
	} else {
		redirect($_SERVER['SCRIPT_NAME']."?".$_SERVER['QUERY_STRING']);
	}
}
// ****************************************************************
function mp_list_for_view($rs, $item_tbl, $id_item, $rowcnt, $pageline, $startline, $endline, $page, $pagemax, $order_tbl, $keystring, $http_arg, $template='', $edit_button_item='', $input_php, $list_filter, $view_description='') {
// ****************************************************************
	if ($list_filter <> "no" && defined("PAGE_LINE_SELECT") && PAGE_LINE_SELECT <> '') {
		mp_list_page_control($rowcnt, $page, $pagemax, $http_arg);
	}
	if ($view_description <> '') {
		echo '<p class="mp_description">'.$view_description.'</p>';
	}
	if ($template <> "") {
		require($template);
	} else {
	// ********** デフォルトテンプレート ここから **********
?>
	<table id="mp_list_table">
	<tr class="mp_list_table_head">
	<?php
		foreach ($item_tbl as $id=>$item) {
			if ($item['type'] <> "password") {
				if (empty($item['break']) or left($item['break'],1)=='後') {
					echo "<th width='".$item['width']."' nowrap>".$item['表示名']."</th>";
				}
			}
		}
	?>
	</tr>
	<?php
	mysql_data_seek($rs, $startline);			//テーブル内の指定行に移動
	$line = $startline;					//$lineに$startlineを代入
	while ($rec=mysql_fetch_array($rs) and $line<=$endline) {
	?>
	<tr class="mp_list_table_data">
	<?php
		foreach ($item_tbl as $id=>$item) {
			if ($item['type'] <> "password") {
				if ($rec['c_privacy'] == 444) {
					$td_view_class = " class='mp_list_privacy'";
				} else {
					$td_view_class = "";
				}
				if (empty($item['break']) or left($item['break'],1)=='後') {
					if ($item['背景カラー表示列名'] <> "") {
						echo "<td".$td_view_class." style='background-color: ".$rec[$item['背景カラー表示列名']].";'>";
					} elseif ($item['参照テーブル背景表示色'] <> "") {
						echo "<td".$td_view_class." style='background-color: ".$rec[$item['参照テーブル背景表示色']].";'>";
					} else {
						echo "<td".$td_view_class.">";
					}
				}
				if ($item['ラベルLIST'] <> '') {
					echo $item['ラベルLIST'];
				}
				if ($item['イメージ表示列名'] <> "") {
					if ($rec[$item['イメージ表示列名']] <> "") {
						echo '<img class="mp_icon_image" src="'.IMAGES_FOLDER.'/'.$rec[$item['イメージ表示列名']].'"';
						if ($item['i_width'].'' <> '') {
							echo ' width="'.$item['i_width'].'"';
						}
						if ($item['i_height'].'' <> '') {
							echo ' height="'.$item['i_height'].'"';
						}
						echo '>';
					}
				}
				if ($item['カラー表示列名'] <> "") {
					$text_color = '<span style="color: '.$rec[$item['カラー表示列名']].';">';
				} elseif ($item['背景カラー表示列名'] <> "") {
					$text_color = '<span style="color: #ffffff;">';
				} else {
					$text_color = '<span>';
				}
				if ($item['参照テーブル表示列'] <> "") {
					if ($item['参照テーブル表示色'] <> "") {
						echo "<span style='color: ".$rec[$item['参照テーブル表示色']].";'>".my_htmlspecialchars($rec[$item['参照テーブル表示列']])."</span>"."";
					} elseif ($item['参照テーブル背景表示色'] <> "") {
						echo "<span style='color: #ffffff;'>".my_htmlspecialchars($rec[$item['参照テーブル表示列']])."</span>".'';
					} else {
						echo my_htmlspecialchars($rec[$item['参照テーブル表示列']]);
					}
				} elseif ($item['文字検索'] == "Y") {
					if ($item['a_tag'] == "Y") {
						echo $text_color.ins_atag_br_keystr($rec[$item['列名']], keystr_and_or($keystring));
					} else {
						echo $text_color.ins_br_keystr($rec[$item['列名']], keystr_and_or($keystring));
					}
				} else {
					if ($item['type'] == "textarea") {
						if ($item['htmlScript'] == "Y") {
							echo str_replace("＼", chr(0x5c), $rec[$item['列名']]);
						} else {
							echo ins_br(my_htmlspecialchars($rec[$item['列名']]));
						}
					} elseif ($item['type'] == "date") {
						echo date_view($rec[$item['列名']]);
					} elseif ($item['a_tag'] == "Y") {
						echo $text_color.ins_atag($rec[$item['列名']]);
					} else {
						echo $text_color.my_htmlspecialchars($rec[$item['列名']]);
					}
				}
				echo "</span>";
				if ($item['列名'] == $edit_button_item) {
					echo "<a class='a_update_form' href='".$input_php."?id=".$rec[$id_item]."&page=".$page."&pl=".$pageline."&cat=".$http_arg['cat']."'>[修正]</a>";
				}
				if (isset($item['break']) and right($item['break'],1) == '後') {
					echo "<br>";
				} elseif (empty($item['break']) or right($item['break'],1) <> '連') {
					if ($item['brOff'].'' <> 'Y') {
						echo "<br>";
					}
					echo "</td>";
				}
			}
		}
	?>
	</tr>
	<?php
		$line++;
	}
	?>
	</table>
<?php
	// ********** デフォルトテンプレート ここまで **********
	}
	if ($list_filter <> "no" && defined("PAGE_LINE_SELECT") && PAGE_LINE_SELECT <> '') {
		mp_list_page_control($rowcnt, $page, $pagemax, $http_arg);
	}
}
// ****************************************************************
function mp_list_sql_create($account_id, $table_name, $item_tbl, $order_tbl, $sortorder, $keystring, $sel_filter, $use_privacy, $add_where="") {
// ****************************************************************
	$sql = "select * from ".$table_name." where c_delete = 0";
	if ($account_id <> "ALL") {
		$sql .= " and id_account = '".$account_id."'";
		if ($use_privacy == 'yes' && $account_id != $_SESSION['login_id']) {
			$sql .= " and c_privacy = 0";
		}
	}
	if ($keystring <> "") {
		$select_item = array();
		foreach ($item_tbl as $id=>$item) {
			if ($item['文字検索'] == "Y") {
				if ($item['strip_tags'] == "Y") {
					$select_item[] = $item['列名'].'_strip_tags';
				} else {
					$select_item[] = $item['列名'];
				}
			}
		}
		if (count($select_item) > 0) {
			$sql .= ' and ( '.query_and_or($select_item, $keystring, $table_name).' )';
		}
	}
	foreach ($sel_filter as $id=>$filter) {
		if ($filter['data'] == '__blank__') {
			$sql .= " and " . $filter['colname'] . " = ''";
		} elseif ($filter['data'] <> '') {
			$sql .= " and " . $filter['colname'] . " = '" . $filter['data'] . "'";
		}
	}
	if ($add_where <> "") {
		$sql .= " and " . $add_where;
	}
	foreach ($order_tbl as $id=>$item) {
		if ($item['get_order_name'] == $sortorder) {
			$order_item = $item['order_by'];
			//break;
		}
	}
	if ($order_item <> '') {
		$sql .= " order by ".$order_item;
	}
	return($sql);
}
// ****************************************************************
function mp_list_sql_add_create($sql, $table_name, $item_tbl, $order_tbl, $sortorder, $keystring, $sel_filter, $add_where="") {
// ****************************************************************
	if ($keystring <> "") {
		$select_item = array();
		foreach ($item_tbl as $id=>$item) {
			if ($item['文字検索'] == "Y") {
				if ($item['strip_tags'] == "Y") {
					$select_item[] = $item['列名'].'_strip_tags';
				} else {
					$select_item[] = $item['列名'];
				}
			}
		}
		if (count($select_item) > 0) {
			$sql .= ' and ( '.query_and_or($select_item, $keystring, $table_name).' )';
		}
	}
	foreach ($sel_filter as $id=>$filter) {
		if ($filter['data'] <> '') {
			$sql .= " and " . $filter['colname'] . " = '" . $filter['data'] . "'";
		}
	}
	if ($add_where <> "") {
		$sql .= " and " . $add_where;
	}
	foreach ($order_tbl as $id=>$item) {
		if ($item['get_order_name'] == $sortorder) {
			$order_item = $item['order_by'];
			//break;
		}
	}
	if ($order_item <> '') {
		$sql .= " order by ".$order_item;
	}
	return($sql);
}
// ****************************************************************
function mp_list_filter($pageline, $keystring, $item_tbl, $sel_filter, $account_id, $table_name, $http_arg, $add_filter, &$add_where, $filter_keysel_break, $list_option_callback) {
// ****************************************************************
?>
<script language="JavaScript">
<?php	require("../scripts/URLencode.js"); ?>
</script>
<span id="mp_list_filter" class="block_xxx">
<script language="JavaScript">
function SelectionCategory(form, sel, selname, arg_pool) {
	for (i = 0; i < sel.options.length; i++) {
		if (sel.options[i].selected == true) {
			window.location.href = "<?= $_SERVER['SCRIPT_NAME'] ?>?" + arg_pool + "&" + selname + "=" + URLencode(sel.options[i].value);
		}
	}
}
function categoryReset(arg_pool) {
	window.location.href = "<?= $_SERVER['SCRIPT_NAME'] ?>?" + arg_pool;
}
function RadioCategory(sel, selname, arg_pool) {
	window.location.href = "<?= $_SERVER['SCRIPT_NAME'] ?>?" + arg_pool + "&" + selname + "=" + URLencode(sel);
}
</script>
<form method="POST" name="filter_form" action="<?= $_SERVER['SCRIPT_NAME'] ?>?<?= query_from_http_arg_pool($http_arg) ?>">
<!-- xxx -->
<?php
	$filter_select_type = "";
	foreach ($item_tbl as $id=>$item) {
		if ($item['type'] == "select" or $item['filter_use'] == "Y") {
			if ($item['filter_c_delete'] == "no") {
					$filter_c_delete = 'no';
			} else {
					$filter_c_delete = '';
			}
			if ($item['filter_type'] == "radio") {
				$filter_select_type = "radio";
?>
	<span class="mp_list_category_radio">
<?php
				mp_list_filter_category_radio($item, $http_arg[$item['http_arg_GET名']], $account_id, $http_arg, $filter_c_delete);
?>
	</span>
<?php
			} elseif ($item['filter_type'] <> "no") {
?>
	<span class="mp_list_category_select">
<?php
				mp_list_filter_category_select($item, $http_arg[$item['http_arg_GET名']], $account_id, $http_arg, $filter_c_delete);
?>
	</span>
<?php
			}
		}
	}
	if ($filter_keysel_break == 'yes') {
?>
	<br>
	<span id="mp_list_filter_key_select" class="block_xxx">
<?php
	} else {
		if ($filter_select_type == "radio") echo '<br>';
?>
	<span id="mp_list_filter_key_select"<?= $filter_select_type == "radio" ? ' class="block_xxx"' : ' class="block_xxx_left"' ?>>
<?php
	}
	mp_list_filter_key_select($keystring, $http_arg);
	mp_list_filter_page($pageline, $http_arg);
	if ($list_option_callback <> '') {
		$sql = $list_option_callback($http_arg);
	}
?>
	</span>
<?php
	if ($add_filter <> "") {
?>
	<br />
	<span id="mp_list_add_filter" class="block_xxx">
<?php
		add_my_filter($http_arg);
?>
	</span>
<?php
	}
?>
<!-- xxx -->
</form>
</span><!-- id="mp_list_filter" -->
<?php
}
// ****************************************************************
function mp_list_filter_category_radio($item, $sel_data, $account_id, $http_arg, $filter_c_delete) {
// ****************************************************************
?>
	<span<?= $sel_data == "" ? ' class="mp_list_filter_true"' : '' ?>><input type="radio" name="Category" value="__reset__" onClick="RadioCategory('__reset__', '<?= $item['http_arg_GET名'] ?>', '<?= query_from_http_arg_pool($http_arg, $item['http_arg_GET名']) ?>')"<?= $sel_data == "" ? ' checked class="mp_list_filter_true"' : '' ?>>すべて</span>
<?php
	$where = '';
	$sqlsel = "select * from ".$item['参照テーブル'];
	if ($filter_c_delete <> 'no') {
		$where .= " c_delete = 0";
	}
	if ($account_id <> "ALL" and $item['参照テーブルユーザー'] <> "共有") {
		if ($where <> '') {
			$where .= " and";
		}
		$where .= " id_account = '".$account_id."'";
	}
	if ($where <> '') {
		$sqlsel .= ' where '.$where;
	}
	$sqlsel .= " order by ".$item['参照テーブル表示順'];
	$rs_sel = my_mysql_query($sqlsel);
	$v_all = 'すべて';
	while ($rec_sel=mysql_fetch_array($rs_sel)) {
		if ($rec_sel[$item['列名']] == '') {
			$rec_val = '__blank__';
			$rec_val_data = '(空白)';
		} else {
			$rec_val = $rec_sel[$item['列名']];
			$rec_val_data = $rec_sel[$item['参照テーブル表示列']];
		}
?>
<span<?= $rec_val == $sel_data ? ' class="mp_list_filter_true"' : '' ?>><input type="radio" name="Category" value="<?= $rec_val ?>" onClick="RadioCategory('<?= $rec_val ?>', '<?= $item['http_arg_GET名'] ?>', '<?= query_from_http_arg_pool($http_arg, $item['http_arg_GET名']) ?>')"<?= $rec_val == $sel_data ? ' checked class="mp_list_filter_true"' : '' ?>><?= $rec_val_data ?></span>
<?php
		$v_all .= $rec_val_data;
		if (str_width($v_all) > 70 ) {
			echo '<br>';
			$v_all = '';
		}
	}
?>
<?php
}
// ****************************************************************
function mp_list_filter_category_select($item, $sel_data, $account_id, $http_arg, $filter_c_delete) {
// ****************************************************************
	if ($item['下位フィルタ_GET名'] <> '') {
		$omit_arg = $item['http_arg_GET名'].','.$item['下位フィルタ_GET名'];	//下位フィルタをリセット
	} else {
		$omit_arg = $item['http_arg_GET名'];
	}
	if ($item['optgroup_jquery_cs'] == 'yes') {
		if ($_GET['cat'] <> '') {
			$addopt = '&cat=' . $_GET['cat'];
		}
?>
<script language="JavaScript">
jQuery(function(){
	jquery_cs_function = 'MP_SelectionOptG_<?= $item['http_arg_GET名'] ?>';
	jquery_cs_arg = '<?= $item['http_arg_GET名'] ?>';
	jquery_cs_style = '';
	$('#<?= 'jquery_cs_'.$item['http_arg_GET名'] ?> select').cs();
});
function MP_SelectionOptG_<?= $item['http_arg_GET名'] ?>(key, data) {
	window.location.href = "<?= $_SERVER['SCRIPT_NAME'] ?>?"+key+"="+data+"<?= $addopt ?>&<?= query_from_http_arg_pool($http_arg, $item['http_arg_GET名']) ?>";
}
</script>
	<span id="<?= 'jquery_cs_'.$item['http_arg_GET名'] ?>">
<?php
	}
?>
	<?= $item['表示名'] ?>：<select class="<? if ($sel_data <> '') echo 'mp_list_filter_true'; ?>" onChange="SelectionCategory(this.form, this, '<?= $item['http_arg_GET名'] ?>', '<?= query_from_http_arg_pool($http_arg, $omit_arg) ?>')">：
	<option value="__reset__" class="mp_list_filter_false">すべて</option>
<?php
	$where = '';
	$sqlsel = "select * from ".$item['参照テーブル'];
	if ($filter_c_delete <> 'no') {
		$where .= " c_delete = 0";
	}
	if ($account_id <> "ALL" and $item['参照テーブルユーザー'] <> "共有") {
		if ($where <> '') {
			$where .= " and";
		}
		$where .= " id_account = '".$account_id."'";
	}
	if ($item['上位フィルタ_GET名'] <> '' and $http_arg[$item['上位フィルタ_GET名']] <> '') {
		if ($where <> '') {
			$where .= " and";
		}
		$where .= " " . $item['上位フィルタ列名'] . " = '".$http_arg[$item['上位フィルタ_GET名']]."'";
	}
	if ($where <> '') {
		$sqlsel .= ' where '.$where;
	}
	$sqlsel .= " order by ".$item['参照テーブル表示順'];
	$rs_sel = my_mysql_query($sqlsel);
	if ($item['参照テーブルoptgroup'] <> '') {
		$optgroup = '';
		while ($rec_sel=mysql_fetch_array($rs_sel)) {
			if ($optgroup <> $rec_sel[$item['参照テーブルoptgroup']]) {
				if ($optgroup <> '') {
					if (!strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
					// IE以外 (なぜか一番下の選択肢がリセットのボックスにはみ出してしまうため)
		?>
					<option value=""></option>
		<?php
					}
		?>
			</optgroup>
		<?php
				}
		?>
		<optgroup label="<?= $rec_sel[$item['参照テーブルoptgroup']] ?>">
		<?php
			}
			if ($rec_sel[$item['列名']] == '') {
				$rec_val = '__blank__';
			} else {
				$rec_val = $rec_sel[$item['列名']];
			}
	?>
		<option value="<?= $rec_val ?>"<?= $rec_val == $sel_data ? ' selected class="mp_list_filter_true"' : ' class="mp_list_filter_false"' ?>><?= $rec_sel[$item['参照テーブル表示列']] ?></option>
		<?php
			$optgroup = $rec_sel[$item['参照テーブルoptgroup']];
		}
	?>
		</optgroup>
	<?php
	} else {
		while ($rec_sel=mysql_fetch_array($rs_sel)) {
			if ($rec_sel[$item['列名']] == '') {
				$rec_val = '__blank__';
			} else {
				$rec_val = $rec_sel[$item['列名']];
			}
	?>
	<option value="<?= $rec_val ?>"<?= $rec_val == $sel_data ? ' selected class="mp_list_filter_true"' : ' class="mp_list_filter_false"' ?>><?= $rec_sel[$item['参照テーブル表示列']] ?></option>
	<?php
		}
	}
?>
	</select>
<?php
	if ($item['optgroup_jquery_cs'] == 'yes') {
?>
	</span>
<?php
	}
?>
	<input type="button" name="カテゴリリセット" value="リセット" onClick="categoryReset('<?= query_from_http_arg_pool($http_arg, $item['http_arg_GET名']) ?>')">
<?php
}
// ****************************************************************
function mp_list_filter_key_select($keystring, $http_arg) {
// ****************************************************************
	$html_key = my_htmlspecialchars($keystring);
?>
<script type="text/javascript">
$(function(){
	$("#key_input").keydown(function(){
		if (event.keyCode == 13) {		// Returnキーで検索を可能にする
			keySearch();
			return false;
		}
		$(this).css("background-color","#ffffff");
		$("#key_input").css({width:width_by_len($("#key_input").val()+" ")+"px"});
	});
	$("#key_input").mousedown(function(){
		$(this).css({width:width_by_len($(this).val())+"px"});
	});
/*
	$("#key_input").focus(function(){
		$(this).css({width:width_by_len($(this).val())+"px"});
//	}).blur(function(){		// この方法だと検索ボタンを2回クリックしないと検索onClick()が実行されない
//		$(this).css({width:"90px"});
	});
*/
});
function width_by_len(str) {
	ln = str_width(str);
	if (ln > 8) return (((ln-8) * 7) + 90);
	return 90;
}
function str_width(str) {
// 文字列の文字幅(漢字は2)を求める
// by http://www.kanaya440.com/contents/tips/javascript/006.html
	var r = 0;
	for (var i = 0; i < str.length; i++) {
		var c = str.charCodeAt(i);
		// Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff
		// Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3
		if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) {
			r += 1;
		} else {
			r += 2;
		}
	}
	return r;
}
</script>
<?php
	if (($len = str_width($html_key)) > 8) {
		$width = (($len - 8) * 7) + 90;
	} else {
		$width = 90;
	}
?>
	検索：<input class="text<?= $html_key <> '' ? ' mp_list_filter_true' : '' ?>" type="text" name="filter_keyword" value="<?= $html_key ?>" id="key_input" style="width:<?= $width ?>px;">
	<script language="JavaScript">
	function keySearch() {
	//	$("#key_input").css({width:"90px"});
		window.location.href = "<?= $_SERVER['SCRIPT_NAME'] ?>?key=" + URLencode(document.filter_form.filter_keyword.value) + "&<?= query_from_http_arg_pool($http_arg, 'key') ?>";
	}
	function keyReset() {
		window.location.href = "<?= $_SERVER['SCRIPT_NAME'] ?>?<?= query_from_http_arg_pool($http_arg, 'key') ?>&key=__reset__";
	}
	</script>
	<input type="button" name="検索" value="検索" onClick="keySearch();">
	<input type="button" name="検索リセット" value="リセット" onClick="keyReset()">
<?php
}
// ****************************************************************
function mp_list_filter_page($pageline, $http_arg) {
// ****************************************************************
	if (defined("PAGE_LINE_SELECT") && PAGE_LINE_SELECT <> '') {	// 定義がない場合はページコントロールしない
?>
	<script language="JavaScript">
	function SelectionPageLine(form, sel) {
		for (i = 0; i < sel.options.length; i++) {
			if (sel.options[i].selected == true) {
				window.location.href = '<?= $_SERVER['SCRIPT_NAME'] ?>?<?= query_from_http_arg_pool($http_arg, "pl") ?>&pl=' + sel.options[i].value;
			}
		}
	}
	</script>
	頁行数：<select name="" onchange="SelectionPageLine(this.form, this)">
	<?php
		$keyary = explode(",", PAGE_LINE_SELECT);
		foreach ($keyary as $keytmp) {
	?>
		<option value="<?= $keytmp ?>"<?= $pageline == $keytmp ? " selected" : "" ?>><?= $keytmp ?></option>
	<?php
		}
	?>
		</select>
<?php
	}
}
// ****************************************************************
function mp_list_for_edit($rs, $item_tbl, $id_item, $startline, $endline, $account_id, $rowcnt, $http_arg, $use_privacy, $template='', $edit_description='', $add_row_use='') {
// ****************************************************************
	$query_string = str_replace("edit=y","",str_replace("edit=y&","",$_SERVER['QUERY_STRING']));
	$query_string = str_replace("edit=a","",str_replace("edit=a&","",$query_string));
?>
	<div id="mp_list_for_edit">
	<form method="POST" name="form0" action="<?= $_SERVER['SCRIPT_NAME'] ?>?<?= $query_string ?>">
		<input class="input_form_button" type="submit" name="登録" value="登録/修正">
		<input class="input_form_button" type="reset" name="リセット" value="リセット">
		<input type="hidden" name="login_id" value="<?= $_SESSION['login_id'] ?>">
		<input type="hidden" name="current_id" value="<?= $_SESSION['current_id'] ?>">
		<a class="mp_a_cancel_back" href="javascript:history.back();">戻る</a>
		<br><br>
<?php
	if ($edit_description <> '') {
		echo '<p class="mp_description">'.$edit_description.'</p>';
	}
	if ($template <> "") {
		require($template);
	} else {
	// ********** デフォルトテンプレート ここから **********
?>
	<?php
		foreach ($item_tbl as $id=>$item) {
			if ($item['上位フィルタ参照テーブル'] <> '') {	// ##################
	?>
<script language="JavaScript">
<?php
	$ids = "ids = new Array(";
	$sqlsel = "select * from ".$item['上位フィルタ参照テーブル']. " order by ".$item['上位フィルタ表示順'];
	$rs_cat = my_mysql_query($sqlsel);
	$row = mysql_num_rows($rs_cat);
	if ($row <> 0) {
		$ix = 0;
		while ($rec_cat=mysql_fetch_array($rs_cat)) {
			$sqlsel = "select * from ".$item['参照テーブル']." where ".$item['上位フィルタ列名']." = '".$rec_cat[$item['上位フィルタ列名']]."' order by ".$item['参照テーブル表示順'];
			$rs_cat2 = my_mysql_query($sqlsel);
			echo "ids".$ix."=new Array(";
			$rc = 0;
			while ($rec_cat2=mysql_fetch_array($rs_cat2)) {
				if ($rc++ <> 0) echo ",";
				echo "'".$rec_cat2[$item['列名']]."'";
			}
			echo ");"."\n";
			if ($ix <> 0) {
				$ids .= ",";
			}
			$ids .= "ids".$ix;
			$ix++;
		}
		$ids .= ");";
		echo $ids."\n";
	}
	$vals = "vals = new Array(";
	$sqlsel = "select * from ".$item['上位フィルタ参照テーブル']. " order by ".$item['上位フィルタ表示順'];
	$rs_cat = my_mysql_query($sqlsel);
	$row = mysql_num_rows($rs_cat);
	if ($row <> 0) {
		$ix = 0;
		while ($rec_cat=mysql_fetch_array($rs_cat)) {
			$sqlsel = "select * from ".$item['参照テーブル']." where ".$item['上位フィルタ列名']." = '".$rec_cat[$item['上位フィルタ列名']]."' order by ".$item['参照テーブル表示順'];
			$rs_cat2 = my_mysql_query($sqlsel);
			echo "vals".$ix."=new Array(";
			$rc = 0;
			while ($rec_cat2=mysql_fetch_array($rs_cat2)) {
				if ($rc++ <> 0) echo ",";
				echo "'".$rec_cat2[$item['参照テーブル表示列']]."'";
			}
			echo ");"."\n";
			if ($ix <> 0) {
				$vals .= ",";
			}
			$vals .= "vals".$ix;
			$ix++;
		}
		$vals .= ");";
		echo $vals."\n";
	}
?>
	len=0;
	for(i=0; i<ids.length; i++) if(ids[i].length > len) len=ids[i].length;
	selx=0;
	function SelectChange1(ix) {
		var selname1 = "<?= $item['上位フィルタ列名'] ?>" + ix;
		var selname2 = "<?= $item['列名'] ?>" + ix;
		var s1 = eval( 'document.form0.' + selname1);
		var s2 = eval( 'document.form0.' + selname2);
		selx = s1.selectedIndex;
		s2.selectedIndex = 0
		s2.options.length = 0
		iy=0;
		for(i=0; i<len; i++) {
			if(ids[selx].length < len && ids[selx].length <= i) {
				s2.options[i-iy]=null;
				iy++;
			} else {
				s2.options[i]=new Option(vals[selx][i],ids[selx][i]);
			}
		}
	}
	function SelectChange2(ix) {
		var selname1 = "<?= $item['上位フィルタ列名'] ?>" + ix;
		var selname2 = "<?= $item['列名'] ?>" + ix;
		var s1 = eval( 'document.form0.ADD_REC' + selname1);
		var s2 = eval( 'document.form0.ADD_REC' + selname2);
		selx = s1.selectedIndex;
		s2.selectedIndex = 0
		s2.options.length = 0
		iy=0;
		for(i=0; i<len; i++) {
			if(ids[selx].length < len && ids[selx].length <= i) {
				s2.options[i-iy]=null;
				iy++;
			} else {
				s2.options[i]=new Option(vals[selx][i],ids[selx][i]);
			}
		}
	}
</script>
	<?php
			}						// ##################
		}
	?>
	<table id="mp_list_table_edit" cellspacing=0>
	<tr class="mp_list_table_head">
		<th>削除</th>
	<?php if ($use_privacy == 'yes' && $account_id == $_SESSION['login_id']) { ?>
		<th>非公</th>
	<? } ?>
	<?php
		foreach ($item_tbl as $id=>$item) {
			if ($item['type'] <> "no_edit_no_col" and (empty($item['break']) or left($item['break'],1)=='後')) {
				echo "<th>".$item['表示名']."</th>";
			}
		}
	?>
	</tr>
	<?php
	if ($rowcnt > 0) { //*********************************************
		$cnt = 0;
		mysql_data_seek($rs, $startline);			//テーブル内の指定行に移動
		$line = $startline;					//$lineに$startlineを代入
		while ($rec=mysql_fetch_array($rs) and $line<=$endline) {
	?>
	<tr class="mp_list_table_data">
		<td><input type="hidden" name="UP_ID<?= $rec[$id_item] ?>" value="<?= $rec[$id_item] ?>">
			<input type="checkbox" name="DEL_ID<?= $rec[$id_item] ?>" value="削除">
		</td>
		<?php if ($use_privacy == 'yes' && $account_id == $_SESSION['login_id']) { ?>
			<td><input type="checkbox" name="c_privacy<?= $rec[$id_item] ?>" value="444"<?= ($rec['c_privacy'] == 444) ? ' checked' : '' ?>></td>
		<? } ?>
	<?php
			foreach ($item_tbl as $id=>$item) {
			    if ($item['type'] <> "no_edit_no_col") { /* ------ */
				if (empty($item['break']) or left($item['break'],1)=='後') {
					if ($item['align'] <> '') $align = ' style="text-align: '.$item['align'].'"';
	?>
		<td nowrap<?= $align?>>
	<?php
				}
				if ($item['ラベル'] <> '') {
					echo $item['ラベル'];
				}
				if ($item['type'] == "text") {
					if ($item['背景カラー表示列名'] <> "") {
						$add_style = ' color: #ffffff; background-color: '.$rec[$item['背景カラー表示列名']].';';
					} elseif ($item['カラー表示列名'] <> "") {
						if ($item['カラー表示列名'] == $item['列名']) {
							//$add_style = ' color: #ffffff; background-color: '.$rec[$item['カラー表示列名']].';';
							$add_style = '';
						} else {
							$add_style = ' color: '.$rec[$item['カラー表示列名']].';';
						}
					} else {
						$add_style = '';
					}
					if ($item['zero'] == "space" and $rec[$item['列名']] == 0) {
						$int_val = '';
					} else {
						$int_val = my_htmlspecialchars($rec[$item['列名']]);
					}
					$px = $item['size']*5;
	?>
		<input class="text" type="text" name="<?= $item['列名'] ?><?= $rec[$id_item] ?>" value="<?= $int_val ?>" style="ime-mode: <?= $item['ime-mode'] ?>; width:<?= $px ?>px; <?= $add_style ?>">
	<?php
				} elseif ($item['type'] == "textarea") {
					$px = $item['cols']*5;
	?>
		<textarea name="<?= $item['列名'] ?><?= $rec[$id_item] ?>" cols="<?= $item['cols'] ?>" rows="<?= $item['rows'] ?>" wrap="soft" style="width:<?= $px ?>px;"><?= my_htmlspecialchars($rec[$item['列名']]) ?></textarea>
	<?php
				} elseif ($item['type'] == "select") {
					if ($item['select_num_min'] <> '') {
	?>
						<select name="<?= $item['列名'] ?><?= $rec[$id_item] ?>">
						<?php if ($item['select_space'] == "Y") { ?>
							<option value=""></option>
						<?php } ?>
						<?php
							for ($sel_num = (int)$item['select_num_min']; $sel_num <= (int)$item['select_num_max']; $sel_num++) {
						?>
							<option value="<?= $sel_num ?>"<?= $rec[$item['列名']] == $sel_num ? " selected" : "" ?>><?= $sel_num ?></option>
						<?php
							}
						?>
						</select>
	<?php				} elseif ($item['select_options'] <> '') {
						$option_ary = explode(",", $item['select_options']);
	?>
						<select name="<?= $item['列名'] ?><?= $rec[$id_item] ?>">
						<?php
							foreach ($option_ary as $opt) {
						?>
							<option value="<?= $opt ?>"<?= $rec[$item['列名']] == $opt ? " selected" : "" ?>><?= $opt ?></option>
						<?php
							}
						?>
						</select>
	<?php				} else { ?>
						<?php
						if ($item['下位フィルタ_GET名'] <> '') {
							$onChange = ' onChange="SelectChange1(' . $rec[$id_item] . ');"';
						} else {
							$onChange = '';
						}
						?>
						<select name="<?= $item['列名'] ?><?= $rec[$id_item] ?>"<?= $onChange ?>>
						<?php if ($item['select_space'] == "Y") { ?>
							<option value=""></option>
						<?php } ?>
						<?php
						$sqlsel = "select * from ".$item['参照テーブル'];
						$where = '';
						if ($item['filter_c_delete'] <> 'no') {
							$where = " c_delete = 0";
						}
						if ($account_id <> "ALL" and substr($item['参照テーブル'],0,1) == 'm' and $item['参照テーブルユーザー'] <> "共有") {
							if ($where <> '') {
								$where .= " and";
							}
							$where .= " id_account = '".$account_id."'";
						}
						if ($item['上位フィルタ列名'] <> '') {
							if ($where <> '') {
								$where .= " and";
							}
							$where .= " ".$item['上位フィルタ列名']." = '".$rec[$item['上位フィルタ列名']]."'";
						}
						if ($where <> '') {
							$sqlsel .= " where".$where;
						}
						$sqlsel .= " order by ".$item['参照テーブル表示順'];
						$rs_sel = my_mysql_query($sqlsel);
						if ($item['参照テーブルoptgroup'] <> '') {
							$optgroup = '';
							while ($rec_sel=mysql_fetch_array($rs_sel)) {
								if ($optgroup <> $rec_sel[$item['参照テーブルoptgroup']]) {
						?>
							<optgroup label="<?= $rec_sel[$item['参照テーブルoptgroup']] ?>">
						<?php
								}
						?>
							<option value="<?= $rec_sel[$item['列名']] ?>"<?= $rec_sel[$item['列名']] == $rec[$item['列名']] ? " selected" : "" ?>><?= $rec_sel[$item['参照テーブル表示列']] ?></option>
						<?php
								$optgroup = $rec_sel[$item['参照テーブルoptgroup']];
							}
						?>
							</optgroup>
						</select>
	<?php
						} else {
							while ($rec_sel=mysql_fetch_array($rs_sel)) {
						?>
							<option value="<?= $rec_sel[$item['列名']] ?>"<?= $rec_sel[$item['列名']] == $rec[$item['列名']] ? " selected" : "" ?>><?= $rec_sel[$item['参照テーブル表示列']] ?></option>
						<?php
							}
						?>
						</select>
	<?php
						}
					}
				} elseif ($item['type'] == "password") {
					$px = $item['size']*5;
	?>
		<input class="password" type="password" name="<?= $item['列名'] ?><?= $rec[$id_item] ?>" value="<?= $rec[$item['列名']] ?>" style="ime-mode: <?= $item['ime-mode'] ?>; width:<?= $px ?>px;">
	<?php
				} elseif ($item['type'] == "date") {
					$year = date_from_mysql("Y", $rec[$item['列名']]);
					$month = date_from_mysql("n", $rec[$item['列名']]);
					$day = date_from_mysql("d", $rec[$item['列名']]);
					if ($item['toYear'] <> "") {
						$endYY = date("Y") + $item['toYear'];
					} else {
						$endYY = date("Y") + 10;
					}
					select_view_ymd("Y".$item['列名'].$rec[$id_item], "", $item['firstYear'], $endYY, $year);
					select_view_ymd("M".$item['列名'].$rec[$id_item], "", 1, 12, $month);
					select_view_ymd("D".$item['列名'].$rec[$id_item], "", 1, 31, $day);
				} elseif ($item['type'] == "time") {
					select_view_time($item['列名'].$rec[$id_item], $rec[$item['列名']]);
				} else {	// no_edit
	?>
						<?= my_htmlspecialchars($rec[$item['列名']]) ?>
	<?php
				}
				if (isset($item['break']) and right($item['break'],1) == '後') {
	?>
		<br>
	<?php
				} elseif (empty($item['break']) or right($item['break'],1) <> '連') {
	?>
		<br></td>
	<?php
				}
			    } /* ------ */
			}
	?>
	</tr>
	<?php
			$cnt++;
			$line++;
		}
	} //*********************************************

	if ($add_row_use == 'no') {
		return;
	}
		if ($cnt < 5) {
			$add_row = 10 - $cnt;
		} else {
			$add_row = 5;
		}
		$up_filter_first;
		for ($ix=1; $ix<=$add_row; $ix++) {
	?>
	<tr class="mp_list_table_data">
		<td>追加<input type="hidden" name="ADD_ID<?= $ix ?>" value="<?= $ix ?>"></td>
		<?php if ($use_privacy == 'yes' && $account_id == $_SESSION['login_id']) { ?>
			<td><input type="checkbox" name="ADD_RECc_privacy<?= $ix ?>" value="444"></td>
		<? } ?>
	<?php
			foreach ($item_tbl as $id=>$item) {
				if (!$up_filter_first) {
					if ($item['上位フィルタ列名'] <> '') {
						$sqlsel = "select * from ".$item['上位フィルタ参照テーブル'];
						if ($http_arg[$item['上位フィルタ_GET名']] <> '') {
							$sqlsel .= " where ".$item['上位フィルタ列名']." = '".$http_arg[$item['上位フィルタ_GET名']]."'";
						}
						$sqlsel .= " order by ".$item['上位フィルタ表示順'];
						$rs_sel = my_mysql_query($sqlsel);
						if ($rec_sel=mysql_fetch_array($rs_sel)) {
							$up_filter_first = $rec_sel[$item['上位フィルタ列名']];
						}
					}
				}
			    if ($item['type'] <> "no_edit_no_col") { /* ------ */
				if (empty($item['break']) or left($item['break'],1)=='後') {
					if ($item['align'] <> '') $align = ' style="text-align: '.$item['align'].'"';
	?>
		<td nowrap<?= $align?>>
	<?php
				}
				if ($item['ラベル'] <> '') {
					echo $item['ラベル'];
				}
				if ($item['type'] == "text" || $item['type'] == "password") {
					$px = $item['size']*5;
	?>
		<input class="text" type="text" name="ADD_REC<?= $item['列名'] ?><?= $ix ?>" value="<?= $item['初期値'] ?>" style="ime-mode: <?= $item['ime-mode'] ?>; width:<?= $px ?>px;">
	<?php
				} elseif ($item['type'] == "textarea") {
					$px = $item['cols']*5;
	?>
		<textarea name="ADD_REC<?= $item['列名'] ?><?= $ix ?>" rows="<?= $item['rows'] ?>" wrap="soft" style="width:<?= $px ?>px;"></textarea>
	<?php
				} elseif ($item['type'] == "select") {
					if ($item['select_num_min'] <> '') {
	?>
						<select name="ADD_REC<?= $item['列名'] ?><?= $ix ?>">
						<?php if ($item['select_space'] == "Y") { ?>
							<option value=""></option>
						<?php } ?>
					<?php
							for ($sel_num = (int)$item['select_num_min']; $sel_num <= (int)$item['select_num_max']; $sel_num++) {
					?>
							<option value="<?= $sel_num ?>"><?= $sel_num ?></option>
					<?php
							}
					?>
						</select>
	<?php				} elseif ($item['select_options'] <> '') {
						$option_ary = explode(",", $item['select_options']);
	?>
						<select name="ADD_REC<?= $item['列名'] ?><?= $ix ?>">
						<?php
							foreach ($option_ary as $opt) {
						?>
							<option value="<?= $opt ?>"><?= $opt ?></option>
						<?php
							}
						?>
						</select>
	<?php				} else { ?>
						<?php
						if ($item['下位フィルタ_GET名'] <> '') {
							$onChange = ' onChange="SelectChange2(' . $ix . ');"';
						} else {
							$onChange = '';
						}
						?>
						<select name="ADD_REC<?= $item['列名'] ?><?= $ix ?>"<?= $onChange ?>>
						<?php if ($item['select_space'] == "Y") { ?>
							<option value=""></option>
						<?php } ?>
					<?php
						$sqlsel = "select * from ".$item['参照テーブル'];
						$where = '';
						if ($item['filter_c_delete'] <> 'no') {
							$where = " c_delete = 0";
						}
						if ($account_id <> "ALL" and substr($item['参照テーブル'],0,1) == 'm' and $item['参照テーブルユーザー'] <> "共有") {
							if ($where <> '') {
								$where .= " and";
							}
							$where .= " id_account = '".$account_id."'";
						}
						if ($item['上位フィルタ列名'] <> '') {
							if ($where <> '') {
								$where .= " and";
							}
							$where .= " ".$item['上位フィルタ列名']." = '".$up_filter_first."'";
						}
						if ($where <> '') {
							$sqlsel .= " where".$where;
						}
						$sqlsel .= " order by ".$item['参照テーブル表示順'];
						$rs_sel = my_mysql_query($sqlsel);
						if ($item['参照テーブルoptgroup'] <> '') {
								$optgroup = '';
								while ($rec_sel=mysql_fetch_array($rs_sel)) {
									if ($optgroup <> $rec_sel[$item['参照テーブルoptgroup']]) {
							?>
								<optgroup label="<?= $rec_sel[$item['参照テーブルoptgroup']] ?>">
							<?php
									}
									if ($item['http_arg_GET名'] <> "") {
						?>
								<option value="<?= $rec_sel[$item['列名']] ?>"<?= $rec_sel[$item['列名']] == $http_arg[$item['http_arg_GET名']] ? " selected" : "" ?>><?= $rec_sel[$item['参照テーブル表示列']] ?></option>
						<?php
									} else {
						?>
								<option value="<?= $rec_sel[$item['列名']] ?>"><?= $rec_sel[$item['参照テーブル表示列']] ?></option>
						<?php
									}
									$optgroup = $rec_sel[$item['参照テーブルoptgroup']];
								}
							?>
								</optgroup>
						<?php
							} else {
								while ($rec_sel=mysql_fetch_array($rs_sel)) {
									if ($item['http_arg_GET名'] <> "") {
						?>
								<option value="<?= $rec_sel[$item['列名']] ?>"<?= $rec_sel[$item['列名']] == $http_arg[$item['http_arg_GET名']] ? " selected" : "" ?>><?= $rec_sel[$item['参照テーブル表示列']] ?></option>
						<?php
									} else {
						?>
								<option value="<?= $rec_sel[$item['列名']] ?>"><?= $rec_sel[$item['参照テーブル表示列']] ?></option>
						<?php
									}
								}
							}
					?>
						</select>
	<?php
					}
				} elseif ($item['type'] == "date") {
					if ($item['toYear'] <> "") {
						$endYY = date("Y") + $item['toYear'];
					} else {
						$endYY = date("Y") + 10;
					}
					$year = date("Y");
					$month = date("m");
					$day = date("d");
					if ($item['date_http_arg_y'] <> "") {
						if ($http_arg[$item['date_http_arg_y']] <> "") {
							$year = $http_arg[$item['date_http_arg_y']];
						}
					}
					if ($item['date_http_arg_m'] <> "") {
						if ($http_arg[$item['date_http_arg_m']] <> "") {
							$month = $http_arg[$item['date_http_arg_m']];
						}
					}
					if ($item['date_http_arg_d'] <> "") {
						if ($http_arg[$item['date_http_arg_d']] <> "") {
							$day = $http_arg[$item['date_http_arg_d']];
						}
					}
					select_view_ymd("ADD_REC"."Y".$item['列名'].$ix, "", $item['firstYear'], $endYY, $year);
					select_view_ymd("ADD_REC"."M".$item['列名'].$ix, "", 1, 12, $month);
					select_view_ymd("ADD_REC"."D".$item['列名'].$ix, "", 1, 31, $day);
				} elseif ($item['type'] == "time") {
					select_view_time($item['列名'].$ix, "", "ADD_REC");
				}
				if (isset($item['break']) and right($item['break'],1) == '後') {
	?>
		<br>
	<?php
				} elseif (empty($item['break']) or right($item['break'],1) <> '連') {
	?>
		<br></td>
	<?php
				}
			    } /* ------ */
			}
	?>
	</tr>
	<?php
		}
	?>
	</table>
<?php
	// ********** デフォルトテンプレート ここまで **********
	}
?>
	<input class="input_form_button" type="submit" name="登録" value="登録/修正">
	<input class="input_form_button" type="reset" name="リセット" value="リセット">
	</form>
	</div>
<?php
}
// ****************************************************************
function mp_list_db_update($account_id, $table_name, $item_tbl, $id_item, $must_item, $use_privacy, $arg) {
// ****************************************************************
	foreach ($_POST as $name => $value) {
			//print($name . ":" . $value . "<br>\n");
			//print("  " . mb_substr($name,0,5) . "<br>\n");
		if (mb_substr($name,0,5) == "UP_ID") {
			$upid = mb_substr($name, 5);
			$sql = "update ".$table_name;
			if ($_POST['DEL_ID'.$upid] <> "削除") {
				$sql .= " set c_updatetime = '". date("Y/m/d H:i:s")."'";
				if ($arg['update_account'].'' <> '') {
						$sql .= ", c_update_account = ".$arg['update_account'];
				}
				$sql .= mp_list_update_sql_item($item_tbl, $upid, $must_item);
				if ($use_privacy == 'yes' && $account_id == $_SESSION['login_id']) {
					if ($_POST['c_privacy'.$upid] == '444') {
						$sql .= ", c_privacy = 444";
					} else {
						$sql .= ", c_privacy = 0";
					}
				}
				$sql .= " where ".$id_item." = ".$upid;
				if ($account_id <> "ALL") {
					$sql .= " and id_account = '".$account_id."'";
				}
				$sql .= " and (".mp_list_update_sql_where($item_tbl, $upid);
				if ($use_privacy == 'yes' && $account_id == $_SESSION['login_id']) {
					if ($_POST['c_privacy'.$upid] == '444') {
						$sql .= " or c_privacy <> 444";
					} else {
						$sql .= " or c_privacy <> 0";
					}
				}
				$sql .= ")";
			} else {
				$sql .= " set c_updatetime = '". date("Y/m/d H:i:s")."'";
				if ($arg['update_account'].'' <> '') {
						$sql .= ", c_update_account = ".$arg['update_account'];
				}
				$sql .= ", c_delete = 999";
				$sql .= " where ".$id_item." = ".$upid;
				if ($account_id <> "ALL") {
					$sql .= " and id_account = '".$account_id."'";
				}
			}
			$ret = mysql_query($sql);
			if (!$ret) {
				if (_DEBUG_ERROR_MSG == "YES") {
					error_exit("更新 失敗。<br><br>".$sql, True);
				} else {
					error_exit("更新 失敗。", True);
				}
			}
		}
		if (mb_substr($name,0,6) == "ADD_ID") {
			$addid = mb_substr($name, 6);
			if ($_POST['ADD_REC'.$must_item.$addid] <> "") {
				$sql = "insert into ".$table_name." (";
				$sql .= "c_registtime, c_updatetime";
				if ($arg['update_account'].'' <> '') {
					$sql .= ", c_update_account";
				}
				if ($account_id <> "ALL") {
					$sql .= ", id_account";
				}
				$sql .= mp_list_insert_sql_item_name($item_tbl);
				if ($use_privacy == 'yes' && $account_id == $_SESSION['login_id']) {
					$sql .= ", c_privacy";
				}
				$sql .= ") values (";
				$sql .= "'". date("Y/m/d H:i:s")."'";
				$sql .= ", '". date("Y/m/d H:i:s")."'";
				if ($arg['update_account'].'' <> '') {
					$sql .= ", '". $arg['update_account']."'";
				}
				if ($account_id <> "ALL") {
					$sql .= ", '". $account_id."'";
				}
				$sql .= mp_list_insert_sql_item_data($item_tbl, $addid);
				if ($use_privacy == 'yes' && $account_id == $_SESSION['login_id']) {
					if ($_POST['ADD_RECc_privacy'.$addid] == '444') {
						$sql .= ", 444";
					} else {
						$sql .= ", 0";
					}
				}
				$sql .= ")";
				$ret = mysql_query($sql);
				if (!$ret) {
					if (_DEBUG_ERROR_MSG == "YES") {
						error_exit("追加 失敗。<br><br>".$sql, True);
					} else {
						error_exit("追加 失敗。", True);
					}
				}
			}
		}
	}
}
// ****************************************************************
function mp_list_update_sql_item($item_tbl, $upid, $must_item) {
// ****************************************************************
	$sql = "";
	foreach ($item_tbl as $id=>$item) {
		if (left($item['type'],7) <> 'no_edit' and $item['下位フィルタ_GET名'].'' == '') {
			if ($item['toInt'] == "Y") {
				$val = toInt($_POST[$item['列名'].$upid]);
			} elseif ($item['type'] == "date") {
				$year = $_POST['Y'.$item['列名'].$upid];
				$month = $_POST['M'.$item['列名'].$upid];
				$day = $_POST['D'.$item['列名'].$upid];
				if (checkdate($month, $day, $year)) {
					$val = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
				} else {
					$val = '';
				}
			} elseif ($item['type'] == "time") {
				$hour = $_POST['HH'.$item['列名'].$upid];
				$minute = $_POST['MM'.$item['列名'].$upid];
				if ($hour <> "") {
					$val = "'2008-1-1 ".$hour.":".$minute.":00'";
				} else {
					$val = "NULL";
				}
			} else {
				if ($item['列名'] == $must_item && $_POST[$must_item.$upid] == "") {
					$val = "(未記入)";
				} else {
					$val = form_str_adjust($_POST[$item['列名'].$upid]);
				}
			}
			if ($item['type'] == "time") {
				$sql .= ", ".$item['列名']." = ".$val;
			} else {
				$sql .= ", ".$item['列名']." = '".str_for_mysql($val)."'";
			}
			if ($item['strip_tags'] == "Y") {
				$val = form_str_adjust_strip_tags($_POST[$item['列名'].$upid]);
				$sql .= ", ".$item['列名']."_strip_tags = '".str_for_mysql($val)."'";
			}
		}
	}
	return ($sql);
}
// ****************************************************************
function mp_list_update_sql_where($item_tbl, $upid) {
// ****************************************************************
	$sql = "";
	foreach ($item_tbl as $id=>$item) {
		if (left($item['type'],7) <> 'no_edit' and $item['下位フィルタ_GET名'].'' == '') {
			if ($item['toInt'] == "Y") {
				$val = toInt($_POST[$item['列名'].$upid]);
			} elseif ($item['type'] == "date") {
				$year = $_POST['Y'.$item['列名'].$upid];
				$month = $_POST['M'.$item['列名'].$upid];
				$day = $_POST['D'.$item['列名'].$upid];
				if (checkdate($month, $day, $year)) {
					$val = "(Year(".$item['列名'].") <> '".$year."'";
					$val .= " or Month(".$item['列名'].") <> '".$month."'";
					$val .= " or Day(".$item['列名'].") <> '".$day."')";
				} else {
					$val = "EROOOOOOOOOOOOR";
				}
			} else {
				$val = $_POST[$item['列名'].$upid];
			}
			if ($val."" <> "EROOOOOOOOOOOOR") {		// $val <> ..だと「0」の時Falseになってしまう。
				if ($sql <> "") {
					$sql .= " or ";
				}
				if ($item['type'] <> "date") {
					$sql .= $item['列名']." <> '".$val."'";
				} else {
					$sql .= $val;
				}
			}
		}
	}
	return ($sql);
}
// ****************************************************************
function mp_list_insert_sql_item_name($item_tbl) {
// ****************************************************************
	$sql = "";
	foreach ($item_tbl as $id=>$item) {
		if (left($item['type'],7) <> 'no_edit' and $item['下位フィルタ_GET名'].'' == '') {
			$sql .= ", ".$item['列名'];
		}
		if ($item['strip_tags'] == "Y") {
			$sql .= ", ".$item['列名']."_strip_tags";
		}
	}
	return ($sql);
}
// ****************************************************************
function mp_list_insert_sql_item_data($item_tbl, $addid) {
// ****************************************************************
	$sql = "";
	foreach ($item_tbl as $id=>$item) {
		if ($item['type'] == "date") {
			$year = $_POST['ADD_REC'.'Y'.$item['列名'].$addid];
			$month = $_POST['ADD_REC'.'M'.$item['列名'].$addid];
			$day = $_POST['ADD_REC'.'D'.$item['列名'].$addid];
			if (checkdate($month, $day, $year)) {
				$val = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
			} else {
				$val = '';
			}
			$sql .= ", '".$val."'";
		} elseif ($item['type'] == "time") {
			$hour = $_POST['ADD_REC'.'HH'.$item['列名'].$addid];
			$minute = $_POST['ADD_REC'.'MM'.$item['列名'].$addid];
			if ($hour <> "") {
				$val = str_for_mysql("'2008-1-1 ".$hour.":".$minute.":00'");
			} else {
				$val = "NULL";
			}
			$sql .= ", ".$val;
		} elseif (left($item['type'],7) <> 'no_edit' and $item['下位フィルタ_GET名'].'' == '') {
			if ($item['toInt'] == "Y") {
				$val = toInt($_POST['ADD_REC'.$item['列名'].$addid]);
			} else {
				$val = form_str_adjust($_POST['ADD_REC'.$item['列名'].$addid]);
			}
			$sql .= ", '".str_for_mysql($val)."'";
		}
		if ($item['strip_tags'] == "Y") {
			$val = form_str_adjust_strip_tags($_POST['ADD_REC'.$item['列名'].$addid]);
			$sql .= ", '".str_for_mysql($val)."'";
		}
	}
	return ($sql);
}
// ****************************************************************
function mp_list_page_control($rowcnt, $page, $pagemax, $http_arg) {
// ****************************************************************
	$arg = query_from_http_arg_pool($http_arg);
?>
<div class="mp_list_page_control">
<span class="mp_list_page_control_info">
	<span class="choice">件数：<span class="mp_rowcnt"><?= $rowcnt ?></span>件</span>
	<span class="choice">頁：<span class="mp_page"><?= $page ?></span>/<span class="mp_pagemax"><?= $pagemax ?></span></span>
</span>
<span class="mp_list_page_control_move">
	<?php if ($page > 1) { ?>
		<span><a href="?page=1&<?= $arg ?>">[←先頭]</a></span>
		<span><a href="?page=<?= $page-1 ?>&<?= $arg ?>">[←前]</a></span>
	<?php } else { ?>
		<span class="link_off">[←先頭]</span>
		<span class="link_off">[←前]</span>
	<?php } ?>
	<?php if ($page < $pagemax) { ?>
		<span><a href="?page=<?= $page+1 ?>&<?= $arg ?>">[→次]</a></span>
		<span><a href="?page=<?= $pagemax ?>&<?= $arg ?>">[→最後]</a></span>
	<?php } else { ?>
		<span class="link_off">[→次]</span>
		<span class="link_off">[→最後]</span>
	<?php } ?>
</span>
</div>
<?php
}
// ****************************************************************
function select_view_ymd($name, $suffix, $first, $end, $now) {
// ****************************************************************
	echo "<select name='".$name."'>";
	for ($i=$first; $i<=$end; $i++) {
		echo "<option value='".$i."'";
		if ($i == $now) {
			echo " selected";
		}
		echo ">".$i."</option>";
	}
	echo "</select>".$suffix;
}
// ****************************************************************
function select_view_time($name, $now_time, $pre_name='') {
// ****************************************************************
	$hour_name = $pre_name.'HH'.$name;
	$minute_name = $pre_name.'MM'.$name;
	if ($now_time.'' <> '') {
		$hour = date_from_mysql("H", $now_time);
		$minute = date_from_mysql("i", $now_time);
	} else {
		$hour = '';
		$minute = '';
	}
	echo "<select name='".$hour_name."'>";
	echo "<option value=''>";
	for ($sel=8; $sel<=23; $sel++) {
		$hh = right("0".$sel,2);
		echo "<option value='".$hh."'";
		if ($hh == $hour) {
			echo " selected";
		}
		echo ">".$hh."</option>";
	}
	for ($sel=0; $sel<=7; $sel++) {
		$hh = right("0".$sel,2);
		echo "<option value='".$hh."'";
		if ($hh == $hour) {
			echo " selected";
		}
		echo ">".$hh."</option>";
	}
	echo "</select>";
	echo "<select name='".$minute_name."'>";
	for ($sel=0; $sel<=50; $sel+=10) {
		$mm = right("0".$sel,2);
		echo "<option value='".$mm."'";
		if ($mm == $minute) {
			echo " selected";
		}
		echo ">".$mm."</option>";
		if ($sel == 10 or $sel == 40) {
			$mm = right("0".$sel+5,2);
			echo "<option value='".$mm."'";
			if ($mm == $minute) {
				echo " selected";
			}
			echo ">".$mm."</option>";
		}
	}
	echo "</select>";
}
?>
