<?php    
include ('includes/connection.php'); 
  
if (isset($_POST['change'])){  
$student_id=$user_row['student_id'];
$student_name = $_POST['student_name'];
$student_dob = $_POST['student_dob'];
$student_gender = $_POST['student_gender'];
$company = $_POST['company'];
$student_address = $_POST['student_address'];
$IndustrialCategory = $_POST['IndustrialCategory'];
$student_contact_no = $_POST['student_contact_no'];
$student_email_id = $_POST['student_email_id'];    

 

  $query=mysqli_query($conn,"UPDATE student_soes set student_name = '$student_name',student_gender = '$student_gender',company = '$company',student_address = '$student_address',IndustrialCategory = '$IndustrialCategory',student_contact_no = '$student_contact_no',student_email_id = '$student_email_id',student_dob = '$student_dob' where student_id = '$student_id'")or die(mysqli_error());
  if($query){ 
         ?>
         <script type="text/javascript">
             alert("Your Infomation is successfully change");
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Sorry Your Infomation is not changed");
        </script>
        <?php
    }
}  
if (isset($_POST['pass_change'])){  
$student_id=$user_row['student_id'];
$current_password = md5($_POST['current_password']);
$retype_password = md5($_POST['retype_password']);
$new_password =md5($_POST['new_password']); 
$PasswordHash =$_POST['PasswordHash'];

if ($PasswordHash != $current_password)
{ 
 ?>
 <script type="text/javascript">
     alert("Password does not match with your current password");
 </script>
<?php 
}else if  ($new_password != $retype_password){
   ?>
   <script type="text/javascript">
       alert("Password does not match with your new password");
   </script>
  <?php  
}else if (($PasswordHash == $current_password) && ($new_password == $retype_password)){

  $query=mysqli_query($conn,"UPDATE student_soes set PasswordHash = '$new_password' where student_id = '$student_id'")or die(mysqli_error());
  if($query){ 
         ?>
         <script type="text/javascript">
             alert("Your Password is successfully change");
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Sorry Your Password is not changed");
        </script>
        <?php
    }
}
} 
?> 
  <?php    
        if (isset($_POST['profile'])){   
          $student_id=$user_row['student_id'];
          $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
          $image_name = addslashes($_FILES['image']['name']);
          $image_size = getimagesize($_FILES['image']['tmp_name']);

          move_uploaded_file($_FILES["image"]["tmp_name"], "assets/img/user/" . $_FILES["image"]["name"]);
          $adminthumbnails = "assets/img/user/" . $_FILES["image"]["name"];
                
                mysqli_query($conn,"UPDATE student_soes set student_image = '$adminthumbnails' where student_id = '$student_id' ")or die(mysqli_error());

          mysqli_query($conn,"UPDATE student_soes SET  student_image='$adminthumbnails' where student_id = '$student_id'") 
          or die(mysqli_error()); 
          ?>
         <script type="text/javascript">
             alert("Your profile is successfully change");
         </script>
        <?php 
        }
  ?>
