acracb admin subirlogs por puntos

{source}<?php
$db = JFactory::getDbo();
$user = JFactory::getUser();
$uname = strtoupper($user->get(‘username’));

// tabla de rankings
$usertable_ranking_participantes_puntos_cb = «logs_ranking_participantes_puntos_cb»;
$usertable_ranking_participantes_puntos_dmr = «logs_ranking_participantes_puntos_dmr»;
$usertable_ranking_participantes_puntos_hf = «logs_ranking_participantes_puntos_hf»;
$usertable_ranking_participantes_puntos_vhf = «logs_ranking_participantes_puntos_vhf»;
$usertable_ranking_participantes_puntos_pmr = «logs_ranking_participantes_puntos_pmr»;
$usertable_ranking_participantes_puntos_voi = «logs_ranking_participantes_puntos_voi»;
$usertable_ranking_participantes_puntos_cw = «logs_ranking_participantes_puntos_cw»;
$usertable_ranking_participantes_puntos_mgm = «logs_ranking_participantes_puntos_mgm»;

// tablas de logs
$usertable = «logs»;
//$fechatable = «afecha»;

// password
$uploadpassword = «acracbpuntoorg»;

$dir_articulo = ‘/index.php?option=com_content&view=article&id=860’;
//$dir_articulo=’/acracb/index.php/acracb-prueba2′;

$dir_imagenes_corto = ‘/images/’;
$dir_imagenes = $dir_imagenes_corto . ‘bancomu/’;

if (!isset($_POST[«acracb_form_admin_subir_logs_accion»])) {$accion = «»;} else { $accion = $db->escape($_POST[«acracb_form_admin_subir_logs_accion»]);}
if (!isset($_POST[«pref»])) {$pref = «»;} else { $pref = $db->escape($_POST[«pref»]);}
if (!isset($_POST[«Actividad»])) {$Actividad = «»;} else { $Actividad = $db->escape($_POST[«Actividad»]);}
//if (!isset($_POST[«act»])) { $act=»»; } else {$act=$db->escape($_POST[«act»]);}
//if (!isset($_POST[«act2″])) { $act2=»»; } else {$act2=$db->escape($_POST[«act2»]);}
if (!isset($_POST[«ref»])) {$ref = «»;} else { $ref = $db->escape($_POST[«ref»]);}
if (!isset($_POST[«dia»])) {$dia = «»;} else { $dia = $db->escape($_POST[«dia»]);}
if (!isset($_POST[«mes»])) {$mes = «»;} else { $mes = $db->escape($_POST[«mes»]);}
if (!isset($_POST[«ano»])) {$ano = «»;} else { $ano = $db->escape($_POST[«ano»]);}
if (!isset($_POST[«operador»])) {$operador = «»;} else { $operador = $db->escape($_POST[«operador»]);}
if (!isset($_POST[«otro_operador»])) {$otro_operador = «»;} else { $otro_operador = $db->escape($_POST[«otro_operador»]);}
if (!isset($_POST[«password»])) {$password = «»;} else { $password = $db->escape($_POST[«password»]);}
if (!isset($_POST[«tipo_diploma»])) {$tipo_diploma = «»;} else { $tipo_diploma = $db->escape($_POST[«tipo_diploma»]);}

$accion = trim($accion);
$Pref = trim($Pref);
$Actividad = trim($Actividad);
//$act=trim($act);
//$act2=trim($act2);
$ref = trim($ref);
$dia = trim($dia);
$mes = trim($mes);
$ano = trim($ano);
$operador = trim($operador);
$otro_operador = trim($otro_operador);
$password = trim($password);
$tipo_diploma = trim($tipo_diploma);

$Pref = str_replace(‘%’, », $Pref);
$Actividad = str_replace(‘%’, », $Actividad);
//$act=str_replace(‘%’,», $act);
//$act2=str_replace(‘%’,», $act2);
$ref = str_replace(‘%’, », $ref);
$dia = str_replace(‘%’, », $dia);
$mes = str_replace(‘%’, », $mes);
$ano = str_replace(‘%’, », $ano);
$operador = str_replace(‘%’, », $operador);
$otro_operador = str_replace(‘%’, », $otro_operador);
$password = str_replace(‘%’, », $password);
$tipo_diploma = str_replace(‘%’, », $tipo_diploma);
list($Actividad_temp, $act, $act2) = explode(«/», $Actividad);
$Actividad = $Actividad_temp;
if (isset($act)) {$act = «/$act»;} else {}
if (isset($act2)) {$act2 = «/$act2»;} else {}

$valid_file = 0;
$duplicateQSO = 0;
$qso_count = 0;
$errorQSO = 0;

