<?php
	require("__include-common.php");
define("LOGINCHECK_SESSION_URL", "NO");		// URLをSESSION変数にセットしない。
	require("../account/__logincheck.php");
	$con = my_mysql_connect(_DB_SCHEMA);
	$sql = 'select * from m_todo where id_account = ' . $_SESSION['current_id'];
	$sql .= ' and c_delete = 0 order by c_priority desc, id_todo asc';
	$rs = my_mysql_query($sql);
	$row = mysql_num_rows($rs);
	if ($row == 0) {
		exit;
	}
?>
<script>
$("#todo_view_table").sortable({stop: function(event, ui) {
	id_nums = $("#todo_view_table").sortable("toArray");
	$.ajax({
		type: "GET",
		url: "todo-renum.php",
		data: "ids="+id_nums,
		async: false,
		success: function(){
			document.todo_form.add_todo.value="";
			document.todo_form.add_todo.focus();
			todo_view();
		}
	})
}});
</script>
<div id="todo_view_table">
<?php
	$GLOBALS['URL_2_ATAG_SHORT_LEN'] = 32;
	while ($rec=mysql_fetch_array($rs)) {
?>
		<table cellspacing=0 id="<?= $rec['id_todo'] ?>">
		<tr>
	<?php	if (is_write_permit() == True) {	?>
		<td class="todo_view_button" nowrap>
			<input type="button" value="削除" OnClick="del_id(<?= $rec['id_todo'] ?>)">
			<input type="button" value="修正" OnClick="update_view_id(<?= $rec['id_todo'] ?>)">
		</td>
	<?	}	?>
		<td class="todo_view_todo"<? if ($rec['c_color'] <> '') echo ' style="word-break: break-all; color:'.$rec['c_color'].';"' ?>>
			<?= ins_atag_br_short($rec['c_todo']) ?>
		</td>
	<?php	if (is_write_permit() == True) {	?>
		<td class="todo_view_time" nowrap>
			<?= date_from_mysql("y/m/d", $rec['c_registtime']) ?>
			<input type="button" value="↑" OnClick="up_id(<?= $rec['id_todo'] ?>)">
			<input type="button" value="↓" OnClick="down_id(<?= $rec['id_todo'] ?>)">
		</td>
	<?	}	?>
		</tr>
	<?php	if (is_write_permit() == True) {	?>
		<tr id="todo_update_inp<?= $rec['id_todo'] ?>" style="display: none;">
		<td colspan=3 nowrap>
			<input class="text" type="text" id="edit_todo<?= $rec['id_todo'] ?>" size=40 value="<?= $rec['c_todo'] ?>"<? if ($rec['c_color'] <> '') echo ' style="color: '.$rec['c_color'].';"'; ?>">
		<?php
			todo_select_color($rec['c_color'], $rec['id_todo']);
		?>
			<input type="button" value="修正" OnClick="update_done_id(<?= $rec['id_todo'] ?>)">
			<input type="button" value="ｷｬﾝｾﾙ" OnClick="update_cancel_id(<?= $rec['id_todo'] ?>)">
		</td>
		</tr>
		</table>
	<?	}	?>
<?php
	}
?>
</div>
<?php
	$con = mysql_close($con);
?>
