2024-05-25 09:41:27 +02:00
< ? php if ( ! defined ( 'BASEPATH' )) exit ( 'No direct script access allowed' );
2019-06-19 14:14:10 +01:00
/*
Controller to interact with the Clublog API
*/
2024-05-25 09:41:27 +02:00
class Clublog extends CI_Controller
{
2019-06-19 14:14:10 +01:00
2024-02-29 13:52:54 +01:00
function __construct ()
{
parent :: __construct ();
2024-05-25 09:41:27 +02:00
2024-02-29 13:52:54 +01:00
if ( ENVIRONMENT == 'maintenance' && $this -> session -> userdata ( 'user_id' ) == '' ) {
2024-06-08 11:01:59 +02:00
echo __ ( " Maintenance Mode is active. Try again later. " ) . " \n " ;
2024-05-25 09:41:27 +02:00
redirect ( 'dashboard' );
2024-02-29 13:52:54 +01:00
}
}
2019-06-19 14:14:10 +01:00
// Show frontend if there is one
2024-05-25 09:41:27 +02:00
public function index ()
{
// nothing to display
redirect ( 'dashboard' );
2019-06-19 14:14:10 +01:00
}
// Upload ADIF to Clublog
2024-05-25 09:41:27 +02:00
public function upload ()
{
2026-07-24 13:12:48 +02:00
$this -> load -> helper ( 'cronauth' );
if ( ! cronauth_allowed ( 3 )) {
// return a 403
$this -> output -> set_status_header ( 403 );
exit ();
}
2024-05-25 09:41:27 +02:00
2024-02-29 13:52:54 +01:00
$this -> load -> model ( 'clublog_model' );
2022-09-11 15:02:31 +02:00
2024-05-03 11:14:52 +02:00
// set the last run in cron table for the correct cron id
2024-04-22 23:32:34 +02:00
$this -> load -> model ( 'cron_model' );
2024-05-25 09:41:27 +02:00
$this -> cron_model -> set_last_run ( $this -> router -> class . '_' . $this -> router -> method );
2024-04-22 23:32:34 +02:00
2024-02-29 13:52:54 +01:00
$users = $this -> clublog_model -> get_clublog_users ();
2022-09-11 15:02:31 +02:00
2026-07-11 17:48:02 +02:00
$r = '' ;
2024-05-25 09:41:27 +02:00
if ( ! empty ( $users )) {
foreach ( $users as $user ) {
$r = $this -> clublog_model -> uploadUser ( $user -> user_id , $user -> user_clublog_name , $user -> user_clublog_password );
}
} else {
2024-06-08 11:01:59 +02:00
$r = __ ( " No user has configured Clublog. " );
2022-09-11 15:02:31 +02:00
}
2024-05-25 09:41:27 +02:00
echo $r ;
2022-09-11 15:02:31 +02:00
}
2019-10-05 19:26:07 +01:00
2024-05-09 08:18:38 +00:00
// Download ADIF from Clublog
2024-05-25 09:41:27 +02:00
public function download ()
{
2024-05-09 06:02:17 +00:00
$this -> load -> model ( 'clublog_model' );
// set the last run in cron table for the correct cron id
$this -> load -> model ( 'cron_model' );
2024-05-25 09:41:27 +02:00
$this -> cron_model -> set_last_run ( $this -> router -> class . '_' . $this -> router -> method );
2024-05-09 06:02:17 +00:00
$users = $this -> clublog_model -> get_clublog_users ();
2026-07-11 17:48:02 +02:00
$r = '' ;
2024-05-25 09:41:27 +02:00
if ( ! empty ( $users )) {
foreach ( $users as $user ) {
$r = $this -> clublog_model -> downloadUser ( $user -> user_id , $user -> user_clublog_name , $user -> user_clublog_password );
2025-10-07 17:41:07 +00:00
if ( $r == 'Impossible to reach Clublog' ) { // Stop Download immediatly, because we're blocked
log_message ( " Error " , " We're blocked by Clublog. Stopping Download! " );
break ;
}
2024-05-08 18:38:06 +00:00
}
2024-05-25 09:41:27 +02:00
} else {
2024-06-08 11:01:59 +02:00
$r = __ ( " No user has configured Clublog. " );
2024-05-08 18:38:06 +00:00
}
2019-06-19 14:48:06 +01:00
2024-05-25 09:41:27 +02:00
echo $r ;
2019-06-19 16:42:04 +01:00
}
2019-06-19 18:03:48 +01:00
2025-01-17 14:02:20 +01:00
/*
2025-01-25 09:01:53 +01:00
* Used for displaying the uid for manually selecting log for upload to Clublog
2025-01-17 14:02:20 +01:00
*/
public function export () {
if ( ! $this -> user_model -> authorize ( 2 ) || ! clubaccess_check ( 9 )) { $this -> session -> set_flashdata ( 'error' , __ ( " You're not allowed to do that! " )); redirect ( 'dashboard' ); }
$this -> load -> model ( 'clublog_model' );
$this -> load -> model ( 'stations' );
$data [ 'page_title' ] = __ ( " Clublog " );
$data [ 'station_profiles' ] = $this -> stations -> all_of_user ();
$data [ 'station_profile' ] = $this -> clublog_model -> stations_with_clublog_enabled ();
$data [ 'callsigns' ] = $this -> stations -> callsigns_of_user ( $this -> session -> userdata ( 'user_id' ));
$this -> load -> model ( 'cron_model' );
$data [ 'next_run_up' ] = $this -> cron_model -> get_next_run ( " clublog_upload " );
$data [ 'next_run_down' ] = $this -> cron_model -> get_next_run ( " clublog_download " );
2025-01-27 13:03:55 +01:00
$footerData = [];
$footerData [ 'scripts' ] = [
2026-02-13 16:58:57 +01:00
'assets/js/sections/clublog.js' ,
2025-01-27 13:03:55 +01:00
];
2025-01-17 14:02:20 +01:00
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'clublog/export' );
2025-01-27 13:03:55 +01:00
$this -> load -> view ( 'interface_assets/footer' , $footerData );
2025-01-17 14:02:20 +01:00
}
2025-01-25 09:01:53 +01:00
2025-01-27 13:03:55 +01:00
public function uploadlog () {
2025-01-28 07:53:17 +01:00
if ( ! ( $this -> config -> item ( 'disable_manual_clublog' ))) {
$this -> load -> model ( 'clublog_model' );
$clean_station_id = $this -> security -> xss_clean ( $this -> input -> post ( 'station_id' ));
$users = $this -> clublog_model -> get_clublog_users ( $this -> session -> userdata ( 'user_id' ));
if ( ! empty ( $users )) {
foreach ( $users as $user ) {
$data [ 'status' ] = 'OK' ;
$data [ 'infomessage' ] = $this -> clublog_model -> uploadUser ( $user -> user_id , $user -> user_clublog_name , $user -> user_clublog_password , $clean_station_id );
$data [ 'errormessages' ] = '' ;
}
} else {
$data [ 'status' ] = 'Error' ;
$data [ 'errormessages' ] = __ ( " No user has configured Clublog. " );
2025-01-25 09:01:53 +01:00
}
2025-01-28 19:24:53 +01:00
$stationinfo = $this -> clublog_model -> stations_with_clublog_enabled ();
$info = $stationinfo -> result ();
$data [ 'info' ] = $info ;
2025-01-28 07:53:17 +01:00
header ( 'Content-type: application/json' );
echo json_encode ( $data );
2025-01-25 09:01:53 +01:00
} else {
2025-01-28 07:53:17 +01:00
redirect ( 'dashboard' );
2025-01-25 09:01:53 +01:00
}
}
public function importlog () {
2025-01-31 07:51:59 +01:00
if ( ! ( $this -> config -> item ( 'disable_manual_clublog' ))) {
2025-01-25 09:01:53 +01:00
2025-01-31 07:51:59 +01:00
if ( ! $this -> user_model -> authorize ( 2 )) { $this -> session -> set_flashdata ( 'error' , __ ( " You're not allowed to do that! " )); redirect ( 'dashboard' ); }
2025-01-25 09:01:53 +01:00
2025-01-31 07:51:59 +01:00
$data [ 'page_title' ] = __ ( " Clublog QSL Import " );
2025-01-25 09:01:53 +01:00
2025-01-31 07:51:59 +01:00
$this -> load -> model ( 'clublog_model' );
2025-01-25 09:01:53 +01:00
2025-01-31 07:51:59 +01:00
$customDate = $this -> input -> post ( 'date' );
if ( $customDate != NULL ) {
$clublog_last_date = date ( $customDate );
} else {
// Query the logbook to determine when the last LoTW confirmation was
$clublog_last_date = null ;
2025-01-25 09:01:53 +01:00
}
2025-01-31 07:51:59 +01:00
$users = $this -> clublog_model -> get_clublog_users ( $this -> session -> userdata ( 'user_id' ));
2026-07-11 17:48:02 +02:00
$r = '' ;
2025-01-31 07:51:59 +01:00
if ( ! empty ( $users )) {
foreach ( $users as $user ) {
$r = $this -> clublog_model -> downloadUser ( $user -> user_id , $user -> user_clublog_name , $user -> user_clublog_password , $clublog_last_date );
}
} else {
$r = __ ( " No user has configured Clublog. " );
}
header ( 'Content-type: application/json' );
echo json_encode ( $r );
2025-01-25 09:01:53 +01:00
} else {
2025-01-31 07:51:59 +01:00
redirect ( 'dashboard' );
2025-01-25 09:01:53 +01:00
}
}
2025-01-30 20:39:56 +01:00
2019-10-08 20:53:14 +01:00
}