diff --git a/application/controllers/Clublog.php b/application/controllers/Clublog.php index 6e1239b3..e4b77fdf 100644 --- a/application/controllers/Clublog.php +++ b/application/controllers/Clublog.php @@ -12,9 +12,20 @@ class Clublog extends CI_Controller { } // Upload ADIF to Clublog - public function upload($username) { + public function upload() { + $this->load->model('clublog_model'); + $users = $this->clublog_model->get_clublog_users(); + + foreach ($users as $user) { + $this->uploadUser($user->user_id, $user->user_clublog_name, $user->user_clublog_password); + } + } + + function uploadUser($userid, $username, $password) { $clean_username = $this->security->xss_clean($username); + $clean_passord = $this->security->xss_clean($password); + $clean_userid = $this->security->xss_clean($userid); $this->config->load('config'); ini_set('memory_limit', '-1'); @@ -24,27 +35,15 @@ class Clublog extends CI_Controller { $this->load->helper('file'); - $this->load->model('logbook_model'); - - $this->load->model('stations'); - $this->load->model('clublog_model'); - $clublog_info = $this->clublog_model->get_clublog_auth_info($clean_username); - - if(!isset($clublog_info['user_name'])) { - echo "Username unknown"; - exit; - } - - - $station_profiles = $this->stations->all_with_count(); + $station_profiles = $this->clublog_model->all_with_count($clean_userid); if($station_profiles->num_rows()){ foreach ($station_profiles->result() as $station_row) { if($station_row->qso_total > 0) { - $data['qsos'] = $this->logbook_model->get_clublog_qsos($station_row->station_id); + $data['qsos'] = $this->clublog_model->get_clublog_qsos($station_row->station_id); if($data['qsos']->num_rows()){ $string = $this->load->view('adif/data/clublog', $data, TRUE); @@ -79,8 +78,8 @@ class Clublog extends CI_Controller { $request, CURLOPT_POSTFIELDS, array( - 'email' => $clublog_info['user_clublog_name'], - 'password' => $clublog_info['user_clublog_password'], + 'email' => $clean_username, + 'password' => $clean_passord, 'callsign' => $station_row->station_callsign, 'api' => "a11c3235cd74b88212ce726857056939d52372bd", 'file' => $cFile diff --git a/application/models/Clublog_model.php b/application/models/Clublog_model.php index f6c38688..f9c2ffce 100644 --- a/application/models/Clublog_model.php +++ b/application/models/Clublog_model.php @@ -2,6 +2,14 @@ class Clublog_model extends CI_Model { + function get_clublog_users() { + $this->db->select('user_clublog_name, user_clublog_password, user_id'); + $this->db->where('coalesce(user_clublog_name, "") != ""'); + $this->db->where('coalesce(user_clublog_password, "") != ""'); + $query = $this->db->get($this->config->item('auth_table')); + return $query->result(); + } + function get_clublog_auth_info($username) { $this->db->select('user_name, user_clublog_name, user_clublog_password'); $this->db->where('user_name', $username); @@ -53,6 +61,35 @@ class Clublog_model extends CI_Model { $this->db->where("COL_CLUBLOG_QSO_UPLOAD_STATUS", "Y"); $this->db->update($this->config->item('table_name'), $data); } + + function get_clublog_qsos($station_id){ + $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); + $this->db->where($this->config->item('table_name').'.station_id', $station_id); + $this->db->group_start(); + $this->db->where("COL_CLUBLOG_QSO_UPLOAD_STATUS", null); + $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", ""); + $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", "N"); + $this->db->group_end(); + + $query = $this->db->get($this->config->item('table_name')); + + return $query; + } + + function all_with_count($userid) { + $this->db->select('station_profile.station_id, station_profile.station_callsign, count('.$this->config->item('table_name').'.station_id) as qso_total'); + $this->db->from('station_profile'); + $this->db->join($this->config->item('table_name'),'station_profile.station_id = '.$this->config->item('table_name').'.station_id','left'); + $this->db->group_by('station_profile.station_id'); + $this->db->where('station_profile.user_id', $userid); + $this->db->group_start(); + $this->db->where("COL_CLUBLOG_QSO_UPLOAD_STATUS", null); + $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", ""); + $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", "N"); + $this->db->group_end(); + + return $this->db->get(); + } } ?> \ No newline at end of file diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index cc9fab33..39575ed8 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1045,18 +1045,6 @@ class Logbook_model extends CI_Model { return $this->db->get(); } - function get_clublog_qsos($station_id){ - $this->db->where($this->config->item('table_name').'.station_id', $station_id); - $this->db->where("COL_CLUBLOG_QSO_UPLOAD_STATUS", null); - $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", ""); - $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", "N"); - $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); - - $query = $this->db->get($this->config->item('table_name')); - - return $query; - } - /* * Function returns the QSOs from the logbook, which have not been either marked as uploaded to qrz, or has been modified with an edit */