<%
if user
  found = nil
  ary = []
  count, total = @saifu.retrieve_all(user) do |x| 
    ary.push(x)
    found = x if x.key == @edit
  end
  bg = ERbUtil::BGAttr.new
%>
<h2><%=h user %></h2>
<p>total: <%=total%></p>
<table 
  border="0" cellpadding="0" cellspacing="0" 
  width="100%" bgcolor="#ddddaa">
<tr>
<td valign="top" bgcolor="white">
<table 
  border="0" cellpadding="0" cellspacing="0" 
  width="100%">
<% 
  if found 
%>
  <tr <%=bg%>>
    <td colspan="3">&nbsp;</td>
    <td align="center">
      <%=a('detail', {'key'=>-1}, context)%>new</a>
    </td>
  </tr>
<% 
  else 
    bg.succ
%>
  <tr bgcolor="#ddddaa"><td align="center" colspan="4">&nbsp;</td></tr>
<% 
  end 
%>
<%
  ary.each do |rec|
    bgattr = if rec.key == @edit
               bg.succ
               'bgcolor="#ddddaa"'
             else	
               bg
             end
%>
<tr <%=bgattr%>>
  <td>[<%=a('delete', {'key'=>rec.key.to_s}, context)%>X</a>]
      <%=h rec.date %></td>
  <td><%=h rec.memo %></td>
  <td align="right"><%=h rec.value %></td>
  <td align="center">[<%=a('detail', {'key'=>rec.key.to_s}, context)%>>></a>]</td>
</tr>
<%
  end
%>
</table>
</td>
<td valign='top'>
<% 
  if found 
%>
<%=form('update', context)%>
<input type="hidden" name="key" value="<%=h found.key %>" />
<table 
  border="0" cellpadding="0" cellspacing="0" 
  width="100%" bgcolor="#ddddaa">
<tr><th colspan="2">edit</th></tr>
<tr>
 <th>date</th>
 <td>
  <input size="24" type="text" name="date" value="<%=h found.date%>" />
 </td>
</tr>
<tr>
 <th>memo</th>
 <td>
  <input size="24" type="text" name="memo" value="<%=h found.memo%>" />
  </td>
</tr>
<tr>
 <th>value</th>
 <td>
  <input size="24" type="text" name="value" value="<%=h found.value%>" />
  </td>
</tr>
<tr>
 <td align="center" colspan="2">
  <input type="submit" value="Update" />
 </td>
</tr>
</table>
<% 
  else 
    date = Time.now.strftime("%Y-%m-%d")
%>
<%=form('add', context)%>
<table 
  border="0" cellpadding="0" cellspacing="0" 
  width="100%" bgcolor="#ddddaa">
<tr><th colspan="2">add</th></tr>
<tr>
 <th>date</th>
 <td>
  <input size="24" type="text" name="date" value="<%=h date%>" />
 </td>
</tr>
<tr>
 <th>memo</th>
 <td>
  <input size="24" type="text" name="memo" value="" />
  </td>
</tr>
<tr>
 <th>value</th>
 <td>
  <input size="24" type="text" name="value" value="0" />
  </td>
</tr>
<tr>
 <td align="center" colspan="2">
  <input type="submit" value="Add" />
 </td>
</tr>
</table>
<% 
  end 
%>
</td>
</tr>
</table>
<%

end
%>