if (!isset($_FILES[‘Filename’])) {
$browser_name = «»;
$temp_name = «»;
$filesize = «»;
} else {
$browser_name = $_FILES[‘Filename’][‘name’];
$temp_name = $_FILES[‘Filename’][‘tmp_name’];
$filesize = $_FILES[‘Filename’][‘size’];
}
?>
<?php
/*funcionaes auxiliares*/
function validar_fichero($file)
{
$string = «»;
$valid_file = 2;
$desc_error = «»;
$encontrado_call = 0;
$log = 0;
$log_html = 0;

while ($string = fgets($file, 1024)) {
$string = utf8_encode(strtoupper($string));
//$string = strtoupper ($string);
if ($log_html == 1) {echo «html1-> » . htmlentities($string) . «<br>»;}
if (stristr($string, «<EOH>») || stristr($string, «<CALL») || stristr($string, «<BAND») || stristr($string, «<FREQ») || stristr($string, «<MODE»)) {
if (stristr($string, «<CALL»)) {
$encontrado_call = $encontrado_call + 1;
if ($log == 1) {echo «log01-> » . $encontrado_call . «<br>»;}
} elseif (stristr($string, «<EOH>»)) {
$encontrado_call = 0;
if ($log == 1) {echo «log02-> » . $encontrado_call . «<br>»;}
}

$EOR = 0;
if ($log_html == 1) {echo «html2-> » . htmlentities($string) . «<br>»;}
// inicializamos el array
$qso_data = array(‘MyCallsign’ => », ‘Date’ => », ‘Time’ => », ‘Callsign’ => », ‘Band’ => », ‘Frequency’ => », ‘Mode’ => », ‘RSTS’ => », ‘RSTR’ => »);

while (!$EOR) {
readADIFQSO($string, $qso_data);
/*buscamos el final de cada registro del ADIF*/
if (stristr($string, «<EOR>»)) {
$EOR = 1;
if (strlen(trim($qso_data[‘Callsign’])) <= 0) {
$valid_file = 0;
$desc_error = «CALL NO ENCONTRADO»;
if ($log == 1) {echo «log03-> » . $desc_error . «<br>»;}
} else {
if ($valid_file != 0) {
$valid_file = 1;
}
}
if ($encontrado_call > 1) {
$valid_file = 0;
$desc_error = «1. FALTA EOR (» . $encontrado_call . «)»;
if ($log == 1) {echo «log04-> » . $desc_error . «<br>»;}
}
$encontrado_call = 0;
if ($log == 1) {echo «log05-> » . $encontrado_call . «<br>»;}
} else {
$string = fgets($file, 1024);
if (stristr($string, «<CALL»)) {
$encontrado_call = $encontrado_call + 1;
if ($log == 1) {echo «log06-> » . $encontrado_call . «<br>»;}
}
if (stristr($string, «<EOH>»)) {
// inicializamos el array
$qso_data = array(‘MyCallsign’ => », ‘Date’ => », ‘Time’ => », ‘Callsign’ => », ‘Band’ => », ‘Frequency’ => », ‘Mode’ => », ‘RSTS’ => », ‘RSTR’ => »);
$encontrado_call = 0;
if ($log == 1) {echo «log07-> » . $encontrado_call . «<br>»;}
}
if ($log_html == 1) {echo «html3-> » . htmlentities($string) . «<br>»;}
}
}
}
}

if ($valid_file != 0) {$valid_file = 1;}
if ($log == 1) {if ($valid_file == 0) {echo «log08-> » . $desc_error . «<br>»;}}

return $valid_file;
}

function readADIFQSO($string, &$qso_data)
{
$string = utf8_encode(strtoupper($string));
//$string = strtoupper($string);

// Read Date
if ($s = stristr($string, «<QSO_DATE»)) {
$values = sscanf($s, «<QSO_DATE:%d>%s «, $length, $qso_data[‘Date’]);
$qso_data[‘Date’] = substr($qso_data[‘Date’], 0, $length);
if ($values != 2) {
sscanf($s, «<QSO_DATE:%d:%c>%s «, $length, $dummy, $qso_data[‘Date’]);
}
}

// Read Time
if ($s = stristr($string, «<TIME_ON»)) {
$values = sscanf($s, «<TIME_ON:%d>%s «, $length, $qso_data[‘Time’]);
$qso_data[‘Time’] = substr($qso_data[‘Time’], 0, $length);
if ($values != 2) {
sscanf($s, «<TIME_ON:%d:%c>%s «, $length, $dummy, $qso_data[‘Time’]);
}

/*if (strlen($qso_data[‘Time’]) > «4») {
$qso_data[‘Time’] = substr($qso_data[‘Time’], 0, 4);
}*/
}

// Read Callsign
if ($s = stristr($string, «<CALL»)) {
//$values = sscanf ($s, «<CALL:%d>%s «, $length,$qso_data[‘Callsign’]);
//para que tenga en cuenta los espacios
$values = sscanf($s, «<CALL:%d>%[^\n]», $length, $qso_data[‘Callsign’]);
$qso_data[‘Callsign’] = explode(«<«, $qso_data[‘Callsign’]);
$qso_data[‘Callsign’] = $qso_data[‘Callsign’][0];
if ($values != 2) {
sscanf($s, «<CALL:%d:%c>%s «, $length, $dummy, $qso_data[‘Callsign’]);
}

}

// Read Band
if ($s = stristr($string, «<BAND»)) {
$values = sscanf($s, «<BAND:%d>%s «, $length, $qso_data[‘Band’]);
$qso_data[‘Band’] = substr($qso_data[‘Band’], 0, $length);
if ($values != 2) {
sscanf($s, «<BAND:%d:%c>%s «, $length, $dummy, $qso_data[‘Band’]);
}

if (($pos = strpos($qso_data[‘Band’], ‘M’)) != null) {
$qso_data[‘Band’][$pos] = ‘ ‘;
}

$qso_data[‘Band’] = trim($qso_data[‘Band’]);
}

// Read Frequency
if ($s = stristr($string, «<FREQ»)) {
$values = sscanf($s, «<FREQ:%d>%s «, $length, $qso_data[‘Frequency’]);
$qso_data[‘Frequency’] = substr($qso_data[‘Frequency’], 0, $length);
}

// Read Mode
if ($s = stristr($string, «<MODE»)) {
$values = sscanf($s, «<MODE:%d>%s «, $length, $qso_data[‘Mode’]);
$qso_data[‘Mode’] = substr($qso_data[‘Mode’], 0, $length);
if ($values != 2) {
sscanf($s, «<MODE:%d:%c>%s «, $length, $dummy, $qso_data[‘Mode’]);
}

switch ($qso_data[‘Mode’]) {
case «USB»:
case «LSB»:
$qso_data[‘Mode’] = «SSB»;
}
}

}

