Commit ed6a3e0b authored by f4eyq's avatar f4eyq

update 2/2/2019 - 1

parent bfd01572
......@@ -20,10 +20,10 @@
/**
* @author Bastien Barbe - CRX-FRAMEWORK (cms part)
* @date 012005
* @revision 09072017
* @revision 01022019
* @module file
* @copyright see header
* @version 1.3.1
* @version 1.3.2
*/
class crxFile{
......@@ -205,13 +205,27 @@ class crxFile{
}
//todo implement new method : file_get_contents
static function getFileContent($file,$create_if_not_exist_yet=true,$cache_result=false,$cache_key=''){
if($cache_result && isset($_SESSION[$cache_key])){
return $_SESSION[$cache_key];
}
if(file_exists($file)){
$content = file_get_contents($file);
if($cache_result){
$_SESSION[$cache_key] = $content;
}
return $content;
/*
$file_size=filesize($file);
if($file_size>0){
$fp=fopen($file,'r');
......@@ -223,14 +237,16 @@ class crxFile{
}
return $content;
}
}elseif($create_if_not_exist_yet){
}*/
}
elseif($create_if_not_exist_yet){
@touch($file);
}
}
//todo implement new method : file_put_contents
function setFileContent($file,$content){
$file = trim($file);
......@@ -247,19 +263,23 @@ class crxFile{
}
}
file_put_contents($file,$content);
return true;
/*
if(
file_exists($file) &&
fopen($file, "wb")
){
$fp = fopen($file, "wb");
if(fputs($fp, $content)){
fclose($fp);
return true;
}else{
}
}
else{
......@@ -268,6 +288,12 @@ class crxFile{
//throw new crxException("Error : file :".$file.' didnt exist ! ');
return false;
}
*/
}
function fileSize($file){
......
<?php
/**
* @author Bastien Barbe - CRX-FRAMEWORK
* @version 1.0
* @date 11/2018
* @revision 23/11/2018
* @module library
* @description This class is used to load composer project with simply
* set the lib source path :
*
* $p = _APPLI_MAIN_MODULES_PATH_.'dxclusterAiReport/php-ml-master/src';
* $ia = new crxLoaderForLib($p,'Phpml');
*
*/
class crxLoaderForLib{
var $_path_root = '';
var $_ns = '';
public function __construct($path_root_project,$name_space){
$this->debug = 0;
$this->_path_root = $path_root_project;
$this->_ns = $name_space;
$this->_file = array();
spl_autoload_register( array($this, 'load') );
}
function load( $class ){
if(empty($this->_file)){
if ($handle = opendir($this->_path_root)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && strtolower(substr($entry, strrpos($entry, '.') + 1)) == 'php') {
$f=explode('.',$entry);
$k=$f[0];
$php_file[$k]=$entry;
}
else{
if ($handleSub = opendir($this->_path_root.'/'.$entry)) {
while (false !== ($entrysub = readdir($handleSub))) {
if ($entrysub != "." && $entrysub != ".." && strtolower(substr($entrysub, strrpos($entrysub, '.') + 1)) == 'php') {
//echo "sub dir : $entry / $entrysub <br />";
$f=explode('.',$entrysub);
$k=$f[0];
$php_file[$k]=$entry.'/'.$entrysub;
}
}
closedir($handleSub);
}
}
}
closedir($handle);
//var_dump($class);
//var_dump($php_file);
//die();
}
}else{
$this->_file=$php_file;
}
$ftest='';
if(isset($php_file[$class])){
$ftest=$php_file[$class];
}
/*
else{
echo $class.' not found'."\n";
return;
}
*/
$include_path=$this->_path_root.'/'.$ftest;
if(is_file($include_path) && file_exists($include_path)){
if($this->debug)echo 'INFO include class:'.$class."\n";
//if($this->debug)var_dump($include_path);
require_once($include_path);
}
else{
//use Phpml\SupportVectorMachine\SupportVectorMachine;
//echo "name space class include :".$class._BR_;
$o=str_replace($this->_ns,'',$class);
$o=str_replace('\\','/',$o);
$o=$o.'.php';
//remove first / from path :
$o=crxString::removeFirstCharOfString($o);
$include_path=$this->_path_root.'/'.$o;
if(is_file($include_path) && file_exists($include_path)){
if($this->debug)echo 'INFO include class:'.$class."\n";
//var_dump($include_path);
require_once($include_path);
}else{
//echo 'ERROR:'.$class.' not found'."\n";
//echo "ERROR ON : $class : $include_path \n";
}
}
}
}
?>
<?php
class spotNg{
var $_task_dir_ham = '/home/hosting/www_root/ham.crx.cloud/html/app-php/dxClusterWeb/scheduler-dxspider2';
var $_tbl = 'crx_cluster_spots';
var $_data_map = array(
'HAM' =>
array(
'id_spot' => 'rowid',
'date_spot' => 'time',
'callsign_dx' => 'spotcall',
'callsign_sender'=> 'spotter',
'frequency' => 'freq',
'band' => '',
'mode' => '',
'source' => 'origin',
'comment' => 'comment'
),
'11M' =>
array(
'id_spot' => 'id_spot',
'date_spot' => 'date_spot',
'callsign_dx' => 'callsign_dx',
'callsign_sender'=> 'callsign_sender',
'frequency' => 'frequency',
'band' => 'band',
'mode' => 'mode',
'source' => 'source',
'comment' => 'comment'
)
);
function setCurrentModule($m){
$this->_current_module = $m;
}
function __construct($plateform_name,$dbi){
$this->_plateform=$plateform_name;
if($this->_plateform=='HAM')$this->_tbl='spot';
$this->c_db = $dbi;
$this->_uid = crxFramework::getGlobalValue('userId');
}
function put($spot_data){
/*
input :
dxcall
qrg
band
mode
rmq
+11m version :
report
qsotype
*/
if($this->_plateform=='11M'){
if($spot_data['band']=='11m') $spot_data['band']='11';
if($spot_data['band']=='pmruhf') $spot_data['band']='PMR';
$this->widget=$spot_data;
$u=crxFramework::getUserInstance();
$v=$u->getUserInfo('',crxFramework::getGlobalValue('userId'));
$this->widget['callsign_sender']= $v['callsign_main'];
$this->widget['callsign_dx'] = $spot_data['dxcall'];
$this->widget['frequency'] = (int)$spot_data['qrg'];
$this->widget['band'] = $spot_data['band'];
$this->widget['mode'] = $spot_data['mode'];
$this->widget['comment'] = $spot_data['rmq'];
$this->widget['report'] = (int)$spot_data['report'];
$this->widget['type'] = $spot_data['qsotype'];
$this->widget['source'] = 'N1';
$this->widget['date_spot'] = time();
$c = new dxClusterSpots();
$c->setDbHandler($this->c_db);
$geo=$c->calcGeoItuAndCqZone(
$this->widget['callsign_sender'],
$this->widget['callsign_dx']
);
foreach($geo as $k=>$v){$this->widget[$k]=$v;}
$this->widget['callsign_dx'] = dxClusterSpots::cleanCallsign($this->widget['callsign_dx']);
$this->widget['source'] = 'N1';
$this->_ispotObject = new spotObject();
$this->_ispotObject->setCurrentModule($this->_current_module);
$this->_ispotObject->setNodeInfo($this->widget['source']);
$this->_ispotObject->setClusterSchema(
array(
'date_spot',
'callsign_dx',
'locator_dx',
'name_dx',
'callsign_sender',
'locator_sender',
'name_sender',
'frequency',
'band',
'mode',
'report',
'type',
'comment',
'valid_level',
'source',
'spotitu',
'spotcq',
'spotteritu',
'spottercq'
)
);
$this->_ispotObject->setDbHandler($this->c_db);
$this->_ispotObject-> setParams();
$this->_ispotObject -> createNew($this->widget);
return TRUE;
}
if($this->_plateform=='HAM'){
$t = new crxSchedulerTask();
$t->setDbHandler($this->c_db);
$t->_debug=0;
$tid = $t->declareTask(
$this->_uid,
'Send spot on dx spider',
'dxspot',
'dxspidersendspot'
);
$u=crxFramework::getUserInstance();
$v=$u->getUserInfo('',crxFramework::getGlobalValue('userId'));
$p = array(
'dxspot',
array(
'sender' => $v['callsign_main'],
'dx' => $spot_data['dxcall'],
'qrg' => $spot_data['qrg'],
'comment' => $spot_data['rmq']
)
);
$t->setProperties($p);
$t->setTaskType('dxspot');
$t->setRootPath($this->_task_dir_ham);
$t->save();
return TRUE;
}
else{
return TRUE;
}
}
function inv($result,$fieldKey,$map){
//if($this->_plateform<>'HAM'){
// return $result[$fieldKey];
//}
$rkey=$map[$fieldKey];
$fieldValue=$result[$rkey];
return $fieldValue;
}
function getDebug($debug=0){
if($debug==1)return $this->dbg;
else return '';
}
function _oneOfsubBandIsSelected($sub){
foreach($sub as $k=>$v){
if($v==1)return true;
}return false;
}
function getSpots($cursor_low,$cursor_hight,$filters,$data_bands_values){
//date, dxcall, qrg
$spots_arr=array();
$map=$this->_data_map[$this->_plateform];
$WHERE=' ';
if(isset($filters['band']) && count($filters['band']) >=1){
if($this->_oneOfsubBandIsSelected($_SESSION['dsp_filter']['subband'])){
$WHERE.=' WHERE ';
}
foreach($filters['band'] as $band_key=>$v){
$bdv=$data_bands_values[$band_key]['band'];
$l=$bdv[0];
$h=$bdv[1];
if(!$this->_oneOfsubBandIsSelected($_SESSION['dsp_filter']['subband'])){
$WHERE.=" WHERE (`".$map['frequency']."` > $l AND `".$map['frequency']."` < $h ) ";
}
if($_SESSION['dsp_filter']['subband']){
//first count item available to build sql request : ( set OR or '' )
$it=0;foreach($_SESSION['dsp_filter']['subband'] as $kkk=>$vvv){
$bdv=$data_bands_values[$band_key][$kkk];
if($vvv==1 && $bdv[0]){
$it++;
}
}
foreach($_SESSION['dsp_filter']['subband'] as $kkk=>$vvv){
$bdv=$data_bands_values[$band_key][$kkk];
if($vvv==1 && $bdv[0]){
$cpt++;
$l=$bdv[0];
$h=$bdv[1];
$WHERE.=" (`".$map['frequency']."` > $l AND `".$map['frequency']."` < $h ) ";
//compare value with first count :
if($it<>$cpt)
$WHERE.=' OR ';
}
}
}
}
}
if(isset($filters['dxcall']) && $filters['dxcall']){
if($WHERE==' '){
$WHERE.=' WHERE ';
}else{
$WHERE.=' AND ';
}
$WHERE.=" `".$map['callsign_dx']."` = '".$filters['dxcall']."'";
}
$q='SELECT * FROM `'.$this->_tbl.'`'.$WHERE.'ORDER BY `'.$map['date_spot'].'` DESC LIMIT '.$cursor_low.' , '.$cursor_hight.'';
$this->c_db->execSql($q);
while($r=$this->c_db->returnLine()){
$spots_arr[]=array(
'id_spot' => $this->inv($r,'id_spot',$map),
'date_spot' => $this->inv($r,'date_spot',$map),
'callsign_dx' => $this->inv($r,'callsign_dx',$map),
'callsign_sender' => $this->inv($r,'callsign_sender',$map),
'frequency' => $this->inv($r,'frequency',$map),
'band' => $this->inv($r,'band',$map),
'mode' => $this->inv($r,'mode',$map),
'source' => $this->inv($r,'source',$map),
'comment' => $this->inv($r,'comment',$map),
);
}
$this->dbg=$q;
return $spots_arr;
}
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment