<?php
function add_where_create($http_arg) {
	$add_where = "";
	for ($ix=1; $ix<=5; $ix++) {
		if ($_GET['chk'.$ix] <> '') {
			if ($_GET['chk'.$ix] == 'all') {
				 $_SESSION['abook_chk_sel'.$ix] = '';
			} else {
				 $_SESSION['abook_chk_sel'.$ix] = $_GET['chk'.$ix];
			}
		}
		if ($_SESSION['abook_chk_sel'.$ix] <> '') {
			if ($add_where <> "") $add_where .= " and";
			$add_where .= " c_check".$ix." = '".$_SESSION['abook_chk_sel'.$ix]."'";
		}
	}
	if ($_GET['yomi'].'' == '__reset__') {
		$_SESSION['abook_yomi'] = '';
	} elseif ($_GET['yomi'].'' <> '') {
		$_SESSION['abook_yomi'] = $_GET['yomi'];
	}
	if ($_SESSION['abook_yomi'] <> '') {
		if ($add_where <> "") $add_where .= " and";
			if ($_SESSION['abook_yomi'] >= 'A' and $_SESSION['abook_yomi'] <= 'Z') {
				$add_where .= " (c_name1 like '".$_SESSION['abook_yomi']."%'";
				$add_where .= " or c_name2 like '".$_SESSION['abook_yomi']."%'";
				$add_where .= " or c_yomi1 like '".$_SESSION['abook_yomi']."%'";
				$add_where .= " or c_yomi2 like '".$_SESSION['abook_yomi']."%' )";
			} else {
				$add_where .= " (";
				$kana_ary = kana_array();
				foreach ($kana_ary as $kana) {
					if ($kana[0] == $_SESSION['abook_yomi']) {
						$len = mb_strlen($kana[1]);
						for ($ix=0; $ix<$len; $ix++) {
							if ($ix<>0) {
								$add_where .= " or";
							}
							$add_where .= " c_name1 like '".mb_substr($kana[1],$ix,1)."%'";
							$add_where .= " or c_name2 like '".mb_substr($kana[1],$ix,1)."%'";
							$add_where .= " or c_yomi1 like '".mb_substr($kana[1],$ix,1)."%'";
							$add_where .= " or c_yomi2 like '".mb_substr($kana[1],$ix,1)."%'";
						}
					}
				}
				$add_where .= " )";
			}
	}
	return ($add_where);
}
?>
<?php
function add_my_filter($http_arg) {
?>
	<div id="check_select">
<script language="JavaScript">
jQuery(function(){
	jquery_cs_function = 'SelectionYomi';
	jquery_cs_arg = 'yomi';
	jquery_cs_style = '';
	$('#jquery_cs_yomi select').cs();
});
function SelectionYomi(key, data) {
	window.location.href = "?"+key+"="+data+"&<?= query_from_http_arg_pool($http_arg, 'yomi') ?>";
}
function SelectionYomiReset() {
	window.location.href = "?yomi=__reset__&<?= query_from_http_arg_pool($http_arg, 'yomi') ?>";
}
</script>
<span id="jquery_cs_yomi">
	読み：<select class="<? if ($_SESSION['abook_yomi'] <> '') echo 'mp_list_filter_true'; ?>">：
	<option value="__reset__" class="mp_list_filter_false">すべて</option>
<?php
	$kana_ary = kana_array();
	$ix = 0;
	foreach ($kana_ary as $kana) {
		if ((floor($ix/5)*5 == $ix and $ix <= 35) or $ix == 38 or $ix == 43) {
			if ($ix <> 0) {
				if (!strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
				// IE以外 (なぜか一番下の選択肢がリセットのボックスにはみ出してしまうため)
?>
			<option value=""></option>
<?php
				}
?>
		</optgroup>
<?php
			}
?>

		<optgroup label="<?= $kana[0] ?>">
<?php
		}
?>
		<option value="<?= urlencode($kana[0]) ?>"<?= $kana[0] == $_SESSION['abook_yomi'] ? ' selected class="mp_list_filter_true"' : ' class="mp_list_filter_false"' ?>><?= $kana[0] ?></option>
<?php
		$ix++;
	}
	for ($ix=65; $ix<91; $ix++) {
		if (floor($ix/5)*5 == $ix and $ix <> 90) {
				if (!strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
				// IE以外 (なぜか一番下の選択肢がリセットのボックスにはみ出してしまうため)
?>
			<option value=""></option>
		</optgroup>
<?php
			}
?>
		<optgroup label="<?= chr($ix) ?>">
<?php
		}
?>
		<option value="<?= chr($ix) ?>"<?= chr($ix) == $_SESSION['abook_yomi'] ? ' selected class="mp_list_filter_true"' : ' class="mp_list_filter_false"' ?>><?= chr($ix) ?></option>
<?php
	}
		if (!strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
		// IE以外 (なぜか一番下の選択肢がリセットのボックスにはみ出してしまうため)
?>
		<option value=""></option>
<?php
		}
?>
		</optgroup>
	</select>
	<input type="button" value="リセット" onClick="SelectionYomiReset()">
</span>
<script language="JavaScript">
function SelectionCheck(form, sel, no) {
	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) ?>&chk' + no + '=' + sel.options[i].value;
		}
	}
}
function SelectionCheckClear() {
	window.location.href = '<?= $_SERVER['SCRIPT_NAME'] ?>?<?= query_from_http_arg_pool($http_arg) ?>&chk1=all&chk2=all&chk3=all&chk4=all&chk5=all';
}
function CheckboxEmailOnOff(onOff) {
	if (onOff == 'off') {
		window.location.href = "<?= $_SERVER['SCRIPT_NAME'] ?>?<?= query_from_http_arg_pool($http_arg) ?>&em=on";
	} else {
		window.location.href = "<?= $_SERVER['SCRIPT_NAME'] ?>?<?= query_from_http_arg_pool($http_arg) ?>&em=off";
	}
}
</script>
チェック有無：
<?php
	for ($ix=1; $ix<=5; $ix++) {
?>
	<?= roman_number($ix) ?>：<select name="" onchange="SelectionCheck(this.form, this, <?= $ix ?>)"<? if ($_SESSION['abook_chk_sel'.$ix] <> '') echo ' class="mp_list_filter_true"'; ?>>
	<option value="all" class="mp_list_filter_false">
	<option value="1"<?= $_SESSION['abook_chk_sel'.$ix] == '1' ? ' selected class="mp_list_filter_true"' : ' class="mp_list_filter_false"' ?>>有
	<option value="0"<?= $_SESSION['abook_chk_sel'.$ix] == '0' ? ' selected class="mp_list_filter_true"' : ' class="mp_list_filter_false"' ?>>無
	</select>
<?php
	}
