kopia lustrzana https://github.com/magicbug/Cloudlog
[LOTW] LoTW user lookup switched from importing CSV to database to PHP reading it directly reducing MySQL load
rodzic
2c44517370
commit
d4a164fc94
|
@ -67,11 +67,32 @@ class Logbook extends CI_Controller {
|
||||||
$this->load->model('user_model');
|
$this->load->model('user_model');
|
||||||
if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
|
if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
|
||||||
|
|
||||||
$this->load->model('lotw_user');
|
// Check if callsign is an LOTW User
|
||||||
|
$lotw_member = "";
|
||||||
$lotw_member = $this->lotw_user->check($callsign);
|
$lotw_file_name = "./updates/lotw_users.csv";
|
||||||
|
|
||||||
|
if (file_exists($lotw_file_name)) {
|
||||||
|
$f = fopen($lotw_file_name, "r");
|
||||||
|
$result = false;
|
||||||
|
while ($row = fgetcsv($f)) {
|
||||||
|
if ($row[0] == strtoupper($callsign)) {
|
||||||
|
$result = $row[0];
|
||||||
|
$lotw_member = "active";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($lotw_member != "active") {
|
||||||
|
$lotw_member = "not found";
|
||||||
|
}
|
||||||
|
fclose($f);
|
||||||
|
} else {
|
||||||
|
$lotw_member = "not found";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Check Database for all other data
|
||||||
$this->load->model('logbook_model');
|
$this->load->model('logbook_model');
|
||||||
|
|
||||||
$return = [
|
$return = [
|
||||||
|
|
|
@ -819,42 +819,41 @@ class Lotw extends CI_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Load the ARRL LOTW User Activity CSV into LOTW User Table for cross checking when logging
|
Load the ARRL LOTW User Activity CSV and saves into uploads/lotw_users.csv
|
||||||
*/
|
*/
|
||||||
function load_users() {
|
public function load_users() {
|
||||||
set_time_limit(0);
|
$contents = file_get_contents('https://lotw.arrl.org/lotw-user-activity.csv', true);
|
||||||
$this->load->model('lotw_user');
|
|
||||||
|
|
||||||
$this->lotw_user->empty_table();
|
if($contents === FALSE) {
|
||||||
|
echo "something went wrong";
|
||||||
|
} else {
|
||||||
|
$file = './updates/lotw_users.csv';
|
||||||
|
|
||||||
$row = 1;
|
if(!is_file($file)){ // Some simple example content.
|
||||||
if (($handle = fopen("https://lotw.arrl.org/lotw-user-activity.csv", "r")) !== FALSE) {
|
file_put_contents($file, $contents); // Save our content to the file.
|
||||||
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
|
}
|
||||||
$num = count($data);
|
|
||||||
$row++;
|
|
||||||
|
|
||||||
if(isset($data[2])) {
|
|
||||||
$callsign = $data[0];
|
|
||||||
$upload_date = $data[1]." ".$data[2];
|
|
||||||
$this->lotw_user->add_lotwuser($callsign, $upload_date);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
fclose($handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
echo "LoTW User Data Saved.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check if callsign is an active LOTW user and return whether its true or not
|
Check if callsign is an active LOTW user and return whether its true or not
|
||||||
*/
|
*/
|
||||||
function lotw_usercheck($callsign) {
|
function lotw_usercheck($callsign) {
|
||||||
$this->load->model('lotw_user');
|
$f = fopen('./updates/lotw_users.csv', "r");
|
||||||
|
$result = false;
|
||||||
|
while ($row = fgetcsv($f)) {
|
||||||
$lotw_user_result = $this->lotw_user->check($callsign);
|
if ($row[0] == strtoupper($callsign)) {
|
||||||
|
$result = $row[0];
|
||||||
|
echo "Found";
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
echo "Not Found"
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($f);
|
||||||
}
|
}
|
||||||
|
|
||||||
function signlog($sign_key, $string) {
|
function signlog($sign_key, $string) {
|
||||||
|
|
|
@ -256,5 +256,39 @@ class Update extends CI_Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function download_lotw_users() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$contents = file_get_contents('https://lotw.arrl.org/lotw-user-activity.csv', true);
|
||||||
|
|
||||||
|
if($contents === FALSE) {
|
||||||
|
echo "something went wrong";
|
||||||
|
} else {
|
||||||
|
$file = './updates/lotw_users.csv';
|
||||||
|
|
||||||
|
if(!is_file($file)){ // Some simple example content.
|
||||||
|
file_put_contents($file, $contents); // Save our content to the file.
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "LoTW User Data Saved.";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function lotw_check() {
|
||||||
|
$f = fopen('./updates/lotw_users.csv', "r");
|
||||||
|
$result = false;
|
||||||
|
while ($row = fgetcsv($f)) {
|
||||||
|
if ($row[0] == '2M0SQL/MM') {
|
||||||
|
$result = $row[0];
|
||||||
|
echo "found";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Plik diff jest za duży
Load Diff
Ładowanie…
Reference in New Issue