2011-09-21 14:30:01 +01:00
< ? php if ( ! defined ( 'BASEPATH' )) exit ( 'No direct script access allowed' );
class adif extends CI_Controller {
/* Controls ADIF Import/Export Functions */
2014-09-25 23:09:44 +01:00
2011-11-19 22:28:05 +00:00
function __construct ()
{
parent :: __construct ();
$this -> load -> helper ( array ( 'form' , 'url' ));
2014-09-25 23:09:44 +01:00
2012-11-19 22:24:10 +00:00
$this -> load -> model ( 'user_model' );
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' ); }
2011-11-19 22:28:05 +00:00
}
2019-10-21 17:41:21 +01:00
public function test () {
if ( validateADIFDate ( '20120228' ) == true ){
2024-06-08 11:01:59 +02:00
echo __ ( " valid date " );
2019-10-21 17:41:21 +01:00
} else {
2024-06-08 11:01:59 +02:00
echo __ ( " date incorrect " );
2019-10-21 17:41:21 +01:00
}
}
2019-06-30 23:29:58 +01:00
2011-09-21 14:30:01 +01:00
// Export all QSO Data in ASC Order of Date.
public function exportall ()
{
2011-09-23 18:15:47 +01:00
// Set memory limit to unlimited to allow heavy usage
ini_set ( 'memory_limit' , '-1' );
2014-09-25 23:09:44 +01:00
2011-09-21 14:30:01 +01:00
$this -> load -> model ( 'adif_data' );
2024-09-11 08:25:06 +00:00
$data [ 'qsos' ] = $this -> adif_data -> export_all ( null , $this -> input -> post ( 'from' , true ), $this -> input -> post ( 'to' , true ));
2020-04-08 14:47:25 +01:00
2011-09-21 14:30:01 +01:00
$this -> load -> view ( 'adif/data/exportall' , $data );
}
2014-09-25 23:09:44 +01:00
2019-01-07 16:58:23 +00:00
// Export all QSO Data in ASC Order of Date.
public function exportsat ()
{
// Set memory limit to unlimited to allow heavy usage
ini_set ( 'memory_limit' , '-1' );
$this -> load -> model ( 'adif_data' );
2019-04-08 15:47:03 +01:00
$data [ 'qsos' ] = $this -> adif_data -> sat_all ();
2019-04-08 15:36:23 +01:00
$this -> load -> view ( 'adif/data/exportsat' , $data );
}
// Export all QSO Data in ASC Order of Date.
public function exportsatlotw ()
{
// Set memory limit to unlimited to allow heavy usage
ini_set ( 'memory_limit' , '-1' );
$this -> load -> model ( 'adif_data' );
$data [ 'qsos' ] = $this -> adif_data -> satellte_lotw ();
2019-01-07 16:58:23 +00:00
$this -> load -> view ( 'adif/data/exportsat' , $data );
}
2011-09-21 14:30:01 +01:00
public function export_custom () {
2011-09-23 18:15:47 +01:00
// Set memory limit to unlimited to allow heavy usage
ini_set ( 'memory_limit' , '-1' );
2024-09-11 08:36:26 +00:00
2011-09-21 14:30:01 +01:00
$this -> load -> model ( 'adif_data' );
2024-09-11 08:36:26 +00:00
2021-03-08 20:20:05 +01:00
$station_id = $this -> security -> xss_clean ( $this -> input -> post ( 'station_profile' ));
2024-09-11 08:36:26 +00:00
2020-06-23 09:22:37 +02:00
// Used for exporting QSOs not previously exported to LoTW
2024-09-11 08:25:06 +00:00
if ( $this -> input -> post ( 'exportLotw' ) == 1 ) {
$exportLotw = true ;
} else {
$exportLotw = false ;
2020-11-17 17:35:48 +00:00
}
2024-09-11 08:36:26 +00:00
2021-03-08 20:20:05 +01:00
$data [ 'qsos' ] = $this -> adif_data -> export_custom ( $this -> input -> post ( 'from' ), $this -> input -> post ( 'to' ), $station_id , $exportLotw );
2024-09-11 08:36:26 +00:00
2011-09-21 14:30:01 +01:00
$this -> load -> view ( 'adif/data/exportall' , $data );
2014-09-25 23:09:44 +01:00
2024-09-11 08:36:26 +00:00
2020-04-01 08:43:08 +02:00
if ( $this -> input -> post ( 'markLotw' ) == 1 ) {
2024-09-11 08:25:06 +00:00
foreach ( $data [ 'qsos' ] -> result () as $qso )
{
$this -> adif_data -> mark_lotw_sent ( $qso -> COL_PRIMARY_KEY );
}
}
}
2020-04-01 08:43:08 +02:00
2024-09-11 08:25:06 +00:00
public function mark_lotw () {
// Set memory limit to unlimited to allow heavy usage
ini_set ( 'memory_limit' , '-1' );
2020-04-01 08:43:08 +02:00
2021-03-08 20:20:05 +01:00
$station_id = $this -> security -> xss_clean ( $this -> input -> post ( 'station_profile' ));
2024-09-11 08:25:06 +00:00
$this -> load -> model ( 'adif_data' );
2020-04-01 08:43:08 +02:00
2024-09-11 08:25:06 +00:00
$data [ 'qsos' ] = $this -> adif_data -> export_custom ( $this -> input -> post ( 'from' ), $this -> input -> post ( 'to' ), $station_id );
2020-04-01 08:43:08 +02:00
2024-09-11 08:25:06 +00:00
foreach ( $data [ 'qsos' ] -> result () as $qso )
{
$this -> adif_data -> mark_lotw_sent ( $qso -> COL_PRIMARY_KEY );
}
2020-04-01 08:43:08 +02:00
2024-09-11 08:25:06 +00:00
$this -> load -> view ( 'adif/mark_lotw' , $data );
}
2011-09-21 14:30:01 +01:00
2013-03-04 22:57:29 -06:00
public function export_lotw ()
{
// Set memory limit to unlimited to allow heavy usage
ini_set ( 'memory_limit' , '-1' );
2014-09-25 23:09:44 +01:00
2013-03-04 22:57:29 -06:00
$this -> load -> model ( 'adif_data' );
$data [ 'qsos' ] = $this -> adif_data -> export_lotw ();
$this -> load -> view ( 'adif/data/exportall' , $data );
2014-09-25 23:09:44 +01:00
2013-03-06 23:31:19 -06:00
foreach ( $data [ 'qsos' ] -> result () as $qso )
{
$this -> adif_data -> mark_lotw_sent ( $qso -> COL_PRIMARY_KEY );
}
2013-03-04 22:57:29 -06:00
}
2014-09-25 23:09:44 +01:00
2019-06-30 00:06:24 +01:00
public function index () {
2024-03-20 07:47:34 +00:00
$this -> load -> model ( 'contesting_model' );
$data [ 'contests' ] = $this -> contesting_model -> getActivecontests ();
2019-08-19 22:25:50 +01:00
$this -> load -> model ( 'stations' );
2019-09-24 23:42:01 +01:00
2024-06-08 11:01:59 +02:00
$data [ 'page_title' ] = __ ( " ADIF Import / Export " );
2019-06-30 00:06:24 +01:00
$data [ 'max_upload' ] = ini_get ( 'upload_max_filesize' );
2019-09-24 23:42:01 +01:00
2025-01-02 10:22:23 +01:00
if ( $this -> config -> item ( 'special_callsign' ) && clubaccess_check ( 9 ) && $this -> session -> userdata ( 'clubstation' ) == 1 ) {
$this -> load -> model ( 'club_model' );
$data [ 'club_operators' ] = $this -> club_model -> get_club_members ( $this -> session -> userdata ( 'user_id' ));
} else {
$data [ 'club_operators' ] = false ;
}
2021-11-15 19:46:20 +01:00
$data [ 'station_profile' ] = $this -> stations -> all_of_user ();
2024-09-11 08:25:06 +00:00
$active_station_id = $this -> stations -> find_active ();
$station_profile = $this -> stations -> profile ( $active_station_id );
2019-09-24 23:42:01 +01:00
$data [ 'active_station_info' ] = $station_profile -> row ();
2024-05-26 20:47:36 +02:00
$data [ 'active_station_id' ] = $active_station_id ;
2019-09-24 23:42:01 +01:00
2019-06-30 00:06:24 +01:00
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'adif/import' );
$this -> load -> view ( 'interface_assets/footer' );
}
2013-08-17 16:24:16 +01:00
public function import () {
2019-08-19 22:25:50 +01:00
$this -> load -> model ( 'stations' );
2021-11-15 19:46:20 +01:00
$data [ 'station_profile' ] = $this -> stations -> all_of_user ();
2014-09-25 23:09:44 +01:00
2024-01-11 14:52:17 +00:00
$active_station_id = $this -> stations -> find_active ();
$station_profile = $this -> stations -> profile ( $active_station_id );
2019-09-24 23:42:01 +01:00
$data [ 'active_station_info' ] = $station_profile -> row ();
2024-06-08 11:01:59 +02:00
$data [ 'page_title' ] = __ ( " ADIF Import " );
2023-10-17 16:19:05 +02:00
$data [ 'tab' ] = " adif " ;
2011-11-19 22:28:05 +00:00
2017-12-18 00:41:17 -07:00
$config [ 'upload_path' ] = './uploads/' ;
2024-01-11 14:52:17 +00:00
$config [ 'allowed_types' ] = 'adi|ADI|adif|ADIF|zip' ;
2011-11-19 22:28:05 +00:00
2024-01-12 15:51:16 +00:00
log_message ( " Error " , " ADIF Start " );
session_write_close ();
2011-11-19 22:28:05 +00:00
$this -> load -> library ( 'upload' , $config );
2023-07-19 18:18:03 +00:00
if ( ! $this -> upload -> do_upload ()) {
2011-11-19 22:28:05 +00:00
$data [ 'error' ] = $this -> upload -> display_errors ();
2019-05-16 16:19:56 +01:00
$data [ 'max_upload' ] = ini_get ( 'upload_max_filesize' );
2019-05-16 16:03:52 +01:00
2019-01-13 19:11:46 +00:00
$this -> load -> view ( 'interface_assets/header' , $data );
2023-10-17 16:19:05 +02:00
$this -> load -> view ( 'adif/import' , $data );
2019-01-13 19:11:46 +00:00
$this -> load -> view ( 'interface_assets/footer' );
2023-07-19 18:18:03 +00:00
} else {
2024-10-31 10:26:59 +01:00
if ( $this -> stations -> check_station_is_accessible ( $this -> input -> post ( 'station_profile' , TRUE ))) {
2025-01-02 10:22:23 +01:00
$contest = $this -> input -> post ( 'contest' , true ) ? ? '' ;
$club_operator = $this -> input -> post ( 'club_operator' , true ) ? ? '' ;
2024-01-11 14:52:17 +00:00
$stopnow = false ;
$fdata = array ( 'upload_data' => $this -> upload -> data ());
2023-07-19 18:18:03 +00:00
ini_set ( 'memory_limit' , '-1' );
set_time_limit ( 0 );
2011-11-19 22:28:05 +00:00
2023-07-19 18:18:03 +00:00
$this -> load -> model ( 'logbook_model' );
2011-11-19 22:28:05 +00:00
2024-01-11 14:52:17 +00:00
$f_elements = explode ( " . " , $fdata [ 'upload_data' ][ 'file_name' ]);
if ( strtolower ( $f_elements [ count ( $f_elements ) - 1 ]) == 'zip' ) {
$f_adif = preg_replace ( '/\\.zip$/' , '' , $fdata [ 'upload_data' ][ 'file_name' ]);
2024-02-14 05:36:09 +00:00
$p_adif = hash ( 'sha256' , $this -> session -> userdata ( 'user_callsign' ) ) . '.adif' ;
2024-01-11 14:52:17 +00:00
if ( preg_match ( " /.* \ .adi.? $ / " , strtolower ( $p_adif ))) { // Check if adi? inside zip
$zip = new ZipArchive ;
if ( $zip -> open ( './uploads/' . $fdata [ 'upload_data' ][ 'file_name' ])) {
$zip -> extractTo ( " ./uploads/ " , array ( $p_adif ));
$zip -> close ();
}
unlink ( './uploads/' . $fdata [ 'upload_data' ][ 'file_name' ]);
} else {
unlink ( './uploads/' . $fdata [ 'upload_data' ][ 'file_name' ]);
2024-06-08 11:01:59 +02:00
$data [ 'error' ] = __ ( " Unsupported Filetype " );
2024-01-11 14:52:17 +00:00
$stopnow = true ;
}
} else {
$p_adif = $fdata [ 'upload_data' ][ 'file_name' ];
}
if ( ! ( $stopnow )) {
2024-09-11 10:09:43 +02:00
if ( ! $this -> load -> is_loaded ( 'adif_parser' )) {
$this -> load -> library ( 'adif_parser' );
}
2024-01-11 14:52:17 +00:00
$this -> adif_parser -> load_from_file ( './uploads/' . $p_adif );
unlink ( './uploads/' . $p_adif );
$fdata [ 'upload_data' ] = '' ; // free memory
$this -> adif_parser -> initialize ();
$custom_errors = " " ;
$alladif = [];
2024-04-25 09:10:46 +00:00
while ( $record = $this -> adif_parser -> get_record ()) {
2024-03-20 07:47:34 +00:00
if ( $contest != '' ) {
$record [ 'contest_id' ] = $contest ;
}
2025-01-02 10:22:23 +01:00
if ( $club_operator != '' ) {
$record [ 'operator' ] = strtoupper ( $club_operator );
}
2024-01-11 14:52:17 +00:00
if ( count ( $record ) == 0 ) {
break ;
};
array_push ( $alladif , $record );
2023-07-19 18:18:03 +00:00
};
2024-01-11 14:52:17 +00:00
$record = '' ; // free memory
2024-08-28 09:29:22 +02:00
try {
2025-01-02 10:22:23 +01:00
$custom_errors = $this -> logbook_model -> import_bulk ( $alladif , $this -> input -> post ( 'station_profile' , TRUE ), $this -> input -> post ( 'skipDuplicate' ), $this -> input -> post ( 'markClublog' ), $this -> input -> post ( 'markLotw' ), $this -> input -> post ( 'dxccAdif' ), $this -> input -> post ( 'markQrz' ), $this -> input -> post ( 'markEqsl' ), $this -> input -> post ( 'markHrd' ), $this -> input -> post ( 'markDcl' ), true , $this -> input -> post ( 'operatorName' ) ? ? false , false , $this -> input -> post ( 'skipStationCheck' ));
2024-08-28 09:29:22 +02:00
} catch ( Exception $e ) {
log_message ( 'error' , 'Import error: ' . $e -> getMessage ());
2024-08-28 10:12:36 +02:00
$data [ 'page_title' ] = __ ( " ADIF Import failed! " );
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'adif/import_failed' );
$this -> load -> view ( 'interface_assets/footer' );
return ;
2024-08-28 09:29:22 +02:00
}
2024-01-11 14:52:17 +00:00
} else { // Failure, if no ADIF inside ZIP
$data [ 'max_upload' ] = ini_get ( 'upload_max_filesize' );
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'adif/import' , $data );
$this -> load -> view ( 'interface_assets/footer' );
return ;
}
2023-07-19 18:18:03 +00:00
} else {
2024-06-08 14:09:20 +02:00
$custom_errors = __ ( " Station Profile not valid for User " );
2023-07-19 18:18:03 +00:00
}
2011-11-19 22:28:05 +00:00
2024-01-12 15:51:16 +00:00
log_message ( " Error " , " ADIF End " );
2021-03-08 20:20:05 +01:00
$data [ 'adif_errors' ] = $custom_errors ;
2023-10-16 09:34:29 +02:00
$data [ 'skip_dupes' ] = $this -> input -> post ( 'skipDuplicate' );
2019-10-21 17:41:21 +01:00
2024-06-08 11:01:59 +02:00
$data [ 'page_title' ] = __ ( " ADIF Imported " );
2019-01-13 19:11:46 +00:00
$this -> load -> view ( 'interface_assets/header' , $data );
2011-11-19 22:28:05 +00:00
$this -> load -> view ( 'adif/import_success' );
2019-01-13 19:11:46 +00:00
$this -> load -> view ( 'interface_assets/footer' );
2011-11-19 22:28:05 +00:00
}
}
2023-10-17 16:19:05 +02:00
public function dcl () {
$this -> load -> model ( 'stations' );
$data [ 'station_profile' ] = $this -> stations -> all_of_user ();
2024-06-08 11:01:59 +02:00
$data [ 'page_title' ] = __ ( " DCL Import " );
2023-10-17 16:19:05 +02:00
$data [ 'tab' ] = " dcl " ;
$config [ 'upload_path' ] = './uploads/' ;
$config [ 'allowed_types' ] = 'adi|ADI|adif|ADIF' ;
$this -> load -> library ( 'upload' , $config );
if ( ! $this -> upload -> do_upload ()) {
$data [ 'error' ] = $this -> upload -> display_errors ();
$data [ 'max_upload' ] = ini_get ( 'upload_max_filesize' );
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'adif/import' , $data );
$this -> load -> view ( 'interface_assets/footer' );
} else {
$data = array ( 'upload_data' => $this -> upload -> data ());
ini_set ( 'memory_limit' , '-1' );
set_time_limit ( 0 );
$this -> load -> model ( 'logbook_model' );
2024-09-11 10:12:56 +02:00
if ( ! $this -> load -> is_loaded ( 'adif_parser' )) {
$this -> load -> library ( 'adif_parser' );
}
2023-10-17 16:19:05 +02:00
$this -> adif_parser -> load_from_file ( './uploads/' . $data [ 'upload_data' ][ 'file_name' ]);
$this -> adif_parser -> initialize ();
2023-10-18 11:31:15 +02:00
$error_count = array ( 0 , 0 , 0 );
2023-10-17 16:19:05 +02:00
$custom_errors = " " ;
while ( $record = $this -> adif_parser -> get_record ())
{
if ( count ( $record ) == 0 ) {
break ;
};
$dok_result = $this -> logbook_model -> update_dok ( $record , $this -> input -> post ( 'ignoreAmbiguous' ), $this -> input -> post ( 'onlyConfirmed' ), $this -> input -> post ( 'overwriteDok' ));
if ( ! empty ( $dok_result )) {
2023-10-18 11:31:15 +02:00
switch ( $dok_result [ 0 ]) {
case 0 :
2023-10-17 16:19:05 +02:00
$error_count [ 0 ] ++ ;
2023-10-18 11:31:15 +02:00
break ;
case 1 :
$custom_errors .= $dok_result [ 1 ];
$error_count [ 1 ] ++ ;
break ;
case 2 :
$custom_errors .= $dok_result [ 1 ];
$error_count [ 2 ] ++ ;
2023-10-17 16:19:05 +02:00
}
}
};
unlink ( './uploads/' . $data [ 'upload_data' ][ 'file_name' ]);
$data [ 'dcl_error_count' ] = $error_count ;
$data [ 'dcl_errors' ] = $custom_errors ;
2024-06-08 11:01:59 +02:00
$data [ 'page_title' ] = __ ( " DCL Data Imported " );
2023-10-17 16:19:05 +02:00
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'adif/dcl_success' );
$this -> load -> view ( 'interface_assets/footer' );
}
2024-09-11 08:25:06 +00:00
}
2011-09-21 14:30:01 +01:00
}
2014-09-25 23:09:44 +01:00
/* End of file adif.php */