// Function to read an ADIF file and insert each QSO into the database
function processADIFFile($file, &$qso_count, &$duplicateQSO, &$errorQSO, $usertable, $pref, $Actividad, $act, $act2, $ref, $dia, $mes, $ano, $operador, $otro_operador, &$duplicados, &$insertados, $tipo_diploma)
{
$string = «»;

while ($string = fgets($file, 1024)) {
$string = utf8_encode(strtoupper($string));
//$string = strtoupper($string);

if (stristr($string, «<EOH>») || stristr($string, «<CALL») || stristr($string, «<BAND») || stristr($string, «<FREQ») || stristr($string, «<MODE»)) {
$EOR = 0;
// inicializamos el array
$qso_data = array(‘MyCallsign’ => », ‘Date’ => », ‘Time’ => », ‘Callsign’ => », ‘Band’ => », ‘Frequency’ => », ‘Mode’ => », ‘RSTS’ => », ‘RSTR’ => »);
while (!$EOR) {
readADIFQSO($string, $qso_data);
/*buscamos el final de cada registro del ADIF*/
if (stristr($string, «<EOR>»)) {
$EOR = 1;
/*ahora ya hemos leido el registro entero que puede
tener varias lineas hasta encontrar el <EOR>*/
if (strlen(trim($qso_data[‘Band’])) <= 0) {
if (strlen(trim($qso_data[‘Frequency’])) > 0) {
$qso_data[‘Frequency’] = substr($qso_data[‘Frequency’], 0, -2);
$frecuencia_temp = strval(str_replace(array(‘,’, ‘.’), array(», »), trim($qso_data[‘Frequency’])));
$frecuencia_valor = «»;
if ($frecuencia_temp >= 1830 and $frecuencia_temp <= 1850) {$frecuencia_valor = «160»;}
if ($frecuencia_temp >= 3500 and $frecuencia_temp <= 3800) {$frecuencia_valor = «80»;}
if ($frecuencia_temp >= 7000 and $frecuencia_temp <= 7200) {$frecuencia_valor = «40»;}
if ($frecuencia_temp >= 10100 and $frecuencia_temp <= 10150) {$frecuencia_valor = «30»;}
if ($frecuencia_temp >= 14000 and $frecuencia_temp <= 14350) {$frecuencia_valor = «20»;}
if ($frecuencia_temp >= 18068 and $frecuencia_temp <= 18168) {$frecuencia_valor = «17»;}
if ($frecuencia_temp >= 21000 and $frecuencia_temp <= 21450) {$frecuencia_valor = «15»;}
if ($frecuencia_temp >= 24890 and $frecuencia_temp <= 24990) {$frecuencia_valor = «12»;}
if ($frecuencia_temp >= 28000 and $frecuencia_temp <= 29700) {$frecuencia_valor = «10»;}
if ($frecuencia_temp >= 50000 and $frecuencia_temp <= 52000) {$frecuencia_valor = «6»;}
if (strlen($frecuencia_valor) > 0) {
$qso_data[‘Band’] = $frecuencia_valor;
} else {
$qso_data[‘Band’] = ’40’;
}
} else {
$qso_data[‘Band’] = ’40’;
}
}
/*la fecha tiene el formato añonmesdia -> 20170929*/
$dia = substr($qso_data[‘Date’], -2);
$mes = substr($qso_data[‘Date’], -4, -2);
$ano = substr($qso_data[‘Date’], 0, -4);

$qso_data[‘Callsign’] = trim($qso_data[‘Callsign’]);
$qso_data[‘Band’] = trim($qso_data[‘Band’]);
$qso_data[‘Mode’] = trim($qso_data[‘Mode’]);

if (strlen(trim($qso_data[‘Mode’])) <= 0) {$qso_data[‘Mode’] = ‘SSB’;}
/*
comprobamos que:
– concat(pref,Actividad,act,act2) like concat(‘$pref’,’$Actividad’,’$act’,’$act2′)
– Qrz like $qso_data[‘Callsign’]
– ref like ‘$ref’
– concat(dia,’/’,mes,’/’,ano) like concat(‘$dia’,’/’,’$mes’,’/’,’$ano’)
– banda like $qso_data[‘Band’]
– modo like $qso_data[‘Mode’]
*/
$sql = «SELECT count(*) as total FROM $usertable where concat(pref,Actividad,act,act2) like concat(‘$pref’,’$Actividad’,’$act’,’$act2′) and Qrz like ‘» . $qso_data[‘Callsign’] . «‘ and ref like ‘$ref’ and concat(dia,’/’,mes,’/’,ano) like concat(‘$dia’,’/’,’$mes’,’/’,’$ano’) and banda like ‘» . $qso_data[‘Band’] . «‘ and modo like ‘» . $qso_data[‘Mode’] . «‘ and tipo_diploma='» . $tipo_diploma . «‘»;
$db = JFactory::getDbo();
$db->setQuery($sql);
$total = $db->loadResult();
if ($total <= 0 and strlen($Actividad) > 0 and strlen($qso_data[‘Callsign’]) > 0 and strlen($ref) > 0 and strlen($qso_data[‘Band’]) > 0 and strlen($qso_data[‘Mode’]) > 0 and strlen($dia) > 0 and strlen($mes) > 0 and strlen($ano) > 0) {
// Insert QSO into the database
/*
cb y fm 5 puntos
26000 30000 cb
144000 146000 fm (vhf)
otros 1 punto
*/
$cinco_puntos = array(‘CB’, ‘AM’, ‘FM’, ‘DMR’, ‘VHF’);

/*asignamos cuando otorgamos 5 puntos*/
if ($tipo_diploma == ‘8’) {
$cinco_puntos = array();
}

if (in_array($tipo_diploma, array(‘5′,’9′,’10’,’11’,’14’,’15’,’16’,’17’,’18’,’20’,’21’,’22’,’23’,’24’,’25’,’26’,’29’, ’31’,’39’))) {
$cinco_puntos = array(‘CB’, ‘AM’);
}

/* asignamos puntos*/
$puntos = ‘1’;
if (in_array(strtoupper(trim($qso_data[‘Mode’])), $cinco_puntos)) {
$puntos = ‘5’;
}

/* 1 punto todo*/
if (in_array($tipo_diploma, array(’40’,’41’,’42’,’44’,’48’,’49’,’50’,’51’,’56’,’57’,’58’,’60’,’61’,’62’,’63’,’64’,’65’,’66’,’67’,’68’,’69’,’70’,’71’,’72’,’73’,’74’,’77’,’78’,’79’,’80’,’81’))) {
$puntos = ‘1’;
if (in_array(strtoupper(trim($qso_data[‘Mode’])), $cinco_puntos)) {
$puntos = ‘1’;
}

/* Definición de HF*/

elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘SSB’, ‘USB’, ‘LSB’))) {
$puntos = ‘1’;
}

/* Definición de MGM */

if ((in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘FT8′,’FT4′,’MFSK’,’PSK’,’RTTY’))) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(‘160M’,’80M’,’40M’,’30M’,’160′,’80’,’40’,’30’)))) {
$puntos = ‘1’;
}
}

