<?php $page_title = "My Profile" ?>
<?php include 'user_header.php'; ?>
<?php
  if (isset($_POST['update_profile_pic'])) {
      $profile_pic = $_FILES["profile_pic"]["name"];
      $tempname = $_FILES["profile_pic"]["tmp_name"];
      $folder = "../images/$profile_pic";

      if (empty($profile_pic)) {
        $error = "<div class='alert alert-danger d-flex align-items-center' role='alert'>
          <i class='fa fa-warning'></i> &nbsp; Upload an image to update your profile
        </div>";
      }else {
        if (move_uploaded_file($tempname, $folder)) {
            $acct_update = "UPDATE users SET image = '$profile_pic' WHERE user_id = '$user_id'";
            if ($connection->query($acct_update)===TRUE) {
              echo "<script>
                window.location.href='profile.php?status=success'
              </script>";
            }else {
              echo "<script>
                window.location.href='profile.php?status=error'
              </script>";
            }
        }else {
          echo "<script>
            window.location.href='profile.php?status=error'
          </script>";
        }
      }

  }

 ?>

 <?php
   $dep_status = $_GET['status']
  ?>
 <?php if ($dep_status == "success"): ?>
   <div class='alert alert-success d-flex align-items-center' role='alert'>
     <i class='fa fa-check'></i> &nbsp; Profile picture updated successfully.
   </div>

 <?php elseif ($dep_status == "error"): ?>
   <div class='alert alert-danger d-flex align-items-center' role='alert'>
     <i class='fa fa-warning'></i> &nbsp;  Sorry an error occurred. Please try again later or contact support
   </div>
 <?php else: ?>
     <?php echo $error; ?>
 <?php endif; ?>


