| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | // Pojmenovánà statistických kategoriÃ
|
|---|
| 4 | $StatCategory = array(
|
|---|
| 5 | 'browser' => 'ProhlÞeÄe',
|
|---|
| 6 | 'referer' => 'Odkud pÅiÅ¡li',
|
|---|
| 7 | 'module' => 'Sekce webu',
|
|---|
| 8 | 'host' => 'Adresy návÅ¡tÄvnÃků',
|
|---|
| 9 | 'word' => 'Hledaná slova',
|
|---|
| 10 | 'user' => 'Uživatelé',
|
|---|
| 11 | 'action' => 'Akce',
|
|---|
| 12 | );
|
|---|
| 13 |
|
|---|
| 14 | $StatMonths = array('Leden','Ãnor','BÅezen','Duben','KvÄten','Äerven','Äervenec','Srpen','ZáÅÃ','ÅÃjen','Listopad','Prosinec');
|
|---|
| 15 |
|
|---|
| 16 | /*
|
|---|
| 17 | if (!session_is_registered('Stat_Category')) {
|
|---|
| 18 | session_register('Stat_Category');
|
|---|
| 19 | $Stat_Category = 'module';
|
|---|
| 20 | }
|
|---|
| 21 | if (!session_is_registered('Stat_Name')) {
|
|---|
| 22 | session_register('Stat_Name');
|
|---|
| 23 | $Stat_Name = 'index';
|
|---|
| 24 | }
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 | function System_Date()
|
|---|
| 28 | {
|
|---|
| 29 | return(gmdate('Y-m-d'));
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | function StatUpdate($Cat, $Name)
|
|---|
| 33 | {
|
|---|
| 34 | global $DB_Prefix, $Database;
|
|---|
| 35 |
|
|---|
| 36 | $Date = System_Date();
|
|---|
| 37 | $DbResult = $Database->select('stat', '*', "category='$Cat' AND name='$Name' AND date='$Date'");
|
|---|
| 38 | if($DbResult->num_rows > 0) $Database->query("UPDATE ".$DB_Prefix."stat SET hits=hits+1 WHERE category='$Cat' AND name='$Name' AND date='$Date'");
|
|---|
| 39 | else
|
|---|
| 40 | {
|
|---|
| 41 | $Data = array(
|
|---|
| 42 | 'category' => $Cat,
|
|---|
| 43 | 'name' => $Name,
|
|---|
| 44 | 'date' => $Date,
|
|---|
| 45 | 'hits' => 1,
|
|---|
| 46 | );
|
|---|
| 47 | $Database->insert('stat', $Data);
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | function StatProcess()
|
|---|
| 52 | {
|
|---|
| 53 | global $Options;
|
|---|
| 54 | // Zjistà zobrazený modul
|
|---|
| 55 | StatUpdate('module', substr($_SERVER['SCRIPT_NAME'], $Options['StatPathCut']));
|
|---|
| 56 |
|
|---|
| 57 | // Zjistà stránku odkud uzivatel pÅisel
|
|---|
| 58 | if(array_key_exists('HTTP_REFERER', $_SERVER))
|
|---|
| 59 | {
|
|---|
| 60 | $Url = explode('/',$_SERVER['HTTP_REFERER']);
|
|---|
| 61 | if(strpos($Url[2],':'))
|
|---|
| 62 | {
|
|---|
| 63 | $Hostname = explode(':',$Url[2]);
|
|---|
| 64 | $ServerIP = gethostbyname($HostName[0]);
|
|---|
| 65 | } else $ServerIP = gethostbyname($Url[2]);
|
|---|
| 66 | //echo($ServerIP.'-'.$_SERVER["SERVER_ADDR"]);
|
|---|
| 67 | if(($ServerIP != $_SERVER["SERVER_ADDR"]) && ($ServerIP!='127.0.0.1'))
|
|---|
| 68 | StatUpdate('referer', $_SERVER['HTTP_REFERER']);
|
|---|
| 69 | } else StatUpdate('referer', 'direct');
|
|---|
| 70 |
|
|---|
| 71 | // Zjistà typ prohlÃľeÄe
|
|---|
| 72 | StatUpdate('browser', $_SERVER['HTTP_USER_AGENT']);
|
|---|
| 73 | // Zjistà DNS a IP adresu klienta
|
|---|
| 74 | StatUpdate('host', $_SERVER['REMOTE_ADDR']);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | function StatShow()
|
|---|
| 78 | {
|
|---|
| 79 | if(!array_key_exists('period', $_GET)) $Period = '';
|
|---|
| 80 | else $Period = $_GET['period'];
|
|---|
| 81 | switch($Period)
|
|---|
| 82 | {
|
|---|
| 83 | case 'years':
|
|---|
| 84 | $Out = StatShowYears();
|
|---|
| 85 | break;
|
|---|
| 86 | case 'months':
|
|---|
| 87 | $Out = StatShowMonths();
|
|---|
| 88 | break;
|
|---|
| 89 | case 'days':
|
|---|
| 90 | $Out = StatShowDays();
|
|---|
| 91 | break;
|
|---|
| 92 | default:
|
|---|
| 93 | $Out = StatShowMain();
|
|---|
| 94 | }
|
|---|
| 95 | return($Out);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | function StatShowYears()
|
|---|
| 99 | {
|
|---|
| 100 | global $Options, $Database;
|
|---|
| 101 |
|
|---|
| 102 | if(array_key_exists('name', $_GET) and array_key_exists('category', $_GET))
|
|---|
| 103 | {
|
|---|
| 104 | $Output = '<div class="StatList"><strong>RoÄnà statistika</strong><br><br>'.
|
|---|
| 105 | '<table class="StatTable"><tr><th>Rok</th><th>Prohlédnutých stránek</th></tr>';
|
|---|
| 106 |
|
|---|
| 107 | // Zjisti rozmezà roků
|
|---|
| 108 | $DbResult = $Database->select('stat', 'DISTINCT date', 'name="'.$_GET['name'].'" AND category="'.$_GET['category'].'"');
|
|---|
| 109 | while($Row = $DbResult->fetch_assoc())
|
|---|
| 110 | {
|
|---|
| 111 | $Year = substr($Row['date'],0,4);
|
|---|
| 112 | if(!isset($Min)) $Min = $Year;
|
|---|
| 113 | if(!isset($Max)) $Max = $Year;
|
|---|
| 114 | if(($Year < $Min) or ($Min=='')) $Min = $Year;
|
|---|
| 115 | if($Year > $Max) $Max = $Year;
|
|---|
| 116 | }
|
|---|
| 117 | // NaÄti body roků a body celkem
|
|---|
| 118 | for($I=$Min;$I<=$Max;$I++)
|
|---|
| 119 | {
|
|---|
| 120 | $DateFrom = $I;
|
|---|
| 121 | $DateTo = $DateFrom.'-12-31';
|
|---|
| 122 | $DateFrom .= '-01-01';
|
|---|
| 123 |
|
|---|
| 124 | $DbResult = $Database->select('stat', 'SUM(hits)', 'name="'.$_GET['name'].'" AND category="'.$_GET['category'].'"');
|
|---|
| 125 | $Row = $DbResult->fetch_row();
|
|---|
| 126 | $Total = $Row[0];
|
|---|
| 127 |
|
|---|
| 128 | $DbResult = $Database->select('stat', 'hits', 'name="'.$_GET['name'].'" AND date>="'.$DateFrom.'" AND date<="'.$DateTo.'" AND category="'.$_GET['category'].'"');
|
|---|
| 129 | $Row = $DbResult->fetch_row();
|
|---|
| 130 | $Percent = round($Row[0]/$Total*100,2);
|
|---|
| 131 | if($Percent==0) $Percent = '0';
|
|---|
| 132 | $Output .= '<tr><td><a href="?module=stat&category='.$_GET['category'].'&name='.$_GET['name'].'&period=months&year='.$I.'">'.$I.'</a></td>'.
|
|---|
| 133 | '<td><img src="images/leftbar.gif" width="7" height="15"><img src="images/mainbar.gif" width="'.round($Percent*2).'" height="15"><img src="images/rightbar.gif" width="7" height="15"> '.$Percent.'% ('.$Row[0].')</td></tr>';
|
|---|
| 134 | }
|
|---|
| 135 | $Output .= '</table><a href="?module=stat&category='.$_GET['category'].'">Zpátky pÅehled statistiky</a></div>';
|
|---|
| 136 | }
|
|---|
| 137 | return($Output);
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | // Zobrazà statistiku mÄsÃcu //
|
|---|
| 141 | function StatShowMonths()
|
|---|
| 142 | {
|
|---|
| 143 | global $StatMonths, $Database;
|
|---|
| 144 | if(array_key_exists('name', $_GET) and array_key_exists('category', $_GET) and array_key_exists('year', $_GET))
|
|---|
| 145 | {
|
|---|
| 146 |
|
|---|
| 147 | $Output = '<div class="StatList"><strong>MÄsÃÄnà statistika pro rok '.$_GET['year'].'</strong><br><br>'.
|
|---|
| 148 | '<table class="StatTable" cellspacing="0"><tr><th>MÄsÃc</th><th>Prohlédnutých stránek</th></tr>';
|
|---|
| 149 |
|
|---|
| 150 | // SpoÄÃtej poÄty pro mÄsÃce
|
|---|
| 151 | for($I=1;$I<13;$I++)
|
|---|
| 152 | {
|
|---|
| 153 | $DateFrom = $_GET['year'].'-'.$I.'-';
|
|---|
| 154 | $DateTo = $DateFrom.'31';
|
|---|
| 155 | $DateFrom .= '01';
|
|---|
| 156 |
|
|---|
| 157 | $DbResult = $Database('stat', 'SUM(hits)', 'name="'.$_GET['name'].'" AND category="'.$_GET['category'].'"');
|
|---|
| 158 | $Row = $DbResult->fetch_row();
|
|---|
| 159 | $Total = $Row[0];
|
|---|
| 160 |
|
|---|
| 161 | $DbResult = $Datbase->select('stat', 'hits', 'name="'.$_GET['name'].'" AND date>="'.$DateFrom.'" AND date<="'.$DateTo.'" AND category="'.$_GET['category'].'"');
|
|---|
| 162 | $Row = $DbResult->fetch_row();
|
|---|
| 163 | $Percent = round($Row[0]/$Total*100,2);
|
|---|
| 164 | if($Percent==0) $Percent = '0';
|
|---|
| 165 | $Output .= '<tr><td><a href="?module=stat&category='.$_GET['category'].'&name='.$_GET['name'].'&period=days&year='.$_GET['year'].'&month='.$I.'">'.$StatMonths[$I-1].'</a></td>'.
|
|---|
| 166 | '<td><img src="images/leftbar.gif" width="7" height="15"><img src="images/mainbar.gif" width="'.round($Percent*2).'" height="15"><img src="images/rightbar.gif" width="7" height="15">  '.$Percent.'% ('.$Row[0].')</td></tr>';
|
|---|
| 167 | }
|
|---|
| 168 | $Output .= '</table><a href="?module=stat&period=years&category='.$_GET['category'].'&name='.$_GET['name'].'">Zpátky na statistiku roků</a></div>';
|
|---|
| 169 | return($Output);
|
|---|
| 170 | }
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | function StatShowDays()
|
|---|
| 174 | {
|
|---|
| 175 | global $StatMonths, $Database;
|
|---|
| 176 |
|
|---|
| 177 | if(array_key_exists('name', $_GET) and array_key_exists('category', $_GET) and array_key_exists('year', $_GET) and array_key_exists('month', $_GET))
|
|---|
| 178 | {
|
|---|
| 179 | $Output = '<div class="StatList"><strong>Dennà statistika pro mÄsic '.$StatMonths[$_GET['month']].'</strong><br><br>'.
|
|---|
| 180 | '<table class="StatTable" cellspacing="0"><tr><th>Den</th><th>Prohlédnutých stránek</th></tr>';
|
|---|
| 181 | for($I=1;$I<32;$I++)
|
|---|
| 182 | {
|
|---|
| 183 | $DbResult = $Database->select('stat', 'SUM(hits)', 'name="'.$_GET['name'].'" AND category="'.$_GET['category'].'"');
|
|---|
| 184 | $Row = $DbResult->fetch_row();
|
|---|
| 185 | $Total = $Row[0];
|
|---|
| 186 |
|
|---|
| 187 | $Date = $_GET['year'].'-'.$_GET['month'].'-'.$I;
|
|---|
| 188 | $DbResult = $Database->select('stat', 'hits', 'name="'.$_GET['name'].'" AND date="'.$Date.'" AND category="'.$_GET['category'].'"');
|
|---|
| 189 | $Row = $DbResult->fetch_row();
|
|---|
| 190 |
|
|---|
| 191 | $Percent = round($Row[0]/$Total*100,2);
|
|---|
| 192 | if($Percent==0) $Percent = '0';
|
|---|
| 193 | $Output .= '<tr><td>'.$I.'</td>'.
|
|---|
| 194 | '<td><img src="images/leftbar.gif" width="7" height="15"><img src="images/mainbar.gif" width="'.round($Percent*2).'" height="15"><img src="images/rightbar.gif" width="7" height="15">  '.$Percent.'% ('.$Row[0].')</td></tr>';
|
|---|
| 195 | }
|
|---|
| 196 | $Output .= '</table><a href="?module=stat&period=months&name='.$_GET['name'].'&category='.$_GET['category'].'&year='.$_GET['year'].'">Zpátky na statistiku mÄsÃců</a></div>';
|
|---|
| 197 | }
|
|---|
| 198 | return($Output);
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | function StatShowMain()
|
|---|
| 202 | {
|
|---|
| 203 | global $StatCategory, $Database;
|
|---|
| 204 |
|
|---|
| 205 | $DbResult = $Database->select('stat', 'DISTINCT category');
|
|---|
| 206 | $Output = '<div class="StatList"><strong>Seznam kategoriÃ:</strong><br><br><table class="StatTable" cellspacing="0"><tr><th>Název</t></tr>';
|
|---|
| 207 | while($Row = $DbResult->fetch_assoc())
|
|---|
| 208 | {
|
|---|
| 209 | $Output .= '<tr><td><a href="?module=stat&category='.$Row['category'].'">'.$StatCategory[$Row['category']].'</a></td></tr>';
|
|---|
| 210 | }
|
|---|
| 211 | $Output .= '</table>';
|
|---|
| 212 | if(array_key_exists('category', $_GET))
|
|---|
| 213 | {
|
|---|
| 214 | $DbResult = $Database->select('stat', 'SUM(hits)', 'category="'.$_GET['category'].'"');
|
|---|
| 215 | $Row = $DbResult->fetch_row();
|
|---|
| 216 | $All = $Row[0];
|
|---|
| 217 | $Output .= '<br><strong>Výpis kategorie:</strong><br><br><table class="StatTable" cellspacing="0"><tr><th>Název</th><th>Stránek</th></tr>';
|
|---|
| 218 | $DbResult = $Database->select('stat', 'DISTINCT name', "category='".$_GET['category']."' ORDER BY 'name'");
|
|---|
| 219 | while($Row = $DbResult->fetch_assoc())
|
|---|
| 220 | {
|
|---|
| 221 | $DbResult2 = $Datbase->select('stat', 'SUM(hits)', "name='".$Row['name']."' AND category='".$_GET['category']."'");
|
|---|
| 222 | $Row2 = $DbResult2->fetch_array();
|
|---|
| 223 | if($Row['name'] == 'direct') $Nazev = 'Zadáno pÅÃmo'; else $Nazev = $Row['name'];
|
|---|
| 224 | if($_GET['category'] == 'host') $Nazev = gethostbyaddr($Nazev);
|
|---|
| 225 | $Output .= '<tr><td><a href="?module=stat&category='.$_GET['category'].'&period=years&name='.$Row['name'].'">'.$Nazev.'</a></td>'.
|
|---|
| 226 | '<td><img src="images/leftbar.gif" width="7" height="15"><img src="images/mainbar.gif" width="'.(round($Row2[0]/$All*100,2)).'" height="15"><img src="images/rightbar.gif" width="7" height="15">'.$Row2[0].'</td></tr>';
|
|---|
| 227 | }
|
|---|
| 228 | $Output .= '</table></div>';
|
|---|
| 229 | }
|
|---|
| 230 | return($Output);
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | ?>
|
|---|