hubtel_sms/views/manage.php
2025-01-14 00:21:05 +00:00

302 lines
15 KiB
PHP

<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>
<div id="wrapper">
<div class="content">
<div class="row">
<div class="col-md-12">
<!-- Quick Stats -->
<div class="row">
<div class="col-md-3">
<div class="panel_s">
<div class="panel-body">
<h3 class="text-muted _total"><?php echo $total_messages; ?></h3>
<span class="text-muted"><?php echo _l('total_messages'); ?></span>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel_s">
<div class="panel-body">
<h3 class="text-success _total"><?php echo $sent_messages; ?></h3>
<span class="text-success"><?php echo _l('sent_messages'); ?></span>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel_s">
<div class="panel-body">
<h3 class="text-danger _total"><?php echo $failed_messages; ?></h3>
<span class="text-danger"><?php echo _l('failed_messages'); ?></span>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel_s">
<div class="panel-body">
<h3 class="text-info _total"><?php echo app_format_money($total_cost, get_base_currency()); ?></h3>
<span class="text-info"><?php echo _l('total_cost'); ?></span>
</div>
</div>
</div>
</div>
<div class="panel_s">
<div class="panel-body">
<div class="_buttons">
<?php if (has_permission('hubtel_sms', '', 'create')) { ?>
<a href="#" class="btn btn-primary pull-left display-block" onclick="send_sms_modal();">
<i class="fa fa-paper-plane"></i> <?php echo _l('new_sms'); ?>
</a>
<a href="<?php echo admin_url('hubtel_sms/template'); ?>" class="btn btn-success pull-left display-block mleft5">
<i class="fa fa-plus"></i> <?php echo _l('new_template'); ?>
</a>
<!-- Bulk SMS Button -->
<a href="#" class="btn btn-info pull-left display-block mleft5" onclick="bulk_sms_modal();">
<i class="fa fa-users"></i> <?php echo _l('bulk_sms'); ?>
</a>
<?php } ?>
<?php if (has_permission('hubtel_sms', '', 'edit')) { ?>
<a href="<?php echo admin_url('hubtel_sms/settings'); ?>" class="btn btn-default pull-right">
<i class="fa fa-cog"></i> <?php echo _l('settings'); ?>
</a>
<?php } ?>
</div>
<div class="clearfix"></div>
<hr class="hr-panel-heading" />
<!-- Tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
<a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">
<?php echo _l('sms_messages'); ?>
</a>
</li>
<li role="presentation">
<a href="#templates" aria-controls="templates" role="tab" data-toggle="tab">
<?php echo _l('sms_templates'); ?>
</a>
</li>
</ul>
<!-- Tab Content -->
<div class="tab-content">
<!-- Messages Tab -->
<div role="tabpanel" class="tab-pane active" id="messages">
<div class="row mtop15">
<div class="col-md-12">
<!-- SMS Messages Table -->
<table class="table dt-table" data-order-col="4" data-order-type="desc">
<thead>
<tr>
<th><?php echo _l('id'); ?></th>
<th><?php echo _l('to'); ?></th>
<th><?php echo _l('message'); ?></th>
<th><?php echo _l('status'); ?></th>
<th><?php echo _l('response_code'); ?></th>
<th><?php echo _l('rate'); ?></th>
<th><?php echo _l('network'); ?></th>
<th><?php echo _l('date_sent'); ?></th>
<th><?php echo _l('sent_by'); ?></th>
<th><?php echo _l('options'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($messages as $message) { ?>
<tr>
<td><?php echo $message['id']; ?></td>
<td><?php echo $message['to']; ?></td>
<td>
<span class="text-wrap"><?php echo htmlspecialchars($message['message']); ?></span>
</td>
<td>
<?php
$status_badge = 'info';
if ($message['status'] == 'sent') {
$status_badge = 'success';
} elseif ($message['status'] == 'failed') {
$status_badge = 'danger';
}
?>
<span class="badge badge-<?php echo $status_badge; ?>">
<?php echo _l($message['status']); ?>
</span>
</td>
<td><?php echo isset($message['response_code']) ? $message['response_code'] : '-'; ?></td>
<td><?php echo isset($message['rate']) ? app_format_money($message['rate'], get_base_currency()) : '-'; ?></td>
<td><?php echo isset($message['network_id']) ? $message['network_id'] : '-'; ?></td>
<td data-order="<?php echo strtotime($message['date_sent']); ?>">
<?php echo _dt($message['date_sent']); ?>
</td>
<td><?php echo get_staff_full_name($message['sent_by']); ?></td>
<td>
<div class="btn-group">
<a href="#" class="btn btn-default btn-icon" onclick="view_message(<?php echo $message['id']; ?>)"
data-toggle="tooltip" title="<?php echo _l('view'); ?>">
<i class="fa fa-eye"></i>
</a>
<?php if ($message['status'] == 'failed') { ?>
<a href="#" class="btn btn-info btn-icon" onclick="resend_sms(<?php echo $message['id']; ?>)"
data-toggle="tooltip" title="<?php echo _l('resend'); ?>">
<i class="fa fa-refresh"></i>
</a>
<?php } ?>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Templates Tab -->
<div role="tabpanel" class="tab-pane" id="templates">
<div class="row mtop15">
<div class="col-md-12">
<table class="table dt-table">
<thead>
<tr>
<th><?php echo _l('id'); ?></th>
<th><?php echo _l('name'); ?></th>
<th><?php echo _l('template'); ?></th>
<th><?php echo _l('last_updated'); ?></th>
<th><?php echo _l('options'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($templates as $template) { ?>
<tr>
<td><?php echo $template['id']; ?></td>
<td><?php echo $template['name']; ?></td>
<td>
<span class="text-wrap"><?php echo htmlspecialchars($template['template']); ?></span>
</td>
<td data-order="<?php echo strtotime($template['updated_at'] ?? $template['created_at']); ?>">
<?php echo _dt($template['updated_at'] ?? $template['created_at']); ?>
</td>
<td>
<div class="btn-group">
<?php if (has_permission('hubtel_sms', '', 'edit')) { ?>
<a href="<?php echo admin_url('hubtel_sms/template/' . $template['id']); ?>"
class="btn btn-default btn-icon" data-toggle="tooltip" title="<?php echo _l('edit'); ?>">
<i class="fa fa-pencil"></i>
</a>
<?php } ?>
<a href="#" class="btn btn-info btn-icon" onclick="preview_template(<?php echo $template['id']; ?>)"
data-toggle="tooltip" title="<?php echo _l('preview'); ?>">
<i class="fa fa-eye"></i>
</a>
<?php if (has_permission('hubtel_sms', '', 'delete')) { ?>
<a href="<?php echo admin_url('hubtel_sms/delete_template/' . $template['id']); ?>"
class="btn btn-danger btn-icon _delete" data-toggle="tooltip" title="<?php echo _l('delete'); ?>">
<i class="fa fa-remove"></i>
</a>
<?php } ?>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Include Modals -->
<?php $this->load->view('hubtel_sms/modals/send_sms'); ?>
<?php $this->load->view('hubtel_sms/modals/bulk_sms'); ?>
<?php $this->load->view('hubtel_sms/modals/view_message'); ?>
<?php $this->load->view('hubtel_sms/modals/preview_template'); ?>
<?php init_tail(); ?>
<script src="<?php echo module_dir_url('hubtel_sms', 'assets/js/hubtel_sms.js'); ?>"></script>
<script>
$(function() {
// Initialize tooltips
$('[data-toggle="tooltip"]').tooltip();
// Initialize select2 for template selection
$('#template_id').select2();
});
// Function to handle sending SMS
function send_sms_modal() {
$('#send_sms_modal').modal('show');
$('#send_sms_modal').find('form')[0].reset();
$('#template_id').trigger('change');
}
// Function to handle bulk SMS
function bulk_sms_modal() {
$('#bulk_sms_modal').modal('show');
$('#bulk_sms_modal').find('form')[0].reset();
}
// Function to view message details
function view_message(id) {
$.get(admin_url + 'hubtel_sms/view_message/' + id, function(response) {
$('#message_details').html(response);
$('#view_message_modal').modal('show');
});
}
// Function to preview template
function preview_template(id) {
$.get(admin_url + 'hubtel_sms/preview_template/' + id, function(response) {
$('#template_preview').html(response);
$('#preview_template_modal').modal('show');
});
}
// Function to resend SMS
function resend_sms(id) {
if (confirm(app.lang.confirm_action_prompt)) {
$.get(admin_url + 'hubtel_sms/resend/' + id, function(response) {
if (response.success) {
alert_float('success', response.message);
location.reload();
} else {
alert_float('danger', response.message);
}
}, 'json');
}
}
// Handle template selection
$('#template_id').on('change', function() {
var templateId = $(this).val();
if (templateId) {
$.get(admin_url + 'hubtel_sms/get_template/' + templateId, function(response) {
if (response.success) {
$('#message').val(response.template.template);
init_message_preview();
}
}, 'json');
}
});
// Initialize message preview
function init_message_preview() {
var message = $('#message').val();
var previewHtml = message ? message : app.lang.no_message_preview;
$('#message_preview').html(previewHtml);
}
// Update character count
$('#message').on('keyup', function() {
var chars = $(this).val().length;
$('#char_count').text(chars);
$('#messages_count').text(Math.ceil(chars / 160));
init_message_preview();
});
</script>