wavelog/application/controllers/Backup.php

99 lines
2.8 KiB
PHP
Raw Permalink Normal View History

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Backup extends CI_Controller {
2019-10-05 19:35:55 +01:00
function __construct()
{
parent::__construct();
}
/* User Facing Links to Backup URLs */
public function index()
{
2024-08-16 10:08:44 +02:00
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }
2024-06-08 11:01:59 +02:00
$data['page_title'] = __("Backup");
2011-11-04 17:32:03 +00:00
2019-01-14 16:29:06 +00:00
$this->load->view('interface_assets/header', $data);
$this->load->view('backup/main');
2019-01-14 16:29:06 +00:00
$this->load->view('interface_assets/footer');
}
2011-10-01 19:35:23 +01:00
/* Gets all QSOs and Dumps them to logbook.adi */
public function adif($key = null){
if ($key == null) {
2024-08-16 10:08:44 +02:00
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }
}
2024-08-14 13:29:07 +02:00
$clean_key = $this->security->xss_clean($key);
$this->load->helper('file');
2025-12-05 06:02:17 +00:00
$this->load->library('AdifHelper');
// Set memory limit to unlimited to allow heavy usage
ini_set('memory_limit', '-1');
$this->load->model('adif_data');
2025-12-05 06:02:17 +00:00
$filename = 'backup/logbook'. date('_Y_m_d_H_i_s') .'.adi';
2025-12-05 06:02:17 +00:00
header('Content-Type: text/plain; charset=utf-8');
header('Content-Disposition: attachment; filename="'.$filename.'"');
2025-12-05 06:02:17 +00:00
// Output ADIF header // No chance to use exportall-view any longer, because of chunking logic
2026-03-22 17:29:48 +01:00
echo $this->adifhelper->getAdifHeader($this->config->item('app_name'),$this->optionslib->get_option('version'), $this->optionslib->get_option('adif_version'));
2025-12-05 06:02:17 +00:00
// Stream QSOs in 5K chunks
$offset = 0;
$chunk_size = 5000;
2011-11-04 17:32:03 +00:00
2025-12-05 06:02:17 +00:00
do {
$qsos = $this->adif_data->export_all_chunked($clean_key, null, null, false, null, $offset, $chunk_size, true);
2025-12-05 06:02:17 +00:00
if ($qsos->num_rows() > 0) {
foreach ($qsos->result() as $qso) {
echo $this->adifhelper->getAdifLine($qso);
}
// Free memory
$qsos->free_result();
}
$offset += $chunk_size;
} while ($qsos->num_rows() > 0);
2025-12-05 06:02:17 +00:00
exit;
}
2011-10-01 19:35:23 +01:00
/* Export the notes to XML */
public function notes($key = null) {
if ($key == null) {
2024-08-16 10:08:44 +02:00
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }
}
2024-08-14 13:29:07 +02:00
$clean_key = $this->security->xss_clean($key);
2011-10-01 19:35:23 +01:00
$this->load->helper('file');
$this->load->model('note');
2024-08-14 13:29:07 +02:00
$data['list_note'] = $this->note->list_all($clean_key);
$data['filename'] = 'backup/notes'. date('_Y_m_d_H_i_s') .'.xml';
2011-10-01 19:35:23 +01:00
if ( ! write_file($data['filename'], $this->load->view('backup/notes', $data, true)))
2011-10-01 19:35:23 +01:00
{
$data['status'] = false;
2011-10-01 19:35:23 +01:00
}
else
{
$data['status'] = true;
2011-10-01 19:35:23 +01:00
}
2024-06-08 11:01:59 +02:00
$data['page_title'] = __("Notes - Backup");
2011-11-04 17:32:03 +00:00
2019-01-14 16:29:06 +00:00
$this->load->view('interface_assets/header', $data);
2011-11-04 17:32:03 +00:00
$this->load->view('backup/notes_view');
2019-01-14 16:29:06 +00:00
$this->load->view('interface_assets/footer');
2011-10-01 19:35:23 +01:00
}
}
/* End of file Backup.php */