<?php include("header.php");
if(!isset($_SESSION['cid']))
{
	?>
		<script>
        	window.location="<?php echo $actual_link?>index";
        </script>
	<?php
}

$msg="";
$sqlmydetail=mysql_query("select * from tbl_users where userid='".$_SESSION['cid']."'");
$resmydetail=mysql_fetch_assoc($sqlmydetail);


$fullname=ucwords($resmydetail['fullname']);

$explodename=explode(" ",$fullname);

$countname=count($explodename);


if(isset($_POST['update']))
{
	$fname=mysql_real_escape_string(ucfirst($_POST['fname']));
	$lname=mysql_real_escape_string(ucfirst($_POST['lname']));
	$address=mysql_real_escape_string(ucfirst($_POST['address']));
	$city=$_POST['city'];
	$locality=$_POST['locality'];
	
	
	if(isset($_FILES['file']))
	{
		
		if($_FILES['file']['name']=="")
		{
			$update=mysql_query("update tbl_users set fullname='".$fname.' '.$lname."',email='".$_POST['email']."',number='".$_POST['number']."',address='".$address."',postcode='".$_POST['postcode']."', city='$city',locality='$locality' where userid='".$_SESSION['cid']."'");
		}
		else
		{
			
			move_uploaded_file($_FILES['file']['tmp_name'],"userimage/".time().$_FILES['file']['name']);
			
			$update=mysql_query("update tbl_users set fullname='".$fname.' '.$lname."',email='".$_POST['email']."',number='".$_POST['number']."',address='".$address."',postcode='".$_POST['postcode']."', image='".time().$_FILES['file']['name']."', city='$city',locality='$locality' where userid='".$_SESSION['cid']."'");
			
		}
	}
	
	

	
	
	$msg="Profile Update Successfully";
	
	?>
		<script>
		setTimeout(function(){
			window.location.href=window.location.href;
		},1000);
		</script>
	<?php 
}

?>
 
<div class="main-container">
<div class="container">
<?php 
if($msg!=="")
{
	?>
	<div class="alert alert-success">
      <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
      <?php echo $msg;?>
    </div>
	<?php
}
?>
<div class="row">
<?php include("profileside.php");?>
 
<div class="col-sm-9 page-content">
<div class="inner-box">
<div class="row">
<div class="col-md-5 col-xs-4 col-xxs-12">
<h3 class="no-padding text-center-480 useradmin"><a href="#">
<?php if($resmydetail['image']!=="")
{?>
<img class="userImg" src="userimage/<?php echo $resmydetail['image'];?>" alt="user">
<?php }
else
{
	?>
		<img class="userImg" src="images/user.jpg" alt="user">
	<?php
}
 ?>

 <?php echo $_SESSION['cname'];?> </a> </h3>
</div>
<div class="col-md-7 col-xs-8 col-xxs-12">
<div class="header-data text-center-xs">
 
<!--<div class="hdata">
<div class="mcol-left">
 
<i class="fa fa-eye ln-shadow"></i> </div>
<div class="mcol-right">
 
<p><a href="#">7000</a> <em>visits</em></p>
</div>
<div class="clearfix"></div>
</div>-->
 
<div class="hdata">
<div class="mcol-left">
 
<i class="icon-th-thumb ln-shadow"></i> </div>
<div class="mcol-right">
<?php $sqltotala=mysql_query("select * from tbl_ads where posted_userid='".$_SESSION['cid']."' and admin_status='Approved'");

?> 
<p><a href="<?php $actual_link?>myads"><?php echo mysql_num_rows($sqltotala);?></a><em>Ads</em></p>
</div>
<div class="clearfix"></div>
</div>
 
<div class="hdata">
<div class="mcol-left">
 
<i class="fa fa-user ln-shadow"></i> </div>
<div class="mcol-right">
 <?php 
