From e0b182c8d754ff60adcc166ad7650e475ead7cee Mon Sep 17 00:00:00 2001 From: pezcurrel Date: Thu, 9 Jan 2020 20:43:28 +0100 Subject: [PATCH] iframe -> XMLHttpRequest, mostra i criteri di ricerca in uso --- web/admin/instances.php | 142 ++++++++++++++++++++++++++++++--------- web/admin/instancesh.php | 27 ++------ web/admin/theme.css | 8 +-- 3 files changed, 118 insertions(+), 59 deletions(-) diff --git a/web/admin/instances.php b/web/admin/instances.php index 745ad94..205a8d4 100644 --- a/web/admin/instances.php +++ b/web/admin/instances.php @@ -137,9 +137,9 @@ $cols=array( 'TagID'=>array('name'=>'[Tags]','type'=>'join','join'=>array('InstTags ON InstTags.InstID=Instances.ID')), 'Tags.Name'=>array('name'=>'Tags','type'=>'join','joini'=>array('InstTags ON InstTags.InstID=Instances.ID','Tags ON Tags.ID=InstTags.TagID'),'subtype'=>'text'), - 'Statuses'=>array('name'=>'Stati ultima settimana','type'=>'joini','join'=>array('InstActivity ON InstActivity.InstID=Instances.ID'),'subtype'=>'int','select'=>'MAX(Week) AS maxweek'), + /*'Statuses'=>array('name'=>'Stati ultima settimana','type'=>'joini','join'=>array('InstActivity ON InstActivity.InstID=Instances.ID'),'subtype'=>'int','select'=>'MAX(Week) AS maxweek'), 'Logins'=>array('name'=>'Logins ultima settimana','type'=>'joini','join'=>array('InstActivity ON InstActivity.InstID=Instances.ID'),'subtype'=>'int','select'=>'MAX(Week) AS maxweek'), - 'Registrations'=>array('name'=>'Registrazioni ultima settimana','type'=>'joini','join'=>array('InstActivity ON InstActivity.InstID=Instances.ID'),'subtype'=>'int','select'=>'MAX(Week) AS maxweek'), + 'Registrations'=>array('name'=>'Registrazioni ultima settimana','type'=>'joini','join'=>array('InstActivity ON InstActivity.InstID=Instances.ID'),'subtype'=>'int','select'=>'MAX(Week) AS maxweek'),*/ ); $types=array('bool','int','time','text','join','joini'); @@ -188,25 +188,39 @@ foreach ($cols as $key=>$val) { [condsel-6] => = [valuesel-6] => 20 [closepar-6] => null +[andor-6] => AND */ +$i=0; +$jsaddrows=''; +$jssetrows=''; +$cp=count($_POST)/6; // /6 perché ogni "blocco" contiene 6 righe $sels=array(); $joins=array(); $where=''; foreach ($_POST as $key=>$val) { - if (preg_match('/^openpar-\d+/',$key)===1 && preg_match('/^\(+$/',$val)===1) - $where.=$val; + if (preg_match('/^openpar-\d+/',$key)===1) { + $i++; + if (preg_match('/^\(+$/',$val)===1) + $where.=$val; + $jsaddrows.='addrow('.$i.',false);'.N; + $jssetrows.='setrow('.$i.','.json_encode($val); + } if (preg_match('/^fieldsel-\d+/',$key)===1 && preg_match('/^(.+)§(.+)§(.+)$/',$val,$buf)===1) { - if (array_key_exists($buf[1],$cols) && in_array($buf[2],$types)) { - $where.=$buf[1]; - if ($buf[2]=='join' || $buf[2]=='joini') { - foreach ($cols[$buf[1]]['join'] as $join) { + $col=$buf[1]; + $type=$buf[2]; + $subtype=$buf[3]; + if (array_key_exists($col,$cols) && in_array($type,$types)) { + $where.=$col; + if ($type=='join' || $type=='joini') { + foreach ($cols[$col]['join'] as $join) { if (!in_array($join,$joins)) $joins[]=$join; } - if ($buf[2]=='joini' && array_key_exists('select',$cols[$buf[1]]) && !in_array($cols[$buf[1]]['select'],$sels)) - $sels[]=$cols[$buf[1]]['select']; + if ($type=='joini' && array_key_exists('select',$cols[$col]) && !in_array($cols[$col]['select'],$sels)) + $sels[]=$cols[$col]['select']; } + $jssetrows.=','.json_encode($val); } else { muoribene($dbg.'
Dati POST corrotti.
Puoi riprovare o tornare al login.',true); } @@ -214,19 +228,35 @@ foreach ($_POST as $key=>$val) { if (preg_match('/^condsel-\d+/',$key)===1) { $where.=' '.$val.' '; $cond=$val; + $jssetrows.=','.json_encode($val); } - if (preg_match('/^valuesel-\d+/',$key)===1) + if (preg_match('/^valuesel-\d+/',$key)===1) { $where.=$val; + $jssetrows.=','.json_encode($val); + $jssetrows.=',""'; + } if (preg_match('/^valueinp-\d+/',$key)===1) { if (preg_match('/^(LIKE|NOT LIKE)$/',$cond)===1) $where.='\'%'.myesc($link,$val).'%\''; else $where.='\''.myesc($link,$val).'\''; + $jssetrows.=',""'; + $jssetrows.=','.json_encode($val); } - if (preg_match('/^closepar-\d+/',$key)===1 && preg_match('/^\)+$/',$val)===1) - $where.=$val; - if (preg_match('/^andor-\d+/',$key)===1 && preg_match('/^(AND|OR)$/',$val)===1) - $where.=' '.$val.' '; + if (preg_match('/^closepar-\d+/',$key)===1) { + if (preg_match('/^\)+$/',$val)===1) + $where.=$val; + $jssetrows.=','.json_encode($val); + } + if (preg_match('/^andor-\d+/',$key)===1 && preg_match('/^(AND|OR)$/',$val)===1) { + if ($i<$cp) + $where.=' '.$val.' '; + $jssetrows.=','.json_encode($val).');'.N; + } +} +if ($jsaddrows!='') { + $jsaddrows.='document.getElementById("filbut").value="Rimuovi tutti i criteri di ricerca";'.N; + $jsaddrows.='synctai();'.N; } if (count($sels)>0) @@ -242,10 +272,10 @@ else $query='SELECT *, Instances.ID AS IID'.$sels.' FROM Instances '.$joins.' '.$where.' GROUP BY IID ORDER BY Instances.URI ASC LIMIT 50'; $dbg.='QUERONA: '.$query.'
'.N; +$tini=microtime(true); $res=mysqli_query($link,$query) or muoribene($dbg.'
'.$query.': '.mysqli_error($link),true); - - +$dbg.='Durata esecuzione query: '.round(microtime(true)-$tini,4).' sec.
'.N; if (mysqli_num_rows($res)<1) { $out='

