<?php include('up_index.php');?>
<?php include('admin.php');?>
<script src="java-update.js"></script>
<script language="javascript">
	$(document).ready(function(e) {
		$("#show_update").hide();
		$("#m1").click(function(e) {
			$("#show_update").hide(500);
			$("#show_sale").show(500);
		});
		$("#m2").click(function(e) {
			$("#show_update").show(500);
			$("#show_sale").hide(500);
		});
	});
	
</script>
<center>
    <br/>
    <div class="table_product_show">

    <br/>
    <table width="200" border="0">
      <tr>
		<?php if($lv_chk=="admin"){ ?><td><a href="menu_admin.php"><div class="link3">จัดการระบบ</div></a></td><?php } ?>
        <td><div id="m1" class="link3"><font color="#FFFFFF">รายการสั่งซื้อ</font></div></a></td>
        <td><div id="m2" class="link3"><font color="#FFFFFF">แก้ไขสมาชิก</font></div></a></td>
      </tr>
    </table>
	<div id="show_sale">

 <br/> <br/>
 <table width="800" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td width="100" align="center">เลขที่สั่งชื้อ</td>
    <td width="400" align="center">โดย</td>
    <td width="150" align="center">เวลาสั่งชื้อ</td>
    <td width="150" align="center">สถานะ</td>
  </tr>
  <script src="show.js"></script>
  <?php 
	$strSQL = "SELECT * FROM sale p,members m where p.user = m.user and p.user='".$_GET['user']."'";
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	$Num_Rows = mysql_num_rows($objQuery);
	
	$Per_Page = 20;   // Per Page
	
	$Page = $_GET["Page"];
	if(!$_GET["Page"])
	{
		$Page=1;
	}
	
	$Prev_Page = $Page-1;
	$Next_Page = $Page+1;
	
	$Page_Start = (($Per_Page*$Page)-$Per_Page);
	if($Num_Rows<=$Per_Page)
	{
		$Num_Pages =1;
	}
	else if(($Num_Rows % $Per_Page)==0)
	{
		$Num_Pages =($Num_Rows/$Per_Page) ;
	}
	else
	{
		$Num_Pages =($Num_Rows/$Per_Page)+1;
		$Num_Pages = (int)$Num_Pages;
	}
	
	$strSQL .=" ORDER BY date_book DESC LIMIT $Page_Start , $Per_Page";
	$objQuery  = mysql_query($strSQL);

	while ($objResult  = mysql_fetch_array($objQuery))
	{
		
		echo "<tr>
			<td align=\"center\"><a id=\"alink\" href=\"sale_confirm.php?id_sale=".$objResult ['id_sale']."\">".$objResult ['id_sale']."</a></td>
			<td><a id=\"alink\" href=\"sale_confirm.php?id_sale=".$objResult ['id_sale']."\">  ".$objResult ['fname']." ".$objResult['lname']."</a></td>
			<td align=\"center\"><a id=\"alink\" href=\"sale_confirm.php?id_sale=".$objResult ['id_sale']."\">".$objResult ['date_book']."</a></td>
			<td align=\"center\"><a id=\"alink\" href=\"sale_confirm.php?id_sale=".$objResult ['id_sale']."\">".$objResult ['status']."</a></td>
		</tr>";
		
	}	
	?>
</table>
<br/>
	<?php
	if($Prev_Page)
{
	echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&status=".$_GET['status']."'><< Back</a> ";
}

for($i=1; $i<=$Num_Pages; $i++){
	if($i != $Page)
	{
		echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&status=".$_GET['status']."'>$i</a> ]";
	}
	else
	{
		echo "<b> $i </b>";
	}
}
if($Page!=$Num_Pages)
{
	echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&status=".$_GET['status']."'>Next>></a> ";
}

?>

  </div>
<div id="show_update">
<form method="post" name="register" id="register" action="save_update_user.php" >
		<h1>แก้ไขสมาชิก</h1><?php
	$sql = "select * from members where user ='".$_GET['user']."'";
	$result = mysql_query($sql);
	while ($user = mysql_fetch_array($result))
	{


		?>
        
        <table width="500" border="0" cellpadding="1" cellspacing="1">
          <tr>
            <td width="200">Username : </td>
            <td width="300"><input name="txtuser" type="text" id="txtuser" value="<?=$user['user'];?>" size="20" maxlength="100" readonly="readonly" />
            <div id="txtnamaok" style="float:right;"></div></td>
          </tr>
          <tr>
            <td>Password : </td>
            <td><input name="txtpass" type="password" id="txtpass" value="<?=$user['pass'];?>" size="20" maxlength="100" />
            <div id="txtpassok" style="float:right;"></div></td>
          </tr>
          <tr>
            <td>Re-Password : </td>
            <td><input name="txtpass2" type="password" id="txtpass2" value="<?=$user['pass'];?>" size="20" maxlength="100" />
            <div id="txtpassok2" style="float:right;"></div></td>
          </tr>
          <tr>
            <td>ชื่อ : </td>
            <td><input name="txtfname" type="text" id="txtfname" value="<?=$user['fname'];?>" size="22" maxlength="100" />
            <div id="txtfnameok" style="float:right;"></div></td>
          </tr>
          <tr>
            <td>นามสกุล : </td>
            <td><input name="txtlname" type="text" id="txtlname" value="<?=$user['lname'];?>" size="22" maxlength="100" />
            <div id="txtlnameok" style="float:right;"></div></td>
          </tr>
          <tr>
            <td>เพศ :</td>
            <td><input name="radio" type="radio" id="sex" value="ชาย" <?php if($user['sex']=="ชาย")echo "checked=\"checked\"" ?>/>
            
            ชาย 
            <input type="radio" name="radio" id="sex" value="หญิง" <?php if($user['sex']=="หญิง")echo "checked=\"checked\"" ?>/>
            หญิง</td>
          </tr>
          <tr>
            <td>เลขบัตรประจำตัวประชาชน : </td>
            <td><input name="id_key" type="text" id="id_key" value="<?=$user['id_key'];?>" size="15" maxlength="13" />
            <div id="id_keyok" style="float:right;"></div></td>
          </tr>
          <tr>
            <td>ที่อยู่ : </td>
            <td><textarea name="address" cols="50" rows="10" id="address"><?=$user['address'];?>
            </textarea>
            <div id="addressok" style="float:right;"></div></td>
          </tr>
          <tr>
            <td>เบอร์โทรศัพท์ : </td>
            <td><input name="tel" type="text" id="tel" value="<?=$user['tel'];?>" size="13" maxlength="10" />
            <div id="telok" style="float:right;"></div></td>
          </tr>
          <tr>
            <td>E-mail : </td>
            <td><input name="email" type="text" id="email" value="<?=$user['email'];?>" size="25" maxlength="100" />
            <div id="emailok" style="float:right;"></div></td>
          </tr>
          <tr>
            <td colspan="2" align="center"><input type="submit" name="submit" id="submit" value="แก้ไข" />
            <input type="reset" name="Reset" id="button" /></td>
          </tr>
        </table>
        
        <?php } ?>
	</form>
	    <br/><br/>
	</div>
</div>
    <br/>
</center>
<?php include('down_index.php'); ?>