<div class="container-fluid content-inner pb-0">
    <div>
        <div class="row">
            <div class="col-xl-3 col-lg-4">
                <div class="card">
                    <div class="card-header d-flex justify-content-between">
                        <div class="header-title">
                            <h4 class="card-title">Edit your profile</h4>
                        </div>
                    </div>
                    <div class="card-body">
                        <form action="" method="post" enctype="multipart/form-data">
                            <div class="form-group">
                                <div class="profile-img-edit position-relative">
                                    <img id="imagePreview" class="img-fluid avatar avatar-100 avatar-rounded" src="../images/<?php echo $image ?>" alt="profile-pic">
                                    <div class="upload-icone bg-primary">
                                        <svg class="upload-button" width="14" height="14" viewBox="0 0 24 24">
                                            <path fill="#ffffff" d="M14.06,9L15,9.94L5.92,19H5V18.08L14.06,9M17.66,3C17.41,3 17.15,3.1 16.96,3.29L15.13,5.12L18.88,8.87L20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18.17,3.09 17.92,3 17.66,3M14.06,6.19L3,17.25V21H6.75L17.81,9.94L14.06,6.19Z"></path>
                                        </svg>
                                        <input class="file-upload" name="profile_pic" id="imageInput" type="file" accept="image/*">
                                    </div>
                                </div>
                                <div class="img-extension mt-3">
                                    <div class="d-inline-block align-items-center">
                                        <span>Only</span>
                                        <a href="javascript:void();">.jpg</a>
                                        <a href="javascript:void();">.png</a>
                                        <a href="javascript:void();">.jpeg</a>
                                        <span>allowed</span>
                                    </div>
                                </div>
                            </div>
                            <button name="update_profile_pic" type="submit" class="btn btn-primary">save</button>
                        </form>
                    </div>
                </div>
            </div>
            <div class="col-xl-9 col-lg-8">
                <div class="card">
                    <div class="card-header d-flex justify-content-between">
                        <div class="header-title">
                            <h4 class="card-title">Edit User Information</h4><button class="badge rounded-pill bg-danger"></button>
                        </div>
                    </div>
                    <div class="card-body">

                      <?php
                       if (isset($_POST['save'])) {
                         $firstname = $_POST['firstname'];
                         $lastname = $_POST['lastname'];
                         $address = $_POST['address'];
                         $country = $_POST['country'];
                         $phone = $_POST['phone'];
                         $city = $_POST['city'];
                         $zip = $_POST['zip'];

                         $user_fullname = $firstname.' '.$lastname;

                         if (empty($firstname) || empty($lastname) || empty($address) || empty($country) || empty($phone) || empty($city)) {
                           $error2 = "<div class='alert alert-danger d-flex align-items-center' role='alert'>
                             <i class='fa fa-warning'></i> &nbsp; Please fill out all fields
                           </div>";
                         }else {
                           $sql_update = "UPDATE users SET full_name = '$user_fullname', address = '$address', country = '$country', phone = '$phone',
                           city = '$city', zip = '$zip' WHERE user_id = '$user_id'";
                           if ($connection->query($sql_update) === TRUE) {
                             echo "<script>
                               window.location.href='profile.php?update=success'
                             </script>";
                           }else {
                             echo "<script>
                               window.location.href='profile.php?update=error'
                             </script>";
                           }
                         }
                       }
                       ?>

                      <?php
                        $update_status = $_GET['update']
                       ?>
                      <?php if ($update_status == "success"): ?>
                        <div class='alert alert-success d-flex align-items-center' role='alert'>
                          <i class='fa fa-check'></i> &nbsp; User information inserted successfully.
                        </div>

                      <?php elseif ($update_status == "error"): ?>
                        <div class='alert alert-danger d-flex align-items-center' role='alert'>
                          <i class='fa fa-warning'></i> &nbsp;  Sorry an error occurred. Please try again later or contact support
                        </div>
                      <?php else: ?>
                          <?php echo $error2; ?>
                      <?php endif; ?>



                        <div class="new-user-info">
                            <form action="" method="post">
                                <div class="row">
                                    <div class="form-group col-md-6">
                                        <label class="form-label" for="fname">First Name:</label>
                                        <input type="text" class="form-control" name="firstname" value="<?php echo $fname ?>" id="fname" placeholder="First Name">
                                    </div>
                                    <div class="form-group col-md-6">
                                        <label class="form-label" for="lname">Last Name:</label>
                                        <input type="text" class="form-control" name="lastname" value="<?php echo $lname ?>" id="lname" placeholder="Last Name">
                                    </div>
                                    <div class="form-group col-md-6">
                                        <label class="form-label" for="add1">House Address</label>
                                        <input type="text" name="address" value="<?php echo $address ?>" class="form-control" id="add1" placeholder="Street Address 1">
                                    </div>

                                    <div class="form-group col-sm-12">
                                        <label class="form-label">Country:</label>
                                        <select name="country" class="selectpicker form-control" data-style="py-0">
                                            <option value="<?php echo $country ?>"><?php echo $country ?></option>
                                            <option value="Afghanistan">Afghanistan</option>
                                            <option value="Albania">Albania</option>
                                            <option value="Algeria">Algeria</option>
                                            <option value="Andorra">Andorra</option>
                                            <option value="Angola">Angola</option>
                                            <option value="Antigua and Barbuda">Antigua and Barbuda</option>
                                            <option value="Argentina">Argentina</option>
                                            <option value="Armenia">Armenia</option>
                                            <option value="Australia">Australia</option>
                                            <option value="Austria">Austria</option>
                                            <option value="Azerbaijan">Azerbaijan</option>
                                            <option value="Bahamas">Bahamas</option>
                                            <option value="Bahrain">Bahrain</option>
                                            <option value="Bangladesh">Bangladesh</option>
                                            <option value="Barbados">Barbados</option>
                                            <option value="Belarus">Belarus</option>
                                            <option value="Belgium">Belgium</option>
                                            <option value="Belize">Belize</option>
                                            <option value="Benin">Benin</option>
                                            <option value="Bhutan">Bhutan</option>
                                            <option value="Bolivia">Bolivia</option>
                                            <option value="Bosnia and Herzegovina">Bosnia and Herzegovina</option>
                                            <option value="Botswana">Botswana</option>
                                            <option value="Brazil">Brazil</option>
                                            <option value="Brunei">Brunei</option>
                                            <option value="Bulgaria">Bulgaria</option>
                                            <option value="Burkina Faso">Burkina Faso</option>
                                            <option value="Burundi">Burundi</option>
                                            <option value="Cambodia">Cambodia</option>
                                            <option value="Cameroon">Cameroon</option>
                                            <option value="Canada">Canada</option>
                                            <option value="Cape Verde">Cape Verde</option>
                                            <option value="Central African Republic">Central African Republic</option>
                                            <option value="Chad">Chad</option>
                                            <option value="Chile">Chile</option>
                                            <option value="China">China</option>
                                            <option value="Colombia">Colombia</option>
                                            <option value="Comoros">Comoros</option>
                                            <option value="Congo (Brazzaville)">Congo (Brazzaville)</option>
                                            <option value="Congo (Kinshasa)">Congo (Kinshasa)</option>
                                            <option value="Costa Rica">Costa Rica</option>
                                            <option value="Cote d&#39;Ivoire">Cote d'Ivoire</option>
                                            <option value="Croatia">Croatia</option>
                                            <option value="Cuba">Cuba</option>
                                            <option value="Cyprus">Cyprus</option>
                                            <option value="Czech Republic">Czech Republic</option>
                                            <option value="Denmark">Denmark</option>
                                            <option value="Djibouti">Djibouti</option>
                                            <option value="Dominica">Dominica</option>
                                            <option value="Dominican Republic">Dominican Republic</option>
                                            <option value="East Timor (Timor Timur)">East Timor (Timor Timur)</option>
                                            <option value="Ecuador">Ecuador</option>
                                            <option value="Egypt">Egypt</option>
                                            <option value="El Salvador">El Salvador</option>
                                            <option value="Equatorial Guinea">Equatorial Guinea</option>
                                            <option value="Eritrea">Eritrea</option>
                                            <option value="Estonia">Estonia</option>
                                            <option value="Ethiopia">Ethiopia</option>
                                            <option value="Fiji">Fiji</option>
                                            <option value="Finland">Finland</option>
                                            <option value="France">France</option>
                                            <option value="Gabon">Gabon</option>
                                            <option value="Gambia, The">Gambia, The</option>
                                            <option value="Georgia">Georgia</option>
                                            <option value="Germany">Germany</option>
                                            <option value="Ghana">Ghana</option>
                                            <option value="Greece">Greece</option>
                                            <option value="Grenada">Grenada</option>
                                            <option value="Guatemala">Guatemala</option>
                                            <option value="Guinea">Guinea</option>
                                            <option value="Guinea-Bissau">Guinea-Bissau</option>
                                            <option value="Guyana">Guyana</option>
                                            <option value="Haiti">Haiti</option>
                                            <option value="Honduras">Honduras</option>
                                            <option value="Hungary">Hungary</option>
                                            <option value="Iceland">Iceland</option>
                                            <option value="India">India</option>
                                            <option value="Indonesia">Indonesia</option>
                                            <option value="Iran">Iran</option>
                                            <option value="Iraq">Iraq</option>
                                            <option value="Ireland">Ireland</option>
                                            <option value="Israel">Israel</option>
                                            <option value="Italy">Italy</option>
                                            <option value="Jamaica">Jamaica</option>
                                            <option value="Japan">Japan</option>
                                            <option value="Jordan">Jordan</option>
                                            <option value="Kazakhstan">Kazakhstan</option>
                                            <option value="Kenya">Kenya</option>
                                            <option value="Kiribati">Kiribati</option>
                                            <option value="Korea, North">Korea, North</option>
                                            <option value="Korea, South">Korea, South</option>
                                            <option value="Kuwait">Kuwait</option>
                                            <option value="Kyrgyzstan">Kyrgyzstan</option>
                                            <option value="Laos">Laos</option>
                                            <option value="Latvia">Latvia</option>
                                            <option value="Lebanon">Lebanon</option>
                                            <option value="Lesotho">Lesotho</option>
                                            <option value="Liberia">Liberia</option>
                                            <option value="Libya">Libya</option>
                                            <option value="Liechtenstein">Liechtenstein</option>
                                            <option value="Lithuania">Lithuania</option>
                                            <option value="Luxembourg">Luxembourg</option>
                                            <option value="Macedonia">Macedonia</option>
                                            <option value="Madagascar">Madagascar</option>
                                            <option value="Malawi">Malawi</option>
                                            <option value="Malaysia">Malaysia</option>
                                            <option value="Maldives">Maldives</option>
                                            <option value="Mali">Mali</option>
                                            <option value="Malta">Malta</option>
                                            <option value="Marshall Islands">Marshall Islands</option>
                                            <option value="Mauritania">Mauritania</option>
                                            <option value="Mauritius">Mauritius</option>
                                            <option value="Mexico">Mexico</option>
                                            <option value="Micronesia">Micronesia</option>
                                            <option value="Moldova">Moldova</option>
                                            <option value="Monaco">Monaco</option>
                                            <option value="Mongolia">Mongolia</option>
                                            <option value="Morocco">Morocco</option>
                                            <option value="Mozambique">Mozambique</option>
                                            <option value="Myanmar">Myanmar</option>
                                            <option value="Namibia">Namibia</option>
                                            <option value="Nauru">Nauru</option>
                                            <option value="Nepal">Nepal</option>
                                            <option value="Netherlands">Netherlands</option>
                                            <option value="New Zealand">New Zealand</option>
                                            <option value="Nicaragua">Nicaragua</option>
                                            <option value="Niger">Niger</option>
                                            <option value="Nigeria">Nigeria</option>
                                            <option value="Norway">Norway</option>
                                            <option value="Oman">Oman</option>
                                            <option value="Pakistan">Pakistan</option>
                                            <option value="Palau">Palau</option>
                                            <option value="Panama">Panama</option>
                                            <option value="Papua New Guinea">Papua New Guinea</option>
                                            <option value="Paraguay">Paraguay</option>
                                            <option value="Peru">Peru</option>
                                            <option value="Philippines">Philippines</option>
                                            <option value="Poland">Poland</option>
                                            <option value="Portugal">Portugal</option>
                                            <option value="Qatar">Qatar</option>
                                            <option value="Romania">Romania</option>
                                            <option value="Russia">Russia</option>
                                            <option value="Rwanda">Rwanda</option>
                                            <option value="Saint Kitts and Nevis">Saint Kitts and Nevis</option>
                                            <option value="Saint Lucia">Saint Lucia</option>
                                            <option value="Saint Vincent">Saint Vincent and The Grenadines</option>
                                            <option value="Samoa">Samoa</option>
                                            <option value="San Marino">San Marino</option>
                                            <option value="Sao Tome and Principe">Sao Tome and Principe</option>
                                            <option value="Saudi Arabia">Saudi Arabia</option>
                                            <option value="Senegal">Senegal</option>
                                            <option value="Serbia and Montenegro">Serbia and Montenegro</option>
                                            <option value="Seychelles">Seychelles</option>
                                            <option value="Sierra Leone">Sierra Leone</option>
                                            <option value="Singapore">Singapore</option>
                                            <option value="Slovakia">Slovakia</option>
                                            <option value="Slovenia">Slovenia</option>
                                            <option value="Solomon Islands">Solomon Islands</option>
                                            <option value="Somalia">Somalia</option>
                                            <option value="South Africa">South Africa</option>
                                            <option value="Spain">Spain</option>
                                            <option value="Sri Lanka">Sri Lanka</option>
                                            <option value="Sudan">Sudan</option>
                                            <option value="Suriname">Suriname</option>
                                            <option value="Swaziland">Swaziland</option>
                                            <option value="Sweden">Sweden</option>
                                            <option value="Switzerland">Switzerland</option>
                                            <option value="Syria">Syria</option>
                                            <option value="Taiwan">Taiwan</option>
                                            <option value="Tajikistan">Tajikistan</option>
                                            <option value="Tanzania">Tanzania</option>
                                            <option value="Thailand">Thailand</option>
                                            <option value="Togo">Togo</option>
                                            <option value="Tonga">Tonga</option>
                                            <option value="Trinidad and Tobago">Trinidad and Tobago</option>
                                            <option value="Tunisia">Tunisia</option>
                                            <option value="Turkey">Turkey</option>
                                            <option value="Turkmenistan">Turkmenistan</option>
                                            <option value="Tuvalu">Tuvalu</option>
                                            <option value="Uganda">Uganda</option>
                                            <option value="Ukraine">Ukraine</option>
                                            <option value="United Arab Emirates">United Arab Emirates</option>
                                            <option value="United Kingdom">United Kingdom</option>
                                            <option value="United States">United States</option>
                                            <option value="Uruguay">Uruguay</option>
                                            <option value="Uzbekistan">Uzbekistan</option>
                                            <option value="Vanuatu">Vanuatu</option>
                                            <option value="Vatican City">Vatican City</option>
                                            <option value="Venezuela">Venezuela</option>
                                            <option value="Vietnam">Vietnam</option>
                                            <option value="Yemen">Yemen</option>
                                            <option value="Zambia">Zambia</option>
                                            <option value="Zimbabwe">Zimbabwe</option>
                                        </select>

                                    </div>
                                    <div class="form-group col-md-6">
                                        <label class="form-label" for="mobno">Phone Number:</label>
                                        <input type="text" name="phone" value="<?php echo $phone ?>" class="form-control" id="mobno" placeholder="Phone Number">
                                    </div>

                                    <div class="form-group col-md-6">
                                        <label class="form-label" for="email">Email:</label>
                                        <input type="email" name="email" value="<?php echo $email ?>" class="form-control" id="email" placeholder="Email" readonly="">
                                    </div>

                                    <div class="form-group col-md-12">
                                        <label class="form-label" for="city">Town/City:</label>
                                        <input type="text" class="form-control" name="city" value="<?php echo $city ?>" id="city" placeholder="Town/City">
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label class="form-label" for="zip">Zip code:</label>
                                        <input type="text" class="form-control" name="zip" value="<?php echo $zip ?>" id="zip" placeholder="Zip/postal code">
                                    </div>
                                </div>


                                <button name="save" type="submit" class="btn btn-primary">
                                    save
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xl-9 col-lg-8">
                <div class="card">
                    <div class="card-header d-flex justify-content-between">
                        <div class="header-title">
                            <h6 class="card-title">Account Verification</h6>
                            <span>Verify your account to access all platform features</span>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="new-user-info">
                            <div class="bd-example table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th scope="col"></th>
                                            <th scope="col">Unverified</th>
                                            <th scope="col">Verified</th>

                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <th scope="row">Withdrawals limit per day</th>
                                            <td>20,000 USD (or equal)</td>
                                            <td>Unlimited</td>

                                        </tr>
                                        <tr>
                                            <th scope="row">KYC Bonus</th>
                                            <td>-</td>
                                            <td>10 USD</td>

                                        </tr>
                                        <tr>
                                            <th scope="row"></th>
                                            <td></td>
                                            <td><a href="kyc.php" class="btn btn-sm btn-info">Verify</a></td>

                                        </tr>
                                    </tbody>

                                </table>
                                <span style="font-size: 12px;">Usually, KYC verification takes no more than 2 minutes.
                                    For more information
                                    about our KYC and AML Policy please message our support</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xl-9 col-lg-8">
                <div class="card">
                    <div class="card-header d-flex justify-content-between">
                        <div class="header-title">
                            <h4 class="card-title">Edit Security</h4>
                        </div>
                    </div>
                    <div class="card-body">
                      <?php
                          if (isset($_POST['update_pass'])) {
                              $old = $_POST['oldpass'];
                              $new = $_POST['newpassword'];
                              $confirm = $_POST['confirmpassword'];

                              if(empty($old) || empty($new) || empty($confirm)){
                                $pass_error = "<div class='alert alert-danger d-flex align-items-center' role='alert'>
                                  <i class='fa fa-warning'></i> &nbsp; Enter old password, new password and confirm password
                                </div>";

                              }elseif ($old != $password) {
                                $pass_error = "<div class='alert alert-danger d-flex align-items-center' role='alert'>
                                  <i class='fa fa-warning'></i> &nbsp; Incorrect password
                                </div>";

                              }else if ($new != $confirm) {
                                $pass_error = "<div class='alert alert-danger d-flex align-items-center' role='alert'>
                                  <i class='fa fa-warning'></i> &nbsp; Passwords do not match
                                </div>";

                              }else if (strlen($new) <=5) {
                                $pass_error = "<div class='alert alert-danger d-flex align-items-center' role='alert'>
                                  <i class='fa fa-warning'></i> &nbsp; Password must be more than 5 characters
                                </div>";

                              }else {
                                  $sql_password = "UPDATE users SET password  = '$new' WHERE user_id = '$user_id'";
                                  if ($connection->query($sql_password)===TRUE) {
                                    echo "<script>
                                      window.location.href='profile.php?pass_update=success'
                                    </script>";
                                  }else {
                                    echo "<script>
                                      window.location.href='profile.php?pass_update=error'
                                    </script>";
                                  }
                              }

                          }
                      ?>

                      <?php
                        $pass_update = $_GET['pass_update']
                       ?>
                      <?php if ($pass_update == "success"): ?>
                        <div class='alert alert-success d-flex align-items-center' role='alert'>
                          <i class='fa fa-check'></i> &nbsp; Password updated successfully.
                        </div>

                      <?php elseif ($pass_update == "error"): ?>
                        <div class='alert alert-danger d-flex align-items-center' role='alert'>
                          <i class='fa fa-warning'></i> &nbsp;  Sorry an error occurred. Please try again later or contact support
                        </div>
                      <?php else: ?>
                          <?php echo $pass_error; ?>
                      <?php endif; ?>


                        <div class="new-user-info">
                            <form action="" method="post">

                                <h5 class="mb-3">Security</h5>
                                <div class="row">

                                    <div class="form-group col-md-6">
                                        <label class="form-label" for="pass">Current Password:</label>
                                        <input type="password" name="oldpass" class="form-control" id="pass" placeholder="Enter old password">
                                    </div>
                                    <div class="form-group col-md-6">
                                        <label class="form-label" for="pass">New Password:</label>
                                        <input type="password" name="newpassword" class="form-control" id="newpass" placeholder="Enter new password">
                                    </div>
                                    <div class="form-group col-md-6">
                                        <label class="form-label" for="rpass">Repeat new Password:</label>
                                        <input type="password" name="confirmpassword" class="form-control" id="rpass" placeholder="Repeat Password ">
                                    </div>
                                </div>

                                <button name="update_pass" type="submit" class="btn btn-primary">
                                    save
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" charset="utf-8" async="" src="./asset_files/loader.js.download"></script><script>
// Function to preview the selected image
function previewImage() {
    var input = document.getElementById('imageInput');
    var preview = document.getElementById('imagePreview');

    // Check if a file is selected
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function(e) {
            preview.src = e.target.result;
            preview.style.display = 'block'; // Display the image
        }

        reader.readAsDataURL(input.files[0]);
    } else {
        preview.src = '#';
        preview.style.display = 'none'; // Hide the image if no file is selected
    }
}

// Attach the 'previewImage' function to the 'change' event of the file input
document.getElementById('imageInput').addEventListener('change', previewImage);
</script>

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