<?php
    session_start();
    include "../../db.php";
    date_default_timezone_set('Asia/Kolkata');
    $currentTime = date('M j, Y g:i a');

    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) ) {
        header("Location: logout.php");
        exit();
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
 <?php include "includes/meta.php"; ?>             
    <?php include "includes/css.php"; ?>
    <link href="css/all.min.css" rel="stylesheet" type="text/css">
    <link href="css/alltable.css" rel="stylesheet"> 
    
</head>

<body>

  <!--==========================
  Header
  ============================-->
   <?php include "includes/header2.php"; ?>

  <!--==========================
    Intro Section
  ============================-->
                

 <div class="container">
            <div class="row mx-0 just ify-content-center">
                <div class="col-12 col-sm-12 col-md-12">
                        <div class="card-body">

                            <h1 class="h3 mb-2 text-gray-800 text-center" style="margin-top: 90px">Profile</h1>
                            <hr>
							
							

                            <?php
                                $edit_run = mysqli_query($con, "SELECT * FROM users WHERE uid = '$_SESSION[uid]'");
                                $edit_row = mysqli_fetch_assoc($edit_run);
                            ?>
							
							<?php
            $slider_sql = "SELECT * FROM slider where sby='$_SESSION[uid]' ORDER BY  spos ASC LIMIT 1";
            $slider_run = mysqli_query($con, $slider_sql);
            while ( $slider_rows = mysqli_fetch_assoc($slider_run) ) {
              $sliderPath = substr($slider_rows['slgimage'], 3);
              $sliderPath = "../../login/".$sliderPath;
             
            }
          ?>  
							<div class="col-sm-12 row">
							<div class="col-sm-2 mb-1 mb-sm-0">
										</div>  
                                            <div class="col-sm-8 mb-1 mb-sm-0">
											<p align="right">
							<img src="<?php echo  $sliderPath; ?> " alt="Smiley face" height="auto" width="100">
							<br> Name - <?php echo $edit_row["uname"]; ?>
											 <br>
											  Creat Date - <?php echo $edit_row["ucreated"]; ?> <br>
											   <a  href="<?php echo $edit_row["uagreement"]; ?>"  target="_blank"> View Aagreement  </a>
											
										  </p>
										 
											 <br>
											Main Mobile - <a href="tel:+91<?php echo $edit_row["uphone"]; ?>"> <?php echo $edit_row["uphone"]; ?></a><br>   
											Oth Mobile - <a href="tel:+91<?php echo $edit_row["uothcontact"]; ?>"> <?php echo $edit_row["uothcontact"]; ?></a>   <br>                                    																					
											Type of Org -   <?php echo $edit_row["utypeorg"]; ?> <br>
											WhatsApp  -   <a href="https://wa.me/91<?php echo $edit_row["uwhatsapp"]; ?>" target="_blank" > <?php echo $edit_row["uwhatsapp"]; ?></a><br>											 
											Email -  <?php echo $edit_row["umail"]; ?> <br>
											Website -  <a  href="<?php echo $edit_row["uweburl"]; ?>"  target="_blank"> <?php echo $edit_row["uweburl"]; ?> </a><br>
											Fb URL  - <a  href="<?php echo $edit_row["ufburl"]; ?>"  target="_blank">  <?php echo $edit_row["ufburl"]; ?> </a><br>
											Twitter URL  - <a  href="<?php echo $edit_row["utwitter"]; ?>"  target="_blank">  <?php echo $edit_row["utwitter"]; ?> </a><br>
											Instragram URL  - <a  href="<?php echo $edit_row["uinsta"]; ?>"  target="_blank">  <?php echo $edit_row["uinsta"]; ?> </a><br>
											YouTube URL  - <a  href="<?php echo $edit_row["uyoutube"]; ?>"  target="_blank">  <?php echo $edit_row["uyoutube"]; ?> </a><br>
											Linkdin URL  - <a  href="<?php echo $edit_row["linkdin"]; ?>"  target="_blank">  <?php echo $edit_row["linkdin"]; ?> </a><br>
											Address - <?php echo $edit_row["uaddress1"]; ?> &nbsp;  <?php echo $edit_row["uaddress2"]; ?><br>
											
							
							<br><br>
							 <p align="center"class=" btn-success btn-user m-2" name="edit_cat">
                                    <i class="far fa-image"></i> Update Profile
                              </p>
							
                            <form class="user" method="post" enctype="multipart/form-data">
                                <h4 class="mb-3 badge badge-secondary">	Personal Details</h4>
                                <div class="row justify-content-center ">
								
								<div class="  col-md-5 ">
                                    <div class=" mb-1 mb-sm-0">
									 Name
                                        <input type="text" class="form-control form-control-sm mb-2" id="uname" placeholder="" name="uname" value="<?php echo $edit_row["uname"]; ?>" >
                                    </div>
									<div class=" mb-1 mb-sm-0">
								WhatsApp no
                                        <input type="text" class="form-control form-control-sm mb-2" id="uwhatsapp" placeholder="" name="uwhatsapp" value="<?php echo $edit_row["uwhatsapp"]; ?>" >
                                    </div>
									<div class=" mb-1 mb-sm-0">
									Others Contact
                                        <input type="text" class="form-control form-control-sm mb-2" id="uothcontact" placeholder="" name="uothcontact" value="<?php echo $edit_row["uothcontact"]; ?>" >
                                    </div>
									<div class=" mb-1 mb-sm-0">
									Email id 
                                        <input type="text" class="form-control form-control-sm mb-2" id="umail" placeholder="" name="umail" value="<?php echo $edit_row["umail"]; ?>" >
                                    </div>
									
									<div class=" mb-1 mb-sm-0">
									Fb URL
                                        <input type="text" class="form-control form-control-sm mb-2" id="ufburl" placeholder="" name="ufburl" value="<?php echo $edit_row["ufburl"]; ?>" >
                                    </div>
									<div class=" mb-1 mb-sm-0">
									Twitter url
                                        <input type="text" class="form-control form-control-sm mb-2" id="utwitter" placeholder="" name="utwitter" value="<?php echo $edit_row["utwitter"]; ?>" >
                                    </div>
									</div>
									<div class="col-md-5 ">
									
									<div class=" mb-1 mb-sm-0">
									Instragram 
                                        <input type="text" class="form-control form-control-sm mb-2" id="uinsta" placeholder="" name="uinsta" value="<?php echo $edit_row["uinsta"]; ?>" >
                                    </div>
									<div class=" mb-1 mb-sm-0">
									You Tube url  
                                        <input type="text" class="form-control form-control-sm mb-2" id="uyoutube" placeholder="" name="uyoutube" value="<?php echo $edit_row["uyoutube"]; ?>" >
                                    </div> <div class=" mb-1 mb-sm-0">
									Linkdin url  
                                        <input type="text" class="form-control form-control-sm mb-2" id="linkdin" placeholder="" name="linkdin" value="<?php echo $edit_row["linkdin"]; ?>" >
                                    </div>
									
									
									<div class=" mb-1 mb-sm-0">
									Organization Address1
                                        <input type="text" class="form-control form-control-sm mb-2" id="uname" placeholder="" name="uaddress1" value="<?php echo $edit_row["uaddress1"]; ?>" >
                                    </div>
									<div class=" mb-1 mb-sm-0">
									Organization Address2
                                        <input type="text" class="form-control form-control-sm mb-2" id="uname" placeholder="" name="uaddress2" value="<?php echo $edit_row["uaddress2"]; ?>" >
                                    </div>
									
										<div class="mb-1 mb-sm-0">
											
											<select name="theme" id="theme" class="form-control mb-3" >
                                        <option  value="<?php echo $edit_row["theme"];?>"> Select Theme : <?php echo $edit_row["theme"]; ?></option>
                                           <option value="FFA500">FFA500</option>
										 <option value="3887c7">3887c7</option>
										  <option value="336600">336600</option>
										  	  <option value="336699">336699</option>
											  	  <option value="666633">666633</option>
                                              
                                    </select>
											
											
                                                  </div>
								</div>
									
                                </div>
                                <h4 class="mb-3 badge badge-secondary">Login Details</h4>
                                <div class="form-group ">
                                   
                                    <div class="c mb-1 mb-sm-0">
									Password
                                        <input type="text" class="form-control form-control-sm mb-2" id="upass" placeholder="Password *" name="upass" value="<?php echo $edit_row["upass"]; ?>" >
                                    </div>
                                </div>
                                <button type="submit" class="btn btn-success btn-user m-2" name="edit_cat">
                                    <i class="far fa-image"></i> Update Profile
                                </button>
                                <a href="index.php" class="btn btn-warning btn-user m-2"> <i class="fas fa-ban"></i> Cancel </a>
                            </form>

                            <hr>
							</div></div>

                        </div>
                    </div>

                </div>

            </div>

            <?php include "includes/ft.php"; ?>
            <?php include "includes/js.php"; ?>



</body>
</html>



<?php
    if(isset($_POST['edit_cat'])){
        $uname = mysqli_real_escape_string($con, strip_tags($_POST['uname']));
		      $uwhatsapp = mysqli_real_escape_string($con, strip_tags($_POST['uwhatsapp']));
			  $uothcontact = mysqli_real_escape_string($con, strip_tags($_POST['uothcontact']));
			  $umail = mysqli_real_escape_string($con, strip_tags($_POST['umail']));
			  $ufburl = mysqli_real_escape_string($con, strip_tags($_POST['ufburl']));
			  $utwitter = mysqli_real_escape_string($con, strip_tags($_POST['utwitter']));
			  $uinsta = mysqli_real_escape_string($con, strip_tags($_POST['uinsta']));
			  $uyoutube = mysqli_real_escape_string($con, strip_tags($_POST['uyoutube']));
			    $linkdin = mysqli_real_escape_string($con, strip_tags($_POST['linkdin']));
			  $uaddress1 = mysqli_real_escape_string($con, strip_tags($_POST['uaddress1']));
			        $uaddress2 = mysqli_real_escape_string($con, strip_tags($_POST['uaddress2']));
					      $theme = mysqli_real_escape_string($con, strip_tags($_POST['theme']));
		
      
        $upass = mysqli_real_escape_string($con, strip_tags($_POST['upass']));

        $up_sql = "UPDATE users SET uname = '$uname', uwhatsapp = '$uwhatsapp',uothcontact = '$uothcontact',umail = '$umail',ufburl = '$ufburl',utwitter = '$utwitter',uinsta = '$uinsta',uyoutube = '$uyoutube',linkdin = '$linkdin', uaddress1 = '$uaddress1', uaddress2 = '$uaddress2', theme = '$theme',  upass = '$upass' WHERE uid = '$_SESSION[uid]'";

        $_SESSION["uname"] = $uname;

        if(mysqli_query($con, $up_sql)){
            ?>
            <script>window.location = 'profile.php';</script>
            <?php
        }
        else{
            ?>
            <script>
                alert('OOPS !!!!');
                setTimeout(() => {
                    window.location = 'profile.php';
                }, 500);
            </script>
            <?php
        }
    }
?>