$sql_fav_ads1=mysql_query("select * from tbl_favorite where userid='".$_SESSION['cid']."'");
//$num_fav=mysql_num_rows($sql_fav_ads1);
$kl=0;
while($resfavs=mysql_fetch_assoc($sql_fav_ads1))
{
$sqlads1=mysql_query("select * from tbl_ads where ads_id='".$resfavs['ads_id']."' and admin_status!='Achieved'");
$resads1=mysql_fetch_assoc($sqlads1);

if($resads1['ads_id']>0)
{
	$kl++;
}
}

?>
<p><a href="<?php $actual_link?>favourite_ads"><?php echo $kl;?></a> <em>Favorites </em></p>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
</div>
<div class="inner-box">
<div class="welcome-msg">
<h3 class="page-sub-header2 clearfix no-padding">Hello <?php echo $_SESSION['cname'];?> </h3>
 </div>
<div id="accordion" class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"> <a href="#collapseB1" data-toggle="collapse"> My details </a> </h4>
</div>
<div class="panel-collapse collapse in" id="collapseB1">
<div class="panel-body">
<form class="form-horizontal" role="form" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="col-sm-3 control-label">First Name</label>
<div class="col-sm-8">
<input type="text" name="fname" class="form-control"  value="<?php  if($countname>2) { if(isset($explodename[0])) { echo $explodename[0]; }  if(isset($explodename[1])) { echo " ".$explodename[1]; } }else{ echo $explodename[0];}?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Last name</label>
<div class="col-sm-8">
<input type="text" name="lname" class="form-control" value="<?php  if($countname>2) 
{ if(isset($explodename[2])) { echo $explodename[2]; };}else {  if(isset($explodename[1])) { echo " ".$explodename[1]; } }?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Email</label>
<div class="col-sm-8">
<input type="email" name="email" class="form-control" value="<?php echo $resmydetail['email']?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Address</label>
<div class="col-sm-8">
<input type="text" name="address" class="form-control" value="<?php echo $resmydetail['address']?>">
</div>
</div>
<div class="form-group">
<label for="Phone" class="col-sm-3 control-label">Phone</label>
<div class="col-sm-8">
<input type="text" name="number" class="form-control" id="Phone" value="<?php echo $resmydetail['number']?>">
</div>
</div>

<div class="form-group">
<label for="Phone" class="col-sm-3 control-label">City</label>
<div class="col-sm-8">
<select name="city" class="form-control" id="citis">
	<option value="">Select City</option>
    <?php $sqlcity=mysql_query("select * from tbl_cities where status='Enable' order by cityname asc");
      while($rescity=mysql_fetch_assoc($sqlcity))
	  {
?>
	<option <?php if($resmydetail['city']==$rescity['city_id']) { echo "selected";} ?> value="<?php echo $rescity['city_id'];?>"><?php echo $rescity['cityname'];?></option>

<?php } ?>

</select>

</div>
</div>

<div id="local">
<div class="form-group">
<label for="Phone" class="col-sm-3 control-label">Locality</label>
<div class="col-sm-8">
<select name="locality" class="form-control">
	    
	<option value="<?php echo $resmydetail['locality'];?>" selected="selected"><?php echo $resmydetail['locality'];?></option>

</select>
</div>
</div>
</div>

<div class="form-group">
<label class="col-sm-3 control-label">Postcode</label>
<div class="col-sm-8">
<input type="text" name="postcode" required="" id="postcode" autocomplete="off" class="form-control" value="<?php echo $resmydetail['postcode']?>">
<p  id="posC"></p>
</div>
</div>


<div class="form-group">
<label class="col-md-3 control-label" for="textarea"> Picture </label>
<div class="col-md-8">
<div class="mb10">
<input id="input-upload-img1" type="file" name="file" class="file" data-preview-file-type="text" value="">
</div>


</div>
</div>


<div class="form-group">
<div class="col-sm-offset-3 col-sm-8">
<button type="submit" name="update" class="btn btn-default">Update</button>
</div>
</div>
</form>
</div>
</div>
</div>

</div>
 
</div>
</div>
 
</div>
 
</div>
 
</div>
 
<?php include("footer.php");?>
<script src="<?php echo $actual_link;?>assets/js/fileinput.min.js" type="text/javascript"></script>
<script>
$("#input-upload-img1").fileinput();
</script>
