<? require_once "application_top.php";
require_once "include/dbconnect.php";
if(isset($_SESSION['uid']) && ($_SESSION['uid'])){
	$sql = "select * from users where uid = '".$_SESSION['uid']."' limit 0, 1";
	$results = mysql_query($sql) or die(mysql_error());
	$row = mysql_fetch_array($results);
}else{
	if(isset($_REQUEST['donorusername']) && ($_REQUEST['donorusername'])){
		$sql = "select * from users where username = '".$_REQUEST['donorusername']."' and ipassword = '".$_REQUEST['ipassword']."' limit 0, 1";
		$results = mysql_query($sql) or die(mysql_error());
		$numrows = mysql_num_rows($results);
		if(!$numrows){
			header("location:index.php?msg=<div class=msg>Username / Password incorrect</div>");
			exit;
		}
		$row = mysql_fetch_array($results);
		$_SESSION['uid'] = $row['uid'];
	}else{
		header("location:index.php?msg=<div class=msg>Username / Password incorrect</div>");
		exit;
	}
}
?>

<?
if(isset($_REQUEST['update']) && ($_REQUEST['update'])){
	
	require_once "include/dbconnect.php";
	
	$fname = $_REQUEST['fname']; 
	$ipassword = $_REQUEST['ipassword']; 
	$bloodgroup = $_REQUEST['bloodgroup']; 
	$mobile = $_REQUEST['mobile']; 
	$dayphone = $_REQUEST['dayphone']; 
	$evephone = $_REQUEST['evephone']; 

	$chkSMS = (isset($_REQUEST['chkSMS']))? $_REQUEST['chkSMS'] : ""; 
	
	$statecity = (isset($_REQUEST['stateId2']) && ($_REQUEST['stateId2']))? " state = '".$_REQUEST['stateId2']."', city = '".$_REQUEST['mycity']."', "  : "";
	
	$how_often = $_REQUEST['how_often']; 

	$dlast = $_REQUEST['dlast']; 
	$mlast = $_REQUEST['mlast']; 
	$ylast = $_REQUEST['ylast']; 

	$chkHideMobile = (isset($_REQUEST['chkHideMobile']))? $_REQUEST['chkHideMobile'] : ""; 
	$suffered1 = "";
	if(count($_REQUEST['suffered1'])){
		$cnt = 0;
		foreach($_REQUEST['suffered1'] as $suffer){
			$comma = ($cnt)? "," : ""; 
			$suffered1 .= $comma.$suffer;
			$cnt++;
		}
	}
	$sql = "update users set $statecity fname = '$fname', mobile = '$mobile', dayphone = '$dayphone', evephone = '$evephone', chkSMS = '$chkSMS', how_often = '$how_often', dlast = '$dlast', mlast = '$mlast', ylast = '$ylast', chkHideMobile = '$chkHideMobile', suffered1 = '$suffered1' where uid = '".$_SESSION['uid']."'";
	$results = mysql_query($sql) or die(mysql_error());
	header("location:login.php?msg=<div class='msg'>Record Updated successfully</div>");
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Bihar Blood Bank</title>

<? include ("include/header.php"); ?>

	<table id="containerTable" border="0">
	<tr>
		<td width="220">
		<? require "left.php";?>
		</td>
		
		<td width="500px;text-align:center;">
		
		<h1>My Account</h1>
		
		<?=$msg;?>
		
		<div id="form">
		
		<form name="newfrm" id="newfrm" action="<?=$_SERVER['PHP_SELF'];?>?update=1" method="post" onsubmit="return register();" style="margin:0px;">
		<fieldset>
			<div align="right"  class="linktxt" >* Mark fields are mandatory</div>	
			<div style="width:255px;float:left;">
				<div style="padding:10px;"><span><font class="boldtxt">Name<font class="formclr">*</font> :</font></span><br>
				<input type="text" name="fname" id="fname" tabindex="1" value="<?=$row['fname'];?>" class="required" size="30" maxlength="50">
				</div>
				<div style="padding:10px;padding-top:18px;"><span><font class="boldtxt">Password<font class="formclr">*</font>:</font></span><br>
				<input type="password" name="ipassword" id="ipassword" tabindex="3" value="<?=$row['ipassword'];?>" class="required" minlength="4" size="30"><br>
				<font class="frmcomments">Minimum 4 characters allowed</font></div>
				
			
				<div class="left" style="padding:10px;"><span><font class="boldtxt">Contact Number :</font></span>
					<div class="left" style="padding-bottom:10px;width:60px;">Mobile<font class="formclr">*</font>:</div>
					<div class="left" style="padding-bottom:10px;">
					<input type="text" name="mobile" id="mobile" class="required" value="<?=$row['mobile'];?>" tabindex="12"></div><br clear="all">
					<div class="left" style="padding-bottom:10px;width:60px;">Residence:</div>
					<div class="left" style="padding-bottom:10px;">
					<input type="text" name="dayphone" id="dayphone" class="textbox" value="<?=$row['dayphone'];?>" tabindex="13"></div><br clear="all">
					<div class="left" style="padding-bottom:10px;width:60px;">Office:</div>
					<div class="left" style="padding-bottom:10px;">
					<input type="text" name="evephone" id="evephone" class="textbox" value="<?=$row['evephone'];?>" tabindex="14"></div><br clear="all">
					<font class="frmcomments">Note: Please provide at least one contact number. But it is recommended to provide as many contact numbers as possible because it will be easier for the recipients to contact you in times of emergency. Remember a life may be depending on you!</font>
				</div><br clear="all">
				<div style="padding:10px;"><span><font class="boldtxt">SMS Alert :</font></span>
				<INPUT TYPE="checkbox" NAME="chkSMS"  id="chkSMS"  value="1" <?=($row['chkSMS'])? "checked=checked" : "";?>  tabindex="19"><br><font class="frmcomments">You will receive an alert on your mobile when there is a request for your blood type within your city.</font></div>
				
				<div style="padding:10px;">
				<b>(Leaave this if you don't want to change your State and City)</b><br/>
				<span><font class="boldtxt">State:</font></span><br>
				<div id="state">
					<? 
					$StateInputIdName = "stateId2";
					include "include/states.php"; 
					?>
				</div>
				</div>
				<div style="padding:10px;"><span><font class="boldtxt">City:</font></span><br>
				<div id="afdd">
					<? 
					$loaderDivName = "cityDiv2";
					include "include/cities.php";?>
				</div>
				</div>
				<div style="padding:10px;"><span><font class="boldtxt">Area:</font><br>		
				<div id="area">
				<select style="width:200px;" id="town" NAME="town" size="1" tabindex="24">		
					<option value="">Select Area</option>
					<option value="all" selected="selected">All</option>
				</select></div>
				</div>
				
				
				
				<div style="padding:10px;"><span><font class="boldtxt">How often have you donated blood in the past?</font></span><br>
					<select style="width:100px;" class="smalltxt textbox" name="how_often" id="how_often" size="1" tabindex="26">
						<option value="yet to donate" <? if($row['how_often'] == "yet to donate"){ ?>selected = "selected"<? } ?>>Yet to donate</option>
						<option value="regular donor" <? if($row['how_often'] == "regular donor"){ ?>selected = "selected"<? } ?>>Regular donor</option>
						<option value="on need basis" <? if($row['how_often'] == "on need basis"){ ?>selected = "selected"<? } ?>>On need basis</option>
					</select>
				</div>
				
			</div>
			<div class="left" style="border-left:1px dotted #000000;width:235px;float:left;">	
				
				<div style="padding:10px;"><span><font class="boldtxt">Date of last blood donation :</font></span><br>
				
				<select style="width:45px;" class="smalltxt textbox" NAME="dlast" id="dlast" size="1" tabindex="16">
					<option value="">DD
						<?
						for($i=1;$i<=31;$i++){
						if($i<10){ $i = "0$i"; }
						?>
						<option value="<?=$i;?>" <?=($row['dlast']== $i)? "selected = selected" : "";?>><?=$i;?></option>
						<?
						}
						?>
				</select>
				<select style="width:45px;" class="smalltxt textbox" NAME="mlast" id="mlast" size="1" tabindex="17">
					<option value="">MM
						<?
						for($i=1;$i<=12;$i++){
						if($i<10){ $i = "0$i"; }
						?>
						<option value="<?=$i;?>" <?=($row['mlast']== $i)? "selected = selected" : "";?>><?=$i;?></option>
						<?
						}
						?>
				</select>
				<select style="width:55px;" class="smalltxt textbox" NAME="ylast" id="ylast" size="1" tabindex="18">
					<option value="">YYYY
					<?
						for($i=1950;$i<=2011;$i++){
						if($i<10){ $i = "0$i"; }
						?>
						<option value="<?=$i;?>" <?=($row['ylast']== $i)? "selected = selected" : "";?>><?=$i;?></option>
						<?
						}
						?>
				</select><br><font class="frmcomments">(optional)</font>
				</div>

				<div style="padding:0px 10px 10px 10px;"><span><font class="boldtxt">Hide Mobile Number<font class="formclr"></font>:</font></span><INPUT TYPE="checkbox" NAME="chkHideMobile" value="1" <?=($row['chkHideMobile'])? "checked = checked" : "";?> tabindex="20"></div>

				<!-- <div style="padding:10px;"><font class="boldtxt">Personal Message</font><br><font class="smalltxt">(Message from donor)</font> :<br><textarea rows=3 cols=30 name="about_me" tabindex="24"  class="textbox"></textarea></div> -->
			</div>
			</div>
		</div>

	<div class="clear"></div>
	
	<div style="float:left;width:561px;border:1px solid #D7D7D7;">
		<div class="left" style="width:561px;">
				<div style="background: url(images/div-spheadbg-crv.gif);"></div>
						<div class="left" style="width:541px;">
						
						

						<div style="padding-left:30px;"><font color="#FF0000">#</font> <font class="frmcomments">Please consult your physician to check for eligibility.</font></div>
						<div style="padding:10px;"><input type="checkbox" name="suffered" value="YES" checked class="required" tabindex="31">I have read the above eligibility criteria and confirm that I am eligible to donate blood.</div><br>
						<center><input type="submit" value=" Update " class="button"></center>

						</div>
				
		</div>
		</fieldset>
		</form><br>
	</div>
</div>
		
		</td>
		
		<td width="220" align="right">
		<? require "right.php";?>
		</td>
	</tr>
	</table>
	
<? include ("include/footer.php"); ?>