Domain: amberpublishers.in
Server Adress: 86.38.243.169

privdayz.com

/home/u866425823/domains/mastercleanindia.co.in/public_html/admin/
Dosya Yükle :
Current File : /home/u866425823/domains/mastercleanindia.co.in/public_html/admin/profile.php

<?php
session_start();
require 'include/PHPHelper.php';
if (!isset($_SESSION['userID'])) {
  header("location: login.php");
}
// handle profile uodate
if (isset($_POST['updateProfile'])) {
  // get full name and break it into first name and last name
  $fullName = $_POST['fullName'];
  $fullName = explode(" ", $fullName);
  $firstName = $fullName[0];
  $lastName = $fullName[1];
  $userID = $_SESSION['userID'];
  $sql = "UPDATE users SET firstName='$firstName', lastName='$lastName' WHERE userID='$userID'";
  $result = mysqli_query($conn, $sql);
  if ($result) {
    $_SESSION['userName'] = $fullName;
    echo "<script>alert('Profile Updated Successfully');</script>";
    echo "<script>window.location.href='profile.php';</script>";
  } else {
    echo "<script>alert('Profile Update Failed');</script>";
    echo "<script>window.location.href='profile.php';</script>";
  }
}
// handle password change
// first check if the current password is correct by mathching it's hash with the hash in the database
// then check if the new password and re-enter new password are same
// if both are correct then update the password
if (isset($_POST['updatePassword'])) {
  $userID = $_SESSION['userID'];
  $password = $_POST['password'];
  $newpassword = $_POST['newpassword'];
  $renewpassword = $_POST['renewpassword'];
  $sql = "SELECT * FROM users WHERE userID='$userID'";
  $result = mysqli_query($conn, $sql);
  $row = mysqli_fetch_assoc($result);
  $hash = $row['userPassword'];
  if (password_verify($password, $hash)) {
    if ($newpassword == $renewpassword) {
      $newpassword = password_hash($newpassword, PASSWORD_DEFAULT);
      $sql = "UPDATE users SET userPassword='$newpassword' WHERE userID='$userID'";
      $result = mysqli_query($conn, $sql);
      if ($result) {
        echo "<script>alert('Password Updated Successfully');</script>";
        echo "<script>window.location.href='profile.php';</script>";
      } else {
        echo "<script>alert('Password Update Failed');</script>";
        echo "<script>window.location.href='profile.php';</script>";
      }
    } else {
      echo "<script>alert('New Password and Re-enter New Password do not match');</script>";
      echo "<script>window.location.href='profile.php';</script>";
    }
  } else {
    echo "<script>alert('Current Password is incorrect');</script>";
    echo "<script>window.location.href='profile.php';</script>";
  }
}

?>

<!DOCTYPE html>
<html lang="en">
<?php

$title = "$sessionUserName Profile || Master Clean India";
include 'include/head.php';


?>


<body>

  <!-- ======= Header ======= -->
  <?php
  include 'include/header.php';
  ?>
  <!-- End Header -->

  <!-- ======= Sidebar ======= -->
  <?php
  include 'include/sidebar.php';
  ?>
  <!-- End Sidebar-->

  <main id="main" class="main">

    <div class="pagetitle">
      <h1>Profile</h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
          <li class="breadcrumb-item">Users</li>
          <li class="breadcrumb-item active">Profile</li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section profile">
      <div class="row">
        <div class="col-xl-12">

          <div class="card">
            <div class="card-body profile-card pt-4 d-flex flex-column align-items-center">
              <h2><?php echo $sessionUserName; ?></h2>
              <h3><?php echo $sessionUserRole; ?></h3>
            </div>
          </div>

        </div>

        <div class="col-xl-12">

          <div class="card">
            <div class="card-body pt-3">
              <!-- Bordered Tabs -->
              <ul class="nav nav-tabs nav-fill nav-justified">

                <li class="nav-item">
                  <button class="nav-link active" data-bs-toggle="tab" data-bs-target="#profile-overview">Overview</button>
                </li>

                <li class="nav-item">
                  <button class="nav-link" data-bs-toggle="tab" data-bs-target="#profile-edit">Edit Profile</button>
                </li>
                <li class="nav-item">
                  <button class="nav-link" data-bs-toggle="tab" data-bs-target="#profile-change-password">Change Password</button>
                </li>

              </ul>
              <div class="tab-content pt-2">

                <div class="tab-pane fade show active profile-overview" id="profile-overview">
                  <h5 class="card-title">Profile Details</h5>

                  <div class="row">
                    <div class="col-lg-3 col-md-4 label ">User Name</div>
                    <div class="col-lg-9 col-md-8"><?php echo $sessionUserName; ?></div>
                  </div>

                  <div class="row">
                    <div class="col-lg-3 col-md-4 label">User Role</div>
                    <div class="col-lg-9 col-md-8"><?php echo $sessionUserRole; ?></div>
                  </div>
                </div>

                <div class="tab-pane fade profile-edit pt-3" id="profile-edit">

                  <!-- Profile Edit Form -->
                  <form class="profileEditForm" id="profileEditForm" method="POST">

                    <div class="row mb-3">
                      <label for="fullName" class="col-md-4 col-lg-3 col-form-label">Full Name</label>
                      <div class="col-md-8 col-lg-9">
                        <input name="fullName" type="text" class="form-control" id="fullName" value="<?php echo $sessionUserName; ?>">
                      </div>
                    </div>

                    <div class="row mb-3">
                      <label for="position" class="col-md-4 col-lg-3 col-form-label">User Role</label>
                      <div class="col-md-8 col-lg-9">
                        <input name="userRole" type="text" class="form-control" id="userRole" value="<?php echo $sessionUserRole; ?>" disabled>
                      </div>
                    </div>
                    <div class="text-center">
                      <button type="submit" name="updateProfile" id="updateProfile" class="btn btn-primary">Save Changes</button>
                    </div>
                  </form><!-- End Profile Edit Form -->

                </div>
                <div class="tab-pane fade pt-3" id="profile-change-password">
                  <!-- Change Password Form -->
                  <form class="profilePasswordChangeForm" id="profilePasswordChangeForm" name="profilePasswordChangeForm" method="POST">
                    <div class="row mb-3">
                      <label for="currentPassword" class="col-md-4 col-lg-3 col-form-label">Current Password</label>
                      <div class="col-md-8 col-lg-9">
                        <input name="password" type="password" class="form-control" id="currentPassword">
                      </div>
                    </div>

                    <div class="row mb-3">
                      <label for="newPassword" class="col-md-4 col-lg-3 col-form-label">New Password</label>
                      <div class="col-md-8 col-lg-9">
                        <input name="newpassword" type="password" class="form-control" id="newPassword">
                      </div>
                    </div>

                    <div class="row mb-3">
                      <label for="renewPassword" class="col-md-4 col-lg-3 col-form-label">Re-enter New Password</label>
                      <div class="col-md-8 col-lg-9">
                        <input name="renewpassword" type="password" class="form-control" id="renewPassword">
                      </div>
                    </div>

                    <div class="text-center">
                      <button type="submit" name="updatePassword" id="updatePassword" class="btn btn-primary">Change Password</button>
                    </div>
                  </form><!-- End Change Password Form -->

                </div>

              </div><!-- End Bordered Tabs -->

            </div>
          </div>

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

  </main><!-- End #main -->

  <!-- ======= Footer ======= -->
  <?php
  include 'include/footer.php';
  ?>

</body>

</html>

coded by Privdayz.com - Visit https://privdayz.com/ for more php shells.