/
home
/
u775757334
/
domains
/
civicwelllife.com
/
public_html
/
seller
/
function
/
/home/u775757334/domains/civicwelllife.com/public_html/seller/function
mkdir
upload
Name
Size
Mode
Actions
ajax_function.php
13392
0644
edit
dl
rm
custum.css
10832
0644
edit
dl
rm
custum.js
4159
0644
edit
dl
rm
Edit:
/home/u775757334/domains/civicwelllife.com/public_html/seller/function/ajax_function.php
(13392B)
<?php include('../config.php'); if (!isset($conn)) { $response['status'] = 'error'; $response['message'] = 'Database connection failed.'; echo json_encode($response); exit; } $response = array(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $case = $_POST['case']; switch ($case) { case 'loginSeller': loginSeller($conn); break; case 'saveSellerProduct': saveSellerProduct($conn); break; case 'deleteData1': deleteData1($conn); break; case 'saveSellerProfile': saveSellerProfile($conn); break; default: $response['status'] = 'error'; $response['message'] = 'Invalid case'; echo json_encode($response); break; } } else { $response['status'] = 'error'; $response['message'] = 'Invalid request method'; echo json_encode($response); } function loginSeller($conn) { header('Content-Type: application/json'); $login_id = trim($_POST['login_id'] ?? ''); $password = trim($_POST['password'] ?? ''); if ($login_id == '' || $password == '') { echo json_encode([ 'status' => 0, 'msg' => 'Please enter email/phone and password.' ]); exit; } $stmt = mysqli_prepare($conn, "SELECT id, company_name, brand_name, contact_person_name, email_id, phone_number, status, seller_password FROM tbl_seller_registration WHERE (email_id = ? OR phone_number = ?) LIMIT 1"); mysqli_stmt_bind_param($stmt, "ss", $login_id, $login_id); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); if ($row = mysqli_fetch_assoc($result)) { // 🔥 STATUS CHECK (More Controlled) if ($row['status'] == 0) { echo json_encode([ 'status' => 0, 'msg' => 'Your seller account is pending approval.' ]); exit; } if ($row['status'] == 2) { echo json_encode([ 'status' => 0, 'msg' => 'Your seller account has been rejected. Contact admin.' ]); exit; } if ($row['status'] != 1) { echo json_encode([ 'status' => 0, 'msg' => 'Your account is inactive. Please contact support.' ]); exit; } // 🔐 Password check if (empty($row['seller_password'])) { echo json_encode([ 'status' => 0, 'msg' => 'Password is not set for this seller account.' ]); exit; } if (md5($password) !== $row['seller_password']) { echo json_encode([ 'status' => 0, 'msg' => 'Invalid login credentials.' ]); exit; } // ✅ SESSION SET $_SESSION['seller_id'] = $row['id']; $_SESSION['seller_company_name'] = $row['company_name']; $_SESSION['seller_brand_name'] = $row['brand_name']; $_SESSION['seller_name'] = $row['contact_person_name']; $_SESSION['seller_email'] = $row['email_id']; $_SESSION['seller_phone'] = $row['phone_number']; echo json_encode([ 'status' => 1, 'msg' => 'Login successful.', 'redirect' => 'dashboard.php' ]); exit; } echo json_encode([ 'status' => 0, 'msg' => 'Seller account not found.' ]); exit; } function saveSellerProduct($conn) { header('Content-Type: application/json'); if (!isset($_SESSION['seller_id'])) { echo json_encode(['status' => 0, 'msg' => 'Please login first.']); exit; } $seller_id = (int)$_SESSION['seller_id']; $product_id = (int)($_POST['product_id'] ?? 0); $category_id = trim($_POST['category_id'] ?? ''); $product_size = trim($_POST['product_size'] ?? ''); $color = trim($_POST['color'] ?? ''); $sku = trim($_POST['sku'] ?? ''); $name = trim($_POST['name'] ?? ''); $url = trim($_POST['url'] ?? ''); $mrp = trim($_POST['mrp'] ?? 0); $sale_price = trim($_POST['sale_price'] ?? 0); $point = trim($_POST['point'] ?? 0); $short_description = trim($_POST['short_description'] ?? ''); $full_description = trim($_POST['full_description'] ?? ''); $meta_title = trim($_POST['meta_title'] ?? ''); $show_home = trim($_POST['show_home'] ?? 0); $meta_keyword = trim($_POST['meta_keyword'] ?? ''); $meta_description = trim($_POST['meta_description'] ?? ''); $shipping_charge = trim($_POST['shipping_charge'] ?? 0); $status = trim($_POST['status'] ?? 1); $ingredieants = trim($_POST['ingredieants'] ?? ''); $usages = trim($_POST['usages'] ?? ''); $brand_id = trim($_POST['brand_id'] ?? ''); if ($category_id == '' || $name == '' || $url == '') { echo json_encode(['status' => 0, 'msg' => 'Please fill required fields.']); exit; } $upload_dir = "../../media/image/"; if (!is_dir($upload_dir)) { mkdir($upload_dir, 0777, true); } $thumb_dir = "../../media/image/thumb/"; if (!is_dir($thumb_dir)) { mkdir($thumb_dir, 0777, true); } $images = []; $thumbs = []; for ($i = 1; $i <= 6; $i++) { $images[$i] = $_POST['old_image' . $i] ?? ''; $thumbs[$i] = $_POST['old_thumb' . $i] ?? ''; if (!empty($_FILES['image' . $i]['name'])) { $ext = pathinfo($_FILES['image' . $i]['name'], PATHINFO_EXTENSION); $fileName = time() . '_' . $i . '_' . rand(1000, 9999) . '.' . $ext; $mainPath = $upload_dir . $fileName; $thumbPath = $thumb_dir . $fileName; // Upload main image move_uploaded_file($_FILES['image' . $i]['tmp_name'], $mainPath); // Copy to thumb folder copy($mainPath, $thumbPath); $images[$i] = $fileName; $thumbs[$i] = $fileName; } } if ($product_id > 0) { $check = mysqli_query($conn, "SELECT id FROM tbl_product WHERE id = '$product_id' AND seller_id = '$seller_id' LIMIT 1"); if (!$check || mysqli_num_rows($check) == 0) { echo json_encode(['status' => 0, 'msg' => 'Invalid product.']); exit; } $sql = "UPDATE tbl_product SET category_id='$category_id', product_size='$product_size', color='$color', sku='$sku', name='$name', url='$url', mrp='$mrp', sale_price='$sale_price', point='$point', short_description='$short_description', full_description='$full_description', meta_title='$meta_title', show_home='$show_home', meta_keyword='$meta_keyword', meta_description='$meta_description', shipping_charge='$shipping_charge', status='$status', image1='{$images[1]}', image2='{$images[2]}', image3='{$images[3]}', image4='{$images[4]}', image5='{$images[5]}', image6='{$images[6]}', thumb1='{$thumbs[1]}', thumb2='{$thumbs[2]}', thumb3='{$thumbs[3]}', thumb4='{$thumbs[4]}', thumb5='{$thumbs[5]}', thumb6='{$thumbs[6]}', ingredieants='$ingredieants', usages='$usages', brand_id='$brand_id' WHERE id='$product_id' AND seller_id='$seller_id'"; if (mysqli_query($conn, $sql)) { echo json_encode(['status' => 1, 'msg' => 'Product updated successfully.']); } else { echo json_encode(['status' => 0, 'msg' => 'Update failed.']); } exit; } $sql = "INSERT INTO tbl_product (seller_id, category_id, product_size, color, sku, name, url, mrp, sale_price, point, short_description, full_description, meta_title, show_home, meta_keyword, meta_description, shipping_charge, status, image1, image2, image3, image4, image5, image6, ingredieants, usages, brand_id,thumb1, thumb2, thumb3, thumb4, thumb5, thumb6) VALUES ('$seller_id', '$category_id', '$product_size', '$color', '$sku', '$name', '$url', '$mrp', '$sale_price', '$point', '$short_description', '$full_description', '$meta_title', '$show_home', '$meta_keyword', '$meta_description', '$shipping_charge', '$status', '{$images[1]}', '{$images[2]}', '{$images[3]}', '{$images[4]}', '{$images[5]}', '{$images[6]}', '$ingredieants', '$usages', '$brand_id','{$thumbs[1]}','{$thumbs[2]}','{$thumbs[3]}','{$thumbs[4]}','{$thumbs[5]}','{$thumbs[6]}')"; if (mysqli_query($conn, $sql)) { echo json_encode(['status' => 1, 'msg' => 'Product added successfully.']); } else { echo json_encode(['status' => 0, 'msg' => 'Insert failed.']); } exit; } function deleteData1($conn) { $table = $_POST['table']; $id = $_POST['id']; if (empty($table) || empty($id)) { echo json_encode(['status' => 0, 'msg' => 'Invalid request']); exit; } $sql = "DELETE FROM $table WHERE id='$id'"; if (mysqli_query($conn, $sql)) { echo json_encode(['status' => 1, 'msg' => 'Deleted Successfully']); } else { echo json_encode(['status' => 0, 'msg' => mysqli_error($conn)]); } exit; } function saveSellerProfile($conn) { header('Content-Type: application/json'); if (!isset($_SESSION['seller_id'])) { echo json_encode(['status' => 0, 'msg' => 'Please login first.']); exit; } $seller_id = (int)$_SESSION['seller_id']; $company_name = trim($_POST['company_name'] ?? ''); $brand_name = trim($_POST['brand_name'] ?? ''); $gst_number = trim($_POST['gst_number'] ?? ''); $license_number = trim($_POST['license_number'] ?? ''); $pan_number = trim($_POST['pan_number'] ?? ''); $company_address = trim($_POST['company_address'] ?? ''); $contact_person_name = trim($_POST['contact_person_name'] ?? ''); $phone_number = trim($_POST['phone_number'] ?? ''); $email_id = trim($_POST['email_id'] ?? ''); $bank_name = trim($_POST['bank_name'] ?? ''); $account_holder_name = trim($_POST['account_holder_name'] ?? ''); $account_number = trim($_POST['account_number'] ?? ''); $ifsc_code = trim($_POST['ifsc_code'] ?? ''); $logistics_type = trim($_POST['logistics_type'] ?? 'self_shipping'); $seller_password = trim($_POST['seller_password'] ?? ''); if ( $company_name == '' || $brand_name == '' || $contact_person_name == '' || $phone_number == '' || $email_id == '' ) { echo json_encode(['status' => 0, 'msg' => 'Please fill required fields.']); exit; } if (!filter_var($email_id, FILTER_VALIDATE_EMAIL)) { echo json_encode(['status' => 0, 'msg' => 'Please enter valid email address.']); exit; } $check = mysqli_query($conn, "SELECT id FROM tbl_seller_registration WHERE (email_id = '$email_id' OR phone_number = '$phone_number') AND id != '$seller_id' LIMIT 1"); if ($check && mysqli_num_rows($check) > 0) { echo json_encode(['status' => 0, 'msg' => 'Email or phone already used by another seller.']); exit; } $password_sql = ""; if ($seller_password != '') { $new_pass = md5($seller_password); $password_sql = ", seller_password='$new_pass'"; } $sql = "UPDATE tbl_seller_registration SET company_name='$company_name', brand_name='$brand_name', gst_number='$gst_number', license_number='$license_number', pan_number='$pan_number', company_address='$company_address', contact_person_name='$contact_person_name', phone_number='$phone_number', email_id='$email_id', bank_name='$bank_name', account_holder_name='$account_holder_name', account_number='$account_number', ifsc_code='$ifsc_code', logistics_type='$logistics_type' $password_sql WHERE id='$seller_id'"; if (mysqli_query($conn, $sql)) { $_SESSION['seller_company_name'] = $company_name; $_SESSION['seller_brand_name'] = $brand_name; $_SESSION['seller_name'] = $contact_person_name; $_SESSION['seller_email'] = $email_id; $_SESSION['seller_phone'] = $phone_number; echo json_encode(['status' => 1, 'msg' => 'Profile updated successfully.']); } else { echo json_encode(['status' => 0, 'msg' => 'Profile update failed.']); } exit; }
Save
cmd:
run