[OQRS] Created new view for OQRS requests

这个提交包含在:
Andreas 2022-12-29 17:14:18 +01:00
父节点 455b28a756
当前提交 d5842bbc5a
共有 4 个文件被更改,包括 402 次插入129 次删除

查看文件

@ -91,6 +91,7 @@ class Oqrs extends CI_Controller {
$this->load->model('oqrs_model');
$data['result'] = $this->oqrs_model->getOqrsRequests($location_list);
$data['stations'] = $this->oqrs_model->get_oqrs_stations();
$this->load->view('interface_assets/header', $data);
$this->load->view('oqrs/showrequests');
@ -182,4 +183,21 @@ class Oqrs extends CI_Controller {
$this->oqrs_model->mark_oqrs_line_as_done($id);
}
public function search() {
$this->load->model('oqrs_model');
$searchCriteria = array(
'user_id' => (int)$this->session->userdata('user_id'),
'de' => xss_clean($this->input->post('de')),
'dx' => xss_clean($this->input->post('dx')),
'status' => xss_clean($this->input->post('status')),
'oqrsResults' => xss_clean($this->input->post('oqrsResults')),
);
$qsos = $this->oqrs_model->searchOqrs($searchCriteria);
header("Content-Type: application/json");
print json_encode($qsos);
}
}

查看文件

