obanana_b2b_test/user-profile.php

1698 lines
90 KiB
PHP
Raw Permalink Normal View History

2024-02-12 10:35:09 +08:00
<?php
include "functions.php";
2024-02-12 10:35:09 +08:00
$_SESSION["url"] = $_SERVER['REQUEST_URI'];
if ($_SESSION["userId"] <> "") {
$_SESSION["isLoggedIn"] = true;
$customer_data = getCustomerbyLoginId($_SESSION["userId"]);
} else {
$_SESSION["isLoggedIn"] = false;
2024-04-16 10:47:29 +08:00
header("location: login.php");
2024-02-12 10:35:09 +08:00
}
if ($_SESSION["isVendor"] == true) {
header("location: vendor-dashboard.php");
}
2024-02-12 10:35:09 +08:00
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<title>oBanana B2B - Elevate Your Business</title>
2024-05-30 10:03:49 +08:00
<meta name="keywords"
content="apparel, catalog, clean, ecommerce, ecommerce HTML, electronics, fashion, html eCommerce, html store, minimal, multipurpose, multipurpose ecommerce, online store, responsive ecommerce template, shops" />
2024-02-12 10:35:09 +08:00
<meta name="description" content="Best ecommerce html template for single and multi vendor store.">
<meta name="author" content="ashishmaraviya">
<!-- site Favicon -->
<link rel="icon" href="assets/images/favicon/favicon.png" sizes="32x32" />
<link rel="apple-touch-icon" href="assets/images/favicon/favicon.png" />
<meta name="msapplication-TileImage" content="assets/images/favicon/favicon.png" />
<!-- css Icon Font -->
2024-05-30 10:03:49 +08:00
<link rel="stylesheet" href="assets/css/vendor/ecicons.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
2024-02-12 10:35:09 +08:00
<!-- css All Plugins Files -->
<link rel="stylesheet" href="assets/css/plugins/animate.css" />
<link rel="stylesheet" href="assets/css/plugins/swiper-bundle.min.css" />
<link rel="stylesheet" href="assets/css/plugins/jquery-ui.min.css" />
<link rel="stylesheet" href="assets/css/plugins/countdownTimer.css" />
<link rel="stylesheet" href="assets/css/plugins/slick.min.css" />
<link rel="stylesheet" href="assets/css/plugins/bootstrap.css" />
<!-- Main Style -->
<link rel="stylesheet" href="assets/css/style.css" />
<link rel="stylesheet" href="assets/css/style2.css" />
<link rel="stylesheet" href="assets/css/responsive.css" />
2024-03-07 10:53:15 +08:00
<!-- FONTAWESOME -->
2024-05-30 10:03:49 +08:00
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
2024-03-07 10:53:15 +08:00
2024-02-12 10:35:09 +08:00
<!-- Background css -->
<link rel="stylesheet" id="bg-switcher-css" href="assets/css/backgrounds/bg-4.css">
2024-05-30 10:03:49 +08:00
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@latest/dist/css/select2.min.css"
crossorigin="anonymous" referrerpolicy="no-referrer" />
2024-02-12 10:35:09 +08:00
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
2024-05-30 10:03:49 +08:00
<script src="https://cdn.jsdelivr.net/npm/select2@latest/dist/js/select2.min.js" crossorigin="anonymous"
referrerpolicy="no-referrer"></script>
2024-02-12 10:35:09 +08:00
<script>
2024-05-30 10:03:49 +08:00
function updateCartItemCount() {
$.get("cartitems.php?id=<?php echo $_SESSION['customerId']; ?>", function(data, status) {
if (data != "") {
console.log("Data: " + data + "\nStatus: " + status);
document.getElementById("cartItemCount").innerHTML = data;
}
});
}
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
function updateWishItemCount() {
$.get("wishlistitems.php?id=<?php echo $_SESSION['customerId']; ?>", function(data) {
if (data != "") {
document.getElementById("wishItemCount").innerHTML = data;
}
});
}
2024-02-12 10:35:09 +08:00
</script>
<style>
2024-05-30 10:03:49 +08:00
#edit_modal .cover-upload:after {
background-color: orange;
}
.ec-user-account .ec-vendor-block-bg {
width: 100%;
height: 200px;
background-image: none;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-blend-mode: overlay;
background-color: rgba(0, 0, 0, 0.6);
border-radius: 5px;
}
#editDelete:hover i {
color: #ffaa00;
cursor: pointer;
}
2024-02-12 10:35:09 +08:00
</style>
</head>
<body class="shop_page" onload="updateCartItemCount(); updateWishItemCount()">
<div id="ec-overlay">
<div class="ec-ellipsis">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
<!-- Header start -->
<?php include "header.php" ?>
<!-- Header End -->
<!-- ekka Cart Start -->
<!-- ekka Cart End -->
2024-02-29 16:00:50 +08:00
<!-- Category Sidebar start -->
<?php include "category-slider.php" ?>
2024-02-29 16:00:50 +08:00
2024-02-12 10:35:09 +08:00
<!-- Ec breadcrumb start -->
<div class="sticky-header-next-sec ec-breadcrumb section-space-mb">
<div class="container">
<div class="row">
<div class="col-12">
<div class="row ec_breadcrumb_inner">
<div class="col-md-6 col-sm-12">
<h2 class="ec-breadcrumb-title">User Profile</h2>
</div>
<div class="col-md-6 col-sm-12">
<!-- ec-breadcrumb-list start -->
<ul class="ec-breadcrumb-list">
<li class="ec-breadcrumb-item"><a href="index.php">Home</a></li>
<li class="ec-breadcrumb-item active">Profile</li>
</ul>
<!-- ec-breadcrumb-list end -->
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Ec breadcrumb end -->
<!-- User profile section -->
<section class="ec-page-content ec-vendor-uploads ec-user-account section-space-p">
<div class="container">
<div class="row">
<!-- Sidebar Area Start -->
<div class="ec-shop-leftside ec-vendor-sidebar col-lg-3 col-md-12">
<div class="ec-sidebar-wrap ec-border-box">
<!-- Sidebar Category Block -->
<div class="ec-sidebar-block">
<div class="ec-vendor-block">
<!-- <div class="ec-vendor-block-bg"></div>
<div class="ec-vendor-block-detail">
<img loading="lazy" class="v-img" src="assets/images/user/1.jpg" alt="vendor image">
2024-02-12 10:35:09 +08:00
<h5>Mariana Johns</h5>
</div> -->
<?php include 'user-profile-tabs.php' ?>
</div>
</div>
2024-05-30 10:03:49 +08:00
2024-02-12 10:35:09 +08:00
</div>
</div>
<div class="ec-shop-rightside col-lg-9 col-md-12">
<div class="ec-vendor-dashboard-card ec-vendor-setting-card">
<div class="ec-vendor-card-body">
<div class="row">
<div class="col-md-12">
<div class="ec-vendor-block-profile">
<div class="ec-vendor-block-img space-bottom-30 ">
2024-05-30 10:03:49 +08:00
<div class="ec-vendor-block-bg"
style="background-color: orange; background-image: url(<?php echo $customer_data['customer_banner'] ?>) !important;">
<a href="#" class="btn btn-lg btn-primary" data-link-action="editmodal"
title="Edit Detail" data-bs-toggle="modal"
data-bs-target="#edit_modal">Edit Detail</a>
2024-02-12 10:35:09 +08:00
</div>
<div class="ec-vendor-block-detail">
<?php
$customer_image = isset($customer_data[0]['customer_image']) ? $customer_data[0]['customer_image'] : 'https://yourteachingmentor.com/wp-content/uploads/2020/12/istockphoto-1223671392-612x612-1.jpg';
?>
2024-05-30 10:03:49 +08:00
<img loading="lazy" class="v-img" src=<?php echo $customer_image ?>
alt="vendor image">
<h5 class="name"><?php echo $customer_data[0]['first_name'] ?>
<?php echo $customer_data[0]['last_name'] ?></h5>
2024-02-12 10:35:09 +08:00
</div>
</div>
<h5>Account Information </h5>
<div class="row">
<div class="col-md-6 col-sm-12">
2024-05-30 10:03:49 +08:00
<div
class="ec-vendor-detail-block ec-vendor-block-email space-bottom-30">
2024-02-12 10:35:09 +08:00
<h6>E-mail address </h6>
<ul>
2024-05-30 10:03:49 +08:00
<li><strong>
</strong><?php echo $customer_data[0]['user_email'] ?></li>
2024-02-12 10:35:09 +08:00
</ul>
</div>
</div>
<div class="col-md-6 col-sm-12">
2024-05-30 10:03:49 +08:00
<div
class="ec-vendor-detail-block ec-vendor-block-contact space-bottom-30">
2024-02-12 10:35:09 +08:00
<h6>Contact number</h6>
<ul>
<li><strong><?php echo $customer_data['phone_number'] ?></li>
2024-02-12 10:35:09 +08:00
</ul>
</div>
</div>
<div class="col-md-12 col-sm-12">
2024-05-30 10:03:49 +08:00
<div
class="ec-vendor-detail-block ec-vendor-block-contact space-bottom-30">
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
<h6>Address <button type="button" class="btn btn-primary"
id="addressModalBtn" data-bs-toggle="modal"
data-bs-target="#addressModal">My Addresses</button></h6>
2024-02-12 10:35:09 +08:00
<div class="shipping">
<?php foreach ($customer_data[0]['address'] as $address) : ?>
2024-05-30 10:03:49 +08:00
<?php if ($address['shipping']) : ?>
<div>
<span style="font-size:16px;font-weight:800;">Shipping
Address:</span>
</div>
2024-05-30 10:03:49 +08:00
<div class="sName">
<span>Name:
<span
id="selectedFName"><?php echo $address['first_name']; ?></span>
<span id="selectedLName">
<?php echo $address['last_name']; ?></span>
</span>
</div>
<div class="sContact">
<span id="selectedContact">Contact #:
<?php echo $address['phone']; ?></span>
</div>
<div class="sAddress">
<span>Address:
<span
id="sBuilding"><?php echo $address['address_1']; ?></span>
<span
id="sStreet"><?php echo $address['address_2']; ?></span>
<span
id="sBarangay"><?php echo $address['barangay']; ?></span>
<span id="sCity"><?php echo $address['city']; ?></span>
<span
id="sProvince"><?php echo $address['province']; ?></span>
<span
id="sCountry"><?php echo $address['country']; ?></span>
</span>
</div>
<?php endif; ?>
<?php if ($address['billing']) : ?>
<div>
<span style="font-size:16px;font-weight:800;">Billing
Address:</span>
</div>
<div class="sName">
<span>Name:
<span
id="selectedBillingFName"><?php echo $address['first_name']; ?></span>
<span id="selectedBillingLName">
<?php echo $address['last_name']; ?></span>
</span>
</div>
<div class="sContact">
<span id="selectedBillingContact">Contact #:
<?php echo $address['phone']; ?></span>
</div>
<div class="sAddress">
<span>Address:
<span
id="sBillingBuilding"><?php echo $address['address_1']; ?></span>
<span
id="sBillingStreet"><?php echo $address['address_2']; ?></span>
<span
id="sBillingBarangay"><?php echo $address['barangay']; ?></span>
<span
id="sBillingCity"><?php echo $address['city']; ?></span>
<span
id="sBillingProvince"><?php echo $address['province']; ?></span>
<span
id="sBillingCountry"><?php echo $address['country']; ?></span>
</span>
</div>
<?php endif; ?>
2024-02-12 10:35:09 +08:00
<?php endforeach; ?>
</div>
<!-- <div class="billing">
<php foreach ($customer_data[0]['address'] as $address) : ?>
<php if ($address['billing']) : ?>
<div>
<span style="font-size:16px;font-weight:800;"><php var_dump($address); ?>Billing Address:</span>
</div>
<div class="sName">
<span>Name:
<span id="selectedBillingFName"><php echo $address['first_name']; ?></span>
<span id="selectedBillingLName"> <php echo $address['last_name']; ?></span>
</span>
</div>
<div class="sContact">
<span id="selectedBillingContact">Contact #: <php echo $address['phone']; ?></span>
</div>
<div class="sAddress">
<span>Address:
<span id="sBillingBuilding"><php echo $address['address_1']; ?></span>
<span id="sBillingStreet"><php echo $address['address_2']; ?></span>
<span id="sBillingBarangay"><php echo $address['barangay']; ?></span>
<span id="sBillingCity"><php echo $address['city']; ?></span>
<span id="sBillingProvince"><php echo $address['province']; ?></span>
<span id="sBillingCountry"><php echo $address['country']; ?></span>
</span>
</div>
<php endif; ?>
<php endforeach; ?>
</div> -->
2024-02-12 10:35:09 +08:00
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="addressModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-sm" role="document" style="max-width: 800px;">
<div class="modal-content">
<div class="modal-body" style="overflow-y: auto; max-height: 90vh;">
2024-05-30 10:03:49 +08:00
<button type="button" class="btn btn-primary mb-3" data-bs-toggle="modal"
data-bs-target="#secondModal">Add New Address</button>
2024-02-12 10:35:09 +08:00
<!-- Display a list of addresses and let the user choose -->
<form id="addressForm">
<?php foreach ($customer_data as $customer_index => $customer) { ?>
2024-05-30 10:03:49 +08:00
<?php foreach ($customer['address'] as $address_index => $address) { ?>
<!-- added id -->
<div class="card mb-3" id="form-check-<?php echo $address_index ?>">
<div class="card-body">
<div class="selectCon">
<div class="selectWrap"
style="display: flex; justify-content: center; align-items: center; width: 50%;">
<input type="radio"
style="padding-left: 0px !important; margin: 0px 0px !important;"
name="selectedBillingAddress[<?php echo $customer_index; ?>]"
id="billing_address_<?php echo $customer_index; ?>_<?php echo $address_index; ?>"
value="<?php echo $customer_index; ?>_<?php echo $address_index; ?>"
2024-05-30 10:03:49 +08:00
class="form-check-input"
onchange="updateAddressBilling('<?php echo $customer['_id']; ?>', <?php echo $address_index; ?>, true)"
<?php echo $address["billing"] ? 'checked' : ''; ?>>
<!-- <input type="radio" style="padding-left: 0px !important; margin: 0px 0px !important;" name="selectedBillingAddress[<?php # echo $customer_index; ?>]" id="billing_address_<?php # echo $customer_index; ?>_<?php # echo $address_index; ?>" value="<?php # echo $customer_index; ?>_<?php # echo $address_index; ?>" class="form-check-input" <?php # echo $address["billing"] ? 'checked' : ''; ?>> -->
2024-05-30 10:03:49 +08:00
<label class="form-check-label" style="margin: 0px 10px !important;"
for="billing_address_<?php echo $customer_index; ?>_<?php echo $address_index; ?>">
Billing Address
</label>
</div>
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
<div class="selectWrap"
style="display: flex; justify-content: center; align-items: center; width: 50%; margin-left:-20px;">
<input type="radio"
style="padding-left: 0px !important; margin: 0px 0px !important;"
name="selectedShippingAddress[<?php echo $customer_index; ?>]"
id="shipping_address_<?php echo $customer_index; ?>_<?php echo $address_index; ?>"
value="<?php echo $customer_index; ?>_<?php echo $address_index; ?>"
2024-05-30 10:03:49 +08:00
class="form-check-input"
onchange="updateAddressShipping('<?php echo $customer['_id']; ?>', <?php echo $address_index; ?>, true)"
<?php echo $address["shipping"] ? 'checked' : ''; ?>>
<!-- <input type="radio" style="padding-left: 0px !important; margin: 0px 0px !important;" name="selectedShippingAddress[<?php # echo $customer_index; ?>]" id="shipping_address_<?php # echo $customer_index; ?>_<?php # echo $address_index; ?>" value="<?php # echo $customer_index; ?>_<?php # echo $address_index; ?>" class="form-check-input" <?php # echo $address["billing"] ? 'checked' : ''; ?>> -->
2024-05-30 10:03:49 +08:00
<label class="form-check-label" style="margin: 0px 10px !important;"
for="shipping_address_<?php echo $customer_index; ?>_<?php echo $address_index; ?>">
Shipping Address
</label>
</div>
</div>
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
<!-- 03-01-2024 Stacy modified this block of code -->
<div class="container">
<div class="row">
<div class="col-md-12 mx-auto">
<!-- Adjust the column size as needed -->
<div id="editDelete"
style="display:flex; float:right; width:20px; margin-right:-10px;">
<?php
2024-03-07 10:53:15 +08:00
$address['id'] =$address_index;
$jsonAddress = json_encode($address)?>
2024-05-30 10:03:49 +08:00
<a href="javascript:0" data-bs-toggle="modal"
data-value=' <?php echo $jsonAddress; ?>'
data-bs-target="#thirdModal">
<i class="fa-regular fa-pen-to-square"
style="font-size:15px; float:right;"></i></a>
<!-- <i class="fa-regular fa-trash-can" style="font-size:15px; float:right;"></i> -->
2024-02-12 10:35:09 +08:00
</div>
2024-05-30 10:03:49 +08:00
<div id="editDelete"
style="display:flex; float:right; width:20px; margin-top:20px; margin-right:-20px; margin-top:30px;">
<!-- <i class="fa-solid fa-pen" style="font-size:15px; float:right;"></i></a> -->
<i onclick="deleteAddress('<?php echo $customer['_id']; ?>', <?php echo $address_index; ?>, true)"
class="fa-regular fa-trash-can"
style="font-size:15px; float:right;"></i>
</div>
<label class="form-check-label"
for="address_<?php echo $customer_index; ?>_<?php echo $address_index; ?>">
<?php echo $address['first_name']; ?>
<?php echo $address['last_name']; ?><br>
<?php echo $address['address_1']; ?>
<?php echo $address['address_2']; ?>
<?php echo $address['barangay']; ?>,
<?php echo $address['city']; ?>,
<?php echo $address['province']; ?>
<?php echo $address['country']; ?><br>
Phone: <?php echo $address['phone']; ?>
</label>
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
</div>
2024-02-12 10:35:09 +08:00
</div>
</div>
2024-05-30 10:03:49 +08:00
</div>
</div>
2024-02-12 10:35:09 +08:00
<?php } ?>
2024-05-30 10:03:49 +08:00
<?php } ?>
<!-- <button type="button" onclick="updateAddressBilling('<?php # echo $customer['_id']; ?>', <?php # echo $address_index; ?>, true)">Use Selected Address</button> -->
2024-02-12 10:35:09 +08:00
</form>
</div>
</div>
</div>
</div>
2024-03-07 10:53:15 +08:00
<!-- secondModal -->
2024-02-12 10:35:09 +08:00
<div class="modal fade" id="secondModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-sm" role="document" style="max-width: 800px;">
<div class="modal-content">
<div class="modal-body" style="overflow-y: auto; max-height: 90vh;">
<form>
<div class="form-group">
2024-05-30 10:03:49 +08:00
<label for="addressFirstName" class="text-dark font-weight-medium pt-3 mb-2">First
Name</label>
2024-02-12 10:35:09 +08:00
<input type="text" class="form-control" id="addressFirstName">
</div>
<div class="form-group">
2024-05-30 10:03:49 +08:00
<label for="addressLastName" class="text-dark font-weight-medium pt-3 mb-2">Last
Name</label>
2024-02-12 10:35:09 +08:00
<input type="text" class="form-control" id="addressLastName">
</div>
<div class="form-group">
2024-05-30 10:03:49 +08:00
<label for="addressContact" class="text-dark font-weight-medium pt-3 mb-2">Contact
Number</label>
<input type="text" class="form-control" id="addressContact" value="+63 "
oninput="preventErasePrefix(this)">
2024-02-12 10:35:09 +08:00
</div>
<div class="form-group">
2024-05-30 10:03:49 +08:00
<label for="addressBuilding" class="text-dark font-weight-medium pt-3 mb-2">
House/Unit/Floor #, Bldg Name, Block or Lot # </label>
2024-02-12 10:35:09 +08:00
<input type="text" class="form-control" id="addressBuilding">
</div>
<div class="form-group">
2024-05-30 10:03:49 +08:00
<label for="addressStreet" class="text-dark font-weight-medium pt-3 mb-2"> Street
</label>
2024-02-12 10:35:09 +08:00
<input type="text" class="form-control" id="addressStreet">
</div>
<div class="form-group">
<label for="provinceSelect">Province</label>
<select class="form-select" id="provinceSelect">
<option value="" disabled selected hidden>Select Province</option>
</select>
</div>
<div class="form-group">
<label for="citySelect">Municipality/City</label>
<select class="form-select" id="citySelect" required>
<option value="" disabled selected hidden>Select Municipality/City</option>
</select>
</div>
<div class="form-group">
<label for="barangaySelect">Barangay</label>
<select class="form-select" id="barangaySelect" required>
<option value="" disabled selected hidden>Select Barangay</option>
</select>
</div>
<div class="form-group">
2024-05-30 10:03:49 +08:00
<label for="addressCountry"
class="text-dark font-weight-medium pt-3 mb-2">Country</label>
<input type="text" class="form-control" id="addressCountry" value="Philippines">
2024-02-12 10:35:09 +08:00
</div>
2024-04-23 08:58:19 +08:00
<button type="button" class="btn btn-primary mt-4" id="submitBtn">Submit</button>
2024-02-12 10:35:09 +08:00
</form>
</div>
</div>
</div>
</div>
2024-03-07 10:53:15 +08:00
<!-- 03-01-2024 Stacy added thirdModal -->
<div class="modal fade" id="thirdModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-sm" role="document" style="max-width: 800px;">
<div class="modal-content">
<div class="modal-body" style="overflow-y: auto; max-height: 90vh;">
<form>
<div class="form-group">
2024-05-30 10:03:49 +08:00
<label for="addressFirstName" class="text-dark font-weight-medium pt-3 mb-2">First
Name</label>
<input type="text" class="form-control" id="addressFirstName2"
value="<?php echo $address['first_name']; ?>">
2024-03-07 10:53:15 +08:00
<!-- <label for="addressFirstName" class="text-dark font-weight-medium pt-3 mb-2">First Name</label>-->
2024-05-30 10:03:49 +08:00
<input type="hidden" class="form-control" id="addressId">
2024-03-07 10:53:15 +08:00
</div>
<div class="form-group">
2024-05-30 10:03:49 +08:00
<label for="addressLastName" class="text-dark font-weight-medium pt-3 mb-2">Last
Name</label>
<input type="text" class="form-control" id="addressLastName2"
value="<?php echo $address['last_name']; ?>">
2024-03-07 10:53:15 +08:00
<!-- <label for="addressLastName" class="text-dark font-weight-medium pt-3 mb-2">Last Name</label>
<input type="text" class="form-control" id="addressLastName"> -->
</div>
<div class="form-group">
2024-05-30 10:03:49 +08:00
<label for="addressContact" class="text-dark font-weight-medium pt-3 mb-2">Contact
Number</label>
<input type="text" class="form-control" id="addressContact2"
value="<?php echo $address['phone']; ?>" oninput="preventEraseThePrefix(this)">
2024-03-07 10:53:15 +08:00
<!-- <label for="addressContact" class="text-dark font-weight-medium pt-3 mb-2">Contact Number</label>
<input type="number" class="form-control" id="addressContact"> -->
</div>
<div class="form-group">
<label for="addressBuilding" class="text-dark font-weight-medium pt-3 mb-2">House/Unit/Flr #, Bldg Name, Blk or Lot #</label>
<input type="text" class="form-control" id="addressBuilding2" value="<?php echo $address['address_1']; ?>">
2024-03-07 10:53:15 +08:00
<!-- <label for="addressBuilding" class="text-dark font-weight-medium pt-3 mb-2"> Building,Number </label>
<input type="text" class="form-control" id="addressBuilding"> -->
</div>
<div class="form-group">
2024-05-30 10:03:49 +08:00
<label for="addressStreet" class="text-dark font-weight-medium pt-3 mb-2">Street
</label>
<input type="text" class="form-control" id="addressStreet2"
value="<?php echo $address['address_2']; ?>">
2024-03-07 10:53:15 +08:00
<!-- <label for="addressStreet" class="text-dark font-weight-medium pt-3 mb-2"> Street </label>
<input type="text" class="form-control" id="addressStreet"> -->
</div>
<div class="form-group">
<label for="provinceSelect2">Province</label>
<select class="form-select" id="provinceSelect2">
2024-05-30 10:03:49 +08:00
<option id="provinceSelect2Opt" value="<?php echo $address['province']; ?>">Select
Province</option>
2024-03-07 10:53:15 +08:00
</select>
<!-- <label for="provinceSelect">Province</label>
<select class="form-select" id="provinceSelect">
<option value="" disabled selected hidden>Select Province</option>
</select> -->
</div>
<div class="form-group">
<label for="citySelect2">Municipality/City</label>
<select class="form-select" id="citySelect2" required>
2024-05-30 10:03:49 +08:00
<option value="" id="citySelect2Opt" selected hidden>Select Municipality/City
</option>
2024-03-07 10:53:15 +08:00
</select>
</div>
<div class="form-group">
<label for="barangaySelect2">Barangay</label>
<select class="form-select" id="barangaySelect2" required>
2024-05-30 10:03:49 +08:00
<option value="" id="barangaySelect2Opt" selected hidden>Select Barangay</option>
2024-03-07 10:53:15 +08:00
</select>
</div>
<div class="form-group">
2024-05-30 10:03:49 +08:00
<label for="addressCountry2"
class="text-dark font-weight-medium pt-3 mb-2">Country</label>
2024-03-07 10:53:15 +08:00
<input type="text" class="form-control" id="addressCountry2">
</div>
2024-04-23 08:58:19 +08:00
<button type="button" class="btn btn-primary mt-4" id="submitBtn2">Submit</button>
2024-05-30 10:03:49 +08:00
2024-03-07 10:53:15 +08:00
</form>
</div>
</div>
</div>
</div>
<script>
2024-05-30 10:03:49 +08:00
function preventErasePrefix(input) {
/* secondmodal */
var numericValue = input.value.replace(/\D/g, '');
if (numericValue.startsWith('63')) {
input.value = "+63 " + numericValue.substring(2);
} else {
input.value = "+63 " + numericValue;
}
if (input.value.length > 14) {
input.value = input.value.slice(0, 14);
}
2024-05-30 10:03:49 +08:00
}
2024-05-30 10:03:49 +08:00
function preventEraseThePrefix(input) {
/* thirdmodal */
var numericValue = input.value.replace(/\D/g, '');
if (numericValue.startsWith('63')) {
input.value = "+63 " + numericValue.substring(2);
} else {
input.value = "+63 " + numericValue;
}
if (input.value.length > 14) {
input.value = input.value.slice(0, 14);
}
2024-05-30 10:03:49 +08:00
}
function preventEraseInPrefix(input) {
/* edit details */
var numericValue = input.value.replace(/\D/g, '');
if (numericValue.startsWith('63')) {
input.value = "+63 " + numericValue.substring(2);
} else {
input.value = "+63 " + numericValue;
}
if (input.value.length > 14) {
input.value = input.value.slice(0, 14);
}
2024-05-30 10:03:49 +08:00
}
</script>
2024-02-12 10:35:09 +08:00
<script>
2024-05-30 10:03:49 +08:00
// var myElement = document.getElementById('myElement');
// myElement.style.backgroundImage = 'red';
function editUser() {
// var fileInput = document.getElementById('fileInput' + vendorId);
// var file = fileInput.files[0];
const customerId = `<?php echo $customer_data[0]['_id']; ?>`;
const firstName = document.getElementById('first_name-').value;
const lastName = document.getElementById('last_name-').value;
const username = document.getElementById('username-').value;
const phone = document.getElementById('phone-').value;
// If no file selected, only update the email
fetch(`https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/${customerId}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
first_name: firstName,
last_name: lastName,
user_login: username,
phone_number: phone,
2024-02-12 10:35:09 +08:00
})
2024-05-30 10:03:49 +08:00
})
.then(response => {
if (response.ok) {
console.log('Profile updated Successful');
location.reload();
// Handle any other actions after the successful email update
} else {
console.error('Profile Failed to Upload');
// Handle errors or display a message to the user
}
})
.catch(error => {
console.error('Error during fetch:', error);
// Handle network or other errors
});
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
}
2024-02-12 10:35:09 +08:00
</script>
<script>
2024-05-30 10:03:49 +08:00
// function for delete
function deleteAddress(customerId, addressIndex) {
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/' + customerId)
2024-03-07 10:53:15 +08:00
.then(response => response.json())
.then(data => {
let existingAddresses = data.address || [];
if (addressIndex >= 0 && addressIndex < existingAddresses.length) {
existingAddresses.splice(addressIndex, 1);
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/' + customerId, {
2024-05-30 10:03:49 +08:00
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
address: existingAddresses
}),
})
.then(response => {
if (response.ok) {
// location.reload();
// filter the delete action
document.getElementById('form-check-' + addressIndex).remove();
} else {
console.error('Failed to submit data');
alert('Failed to submit data');
}
})
.catch(error => {
console.error('Error:', error);
alert('Error submitting data');
});
2024-03-07 10:53:15 +08:00
} else {
console.log("Invalid address index.");
}
})
.catch(error => {
console.error('Error:', error);
alert('Error fetching customer data');
});
2024-05-30 10:03:49 +08:00
}
2024-03-07 10:53:15 +08:00
</script>
<script>
2024-05-30 10:03:49 +08:00
// 03-04-2024 added
$('#thirdModal').on('shown.bs.modal', function(event) {
2024-03-07 10:53:15 +08:00
var jsonString = $(event.relatedTarget).data('value');
2024-05-30 10:03:49 +08:00
2024-03-07 10:53:15 +08:00
var jsonObject = JSON.parse(jsonString);
console.log(jsonObject)
// document.getElementById("addressFirstName2").value('mmmm');
// $('#addressFirstName2').setAttribute('value','My default value');
2024-05-30 10:03:49 +08:00
2024-03-07 10:53:15 +08:00
// shows inputed data by the customer
document.querySelector('input[id="addressFirstName2"]').value = jsonObject.first_name;
document.querySelector('input[id="addressLastName2"]').value = jsonObject.last_name;
document.querySelector('input[id="addressContact2"]').value = jsonObject.phone;
document.querySelector('input[id="addressBuilding2"]').value = jsonObject.address_1;
document.querySelector('input[id="addressStreet2"]').value = jsonObject.address_2;
document.querySelector('option[id="provinceSelect2Opt"]').text = jsonObject.province;
document.querySelector('option[id="provinceSelect2Opt"]').value = jsonObject.province;
document.querySelector('option[id="citySelect2Opt"]').text = jsonObject.city;
document.querySelector('option[id="citySelect2Opt"]').value = jsonObject.city;
document.querySelector('option[id="barangaySelect2Opt"]').text = jsonObject.barangay;
document.querySelector('option[id="barangaySelect2Opt"]').value = jsonObject.barangay;
document.querySelector('input[id="addressCountry2"]').value = jsonObject.country;
document.querySelector('input[id="addressId"]').value = jsonObject.id;
console.log('id ' + jsonObject.id)
const provinceSelect = $('#provinceSelect2'); // Use jQuery to select the element
const citySelect = $('#citySelect2'); // Use jQuery to select the element
const barangaySelect = $('#barangaySelect2'); // Use jQuery to select the element
// Initialize Select2 on the provinceSelect, citySelect, and barangaySelect elements
provinceSelect.select2({
dropdownParent: $('#thirdModal'),
containerCssClass: 'select2-zindex-high' // Optional, add a custom class for styling
});
citySelect.select2({
dropdownParent: $('#thirdModal'),
containerCssClass: 'select2-zindex-high' // Optional, add a custom class for styling
});
barangaySelect.select2({
dropdownParent: $('#thirdModal'),
containerCssClass: 'select2-zindex-high' // Optional, add a custom class for styling
});
// Fetch provinces data
fetch('https://psgc.gitlab.io/api/provinces')
.then(response => {
if (response.ok) {
return response.json();
} else {
console.error('Failed to fetch provinces');
throw new Error('Failed to fetch provinces');
}
})
.then(provincesData => {
// Iterate through the provinces data and add options
provincesData.forEach(province => {
const option = new Option(province.name, province.code);
provinceSelect.append(option);
});
// Add an extra option manually
const extraOption = new Option('Metro Manila', '130000000');
provinceSelect.append(extraOption);
// Add event listener to provinceSelect
provinceSelect.on('change', function() {
// Clear existing options in citySelect and barangaySelect
2024-05-30 10:03:49 +08:00
citySelect.html(
'<option value="" disabled selected hidden>Select City</option>');
barangaySelect.html(
'<option value="" disabled selected hidden>Select Barangay</option>'
);
2024-03-07 10:53:15 +08:00
// Fetch and update cities/municipalities based on the selected province
updateCities();
});
})
.catch(error => {
console.error('Error:', error);
});
// Function to update city/municipality options based on the selected province
function updateCities() {
2024-05-30 10:03:49 +08:00
const selectedProvinceCode = provinceSelect
.val(); // Use val() to get the selected value with Select2
2024-03-07 10:53:15 +08:00
if (selectedProvinceCode) {
let citiesEndpoint;
if (selectedProvinceCode === '130000000') {
// Check if Metro Manila is selected
citiesEndpoint = 'https://psgc.gitlab.io/api/regions/130000000/cities-municipalities/';
} else {
2024-05-30 10:03:49 +08:00
citiesEndpoint =
`https://psgc.gitlab.io/api/provinces/${selectedProvinceCode}/cities-municipalities/`;
2024-03-07 10:53:15 +08:00
}
fetch(citiesEndpoint)
.then(response => {
if (response.ok) {
return response.json();
} else {
console.error('Failed to fetch cities/municipalities');
throw new Error('Failed to fetch cities/municipalities');
}
})
.then(citiesData => {
// Iterate through the cities data and add options
citiesData.forEach(city => {
const option = new Option(city.name, city.code);
citySelect.append(option);
});
})
.catch(error => {
console.error('Error:', error);
});
}
}
// Add event listener to citySelect
citySelect.on('change', function() {
// Clear existing options in barangaySelect
2024-05-30 10:03:49 +08:00
barangaySelect.html(
'<option value="" disabled selected hidden>Select Barangay</option>');
2024-03-07 10:53:15 +08:00
// Fetch and update barangays based on the selected city/municipality
const selectedCityCode = citySelect.val();
if (selectedCityCode) {
2024-05-30 10:03:49 +08:00
fetch(
`https://psgc.gitlab.io/api/cities-municipalities/${selectedCityCode}/barangays/`
)
2024-03-07 10:53:15 +08:00
.then(response => {
if (response.ok) {
return response.json();
} else {
console.error('Failed to fetch barangays');
throw new Error('Failed to fetch barangays');
}
})
.then(barangaysData => {
// Iterate through the barangays data and add options
barangaysData.forEach(barangay => {
const option = new Option(barangay.name, barangay.code);
barangaySelect.append(option);
});
})
.catch(error => {
console.error('Error:', error);
});
}
});
// document.querySelector('input[id="addressFirstName2"]').value = jsonObject.last_name;
2024-05-30 10:03:49 +08:00
});
2024-03-07 10:53:15 +08:00
2024-05-30 10:03:49 +08:00
const customerId = '<?php echo $customer_data[0]['_id']; ?>';
document.addEventListener('DOMContentLoaded', function() {
// Get the select elements
const provinceSelect = $('#provinceSelect'); // Use jQuery to select the element
const citySelect = $('#citySelect'); // Use jQuery to select the element
const barangaySelect = $('#barangaySelect'); // Use jQuery to select the element
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
// Initialize Select2 on the provinceSelect, citySelect, and barangaySelect elements
provinceSelect.select2({
dropdownParent: $('#secondModal'),
containerCssClass: 'select2-zindex-high' // Optional, add a custom class for styling
});
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
citySelect.select2({
dropdownParent: $('#secondModal'),
containerCssClass: 'select2-zindex-high' // Optional, add a custom class for styling
});
barangaySelect.select2({
dropdownParent: $('#secondModal'),
containerCssClass: 'select2-zindex-high' // Optional, add a custom class for styling
});
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
// Fetch provinces data
fetch('https://psgc.gitlab.io/api/provinces')
.then(response => {
if (response.ok) {
return response.json();
} else {
console.error('Failed to fetch provinces');
throw new Error('Failed to fetch provinces');
}
})
.then(provincesData => {
// Iterate through the provinces data and add options
provincesData.forEach(province => {
const option = new Option(province.name, province.code);
provinceSelect.append(option);
});
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
// Add an extra option manually
const extraOption = new Option('Metro Manila', '130000000');
provinceSelect.append(extraOption);
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
// Add event listener to provinceSelect
provinceSelect.on('change', function() {
// Clear existing options in citySelect and barangaySelect
citySelect.html(
'<option value="" disabled selected hidden>Select City</option>');
barangaySelect.html(
'<option value="" disabled selected hidden>Select Barangay</option>'
);
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
// Fetch and update cities/municipalities based on the selected province
updateCities();
2024-02-12 10:35:09 +08:00
});
2024-05-30 10:03:49 +08:00
})
.catch(error => {
console.error('Error:', error);
});
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
// Function to update city/municipality options based on the selected province
function updateCities() {
const selectedProvinceCode = provinceSelect
.val(); // Use val() to get the selected value with Select2
if (selectedProvinceCode) {
let citiesEndpoint;
if (selectedProvinceCode === '130000000') {
// Check if Metro Manila is selected
citiesEndpoint = 'https://psgc.gitlab.io/api/regions/130000000/cities-municipalities/';
} else {
citiesEndpoint =
`https://psgc.gitlab.io/api/provinces/${selectedProvinceCode}/cities-municipalities/`;
}
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
fetch(citiesEndpoint)
.then(response => {
if (response.ok) {
return response.json();
} else {
console.error('Failed to fetch cities/municipalities');
throw new Error('Failed to fetch cities/municipalities');
}
})
.then(citiesData => {
// Iterate through the cities data and add options
citiesData.forEach(city => {
const option = new Option(city.name, city.code);
citySelect.append(option);
2024-02-12 10:35:09 +08:00
});
2024-05-30 10:03:49 +08:00
})
.catch(error => {
console.error('Error:', error);
});
2024-02-12 10:35:09 +08:00
}
2024-05-30 10:03:49 +08:00
}
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
// Add event listener to citySelect
citySelect.on('change', function() {
// Clear existing options in barangaySelect
barangaySelect.html(
'<option value="" disabled selected hidden>Select Barangay</option>');
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
// Fetch and update barangays based on the selected city/municipality
const selectedCityCode = citySelect.val();
if (selectedCityCode) {
fetch(
`https://psgc.gitlab.io/api/cities-municipalities/${selectedCityCode}/barangays/`
)
2024-05-30 10:03:49 +08:00
.then(response => {
if (response.ok) {
return response.json();
} else {
console.error('Failed to fetch barangays');
throw new Error('Failed to fetch barangays');
}
})
.then(barangaysData => {
// Iterate through the barangays data and add options
barangaysData.forEach(barangay => {
const option = new Option(barangay.name, barangay.code);
barangaySelect.append(option);
2024-02-12 10:35:09 +08:00
});
2024-05-30 10:03:49 +08:00
})
.catch(error => {
console.error('Error:', error);
});
}
});
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
$('#submitBtn').on('click', function() {
// Retrieve existing addresses from the API
// fetch('https://api.obanana.shop/api/v1/customers/65482e8d209ff8d348bd30fd')
console.log('clickkkkkkkk')
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/' +
customerId)
.then(response => response.json())
.then(data => {
// Get the existing addresses array
const existingAddresses = data.address || [];
// Get the new address details
const firstName = $('#addressFirstName').val();
const lastName = $('#addressLastName').val();
const contact = $('#addressContact').val();
const buildingNumber = $('#addressBuilding').val();
const street = $('#addressStreet').val();
const province = $('#provinceSelect :selected').text();
const city = $('#citySelect :selected').text();
const barangay = $('#barangaySelect :selected').text();
const country = $('#addressCountry').val();
// Create a new address object
const newAddress = {
first_name: firstName,
last_name: lastName,
phone: contact,
address_1: buildingNumber,
address_2: street,
city: city,
province: province,
barangay: barangay,
country: country,
};
// Add the new address to the existing addresses
existingAddresses.push(newAddress);
// Make a PATCH request to update the addresses array
return fetch(
'https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/' +
customerId, {
2024-02-12 10:35:09 +08:00
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
address: existingAddresses
}),
});
2024-05-30 10:03:49 +08:00
})
.then(response => {
if (response.ok) {
// Handle success (e.g., show a success message)
location.reload();
} else {
// Handle error
console.error('Failed to submit data');
alert('Failed to submit data');
}
})
.catch(error => {
// Handle network or other errors
console.error('Error:', error);
alert('Error submitting data');
});
});
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
});
2024-03-07 10:53:15 +08:00
2024-05-30 10:03:49 +08:00
// Added function for edit
$('#submitBtn2').on('click', function() {
2024-03-07 10:53:15 +08:00
// function updateAddress(){
// Retrieve existing addresses from the API
// fetch('https://api.obanana.shop/api/v1/customers/65482e8d209ff8d348bd30fd')
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/' + customerId)
.then(response => response.json())
.then(data => {
// Get the existing addresses array
const existingAddresses = data.address || [];
// Get the new address details
const firstName = $('#addressFirstName2').val();
const lastName = $('#addressLastName2').val();
const contact = $('#addressContact2').val();
const buildingNumber = $('#addressBuilding2').val();
const street = $('#addressStreet2').val();
const province = $('#provinceSelect2 :selected').text();
const city = $('#citySelect2 :selected').text();
const barangay = $('#barangaySelect2 :selected').text();
const country = $('#addressCountry2').val();
const id = $('#addressId').val();
2024-05-30 10:03:49 +08:00
console.log('clickkkkkkkk' + id)
2024-03-07 10:53:15 +08:00
// Create a new address object
const newAddress = {
first_name: firstName,
last_name: lastName,
phone: contact,
address_1: buildingNumber,
address_2: street,
city: city,
province: province,
barangay: barangay,
country: country,
};
// Add the new address to the existing addresses
// existingAddresses.push(newAddress);
2024-05-30 10:03:49 +08:00
// var newAddresses= existingAddresses.filter((e,i)=>i!==id)
2024-03-07 10:53:15 +08:00
let existingAddress = existingAddresses
2024-05-30 10:03:49 +08:00
existingAddress[id] = {
2024-03-07 10:53:15 +08:00
first_name: firstName,
last_name: lastName,
phone: contact,
address_1: buildingNumber,
address_2: street,
city: city,
province: province,
barangay: barangay,
country: country,
};
2024-05-30 10:03:49 +08:00
console.log(existingAddress[id])
2024-03-07 10:53:15 +08:00
// Make a PATCH request to update the addresses array
2024-05-30 10:03:49 +08:00
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/' +
customerId, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
address: existingAddress
}),
});
2024-03-07 10:53:15 +08:00
})
.then(response => {
if (response.ok) {
// Handle success (e.g., show a success message)
location.reload();
} else {
// Handle error
console.error('Failed to submit data');
alert('Failed to submit data');
}
})
.catch(error => {
// Handle network or other errors
console.error('Error:', error);
alert('Error submitting data');
});
});
2024-02-12 10:35:09 +08:00
</script>
<script>
2024-05-30 10:03:49 +08:00
async function updateAddressBilling(customerId, addressIndex, isBilling) {
try {
const apiUrl = `https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/${customerId}`;
const response = await fetch(apiUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
if (!response.ok) {
throw new Error(`Failed to fetch customer data: ${response.status}`);
}
// console.log(customerId + " ." + addressIndex + "." +isBilling + "." + isShipping)
const customerData = await response.json();
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
// Iterate through addresses and update billing/shipping flags
customerData.address.forEach((address, index) => {
if (index === addressIndex) {
if (isBilling !== undefined) {
address.billing = isBilling;
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
const radioButtonId = `#billing_address_${customerId}_${addressIndex}`;
$(radioButtonId).prop('checked', isBilling);
2024-02-12 10:35:09 +08:00
}
2024-05-30 10:03:49 +08:00
// if (isShipping !== undefined) {
// address.shipping = isShipping;
// }
} else {
// Set other addresses to false
address.billing = false;
// address.shipping = false;
2024-02-12 10:35:09 +08:00
}
2024-05-30 10:03:49 +08:00
});
// Send a PATCH request to update the customer data
const updateResponse = await fetch(apiUrl, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
address: customerData.address
}),
});
if (!updateResponse.ok) {
throw new Error(`Failed to update address: ${updateResponse.status}`);
2024-02-12 10:35:09 +08:00
}
const selectedBillingElement = document.getElementById('selectedBillingFName');
const selectedBillingLNameElement = document.getElementById('selectedBillingLName');
const selectedBillingContactElement = document.getElementById('selectedBillingContact');
const sBillingBuildingElement = document.getElementById('sBillingBuilding');
const sBillingStreetElement = document.getElementById('sBillingStreet');
const sBillingBarangayElement = document.getElementById('sBillingBarangay');
const sBillingCityElement = document.getElementById('sBillingCity');
const sBillingProvinceElement = document.getElementById('sBillingProvince');
const sBillingCountryElement = document.getElementById('sBillingCountry');
if (selectedBillingElement) {
selectedBillingElement.textContent = customerData.address[addressIndex].first_name;
selectedBillingLNameElement.textContent = customerData.address[addressIndex].last_name;
selectedBillingContactElement.textContent = 'Contact #: ' + customerData.address[addressIndex]
.phone;
sBillingBuildingElement.textContent = customerData.address[addressIndex].address_1;
sBillingStreetElement.textContent = customerData.address[addressIndex].address_2;
sBillingBarangayElement.textContent = customerData.address[addressIndex].barangay;
sBillingCityElement.textContent = customerData.address[addressIndex].city;
sBillingProvinceElement.textContent = customerData.address[addressIndex].province;
sBillingCountryElement.textContent = customerData.address[addressIndex].country;
2024-02-12 10:35:09 +08:00
}
2024-05-30 10:03:49 +08:00
console.log(`Address updated successfully for customer ${customerId}`);
} catch (error) {
console.error('Error updating address:', error.message);
2024-02-12 10:35:09 +08:00
}
2024-05-30 10:03:49 +08:00
}
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
async function updateAddressShipping(customerId, addressIndex, isShipping) {
try {
// const customerId = `<?php #echo $customer_data[0]['_id']; ?>`;
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
const apiUrl = `https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/${customerId}`;
const response = await fetch(apiUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
throw new Error(`Failed to fetch customer data: ${response.status}`);
}
// console.log(customerId + " ." + addressIndex + "." +isBilling + "." + isShipping)
const customerData = await response.json();
// Iterate through addresses and update billing/shipping flags
customerData.address.forEach((address, index) => {
if (index === addressIndex) {
// if (isBilling !== undefined) {
// address.billing = isBilling;
// }
if (isShipping !== undefined) {
address.shipping = isShipping;
2024-02-12 10:35:09 +08:00
}
2024-05-30 10:03:49 +08:00
} else {
// Set other addresses to false
// address.billing = false;
address.shipping = false;
}
});
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
// Send a PATCH request to update the customer data
const updateResponse = await fetch(apiUrl, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
address: customerData.address
}),
});
2024-02-12 10:35:09 +08:00
2024-05-30 10:03:49 +08:00
if (!updateResponse.ok) {
throw new Error(`Failed to update address: ${updateResponse.status}`);
}
const selectedShippingElement = document.getElementById('selectedFName');
const selectedLNameElement = document.getElementById('selectedLName');
const selectedContactElement = document.getElementById('selectedContact');
const sBuildingElement = document.getElementById('sBuilding');
const sStreetElement = document.getElementById('sStreet');
const sBarangayElement = document.getElementById('sBarangay');
const sCityElement = document.getElementById('sCity');
const sProvinceElement = document.getElementById('sProvince');
const sCountryElement = document.getElementById('sCountry');
if (selectedShippingElement) {
selectedShippingElement.textContent = customerData.address[addressIndex].first_name;
// Update other address details similarly
selectedLNameElement.textContent = customerData.address[addressIndex].last_name;
selectedContactElement.textContent = 'Contact #: ' + customerData.address[addressIndex].phone;
sBuildingElement.textContent = customerData.address[addressIndex].address_1;
sStreetElement.textContent = customerData.address[addressIndex].address_2;
sBarangayElement.textContent = customerData.address[addressIndex].barangay;
sCityElement.textContent = customerData.address[addressIndex].city;
sProvinceElement.textContent = customerData.address[addressIndex].province;
sCountryElement.textContent = customerData.address[addressIndex].country;
2024-02-12 10:35:09 +08:00
}
2024-05-30 10:03:49 +08:00
console.log(`Address updated successfully for customer ${customerId}`);
// location.reload();
// header("location: user-profile.php");
2024-05-30 10:03:49 +08:00
} catch (error) {
console.error('Error updating address:', error.message);
2024-02-12 10:35:09 +08:00
}
2024-05-30 10:03:49 +08:00
}
2024-02-12 10:35:09 +08:00
</script>
</section>
<!-- End User profile section -->
<!-- Footer Start -->
<?php include "footer.php" ?>
<!-- Footer Area End -->
<!-- Modal -->
<div class="modal fade" id="edit_modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="row">
<div class="ec-vendor-block-img space-bottom-30">
<div class="ec-vendor-block-bg cover-upload" style="background-color: orange;">
<div class="thumb-upload">
<!-- <div class="thumb-edit">
<input type='file' id="thumbUpload01" class="ec-image-upload"
accept=".png, .jpg, .jpeg" />
<label><i class="fi-rr-edit"></i></label>
</div> -->
<div class="thumb-preview ec-preview">
<div class="image-thumb-preview">
<!-- <img loading="lazy" class="image-thumb-preview ec-image-preview v-img" src=<?php echo $customer_data[0]['customer_image'] ?> alt="edit" /> -->
2024-02-12 10:35:09 +08:00
</div>
</div>
</div>
</div>
<div class="ec-vendor-block-detail">
<div class="thumb-upload">
<div class="thumb-edit">
2024-05-30 10:03:49 +08:00
<input type='file' id="imageUpload" class="ec-image-upload"
accept=".png, .jpg, .jpeg" onchange="uploadProfileImage()" />
2024-02-12 10:35:09 +08:00
<label><i class="fi-rr-edit"></i></label>
</div>
<div class="thumb-preview ec-preview">
<div class="image-thumb-preview">
<?php
$customer_image = isset($customer_data[0]['customer_image']) ? $customer_data[0]['customer_image'] : 'https://yourteachingmentor.com/wp-content/uploads/2020/12/istockphoto-1223671392-612x612-1.jpg';
?>
2024-05-30 10:03:49 +08:00
<img loading="lazy" class="image-thumb-preview ec-image-preview v-img"
src=<?php echo $customer_image ?> alt="edit" />
2024-02-12 10:35:09 +08:00
</div>
</div>
</div>
</div>
<script>
2024-05-30 10:03:49 +08:00
function uploadProfileImage() {
var customerId = '<?php echo $_SESSION['customerId'] ?>';
var file = document.getElementById('imageUpload').files[0];
if (file) {
var formData = new FormData();
formData.append('image_id', customerId);
formData.append('category', 'customer');
formData.append('image', file);
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/upload_image', {
method: 'POST',
body: formData
})
.then(response => {
if (response.ok) {
return response.json();
} else {
console.error('File upload failed');
throw new Error('File upload failed');
}
})
.then(result => {
const filename = result.filename;
const payload = {
customer_image: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/customer_uploads/${filename}`,
};
console.log('Payload:', payload);
return fetch(
'https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/' +
customerId, {
2024-02-12 10:35:09 +08:00
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
2024-05-30 10:03:49 +08:00
})
.then(secondResponse => {
if (secondResponse.ok) {
console.log('Image Uploaded Successful');
// location.reload();
} else {
console.error('Image Failed to Upload');
}
})
.catch(error => {
console.error('Error during fetch:', error);
});
2024-02-12 10:35:09 +08:00
}
2024-05-30 10:03:49 +08:00
}
2024-02-12 10:35:09 +08:00
</script>
2024-05-30 10:03:49 +08:00
<style>
.avatar {
text-align: center;
margin-bottom: 20px;
}
.avatar img {
width: 100px;
height: 100px;
border-radius: 50%;
}
.form-row {
display: flex;
justify-content: space-between;
margin-bottom: 15px;
}
.form-group {
flex: 1;
}
.form-group+.form-group {
margin-left: 10px;
}
.form-label {
display: block;
margin: 10px 0 5px;
font-weight: 500;
font-size: 14px;
text-align: left;
}
.form-control1 {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 15px !important;
}
.submit-button {
width: 100%;
padding: 10px 15px;
background-color: #ffaa00;
color: #fff;
border: none;
border-radius: 30px;
cursor: pointer;
font-size: 16px;
margin-top: 20px;
}
.submit-button:hover {
background-color: #e69900;
}
</style>
2024-02-12 10:35:09 +08:00
<div class="ec-vendor-upload-detail">
2024-05-30 10:03:49 +08:00
<form>
<!-- First Name and Last Name Row -->
<div class="form-row">
<div class="form-group">
<label for="first_name" class="form-label">First Name</label>
<input type="text" id="first_name-" name="first_name" class="form-control1"
value="<?php echo $customer_data[0]['first_name'] ?>">
</div>
<div class="form-group">
<label for="last_name" class="form-label">Last Name</label>
<input type="text" id="last_name-" name="last_name" class="form-control1"
value="<?php echo $customer_data[0]['last_name'] ?>">
</div>
2024-02-12 10:35:09 +08:00
</div>
2024-05-30 10:03:49 +08:00
<!-- Username and Contact Number Row -->
<div class="form-row">
<div class="form-group">
<label for="username" class="form-label">Username</label>
<input type="text" id="username-" name="username" class="form-control1"
value="<?php echo $customer_data[0]['user_login'] ?>">
</div>
<div class="form-group">
<label for="phone" class="form-label">Contact Number</label>
<input type="text" id="phone-" name="phone" class="form-control1"
value="<?php echo $customer_data[0]['phone_number'] ?>"
oninput="preventEraseInPrefix(this)">
</div>
2024-02-12 10:35:09 +08:00
</div>
2024-05-30 10:03:49 +08:00
<button type="submit" class="submit-button" onclick="editUser()">Submit</button>
2024-02-12 10:35:09 +08:00
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal end -->
<!-- Footer navigation panel for responsive display -->
2024-05-03 18:05:45 +08:00
<!-- <div class="ec-nav-toolbar">
2024-02-12 10:35:09 +08:00
<div class="container">
<div class="ec-nav-panel">
<div class="ec-nav-panel-icons">
<a href="#ec-mobile-menu" class="navbar-toggler-btn ec-header-btn ec-side-toggle"><i class="fi-rr-menu-burger"></i></a>
</div>
<div class="ec-nav-panel-icons">
<a href="#ec-side-cart" class="toggle-cart ec-header-btn ec-side-toggle"><i class="fi-rr-shopping-bag"></i><span class="ec-cart-noti ec-header-count cart-count-lable">3</span></a>
</div>
<div class="ec-nav-panel-icons">
<a href="index.php" class="ec-header-btn"><i class="fi-rr-home"></i></a>
</div>
<div class="ec-nav-panel-icons">
<a href="wishlist.html" class="ec-header-btn"><i class="fi-rr-heart"></i><span class="ec-cart-noti">4</span></a>
</div>
<div class="ec-nav-panel-icons">
<a href="login.php" class="ec-header-btn"><i class="fi-rr-user"></i></a>
</div>
</div>
</div>
2024-05-03 18:05:45 +08:00
</div> -->
2024-02-12 10:35:09 +08:00
<!-- Footer navigation panel for responsive display end -->
<!-- raymart remove popup feb 20 2024 -->
2024-02-12 10:35:09 +08:00
<!-- Recent Purchase Popup -->
<!-- <div class="recent-purchase">
<img loading="lazy" src="assets/images/product-image/1.jpg" alt="payment image">
2024-02-12 10:35:09 +08:00
<div class="detail">
<p>Someone in new just bought</p>
<h6>stylish baby shoes</h6>
<p>10 Minutes ago</p>
</div>
<a href="javascript:void(0)" class="icon-btn recent-close">×</a>
</div> -->
2024-02-12 10:35:09 +08:00
<!-- Recent Purchase Popup end -->
<!-- Cart Floating Button -->
<div class="ec-cart-float">
<a href="#ec-side-cart" class="ec-header-btn ec-side-toggle">
<div class="header-icon"><i class="fi-rr-shopping-basket"></i>
</div>
<span class="ec-cart-count cart-count-lable">3</span>
</a>
</div>
<!-- Cart Floating Button end -->
2024-05-30 10:03:49 +08:00
2024-02-12 10:35:09 +08:00
<!-- Feature tools -->
<div class="ec-tools-sidebar-overlay"></div>
<div class="ec-tools-sidebar">
<div class="tool-title">
<h3>Features</h3>
</div>
<a href="#" class="ec-tools-sidebar-toggle in-out">
<img loading="lazy" alt="icon" src="assets/images/common/settings.png" />
2024-02-12 10:35:09 +08:00
</a>
<div class="ec-tools-detail">
<div class="ec-tools-sidebar-content ec-change-color ec-color-desc">
<h3>Color Scheme</h3>
<ul class="bg-panel">
<li class="active" data-color="01"><a href="#" class="colorcode1"></a></li>
<li data-color="02"><a href="#" class="colorcode2"></a></li>
<li data-color="03"><a href="#" class="colorcode3"></a></li>
<li data-color="04"><a href="#" class="colorcode4"></a></li>
<li data-color="05"><a href="#" class="colorcode5"></a></li>
</ul>
</div>
<div class="ec-tools-sidebar-content">
<h3>Backgrounds</h3>
<ul class="bg-panel">
<li class="bg"><a class="back-bg-1" id="bg-1">Background-1</a></li>
<li class="bg"><a class="back-bg-2" id="bg-2">Background-2</a></li>
<li class="bg"><a class="back-bg-3" id="bg-3">Background-3</a></li>
<li class="bg"><a class="back-bg-4" id="bg-4">Default</a></li>
</ul>
</div>
<div class="ec-tools-sidebar-content">
<h3>Full Screen mode</h3>
<div class="ec-fullscreen-mode">
<div class="ec-fullscreen-switch">
<div class="ec-fullscreen-btn">Mode</div>
<div class="ec-fullscreen-on">On</div>
<div class="ec-fullscreen-off">Off</div>
</div>
</div>
</div>
<div class="ec-tools-sidebar-content">
<h3>Dark mode</h3>
<div class="ec-change-mode">
<div class="ec-mode-switch">
<div class="ec-mode-btn">Mode</div>
<div class="ec-mode-on">On</div>
<div class="ec-mode-off">Off</div>
</div>
</div>
</div>
<div class="ec-tools-sidebar-content">
<h3>RTL mode</h3>
<div class="ec-change-rtl">
<div class="ec-rtl-switch">
<div class="ec-rtl-btn">Rtl</div>
<div class="ec-rtl-on">On</div>
<div class="ec-rtl-off">Off</div>
</div>
</div>
</div>
<div class="ec-tools-sidebar-content">
<h3>Clear local storage</h3>
<a class="clear-cach" href="javascript:void(0)">Clear Cache & Default</a>
</div>
</div>
</div>
<!-- Feature tools end -->
<!-- Vendor JS -->
<!-- <script src="assets/js/vendor/jquery-3.5.1.min.js"></script> -->
<script src="assets/js/vendor/popper.min.js"></script>
<script src="assets/js/vendor/bootstrap.min.js"></script>
<script src="assets/js/vendor/jquery-migrate-3.3.0.min.js"></script>
<script src="assets/js/vendor/modernizr-3.11.2.min.js"></script>
<!--Plugins JS-->
<script src="assets/js/plugins/swiper-bundle.min.js"></script>
<script src="assets/js/plugins/countdownTimer.min.js"></script>
<script src="assets/js/plugins/scrollup.js"></script>
<script src="assets/js/plugins/jquery.zoom.min.js"></script>
<script src="assets/js/plugins/slick.min.js"></script>
<script src="assets/js/plugins/infiniteslidev2.js"></script>
<script src="assets/js/vendor/jquery.magnific-popup.min.js"></script>
<script src="assets/js/plugins/jquery.sticky-sidebar.js"></script>
<script src="assets/js/plugins/nouislider.js"></script>
<!-- Main Js -->
<script src="assets/js/vendor/index.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>