<?php

include('nav-master.php');
include('response.php');








?>

<div style="margin-top: 15px; padding-left: 12px; "  class="hp-main-layout-content">
<div class="row mb-32 gy-32">
				<div class="col-12">
        <div class="page-header-modern">
            <h2 class="header-modern">Master</h2>

    <div class="user-dropdown dropdown">
        <button class="btn btn-user" type="button" data-toggle="dropdown">
            <i class=""></i>
             <img src="images/icon/invoice360-user.png" height=30px; width=30px;>
            <span class="caret"></span>
        </button>

        <ul class="dropdown-menu user-menu" aria-labelledby="userDropdown">
            <li>
                <a class="dropdown-item" href="">
                    <i class="fa fa-user me-2"></i> <?php echo strtok($_SESSION['user_name'], ' ');?> (<?php echo $_SESSION['role']; ?>)
                </a>
            </li>

            <li>
                <a class="dropdown-item" href="Admin/payment-details.php">
                    <i class="fa fa-credit-card"></i> Billing history
                </a>
            </li>

            <li>
                <a class="dropdown-item" href="Admin/company-profile.php">
                    <i class="fa fa-cog me-2"></i> Settings
                </a>
            </li>

            <li><hr class="dropdown-divider"></li>

            <li>
                <a class="dropdown-item text-danger" href="logout.php">
                    <i class="fa fa-sign-out me-2"></i> Sign Out
                </a>
            </li>
        </ul>
        </div>
    </div>
</div>


				
            <div class="col-lg-12">
                <div class="card">
                    
                            
        <div class="card-body">
		<!-- <hr> -->

		<div id="response" class="alert alert-success" style="display:none;">
			<a href="#" class="close" data-dismiss="alert">&times;</a>
			<div class="message"></div>
		</div>

						
<?php


$company_id = (int) ($_GET['id'] ?? 0);
if ($company_id <= 0) die("Invalid company");

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    $plan  = $_POST['plan'];
    $days  = (int) $_POST['days'];

    $stmt = $conn->prepare("
        UPDATE subscriptions
        SET 
            plan = ?,
            status = 'active',
            started_at = NOW(),
            ends_at = DATE_ADD(NOW(), INTERVAL ? DAY)
        WHERE company_id = ?
    ");
    $stmt->bind_param("sii", $plan, $days, $company_id);
    $stmt->execute();

    header("Location: company-subscriptions.php?override=1");
    exit;
}
?>



<h4>Admin Subscription Override</h4>

<form method="post">
    <div class="mb-3">
        <label>Plan</label>
        <select name="plan" class="form-control" required>
            <option value="monthly">Monthly</option>
            <option value="annual">Annual</option>
            <option value="lifetime">Lifetime</option>
        </select>
    </div>

    <div class="mb-3">
        <label>Duration (days)</label>
        <input type="number" name="days" class="form-control" value="30" required>
    </div>

    <button class="btn btn-success">Apply Override</button>
    <a href="company-subscriptions.php" class="btn btn-secondary">Cancel</a>
</form>








                                    
                                   

		


		
             
		
 <!-- Plugin -->
 	
 	
    <script src="app-assets/js/plugin/swiper-bundle.min.js"></script>
    <script src="app-assets/js/plugin/jquery.mask.min.js"></script>
    <script src="app-assets/js/plugin/autocomplete.min.js"></script>
    <script src="app-assets/js/plugin/moment.min.js"></script>

    <!-- Layouts -->
    <script src="app-assets/js/layouts/header-search.js"></script>
    <script src="app-assets/js/layouts/sider.js"></script>
    <script src="app-assets/js/components/input-number.js"></script>

    <!-- Base -->
    <script src="app-assets/js/base/index.js"></script>
    <!-- Customizer -->
    <script src="app-assets/js/customizer.js"></script>

    <!-- Charts -->
    <script src="app-assets/js/plugin/apexcharts.min.js"></script>
    <script src="app-assets/js/charts/apex-chart.js"></script>

    <!-- Cards -->
    <script src="app-assets/js/cards/card-advance.js"></script>
    <script src="app-assets/js/cards/card-analytic.js"></script>
    <script src="app-assets/js/cards/card-statistic.js"></script>

    <!-- Pages -->
    <script src="app-assets/js/pages/dashboard-ecommerce.js"></script>

    <!-- Custom -->
    <script src="assets/js/main.js"></script>  
	
	
	<script> 
	const textarea = document.getElementById('auto-resize-textarea');

textarea.addEventListener('input', () => {
  textarea.style.height = 'auto'; // Reset height to recalculate
  textarea.style.height = textarea.scrollHeight + 'px'; // Set height based on scrollHeight
});

// Optional: Initial resize if content is pre-filled
textarea.style.height = 'auto';
textarea.style.height = textarea.scrollHeight + 'px';
</script>
</body>


</html>