2020-02-09 12:20:59 +00:00
< ? php
class was extends CI_Model {
2020-03-28 23:36:18 +00:00
public $stateString = 'AK,AL,AR,AZ,CA,CO,CT,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY' ;
function get_was_array ( $bands , $postdata ) {
2021-09-09 21:04:50 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $CI -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2021-11-14 16:11:59 +00:00
if ( ! $logbooks_locations_array ) {
return null ;
}
$location_list = " ' " . implode ( " ',' " , $logbooks_locations_array ) . " ' " ;
2020-02-09 12:20:59 +00:00
2020-03-28 23:36:18 +00:00
$stateArray = explode ( ',' , $this -> stateString );
2020-02-09 12:20:59 +00:00
2020-03-28 23:36:18 +00:00
$states = array (); // Used for keeping track of which states that are not worked
2020-02-09 12:20:59 +00:00
2020-03-31 05:43:33 +00:00
foreach ( $stateArray as $state ) { // Generating array for use in the table
$states [ $state ][ 'count' ] = 0 ; // Inits each state's count
}
2020-03-28 23:36:18 +00:00
foreach ( $bands as $band ) {
foreach ( $stateArray as $state ) { // Generating array for use in the table
$bandWas [ $state ][ $band ] = '-' ; // Sets all to dash to indicate no result
}
2020-02-09 12:20:59 +00:00
2020-03-28 23:36:18 +00:00
if ( $postdata [ 'worked' ] != NULL ) {
2021-09-09 21:04:50 +00:00
$wasBand = $this -> getWasWorked ( $location_list , $band , $postdata );
2020-03-28 23:36:18 +00:00
foreach ( $wasBand as $line ) {
2021-07-27 10:11:41 +00:00
$bandWas [ $line -> col_state ][ $band ] = '<div class="alert-danger"><a href=\'javascript:displayContacts("' . $line -> col_state . '","' . $band . '","' . $postdata [ 'mode' ] . '","WAS")\'>W</a></div>' ;
2020-03-28 23:36:18 +00:00
$states [ $line -> col_state ][ 'count' ] ++ ;
}
}
if ( $postdata [ 'confirmed' ] != NULL ) {
2021-09-09 21:04:50 +00:00
$wasBand = $this -> getWasConfirmed ( $location_list , $band , $postdata );
2020-03-28 23:36:18 +00:00
foreach ( $wasBand as $line ) {
2021-07-27 10:11:41 +00:00
$bandWas [ $line -> col_state ][ $band ] = '<div class="alert-success"><a href=\'javascript:displayContacts("' . $line -> col_state . '","' . $band . '","' . $postdata [ 'mode' ] . '","WAS")\'>C</a></div>' ;
2020-03-28 23:36:18 +00:00
$states [ $line -> col_state ][ 'count' ] ++ ;
}
}
}
2020-02-09 12:20:59 +00:00
2020-03-28 23:36:18 +00:00
// We want to remove the worked states in the list, since we do not want to display them
if ( $postdata [ 'worked' ] == NULL ) {
2021-09-09 21:04:50 +00:00
$wasBand = $this -> getWasWorked ( $location_list , $postdata [ 'band' ], $postdata );
2020-03-28 23:36:18 +00:00
foreach ( $wasBand as $line ) {
unset ( $bandWas [ $line -> col_state ]);
}
2020-02-09 12:20:59 +00:00
}
2020-03-28 23:36:18 +00:00
// We want to remove the confirmed states in the list, since we do not want to display them
if ( $postdata [ 'confirmed' ] == NULL ) {
2021-09-09 21:04:50 +00:00
$wasBand = $this -> getWasConfirmed ( $location_list , $postdata [ 'band' ], $postdata );
2020-03-28 23:36:18 +00:00
foreach ( $wasBand as $line ) {
unset ( $bandWas [ $line -> col_state ]);
}
}
2020-02-09 12:20:59 +00:00
2020-03-28 23:36:18 +00:00
if ( $postdata [ 'notworked' ] == NULL ) {
foreach ( $stateArray as $state ) {
if ( $states [ $state ][ 'count' ] == 0 ) {
unset ( $bandWas [ $state ]);
};
2020-02-09 12:20:59 +00:00
}
2020-03-28 23:36:18 +00:00
}
if ( isset ( $bandWas )) {
return $bandWas ;
}
else {
return 0 ;
}
}
2020-08-18 12:41:16 +00:00
/*
* Function gets worked and confirmed summary on each band on the active stationprofile
*/
2022-01-04 18:13:41 +00:00
function get_was_summary ( $bands , $postdata )
2020-08-19 15:23:24 +00:00
{
2021-09-09 21:04:50 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $CI -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2021-11-14 16:11:59 +00:00
if ( ! $logbooks_locations_array ) {
return null ;
}
2021-09-09 21:04:50 +00:00
$location_list = " ' " . implode ( " ',' " , $logbooks_locations_array ) . " ' " ;
2020-08-18 12:41:16 +00:00
2020-08-19 15:23:24 +00:00
foreach ( $bands as $band ) {
2022-01-04 18:13:41 +00:00
$worked = $this -> getSummaryByBand ( $band , $postdata , $location_list );
$confirmed = $this -> getSummaryByBandConfirmed ( $band , $postdata , $location_list );
2020-08-19 15:23:24 +00:00
$wasSummary [ 'worked' ][ $band ] = $worked [ 0 ] -> count ;
$wasSummary [ 'confirmed' ][ $band ] = $confirmed [ 0 ] -> count ;
}
2020-08-18 12:41:16 +00:00
2022-01-04 18:13:41 +00:00
$workedTotal = $this -> getSummaryByBand ( $postdata [ 'band' ], $postdata , $location_list );
$confirmedTotal = $this -> getSummaryByBandConfirmed ( $postdata [ 'band' ], $postdata , $location_list );
2020-10-15 10:24:20 +00:00
$wasSummary [ 'worked' ][ 'Total' ] = $workedTotal [ 0 ] -> count ;
$wasSummary [ 'confirmed' ][ 'Total' ] = $confirmedTotal [ 0 ] -> count ;
2020-08-19 15:23:24 +00:00
return $wasSummary ;
}
2020-08-18 12:41:16 +00:00
2022-01-04 18:13:41 +00:00
function getSummaryByBand ( $band , $postdata , $location_list )
2020-08-19 15:23:24 +00:00
{
2020-08-19 15:30:37 +00:00
$sql = " SELECT count(distinct thcv.col_state) as count FROM " . $this -> config -> item ( 'table_name' ) . " thcv " ;
2020-08-18 12:41:16 +00:00
2021-09-09 21:04:50 +00:00
$sql .= " where station_id in ( " . $location_list . " ) " ;
2020-08-19 15:23:24 +00:00
if ( $band == 'SAT' ) {
$sql .= " and thcv.col_prop_mode =' " . $band . " ' " ;
2020-10-15 10:24:20 +00:00
} else if ( $band == 'All' ) {
2022-09-07 18:40:31 +00:00
$this -> load -> model ( 'bands' );
$bandslots = $this -> bands -> get_worked_bands ( 'was' );
$bandslots_list = " ' " . implode ( " ',' " , $bandslots ) . " ' " ;
$sql .= " and thcv.col_band in ( " . $bandslots_list . " ) " .
" and thcv.col_prop_mode !='SAT' " ;
2020-08-19 15:23:24 +00:00
} else {
$sql .= " and thcv.col_prop_mode !='SAT' " ;
$sql .= " and thcv.col_band =' " . $band . " ' " ;
}
2022-01-04 18:13:41 +00:00
if ( $postdata [ 'mode' ] != 'All' ) {
$sql .= " and (col_mode = ' " . $postdata [ 'mode' ] . " ' or col_submode = ' " . $postdata [ 'mode' ] . " ') " ;
}
2020-08-18 12:41:16 +00:00
$sql .= $this -> addStateToQuery ();
2020-08-19 15:23:24 +00:00
$query = $this -> db -> query ( $sql );
return $query -> result ();
}
2022-01-04 18:13:41 +00:00
function getSummaryByBandConfirmed ( $band , $postdata , $location_list )
2020-08-19 15:23:24 +00:00
{
2020-08-19 15:30:37 +00:00
$sql = " SELECT count(distinct thcv.col_state) as count FROM " . $this -> config -> item ( 'table_name' ) . " thcv " ;
2020-08-18 12:41:16 +00:00
2021-09-09 21:04:50 +00:00
$sql .= " where station_id in ( " . $location_list . " ) " ;
2020-08-18 12:41:16 +00:00
2020-08-19 15:23:24 +00:00
if ( $band == 'SAT' ) {
$sql .= " and thcv.col_prop_mode =' " . $band . " ' " ;
2020-10-15 10:24:20 +00:00
} else if ( $band == 'All' ) {
2022-09-07 18:40:31 +00:00
$this -> load -> model ( 'bands' );
$bandslots = $this -> bands -> get_worked_bands ( 'was' );
$bandslots_list = " ' " . implode ( " ',' " , $bandslots ) . " ' " ;
$sql .= " and thcv.col_band in ( " . $bandslots_list . " ) " .
" and thcv.col_prop_mode !='SAT' " ;
2020-08-19 15:23:24 +00:00
} else {
$sql .= " and thcv.col_prop_mode !='SAT' " ;
$sql .= " and thcv.col_band =' " . $band . " ' " ;
}
2022-01-04 18:13:41 +00:00
if ( $postdata [ 'mode' ] != 'All' ) {
$sql .= " and (col_mode = ' " . $postdata [ 'mode' ] . " ' or col_submode = ' " . $postdata [ 'mode' ] . " ') " ;
}
2020-08-19 15:23:24 +00:00
2022-01-04 18:13:41 +00:00
$sql .= $this -> addQslToQuery ( $postdata );
$sql .= $this -> addStateToQuery ();
2020-08-18 12:41:16 +00:00
$query = $this -> db -> query ( $sql );
return $query -> result ();
}
2020-03-28 23:36:18 +00:00
/*
* Function returns all worked , but not confirmed states
* $postdata contains data from the form , in this case Lotw or QSL are used
*/
2021-09-09 21:04:50 +00:00
function getWasWorked ( $location_list , $band , $postdata ) {
2021-07-24 12:31:16 +00:00
$sql = " SELECT distinct col_state FROM " . $this -> config -> item ( 'table_name' ) . " thcv
2021-09-09 21:04:50 +00:00
where station_id in ( " . $location_list . " ) " ;
2020-03-28 23:36:18 +00:00
2021-07-27 10:11:41 +00:00
if ( $postdata [ 'mode' ] != 'All' ) {
$sql .= " and (col_mode = ' " . $postdata [ 'mode' ] . " ' or col_submode = ' " . $postdata [ 'mode' ] . " ') " ;
}
2020-03-28 23:36:18 +00:00
$sql .= $this -> addStateToQuery ();
$sql .= $this -> addBandToQuery ( $band );
2020-02-09 12:20:59 +00:00
2020-03-28 23:36:18 +00:00
$sql .= " and not exists (select 1 from " . $this -> config -> item ( 'table_name' ) .
2021-09-09 21:04:50 +00:00
" where station_id in ( " . $location_list . " ) " .
2020-03-28 23:36:18 +00:00
" and col_state = thcv.col_state " ;
2020-02-09 12:20:59 +00:00
2021-07-27 10:11:41 +00:00
if ( $postdata [ 'mode' ] != 'All' ) {
$sql .= " and (col_mode = ' " . $postdata [ 'mode' ] . " ' or col_submode = ' " . $postdata [ 'mode' ] . " ') " ;
}
2020-03-28 23:36:18 +00:00
$sql .= $this -> addBandToQuery ( $band );
2020-02-09 12:20:59 +00:00
2020-03-28 23:36:18 +00:00
$sql .= $this -> addQslToQuery ( $postdata );
$sql .= $this -> addStateToQuery ();
$sql .= " ) " ;
$query = $this -> db -> query ( $sql );
return $query -> result ();
}
/*
* Function returns all confirmed states on given band and on LoTW or QSL
* $postdata contains data from the form , in this case Lotw or QSL are used
*/
2021-09-09 21:04:50 +00:00
function getWasConfirmed ( $location_list , $band , $postdata ) {
2021-07-24 12:31:16 +00:00
$sql = " SELECT distinct col_state FROM " . $this -> config -> item ( 'table_name' ) . " thcv
2021-09-09 21:04:50 +00:00
where station_id in ( " . $location_list . " ) " ;
2020-03-28 23:36:18 +00:00
2021-07-27 10:11:41 +00:00
if ( $postdata [ 'mode' ] != 'All' ) {
$sql .= " and (col_mode = ' " . $postdata [ 'mode' ] . " ' or col_submode = ' " . $postdata [ 'mode' ] . " ') " ;
}
2020-03-28 23:36:18 +00:00
$sql .= $this -> addStateToQuery ();
$sql .= $this -> addBandToQuery ( $band );
$sql .= $this -> addQslToQuery ( $postdata );
$query = $this -> db -> query ( $sql );
return $query -> result ();
}
function addQslToQuery ( $postdata ) {
$sql = '' ;
if ( $postdata [ 'lotw' ] != NULL and $postdata [ 'qsl' ] == NULL ) {
$sql .= " and col_lotw_qsl_rcvd = 'Y' " ;
2020-02-09 12:20:59 +00:00
}
2020-03-28 23:36:18 +00:00
if ( $postdata [ 'qsl' ] != NULL and $postdata [ 'lotw' ] == NULL ) {
$sql .= " and col_qsl_rcvd = 'Y' " ;
}
if ( $postdata [ 'qsl' ] != NULL && $postdata [ 'lotw' ] != NULL ) {
$sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y') " ;
}
return $sql ;
}
function addBandToQuery ( $band ) {
$sql = '' ;
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
2022-09-07 18:40:31 +00:00
} else {
$this -> load -> model ( 'bands' );
$bandslots = $this -> bands -> get_worked_bands ( 'was' );
$bandslots_list = " ' " . implode ( " ',' " , $bandslots ) . " ' " ;
$sql .= " and col_band in ( " . $bandslots_list . " ) " .
" and col_prop_mode !='SAT' " ;
2020-03-28 23:36:18 +00:00
}
return $sql ;
}
function addStateToQuery () {
$sql = '' ;
$sql .= " and COL_DXCC in ('291', '6', '110') " ;
$sql .= " and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY') " ;
return $sql ;
2020-02-09 12:20:59 +00:00
}
}
2021-07-24 12:31:16 +00:00
?>