1- <?php if ( ! defined ('BASEPATH ' )) exit ('No direct script access allowed ' );
1+ <?php if (! defined ('BASEPATH ' )) exit ('No direct script access allowed ' );
22
33/*
44 Controller to interact with the hrdlog.net API
@@ -20,11 +20,12 @@ public function upload() {
2020
2121 if ($ station_ids ) {
2222 foreach ($ station_ids as $ station ) {
23+ $ hrdlog_username = $ station ->hrdlog_username ;
2324 $ hrdlog_code = $ station ->hrdlog_code ;
24- if ($ this ->mass_upload_qsos ($ station ->station_id , $ hrdlog_code )) {
25+ if ($ this ->mass_upload_qsos ($ station ->station_id , $ hrdlog_username , $ hrdlog_code )) {
2526 echo "QSOs have been uploaded to hrdlog.net. " ;
2627 log_message ('info ' , 'QSOs have been uploaded to hrdlog.net. ' );
27- } else {
28+ } else {
2829 echo "No QSOs found for upload. " ;
2930 log_message ('info ' , 'No QSOs found for upload. ' );
3031 }
@@ -48,49 +49,53 @@ function setOptions() {
4849 * Function gets all QSOs from given station_id, that are not previously uploaded to hrdlog.
4950 * Adif is build for each qso, and then uploaded, one at a time
5051 */
51- function mass_upload_qsos ($ station_id , $ hrdlog_code ) {
52- $ i = 0 ;
53- $ data ['qsos ' ] = $ this ->logbook_model ->get_hrdlog_qsos ($ station_id );
54- $ errormessages =array ();
55-
56- $ CI =& get_instance ();
57- $ CI ->load ->library ('AdifHelper ' );
58-
59- if ($ data ['qsos ' ]) {
60- foreach ($ data ['qsos ' ]->result () as $ qso ) {
61- $ adif = $ CI ->adifhelper ->getAdifLine ($ qso );
62-
63- if ($ qso ->COL_HRDLOG_QSO_UPLOAD_STATUS == 'M ' ) {
64- $ result = $ this ->logbook_model ->push_qso_to_hrdlog ($ hrdlog_code , $ qso ->COL_STATION_CALLSIGN ,$ adif , true );
65- } else {
66- $ result = $ this ->logbook_model ->push_qso_to_hrdlog ($ hrdlog_code , $ qso ->COL_STATION_CALLSIGN ,$ adif );
67- }
68-
69- if ( ($ result ['status ' ] == 'OK ' ) || ( ($ result ['status ' ] == 'error ' ) || ($ result ['status ' ] == 'duplicate ' )) ){
70- $ this ->markqso ($ qso ->COL_PRIMARY_KEY );
71- $ i ++;
72- } elseif ((substr ($ result ['status ' ],0 ,11 ) == 'auth_error ' )) {
73- log_message ('error ' , 'hrdlog upload failed for qso: Call: ' . $ qso ->COL_CALL . ' Band: ' . $ qso ->COL_BAND . ' Mode: ' . $ qso ->COL_MODE . ' Time: ' . $ qso ->COL_TIME_ON );
74- log_message ('error ' , 'hrdlog upload failed with the following message: ' .$ result ['message ' ]);
75- log_message ('error ' , 'hrdlog upload stopped for Station_ID: ' .$ station_id );
76- $ errormessages [] = $ result ['message ' ] . 'Invalid HRDLog-Code, stopped at Call: ' . $ qso ->COL_CALL . ' Band: ' . $ qso ->COL_BAND . ' Mode: ' . $ qso ->COL_MODE . ' Time: ' . $ qso ->COL_TIME_ON ;
77- break ; /* If key is invalid, immediate stop syncing for more QSOs of this station */
78- } else {
79- log_message ('error ' , 'hrdlog upload failed for qso: Call: ' . $ qso ->COL_CALL . ' Band: ' . $ qso ->COL_BAND . ' Mode: ' . $ qso ->COL_MODE . ' Time: ' . $ qso ->COL_TIME_ON );
80- log_message ('error ' , 'hrdlog upload failed with the following message: ' .$ result ['message ' ]);
81- $ errormessages [] = $ result ['message ' ] . ' Call: ' . $ qso ->COL_CALL . ' Band: ' . $ qso ->COL_BAND . ' Mode: ' . $ qso ->COL_MODE . ' Time: ' . $ qso ->COL_TIME_ON ;
82- }
83- }
84- $ result ['status ' ] = 'OK ' ;
85- $ result ['count ' ] = $ i ;
86- $ result ['errormessages ' ] = $ errormessages ;
87- return $ result ;
88- } else {
89- $ result ['status ' ] = 'Error ' ;
90- $ result ['count ' ] = $ i ;
91- $ result ['errormessages ' ] = $ errormessages ;
92- return $ result ;
93- }
52+ function mass_upload_qsos ($ station_id , $ hrdlog_username , $ hrdlog_code ) {
53+ $ i = 0 ;
54+ $ data ['qsos ' ] = $ this ->logbook_model ->get_hrdlog_qsos ($ station_id );
55+ $ errormessages = array ();
56+
57+ $ this ->load ->library ('AdifHelper ' );
58+
59+ if ($ data ['qsos ' ]) {
60+ foreach ($ data ['qsos ' ]->result () as $ qso ) {
61+ $ adif = $ this ->adifhelper ->getAdifLine ($ qso );
62+
63+ if ($ qso ->COL_HRDLOG_QSO_UPLOAD_STATUS == 'M ' ) {
64+ $ result = $ this ->logbook_model ->push_qso_to_hrdlog ($ hrdlog_username , $ hrdlog_code , $ adif , true );
65+ } else {
66+ $ result = $ this ->logbook_model ->push_qso_to_hrdlog ($ hrdlog_username , $ hrdlog_code , $ adif );
67+ }
68+
69+ if (($ result ['status ' ] == 'OK ' ) || (($ result ['status ' ] == 'error ' ) || ($ result ['status ' ] == 'duplicate ' ))) {
70+ $ this ->markqso ($ qso ->COL_PRIMARY_KEY );
71+ $ i ++;
72+ $ result ['status ' ] = 'OK ' ;
73+ } elseif ((substr ($ result ['status ' ], 0 , 11 ) == 'auth_error ' )) {
74+ log_message ('error ' , 'hrdlog upload failed for qso: Call: ' . $ qso ->COL_CALL . ' Band: ' . $ qso ->COL_BAND . ' Mode: ' . $ qso ->COL_MODE . ' Time: ' . $ qso ->COL_TIME_ON );
75+ log_message ('error ' , 'hrdlog upload failed with the following message: ' . $ result ['message ' ]);
76+ log_message ('error ' , 'hrdlog upload stopped for Station_ID: ' . $ station_id );
77+ $ errormessages [] = $ result ['message ' ] . 'Invalid HRDLog-Code, stopped at Call: ' . $ qso ->COL_CALL . ' Band: ' . $ qso ->COL_BAND . ' Mode: ' . $ qso ->COL_MODE . ' Time: ' . $ qso ->COL_TIME_ON ;
78+ $ result ['status ' ] = 'Error ' ;
79+ break ; /* If key is invalid, immediate stop syncing for more QSOs of this station */
80+ } else {
81+ log_message ('error ' , 'hrdlog upload failed for qso: Call: ' . $ qso ->COL_CALL . ' Band: ' . $ qso ->COL_BAND . ' Mode: ' . $ qso ->COL_MODE . ' Time: ' . $ qso ->COL_TIME_ON );
82+ log_message ('error ' , 'hrdlog upload failed with the following message: ' . $ result ['message ' ]);
83+ $ result ['status ' ] = 'Error ' ;
84+ $ errormessages [] = $ result ['message ' ] . ' Call: ' . $ qso ->COL_CALL . ' Band: ' . $ qso ->COL_BAND . ' Mode: ' . $ qso ->COL_MODE . ' Time: ' . $ qso ->COL_TIME_ON ;
85+ }
86+ }
87+ if ($ i == 0 ) {
88+ $ result ['status ' ]='Error ' ;
89+ }
90+ $ result ['count ' ] = $ i ;
91+ $ result ['errormessages ' ] = $ errormessages ;
92+ return $ result ;
93+ } else {
94+ $ result ['status ' ] = 'Error ' ;
95+ $ result ['count ' ] = $ i ;
96+ $ result ['errormessages ' ] = $ errormessages ;
97+ return $ result ;
98+ }
9499 }
95100
96101 /*
@@ -108,7 +113,7 @@ public function export() {
108113
109114 $ data ['page_title ' ] = "HRDlog.net Logbook " ;
110115
111- $ data ['station_profiles ' ] = $ this ->stations ->all_of_user ();
116+ $ data ['station_profiles ' ] = $ this ->stations ->all_of_user ();
112117 $ data ['station_profile ' ] = $ this ->stations ->stations_with_hrdlog_code ();
113118
114119 $ this ->load ->view ('interface_assets/header ' , $ data );
@@ -126,10 +131,11 @@ public function upload_station() {
126131 $ postData = $ this ->input ->post ();
127132
128133 $ this ->load ->model ('logbook_model ' );
129- $ result = $ this ->logbook_model ->exists_hrdlog_code ($ postData ['station_id ' ]);
134+ $ result = $ this ->logbook_model ->exists_hrdlog_credentials ($ postData ['station_id ' ]);
135+ $ hrdlog_username = $ result ->hrdlog_username ;
130136 $ hrdlog_code = $ result ->hrdlog_code ;
131137 header ('Content-type: application/json ' );
132- $ result = $ this ->mass_upload_qsos ($ postData ['station_id ' ], $ hrdlog_code );
138+ $ result = $ this ->mass_upload_qsos ($ postData ['station_id ' ], $ hrdlog_username , $ hrdlog_code );
133139 if ($ result ['status ' ] == 'OK ' ) {
134140 $ stationinfo = $ this ->stations ->stations_with_hrdlog_code ();
135141 $ info = $ stationinfo ->result ();
@@ -141,31 +147,31 @@ public function upload_station() {
141147 echo json_encode ($ data );
142148 } else {
143149 $ data ['status ' ] = 'Error ' ;
144- $ data ['info ' ] = 'Error: No QSOs found to upload. ' ;
150+ $ data ['info ' ] = 'No QSOs found to upload. ' ;
145151 $ data ['errormessages ' ] = $ result ['errormessages ' ];
146152 echo json_encode ($ data );
147153 }
148154 }
149155
150- public function mark_hrdlog () {
151- // Set memory limit to unlimited to allow heavy usage
152- ini_set ('memory_limit ' , '-1 ' );
156+ public function mark_hrdlog () {
157+ // Set memory limit to unlimited to allow heavy usage
158+ ini_set ('memory_limit ' , '-1 ' );
153159
154- $ station_id = $ this ->security ->xss_clean ($ this ->input ->post ('station_profile ' ));
160+ $ station_id = $ this ->security ->xss_clean ($ this ->input ->post ('station_profile ' ));
155161
156- $ this ->load ->model ('adif_data ' );
162+ $ this ->load ->model ('adif_data ' );
157163
158- $ data ['qsos ' ] = $ this ->adif_data ->export_custom ($ this ->input ->post ('from ' ), $ this ->input ->post ('to ' ), $ station_id );
164+ $ data ['qsos ' ] = $ this ->adif_data ->export_custom ($ this ->input ->post ('from ' ), $ this ->input ->post ('to ' ), $ station_id );
159165
160- $ this ->load ->model ('logbook_model ' );
166+ $ this ->load ->model ('logbook_model ' );
161167
162- foreach ($ data ['qsos ' ]->result () as $ qso )
168+ foreach ($ data ['qsos ' ]->result () as $ qso )
163169 {
164- $ this ->logbook_model ->mark_hrdlog_qsos_sent ($ qso ->COL_PRIMARY_KEY );
165- }
170+ $ this ->logbook_model ->mark_hrdlog_qsos_sent ($ qso ->COL_PRIMARY_KEY );
171+ }
166172
167- $ this ->load ->view ('interface_assets/header ' , $ data );
168- $ this ->load ->view ('hrdlog/mark_hrdlog ' , $ data );
169- $ this ->load ->view ('interface_assets/footer ' );
170- }
173+ $ this ->load ->view ('interface_assets/header ' , $ data );
174+ $ this ->load ->view ('hrdlog/mark_hrdlog ' , $ data );
175+ $ this ->load ->view ('interface_assets/footer ' );
176+ }
171177}
0 commit comments