Nessuna istanza da mostrare.

'.N; @@ -291,7 +321,7 @@ if (mysqli_num_rows($res)<1) { if (mysqli_num_rows($sres)>0) { $attr.='
Stati: '.$tot['tstatuses'].'
Accessi: '.$tot['tlogins'].'
Registrazioni: '.$tot['tregs'].'
'.N; while ($srow=mysqli_fetch_assoc($sres)) { - $attr.='
'.strftime('%e %b %Y',$srow['Week']).'
'.N; + $attr.='
'.strftime('%e %b %Y',$srow['Week']).' ('.$srow['Week'].')
'.N; ($tot['tstatuses']==0) ? $width=0 : $width=str_replace(',','.',100/$tot['tstatuses']*$srow['Statuses']); $attr.='
'.$srow['Statuses'].' stati
'.N; ($tot['tlogins']==0) ? $width=0 : $width=str_replace(',','.',100/$tot['tlogins']*$srow['Logins']); @@ -491,7 +521,7 @@ function inpdisif(index) { if (sel.style.display!='none') sel.disabled=false; } } -function popusels(index) { +function popusels(index,valselval) { console.log('Index: '+index); var key=document.getElementById('fieldsel-'+index).value; var type=key.replace(/^.*§(.*)§.*$/,'$1'); @@ -559,12 +589,26 @@ function popusels(index) { valinp.disabled=true; condsel.setAttribute('onchange','inpdisif('+index+');'); truncsel('valuesel-'+index); - document.getElementById('helper').setAttribute('src','instancesh.php?key='+key+'&parsel=valuesel-'+index); + let xhr=new XMLHttpRequest(); + xhr.open('GET','instancesh.php?key='+key); + xhr.responseType='json'; + xhr.send(); + xhr.onload=function() { + let jarr=xhr.response; + for (i=0; i-1; i--) { nodes[i].setAttribute('id','fieldsel-'+(i+1)); nodes[i].setAttribute('name','fieldsel-'+(i+1)); - nodes[i].setAttribute('onchange','popusels('+(i+1)+');'); + nodes[i].setAttribute('onchange','popusels('+(i+1)+',false);'); } nodes=table.querySelectorAll('.condsel'); for (i=cnodes; i>-1; i--) { @@ -640,6 +686,28 @@ function synctai() { if (cnodes>=0) nodes[cnodes].disabled=true; } +function selind(id,val) { + var el=document.getElementById(id), i=0, found=false; + while (!found && i - +