if (in_array($tipo_diploma, array(’32’,’33’))) {

$puntos = ‘1’;
if (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘VHF’))) {
$puntos = ‘2’;
}

if ((in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘FM’))) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(‘2′,’2M’)))) {

$puntos = ‘2’;
}

// pmr es modo fm y banda 67cm, aveces es 67c y otras 67cm
if ((in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘FM’))) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(’67C’,’67CM’)))) {
$puntos = ‘5’;
}
}

if (in_array($tipo_diploma, array(’55’))) {
$puntos = ‘1’;

// CB

if ((in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘AM’))) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(’40’)))) {

$puntos = ‘5’;
}

// VHF

if ((in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘FM’))) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(‘2’)))) {

$puntos = ‘1’;

}
// pmr es modo fm y banda 67cm
if ((in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘FM’))) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(’67C’)))) {
$puntos = ‘1’;
}
}

if (in_array($tipo_diploma, array(’43’))) {

$puntos = ‘1’;

if ((in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘FM’))) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(‘2′,’2M’)))) {
// vhf
$puntos = ‘2’;
}elseif ((in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘VOI’))) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(’70C’,’70CM’)))){
// voi
$puntos = ‘2’;
}elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘SSB’, ‘USB’, ‘LSB’))) {
// hf
$puntos = ‘1’;
}elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘DMR’, ‘DIGITALVOICE’))) {
// dmr
$puntos = ‘1’;
}else {
echo «Modo no compatible»;
break;
}

}

if (in_array($tipo_diploma, array(’59’))) {

if ((in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘FM’))) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(‘2′,’2M’)))) {
// VHF
$puntos = ‘1’;
}elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘CB’, ‘AM’))) {
// CB
$puntos = ‘5’;
}elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘DMR’, ‘DIGITALVOICE’))) {
// DMR
$puntos = ‘1’;
}elseif ((in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘FM’))) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(’67C’,’67CM’)))) {
// PMR
$puntos = ‘5’;
}elseif ((in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘VOI’))) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(’70C’,’70CM’)))){
// VOI
$puntos = ‘1’;
}elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘SSB’, ‘USB’, ‘LSB’))) {
// HF
$puntos = ‘1’;
}else {
echo «Modo no compatible»;
break;
}
}

if (in_array($tipo_diploma, array(’34’,’45’,’46’))) {
$puntos = ‘1’;
}

if (in_array($tipo_diploma, array(’47’))){
$puntos = ‘1’;
if (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘CW’)) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(‘160M’,’80M’,’40M’,’30M’,’20M’,’17M’,’12M’,’10M’,’6M’,’160′,’80’,’40’,’30’,’20’,’17’,’12’,’10’,’6′)))) {
$puntos = ‘1’;
}elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘CB’, ‘AM’)) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(’40M’,’40’)))) {
$puntos = ‘1’;
}elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘VOI’)) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(’70C’,’70’)))) {
$puntos = ‘1’;
}elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘HF’, ‘SSB’, ‘USB’, ‘LSD’)) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(‘160M’,’80M’,’40M’,’30M’,’20M’,’17M’,’15M’,’12M’,’10M’,’6M’,’160′,’80’,’40’,’30’,’20’,’17’,’15’,’12’,’10’,’6′)))) {
$puntos = ‘1’;
}elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘VHF’, ‘FM’)) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(‘2M’,’2′)))) {
$puntos = ‘1’;
}elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘MGM’,’FT8′,’FT4′,’MFSK’,’PSK’,’RTTY’)) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(‘160M’,’80M’,’40M’,’30M’,’160′,’80’,’40’,’30’)))) {
$puntos = ‘1’;
}elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘PMR’, ‘FM’)) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(’67C’,’67’)))) {
$puntos = ‘1’;
}elseif (in_array(strtoupper(trim($qso_data[‘Mode’])), array(‘DMR’, ‘dmr’, ‘DIGITALVOICE’)) and (in_array(strtoupper(trim($qso_data[‘Band’])), array(’70M’,’70’,’70C’)))) {
$puntos = ‘1’;
}
}