@ -84,7 +84,7 @@ class Oqrs_model extends CI_Model {
}
function getOqrsRequests($location_list) {
$sql = 'select * from oqrs join station_profile on oqrs.station_id = station_profile.station_id where oqrs.station_id in (' . $location_list . ') and oqrs.status < 2';
$sql = 'select * from oqrs join station_profile on oqrs.station_id = station_profile.station_id where oqrs.station_id in (' . $location_list . ')';
$query = $this->db->query($sql);
@ -251,15 +251,46 @@ class Oqrs_model extends CI_Model {
return '';
}
function getOqrsStationsFromSlug($logbook_id) {
$sql = 'SELECT station_callsign FROM `station_logbooks_relationship` JOIN `station_profile` ON station_logbooks_relationship.station_location_id = station_profile.station_id WHERE station_profile.oqrs = 1 AND station_logbook_id = '.$logbook_id.';';
/*
* @param array $searchCriteria
* @return array
*/
public function searchOqrs($searchCriteria) : array {
$conditions = [];
$binding = [$searchCriteria['user_id']];
$query = $this->db->query($sql);
if ($query->num_rows() > 0) {
return true;
} else {
return false;
if ($searchCriteria['de'] !== '') {
$conditions[] = "station_profile.STATION_CALLSIGN = ?";
$binding[] = trim($searchCriteria['de']);
}
if ($searchCriteria['dx'] !== '') {
$conditions[] = "oqrs.requestcallsign LIKE ?";
$binding[] = '%' . trim($searchCriteria['dx']) . '%';
}
if ($searchCriteria['status'] !== '') {
$conditions[] = "oqrs.status = ?";
$binding[] = $searchCriteria['status'];
}
$where = trim(implode(" AND ", $conditions));
if ($where != "") {
$where = "AND $where";
}
$limit = $searchCriteria['oqrsResults'];
$sql = "
SELECT *
FROM oqrs
INNER JOIN station_profile ON oqrs.station_id=station_profile.station_id
WHERE station_profile.user_id = ?
$where
ORDER BY oqrs.id
LIMIT $limit
";
$data = $this->db->query($sql, $binding);
return $data->result('array');
}
}
}

查看文件

@ -1,126 +1,123 @@
<div class="container">
<br>
<h2><?php echo $page_title; ?></h2>
<?php
if (count($result) > 0) {
$station_id = '';
$tablebody = '';
$requester = '';
$first = true;
$second = true;
foreach ($result as $qso) {
if ($station_id != $qso->station_id) {
if (!$first) {
write_table($tablebody);
$tablebody = '';
echo '</div></div><br />';
}
insert_station_data($qso);
$first = false;
}
if ($requester != $qso->requestcallsign) {
if (!$second) {
write_table($tablebody);
}
$second = false;
insert_requester($qso);
write_table_header();
$tablebody = '';
}
$tablebody .= insert_qso_data($qso);
$requester = $qso->requestcallsign;
$station_id = $qso->station_id;
}
write_table($tablebody);
echo '</div></div><br />';
} else {
echo 'No OQRS requests were found at this time.';
}
?>
</div>
</div>
</div>
<?php
function insert_station_data($station) {
?>
<div>
<h5>
Station id: <strong><?php echo $station->station_id; ?></strong>
Station callsign: <strong><?php echo $station->station_callsign; ?></strong>
Profile Name: <strong><?php echo $station->station_profile_name; ?></strong>
Country: <strong><?php echo $station->station_country; ?></strong>
Gridsquare: <strong><?php echo $station->station_gridsquare; ?></strong>
</h5>
<div>
<?php
function echo_status($status) {
switch($status) {
case '0': echo 'Open request'; break;
case '1': echo 'Not in log request'; break;
case '2': echo 'Request done'; break;
}
}
function echo_qsl_method($method) {
switch(strtoupper($method)) {
case 'B': echo 'Bureau'; break;
case 'D': echo 'Direct'; break;
case 'E': echo 'Electronic'; break;
}
}
function insert_requester($requester) {
?>
OQRS Request:
<table style="width:100%" class="result-table table-sm table table-bordered table-hover table-striped table-condensed text-center">
<div class="container-fluid oqrs pt-3 pl-4 pr-4">
<h2><?php echo $page_title; ?></h2>
<?php if ($this->session->flashdata('message')) { ?>
<!-- Display Message -->
<div class="alert-message error">
<p><?php echo $this->session->flashdata('message'); ?></p>
</div>
<?php } ?>
<div class="row">
<form id="searchForm" name="searchForm" action="<?php echo base_url()."index.php/oqrs/search";?>" method="post">
<div class="form-row">
<div class="forn-group col-lg-2 col-md-2 col-sm-3 col-xl">
<label class="form-label" for="de">De</label>
<select id="de" name="de" class="form-control form-control-sm">
<option value="">All</option>
<?php
foreach($stations->result() as $station){
?><option value="<?php echo htmlentities($station->station_id);?>"><?php echo htmlspecialchars($station->station_profile_name . ' - ' . $station->station_callsign);?></option><?php
}
?>
</select>
</div>
<div class="forn-group col-lg-2 col-md-2 col-sm-3 col-xl">
<label class="form-label" for="dx">Dx</label>
<input type="text" name="dx" id="dx" class="form-control form-control-sm" value="">
</div>
<div class="forn-group col-lg-2 col-md-2 col-sm-3 col-xl">
<label for="status">OQRS Status</label>
<select id="status" name="status" class="form-control form-control-sm">
<option value="">All</option>
<option value="0">Open request</option>
<option value="1">Not in log request</option>
<option value="2">Request done</option>
</select>
</div>
<div class="forn-group col-lg-2 col-md-2 col-sm-3 col-xl">
<label for="oqrsResults"># Results</label>
<select id="oqrsResults" name="oqrsResults" class="form-control form-control-sm">
<option value="50">50</option>
<option value="200">200</option>
<option value="500">500</option>
<option value="1000">1000</option>
<option value="All">All</option>
</select>
</div>
<div class="form-group">
<label>&nbsp;</label><br>
<button type="submit" class="btn btn-sm btn-primary" id="searchButton">Search</button>
<button type="reset" class="btn btn-sm btn-danger" id="resetButton">Reset</button>
</div>
</div>
</form>
</div>
<div class="row">
<div class=" mb-2">
<span class="h6">With selected :</span>
<button type="button" class="btn btn-sm btn-warning" id="markOqrs">Mark as done</button>
<button type="button" class="btn btn-sm btn-danger" id="deleteOqrs">Delete</button>
<span id="infoBox"></span>
</div>
</div>
<table style="width:100%" class="table-sm oqrstable table table-bordered table-hover table-condensed text-center" id="qsoList">
<thead>
<tr>
<th>Requester</th>
<th>Time of request</th>
<th>E-mail</th>
<th>Note</th>
<th>QSL route</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $requester->requestcallsign ?></td>
<td><?php echo $requester->requesttime ?></td>
<td><?php echo $requester->email ?></td>
<td><?php echo $requester->note ?></td>
<td><?php echo $requester->qslroute; ?></td>
<th><div class="form-check" style="margin-top: -1.5em"><input class="form-check-input" type="checkbox" id="checkBoxAll" /></div></th>
<th>Time of request</th>
<th>QSO Date</th>
<th>QSO Time</th>
<th>Band</th>
<th>Mode</th>
<th>Request callsign</th>
<th>Station callsign</th>
<th>E-mail</th>
<th>Note</th>
<th>QSL route</th>
<th>Check log</th>
<th>Status</th>
</tr>
</tbody>
</table>
<?php
}
function insert_qso_data($qso) {
$tablebody = '';
$tablebody .= '<tr class="oqrsid_'.$qso->id.'">
<td>' . $qso->date . '</td>
<td>' . $qso->time . '</td>
<td>' . $qso->band . '</td>
<td>' . $qso->mode . '</td>
<td><button class="btn btn-primary btn-sm" type="button" onclick="searchLog(\''. $qso->requestcallsign .'\');"><i class="fas fa-search"></i> Call</button>
<button class="btn btn-primary btn-sm" type="button" onclick="searchLogTimeDate(\''. $qso->id .'\');"><i class="fas fa-search"></i> Date/Time</button>
</td>
<td><a href="javascript:markOqrsLineAsDone('. $qso->id .');" class="btn btn-danger btn-sm" onclick=""><i class="fas fa-plus-square"></i></a></td>
<td><a href="javascript:deleteOqrsLine('. $qso->id .');" class="btn btn-danger btn-sm" onclick=""><i class="fas fa-trash-alt"></i></a></td>
</tr>';
return $tablebody;
}
function write_table_header() {
?>
<table style="width:100%" class="result-table table-sm table table-bordered table-hover table-striped table-condensed text-center">
<thead>
<tr>
<th>Date</th>
<th>Time (UTC)</th>
<th>Band</th>
<th>Mode</th>
<th>Check log</th>
<th>Mark as done</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
}
function write_table($tablebody) {
echo $tablebody; ?>
<?php
/*foreach ($result as $qso) {
echo '<tr class="oqrsid_'.$qso->id.'" oqrsid="'.$qso->id.'">';
echo '<td><div class="form-check"><input class="form-check-input" type="checkbox" /></div></td>';
echo '<td>'. $qso->requesttime .'</td>';
echo '<td>'. $qso->date .'</td>';
echo '<td>'. $qso->time .'</td>';
echo '<td>'. $qso->band .'</td>';
echo '<td>'. $qso->mode .'</td>';
echo '<td>'. $qso->requestcallsign .'</td>';
echo '<td>'. $qso->station_callsign .'</td>';
echo '<td>'. $qso->email .'</td>';
echo '<td>'. $qso->note .'</td>';
echo '<td>'; echo_qsl_method($qso->qslroute); echo '</td>';
echo '<td><button class="btn btn-primary btn-sm" type="button" onclick="searchLog(\''. $qso->requestcallsign .'\');"><i class="fas fa-search"></i> Call</button>
<button class="btn btn-primary btn-sm" type="button" onclick="searchLogTimeDate(\''. $qso->id .'\');"><i class="fas fa-search"></i> Date/Time</button>
</td>';
echo '<td>'; echo_status($qso->status); echo '</td>';
echo '</tr>';
}*/
?>
</tbody>
</table>
<?php
}
</table>

查看文件

@ -228,10 +228,10 @@ function searchLogTimeDate(id) {
$.ajax({
url: base_url + 'index.php/oqrs/search_log_time_date',
type: 'post',
data: {'time': $('.oqrsid_'+id+ ' td:nth-child(2)').text(),
'date': $('.oqrsid_'+id+ ' td:nth-child(1)').text(),
'band': $('.oqrsid_'+id+ ' td:nth-child(3)').text(),
'mode': $('.oqrsid_'+id+ ' td:nth-child(4)').text()
data: {'time': $('#oqrsID_'+id+ ' td:nth-child(4)').text(),
'date': $('#oqrsID_'+id+ ' td:nth-child(3)').text(),
'band': $('#oqrsID_'+id+ ' td:nth-child(5)').text(),
'mode': $('#oqrsID_'+id+ ' td:nth-child(6)').text()
},
success: function(html) {
BootstrapDialog.show({
@ -265,3 +265,230 @@ function markOqrsLineAsDone(id) {
}
});
}
function loadOqrsTable(rows) {
var uninitialized = $('.oqrstable').filter(function() {
return !$.fn.DataTable.fnIsDataTable(this);
});
uninitialized.each(function() {
$(this).DataTable({
searching: false,
responsive: false,
ordering: true,
"scrollY": window.innerHeight - $('#searchForm').innerHeight() - 250,
"scrollCollapse": true,
"paging": false,
"scrollX": true,
"order": [ 0, 'asc' ],
'white-space': 'nowrap',
});
});
var table = $('.oqrstable').DataTable();
table.clear();
for (i = 0; i < rows.length; i++) {
let qso = rows[i];
var data = [
'<div class="form-check"><input class="form-check-input" type="checkbox" /></div>',
qso.requesttime,
qso.date,
qso.time,
qso.band,
qso.mode,
qso.requestcallsign,
qso.station_callsign,
qso.email,
qso.note,
echo_qsl_method(qso.qslroute),
echo_searchlog_button(qso.requestcallsign, qso.id),
echo_status(qso.status),
];
let createdRow = table.row.add(data).index();
table.rows(createdRow).nodes().to$().data('oqrsID', qso.id);
table.row(createdRow).node().id = 'oqrsID_' + qso.id;
}
table.columns.adjust().draw();
}
function echo_status(status) {
switch(status.toUpperCase()) {
case '0': return 'Open request'; break;
case '1': return 'Not in log request'; break;
case '2': return 'Request done'; break;
default: return '';
}
}
function echo_qsl_method(method) {
switch(method.toUpperCase()) {
case 'B': return 'Bureau'; break;
case 'D': return 'Direct'; break;
case 'E': return 'Electronic'; break;
default: return '';
}
}
function echo_searchlog_button(callsign, id) {
return '<button class="btn btn-primary btn-sm" type="button" onclick="searchLog(\'' + callsign + '\');"><i class="fas fa-search"></i> Call</button> ' +
'<button class="btn btn-primary btn-sm" type="button" onclick="searchLogTimeDate(' + id + ');"><i class="fas fa-search"></i> Date/Time</button>';
}
$(document).ready(function () {
$('#searchForm').submit(function (e) {
$('#searchButton').prop("disabled", true);
$.ajax({
url: this.action,
type: 'post',
data: {
de: this.de.value,
dx: this.dx.value,
status: this.status.value,
oqrsResults: this.oqrsResults.value
},
dataType: 'json',
success: function (data) {
$('#searchButton').prop("disabled", false);
loadOqrsTable(data);
},
error: function (data) {
$('#searchButton').prop("disabled", false);
BootstrapDialog.alert({
title: 'ERROR',
message: 'An error ocurred while making the request',
type: BootstrapDialog.TYPE_DANGER,
closable: false,
draggable: false,
callback: function (result) {
}
});
},
});
return false;
});
$('.oqrstable').on('click', 'input[type="checkbox"]', function() {
if ($(this).is(":checked")) {
$(this).closest('tr').addClass('alert-success');
} else {
$(this).closest('tr').removeClass('alert-success');
}
});
$('#deleteOqrs').click(function (event) {
var elements = $('.oqrstable tbody input:checked');
var nElements = elements.length;
if (nElements == 0) {
return;
}
$('#deleteOqrs').prop("disabled", true);
var table = $('.oqrstable').DataTable();
BootstrapDialog.confirm({
title: 'DANGER',
message: 'Warning! Are you sure you want to delete the marked OQRS request(s)?' ,
type: BootstrapDialog.TYPE_DANGER,
closable: true,
draggable: true,
btnOKClass: 'btn-danger',
callback: function(result) {
if(result) {
elements.each(function() {
let id = $(this).first().closest('tr').data('qsoID')
$.ajax({
url: base_url + 'index.php/oqrs/delete_ajax',
type: 'post',
data: {'id': id
},
success: function(data) {
var row = $("#qsoID_" + id);
table.row(row).remove().draw(false);
}
});
$('#deleteOqrs').prop("disabled", false);
})
}
}
});
});
$('#markOqrs').click(function (event) {
var elements = $('.oqrstable tbody input:checked');
var nElements = elements.length;
if (nElements == 0) {
return;
}
$('#markOqrs').prop("disabled", true);
var table = $('.oqrstable').DataTable();
BootstrapDialog.confirm({
title: 'DANGER',
message: 'Warning! Are you sure you want to delete the marked OQRS request(s)?' ,
type: BootstrapDialog.TYPE_DANGER,
closable: true,
draggable: true,
btnOKClass: 'btn-danger',
callback: function(result) {
if(result) {
elements.each(function() {
let id = $(this).first().closest('tr').data('qsoID')
$.ajax({
url: base_url + 'index.php/oqrs/mark_ajax',
type: 'post',
data: {'id': id
},
success: function(data) {
var row = $("#qsoID_" + id);
table.row(row).remove().draw(false);
}
});
$('#markOqrs').prop("disabled", false);
})
}
}
});
});
$('#checkBoxAll').change(function (event) {
if (this.checked) {
$('.oqrstable tbody tr').each(function (i) {
selectQsoID($(this).data('oqrsID'))
});
} else {
$('.oqrstable tbody tr').each(function (i) {
unselectQsoID($(this).data('oqrsID'))
});
}
});
$('#searchForm').submit();
$('#searchForm').on('reset', function(e) {
setTimeout(function() {
$('#searchForm').submit();
});
});
});
function selectQsoID(qsoID) {
var element = $("#oqrsID_" + qsoID);
element.find("input[type=checkbox]").prop("checked", true);
element.addClass('alert-success');
}
function unselectQsoID(qsoID) {
var element = $("#oqrsID_" + qsoID);
element.find("input[type=checkbox]").prop("checked", false);
element.removeClass('alert-success');
$('#checkBoxAll').prop("checked", false);
}