2023-12-16 11:42:56 +01:00
< ? php if ( ! defined ( 'BASEPATH' )) exit ( 'No direct script access allowed' );
2023-07-07 11:35:01 +00:00
/*
Controller to interact with the hrdlog . net API
*/
class Hrdlog extends CI_Controller {
/*
* Upload QSO to hrdlog . net
2024-01-17 14:13:23 +00:00
* When called from the url wavelog / hrdlog / upload , the function loops through all station_id ' s with a hrdlog code defined .
2023-07-07 11:35:01 +00:00
* All QSOs not previously uploaded , will then be uploaded , one at a time
*/
2024-02-29 13:52:54 +01:00
2024-05-16 08:21:03 +00:00
function __construct () {
2024-02-29 13:52:54 +01:00
parent :: __construct ();
2024-05-16 08:21:03 +00: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-02-29 13:52:54 +01:00
redirect ( 'user/login' );
}
}
2023-07-07 11:35:01 +00:00
public function upload () {
2026-07-24 13:16:08 +02:00
$this -> load -> helper ( 'cronauth' );
if ( ! cronauth_allowed ( 3 )) {
// return a 403
$this -> output -> set_status_header ( 403 );
exit ();
}
2024-06-27 17:45:29 +02:00
$this -> load -> model ( 'Hrdlog_model' );
$this -> Hrdlog_model -> upload ();
2023-07-07 11:35:01 +00:00
}
/*
* Used for displaying the uid for manually selecting log for upload to hrdlog
*/
public function export () {
2025-01-02 10:22:23 +01:00
if ( ! $this -> user_model -> authorize ( 2 ) || ! clubaccess_check ( 9 )) { $this -> session -> set_flashdata ( 'error' , __ ( " You're not allowed to do that! " )); redirect ( 'dashboard' ); }
2023-07-07 11:35:01 +00:00
$this -> load -> model ( 'stations' );
$data [ 'page_title' ] = " HRDlog.net Logbook " ;
2023-12-16 11:42:56 +01:00
$data [ 'station_profiles' ] = $this -> stations -> all_of_user ();
2023-07-07 11:35:01 +00:00
$data [ 'station_profile' ] = $this -> stations -> stations_with_hrdlog_code ();
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'hrdlog/export' );
$this -> load -> view ( 'interface_assets/footer' );
}
/*
* Used for ajax - function when selecting log for upload to hrdlog
*/
public function upload_station () {
2024-05-16 08:21:03 +00:00
if ( ! ( $this -> config -> item ( 'disable_manual_hrdlog' ))) {
2024-06-27 17:45:29 +02:00
$this -> load -> model ( 'stations' );
$this -> load -> model ( 'Hrdlog_model' );
$this -> Hrdlog_model -> setOptions ();
2024-05-16 08:21:03 +00:00
$postData = $this -> input -> post ();
$this -> load -> model ( 'logbook_model' );
2025-09-09 09:59:15 +00:00
//checks for credentials. Returns "false" if credentials are there, but upload was disabled
2024-05-16 08:21:03 +00:00
$result = $this -> logbook_model -> exists_hrdlog_credentials ( $postData [ 'station_id' ]);
2025-09-09 09:59:15 +00:00
//check for credential errors before accessing them
if ( $result == false ){
$data [ 'status' ] = 'Credential_Error' ;
2025-09-09 10:14:55 +00:00
$data [ 'infomessage' ] = __ ( " HRD Log upload for this station is disabled. " );
$data [ 'errormessages' ] = array ( __ ( " HRD Log upload for this station is disabled. " ));
2025-09-09 09:59:15 +00:00
echo json_encode ( $data );
return ;
}
//read hrd credentials
2024-05-16 08:21:03 +00:00
$hrdlog_username = $result -> hrdlog_username ;
$hrdlog_code = $result -> hrdlog_code ;
2025-09-09 09:59:15 +00:00
//set header
header ( 'Content-type: application/json' );
//perform upload
$result = $this -> Hrdlog_model -> mass_upload_qsos ( $postData [ 'station_id' ], $hrdlog_username , $hrdlog_code );
//return success
if ( $result [ 'status' ] == 'OK' ) {
2024-05-16 08:21:03 +00:00
$stationinfo = $this -> stations -> stations_with_hrdlog_code ();
$info = $stationinfo -> result ();
$data [ 'status' ] = 'OK' ;
$data [ 'info' ] = $info ;
2024-06-27 17:45:29 +02:00
$data [ 'infomessage' ] = sprintf ( _ngettext ( " %d QSO is now uploaded to HRDlog " , " %d QSOs are now uploaded to HRDlog " , $result [ 'count' ]), $result [ 'count' ]);
2024-05-16 08:21:03 +00:00
$data [ 'errormessages' ] = $result [ 'errormessages' ];
echo json_encode ( $data );
} else {
$data [ 'status' ] = 'Error' ;
2024-06-27 17:45:29 +02:00
$data [ 'info' ] = __ ( " No QSOs found to upload. " );
2024-05-16 08:21:03 +00:00
$data [ 'errormessages' ] = $result [ 'errormessages' ];
echo json_encode ( $data );
}
} else {
redirect ( 'dashboard' );
}
2023-07-07 11:35:01 +00:00
}
2023-12-16 11:42:56 +01:00
public function mark_hrdlog () {
2024-07-01 14:16:42 +00:00
// As far as i did research, this one is ONLY Called by "Mark-QSO" at the UI
$this -> load -> model ( 'hrdlog_model' );
$this -> load -> model ( 'stations' );
$station_id = $this -> security -> xss_clean ( $this -> input -> post ( 'station_profile' ));
$data [ 'qsos' ] = [];
if ( $this -> stations -> check_station_is_accessible ( $station_id )) { // Hard Exit if station_profile not accessible
$data [ 'qsos' ] = $this -> hrdlog_model -> mass_mark_hrdlog_sent ( $station_id , $this -> security -> xss_clean ( $this -> input -> post ( 'from' )), $this -> security -> xss_clean ( $this -> input -> post ( 'to' )));
}
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'hrdlog/mark_hrdlog' , $data );
$this -> load -> view ( 'interface_assets/footer' );
2023-12-16 11:42:56 +01:00
}
2023-07-07 11:35:01 +00:00
}