$ref = $puntos;
/*$sql = «INSERT INTO $usertable (pref,Actividad,act,act2,Qrz,ref,banda,modo,dia,mes,ano,operador,otro_operador,tipo_diploma) values (‘» . $pref . «‘,'» . $Actividad . «‘,'» . $act . «‘,'» . $act2 . «‘,'» . $qso_data[‘Callsign’] . «‘,'» . $ref . «‘,'» . $qso_data[‘Band’] . «‘,'» . $qso_data[‘Mode’] . «‘,'» . $dia . «‘,'» . $mes . «‘,'» . $ano . «‘,'» . $operador . «‘,'» . $otro_operador . «‘,'» . $tipo_diploma . «‘)»;*/
$sql = «INSERT INTO $usertable (pref,Actividad,act,act2,Qrz,ref,banda,modo,dia,mes,ano,operador,otro_operador,tipo_diploma,fecha_hora) values (‘» . $pref . «‘,'» . $Actividad . «‘,'» . $act . «‘,'» . $act2 . «‘,'» . $qso_data[‘Callsign’] . «‘,'» . $ref . «‘,'» . $qso_data[‘Band’] . «‘,'» . $qso_data[‘Mode’] . «‘,'» . $dia . «‘,'» . $mes . «‘,'» . $ano . «‘,'» . $operador . «‘,'» . $otro_operador . «‘,'» . $tipo_diploma . «‘,'» . date_format(date_create($qso_data[‘Date’] . ‘ ‘ . $qso_data[‘Time’]), ‘Y-m-d H:i:s’) . «‘)»;
$db = JFactory::getDbo();
$db->setQuery($sql);
$result = $db->execute();

if ($result) {
$qso_count++;
$insertados[$qso_count][‘actividad’] = trim($pref . $Actividad . $act . $act2);
$insertados[$qso_count][‘qrz’] = trim($qso_data[‘Callsign’]);
$insertados[$qso_count][‘fecha’] = trim($dia . ‘/’ . $mes . ‘/’ . $ano);
$insertados[$qso_count][‘banda’] = trim($qso_data[‘Band’]);
$insertados[$qso_count][‘modo’] = trim($qso_data[‘Mode’]);
} else {
$errorQSO++;
}
} else {
$duplicateQSO++;
$duplicados[$duplicateQSO][‘actividad’] = trim($pref . $Actividad . $act . $act2);
$duplicados[$duplicateQSO][‘qrz’] = trim($qso_data[‘Callsign’]);
$duplicados[$duplicateQSO][‘fecha’] = trim($dia . ‘/’ . $mes . ‘/’ . $ano);
$duplicados[$duplicateQSO][‘banda’] = trim($qso_data[‘Band’]);
$duplicados[$duplicateQSO][‘modo’] = trim($qso_data[‘Mode’]);
}

/*si no hemos encontrado el EOR seguimos*/
} else {
$string = fgets($file, 1024);
$string = utf8_encode(strtoupper($string));
//$string = strtoupper($string);
if (stristr($string, «<EOH>»)) {
// inicializamos el array
$qso_data = array(‘MyCallsign’ => », ‘Date’ => », ‘Time’ => », ‘Callsign’ => », ‘Band’ => », ‘Frequency’ => », ‘Mode’ => », ‘RSTS’ => », ‘RSTR’ => »);
}
}
}
}
}
}
?>
<script language=»javascript» type=»text/javascript»>
function accion(tipo)
{
document.getElementById(«acracb_form_admin_subir_logs_accion»).value = tipo;
document.getElementById(«acracb_form_admin_subir_logs»).submit();
}
function inicializar()
{
document.getElementById(«acracb_form_admin_subir_logs_accion»).value = «»;
document.getElementById(«acracb_form_admin_subir_logs»).submit();
}
</script>
<?php

