@@ -168,7 +168,7 @@ function json($tempcallsign, $temptype, $tempband, $tempmode, $tempstation_id =
168168 $ return ['confirmed ' ] = $ this ->confirmed_grid_before ($ return ['callsign_qra ' ], $ type , $ band , $ mode );
169169
170170 if ($ this ->session ->userdata ('user_show_profile_image ' )) {
171- if (isset ($ callbook )) {
171+ if (isset ($ callbook ) && isset ( $ callbook [ ' image ' ]) ) {
172172 if ($ callbook ['image ' ] == "" ) {
173173 $ return ['image ' ] = "n/a " ;
174174 } else {
@@ -851,27 +851,61 @@ function partial($id) {
851851 $ qrz_session_key = $ this ->qrz ->session ($ this ->config ->item ('qrz_username ' ), $ this ->config ->item ('qrz_password ' ));
852852 $ this ->session ->set_userdata ('qrz_session_key ' , $ qrz_session_key );
853853 }
854- $ data = $ this ->qrz ->search ($ id , $ this ->session ->userdata ('qrz_session_key ' ), $ this ->config ->item ('use_fullname ' ));
855-
856- if (empty ($ data ['callsign ' ]))
857- {
858- $ qrz_session_key = $ this ->qrz ->session ($ this ->config ->item ('qrz_username ' ), $ this ->config ->item ('qrz_password ' ));
859- $ this ->session ->set_userdata ('qrz_session_key ' , $ qrz_session_key );
860- $ data = $ this ->qrz ->search ($ id , $ this ->session ->userdata ('qrz_session_key ' ), $ this ->config ->item ('use_fullname ' ));
861- }
854+ $ callsign ['callsign ' ] = $ this ->qrz ->search ($ id , $ this ->session ->userdata ('qrz_session_key ' ), $ this ->config ->item ('use_fullname ' ));
855+
856+ if (empty ($ callsign ['callsign ' ]['callsign ' ])) {
857+ $ qrz_session_key = $ this ->qrz ->session ($ this ->config ->item ('qrz_username ' ), $ this ->config ->item ('qrz_password ' ));
858+ $ this ->session ->set_userdata ('qrz_session_key ' , $ qrz_session_key );
859+ $ callsign ['callsign ' ] = $ this ->qrz ->search ($ id , $ this ->session ->userdata ('qrz_session_key ' ), $ this ->config ->item ('use_fullname ' ));
860+ }
861+ } else if ($ this ->config ->item ('callbook ' ) == "hamqth " && $ this ->config ->item ('hamqth_username ' ) != null && $ this ->config ->item ('hamqth_password ' ) != null ) {
862+ // Load the HamQTH library
863+ $ this ->load ->library ('hamqth ' );
864+
865+ if (!$ this ->session ->userdata ('hamqth_session_key ' )) {
866+ $ hamqth_session_key = $ this ->hamqth ->session ($ this ->config ->item ('hamqth_username ' ), $ this ->config ->item ('hamqth_password ' ));
867+ $ this ->session ->set_userdata ('hamqth_session_key ' , $ hamqth_session_key );
868+ }
869+
870+ $ callsign ['callsign ' ] = $ this ->hamqth ->search ($ id , $ this ->session ->userdata ('hamqth_session_key ' ));
871+
872+ // If HamQTH session has expired, start a new session and retry the search.
873+ if ($ callsign ['callsign ' ]['error ' ] == "Session does not exist or expired " ) {
874+ $ hamqth_session_key = $ this ->hamqth ->session ($ this ->config ->item ('hamqth_username ' ), $ this ->config ->item ('hamqth_password ' ));
875+ $ this ->session ->set_userdata ('hamqth_session_key ' , $ hamqth_session_key );
876+ $ callsign ['callsign ' ] = $ this ->hamqth ->search ($ callsign , $ this ->session ->userdata ('hamqth_session_key ' ));
877+ }
878+ if (isset ($ data ['callsign ' ]['gridsquare ' ])) {
879+ $ CI = &get_instance ();
880+ $ CI ->load ->model ('logbook_model ' );
881+ $ callsign ['grid_worked ' ] = $ CI ->logbook_model ->check_if_grid_worked_in_logbook (strtoupper (substr ($ data ['callsign ' ]['gridsquare ' ],0 ,4 )), 0 , $ this ->session ->userdata ('user_default_band ' ));
882+ }
883+ if (isset ($ callsign ['callsign ' ]['error ' ])) {
884+ $ callsign ['error ' ] = $ callsign ['callsign ' ]['error ' ];
885+ }
886+ } else {
887+ $ callsign ['error ' ] = 'Lookup not configured. Please review configuration. ' ;
862888 }
863889
864890 // There's no hamli integration? Disabled for now.
865891 /*else {
866892 // Lookup using hamli
867893 $this->load->library('hamli');
868894
869- $data ['callsign'] = $this->hamli->callsign($id);
895+ $callsign ['callsign'] = $this->hamli->callsign($id);
870896 }*/
871897
872- $ data ['id ' ] = strtoupper ($ id );
898+ if (isset ($ callsign ['callsign ' ]['gridsquare ' ])) {
899+ $ CI = &get_instance ();
900+ $ CI ->load ->model ('logbook_model ' );
901+ $ callsign ['grid_worked ' ] = $ CI ->logbook_model ->check_if_grid_worked_in_logbook (strtoupper (substr ($ callsign ['callsign ' ]['gridsquare ' ],0 ,4 )), 0 , $ this ->session ->userdata ('user_default_band ' ));
902+ }
903+ if (isset ($ callsign ['callsign ' ]['error ' ])) {
904+ $ callsign ['error ' ] = $ callsign ['callsign ' ]['error ' ];
905+ }
906+ $ callsign ['id ' ] = strtoupper ($ id );
873907
874- return $ this ->load ->view ('search/result ' , $ data , true );
908+ return $ this ->load ->view ('search/result ' , $ callsign , true );
875909 }
876910 }
877911
@@ -927,8 +961,33 @@ function search_result($id="", $id2="") {
927961 if (isset ($ data ['callsign ' ]['error ' ])) {
928962 $ data ['error ' ] = $ data ['callsign ' ]['error ' ];
929963 }
964+ } else if ($ this ->config ->item ('callbook ' ) == "hamqth " && $ this ->config ->item ('hamqth_username ' ) != null && $ this ->config ->item ('hamqth_password ' ) != null ) {
965+ // Load the HamQTH library
966+ $ this ->load ->library ('hamqth ' );
967+
968+ if (!$ this ->session ->userdata ('hamqth_session_key ' )) {
969+ $ hamqth_session_key = $ this ->hamqth ->session ($ this ->config ->item ('hamqth_username ' ), $ this ->config ->item ('hamqth_password ' ));
970+ $ this ->session ->set_userdata ('hamqth_session_key ' , $ hamqth_session_key );
971+ }
972+
973+ $ data ['callsign ' ] = $ this ->hamqth ->search ($ id , $ this ->session ->userdata ('hamqth_session_key ' ));
974+
975+ // If HamQTH session has expired, start a new session and retry the search.
976+ if ($ data ['callsign ' ]['error ' ] == "Session does not exist or expired " ) {
977+ $ hamqth_session_key = $ this ->hamqth ->session ($ this ->config ->item ('hamqth_username ' ), $ this ->config ->item ('hamqth_password ' ));
978+ $ this ->session ->set_userdata ('hamqth_session_key ' , $ hamqth_session_key );
979+ $ data ['callsign ' ] = $ this ->hamqth ->search ($ callsign , $ this ->session ->userdata ('hamqth_session_key ' ));
980+ }
981+ if (isset ($ data ['callsign ' ]['gridsquare ' ])) {
982+ $ CI = &get_instance ();
983+ $ CI ->load ->model ('logbook_model ' );
984+ $ data ['grid_worked ' ] = $ CI ->logbook_model ->check_if_grid_worked_in_logbook (strtoupper (substr ($ data ['callsign ' ]['gridsquare ' ],0 ,4 )), 0 , $ this ->session ->userdata ('user_default_band ' ));
985+ }
986+ if (isset ($ data ['callsign ' ]['error ' ])) {
987+ $ data ['error ' ] = $ data ['callsign ' ]['error ' ];
988+ }
930989 } else {
931- $ data ['error ' ] = 'No result (qrz not configured) ' ;
990+ $ data ['error ' ] = 'Lookup not configured. Please review configuration. ' ;
932991 } /*else {
933992 // Lookup using hamli
934993 $this->load->library('hamli');
0 commit comments