diff --git a/web/clitools/mustool.php b/web/clitools/mustool.php index 387369d..784627a 100755 --- a/web/clitools/mustool.php +++ b/web/clitools/mustool.php @@ -147,7 +147,7 @@ if ($opts['updstats']) { 'ffffffffffffffffffffffffffffffff' ); $langs=array('ca','en','es','fr','it'); - $urls=array('home','instances','about','stats','contribute','404'); + $urls=array('home','instances','about','statistics','contribute','404'); for ($i=0; $i<1460; $i++) mysqli_query($link,'INSERT INTO ZHits (UID,URL,Lang,TS) VALUES ("'.$uids[rand(0,count($uids)-1)].'","'.$urls[rand(0,count($urls)-1)].'","'.$langs[rand(0,count($langs)-1)].'",'.rand($now-365*24*60*60,$tdstart).')'); } $res=mysqli_query($link,'SELECT * FROM ZHits WHERE TS < '.$tdstart.' ORDER BY TS ASC') or mexit(__LINE__.': '.mysqli_error($link).N,2); @@ -165,23 +165,32 @@ if ($opts['updstats']) { //echo('-------- '.gmdate('d M Y H:i:s',$dstart).' ---------'.N); $inserts++; // questo qui sotto dev'essere sincronizzato con le lingue supportate e le url che serviamo (vedi index.php) - $hits=array('tot'=>0, 'ca'=>0, 'en'=>0, 'es'=>0, 'fr'=>0, 'it'=>0, 'home'=>0, 'instances'=>0, 'about'=>0, 'stats'=>0, 'contribute'=>0, '404'=>0); + $hits=0; + $hitslang=array('ca'=>0, 'en'=>0, 'es'=>0, 'fr'=>0, 'it'=>0); + $hitspage=array('home'=>0, 'instances'=>0, 'about'=>0, 'statistics'=>0, 'contribute'=>0, '404'=>0); $visits=0; $buf=array(); $res=mysqli_query($link,'SELECT * FROM ZHits WHERE TS >= '.$dstart.' AND TS < '.($dstart+$day).' ORDER BY TS ASC') or mexit(__LINE__.': '.mysqli_error($link).N,2); while ($row=mysqli_fetch_assoc($res)) { //echo($row['UID'].' '.$row['URL'].' '.$row['Lang'].' '.$row['TS'].N); - $hits['tot']++; - $hits[$row['Lang']]++; - $hits[$row['URL']]++; + $hits++; + $hitslang[$row['Lang']]++; + $hitspage[$row['URL']]++; if (!in_array($row['UID'],$buf)) { $buf[]=$row['UID']; $visits++; } } - //echo('>>> hits: '.$hits['tot'].', visits: '.$visits.' <<<'.N); - $hits=implode(', ',$hits); - mysqli_query($link,'INSERT INTO ZStats (TS, Hits, HitsCa, HitsEn, HitsEs, HitsFr, HitsIt, HitsHome, HitsInst, HitsAbout, HitsStats, HitsContrib, Hits404, Visits) VALUES ('.$dstart.', '.$hits.', '.$visits.')') or mexit(__LINE__.': '.mysqli_error($link).N,2); + $buf=''; + foreach ($hitslang as $key=>$val) $buf.=$key.':'.$val.';'; + $hitslang=substr($buf,0,-1); + $buf=''; + foreach ($hitspage as $key=>$val) $buf.=$key.':'.$val.';'; + $hitspage=substr($buf,0,-1); + //echo('>>> hits: '.$hits.', hitslang: '.$hitslang.', hitspage: '.$hitspage.', visits: '.$visits.' <<<'.N); + $query='INSERT INTO ZStats (TS, Hits, HitsLang, HitsPage, Visits) VALUES ('.$dstart.', '.$hits.', "'.$hitslang.'", "'.$hitspage.'", '.$visits.')'; + //echo($query.N); + mysqli_query($link,$query) or mexit(__LINE__.': '.mysqli_error($link).N,2); $dstart+=$day; } mysqli_query($link,'DELETE FROM ZHits WHERE TS < '.$tdstart) or mexit(__LINE__.': '.mysqli_error($link).N,2); diff --git a/web/clitools/unatantum/UPDATE.php b/web/clitools/unatantum/UPDATE.php index aec349c..7d1225e 100644 --- a/web/clitools/unatantum/UPDATE.php +++ b/web/clitools/unatantum/UPDATE.php @@ -16,8 +16,24 @@ $link=mysqli_connect($iniarr['db_host'],$iniarr['db_admin_name'],$iniarr['db_adm or mexit('Impossibile connettersi al database: '.mysqli_connect_error().' ['.mysqli_connect_errno().']'.N,1); mysqli_set_charset($link,'utf8mb4'); -/*mysqli_query($link,"ALTER TABLE `ZStats` CHANGE `HitsTrans` `HitsContrib` INT(10) UNSIGNED NOT NULL;") - or mexit(mysqli_error($link).N,2);*/ +mysqli_query($link,"ALTER TABLE `ZStats` ADD `HitsLang` VARCHAR(5000) NOT NULL AFTER `Hits`;") + or mexit(mysqli_error($link).N,2); +mysqli_query($link,"ALTER TABLE `ZStats` ADD `HitsPage` VARCHAR(5000) NOT NULL AFTER `HitsLang`;") + or mexit(mysqli_error($link).N,2); + +$res=mysqli_query($link,"SELECT * FROM `ZStats`") + or mexit(mysqli_error($link).N,2); + +$hlang; +$hpage; +while ($row=mysqli_fetch_assoc($res)) { + $hlang='ca:'.$row['HitsCa'].';en:'.$row['HitsEn'].';es:'.$row['HitsEs'].';fr:'.$row['HitsFr'].';it:'.$row['HitsIt']; + $hpage='home:'.$row['HitsHome'].';inst:'.$row['HitsInst'].';about:'.$row['HitsAbout'].';stats:'.$row['HitsStats'].';contrib:'.$row['HitsContrib'].';404:'.$row['Hits404']; + mysqli_query($link,"UPDATE `ZStats` SET HitsLang='".$hlang."', HitsPage='".$hpage."' WHERE TS=".$row['TS']); +} + +mysqli_query($link,"ALTER TABLE `ZStats` DROP `HitsCa`, DROP `HitsEn`, DROP `HitsEs`, DROP `HitsFr`, DROP `HitsIt`, DROP `HitsHome`, DROP `HitsInst`, DROP `HitsAbout`, DROP `HitsStats`, DROP `HitsContrib`, DROP `Hits404`;") + or mexit(mysqli_error($link).N,2); mysqli_close($link); diff --git a/web/site/stats.php b/web/site/stats.php index 9c8f467..32ad97c 100644 --- a/web/site/stats.php +++ b/web/site/stats.php @@ -30,20 +30,47 @@ $now=time(); $tdstart=gmmktime(0,0,0,gmdate('n',$now),gmdate('j',$now),gmdate('Y',$now)); $limit=$tdstart-(30*24*60*60); $res=mysqli_query($link,'SELECT * FROM ZStats WHERE TS >= '.$limit.' ORDER BY TS DESC') or muorimeglio(__LINE__.': '.mysqli_error($link),true); +$hlmap=array( + 'ca'=>_('Catalan'), + 'en'=>_('English'), + 'es'=>_('Spanish'), + 'fr'=>_('French'), + 'it'=>_('Italian') +); +$hpmap=array( + 'home'=>_('Guide'), + 'instances'=>_('Instances'), + 'about'=>_('About'), + 'statistics'=>_('Statistics'), + 'contribute'=>_('Contribute'), + '404'=>'404' +); while ($row=mysqli_fetch_assoc($res)) { - $buf=array(_('Catalan')=>$row['HitsCa'], _('English')=>$row['HitsEn'], _('Spanish')=>$row['HitsEs'], _('French')=>$row['HitsFr'], _('Italian')=>$row['HitsIt']); + $hl=explode(';',$row['HitsLang']); + $buf=array(); + foreach($hl as $key=>$val) { + $val=explode(':',$val); + $buf[$hlmap[$val[0]]]=$val[1]; + } arsort($buf); - $langs=''; - foreach ($buf as $key=>$val) $langs.=$key.': '.$val.', '; - $langs=_('Hits per language').': '.substr($langs,0,-2); - $buf=array(_('Guide')=>$row['HitsHome'], _('Instances')=>$row['HitsInst'], _('About')=>$row['HitsAbout'], _('Stats')=>$row['HitsStats'], _('Contribute')=>$row['HitsContrib'], '404'=>$row['Hits404']); + $hl=''; + foreach($buf as $key=>$val) $hl.=$key.': '.$val.'; '; + $hl=_('Hits per language').': '.substr($hl,0,-2); + + $hp=explode(';',$row['HitsPage']); + $buf=array(); + foreach($hp as $key=>$val) { + $val=explode(':',$val); + $buf[$hpmap[$val[0]]]=$val[1]; + } arsort($buf); - $pages=''; - foreach ($buf as $key=>$val) $pages.=$key.': '.$val.', '; - $pages=_('Hits per page').': '.substr($pages,0,-2); + $hp=''; + foreach($buf as $key=>$val) $hp.=$key.': '.$val.'; '; + $hp=_('Hits per page').': '.substr($hp,0,-2); + echo('
'.gmdate('d/m/Y',$row['TS']).': '.$row['Visits'].' '.sp($row['Visits'],_('visit'),_('visits')).', '.$row['Hits'].' '.sp($row['Hits'],_('hit'),_('hits')).'
'.N); - echo('
'.$langs.'
'.N); - echo('
'.$pages.'
'.N); + echo('
'.$hl.'
'.N); + echo('
'.$hp.'
'.N); echo('
'.N); echo('
'.N); echo('
'.N);