<div class="container">
      <div class="page-inner">
            <div class="page-header">
              <h3 class="fw-bold mb-3">Training Information</h3>
              <ul class="breadcrumbs mb-3">
                <li class="nav-home">
                  <a href="admin.php?page=dashboard&Id_2=<?php echo $user_row['course']; ?>">
                    <i class="icon-home"></i>
                  </a>
                </li>
                <li class="separator">
                  <i class="icon-arrow-right"></i>
                </li>
                <li class="nav-item">
                  <a href="admin.php?page=dashboard&Id_2=<?php echo $user_row['course']; ?>">User Profile</a>
                </li>
                <li class="separator">
                  <i class="icon-arrow-right"></i>
                </li>
                <li class="nav-item">
                  <a href="admin.php?page=dashboard&Id_2=<?php echo $user_row['course']; ?>">Setting</a>
                </li>
              </ul>
            </div>
            <div class="row">
              <div class="col-md-12">
                <div class="card">
                  <div class="card-header">
                    <h4 class="card-title">Training Information</h4>
                  </div>
                  <div class="card-body"> 
                    <div class="tab-content mt-2 mb-3" id="pills-tabContent">
                      <div class="row">
                        <div class="col-md-4">
                          <div class="card card-profile">
                            <div
                              class="card-header"
                              style="background-image: url('assets/img/academy/AI.png')"
                            >
                              <div class="profile-picture">
                                <div class="avatar avatar-xl">
                                  <img
                                    src="<?php echo $user_row['student_image']; ?>"
                                    alt="..."
                                    class="avatar-img rounded-circle"
                                  />
                             </div>
                        </div>
                    </div>
                  <div class="card-body">
                    <div class="user-profile text-center">
                      <div class="name"><?php echo $user_row['student_name'];  ?></div>
                      <div class="job"><?php echo $user_row['student_email_id'];  ?></div>
                      <div class="desc"><?php echo $user_row['company'];  ?></div>
                      <div class="social-media">
                        <a
                          class="btn btn-info btn-twitter btn-sm btn-link"
                          href="#"
                        >
                          <span class="btn-label just-icon"
                            ><i class="icon-social-twitter"></i>
                          </span>
                        </a>
                        <a
                          class="btn btn-primary btn-sm btn-link"
                          rel="publisher"
                          href="#"
                        >
                          <span class="btn-label just-icon"
                            ><i class="icon-social-facebook"></i>
                          </span>
                        </a>
                        <a
                          class="btn btn-danger btn-sm btn-link"
                          rel="publisher"
                          href="#"
                        >
                                <span class="btn-label just-icon"
                                  ><i class="icon-social-instagram"></i>
                                </span>
                              </a>
                            </div>
                            <div class="view-profile">
                              <div class="btn-group dropend">
                                <button
                                  type="button"
                                  class="btn btn-secondary w-100 btn-round dropdown-toggle"
                                  data-bs-toggle="dropdown" 
                                >
                                  Change Plofile
                                </button>
                                <ul class="dropdown-menu" role="menu">
                                  <li>
                                    <form action="" method="POST" enctype="multipart/form-data">
                                      <div class="form-group">
                                        <label>Upload Image <span style="color: red;">*</span></label>
                                            <input type="file" class="form-control" name="image"  id="fileInput" placeholder="Change profile picture">
                                        </div>
                                     
                                    <div class="dropdown-divider"></div>
                                    <center>  <button type="submit" class="btn btn-secondary btn-round" name="profile">Change</button> </center>
                                    </form>
                                  </li>
                                </ul>
                              </div> 
                            </div>
                            </div>
                          </div>
                          <div class="card-footer">
                            <div class="row user-stats text-center">
                              <div class="col">
                                <div class="number">Mobile</div>
                                <div class="title"><?php echo $user_row['student_contact_no'];  ?></div>
                              </div> 
                              <div class="col">
                                <div class="number">Gender</div>
                                <div class="title"><?php echo $user_row['student_gender'];  ?></div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="col-md-8">
                    <div class="card card-shadow">
                    <div class="card-header">
                        <h5>Update your Information </h5> 
                    </div>
                        <div class="card-body p-3">
                            <form method="post" action="" class="form-horizontal"> 
                            <div class="row">  
                                <div class="col-sm-4"><div class="form-group">
                                    <label>Trainer Name<span style="color: red;">*</span></label>
                                    <input type="text" class="form-control" name="student_name" placeholder="Enter your User name" value="<?php echo $user_row['student_name']; ?>" required> 
                                  </div>
                                </div> 
                                <div class="col-sm-4">
                                  <div class="form-group">
                                      <label>Gender <span style="color: red;">*</span></label>
                                        <div class="select2-purple"> 
                                          <select class="form-control select2" name="student_gender" data-dropdown-css-class="Select a Gender"   style="width: 100%;" required>
                                             <option value="<?php echo $user_row['student_gender']; ?>"><?php echo $user_row['student_gender']; ?></option> 
                                              <option value="MALE">MALE</option>
                                              <option value="FEMALE">FEMALE</option> 
                                        </select>
                                        </div> 
                                      </div>
                                </div> 
                                 <div class="col-sm-4">
                                  <div class="form-group">
                                    <label>Age<span style="color: red;">*</span></label>
                                    <input type="date" class="form-control" name="student_dob" placeholder="Enter your Sge" value="<?php echo $user_row['student_dob']; ?>" required> 
                                  </div>
                                </div> 
                                  <!-- /.form-group -->
                                </div> 
                                            <!-- /.row --> 
                                  <div class="row">
                                    <div class="col-sm-4">
                                      <div class="form-group">
                                        <label>Category <span style="color: red;">*</span></label>
                                        <div class="select2-purple"> 
                                          <select class="form-control select2" name="IndustrialCategory" data-dropdown-css-class="Select a Year of study"   style="width: 100%;" required>
                                             <option value="<?php echo $user_row['IndustrialCategory']; ?>"><?php echo $user_row['IndustrialCategory']; ?></option> 
                                              <option value="education">Education</option>
                                              <option value="ecommerce">Ecommerce</option>
                                              <option value="entrepreneur">Entrepreneur</option>
                                              <option value="businessman">Business</option>
                                              <option value="Other">Other</option> 
                                        </select>
                                        </div> 
                                      </div>
                                    </div>
                                    <div class="col-sm-4">
                                      <div class="form-group">
                                        <label>Vender/Company <span style="color: red;">*</span></label>
                                        <input type="text" class="form-control" name="company" placeholder="Enter your Company / vender" value="<?php echo $user_row['company']; ?>" required> 
                                      </div>
                                 </div>
                                    <div class="col-sm-4">
                                      <div class="form-group">
                                        <label>Location <span style="color: red;">*</span></label>
                                        <input type="text" class="form-control" name="student_address" placeholder="Enter your Current Location" value="<?php echo $user_row['student_address']; ?>" required> 
                                      </div>
                                 </div>     
                                    <!-- /.col -->
                              </div>
                               <div class="row">  
                                <div class="col-sm-6">
                                  <div class="form-group">
                                  <label>Phone Number <span style="color: red;">*</span></label>
                                  <div class="input-group mb-3">
                                    <span class="input-group-text" id="basic-addon1"
                                      ><i class="fas fa-phone"></i></span
                                    >
                                    <input type="text"  class="form-control" name="student_contact_no" placeholder="Phone Number" value="<?php echo $user_row['student_contact_no']; ?>" aria-describedby="basic-addon1"
                                    />
                                  </div> 
                                  </div>
                                </div> 
                                <div class="col-sm-6">
                                  <div class="form-group">
                                   <label>Email <span style="color: red;">*</span></label>
                                  <div class="input-group mb-3">
                                    <span class="input-group-text" id="basic-addon1"
                                      ><i class="fas fa-at"></i></span
                                    >
                                    <input type="email" class="form-control" name="student_email_id" placeholder="Email" required value="<?php echo $user_row['student_email_id']; ?>" aria-describedby="basic-addon1"
                                    />
                                  </div> 
                                  </div> 
                                </div> 
                                  <!-- /.form-group -->
                                </div>  
                                <div class="row" style="text-align: right">
                                  <div class="col-md-12"> 
                                      <button type="submit" name="change" class="btn btn-secondary btn-sm">  <i class="fa fa far fa-send"></i> UPDATE</button>
                                  </div>
                              </div>
                            </form>

                        </div>
                    </div>
                <div class="card card-shadow">
                    <div class="card-header">
                        <h5>Change Password</h5> 
                    </div>
                        <div class="card-body p-3">
                            <form method="post" action="" class="form-horizontal"> 

                                  <div class="form-group">
                                  <input type="hidden" id="password" name="PasswordHash" value="<?php echo $user_row['PasswordHash']; ?>">
                                  <label>Current Password</label>  
                                     <input type="password" class="form-control" id="current_password" name="current_password"  placeholder="Current Password" >
                                  </div>
                                 
                                  <div class="form-group">
                                    <label>New Password  </label>  
                                    <input type="password" class="form-control" id="new_password" name="new_password" placeholder="New Password">
                                  </div>
                                
                                  <div class="form-group">
                                  <label>Re-Enter Password  </label>  
                                    <input type="password" class="form-control" id="retype_password" name="retype_password" placeholder="Re-type Password" >
                                  </div>
                                
                                <div class="row" style="text-align: right">
                                <div class="col-sm-12">  
                                  <button type="submit" name="pass_change" class="btn btn-secondary btn-sm">  <i class="fa fa far fa-edit"></i> CHANGE</button>
                                  </div> 
                               </div>
                             </form>

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

                      </div> 
                    </div>
                  </div>
                  <div class="card-footer"> 
                    <div class="row">
                    <div class="col-md-6"> 
                     </div> 
                          <div style="text-align: center;"> 
                               <h6><i class="fas fa-map-marker-alt"></i> Location: <?php echo $user_row['student_address'];  ?> </h6>
                          </div>
                      </div> 
                   </div>
                  </div>
                </div>
              </div> 
            </div>
          </div> 




 