<?php
function sticky_body($http_arg, $table_name) {
	$con = my_mysql_connect(_DB_SCHEMA);
?>
<div id="sticky_navi_box">
<ul id="sticky_navi">
<?php
	$sql_cat = "select * from m_category where c_delete = 0";
	$sql_cat .= " and id_account = '" . $_SESSION['current_id'] . "' order by c_categoryDisplayOrder asc";
	$rs_cat = my_mysql_query($sql_cat);
	$cat_tbl = array();
	$cnt = 0;
	$cat_id = 0;
	while ($rec_cat = mysql_fetch_array($rs_cat)) {
		if ($cnt == 0 || $rec_cat['id_category'] == intval($http_arg['cat'])) {
			$cat_id = $rec_cat['id_category'];	// カテゴリ選択必須。
		}
		$cat_tbl[] = array($rec_cat['id_category'], my_htmlspecialchars($rec_cat['c_categoryName']));
		$cnt++;
	}
	if ($cnt == 0) {
		echo '<br>最初に、ボードを作成してください。';
		return;
	}
	$http_arg['cat'] = $cat_id;
	arg_val_to_http_arg_pool($http_arg, $table_name);	// 追加/修正(一覧)で、同じカテゴリで開かせるため。
	foreach ($cat_tbl as $category) {
		$categoryName = my_htmlspecialchars($rec_cat['c_categoryName']);
?>
		<li<?= ($category[0] == $cat_id) ? ' id="sticky_navi_current"' : ' class="sticky_navi_tag"' ?> style="width: <?= mb_strwidth($category[1])+4 ?>ex;">
		<a href="index.php?cat=<?= $category[0] ?>" target="_top"><?= $category[1] ?></a></li>
<?php
	}
?>
<script>
window.onload=function(){
	if(!NiftyCheck()) return;
	//RoundedTop("div#sticky_navi li", "transparent", "#404020");
	RoundedTop("li.sticky_navi_tag", "transparent", "#a9b0e0");
	AddTop(document.getElementById("sticky_navi_current"), "transparent", "#ff8c00");
}
</script>
</ul>
</div>
<div id="sticky_body"><div>
<?php
		sticky_form($cat_id);
?>
		</div>
<?php
}
?>
<?php
function sticky_form($category) {
	$query = mysql_query("select * from m_category where id_category = ".$category);
	if ($rec_cat=mysql_fetch_assoc($query)) {
		$bg_color = $rec_cat['c_bg_color'];
		$sticky_width = $rec_cat['c_sticky_width'];
		$font_size = $rec_cat['c_font_size'];
		$font_weight = $rec_cat['c_font_weight'];
		$GLOBALS['URL_2_ATAG_SHORT_LEN'] = $rec_cat['c_url_length'];
	}
	$query = mysql_query("select * from m_notes where id_account = ".$_SESSION['current_id']." and id_category = ".$category." order by id desc");
	$notes = '';
	$left='';
	$top='';
	$zindex='';
	while ($rec=mysql_fetch_assoc($query)) {
		// The xyz column holds the position and z-index in the form 200x100x10:
		list($left,$top,$zindex) = explode('x',$rec['c_xyz']);
		$notes .= '<div id="s'.$rec['id'].'" class="note '.$rec['c_color'].'"';
		$notes .= ' style="left:'.$left.'px;top:'.$top.'px;z-index:'.$zindex.';width:'.$sticky_width.'px;">';
		$notes .= '<span id="t'.$rec['id'].'" style="font-size:'.$font_size.'px;font-weight:'.$font_weight.';">'.ins_atag_br_short($rec['c_text']).'</span>';
		if (is_write_permit()) {
			$notes .= '<br><a class="editButton edit-button" href="form-edit.php?id='.$rec['id'].'&sw='.$sticky_width.'&fs='.$font_size.'">編集</a>';
		}
		$notes .= '<span class="data">'.$rec['id'].'</span>';
		$notes .= '</div>';
	}
?>
<div id="">
<?php	if (is_write_permit()) { ?>
	<a id="addButton" href="form-add.php?cat=<?= $category ?>&sw=<?= $sticky_width ?>&fs=<?= $font_size ?>">新規追加</a>
<?php	} ?>
</div>
<div id="board" style="background-color:<?= $bg_color ?>; clear:both; float:left;">
	<?php echo $notes?>
</div>
<?php
}
?>