<?php
/* Smarty version 4.3.1, created on 2025-09-17 17:16:57
  from '/var/www/html/yatmack/ui/ui/plan.tpl' */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.3.1',
  'unifunc' => 'content_68cac2d9726574_68884552',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '6be11145f2e44fb62e85b7f62586d0954f7edb37' => 
    array (
      0 => '/var/www/html/yatmack/ui/ui/plan.tpl',
      1 => 1758036051,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
    'file:sections/header.tpl' => 1,
    'file:pagination.tpl' => 1,
    'file:sections/footer.tpl' => 1,
  ),
),false)) {
function content_68cac2d9726574_68884552 (Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_subTemplateRender("file:sections/header.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), 0, false);
?>
            <div class="container-fluid">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="card card-hovered mb20 card-primary">
                            <div class="card-header">
                                <h3 class="card-title">Plans</h3>
                                <?php if (in_array($_smarty_tpl->tpl_vars['_admin']->value['user_type'],array('SuperAdmin','Admin'))) {?>
                                    <div>
                                        <div class="btn-group pull-right">
                                            <a class="btn btn-primary" title="save" href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/sync"
                                                onclick="return confirm('This will sync/send Caustomer active plan to Mikrotik?')"><span
                                                    class="fa fa-refresh" aria-hidden="true"></span> sync</a>
                                        </div>
                                        <div class="btn-group pull-right">
                                            <a class="btn btn-info" title="save" href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
customers/csv"
                                                onclick="return confirm('This will export to CSV?')"><span class="fa fa-download"
                                                    aria-hidden="true"></span> CSV</a>
                                        </div>
                                    </div>
                                <?php }?>
                                &nbsp;
                            </div>
                            <div class="card-body">
                                <div class="md-whiteframe-z1 mb20 text-center row">
                                    <div class="col-md-8 mb-3">
                                        <form id="site-search" method="post" action="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/list/">
                                            <div class="input-group">
                                                <div class="input-group-text">
                                                    <span class="fa fa-search"></span>
                                                </div>
                                                <input type="text" name="search" class="form-control"
                                                    placeholder="<?php echo Lang::T('Search by Username');?>
..." value="<?php echo $_smarty_tpl->tpl_vars['search']->value;?>
">
                                                <button class="btn btn-success input-group-btn" type="submit"><?php echo Lang::T('Search');?>
</button>
                                                <!-- <div class="input-group-btn">
                                                </div> -->
                                            </div>
                                        </form>
                                    </div>
                                    <div class="col-md-4">
                                        <a href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/recharge" class="btn btn-primary btn-block"><i
                                                class="fa fa-add"> </i> <?php echo Lang::T('Recharge Account');?>
</a>
                                    </div>&nbsp;
                                </div>
                                <div class="table-responsive">
                                    <table id="datatable" class="table table-bordered table-striped table-condensed table-hover border-primary">
                                        <thead>
                                            <tr>
                                                <th><?php echo Lang::T('Username');?>
</th>
                                                <th><?php echo Lang::T('Plan Name');?>
</th>
                                                <th><?php echo Lang::T('Plan Type');?>
</th>
                                                <th><?php echo Lang::T('Created On');?>
</th>
                                                <th><?php echo Lang::T('Expires On');?>
</th>
                                                <th><?php echo Lang::T('Status');?>
</th>
                                                <th><?php echo Lang::T('Time Left');?>
</th>
                                                <th><?php echo Lang::T('Method');?>
</th>
                                                <th><?php echo Lang::T('Routers');?>
</th>
                                                <th><?php echo Lang::T('Manage');?>
</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['d']->value, 'ds');
$_smarty_tpl->tpl_vars['ds']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['ds']->value) {
$_smarty_tpl->tpl_vars['ds']->do_else = false;
?>
                                                
                                                <tr <?php if ($_smarty_tpl->tpl_vars['ds']->value['is_off']) {?>class="danger" <?php } elseif ($_smarty_tpl->tpl_vars['ds']->value['is_suspended']) {?>class="warning" <?php }?>>
                                                    <td><a href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
customers/viewu/<?php echo $_smarty_tpl->tpl_vars['ds']->value['username'];?>
"><?php echo $_smarty_tpl->tpl_vars['ds']->value['username'];?>
</a></td>
                                                    <td><?php echo $_smarty_tpl->tpl_vars['ds']->value['namebp'];?>
</td>
                                                    <td><?php echo $_smarty_tpl->tpl_vars['ds']->value['type'];?>
</td>
                                                    <td><?php echo Lang::dateAndTimeFormat($_smarty_tpl->tpl_vars['ds']->value['recharged_on'],$_smarty_tpl->tpl_vars['ds']->value['recharged_time']);?>
</td>
                                                    <td><?php echo Lang::dateAndTimeFormat($_smarty_tpl->tpl_vars['ds']->value['expiration'],$_smarty_tpl->tpl_vars['ds']->value['time']);?>
</td>
                                                    <td>
                                                        <?php if ($_smarty_tpl->tpl_vars['ds']->value['is_active']) {?>
                                                            <span class="badge badge-success">Active</span>
                                                        <?php } elseif ($_smarty_tpl->tpl_vars['ds']->value['is_suspended'] && $_smarty_tpl->tpl_vars['ds']->value['is_expired']) {?>
                                                            <span class="badge badge-warning">Suspended</span>
                                                        <?php } elseif ($_smarty_tpl->tpl_vars['ds']->value['is_suspended'] && !$_smarty_tpl->tpl_vars['ds']->value['is_expired']) {?>
                                                            <span class="badge badge-info">Suspending</span>
                                                        <?php } else { ?>
                                                            <span class="badge badge-danger">Inactive</span>
                                                        <?php }?>
                                                    </td>
                                                    <td>
                                                        <?php if ($_smarty_tpl->tpl_vars['ds']->value['is_suspended'] && !$_smarty_tpl->tpl_vars['ds']->value['is_expired']) {?>
                                                            <span class="text-warning" id="countdown-<?php echo $_smarty_tpl->tpl_vars['ds']->value['id'];?>
">
                                                                <i class="fa fa-clock-o"></i> <span id="minutes-<?php echo $_smarty_tpl->tpl_vars['ds']->value['id'];?>
">Calculating...</span>
                                                            </span>
                                                        <?php } elseif ($_smarty_tpl->tpl_vars['ds']->value['is_expired']) {?>
                                                            <span class="text-danger">Expired</span>
                                                        <?php } else { ?>
                                                            <span class="text-muted">-</span>
                                                        <?php }?>
                                                    </td>
                                                    <td><?php echo $_smarty_tpl->tpl_vars['ds']->value['method'];?>
</td>
                                                    <td><?php echo $_smarty_tpl->tpl_vars['ds']->value['routers'];?>
</td>
                                                    <td>
                                                        <a href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/edit/<?php echo $_smarty_tpl->tpl_vars['ds']->value['id'];?>
"
                                                            class="btn btn-warning btn-xs mb-1"><?php echo Lang::T('Edit');?>
</a>
                                                        <?php if (!$_smarty_tpl->tpl_vars['ds']->value['is_off'] && !($_smarty_tpl->tpl_vars['ds']->value['is_suspended'] && $_smarty_tpl->tpl_vars['ds']->value['is_expired'])) {?>
                                                            <button type="button" class="btn btn-warning btn-xs mb-1" 
                                                                onclick="showSuspendModal(<?php echo $_smarty_tpl->tpl_vars['ds']->value['id'];?>
, '<?php echo $_smarty_tpl->tpl_vars['ds']->value['username'];?>
')"
                                                                title="<?php echo Lang::T('Suspend Customer');?>
">
                                                                <i class="fa fa-pause"></i> <?php echo Lang::T('Suspend');?>

                                                            </button>
                                                        <?php } elseif ($_smarty_tpl->tpl_vars['ds']->value['is_suspended'] && $_smarty_tpl->tpl_vars['ds']->value['is_expired']) {?>
                                                            <span class="btn btn-secondary btn-xs mb-1 disabled">
                                                                <i class="fa fa-pause"></i> <?php echo Lang::T('Suspended');?>

                                                            </span>
                                                        <?php } else { ?>
                                                            <span class="btn btn-secondary btn-xs mb-1 disabled">
                                                                <i class="fa fa-ban"></i> <?php echo Lang::T('Inactive');?>

                                                            </span>
                                                        <?php }?>
                                                        <a href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/recharge/<?php echo $_smarty_tpl->tpl_vars['ds']->value['customer_id'];?>
" 
                                                            class="btn btn-success btn-xs mb-1" 
                                                            title="<?php echo Lang::T('Recharge Customer');?>
">
                                                            <i class="fa fa-refresh"></i> <?php echo Lang::T('Recharge');?>

                                                        </a>
                                                        <?php if (in_array($_smarty_tpl->tpl_vars['_admin']->value['user_type'],array('SuperAdmin','Admin'))) {?>
                                                            <a href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/delete/<?php echo $_smarty_tpl->tpl_vars['ds']->value['id'];?>
" id="<?php echo $_smarty_tpl->tpl_vars['ds']->value['id'];?>
"
                                                                onclick="return confirm('<?php echo Lang::T('Delete');?>
?')"
                                                                class="btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>
                                                        <?php }?>
                                                    </td>
                                                </tr>
                                            <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                                        </tbody>
                                    </table>
                                </div>
                                <?php $_smarty_tpl->_subTemplateRender("file:pagination.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), 0, false);
?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Suspend Confirmation Modal -->
            <div class="modal fade" id="suspendModal" tabindex="-1" role="dialog" aria-labelledby="suspendModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="suspendModalLabel"><?php echo Lang::T('Suspend Customer');?>
</h5>
                            <button type="button" class="close" onclick="closeSuspendModal()" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <form id="suspendForm" method="post" action="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/suspend-confirm">
                            <div class="modal-body">
                                <input type="hidden" id="suspend_customer_id" name="id" value="">
                                <div class="form-group">
                                    <label for="customer_name"><?php echo Lang::T('Customer');?>
:</label>
                                    <input type="text" class="form-control" id="customer_name" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="suspension_date"><?php echo Lang::T('Suspension Date');?>
:</label>
                                    <input type="date" class="form-control" id="suspension_date" name="suspension_date" required>
                                </div>
                                <div class="form-group">
                                    <label for="suspension_time"><?php echo Lang::T('Suspension Time');?>
:</label>
                                    <input type="time" class="form-control" id="suspension_time" name="suspension_time" required>
                                </div>
                                <div class="alert alert-info">
                                    <i class="fa fa-info-circle"></i> <?php echo Lang::T('The customer will be suspended at the specified date and time.');?>

                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-secondary" onclick="closeSuspendModal()"><?php echo Lang::T('Cancel');?>
</button>
                                <button type="submit" class="btn btn-warning"><?php echo Lang::T('Suspend Customer');?>
</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

            <!-- Recharge Modal - Removed as recharge now navigates to dedicated page -->

            
            <?php echo '<script'; ?>
>
                // Recharge Modal - Removed as recharge now navigates to dedicated page



                // Recharge modal functions removed as recharge now navigates to dedicated page

                function showSuspendModal(customerId, customerName) {
                    document.getElementById('suspend_customer_id').value = customerId;
                    document.getElementById('customer_name').value = customerName;
                    
                    // Set default date and time (6 minutes from now)
                    var now = new Date();
                    now.setMinutes(now.getMinutes() + 6);
                    
                    var dateStr = now.toISOString().split('T')[0];
                    var timeStr = now.toTimeString().split(' ')[0].substring(0, 5);
                    
                    document.getElementById('suspension_date').value = dateStr;
                    document.getElementById('suspension_time').value = timeStr;
                    
                    // Show modal using both jQuery and vanilla JS for compatibility
                    if (typeof $ !== 'undefined' && $.fn.modal) {
                        $('#suspendModal').modal('show');
                    } else {
                        // Fallback for vanilla JS
                        var modal = document.getElementById('suspendModal');
                        modal.style.display = 'block';
                        modal.classList.add('show');
                        document.body.classList.add('modal-open');
                        
                        // Add backdrop
                        var backdrop = document.createElement('div');
                        backdrop.className = 'modal-backdrop fade show';
                        backdrop.id = 'modal-backdrop';
                        document.body.appendChild(backdrop);
                    }
                }
                
                function closeSuspendModal() {
                    // Close modal using both jQuery and vanilla JS for compatibility
                    if (typeof $ !== 'undefined' && $.fn.modal) {
                        $('#suspendModal').modal('hide');
                    } else {
                        // Fallback for vanilla JS
                        var modal = document.getElementById('suspendModal');
                        modal.style.display = 'none';
                        modal.classList.remove('show');
                        document.body.classList.remove('modal-open');
                        
                        // Remove backdrop
                        var backdrop = document.getElementById('modal-backdrop');
                        if (backdrop) {
                            backdrop.remove();
                        }
                    }
                }
                
                // Close modal when clicking outside of it
                document.addEventListener('click', function(event) {
                    var modal = document.getElementById('suspendModal');
                    if (event.target === modal) {
                        closeSuspendModal();
                    }
                });
                
                // Close modal with Escape key
                document.addEventListener('keydown', function(event) {
                    if (event.key === 'Escape') {
                        var modal = document.getElementById('suspendModal');
                        if (modal.classList.contains('show')) {
                            closeSuspendModal();
                        }
                    }
                });





                // Countdown timer for suspended users
                function updateCountdowns() {
                    var now = new Date().getTime();
                    var hasExpired = false;
                    
                    document.querySelectorAll('[id^="countdown-"]').forEach(function(element) {
                        var customerId = element.id.replace('countdown-', '');
                        var minutesElement = document.getElementById('minutes-' + customerId);
                        
                        if (minutesElement) {
                            // Get expiry time from the table row
                            var row = element.closest('tr');
                            var expiryCell = row.querySelector('td:nth-child(5)'); // Expires On column
                            var expiryText = expiryCell.textContent.trim();
                            
                            // Parse the expiry date and time
                            var expiryDate = new Date(expiryText);
                            
                            if (!isNaN(expiryDate.getTime())) {
                                var timeLeft = expiryDate.getTime() - now;
                                
                                if (timeLeft > 0) {
                                    var minutes = Math.floor(timeLeft / (1000 * 60));
                                    var hours = Math.floor(minutes / 60);
                                    var days = Math.floor(hours / 24);
                                    
                                    var displayText = '';
                                    if (days > 0) {
                                        displayText = days + 'd ' + (hours % 24) + 'h ' + (minutes % 60) + 'm';
                                    } else if (hours > 0) {
                                        displayText = hours + 'h ' + (minutes % 60) + 'm';
                                    } else {
                                        displayText = minutes + 'm';
                                    }
                                    
                                    minutesElement.textContent = displayText;
                                } else {
                                    // Timer has expired - update UI immediately
                                    minutesElement.textContent = 'Expired';
                                    element.className = 'text-danger';
                                    
                                    // Update the status badge to Inactive
                                    var statusCell = row.querySelector('td:nth-child(6)'); // Status column
                                    if (statusCell) {
                                        var badge = statusCell.querySelector('.badge');
                                        if (badge) {
                                            badge.className = 'badge badge-danger';
                                            badge.textContent = 'Inactive';
                                        }
                                    }
                                    
                                    // Update the suspend button to show Inactive
                                    var suspendButton = row.querySelector('button[onclick*="showSuspendModal"]');
                                    if (suspendButton) {
                                        suspendButton.outerHTML = '<span class="btn btn-secondary btn-xs mb-1 disabled"><i class="fa fa-ban"></i> Inactive</span>';
                                    }
                                    
                                    hasExpired = true;
                                }
                            }
                        }
                    });
                    
                    // If any countdown expired, refresh the page after a short delay to sync with backend
                    if (hasExpired) {
                        setTimeout(function() {
                            location.reload();
                        }, 2000); // Wait 2 seconds before refreshing
                    }
                }

                // Update countdowns every 10 seconds for better real-time experience
                setInterval(updateCountdowns, 10000);
                
                // Initial update
                document.addEventListener('DOMContentLoaded', function() {
                    updateCountdowns();
                    
                    // Initialize modal form interactions
                    initializeModalForm();
                });

                // Initialize Modal Form Interactions
                function initializeModalForm() {
                    // Load servers when type changes
                    $('input[type=radio][name="type"]').change(function(){
                        $("#modal_server").html('<option value=""><?php echo Lang::T('Select Routers');?>
</option>');
                        $("#modal_plan").html('<option value=""><?php echo Lang::T('Select Plans');?>
</option>');
                        $("#modal-server-help").text('Loading routers...');
                        $("#modal-plan-help").text('Select a router first to load available plans');
                        
                        if ($('#modalHot').is(':checked') || $('#modalPOE').is(':checked')) {
                            $.ajax({
                                type: "POST",
                                dataType: "html",
                                url: "index.php?_route=autoload/server",
                                success: function(msg){
                                    $("#modal_server").html(msg);
                                    $("#modal_server").prop('disabled', false);
                                    
                                    // Update help text
                                    var serverCount = $("#modal_server option").length - 1;
                                    if (serverCount > 0) {
                                        $("#modal-server-help").text('Found ' + serverCount + ' router(s) available');
                                    } else {
                                        $("#modal-server-help").text('No routers found. Please add routers first.');
                                    }
                                },
                                error: function(xhr, status, error) {
                                    $("#modal-server-help").text('Error loading routers. Please try again.');
                                }
                            });
                        }
                    });
                    
                    // Load plans when server changes
                    $("#modal_server").change(function(){
                        var server = $("#modal_server").val();
                        var jenis = $('input[name="type"]:checked').val();
                        
                        if (server && jenis) {
                            $("#modal-plan-help").text('Loading plans...');
                            $.ajax({
                                type: "POST",
                                dataType: "html",
                                url: "index.php?_route=autoload/plan",
                                data: "jenis=" + jenis + "&server=" + server,
                                success: function(msg){
                                    $("#modal_plan").html(msg);
                                    $("#modal_plan").prop('disabled', false);
                                    
                                    // Update help text
                                    var planCount = $("#modal_plan option").length - 1;
                                    if (planCount > 0) {
                                        $("#modal-plan-help").text('Found ' + planCount + ' plan(s) available');
                                    } else {
                                        $("#modal-plan-help").text('No plans found for this router and type. Please create plans first.');
                                    }
                                },
                                error: function(xhr, status, error) {
                                    $("#modal-plan-help").text('Error loading plans. Please try again.');
                                }
                            });
                        } else {
                            $("#modal_plan").html('<option value=""><?php echo Lang::T('Select Plans');?>
</option>');
                            $("#modal-plan-help").text('Select a router and type first to load available plans');
                        }
                    });
                }
            <?php echo '</script'; ?>
>

<?php $_smarty_tpl->_subTemplateRender("file:sections/footer.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), 0, false);
}
}