?>
	<input type="button" value="リセット" onClick="SelectionCheckClear()">
	<input type="checkbox" name="" value="on" onClick="CheckboxEmailOnOff('<?= $_SESSION['abook_email_off'] ?>')"<?= $_SESSION['abook_email_off'] == 'off' ? ' checked' : '' ?>><span<?= $_SESSION['abook_email_off'] == 'off' ? ' class="mp_list_filter_true"' : '' ?>>電話・EMail表示なし</span>
	</div>
<?php
	global $chk_use;	// list-my-template.phpで使用
	$chk_use = array();
	$sqlchk = "select * from m_check_caption where id_account = " . $_SESSION['current_id'];
	$sqlchk .= " and ( c_caption1 <> '' or c_caption2 <> '' or c_caption3 <> '' or c_caption4 <> '' or c_caption5 <> '' )";
	$rs_chk = my_mysql_query($sqlchk);
	if (mysql_num_rows($rs_chk) <> 0) {
		$rec = mysql_fetch_array($rs_chk);
		if ($rec) {
			echo '<p id="check_caption_box">';
			for ($ix=1; $ix<=5; $ix++) {
				if ($rec['c_caption'.$ix] <> '') {
					$chk_use[$ix] = True;
					echo '<span class="check_caption"><b>'.roman_number($ix).'</b>：&nbsp;'.$rec['c_caption'.$ix].'</span>&nbsp;&nbsp;';
				} else{
					$chk_use[$ix] = False;
				}
			}
			echo '</p>';
		}
	}
}
?>
<?php
function kana_array() {
	$kana = array(
			array('あ','あア'),
			array('い','いイ'),
			array('う','うウヴ'),
			array('え','えエ'),
			array('お','おオ'),
			array('か','かカがガ'),
			array('き','きキぎギ'),
			array('く','くクぐグ'),
			array('け','けケげゲ'),
			array('こ','こコごゴ'),
			array('さ','さサざザ'),
			array('し','しシじジ'),
			array('す','すスずズ'),
			array('せ','せセぜゼ'),
			array('そ','そソぞゾ'),
			array('た','たタだダ'),
			array('ち','ちチぢヂ'),
			array('つ','つツづヅ'),
			array('て','てテでデ'),
			array('と','とトどド'),
			array('な','なナ'),
			array('に','にニ'),
			array('ぬ','ぬヌ'),
			array('ね','ねネ'),
			array('の','のノ'),
			array('は','はハばバぱパ'),
			array('ひ','ひヒびビぴピ'),
			array('ふ','ふフぶブぷプ'),
			array('へ','へヘべベぺペ'),
			array('ほ','ほホぼボぽポ'),
			array('ま','まマ'),
			array('み','みミ'),
			array('む','むム'),
			array('め','めメ'),
			array('も','もモ'),
			array('や','やヤ'),
			array('ゆ','ゆユ'),
			array('よ','よヨ'),
			array('ら','らラ'),
			array('り','りリ'),
			array('る','るル'),
			array('れ','れレ'),
			array('ろ','ろロ'),
			array('わ','わワ'),
			array('を','をヲ'),
			array('ん','んン'),
		);
	return $kana;
}
?>
