|
| 1 | +<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | + |
| 3 | +/* |
| 4 | + Controller to interact with the Cloudlog DXPed Aggregator |
| 5 | +*/ |
| 6 | + |
| 7 | +class Workabledxcc extends CI_Controller |
| 8 | +{ |
| 9 | + |
| 10 | + function __construct() |
| 11 | + { |
| 12 | + parent::__construct(); |
| 13 | + |
| 14 | + $this->load->model('user_model'); |
| 15 | + if (!$this->user_model->authorize(2)) { |
| 16 | + $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); |
| 17 | + redirect('dashboard'); |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + public function index() |
| 22 | + { |
| 23 | + // Load public view |
| 24 | + $data['page_title'] = "Upcoming DXPeditions"; |
| 25 | + $this->load->view('interface_assets/header', $data); |
| 26 | + $this->load->view('/workabledxcc/index'); |
| 27 | + $this->load->view('interface_assets/footer'); |
| 28 | + } |
| 29 | + |
| 30 | + public function dxcclist() |
| 31 | + { |
| 32 | + |
| 33 | + $json = file_get_contents('https://cdn.cloudlog.org/read_ng3k_dxped_list.php'); |
| 34 | + |
| 35 | + // Decode the JSON data into a PHP array |
| 36 | + $dataResult = json_decode($json, true); |
| 37 | + |
| 38 | + // Initialize an empty array to store the required data |
| 39 | + $requiredData = array(); |
| 40 | + |
| 41 | + // Get Date format |
| 42 | + if ($this->session->userdata('user_date_format')) { |
| 43 | + // If Logged in and session exists |
| 44 | + $custom_date_format = $this->session->userdata('user_date_format'); |
| 45 | + } else { |
| 46 | + // Get Default date format from /config/cloudlog.php |
| 47 | + $custom_date_format = $this->config->item('qso_date_format'); |
| 48 | + } |
| 49 | + |
| 50 | + // Iterate through the decoded JSON data |
| 51 | + foreach ($dataResult as $item) { |
| 52 | + // Create a new array with the required fields and add it to the main array |
| 53 | + $oldStartDate = DateTime::createFromFormat('Y-m-d', $item['0']); |
| 54 | + |
| 55 | + $StartDate = $oldStartDate->format($custom_date_format); |
| 56 | + |
| 57 | + $oldEndDate = DateTime::createFromFormat('Y-m-d', $item['1']); |
| 58 | + |
| 59 | + $EndDate = $oldEndDate->format($custom_date_format); |
| 60 | + |
| 61 | + $this->load->model('logbook_model'); |
| 62 | + $dxccInfo = $this->logbook_model->dxcc_lookup($item['callsign'], $StartDate); |
| 63 | + |
| 64 | + // Call DXCC Worked function to check if the DXCC has been worked before |
| 65 | + if (isset($dxccInfo['entity'])) { |
| 66 | + $dxccWorked = $this->dxccWorked($dxccInfo['entity']); |
| 67 | + } else { |
| 68 | + // Handle the case where 'entity' is not set in $dxccInfo |
| 69 | + $dxccWorked = array( |
| 70 | + 'workedBefore' => false, |
| 71 | + 'confirmed' => false, |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + $requiredData[] = array( |
| 76 | + 'clean_date' => $item['0'], |
| 77 | + 'start_date' => $StartDate, |
| 78 | + 'end_date' => $EndDate, |
| 79 | + 'country' => $item['2'], |
| 80 | + 'notes' => $item['6'], |
| 81 | + 'callsign' => $item['callsign'], |
| 82 | + 'workedBefore' => $dxccWorked['workedBefore'], |
| 83 | + 'confirmed' => $dxccWorked['confirmed'], |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + $data['dxcclist'] = $requiredData; |
| 88 | + |
| 89 | + // Return the array with the required data |
| 90 | + |
| 91 | + $this->load->view('/workabledxcc/components/dxcclist', $data); |
| 92 | + } |
| 93 | + |
| 94 | + function dxccWorked($country) |
| 95 | + { |
| 96 | + |
| 97 | + $return = [ |
| 98 | + "workedBefore" => false, |
| 99 | + "confirmed" => false, |
| 100 | + ]; |
| 101 | + |
| 102 | + $user_default_confirmation = $this->session->userdata('user_default_confirmation'); |
| 103 | + $this->load->model('logbooks_model'); |
| 104 | + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); |
| 105 | + $this->load->model('logbook_model'); |
| 106 | + |
| 107 | + if (!empty($logbooks_locations_array)) { |
| 108 | + $this->db->where('COL_PROP_MODE !=', 'SAT'); |
| 109 | + |
| 110 | + $this->db->where_in('station_id', $logbooks_locations_array); |
| 111 | + $this->db->where('COL_COUNTRY', urldecode($country)); |
| 112 | + |
| 113 | + $query = $this->db->get($this->config->item('table_name'), 1, 0); |
| 114 | + foreach ($query->result() as $workedBeforeRow) { |
| 115 | + $return['workedBefore'] = true; |
| 116 | + } |
| 117 | + |
| 118 | + $extrawhere = ''; |
| 119 | + if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'Q') !== false) { |
| 120 | + $extrawhere = "COL_QSL_RCVD='Y'"; |
| 121 | + } |
| 122 | + if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'L') !== false) { |
| 123 | + if ($extrawhere != '') { |
| 124 | + $extrawhere .= " OR"; |
| 125 | + } |
| 126 | + $extrawhere .= " COL_LOTW_QSL_RCVD='Y'"; |
| 127 | + } |
| 128 | + if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'E') !== false) { |
| 129 | + if ($extrawhere != '') { |
| 130 | + $extrawhere .= " OR"; |
| 131 | + } |
| 132 | + $extrawhere .= " COL_EQSL_QSL_RCVD='Y'"; |
| 133 | + } |
| 134 | + |
| 135 | + if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'Z') !== false) { |
| 136 | + if ($extrawhere != '') { |
| 137 | + $extrawhere .= " OR"; |
| 138 | + } |
| 139 | + $extrawhere .= " COL_QRZCOM_QSO_DOWNLOAD_STATUS='Y'"; |
| 140 | + } |
| 141 | + |
| 142 | + |
| 143 | + $this->load->model('logbook_model'); |
| 144 | + $this->db->where('COL_PROP_MODE !=', 'SAT'); |
| 145 | + if ($extrawhere != '') { |
| 146 | + $this->db->where('(' . $extrawhere . ')'); |
| 147 | + } else { |
| 148 | + $this->db->where("1=0"); |
| 149 | + } |
| 150 | + |
| 151 | + |
| 152 | + $this->db->where_in('station_id', $logbooks_locations_array); |
| 153 | + $this->db->where('COL_COUNTRY', urldecode($country)); |
| 154 | + |
| 155 | + $query = $this->db->get($this->config->item('table_name'), 1, 0); |
| 156 | + foreach ($query->result() as $workedBeforeRow) { |
| 157 | + $return['confirmed'] = true; |
| 158 | + } |
| 159 | + |
| 160 | + return $return; |
| 161 | + } else { |
| 162 | + $return['workedBefore'] = false; |
| 163 | + $return['confirmed'] = false; |
| 164 | + |
| 165 | + |
| 166 | + return $return;; |
| 167 | + } |
| 168 | + } |
| 169 | + |
| 170 | +} |
0 commit comments