2023-06-18 22:01:59 +02:00
< ? php
class Gridmap_model extends CI_Model {
2026-07-17 13:44:06 +01:00
function get_band_confirmed ( $band , $mode , $qsl , $lotw , $eqsl , $qrz , $sat , $sat_orbit = 'All' , $logbooks_locations_array = NULL ) {
2024-05-03 16:00:51 +01:00
2023-11-28 00:20:47 +01:00
if ( $logbooks_locations_array == NULL ) {
$CI =& get_instance ();
$CI -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $CI -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
}
2023-06-18 22:01:59 +02:00
if ( ! $logbooks_locations_array ) {
return null ;
}
Sanitize and escape query inputs in models
Sanitize location lists and escape query parameters across multiple models to prevent SQL injection and fix query formatting. Changes include: converting location arrays to comma-separated integer lists (array_map('intval')) instead of quoted implode, adding escape_str for band/mode/sat, adding a sanitize_location_list helper and early-return checks in CQ, escaping band lists, and updating Adif_data date where clauses to use $this->db->escape(..., NULL, FALSE). Files modified: Accumulate_model, Activated_gridmap_model, Adif_data, Cq, and Gridmap_model.
2026-06-24 22:19:35 +01:00
$location_list = implode ( ',' , array_map ( 'intval' , $logbooks_locations_array ));
$band = $this -> db -> escape_str ( $band );
$mode = $this -> db -> escape_str ( $mode );
$sat = $this -> db -> escape_str ( $sat );
2026-07-17 13:44:06 +01:00
$sat_orbit = $this -> db -> escape_str ( $sat_orbit );
2023-06-18 22:01:59 +02:00
$sql = 'SELECT distinct substring(COL_GRIDSQUARE,1,6) as GRID_SQUARES, COL_BAND FROM '
. $this -> config -> item ( 'table_name' )
. ' WHERE station_id in ('
. $location_list . ') AND COL_GRIDSQUARE != ""' ;
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
2026-07-17 13:44:06 +01:00
$sql .= $this -> getSatelliteOrbitFilterSql ( $sat_orbit );
2023-06-19 11:29:46 +02:00
if ( $sat != 'All' ) {
$sql .= " and col_sat_name =' " . $sat . " ' " ;
}
2023-06-18 22:01:59 +02:00
}
else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
if ( $mode != 'All' ) {
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
}
2023-12-08 12:23:19 +00:00
$sql .= $this -> addQslToQuery ( $qsl , $lotw , $eqsl , $qrz );
2023-06-18 22:01:59 +02:00
return $this -> db -> query ( $sql );
}
2026-07-17 13:44:06 +01:00
function get_band ( $band , $mode , $qsl , $lotw , $eqsl , $qrz , $sat , $sat_orbit = 'All' , $logbooks_locations_array = NULL ) {
2023-11-28 00:20:47 +01:00
if ( $logbooks_locations_array == NULL ) {
$CI =& get_instance ();
$CI -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $CI -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
}
2023-06-18 22:01:59 +02:00
if ( ! $logbooks_locations_array ) {
return null ;
}
Sanitize and escape query inputs in models
Sanitize location lists and escape query parameters across multiple models to prevent SQL injection and fix query formatting. Changes include: converting location arrays to comma-separated integer lists (array_map('intval')) instead of quoted implode, adding escape_str for band/mode/sat, adding a sanitize_location_list helper and early-return checks in CQ, escaping band lists, and updating Adif_data date where clauses to use $this->db->escape(..., NULL, FALSE). Files modified: Accumulate_model, Activated_gridmap_model, Adif_data, Cq, and Gridmap_model.
2026-06-24 22:19:35 +01:00
$location_list = implode ( ',' , array_map ( 'intval' , $logbooks_locations_array ));
$band = $this -> db -> escape_str ( $band );
$mode = $this -> db -> escape_str ( $mode );
$sat = $this -> db -> escape_str ( $sat );
2026-07-17 13:44:06 +01:00
$sat_orbit = $this -> db -> escape_str ( $sat_orbit );
2023-06-18 22:01:59 +02:00
$sql = 'SELECT distinct substring(COL_GRIDSQUARE,1,6) as GRID_SQUARES, COL_BAND FROM '
. $this -> config -> item ( 'table_name' )
. ' WHERE station_id in ('
. $location_list . ') AND COL_GRIDSQUARE != ""' ;
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
2026-07-17 13:44:06 +01:00
$sql .= $this -> getSatelliteOrbitFilterSql ( $sat_orbit );
2023-06-19 11:29:46 +02:00
if ( $sat != 'All' ) {
$sql .= " and col_sat_name =' " . $sat . " ' " ;
}
2023-06-18 22:01:59 +02:00
}
else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
if ( $mode != 'All' ) {
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
}
return $this -> db -> query ( $sql );
}
2026-07-17 13:44:06 +01:00
function get_band_worked_vucc_squares ( $band , $mode , $qsl , $lotw , $eqsl , $qrz , $sat , $sat_orbit = 'All' , $logbooks_locations_array = NULL ) {
2023-11-28 00:20:47 +01:00
if ( $logbooks_locations_array == NULL ) {
$CI =& get_instance ();
$CI -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $CI -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
}
2023-06-18 22:01:59 +02:00
if ( ! $logbooks_locations_array ) {
return null ;
}
Sanitize and escape query inputs in models
Sanitize location lists and escape query parameters across multiple models to prevent SQL injection and fix query formatting. Changes include: converting location arrays to comma-separated integer lists (array_map('intval')) instead of quoted implode, adding escape_str for band/mode/sat, adding a sanitize_location_list helper and early-return checks in CQ, escaping band lists, and updating Adif_data date where clauses to use $this->db->escape(..., NULL, FALSE). Files modified: Accumulate_model, Activated_gridmap_model, Adif_data, Cq, and Gridmap_model.
2026-06-24 22:19:35 +01:00
$location_list = implode ( ',' , array_map ( 'intval' , $logbooks_locations_array ));
$band = $this -> db -> escape_str ( $band );
$mode = $this -> db -> escape_str ( $mode );
$sat = $this -> db -> escape_str ( $sat );
2026-07-17 13:44:06 +01:00
$sat_orbit = $this -> db -> escape_str ( $sat_orbit );
2023-06-18 22:01:59 +02:00
$sql = 'SELECT distinct COL_VUCC_GRIDS, COL_BAND FROM '
. $this -> config -> item ( 'table_name' )
. ' WHERE station_id in ('
. $location_list . ') AND COL_VUCC_GRIDS != ""' ;
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
2026-07-17 13:44:06 +01:00
$sql .= $this -> getSatelliteOrbitFilterSql ( $sat_orbit );
2023-06-19 11:29:46 +02:00
if ( $sat != 'All' ) {
$sql .= " and col_sat_name =' " . $sat . " ' " ;
}
2023-06-18 22:01:59 +02:00
}
else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
if ( $mode != 'All' ) {
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
}
2023-06-19 09:38:47 +02:00
return $this -> db -> query ( $sql );
2023-06-18 22:01:59 +02:00
}
2026-07-17 13:44:06 +01:00
function get_band_confirmed_vucc_squares ( $band , $mode , $qsl , $lotw , $eqsl , $qrz , $sat , $sat_orbit = 'All' , $logbooks_locations_array = NULL ) {
2023-11-28 00:20:47 +01:00
if ( $logbooks_locations_array == NULL ) {
$CI =& get_instance ();
$CI -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $CI -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
}
2023-06-18 22:01:59 +02:00
if ( ! $logbooks_locations_array ) {
return null ;
}
Sanitize and escape query inputs in models
Sanitize location lists and escape query parameters across multiple models to prevent SQL injection and fix query formatting. Changes include: converting location arrays to comma-separated integer lists (array_map('intval')) instead of quoted implode, adding escape_str for band/mode/sat, adding a sanitize_location_list helper and early-return checks in CQ, escaping band lists, and updating Adif_data date where clauses to use $this->db->escape(..., NULL, FALSE). Files modified: Accumulate_model, Activated_gridmap_model, Adif_data, Cq, and Gridmap_model.
2026-06-24 22:19:35 +01:00
$location_list = implode ( ',' , array_map ( 'intval' , $logbooks_locations_array ));
$band = $this -> db -> escape_str ( $band );
$mode = $this -> db -> escape_str ( $mode );
$sat = $this -> db -> escape_str ( $sat );
2026-07-17 13:44:06 +01:00
$sat_orbit = $this -> db -> escape_str ( $sat_orbit );
2023-06-18 22:01:59 +02:00
$sql = 'SELECT distinct COL_VUCC_GRIDS, COL_BAND FROM '
. $this -> config -> item ( 'table_name' )
. ' WHERE station_id in ('
. $location_list . ') AND COL_VUCC_GRIDS != ""' ;
2023-06-19 11:29:46 +02:00
if ( $band != 'All' ) {
2023-06-18 22:01:59 +02:00
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
2026-07-17 13:44:06 +01:00
$sql .= $this -> getSatelliteOrbitFilterSql ( $sat_orbit );
2023-06-19 11:29:46 +02:00
if ( $sat != 'All' ) {
$sql .= " and col_sat_name =' " . $sat . " ' " ;
}
2023-06-18 22:01:59 +02:00
}
else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
if ( $mode != 'All' ) {
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
}
2023-12-08 12:23:19 +00:00
$sql .= $this -> addQslToQuery ( $qsl , $lotw , $eqsl , $qrz );
2023-06-18 22:01:59 +02:00
return $this -> db -> query ( $sql );
}
// Adds confirmation to query
2023-12-08 12:23:19 +00:00
function addQslToQuery ( $qsl , $lotw , $eqsl , $qrz ) {
$sql = '' ;
if ( $lotw == " true " ) {
$sql .= " or col_lotw_qsl_rcvd = 'Y' " ;
}
if ( $qsl == " true " ) {
$sql .= " or col_qsl_rcvd = 'Y' " ;
}
if ( $eqsl == " true " ) {
$sql .= " or col_eqsl_qsl_rcvd = 'Y' " ;
}
if ( $qrz == " true " ) {
$sql .= " or col_qrzcom_qso_download_status = 'Y' " ;
}
if ( $sql != '' ) {
2024-01-31 12:29:19 +01:00
$sql = ' and (1=0 ' . $sql . ')' ;
}
if ( $sql == '' ) {
$sql = ' and 1=0' ;
2023-12-08 12:23:19 +00:00
}
return $sql ;
}
2023-06-18 22:01:59 +02:00
2026-07-17 13:44:06 +01:00
function getSatelliteOrbitFilterSql ( $sat_orbit ) {
if ( $sat_orbit === 'MEO' ) {
return " and col_sat_name = 'IO-117' " ;
}
if ( $sat_orbit === 'GEO' ) {
return " and col_sat_name = 'QO-100' " ;
}
if ( $sat_orbit === 'LEO' ) {
return " and col_sat_name not in ('IO-117', 'QO-100') " ;
}
return '' ;
}
2023-06-18 22:01:59 +02:00
/*
* Get ' s the worked modes from the log
*/
function get_worked_modes () {
$CI =& get_instance ();
$CI -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $CI -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
if ( ! $logbooks_locations_array ) {
return null ;
}
Sanitize and escape query inputs in models
Sanitize location lists and escape query parameters across multiple models to prevent SQL injection and fix query formatting. Changes include: converting location arrays to comma-separated integer lists (array_map('intval')) instead of quoted implode, adding escape_str for band/mode/sat, adding a sanitize_location_list helper and early-return checks in CQ, escaping band lists, and updating Adif_data date where clauses to use $this->db->escape(..., NULL, FALSE). Files modified: Accumulate_model, Activated_gridmap_model, Adif_data, Cq, and Gridmap_model.
2026-06-24 22:19:35 +01:00
$location_list = implode ( ',' , array_map ( 'intval' , $logbooks_locations_array ));
2023-06-18 22:01:59 +02:00
// get all worked modes from database
$data = $this -> db -> query (
" SELECT distinct LOWER(`COL_MODE`) as `COL_MODE` FROM ` " . $this -> config -> item ( 'table_name' ) . " ` WHERE station_id in ( " . $location_list . " ) order by COL_MODE ASC "
);
$results = array ();
foreach ( $data -> result () as $row ) {
array_push ( $results , $row -> COL_MODE );
}
$data = $this -> db -> query (
" SELECT distinct LOWER(`COL_SUBMODE`) as `COL_SUBMODE` FROM ` " . $this -> config -> item ( 'table_name' ) . " ` WHERE station_id in ( " . $location_list . " ) and coalesce(COL_SUBMODE, '') <> '' order by COL_SUBMODE ASC "
);
foreach ( $data -> result () as $row ) {
if ( ! in_array ( $row , $results )) {
array_push ( $results , $row -> COL_SUBMODE );
}
}
asort ( $results );
return $results ;
}
2023-11-28 00:20:47 +01:00
}