<?php
include 'header.php';

if (isset($_GET['plans'])) {
    $Editplans = $_GET['plans'];
  
    $sql = mysqli_query($link, "SELECT * FROM  plans  WHERE id = '$Editplans' ");
      if (mysqli_num_rows($sql) > 0) {
      $row = mysqli_fetch_assoc($sql);
      $_plan_name = $row['plan_name']; 
      $_min_amount = $row['min_amount'];  
      $_max_amount = $row['max_amount'];  
      $_profit_percentage = $row['profit_percentage'];  
      $_interval_period = $row['interval_period'];  
      $_time_period = $row['time_period'];  
      $_status = $row['plan_status'];  

    }
}

if (isset($_POST['submit'])) {

    $plan_name = $_POST['Plan_Name'];  
    $min_amount = $_POST['Min'];  
    $max_amount = $_POST['Max'];  
    $profit_percentage = $_POST['Profit'];  
    $interval_period = $_POST['interval_period'];  
    $time_period = $_POST['time_period'];  
    $status = $_POST['status'];  



    $sql = mysqli_query($link, "UPDATE plans SET plan_name = '$plan_name', min_amount = '$min_amount', max_amount = '$max_amount', profit_percentage = '$profit_percentage', interval_period = '$interval_period', time_period = '$time_period', plan_status =  '$status'    WHERE id = '$Editplans' ");

      echo "<script>
      alert('Updated Successfully');
      window.location.href = 'viewplans.php';
      </script>";
    }
  


?>



 <!-- Content wrapper scroll start -->
 <div class="content-wrapper-scroll">

<!-- Content wrapper start -->
<div class="content-wrapper">

  <!-- Row start -->
  <div class="row">
    <div class="col-sm-12 col-12">

      <!-- Card start -->
      <div class="card">
        <div class="card-header">
          <div class="card-title">Edit Plans</div>
        </div>
        <div class="card-body">

          <!-- Row start -->
          <form method="POST" action="" >
          <div class="row">
          <div class="col-xxl-6 col-xl-12 col-lg-6 col-md-6 col-sm-6 col-6">
              <div class="mb-3">
                <label for="inputName" class="form-label">Plan Name </label>
                <input type="text" class="form-control" id="inputName" name="Plan_Name" value="<?php echo $_plan_name ?>">
              </div>
            </div>

            <div class="col-xxl-6 col-xl-12 col-lg-6 col-md-6 col-sm-6 col-6">
              <div class="mb-3">
                <label for="inputEmail" class="form-label">Min Amount</label>
                <input type="text" class="form-control" id="inputEmail" name="Min" value="<?php echo $_min_amount ?>" >
              </div>
            </div>

            <div class="col-xxl-6 col-xl-12 col-lg-6 col-md-6 col-sm-6 col-6">
              <div class="mb-3">
                <label for="inputEmail" class="form-label">Max Amount</label>
                <input type="text" class="form-control" id="inputEmail" name="Max" value="<?php echo $_max_amount ?>" >
              </div>
            </div>

            <div class="col-xxl-6 col-xl-12 col-lg-6 col-md-6 col-sm-6 col-6">
              <div class="mb-3">
                <label for="inputEmail" class="form-label">Profit Percentage</label>
                <input type="text" class="form-control" id="inputEmail" name="Profit" value="<?php echo $_profit_percentage  ?>" >
              </div>
            </div>

            <div class="col-xxl-12 col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
              <div class="mb-3">
                <label for="inputEmail" class="form-label">Interval Period</label>
                <input type="text" class="form-control" id="inputEmail" name="interval_period" value="<?php echo $_interval_period  ?>" >
              </div>
            </div>
            

            <div class="col-xxl-12 col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
              <div class="mb-3">
                <label for="inputEmail" class="form-label">Time Period</label>
                <input type="text" class="form-control" id="inputEmail" name="time_period" value="<?php echo $_time_period  ?>" >
              </div>
            </div>
            
            <div class="col-xxl-12 col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
              <div class="mb-3">
              <div class="form-group basic">
				<div class="input-wrapper">
					<label class="label" for="account1">Change Plan Status</label>
					<select name="status" class="form-control">
						<option value="<?php echo $_status  ?>"><?php echo $_status  ?></option>
						<option value="Inactive">Inactive</option>
						<option value="Active">Active</option>
					</select>
				</div>
            
            <button class="btn btn-success" name="submit" type="submit">Submit</button>

          <!-- Form actions footer end -->

          </form>

        </div>
      </div>
      <!-- Card end -->

    </div>

  </div>
  <!-- Row end -->

</div>
<!-- Content wrapper end -->




<?php
include 'footer.php';
?>