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
2025-11-30 09:13:22 +00:00
private $allowed_tabs = [];
private $tab_method_mapping = [
'import' => [ 'import' ],
'export' => [ 'export_custom' , 'exportall' , 'exportsat' , 'exportsatlotw' ],
2025-12-27 22:17:55 +01:00
'lotw' => [ 'lotw' , 'export_lotw' ],
2025-11-30 09:13:22 +00:00
'dcl' => [ 'dcl' ],
'pota' => [ 'pota' ],
'cbr' => []
];
function __construct () {
2011-11-19 22:28:05 +00:00
parent :: __construct ();
$this -> load -> helper ( array ( 'form' , 'url' ));
2014-09-25 23:09:44 +01:00
2025-11-30 09:13:22 +00:00
if ( ! $this -> user_model -> authorize ( 2 ) || ( ! clubaccess_check ( 6 ) && ! clubaccess_check ( 9 ))) { $this -> session -> set_flashdata ( 'error' , __ ( " You're not allowed to do that! " )); redirect ( 'dashboard' ); }
$this -> determine_allowed_tabs ();
$this -> check_tab_access ();
}
private function determine_allowed_tabs () {
if ( clubaccess_check ( 6 ) && ! clubaccess_check ( 9 )) {
2025-12-01 11:58:50 +00:00
// Only ClubMember ADIF and NOT ClubOfficer
2025-11-30 09:13:22 +00:00
$this -> allowed_tabs = [ 'import' , 'export' ];
} else {
// Default: show all tabs (backward compatible)
$this -> allowed_tabs = [ 'import' , 'export' , 'lotw' , 'dcl' , 'pota' , 'cbr' ];
}
}
private function check_tab_access () {
// Get current method using CI's built-in method
$current_method = $this -> router -> method ;
// Skip access check for some common methods
$skip_methods = [ 'index' , '__construct' , 'determine_allowed_tabs' , 'check_tab_access' , 'get_allowed_tabs' , 'test' ];
if ( in_array ( $current_method , $skip_methods )) {
return ;
}
// Find which tab(s) this method belongs to
$required_tabs = [];
foreach ( $this -> tab_method_mapping as $tab => $methods ) {
if ( in_array ( $current_method , $methods )) {
$required_tabs [] = $tab ;
}
}
// Check if user has access to required tabs
foreach ( $required_tabs as $tab ) {
if ( ! in_array ( $tab , $this -> allowed_tabs )) {
$this -> session -> set_flashdata ( 'error' , __ ( " You're not allowed to access this functionality! " ));
redirect ( 'adif' );
}
}
}
private function get_allowed_tabs () {
return $this -> allowed_tabs ;
}
private function require_tab_access ( $required_tab ) {
if ( ! in_array ( $required_tab , $this -> allowed_tabs )) {
$this -> session -> set_flashdata ( 'error' , __ ( " You're not allowed to access this functionality! " ));
redirect ( 'adif' );
}
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
2025-12-05 05:52:59 +00:00
// Export all QSO Data in ASC Order of Date - use chunks to avoid memory exhaustion
2025-11-30 09:13:22 +00:00
public function exportall () {
2025-11-30 11:00:34 +00:00
$this -> require_tab_access ( 'export' );
2025-12-05 05:52:59 +00:00
2011-09-23 18:15:47 +01:00
ini_set ( 'memory_limit' , '-1' );
2025-12-05 05:52:59 +00:00
set_time_limit ( 300 );
2014-09-25 23:09:44 +01:00
2011-09-21 14:30:01 +01:00
$this -> load -> model ( 'adif_data' );
2025-12-05 05:52:59 +00:00
$this -> load -> library ( 'AdifHelper' );
$from = $this -> input -> post ( 'from' , true );
$to = $this -> input -> post ( 'to' , true );
$filename = $this -> session -> userdata ( 'user_callsign' ) . '-' . date ( 'Ymd-Hi' ) . '.adi' ;
header ( 'Content-Type: text/plain; charset=utf-8' );
header ( 'Content-Disposition: attachment; filename="' . $filename . '"' );
// 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 05:52:59 +00:00
// Stream QSOs in 5K chunks
$offset = 0 ;
$chunk_size = 5000 ;
do {
$qsos = $this -> adif_data -> export_all_chunked ( null , $from , $to , false , null , $offset , $chunk_size );
if ( $qsos -> num_rows () > 0 ) {
foreach ( $qsos -> result () as $qso ) {
echo $this -> adifhelper -> getAdifLine ( $qso );
}
// Free memory
$qsos -> free_result ();
}
2011-09-21 14:30:01 +01:00
2025-12-05 05:52:59 +00:00
$offset += $chunk_size ;
} while ( $qsos -> num_rows () > 0 );
2020-04-08 14:47:25 +01:00
2025-12-05 05:52:59 +00:00
exit ;
2011-09-21 14:30:01 +01:00
}
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.
2025-11-30 09:13:22 +00:00
public function exportsat () {
2019-01-07 16:58:23 +00:00
// Set memory limit to unlimited to allow heavy usage
2025-11-30 11:00:34 +00:00
$this -> require_tab_access ( 'export' );
2019-01-07 16:58:23 +00:00
ini_set ( 'memory_limit' , '-1' );
$this -> load -> model ( 'adif_data' );
2025-11-30 11:00:34 +00:00
if ( clubaccess_check ( 6 ) && ! clubaccess_check ( 9 )) {
$onlyop = ( $this -> session -> userdata ( 'operator_callsign' ) ? ? '' );
} else {
$onlyop = null ;
}
$data [ 'qsos' ] = $this -> adif_data -> sat_all ( $onlyop );
2019-04-08 15:36:23 +01:00
$this -> load -> view ( 'adif/data/exportsat' , $data );
}
// Export all QSO Data in ASC Order of Date.
2025-11-30 09:13:22 +00:00
public function exportsatlotw () {
2019-04-08 15:36:23 +01:00
// Set memory limit to unlimited to allow heavy usage
2025-11-30 11:00:34 +00:00
$this -> require_tab_access ( 'export' );
2019-04-08 15:36:23 +01:00
ini_set ( 'memory_limit' , '-1' );
2025-11-30 11:00:34 +00:00
if ( clubaccess_check ( 6 ) && ! clubaccess_check ( 9 )) {
$onlyop = ( $this -> session -> userdata ( 'operator_callsign' ) ? ? '' );
} else {
$onlyop = null ;
}
2019-04-08 15:36:23 +01:00
$this -> load -> model ( 'adif_data' );
2025-11-30 11:00:34 +00:00
$data [ 'qsos' ] = $this -> adif_data -> satellte_lotw ( $onlyop );
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 () {
2025-11-30 09:13:22 +00:00
// Check if user has access to export tab
$this -> require_tab_access ( 'export' );
2011-09-23 18:15:47 +01:00
// Set memory limit to unlimited to allow heavy usage
ini_set ( 'memory_limit' , '-1' );
2025-12-05 06:39:44 +00:00
set_time_limit ( 300 );
2024-09-11 08:36:26 +00:00
2011-09-21 14:30:01 +01:00
$this -> load -> model ( 'adif_data' );
2025-12-05 06:39:44 +00:00
$this -> load -> library ( 'AdifHelper' );
2025-12-27 22:24:09 +01:00
$this -> load -> model ( 'logbook_model' );
2024-09-11 08:36:26 +00:00
2025-12-05 06:39:44 +00:00
// Get parameters
2021-03-08 20:20:05 +01:00
$station_id = $this -> security -> xss_clean ( $this -> input -> post ( 'station_profile' ));
2025-12-05 06:39:44 +00:00
$from = $this -> input -> post ( 'from' );
$to = $this -> input -> post ( 'to' );
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
2025-11-30 11:00:34 +00:00
if ( clubaccess_check ( 6 ) && ! clubaccess_check ( 9 )) {
$onlyop = ( $this -> session -> userdata ( 'operator_callsign' ) ? ? '' );
} else {
$onlyop = null ;
}
2025-12-05 06:39:44 +00:00
// Set headers for direct download
$filename = $this -> session -> userdata ( 'user_callsign' ) . '-' . date ( 'Ymd-Hi' ) . '.adi' ;
header ( 'Content-Type: text/plain; charset=utf-8' );
header ( 'Content-Disposition: attachment; filename="' . $filename . '"' );
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:39:44 +00:00
// Collect QSO IDs for LoTW marking (since we can't access all at once)
$qso_ids_for_lotw = [];
// Stream QSOs in 5K chunks
$offset = 0 ;
$chunk_size = 5000 ;
2024-09-11 08:36:26 +00:00
2025-12-05 06:39:44 +00:00
do {
$qsos = $this -> adif_data -> export_custom_chunked ( $from , $to , $station_id , $exportLotw , $onlyop , $offset , $chunk_size );
if ( $qsos && $qsos -> num_rows () > 0 ) {
foreach ( $qsos -> result () as $qso ) {
echo $this -> adifhelper -> getAdifLine ( $qso );
// Collect IDs for LoTW marking
$qso_ids_for_lotw [] = $qso -> COL_PRIMARY_KEY ;
}
// Free memory
$qsos -> free_result ();
}
2014-09-25 23:09:44 +01:00
2025-12-05 06:39:44 +00:00
$offset += $chunk_size ;
} while ( $qsos && $qsos -> num_rows () > 0 );
2024-09-11 08:36:26 +00:00
2025-12-05 06:39:44 +00:00
// Handle LoTW marking after export
if (( clubaccess_check ( 9 )) && ( $this -> input -> post ( 'markLotw' ) == 1 ) && ! empty ( $qso_ids_for_lotw )) {
foreach ( $qso_ids_for_lotw as $qso_id ) {
2025-12-27 22:36:30 +01:00
$this -> logbook_model -> mark_lotw_sent ( $qso_id );
2024-09-11 08:25:06 +00:00
}
}
2025-12-05 06:39:44 +00:00
// Stop execution
exit ;
2024-09-11 08:25:06 +00:00
}
2020-04-01 08:43:08 +02:00
2025-11-30 09:13:22 +00:00
public function export_lotw () {
// Check if user has access to lotw tab
$this -> require_tab_access ( 'lotw' );
2013-03-04 22:57:29 -06:00
// 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' );
2025-12-27 22:24:09 +01:00
$this -> load -> model ( 'logbook_model' );
2013-03-04 22:57:29 -06:00
$data [ 'qsos' ] = $this -> adif_data -> export_lotw ();
$this -> load -> view ( 'adif/data/exportall' , $data );
2014-09-25 23:09:44 +01:00
2025-11-30 11:00:34 +00:00
foreach ( $data [ 'qsos' ] -> result () as $qso ) {
2025-12-27 22:36:30 +01:00
$this -> logbook_model -> mark_lotw_sent ( $qso -> COL_PRIMARY_KEY );
2013-03-06 23:31:19 -06:00
}
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 () {
New Wavelog Contesting and Basics for Wavelog Worker (#3063)
* initial commit for new contesting in Wavelog
* implemented cache buster to match logic from upstream dev branch
* refactore data-store to idb since this will be much faster with a lot of QSOs (scale for the future)
* implementation of other exchange types (wip)
* updated migration version
* renamed mig
* renamed mig
* updated mig
* ESC Handler to reset form
* Add Websocket
* stretch maxDuration warning
We can stretch the maxDuration warning to 2 seconds to allow for more network latency and processing time. The heartbeat is protected against multiple parallel requests, so we can afford to be more lenient with the duration before showing a warning. This should help reduce false positives in environments with higher latency or slower processing.
* worked before warning in qso form
While input the logic checks in the qso list if the callisgn already exists on the same band and mode.
* translations
* fix band buttons
* updated migration after release 2.4.2
* Fixing create new contest, add clubstation permission check, add time check to contests
* Adding attach QSO to Contest
* Remove redundant clubstation checks
* Fix function tip
* Remove time check when launch contest
* Fixing contest attach main logbook, adding detach contest qso
* Enable clubstation contest QSO detach attach
* add space handler for callsign input
* set rst default to 599 for cw, 59 for others
* add grid and refactor some ui to make a better fitting here and there
* adjust tabindex
* add "copy exchange to" feature
* fix css for all themes
* adif and cbr export
* fix bug with wrong operator callsign
* add exchange type "exchange+grid"
* introduce new logic for exchangetypes and more flexible order selection
* fix broken qso list scroll
* legacy import feature
* more precise wording
* feat: inline editing of QSOs by double click in the QSO list
* redirect cabrillo to contesting manager
* Fix QSO permission check
* remove unused cabrillo stuff
* remove duplicate function
* fix check if worked before on band change
tnx to @int2001
* fix flash message for legacy importer
* make dropdown searchable and place "other" at the top
* add hint about "Other" contest
* avoid "flash" of winkeyer settings in qso logging, it shows up if cw is set as mode
* winkeyer for the new contesting
need proper testing by @AndreasK79 and @phl0 since I don't have a winkeyer myself. I tested with a python simulator...
* english comments
* proper singular/plural
* fix dropdown
* preselect active station location
* allow editing time aswell
* fix fontsize in radio buttons
* remove redundant qso count query
* cache last updated value for contest qsos to reduce db load
* index on user id
* cache also qso count
* you can now resize windows also on the edges
requested by @xyz667 in https://github.com/wavelog/wavelog/pull/3063#issuecomment-4557850867
* fix oversized clock
* click to prepare logging for contesting
Logic:
- if qso windows is open, call is sent to qso form
- if contest log is open, call is sent to contest log
- if both are open, call is sent to contest log
- if none is open, click opens qso form and call is sent to qso form
* handle exchange s prefill with data from the last qso and make exchange always uppercase
* add dropdown to qso list with option to delete qsos
* language fixes
* english comments
* center text
* fix missing dropdown on new qsos
* add date presets for contest session creator/editor
* basic worker implementation
* support multiple workers for clustering
* remove unnecessary node column
* simple availability check
* websocket for contesting
* bonus: add vip for visibilty in debug view
* use vip if available
* worker disabled in debug view if disabled in config
* racecondition for winkeyer breaks edit/delete dropdown
* racecondition for winkeyer breaks edit/delete dropdown
* qso handling for worker in contesting, no high interval heartbeat anymore
* clear heartbeat intervall
* fix some timing bugs
* remove dedicated worker controller as it's not needed
* handle whitespace
* trigger sync engine after processing QSO sync response and adjust last sync time to avoid spurious resyncs
* fix set and setLocal
* fix change detection and sync logic
* fix the lost of seconds due to edit
* fix table rendering
* watermark handling for true delta
* remove caching as it brings more problems here as benefits
* make serial as default exchangetype
* Add clarification on cluster setup requirements for worker URLs
* add operator to qso list if this is a clubstation
* fix bug for editing qsos in clubmode
* remove redundant code
* integers must be null in database
* fix bug in tabindex if 3 exchangefields are configured (serial, exchange, grid)
* nice contesting map (draft)
* map autofit
* add grid overlay
* calculate distanz and azimuth
* include rotor control via waveloggate (ws only)
* implement simple dedicated callbook lookup
* simpler and faster lookup
* option in contest session to disabled callbook lookup and only calculate dxcc
* syntax issue
* fix bug in CBR export
* catch empty result on contest
* remove some leftovers
* removed some comments
* remove unused stuff
* removed old todos/comments
* add 4s timeout for ajax transport
* you need to be admin for this
* translations
* add option to delete qso's aswell when deleting a session (opt in)
* add quickstart button in manager
* removed old todo
* fix "grows to bottom"
* disable "copy exchange to" if no exchange is set
* clear map on qso clear aswell
* same for scp
* updated documentation link
* calculate distanze and azimut also on grid only
* better space usage in qso input
* callbook db first approach, online lookup can be disabled while being cached for all users when enabled
* some input validation
* use only one sot for qrgtoband
* basic stats component
* fix html encoding
* render all aswell
* ascii
* store locally which time frame the user wants
* sync settings and warn user if something happend on the backend
* dev leftover
* show errors if callbook fails or callsign is invalid
* easier syntax
* Revert "easier syntax" - that was a mistake
This reverts commit 80c75dbf1e6c832f8d0616ea56b8b55d96c36418.
* fix for callbook lookup
* make pathline more visible
* better visibility of qsos
* add classic coordinates bar to the map
* fix bug in stats
* stretch max duration to 4s.. just in case
* simple sanity check in js to prevent unnecessary callbook lookups
* simulate tab after filling the call from scp
* fix poll radios with enabled worker
* reset po/mo files back to upstream/dev
* split contest exports, add back reg1test edi format
* keep the menu item but redirect to contesting
* better syntax and bugfix
* break it down further and fix typo ("constraint")
* use monospace font for input fields
* fix: in worker driven mode we need to do the heartbeat also on not focused windows otherwise we loose this contact
* fix: error handling on invalid times
* wavelog Ø
* more styling
* band lowercase fix
* Other is not a very descriptive title for a contest logger window, so we rename it to "Contest"
* custom contest name
* compare the whole array instead just a few settings
---------
Co-authored-by: int2001 <joerg@dj7nt.de>
Co-authored-by: HadleySo <71105018+HadleySo@users.noreply.github.com>
Co-authored-by: DB4SCW <dev@db4scw.de>
2026-06-14 14:23:00 +02:00
$this -> load -> model ( 'contest_admin_model' );
$data [ 'contests' ] = $this -> contest_admin_model -> getActiveContests ();
2024-03-20 07:47:34 +00:00
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' );
2025-11-30 12:37:07 +00:00
$data [ 'cd_p_level' ] = ( $this -> session -> userdata ( 'cd_p_level' ) ? ? 0 );
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 ;
}
2026-06-20 14:09:33 -07:00
if ( ! empty ( $this -> session -> userdata ( 'user_stations_active_log_only' ))) {
$this -> load -> model ( 'logbooks_model' );
$data [ 'station_profile' ] = $this -> logbooks_model -> list_logbooks_linked ( $this -> session -> userdata ( 'active_station_logbook' ));
2026-06-21 11:44:53 -07:00
$data [ 'stations_active_log_only' ] = true ;
2026-06-20 14:09:33 -07:00
} else {
$data [ 'station_profile' ] = $this -> stations -> all_of_user ();
2026-06-21 11:44:53 -07:00
$data [ 'stations_active_log_only' ] = false ;
2026-06-20 14:09:33 -07:00
}
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
2025-11-30 09:13:22 +00:00
// Pass allowed tabs to view
$data [ 'allowed_tabs' ] = $this -> get_allowed_tabs ();
2019-06-30 00:06:24 +01:00
$this -> load -> view ( 'interface_assets/header' , $data );
2025-11-30 09:13:22 +00:00
$this -> load -> view ( 'adif/import' , $data );
2019-06-30 00:06:24 +01:00
$this -> load -> view ( 'interface_assets/footer' );
}
2013-08-17 16:24:16 +01:00
public function import () {
2025-11-30 09:13:22 +00:00
// Check if user has access to import tab
$this -> require_tab_access ( '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
2025-11-30 09:13:22 +00:00
// Pass allowed tabs to view
$data [ 'allowed_tabs' ] = $this -> get_allowed_tabs ();
2026-07-14 16:31:16 +00:00
$data [ 'stations_active_log_only' ] = ! empty ( $this -> session -> userdata ( 'user_stations_active_log_only' ));
2025-11-30 09:13:22 +00:00
2026-06-17 10:08:32 +00:00
$this -> load -> model ( 'contest_admin_model' );
$data [ 'contests' ] = $this -> contest_admin_model -> getActiveContests ();
$data [ 'active_station_id' ] = $active_station_id ; // local var, set above
$data [ 'cd_p_level' ] = ( $this -> session -> userdata ( 'cd_p_level' ) ? ? 0 );
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 ;
}
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 ();
2025-08-22 15:04:11 +02:00
$custom_errors [ 'errormessage' ] = " " ;
$alladif = [];
2024-11-26 11:01:39 +00:00
$contest_qso_infos = [];
2024-04-25 09:10:46 +00:00
while ( $record = $this -> adif_parser -> get_record ()) {
2025-08-22 15:04:11 +02:00
2025-11-14 11:12:35 +01:00
// Handle slashed zeros
2025-12-22 17:18:54 +01:00
if ( isset ( $record [ 'call' ])) {
$record [ 'call' ] = str_replace ( 'Ø' , " 0 " , $record [ 'call' ]);
}
2025-11-14 11:12:35 +01:00
if (( $record [ 'operator' ] ? ? '' ) != '' ) {
$record [ 'operator' ] = str_replace ( 'Ø' , " 0 " , $record [ 'operator' ]);
}
if (( $record [ 'station_callsign' ] ? ? '' ) != '' ) {
$record [ 'station_callsign' ] = str_replace ( 'Ø' , " 0 " , $record [ 'station_callsign' ]);
}
if (( $record [ 'owner_callsign' ] ? ? '' ) != '' ) {
$record [ 'owner_callsign' ] = str_replace ( 'Ø' , " 0 " , $record [ 'owner_callsign' ]);
}
2024-11-26 11:01:39 +00:00
//overwrite the contest id if user chose a contest in UI
2024-03-20 07:47:34 +00:00
if ( $contest != '' ) {
2024-11-26 11:01:39 +00:00
$record [ 'contest_id' ] = $contest ;
2024-03-20 07:47:34 +00:00
}
2024-11-26 11:01:39 +00:00
2025-11-30 08:13:53 +00:00
//handle club operator based on permission level
$user_permission_level = $this -> session -> userdata ( 'cd_p_level' );
if ( $user_permission_level >= 9 ) {
// Club Officer: Allow operator override
if ( $club_operator != '' ) {
$record [ 'operator' ] = strtoupper ( $club_operator );
}
} elseif ( $user_permission_level == 6 ) {
2025-12-01 11:58:50 +00:00
// ClubMemberADIF: Force operator to current user, ignore input
2025-11-30 08:13:53 +00:00
$record [ 'operator' ] = strtoupper ( $this -> session -> userdata ( 'operator_callsign' ));
2025-01-08 12:02:47 +00:00
}
2025-11-30 08:13:53 +00:00
// Note: Regular Club Member (Level 3) should not reach here due to constructor permission check
2025-01-08 11:59:55 +00:00
2024-11-26 11:01:39 +00:00
//check if contest_id exists in record and extract all found contest_ids
if ( array_key_exists ( 'contest_id' , $record )){
$contest_id = $record [ 'contest_id' ];
2024-11-26 11:35:06 +00:00
if ( $contest_id != '' ){
if ( array_key_exists ( $contest_id , $contest_qso_infos )){
$contest_qso_infos [ $contest_id ] += 1 ;
} else {
$contest_qso_infos [ $contest_id ] = 1 ;
}
2024-11-26 11:01:39 +00:00
}
}
2024-01-11 14:52:17 +00:00
if ( count ( $record ) == 0 ) {
break ;
};
2025-08-22 15:04:11 +02:00
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-10-07 04:11:50 +00:00
if (( $this -> input -> post ( 'skipDuplicate' , true ) ? ? '' ) == '1' ) { // Reverse Logic. View states: "Import Dupes", while Flag is called skipDuplicates
$skipDups = false ; // Box ticked? Means: Import Dupes
} else {
$skipDups = true ; // Box not ticked? Means: Skip Dupes, don't import them
}
2026-03-31 15:53:24 +08:00
$custom_errors = $this -> logbook_model -> import_bulk ( $alladif , $this -> input -> post ( 'station_profile' , TRUE ), $skipDups , $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' ), $this -> input -> post ( 'skipGridCheck' ));
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 {
2025-08-22 15:04:11 +02:00
$custom_errors [ 'errormessage' ] = __ ( " 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 " );
2025-08-22 15:04:11 +02:00
$data [ 'adif_errors' ] = $custom_errors [ 'errormessage' ];
2026-04-02 10:01:52 +00:00
$data [ 'structured_errors' ] = $custom_errors [ 'structured_errors' ] ? ? [];
2025-08-22 15:04:11 +02:00
$data [ 'qsocount' ] = $custom_errors [ 'qsocount' ] ? ? 0 ;
2023-10-16 09:34:29 +02:00
$data [ 'skip_dupes' ] = $this -> input -> post ( 'skipDuplicate' );
2026-07-11 16:08:29 +02:00
$data [ 'imported_contests' ] = $contest_qso_infos ? ? [];
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 () {
2025-11-30 09:13:22 +00:00
// Check if user has access to dcl tab
$this -> require_tab_access ( 'dcl' );
2023-10-17 16:19:05 +02:00
$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 " ;
2025-11-30 09:13:22 +00:00
// Pass allowed tabs to view
$data [ 'allowed_tabs' ] = $this -> get_allowed_tabs ();
2026-07-14 16:31:16 +00:00
$data [ 'stations_active_log_only' ] = ! empty ( $this -> session -> userdata ( 'user_stations_active_log_only' ));
2026-07-14 16:43:43 +00:00
$data [ 'cd_p_level' ] = ( $this -> session -> userdata ( 'cd_p_level' ) ? ? 0 );
$this -> load -> model ( 'contest_admin_model' );
$data [ 'contests' ] = $this -> contest_admin_model -> getActiveContests ();
$data [ 'active_station_id' ] = $this -> stations -> find_active ();
2025-11-30 09:13:22 +00:00
2023-10-17 16:19:05 +02:00
$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
}
2025-09-04 13:54:49 +02:00
public function pota () {
2025-11-30 09:13:22 +00:00
// Check if user has access to pota tab
$this -> require_tab_access ( 'pota' );
2025-09-04 13:54:49 +02:00
$this -> load -> model ( 'stations' );
$data [ 'station_profile' ] = $this -> stations -> all_of_user ();
$data [ 'page_title' ] = __ ( " POTA Import " );
$data [ 'tab' ] = " potab " ;
2025-11-30 09:13:22 +00:00
// Pass allowed tabs to view
$data [ 'allowed_tabs' ] = $this -> get_allowed_tabs ();
2026-07-14 16:31:16 +00:00
$data [ 'stations_active_log_only' ] = ! empty ( $this -> session -> userdata ( 'user_stations_active_log_only' ));
2026-07-14 16:43:43 +00:00
$data [ 'cd_p_level' ] = ( $this -> session -> userdata ( 'cd_p_level' ) ? ? 0 );
$this -> load -> model ( 'contest_admin_model' );
$data [ 'contests' ] = $this -> contest_admin_model -> getActiveContests ();
$data [ 'active_station_id' ] = $this -> stations -> find_active ();
2025-11-30 09:13:22 +00:00
2025-09-04 13:54:49 +02:00
$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' );
if ( ! $this -> load -> is_loaded ( 'adif_parser' )) {
$this -> load -> library ( 'adif_parser' );
}
$this -> adif_parser -> load_from_file ( './uploads/' . $data [ 'upload_data' ][ 'file_name' ]);
$this -> adif_parser -> initialize ();
$error_count = array ( 0 , 0 , 0 );
$custom_errors = " " ;
while ( $record = $this -> adif_parser -> get_record ())
{
if ( count ( $record ) == 0 ) {
break ;
};
$pota_result = $this -> logbook_model -> update_pota ( $record );
if ( ! empty ( $pota_result )) {
switch ( $pota_result [ 0 ]) {
case 0 :
$error_count [ 0 ] ++ ;
break ;
case 1 :
$error_count [ 1 ] ++ ;
break ;
case 2 :
$custom_errors .= $pota_result [ 1 ];
$error_count [ 2 ] ++ ;
}
}
};
unlink ( './uploads/' . $data [ 'upload_data' ][ 'file_name' ]);
$data [ 'pota_error_count' ] = $error_count ;
$data [ 'pota_errors' ] = $custom_errors ;
$data [ 'page_title' ] = __ ( " POTA Data Imported " );
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'adif/pota_success' );
$this -> load -> view ( 'interface_assets/footer' );
}
}
2011-09-21 14:30:01 +01:00
}
2014-09-25 23:09:44 +01:00
/* End of file adif.php */