if (strlen($accion) <= 0) {
?>
<div style=’margin-left:30px;’>
<h3 class=»titulo_anunciar_actividad»>&nbsp;&nbsp;SUBIDA LOGS acracb&nbsp;&nbsp;</h3>
<p align=left>
<font size=2>
<br>
Analizemos esta actividad EA7/IK9XXX/P/QRP :
<ul>
<li><b>Prefijo</b> es EA7/</li>
<li><b>Actividad</b> es IK9XXX</li>
<li><b>Act</b> es /P</li>
<li><b>Act2</b> es /QRP</li>
</ul>
Solamente es aceptado el formato ADIF, los campos que seran necesarios son:
<ul>
<li><b>QSO_DATE</b> tipo 20140413 donde 2014 es el año 04 el mes y 13 el día</li>
<li><b>MODE</b> por defecto SSB</li>
<li><b>CALL</b> el Qrz de la actividad</li>
<li><b>BAND</b> por defecto 40</li>
<li>
<b>FREQ</b> si no existe <b>BAND</b> se tendrá en cuenta <b>FREQ</b> según la tabla de equivalencias siguiente:
<table border=0 width=45%>
<tr>
<td width=15%>&nbsp;</td>
<td width=15%>&nbsp;</td>
<td width=15%>&nbsp;</td>
</tr>
<tr>
<td width=15%>FREQ ENTRE</td>
<td width=15%>FREQ HASTA</td>
<td width=15%>BAND EQUIVALENTE</td>
</tr>
<tr>
<td>1830</td>
<td>1850</td>
<td>160</td>
</tr>
<tr>
<td>3500</td>
<td>3800</td>
<td>80</td>
</tr>
<tr>
<td>7000</td>
<td>7200</td>
<td>40</td>
</tr>
<tr>
<td>10100</td>
<td>10150</td>
<td>30</td>
</tr>
<tr>
<td>14000</td>
<td>14350</td>
<td>20</td>
</tr>
<tr>
<td>18068</td>
<td>18168</td>
<td>17</td>
</tr>
<tr>
<td>21000</td>
<td>21450</td>
<td>15</td>
</tr>
<tr>
<td>24890</td>
<td>24990</td>
<td>12</td>
</tr>
<tr>
<td>28000</td>
<td>29700</td>
<td>10</td>
</tr>
<tr>
<td>50000</td>
<td>52000</td>
<td>6</td>
</tr>
</table>
</li>
<li>SI no existe ni <b>BAND</b> ni <b>FREQ</b> por defecto será <b>BAND</b> 40</li>
</ul>
Comentaremos algunas consideraciones que se tendrán en cuenta con el fichero ADIF:
<ul>
<li>Los registros duplicados que se detecten no se tendrán en cuenta.</li>
<li>
La estructura del fichero ADIF será válida SI contiene la siguiente información:
<ul>
<li>0, 1 o más lineas con cualquiera información, como comentarios, lineas en blanco, ect…</li>
<li>a continuación debe existir EOH</li>
<li>a continuación puede existir 0, 1 o más lineas con cualquiera información, como comentarios, lineas en blanco, ect…</li>
<li>una vez encontrado EOH por cada logs será necesario las etiquetas QSO_DATE, CALL, BAND (FREQ), MODE y EOR</li>
</ul>
</li>
</ul>
Los campos con el <span style=»color:red»><b>*</b></span> son datos obligatorios que son necesario rellenar.
</font>
</p>
<center>
<p align=center>
<form name=»acracb_form_admin_subir_logs» id=»acracb_form_admin_subir_logs» action=»<?php echo $dir_articulo; ?>» method=post enctype=»multipart/form-data»>
<input size=25 type=hidden id=»acracb_form_admin_subir_logs_accion» name=»acracb_form_admin_subir_logs_accion» value=»<?php echo $accion; ?>»>

<table border=»0″ width=»65%» align=center>
<tr>
<td width=»15%» align=left><b>Diploma ACRACB</b>&nbsp;<span style=»color:red»><b>*</b></span></td>
<td width=»50%» align=left>
<select name=»tipo_diploma» id=»lista_diplomas»>
<!– <option value=»»>0 – Seleccione un diploma</option>–>
<?php
$sql = ‘SELECT codigo,descripcion FROM acracb_lista_diplomas where funcion=2 and visible=1 ORDER BY codigo DESC’;
$db->setQuery($sql);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
$codigo = $row->codigo;
$descripcion = $row->descripcion;
echo ‘<option value=»‘ . $codigo . ‘»>’ . $descripcion . ‘</option>’;

}
?>
</select>

<script>
window.onload=function(){
var lb = document.getElementById(‘lista_diplomas’);
arrTexts = new Array();
arrValues = new Array();
arrOldTexts = new Array();

for(i=0; i<lb.length; i++)
{
arrTexts[i] = lb.options[i].text;
arrValues[i] = lb.options[i].value;
arrOldTexts[i] = lb.options[i].text;
}

arrTexts.sort();

for(i=0; i<lb.length; i++)
{
lb.options[i].text = arrTexts[i];
for(j=0; j<lb.length; j++)
{
if (arrTexts[i] == arrOldTexts[j])
{
lb.options[i].value = arrValues[j];
j = lb.length;
}
}
}

}
</script>

