@@ -160,6 +160,10 @@ public function dxcc()
160160 $ dxcclist = $ this ->dxcc ->fetchdxcc ($ postdata );
161161 $ data ['dxcc_array ' ] = $ this ->dxcc ->get_dxcc_array ($ dxcclist , $ bands , $ postdata );
162162 $ data ['dxcc_summary ' ] = $ this ->dxcc ->get_dxcc_summary ($ bands , $ postdata );
163+
164+ // Calculate continent breakdown and totals
165+ $ data ['continent_breakdown ' ] = $ this ->dxcc ->get_continent_breakdown ($ dxcclist );
166+ $ data ['dxcc_statistics ' ] = $ this ->dxcc ->get_dxcc_statistics ($ data ['dxcc_array ' ], $ postdata );
163167
164168 // Render Page
165169 $ data ['page_title ' ] = "Awards - DXCC " ;
@@ -1290,4 +1294,202 @@ function returnStatus($string)
12901294 }
12911295 }
12921296 }
1293- }
1297+
1298+ /*
1299+ * Get QSOs for a specific DXCC entity
1300+ */
1301+ public function get_dxcc_qsos ()
1302+ {
1303+ $ this ->load ->model ('logbooks_model ' );
1304+
1305+ $ dxcc_id = $ this ->security ->xss_clean ($ this ->input ->post ('dxcc_id ' ));
1306+ $ limit = $ this ->security ->xss_clean ($ this ->input ->post ('limit ' )) ?: 20 ;
1307+
1308+ if (!$ dxcc_id || !is_numeric ($ dxcc_id )) {
1309+ header ('Content-Type: application/json ' );
1310+ echo json_encode (array ('error ' => 'Invalid DXCC ID ' ));
1311+ return ;
1312+ }
1313+
1314+ $ logbooks_locations_array = $ this ->logbooks_model ->list_logbook_relationships ($ this ->session ->userdata ('active_station_logbook ' ));
1315+
1316+ if (!$ logbooks_locations_array ) {
1317+ header ('Content-Type: application/json ' );
1318+ echo json_encode (array ('error ' => 'No logbook data ' ));
1319+ return ;
1320+ }
1321+
1322+ $ location_list = "' " . implode ("',' " , $ logbooks_locations_array ) . "' " ;
1323+
1324+ try {
1325+ // Get QSOs for this DXCC
1326+ $ query = $ this ->db ->query ("
1327+ SELECT
1328+ col_time_on,
1329+ col_call,
1330+ col_band,
1331+ col_mode,
1332+ col_rst_sent,
1333+ col_rst_rcvd,
1334+ col_qsl_sent,
1335+ col_qsl_rcvd,
1336+ COL_LOTW_QSL_SENT,
1337+ COL_LOTW_QSL_RCVD
1338+ FROM " . $ this ->config ->item ('table_name ' ) . "
1339+ WHERE station_id IN ( " . $ location_list . ")
1340+ AND col_dxcc = " . $ dxcc_id . "
1341+ ORDER BY col_time_on DESC
1342+ LIMIT " . intval ($ limit )
1343+ );
1344+
1345+ if ($ query ->num_rows () > 0 ) {
1346+ $ qsos = $ query ->result_array ();
1347+ header ('Content-Type: application/json ' );
1348+ echo json_encode (array ('qsos ' => $ qsos , 'count ' => $ query ->num_rows ()));
1349+ } else {
1350+ header ('Content-Type: application/json ' );
1351+ echo json_encode (array ('qsos ' => array (), 'count ' => 0 ));
1352+ }
1353+ } catch (Exception $ e ) {
1354+ header ('Content-Type: application/json ' );
1355+ echo json_encode (array ('error ' => $ e ->getMessage ()));
1356+ }
1357+ }
1358+
1359+ /*
1360+ * Get QSOs for a specific DXCC entity filtered by status (Confirmed or Worked)
1361+ */
1362+ public function get_dxcc_qsos_by_status ()
1363+ {
1364+ $ this ->load ->model ('logbooks_model ' );
1365+
1366+ $ dxcc_id = $ this ->security ->xss_clean ($ this ->input ->post ('dxcc_id ' ));
1367+ $ status = $ this ->security ->xss_clean ($ this ->input ->post ('status ' ));
1368+ $ limit = $ this ->security ->xss_clean ($ this ->input ->post ('limit ' )) ?: 100 ;
1369+
1370+ if (!$ dxcc_id || !is_numeric ($ dxcc_id ) || !$ status ) {
1371+ header ('Content-Type: application/json ' );
1372+ echo json_encode (array ('error ' => 'Invalid parameters ' , 'count ' => 0 , 'qsos ' => array ()));
1373+ return ;
1374+ }
1375+
1376+ $ logbooks_locations_array = $ this ->logbooks_model ->list_logbook_relationships ($ this ->session ->userdata ('active_station_logbook ' ));
1377+
1378+ if (!$ logbooks_locations_array ) {
1379+ header ('Content-Type: application/json ' );
1380+ echo json_encode (array ('error ' => 'No logbook data ' , 'count ' => 0 , 'qsos ' => array ()));
1381+ return ;
1382+ }
1383+
1384+ $ location_list = "' " . implode ("',' " , $ logbooks_locations_array ) . "' " ;
1385+
1386+ try {
1387+ // Build WHERE clause for status filter
1388+ $ status_where = '' ;
1389+ if ($ status === 'C ' ) {
1390+ // Confirmed: either QSL received or LoTW received
1391+ $ status_where = " AND (col_qsl_rcvd = 1 OR COL_LOTW_QSL_RCVD = 'Y') " ;
1392+ } elseif ($ status === 'W ' ) {
1393+ // Worked but not confirmed: neither QSL nor LoTW received
1394+ $ status_where = " AND (col_qsl_rcvd IS NULL OR col_qsl_rcvd != 1) AND (COL_LOTW_QSL_RCVD IS NULL OR COL_LOTW_QSL_RCVD != 'Y') " ;
1395+ }
1396+
1397+ // Get QSOs for this DXCC filtered by status
1398+ $ query = $ this ->db ->query ("
1399+ SELECT
1400+ col_time_on,
1401+ col_call,
1402+ col_band,
1403+ col_mode,
1404+ col_rst_sent,
1405+ col_rst_rcvd,
1406+ col_qsl_sent,
1407+ col_qsl_rcvd,
1408+ COL_LOTW_QSL_SENT,
1409+ COL_LOTW_QSL_RCVD
1410+ FROM " . $ this ->config ->item ('table_name ' ) . "
1411+ WHERE station_id IN ( " . $ location_list . ")
1412+ AND col_dxcc = " . $ dxcc_id . $ status_where . "
1413+ ORDER BY col_time_on DESC
1414+ LIMIT " . intval ($ limit )
1415+ );
1416+
1417+ if ($ query ->num_rows () > 0 ) {
1418+ $ qsos = $ query ->result_array ();
1419+ header ('Content-Type: application/json ' );
1420+ echo json_encode (array ('qsos ' => $ qsos , 'count ' => $ query ->num_rows ()));
1421+ } else {
1422+ header ('Content-Type: application/json ' );
1423+ echo json_encode (array ('qsos ' => array (), 'count ' => 0 ));
1424+ }
1425+ } catch (Exception $ e ) {
1426+ header ('Content-Type: application/json ' );
1427+ echo json_encode (array ('error ' => $ e ->getMessage (), 'count ' => 0 , 'qsos ' => array ()));
1428+ }
1429+ }
1430+
1431+ /*
1432+ * Get DXCC entities for a specific continent with their status
1433+ */
1434+ public function get_continent_qsos ()
1435+ {
1436+ $ this ->load ->model ('logbooks_model ' );
1437+
1438+ $ continent_code = $ this ->security ->xss_clean ($ this ->input ->post ('continent_code ' ));
1439+
1440+ if (!$ continent_code ) {
1441+ header ('Content-Type: application/json ' );
1442+ echo json_encode (array ('error ' => 'Invalid continent code ' , 'count ' => 0 , 'entities ' => array ()));
1443+ return ;
1444+ }
1445+
1446+ $ logbooks_locations_array = $ this ->logbooks_model ->list_logbook_relationships ($ this ->session ->userdata ('active_station_logbook ' ));
1447+
1448+ if (!$ logbooks_locations_array ) {
1449+ header ('Content-Type: application/json ' );
1450+ echo json_encode (array ('error ' => 'No logbook data ' , 'count ' => 0 , 'entities ' => array ()));
1451+ return ;
1452+ }
1453+
1454+ $ location_list = "' " . implode ("',' " , $ logbooks_locations_array ) . "' " ;
1455+
1456+ try {
1457+ // Get all DXCC entities for this continent with their status in a single query
1458+ $ query = $ this ->db ->query ("
1459+ SELECT
1460+ d.adif,
1461+ d.name,
1462+ d.prefix,
1463+ d.cont,
1464+ CASE
1465+ WHEN MAX(CASE WHEN (c.col_qsl_rcvd = 1 OR c.COL_LOTW_QSL_RCVD = 'Y') THEN 1 ELSE 0 END) = 1 THEN 'confirmed'
1466+ WHEN COUNT(c.col_dxcc) > 0 THEN 'worked'
1467+ ELSE 'unworked'
1468+ END as status
1469+ FROM dxcc_entities d
1470+ LEFT JOIN " . $ this ->config ->item ('table_name ' ) . " c ON d.adif = c.col_dxcc AND c.station_id IN ( " . $ location_list . ")
1471+ WHERE d.cont = ' " . $ this ->db ->escape_like_str ($ continent_code ) . "'
1472+ GROUP BY d.adif, d.name, d.prefix, d.cont
1473+ ORDER BY d.name ASC
1474+ " );
1475+
1476+ $ entities = array ();
1477+ if ($ query ->num_rows () > 0 ) {
1478+ foreach ($ query ->result_array () as $ entity ) {
1479+ $ entities [] = array (
1480+ 'adif ' => $ entity ['adif ' ],
1481+ 'name ' => $ entity ['name ' ],
1482+ 'prefix ' => $ entity ['prefix ' ],
1483+ 'status ' => $ entity ['status ' ]
1484+ );
1485+ }
1486+ }
1487+
1488+ header ('Content-Type: application/json ' );
1489+ echo json_encode (array ('entities ' => $ entities , 'count ' => count ($ entities )));
1490+ } catch (Exception $ e ) {
1491+ header ('Content-Type: application/json ' );
1492+ echo json_encode (array ('error ' => $ e ->getMessage (), 'count ' => 0 , 'entities ' => array ()));
1493+ }
1494+ }
1495+ }
0 commit comments