</td>
</tr>
<hr>
<tr style=»display:none»>
<td width=»15%» align=left><b>Prefijo</b></td>
<td width=»50%» align=left><input type=»text» name=»pref» size=»3″ maxlength=»3″>&nbsp;Tipo EA1 a EA9 <b><u>SOLO EN CASO DE Estaciones NO-EA</u></b></td>
</tr>
<tr style=»display:none»>
<td width=»15%» align=left><b>Actividad</b>&nbsp;<span style=»color:red»><b>*</b></span></td>
<td width=»50%» align=left><input type=»text» name=»Actividad» size=»10″ maxlength=»15″ value=»<?php echo $uname; ?>»>&nbsp;Tipo IK9XXX /P /QRP</td>
</tr>
<!–<tr>
<td width=»15%» align=left><b>Act</b></td>
<td width=»50%» align=left><input type=»text» name=»act» size=»5″ maxlength=»5″>&nbsp;Tipo /P</td>
</tr>
<tr style=»display:none»>
<td width=»15%» align=left><b>Act 2</b></td>
<td width=»50%» align=left><input type=»text» name=»act2″ size=»5″ maxlength=»5″>&nbsp;Tipo /QRP</td>
</tr>–>
<tr style=»display:none»>
<td width=»15%» align=left><b>Referencia</b>&nbsp;<span style=»color:red»><b>*</b></span></td>
<td width=»50%» align=left><input size=»10″ maxlength=»15″ name=»ref» type=»text» value=»0″>&nbsp;Tipo CSE-001</td>
</tr>
<tr style=»display:none»>
<td width=»15%» align=left><b>Fecha</b>&nbsp;<span style=»color:red»><b>*</b></span></td>
<td width=»50%» align=left>
<select name=»dia»>
<option value=»»>Dia</option>
<option value=»01″ selected >01</option>
<option value=»02″>02</option>
<option value=»03″>03</option>
<option value=»04″>04</option>
<option value=»05″>05</option>
<option value=»06″>06</option>
<option value=»07″>07</option>
<option value=»08″>08</option>
<option value=»09″>09</option>
<option value=»10″>10</option>
<option value=»11″>11</option>
<option value=»12″>12</option>
<option value=»13″>13</option>
<option value=»14″>14</option>
<option value=»15″>15</option>
<option value=»16″>16</option>
<option value=»17″>17</option>
<option value=»18″>18</option>
<option value=»19″>19</option>
<option value=»20″>20</option>
<option value=»21″>21</option>
<option value=»22″>22</option>
<option value=»23″>23</option>
<option value=»24″>24</option>
<option value=»25″>25</option>
<option value=»26″>26</option>
<option value=»27″>27</option>
<option value=»28″>28</option>
<option value=»29″>29</option>
<option value=»30″>30</option>
<option value=»31″>31</option>
</select>&nbsp;&nbsp;
<select name=»mes»>
<option value=»»>Mes</option>
<option value=»01″ selected>01</option>
<option value=»02″>02</option>
<option value=»03″>03</option>
<option value=»04″>04</option>
<option value=»05″>05</option>
<option value=»06″>06</option>
<option value=»07″>07</option>
<option value=»08″>08</option>
<option value=»09″>09</option>
<option value=»10″>10</option>
<option value=»11″>11</option>
<option value=»12″>12</option></select>&nbsp;&nbsp;
<select name=»ano»>
<option value=»»>Año</option>
<?php
$sql = ‘SELECT min(ano) FROM logs’;
$db->setQuery($sql);
$anio_inicio = $db->loadResult();
$sql = ‘SELECT max(ano) ano_max FROM logs’;
$db->setQuery($sql);
$anio_max = $db->loadResult();
$ano_actual = date(«Y»);
$mes_actual = date(«m»);
$dia_actual = date(«d»);
if (strlen($anio_inicio) <= 0) {
$anio_inicio = $ano_actual;
$anio_max = $ano_actual;
}
if ($mes_actual >= 12) {$anio_max = $ano_actual + 1;}
$indice_array = 1;
for ($var_ano = $anio_inicio; $var_ano <= $anio_max; $var_ano++) {
echo ‘<option value=»‘ . $var_ano . ‘» selected>’ . $var_ano . ‘</option>’;
$array_ano[$indice_array] = $var_ano;
$indice_array++;
}
if (in_array($ano_actual, $array_ano) == false) {
echo ‘<option value=»‘ . $ano_actual . ‘» selected>’ . $ano_actual . ‘</option>’;
}
?>
</select>
</td>
</tr>
<tr>
<td width=»15%» align=left><b>Fichero ADIF</b>&nbsp;<span style=»color:red»><b>*</b></span></td>
<td width=»50%» align=left><input type=»file» name=»Filename» id=»Filename» size=»15″></td>
</tr>
<tr>
<td width=»15%» align=left><b>Operador</b>&nbsp;<span style=»color:red»><b>*</b></span></td>
<td width=»50%» align=left><input size=»10″ maxlength=»10″ name=»operador» type=»text»><span style=»color:red»>&nbsp;&nbsp;Se pondra como la actividad en los logs !!!</span></td>
</tr>
<tr>
<td width=»15%» align=left><b>Otros Operadores</b></td>
<td width=»50%» align=left><input size=»10″ maxlength=»50″ name=»otro_operador» type=»text»>&nbsp;&nbsp;EA5RK1,EA5RK2,EA5RK3</td>
</tr>
<tr>
<td width=»15%» align=left><b>Password</b>&nbsp;<span style=»color:red»><b>*</b></span></td>
<td width=»50%» align=left><input type=»text» name=»password» id=»password» size=»15″></td>
</tr>
</table>
<br>
<table border=»0″ width=»60%» align=center>
<tr>
<td align=center>
<input type=»button» name=»upload» value=»SUBIR LOG» onclick=»accion(‘paso01’);»>
</td>
</tr>
</table>
</form>
</p>
</center>
</div>
<?php
} elseif ($accion == «paso01») {
?>
<div style=’margin-left:30px;’>
<h3 class=»titulo_anunciar_actividad»>&nbsp;&nbsp;SUBIDA LOGS acracb&nbsp;&nbsp;</h3>
<p align=left>
<font size=2>
<br>
<form name=»acracb_form_admin_subir_logs» id=»acracb_form_admin_subir_logs» action=»<?php echo $dir_articulo; ?>» method=post enctype=»multipart/form-data»>
<input size=25 type=hidden id=»acracb_form_admin_subir_logs_accion» name=»acracb_form_admin_subir_logs_accion» value=»<?php echo $accion; ?>»>
</form>
<?php

/*nos aseguramos que ha intentado subir un archvivo*/
if (strlen($temp_name) > 0 && strlen($browser_name) > 0) {
/*nos aseguramos que el fichero se ha subido*/
if (is_uploaded_file($temp_name)) {
/*los datos introducidos por el usuario son validos*/
if (($Actividad != «») && ($ref != «») && ($dia != «») && ($mes != «») && ($ano != «») && ($tipo_diploma != «») && ($operador != «»)) {
/*el dato de la fecha es correcta*/
if ((is_numeric($dia)) && (is_numeric($mes)) && (is_numeric($ano))) {
/*el password es correcto*/
if (strlen($password) > 0 and $password == $uploadpassword) {
/*el fichero subido se puede abrir para manipularlo*/
if (($file1 = fopen($temp_name, «r»)) and ($file2 = fopen($temp_name, «r»))) {
$valid_file = validar_fichero($file1);
//$valid_file=1;
$duplicateQSO = 0;
$qso_count = 0;
$errorQSO = 0;
$insertados = array(0 => array(‘actividad’ => », ‘qrz’ => », ‘fecha’ => », ‘banda’ => », ‘modo’ => »));
$duplicados = array(0 => array(‘actividad’ => », ‘qrz’ => », ‘fecha’ => », ‘banda’ => », ‘modo’ => »));

if ($valid_file) {
$Actividad = $operador;
$operador = »;
/*primero eliminamos todo de una actividad*/
$sql = «DELETE FROM $usertable WHERE Actividad=’$Actividad’ and tipo_diploma=’$tipo_diploma'»;
$db = JFactory::getDbo();
$db->setQuery($sql);
$result = $db->execute();
processADIFFile($file2, $qso_count, $duplicateQSO, $errorQSO, $usertable, $pref, $Actividad, $act, $act2, $ref, $dia, $mes, $ano, $operador, $otro_operador, $duplicados, $insertados, $tipo_diploma);
}
if (!$valid_file) {
?>
<font size=3>
<p align=left>
<b>Se ha encontrado un error en el archivo:&nbsp;<?php echo $browser_name; ?></b>
<br><br>Ningún QSO cargado<br><br>
<a href=’javascript:inicializar();’>Volver</a>
</p>
</font>
<?php
} else {
echo «<br><center><font size=3><b>$errorQSO errores</b> encontrados.</font></center>»;
echo «<br><center><font size=3><b>$duplicateQSO QSOs</b> QSOs duplicados que no se han tenido en cuenta.</font></center>»;
if ($duplicateQSO > 0) {
?>
<br>
<center>
<table border=»0″ cellpadding=»0″ cellspacing=»0″ width=»45%» class=’tabla_acracb’>
<tr class=’tr_cab_acracb’>
<td width=»10%» align=»center»><b>Actividad</b></td>
<td width=»15%» align=»center»><b>Qrz</b></td>
<td width=»10%» align=»center»><b>Fecha</b></td>
<td width=»10%» align=»center»><b>Banda/Modo</b></td>
</tr>
<?php
$tr_impar = ‘tr_impar_acracb’;
$tr_par = ‘tr_par_acracb’;
for ($i = 1; $i <= $duplicateQSO; $i++) {
$tr_class = ($i % 2) ? $tr_impar : $tr_par;
echo «<tr class='» . $tr_class . «‘>
<td width=10% align=left><b>» . $duplicados[$i][‘actividad’] . «</b></td>
<td width=15% align=left><b>» . $duplicados[$i][‘qrz’] . «</b></td>
<td width=10% align=left><b>» . $duplicados[$i][‘fecha’] . «</b></td>
<td width=10% align=left><b>» . $duplicados[$i][‘banda’] . » – » . $duplicados[$i][‘modo’] . «</b></td>
</tr>»;
}
?>
</table>
</center>
<?php
}
echo «<br><center><font size=3><b>$qso_count QSOs</b> subidos a la base de datos en la Referencia:<b> $ref</b></font></center>»;
if ($qso_count > 0) {
?>

<br>
<center>
<table border=»0″ cellpadding=»0″ cellspacing=»0″ width=»45%» class=’tabla_acracb’>
<tr class=’tr_cab_acracb’>
<td width=»10%» align=»center»><b>Actividad</b></td>
<td width=»15%» align=»center»><b>Qrz</b></td>
<td width=»10%» align=»center»><b>Fecha</b></td>
<td width=»10%» align=»center»><b>Banda/Modo</b></td>
</tr>
<?php
$tr_impar = ‘tr_impar_acracb’;
$tr_par = ‘tr_par_acracb’;
for ($i = 1; $i <= $qso_count; $i++) {
$tr_class = ($i % 2) ? $tr_impar : $tr_par;
echo «<tr class='» . $tr_class . «‘>
<td width=10% align=left><b>» . $insertados[$i][‘actividad’] . «</b></td>
<td width=15% align=left><b>» . $insertados[$i][‘qrz’] . «</b></td>
<td width=10% align=left><b>» . $insertados[$i][‘fecha’] . «</b></td>
<td width=10% align=left><b>» . $insertados[$i][‘banda’] . » – » . $insertados[$i][‘modo’] . «</b></td>
</tr>»;
}
?>
</table>
</center>
<?php
}

?>
<font size=3>
<p align=left>
<br>
<center><a href=’javascript:inicializar();’>Volver Subir logs</a></center>
</p>
</font>
<?php
}
} else {
?>
<font size=3>
<p align=left>
<b>Error al abrir el fichero ADIF</b><br><br>
<a href=’javascript:inicializar();’>Volver</a>
</p>
</font>
<?php
}
} else {
?>
<font size=3>
<p align=left>
<b>El Password que has introducido no es valido.<br>Por favor vuelve a intentarlo!</b><br><br>
<a href=’javascript:inicializar();’>Volver</a>
</p>
</font>
<?php
}
} else {
?>
<font size=3>
<p align=left>
<b>Fecha incorrecta.</b><br><br>
<a href=’javascript:inicializar();’>Volver</a>
</p>
</font>
<?php
}
} else {
?>
<font size=3>
<p align=left>
<b>Hay que completar todos los campos necesarios</b><br><br>
<a href=’javascript:inicializar();’>Volver</a>
</p>
</font>
<?php
}
} else {
?>
<font size=3>
<p align=left>
<b>Error al subir el fichero ADIF</b><br><br>
<a href=’javascript:inicializar();’>Volver</a>
</p>
</font>
<?php
}
} else {
?>
<font size=3>
<p align=left>
<b>Error al subir el fichero ADIF</b><br><br>
<a href=’javascript:inicializar();’>Volver</a>
</p>
</font>
<?php
}
?>
</font>
</p>
</div>
<?php
}
?>{/source}

Scroll al inicio