"Fossies" - the Fresh Open Source Software Archive

Member "betterawstats/core/display.inc.php" (17 Mar 2008, 68446 Bytes) of package /linux/www/old/betterawstats-1.0.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 /**
    3  * betterawstats - an alternative display for awstats data
    4  *
    5  * @author      Oliver Spiesshofer, support at betterawstats dot com
    6  * @copyright   2008 Oliver Spiesshofer
    7  * @version     1.0
    8  * @link        http://betterawstats.com
    9 
   10  * Based on the GPL AWStats Totals script by:
   11  * Jeroen de Jong <jeroen@telartis.nl>
   12  * copyright   2004-2006 Telartis
   13  * version 1.13 (http://www.telartis.nl/xcms/awstats)
   14  *
   15  * This program is free software; you can redistribute it and/or
   16  * modify it under the terms of the GNU General Public License
   17  * as published by the Free Software Foundation; either version 2
   18  * of the License, or (at your option) any later version.
   19  *
   20  * This program is distributed in the hope that it will be useful,
   21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   23  * GNU General Public License for more details.
   24  *
   25  * You should have received a copy of the GNU General Public License
   26  * along with this program; if not, write to the Free Software
   27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   28  */
   29 
   30 /**
   31  * File contents:
   32  *
   33  * This file contains one function for each displayed section. The functions
   34  * call the data from the datafile, process & sort it and output the charts/tables
   35  * according to the settings in config.php
   36  */
   37 
   38 
   39 // this file can't be used on its own
   40 if (strpos ($_SERVER['PHP_SELF'], 'display.inc.php') !== false) {
   41     die ('This file can not be used on its own!');
   42 }
   43 
   44 function baw_display_overview($set) {
   45     global $BAW_MES, $BAW_CURR, $BAW_CONF;
   46     $m = $BAW_MES;
   47     $m_name = $m[59+$BAW_CURR['month']];
   48 
   49     if ($g = baw_data($BAW_CURR['site_name'], 'GENERAL', $BAW_CURR['yearmonth'])) {
   50         // we assumethat time exists when general exist
   51         $t = baw_data($BAW_CURR['site_name'], 'TIME', $BAW_CURR['yearmonth']);
   52 
   53         $o = baw_calc_monthdata($t,$g);
   54         $l = $g['LastUpdate'];
   55         $time = baw_time_format($l[0]);
   56         $BAW_CURR['thismonth']['hits'] = $o[1];
   57         $out = "<table class=\"datatable\">\n"
   58             . "    <tr>\n        <td><b>{$m[133]}</b></td><td colspan=\"5\">$m_name {$BAW_CURR['year']}</td>\n    </tr>\n"
   59             . "    <tr class=\"layout_index\">\n        <td><b>{$m[8]}</b></td><td colspan=\"5\">".baw_time_format($g['FirstTime'][0])."</td>\n    </tr>\n"
   60             . "    <tr class=\"layout_index\">\n        <td><b>{$m[9]}</b></td><td colspan=\"5\">".baw_time_format($g['LastTime'][0])."</td>\n    </tr>\n"
   61             . "    <tr>\n        <td>&nbsp;</td>\n"
   62             ."        <th class=\"layout_visitors\">{$m[11]}</th>\n"
   63             ."        <th class=\"layout_visits\">{$m[10]}</th>\n"
   64             ."        <th class=\"layout_pages\">{$m[56]}</th>\n"
   65             ."        <th class=\"layout_hits\">{$m[57]}</th>\n"
   66             ."        <th class=\"layout_bytes\">{$m[75]}</th>\n    </tr>\n"
   67 
   68             . "    <tr style=\"white-space:nowrap;\">\n        <td>{$m[160]}&nbsp;*</td>\n"
   69             ."        <td><b>".baw_num_format($o[0])."</b>".BR."&nbsp;</td>\n"
   70             ."        <td><b>".baw_num_format($o[1])."</b>".BR."(".@baw_num_format($o[1] / $o[0],2)."&nbsp;{$m[52]})</td>\n"
   71             ."        <td><b>".baw_num_format($o[2])."</b>".BR."(".@baw_num_format($o[2] / $o[1],2)."&nbsp;{$m[27]}/{$m[12]})</td>\n"
   72             ."        <td><b>".baw_num_format($o[3])."</b>".BR."(".@baw_num_format($o[3] / $o[1],2)."&nbsp;{$m[57]}/{$m[12]})</td>\n"
   73             ."        <td><b>".baw_byte_format($o[4])."</b>".BR."(".@baw_byte_format($o[4] / $o[1],2)."/{$m[12]})</td>\n    </tr>\n"
   74             . "    <tr>\n        <td>{$m[161]}&nbsp;*</td>\n"
   75             ."        <td colspan=\"2\">&nbsp;</td>\n"
   76             ."        <td><b>".baw_num_format($o[5])."</b></td>\n"
   77             ."        <td><b>".baw_num_format($o[6])."</b></td>\n"
   78             ."        <td><b>".baw_byte_format($o[7])."</b></td></tr>\n"
   79             . "    <tr>\n        <td colspan=\"6\">* {$m[159]}</td>\n    </tr>\n";
   80         if ($BAW_CONF['show_parser_stats']) {
   81             $out .= "    <tr>\n        <td colspan=\"6\"><b>{$m['data_file_stats']}</b></td>\n    </tr>\n"
   82             . "    <tr>\n"
   83             ."        <td>{$m[35]}:".BR."$time</td>\n"
   84             ."        <td>{$m['parsed_records']}".BR . baw_num_format($l[1]) . "</td>\n"
   85             ."        <td>{$m['old_records']}".BR . baw_num_format($l[2]) . "</td>\n"
   86             ."        <td>{$m['new_records']}".BR . baw_num_format($l[3]) . "</td>\n"
   87             ."        <td>{$m['corrupted']}".BR . baw_num_format($l[4]) . "</td>\n"
   88             ."        <td>{$m['dropped']}".BR . baw_num_format($l[5]) . "</td>\n    </tr>\n";
   89         }
   90         $out .= "</table>\n\n";
   91     } else {
   92         $out = "$m_name-{$BAW_CURR['year']} has no data";
   93     }
   94     return $out;
   95 }
   96 
   97 function baw_display_months($set) {
   98     global $BAW_MES, $BAW_CONF, $BAW_CURR, $BAW_DFILES;
   99     $format = array(
  100         0 => array ('format' => 'layout_text', 'title'=> $BAW_MES[5], 'colspan'=>'2'), // first cell in first line
  101         1 => array ('format' => 'layout_text'), // first cell in first line
  102         2 => array ('format' => 'layout_visitors', 'title'=> $BAW_MES[11]),
  103         3 => array ('format' => 'layout_visits', 'title'=> $BAW_MES[10]),
  104         4 => array ('format' => 'layout_pages', 'title'=> $BAW_MES[56]),
  105         5 => array ('format' => 'layout_hits', 'title'=> $BAW_MES[57]),
  106         6 => array ('format' => 'layout_bytes', 'title'=> $BAW_MES[75])
  107     );
  108     $allsites = false;
  109     if ($BAW_CURR['site_name'] !== 'all_months') {
  110         $sites = array($BAW_CURR['site_name']);
  111     } else {
  112         $sites = array_keys($BAW_DFILES);
  113         $allsites = true;
  114     }
  115 
  116     $out = '';
  117     // for each month, get the four data sets
  118     $frm_arr = array('layout_visitors', 'layout_visits', 'layout_pages', 'layout_hits', 'layout_bytes');
  119     foreach ($sites as $site) {
  120         $data_format = array();
  121         $x = 0;
  122         $val = array();
  123         $monthback = $set['top_x'] - 1;
  124         $chart = array();
  125         $val_chart = array();
  126         $lastyear = 0;
  127         for ($i=$monthback; $i>=0; $i--){
  128             // get the month & Year x month ago
  129             $tyear = date("Y", mktime(0, 0, 0, $BAW_CURR['month']-$i, 1, $BAW_CURR['year']));
  130             $tmonth = date("m", mktime(0, 0, 0, $BAW_CURR['month']-$i, 1, $BAW_CURR['year']));
  131             // get the data for that month
  132             if (isset($BAW_DFILES[$site][$tyear .$tmonth])) {
  133                 $g = baw_data($site, 'GENERAL', $tyear . $tmonth);
  134                 $t = baw_data($site, 'TIME', $tyear . $tmonth);
  135                 $data = baw_calc_monthdata($t, $g);
  136                 $x++;
  137                 $month_text = $tmonth + 59;
  138                 $class = '';
  139                 $date = date("Ym", mktime(0,0,0,$tmonth,1,$tyear));
  140                 $today = date("Ym");
  141                 if ($date == $today) {
  142                     $class = "currentday";
  143                 }
  144                 for ($j=0; $j<5; $j++) {
  145                     $chart["{$BAW_MES[$month_text]}|$tyear"][] = array('data' => "$data[$j]", 'class' => "$class", 'format' => $frm_arr[$j]);
  146                 }
  147                 $class .= baw_even($tyear, ' evenyear', ' oddyear');
  148 
  149                 $val[$tmonth.$tyear] = array(
  150                     $tyear,
  151                     $BAW_MES[$month_text],
  152                     $data[0],
  153                     $data[1],
  154                     $data[2],
  155                     $data[3],
  156                     $data[4],
  157                 );
  158                 if ($class !== '') {
  159                     $data_format[$tmonth.$tyear] = $class;
  160                 }
  161             }
  162         }
  163         if ($set['chart']) {
  164             if ($allsites) {
  165                 // make a link to the actual statistics from the overview
  166                 $full_url = "{$BAW_CONF['site_url']}/index.php?site=$site&amp;month={$BAW_CURR['month']}&amp;year={$BAW_CURR['year']}";
  167                 $out .= "<h3 id=\"site_$site\"><a href=\"$full_url\">$site</a></h3>";
  168             }
  169             $out .= baw_render_htmlchart($val, $format, $set['avg'], -$set['top_x'], $data_format);
  170         }
  171         if ($set['table']) {
  172             $out .= baw_render_table($set['name'], $val, $format, $set['avg'], $set['total'], false, $data_format);
  173         }
  174     }
  175     return $out;
  176 }
  177 
  178 function baw_display_days($set) {
  179     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_DFILES;
  180     $sum = array(0,0,0,0,0); // summ all overall data
  181     // this 3 lines is only for collecting data for weekdays
  182     $wdsum_arr = array(); // summ all weekday data
  183     $wdcount_arr = array(0,0,0,0,0,0,0); // count the number of sat, sun etc
  184     $wdavg_arr = array(); // values of avg
  185     $daysoflastmonth = 30;
  186 
  187     // assemble date
  188     $daysofmonth = date("t", strtotime("{$BAW_CURR['year']}{$BAW_CURR['month']}01000000"));
  189     //$thisyear = date("Y", strtotime("-1 month"));
  190     //$lastyear = date("Y", strtotime("-1 month -1 year"));
  191     $current_month = date('m');
  192     $current_day = date('d');
  193     $daydiff = 0;
  194     $data_format = array();
  195     // find how may days we have to go back
  196     if ($BAW_CURR['month'] == $current_month) { // if we have the current month, get some data from the last month
  197         $daydiff = abs($current_day - $daysofmonth); // calculate how many days are missing
  198     }
  199 
  200     $format = array(
  201         0 => array ('format'=> 'layout_text', 'title' => $BAW_MES[4], 'colspan'=>3),
  202         1 => array ('format'=> 'layout_text'),
  203         2 => array ('format'=> 'layout_text'),
  204         3 => array ('format'=> 'layout_visits', 'title' => $BAW_MES[10]),
  205         4 => array ('format'=> 'layout_pages', 'title' => $BAW_MES[56]),
  206         5 => array ('format'=> 'layout_hits', 'title' => $BAW_MES[57]),
  207         6 => array ('format'=> 'layout_bytes', 'title' => $BAW_MES[75])
  208     );
  209     // check if we do all sites or just one
  210     $allsites = false;
  211     if ($BAW_CURR['site_name'] !== 'all_days') {
  212         $sites = array($BAW_CURR['site_name']);
  213     } else {
  214         $sites = array_keys($BAW_DFILES);
  215         $allsites = true;
  216     }
  217     $out = '';
  218     // iterate all sites, normally only one
  219     foreach ($sites as $site) {
  220         // we have to add the days of the previous month
  221         // this has to be inside the loop so we get the variables again for next site
  222         if ($daydiff > 0) {
  223             if ($BAW_CURR['month'] !== '01') {
  224                 $prevyear = $BAW_CURR['year'];
  225                 $prevmonth = sprintf('%02d', $BAW_CURR['month']-1); // date('m', strtotime("-1 month"));
  226                 $daysoflastmonth = date("t", strtotime("{$BAW_CURR['year']}{$prevmonth}01000000"));
  227             } else {
  228                 $prevyear = $BAW_CURR['year'] - 1;
  229                 $prevmonth = '12';
  230             }
  231         }
  232         $val = array();
  233         // get the data for this site if available
  234         if ($val = baw_data($site, 'DAY', $BAW_CURR['yearmonth'])) {
  235             // in case we need last months data, get it too
  236             if ($daydiff > 0) {
  237                 if ($prevdate_data = baw_data($site, 'DAY', $prevyear . $prevmonth)) {
  238                     $date_cut = $prevyear . $prevmonth . $prevmonth =  sprintf('%02d', $daysoflastmonth - $daydiff);
  239                     $val_prev = baw_cut_date_array($prevdate_data, $date_cut);
  240                     $val = $val_prev + $val;
  241                 }
  242             }
  243             $newval = array();
  244             $lastmonth = 0;
  245             for ($j=0; $j<$daysofmonth; $j++) {
  246                 $class = '';
  247                 // foreach ($val as $date => $data) {
  248                 $date = date("Ymd", mktime(0,0,0,$BAW_CURR['month'],1+ $j - $daydiff,$BAW_CURR['year']));
  249                 $month = date("m", mktime(0,0,0,$BAW_CURR['month'],1+ $j - $daydiff,$BAW_CURR['year']));
  250                 $today = date("Ymd");
  251                 if ($date == $today) {
  252                     $class = "currentday";
  253                 }
  254                 if (!isset($val[$date])) {
  255                     $val[$date] = array(0,0,0,0,0);
  256                 }
  257                 $data = $val[$date];
  258                 $xdate = $date . "000000";
  259                 $tstamp = strtotime($xdate);
  260                 $wday = date("w", $tstamp);
  261 
  262                 if ($wday == 0 or $wday == 6) {
  263                     $class = "$class weekend";
  264                     $class = trim($class);
  265                 }
  266                 // these lines is only for collecting data for weekdays
  267                 $wdcount_arr[$wday]++;  // count no of one weekday for avg division
  268                 for ($i=0; $i<=3; $i++) { // iterate data types
  269                     if (!isset($wdsum_arr[$wday][$i])) {
  270                         $wdsum_arr[$wday][$i] = 0;
  271                     }
  272                     $wdsum_arr[$wday][$i] += $data[$i];
  273                 }
  274 
  275                 if (!isset($from)) {
  276                     $from = $xdate;
  277                 }
  278                 $BAW_CURR['wdays']['count'] = $wdcount_arr;
  279                 $BAW_CURR['wdays']['avg'] = $wdsum_arr;
  280                 $BAW_CURR['wdays']['from'] = $from;
  281                 $BAW_CURR['wdays']['to'] = $xdate;
  282                 if (($j !== $daysofmonth)) {
  283                     $newval[$xdate] = array(
  284                         date("Y", strtotime($xdate)),
  285                         date("M", strtotime($xdate)),
  286                         date("d", strtotime($xdate)),
  287                         $data[3],
  288                         $data[0],
  289                         $data[1],
  290                         $data[2]
  291                     );
  292                 }
  293 
  294                 $class .= baw_even($month, ' evenmonth', ' oddmonth');
  295                 if ($class !== '') {
  296                     $data_format[$xdate] = $class;
  297                 }
  298             }
  299             if ($set['chart']) {
  300                 if ($allsites) {
  301                     // make a link to the actual statistics from the overview
  302                     $full_url = "{$BAW_CONF['site_url']}/index.php?site=$site&amp;month={$BAW_CURR['month']}&amp;year={$BAW_CURR['year']}";
  303                     $out .= "<h3 id=\"site_$site\"><a href=\"$full_url\">$site</a></h3>";
  304                     // $html .= baw_display_updatestats($site);
  305                 }
  306                 $out .= baw_render_htmlchart($newval, $format, $set['avg'], false, $data_format);
  307             }
  308             if ($set['table']) {
  309                 $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], false, $data_format);
  310             }
  311         }
  312     }
  313     return $out;
  314 }
  315 
  316 // get all the averages of one weekday each
  317 function baw_display_weekdays($set) {
  318     global $BAW_MES, $BAW_CURR, $BAW_CONF;
  319 
  320     if (isset($BAW_CURR['wdays']['count'])) {
  321         $format = array(
  322             0 => array ('title' => $BAW_MES[4], 'format' => 'layout_text'),
  323             1 => array ('percent' => true, 'title' => $BAW_MES[10], 'format' => 'layout_visits'),
  324             2 => array ('title' => $BAW_MES[56], 'format' => 'layout_pages'),
  325             3 => array ('title' => $BAW_MES[57], 'format' => 'layout_hits'),
  326             4 => array ('title' => $BAW_MES[75], 'format' => 'layout_bytes')
  327         );
  328         $newval = array();
  329         $data_format = array();
  330         $wdcount_arr = $BAW_CURR['wdays']['count'];
  331         $wdsum_arr = $BAW_CURR['wdays']['avg'];
  332         for ($w=0; $w<7; $w++) {
  333             // switch for Mo or Su start
  334             $x = $w;
  335             if ($BAW_CONF['firstdayofweek'] == 1) {
  336                 $x = $w + 1;
  337                 if ($x == 7) {
  338                     $x = 0;
  339                 }
  340             }
  341             $class = '';
  342             if ($x == 0 or $x == 6) {
  343                 $class = "weekend";
  344             }
  345             if ($wdcount_arr[$x] == 0) {
  346                 $wdcount_arr[$x] = 1;
  347             }
  348             for ($i=0; $i<=3; $i++) {
  349                 $wavg[$x][$i] = '1';
  350                 if (!isset($wdsum_arr[$x][$i])) {
  351                     $wdsum_arr[$x][$i] = 0;
  352                 }
  353                 $wavg[$x][$i] = $wdsum_arr[$x][$i] / $wdcount_arr[$x];
  354             }
  355             $newval[84+$x] = array(
  356                 $BAW_MES[84+$x],
  357                 $wavg[$x][3],
  358                 $wavg[$x][0],
  359                 $wavg[$x][1],
  360                 $wavg[$x][2]
  361             );
  362             if ($class !== '') {
  363                 $data_format[84+$x] = $class;
  364             }
  365         }
  366         $out = '';
  367         if ($set['chart']) {
  368             $out .= baw_render_htmlchart($newval, $format, $set['avg'], false, $data_format);
  369         }
  370         if ($set['table']) {
  371             $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], false, $data_format);
  372         }
  373     } else if ($BAW_CONF['hideempty']){
  374         return '';
  375     }
  376     return $out;
  377 }
  378 
  379 function baw_display_hours($set) {
  380     // we have to calculate the average of each hour depending on how many days have
  381     // data at all in this month
  382     // half days will create slightly inaccuarate data.
  383     global $BAW_MES, $BAW_CURR, $BAW_CONF;
  384     $chart = array();
  385     $format = array(
  386         0 => array ('title'=> $BAW_MES[20], 'format' => 'layout_text', 'colspan'=> 2),
  387         1 => array ('format' => 'layout_text'),
  388         2 => array ('percent' => true, 'title'=> $BAW_MES[56], 'format' => 'layout_pages'),
  389         3 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits'),
  390         4 => array ('title'=> $BAW_MES[75], 'format' => 'layout_bytes')
  391     );
  392     $newval = array();
  393     if ($val = baw_data($BAW_CURR['site_name'], "TIME", $BAW_CURR['yearmonth'])) {
  394         $days = baw_data($BAW_CURR['site_name'], "DAY", $BAW_CURR['yearmonth']);
  395         $count_days = count($days);
  396         foreach ($val as $hour => $data) {
  397             $ihour = $hour + 1;
  398             if ($ihour >= 13) {
  399                 $ihour = ($hour - 11);
  400             }
  401             $avgdata = array();
  402             $icon = baw_create_image($BAW_CONF['icons_url'] . "/clock/hr$ihour.png" , array("alt"=>$hour, "title"=>$hour));
  403             $avgdata[0] = $data[0] / $count_days;
  404             $avgdata[1] = $data[1] / $count_days;
  405             $avgdata[2] = $data[2] / $count_days;
  406             $lhour  = sprintf('%02d',$hour);
  407             $newval_table[$hour] = array(
  408                 $icon,
  409                 "$lhour:00 - $lhour:59",
  410                 $avgdata[0],
  411                 $avgdata[1],
  412                 $avgdata[2],
  413             );
  414             $newval_chart[$hour] = array(
  415                 $icon,
  416                 $hour,
  417                 $avgdata[0],
  418                 $avgdata[1],
  419                 $avgdata[2],
  420             );
  421         }
  422     } else if ($BAW_CONF['hideempty']){
  423         return '';
  424     }
  425 
  426     $out = '';
  427     if ($set['chart']) {
  428         $newval_chart = baw_array_sorting($newval_chart, $set['sort'], $set['sort_dir']);
  429         $out .= baw_render_htmlchart($newval_chart, $format, $set['avg'], false);
  430     }
  431     if ($set['table']) {
  432         $newval_table = baw_array_sorting($newval_table, $set['sort'], $set['sort_dir']);
  433         $out .= baw_render_table($set['name'], $newval_table, $format, $set['avg'], $set['total']);
  434     }
  435     return $out;
  436 }
  437 
  438 function baw_display_domains($set) {
  439     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
  440     $chart = array();
  441     $format_table = array(
  442         0 => array ('title'=> $BAW_MES[25] , 'format' => 'layout_text','colspan' => 3),
  443         1 => array ('format' => 'layout_text'),
  444         2 => array ('format' => 'layout_text'),
  445         3 => array ('percent' => true, 'title'=> $BAW_MES[56], 'format' => 'layout_pages'),
  446         4 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits'),
  447         5 => array ('title'=> $BAW_MES[75], 'format' => 'layout_bytes')
  448     );
  449     $format_chart = array(
  450         0 => array ('title'=> $BAW_MES[25] , 'format' => 'layout_text','colspan' => 3),
  451         1 => array ('format' => 'layout_text'),
  452         2 => array ('percent' => true, 'title'=> $BAW_MES[56], 'format' => 'layout_pages'),
  453         3 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits'),
  454         4 => array ('title'=> $BAW_MES[75], 'format' => 'layout_bytes')
  455     );
  456     // $format_jp = array($BAW_MES[56], $BAW_MES[57], $BAW_MES[75]);
  457     $newval = array();
  458     // $jpval = array();
  459     if ($val = baw_data($BAW_CURR['site_name'], "DOMAIN", $BAW_CURR['yearmonth'])) {
  460         $val = baw_array_sorting($val, $set['sort'], $set['sort_dir']);
  461         foreach ($val as $domain => $data) {
  462             if (isset($BAW_LIB['domains'][$domain])) {
  463                 $file = $domain;
  464                 $desc = $BAW_LIB['domains'][$domain];
  465             } else {
  466                 $file = 'unknown';
  467                 $desc = $file;
  468             }
  469             $icon = baw_create_image($BAW_CONF['icons_url'] . "/flags/$file.png" , array("alt" => $domain, "title" => $domain));
  470             $newval_table[$domain] = array(
  471                 $icon,
  472                 $desc,
  473                 $domain,
  474                 $data[0],
  475                 $data[1],
  476                 $data[2]
  477             );
  478             $newval_chart[$domain] = array(
  479                 $icon,
  480                 $domain,
  481                 $data[0],
  482                 $data[1],
  483                 $data[2]
  484             );
  485             $out = '';
  486 
  487             if ($set['chart']) {
  488                 $out .= baw_render_htmlchart($newval_chart, $format_chart, $set['avg'], $set['top_x']);
  489             }
  490             if ($set['map']) {
  491                 $out .= baw_render_map($newval_table, $set['top_x']);
  492             }
  493             if ($set['table']) {
  494                 $out .= baw_render_table($set['name'], $newval_table, $format_table, $set['avg'], $set['total'], $set['top_x']);
  495             }
  496         }
  497     } else if ($BAW_CONF['hideempty']){
  498         return '';
  499     }
  500     return $out;
  501 }
  502 
  503 function baw_display_visitors($set) {
  504     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_CONF_DIS;
  505     $format = array( // first line
  506         0 => array ('title'=> $BAW_MES[81], 'format' => 'layout_text'),
  507         1 => array ('percent' => true, 'title'=> $BAW_MES[56], 'format' => 'layout_pages'),
  508         2 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits'),
  509         3 => array ('title'=> $BAW_MES[75], 'format' => 'layout_bytes'),
  510         4 => array ('title'=> $BAW_MES['ratio_pages_hits'], 'format' => 'layout_ratio', 'ratio' => '2/1'),
  511         5 => array ('title'=> $BAW_MES[9], 'format' => 'layout_date'),
  512     );
  513     $h_data = array(0,0,0,'latest_date'=> 0);
  514     $s_data = array(0,0,0,'latest_date'=> 0);
  515     $i = 0;
  516     $hashotlinks = false;
  517     $hasbots = false;
  518     if ($val = baw_data($BAW_CURR['site_name'], "VISITOR", $BAW_CURR['yearmonth'])) {
  519         baw_debug("data loaded");
  520         foreach ($val as $dns => $data) {
  521             // $infolink = baw_create_link("?", "javascript:neww('$dns','{$dns}XXX')");
  522             // $line[] = array ('data'=> $infolink, 'class' => "aligncenter", 'format' => 'layout_index');
  523             //if (!$set['hidebots'] or $data[1] !== $data[2]) {
  524             $ratio = 0;
  525             if ($data[0] > 0) {
  526                 $ratio = $data[1] / $data[0];
  527             }
  528             // hotlinks & Bots
  529             if ($data[3] =='') {
  530                 $data[3] = 0;
  531             }
  532             // $data[3] = settype($data[3], 'int');
  533             if ($data[0] == 0 && $data[1] !== 0) {
  534                 $h_data['latest_date'] = max($data[3], $h_data['latest_date']);
  535                 $h_data[0] += $data[0];
  536                 $h_data[1] += $data[1];
  537                 $h_data[2] += $data[2];
  538                 $hashotlinks = true;
  539             } else if ($ratio <= $BAW_CONF_DIS['visitors']['assumebot']) {
  540                 $s_data['latest_date'] = max($data[3], $s_data['latest_date']);
  541                 $s_data[0] += $data[0];
  542                 $s_data[1] += $data[1];
  543                 $s_data[2] += $data[2];
  544                 $hasbots = true;
  545             } else {
  546                 $val[$i] = array(
  547                     $dns,
  548                     $data[0],
  549                     $data[1],
  550                     $data[2],
  551                     baw_num_format($ratio, 2),
  552                     $data[3]
  553                 );
  554             }
  555             // try extra to regain the memory here since this is the largest function
  556             $val[$dns] = NULL;
  557             unset($val[$dns]);
  558             $i++;
  559         }
  560         if ($hasbots) {
  561             $val['script'] = array(
  562                 $BAW_MES['assumedscript'],
  563                 $s_data[0],
  564                 $s_data[1],
  565                 $s_data[2],
  566                 $s_data[1] / $s_data[0],
  567                 $s_data['latest_date']
  568             );
  569         }
  570         if ($hashotlinks) {
  571             $val['hotlinks'] = array(
  572                 $BAW_MES['hotlinks_proxies'],
  573                 $h_data[0],
  574                 $h_data[1],
  575                 $h_data[2],
  576                 0,
  577                 $h_data['latest_date']
  578             );
  579         }
  580 
  581         $val = baw_array_sorting($val, $set['sort'], $set['sort_dir']);
  582         baw_debug("data sorted");
  583     } else if ($BAW_CONF['hideempty']){
  584         return '';
  585     }
  586     $out = '';
  587     if ($set['table']) {
  588         $out .= baw_render_table($set['name'], $val, $format, $set['avg'], $set['total'], $set['top_x']);
  589     }
  590     return $out;
  591 }
  592 
  593 function baw_display_logins($set) {
  594     global $BAW_MES, $BAW_CURR, $BAW_CONF;
  595     $format = array(
  596         0 => array ('title'=> $BAW_MES[94], 'format' => 'layout_text'),
  597         1 => array ('percent' => true, 'title'=> $BAW_MES[56], 'format' => 'layout_pages'),
  598         2 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits'),
  599         3 => array ('title'=> $BAW_MES[75], 'format' => 'layout_bytes'),
  600         4 => array ('title'=> $BAW_MES[9], 'format' => 'layout_date'),
  601     );
  602 
  603     $val = array();
  604     if ($val = baw_data($BAW_CURR['site_name'], "LOGIN", $BAW_CURR['yearmonth'])) {
  605         $val = baw_array_sorting($val, $set['sort'], $set['sort_dir']);
  606         foreach ($val as $id => $data) {
  607             $val[$id] = array(
  608                 $id,
  609                 $data[0],
  610                 $data[1],
  611                 $data[2],
  612                 $data[3]
  613             );
  614         }
  615     } else if ($BAW_CONF['hideempty']){
  616         return '';
  617     }
  618     $out = '';
  619     if ($set['table']) {
  620         $out .= baw_render_table($set['name'], $val, $format, $set['avg'], $set['total'], $set['top_x'], false);
  621     }
  622     return $out;
  623 }
  624 
  625 function baw_display_robots($set) {
  626     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
  627     $format = array(
  628         0 => array ('title'=> $BAW_MES[53], 'format' => 'layout_text'),
  629         1 => array ('percent' => false, 'title'=> $BAW_MES[57], 'format' => 'layout_hits'),
  630         2 => array ('title'=> $BAW_MES[57] . " (robots.txt)", 'format' => 'layout_hits'),
  631         3 => array ('title'=> $BAW_MES[75], 'format' => 'layout_bytes'),
  632         4 => array ('title'=> $BAW_MES[9], 'format' => 'layout_date'),
  633     );
  634     $newval = array();
  635     if ($val = baw_data($BAW_CURR['site_name'], "ROBOT", $BAW_CURR['yearmonth'])) {
  636         foreach ($val as $robot => $data) {
  637             if (isset($BAW_LIB['robots'][$robot])) {
  638                 $robot_txt = $BAW_LIB['robots'][$robot];
  639             } else {
  640                 $robot_txt = $robot;
  641             }
  642             $val[$robot] = array(
  643                 $robot_txt,
  644                 $data[0]-$data[3],
  645                 $data[3],
  646                 $data[1],
  647                 $data[2],
  648             );
  649         }
  650     } else if ($BAW_CONF['hideempty']){
  651         return '';
  652     }
  653     $out = '';
  654     if ($set['table']) {
  655         $val = baw_array_sorting($val, $set['sort'], $set['sort_dir']);
  656         $out .= baw_render_table($set['name'], $val, $format, $set['avg'], $set['total'], $set['top_x']);
  657     }
  658     return $out;
  659 }
  660 
  661 function baw_display_worms($set) {
  662     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
  663     $format = array(
  664         0 => array ('title'=> $BAW_MES[163], 'format' => 'layout_text'),
  665         1 => array ('title'=> $BAW_MES[167], 'format' => 'layout_text'),
  666         2 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits'),
  667         3 => array ('title'=> $BAW_MES[75], 'format' => 'layout_bytes'),
  668         4 => array ('title'=> $BAW_MES[9], 'format' => 'layout_date'),
  669     );
  670     $newval = array();
  671     if ($val = baw_data($BAW_CURR['site_name'], "WORMS", $BAW_CURR['yearmonth'])) {
  672         foreach ($val as $worm => $data) {
  673             $val[$worm] = array(
  674                 $BAW_LIB['worms']['names'][$worm],
  675                 $BAW_LIB['worms']['targets'][$worm],
  676                 $data[0],
  677                 $data[1],
  678                 $data[2]
  679             );
  680         }
  681     } else if ($BAW_CONF['hideempty']){
  682         return '';
  683     }
  684     $out = '';
  685     if ($set['table']) {
  686         $val = baw_array_sorting($val, $set['sort'], $set['sort_dir']);
  687         $out .= baw_render_table($set['name'], $val, $format, $set['avg'], $set['total'], $set['top_x']);
  688     }
  689     return $out;
  690 }
  691 
  692 function baw_display_sessions($set) {
  693     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
  694     $format = array(
  695         0 => array ('title'=> $BAW_MES[117], 'format' => 'layout_text'),
  696         1 => array ('percent' => true, 'title'=> $BAW_MES[10], 'format' => 'layout_visits')
  697     );
  698 
  699     $newval = array();
  700     $sum = 0; // sum for "unknown"
  701     if ($val = baw_data($BAW_CURR['site_name'], "SESSION", $BAW_CURR['yearmonth'])) {
  702         foreach ($BAW_LIB['sessions'] as $timespan) {
  703             $newval[$timespan] = array($timespan, 0);
  704             if (isset($val[$timespan][0])) {
  705                 $newval[$timespan][1] = $val[$timespan][0];
  706                 $sum += $val[$timespan][0];
  707             }
  708         }
  709         $unknown = $BAW_CURR['thismonth']['hits'] - $sum;
  710         $newval['Unknown'] = array('Unknown', $unknown);
  711     } else if ($BAW_CONF['hideempty']){
  712         return '';
  713     }
  714     // $newval = baw_array_sorting($newval, 1, SORT_DESC);
  715     $out = '';
  716     if ($set['table']) {
  717         $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], false);
  718     }
  719     return $out;
  720 }
  721 
  722 function baw_display_filetype($set) {
  723     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
  724     $format_table = array(
  725         0 => array ('title'=> $BAW_MES[73], 'format' => 'layout_text', 'colspan' => 3),
  726         1 => array ('format' => 'layout_text'),
  727         2 => array ('format' => 'layout_text'),
  728         3 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits'),
  729         4 => array ('percent' => true, 'title'=> $BAW_MES[75], 'format' => 'layout_bytes'),
  730         5 => array ('title'=> $BAW_MES[100], 'format' => 'layout_bytes'),
  731         6 => array ('title'=> $BAW_MES[101], 'format' => 'layout_bytes'),
  732         7 => array ('title'=> $BAW_MES[99], 'format' => 'layout_bytes'),
  733     );
  734     $format_chart = array(
  735         0 => array ('title'=> $BAW_MES[73], 'format' => 'layout_text', 'colspan' => 3),
  736         1 => array ('format' => 'layout_text'),
  737         2 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits'),
  738         3 => array ('percent' => true, 'title'=> $BAW_MES[75], 'format' => 'layout_bytes'),
  739     );
  740 
  741     $newval_table = array();
  742     $newval_chart = array();
  743     if ($val = baw_data($BAW_CURR['site_name'], "FILETYPES", $BAW_CURR['yearmonth'])) {
  744         // Files type - Hits - Bandwidth - Bandwidth without compression - Bandwidth after compression
  745         $val = baw_array_sorting($val, $set['sort'], $set['sort_dir']);
  746         foreach ($val as $type => $data) {
  747             $icon = '';
  748             if (isset($BAW_LIB['files']['icons'][$type])) {
  749                 $iconname = $BAW_LIB['files']['icons'][$type];
  750                 $icon = baw_create_image($BAW_CONF['icons_url'] . "/mime/$iconname.png" , array("alt" => $iconname, "title" => $iconname));
  751             }
  752             if ($type == 'Unknown') {
  753                 $type_text = "?";
  754                 $desc = $type;
  755             } else {
  756                 $type_text = $type;
  757                 $desc = @$BAW_LIB['files']['types'][$BAW_LIB['files']['family'][$type]];
  758             }
  759             $newval_table[$type] = array(
  760                 $icon,
  761                 $type_text,
  762                 $desc,
  763                 $data[0],
  764                 $data[1],
  765                 $data[2],
  766                 $data[3],
  767                 $data[2] - $data[3]
  768             );
  769             $newval_chart[$type] = array(
  770                 $icon,
  771                 $type_text,
  772                 $data[0],
  773                 $data[1],
  774             );
  775        }
  776     } else if ($BAW_CONF['hideempty']){
  777         return '';
  778     }
  779 
  780     // $chart = baw_array_sorting($chart, $set['sort'], $set['sort_dir']);
  781     // $pieval = baw_array_sorting($pieval, 1, $set['sort_dir']);
  782     $out = '';
  783     if ($set['chart']) {
  784         $out .= baw_render_htmlchart($newval_chart, $format_chart, $set['avg'], $set['top_x']);
  785     }
  786     if ($set['table']) {
  787         $out .= baw_render_table($set['name'], $newval_table, $format_table, $set['avg'], $set['total'], $set['top_x'], false);
  788     }
  789     return $out;
  790 }
  791 
  792 function baw_display_urls($set) {
  793     global $BAW_MES, $BAW_CURR, $BAW_CONF;
  794     $format = array(
  795         0 => array ('title'=> $BAW_MES[19], 'format' => 'layout_text'),
  796         1 => array ('title'=> $BAW_MES[29], 'format' => 'layout_pages'),
  797         2 => array ('title'=> $BAW_MES[106], 'format' => 'layout_bytes'),
  798         3 => array ('title'=> $BAW_MES[104], 'format' => 'layout_hits'),
  799         4 => array ('title'=> $BAW_MES[116], 'format' => 'layout_hits')
  800     );
  801     $val = array();
  802     if ($val = baw_data($BAW_CURR['site_name'], "SIDER", $BAW_CURR['yearmonth'])) {
  803         foreach ($val as $url => $data) {
  804             $link = baw_create_link($url, "http://{$BAW_CURR['site_name']}$url", array(), true);
  805             // URL - Pages - Bandwidth - Entry - Exit
  806             $val[$url] = array(
  807                 $link,
  808                 $data[0],
  809                 $data[1]/$data[0], // average size per page instead of sum
  810                 $data[2],
  811                 $data[3]
  812             );
  813         }
  814     } else if ($BAW_CONF['hideempty']){
  815         return '';
  816     }
  817     $val = baw_array_sorting($val, $set['sort'], $set['sort_dir']);
  818     $out = '';
  819     if ($set['table']) {
  820         $out .= baw_render_table($set['name'], $val, $format, $set['avg'], $set['total'], $set['top_x'], false);
  821     }
  822     return $out;
  823 }
  824 
  825 function baw_display_paths($set) {
  826     global $BAW_MES, $BAW_CURR, $BAW_CONF;
  827     $format = array(
  828         0 => array ('title'=> $BAW_MES['files_paths'], 'format' => 'layout_text'),
  829         1 => array ('title'=> $BAW_MES[29], 'format' => 'layout_pages'),
  830     );
  831     $val = array();
  832     $newval = array();
  833     if ($val = baw_data($BAW_CURR['site_name'], "SIDER", $BAW_CURR['yearmonth'])) {
  834         foreach ($val as $url => $data) {
  835             $full_url = "http://{$BAW_CURR['site_name']}$url";
  836             $url_array = parse_url($full_url);
  837             $link_url = "http://{$BAW_CURR['site_name']}" . $url_array['path'];
  838             $link = baw_create_link($url_array['path'], $link_url, array(), true);
  839             if (!isset($newval[$url_array['path']])) {
  840                 $newval[$url_array['path']] = array(
  841                     0 => $link,
  842                     1 => $data[0]
  843                 );
  844             } else {
  845                 $newval[$url_array['path']][1] += $data[0];
  846             }
  847         }
  848     } else if ($BAW_CONF['hideempty']){
  849         return '';
  850     }
  851     $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
  852     $out = '';
  853     if ($set['table']) {
  854         $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], $set['top_x'], false);
  855     }
  856     return $out;
  857 }
  858 
  859 function baw_display_os($set) {
  860     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
  861     $format_table = array(
  862         0 => array ('title'=> $BAW_MES[59], 'format' => 'layout_text', 'colspan' => 2),
  863         1 => array ('format' => 'layout_text'),
  864         2 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
  865     );
  866     $format_chart = array(
  867         0 => array ('title'=> $BAW_MES[59], 'format' => 'layout_text'),
  868         1 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits')
  869     );
  870     $newval_table = array();
  871     $newval_chart = array();
  872     if ($val = baw_data($BAW_CURR['site_name'], 'OS', $BAW_CURR['yearmonth'])) {
  873         $newval_table = $BAW_LIB['os']['families']; // create an array where the main are already
  874         if ($BAW_CONF['module'] == 'drupal') {
  875             $url = "/{$BAW_CONF['drupal_base']}/details/unknownos/{$BAW_CURR['month']}/{$BAW_CURR['year']}";
  876         } else {
  877             $url = "{$BAW_CONF['site_url']}/index.php?site={$BAW_CURR['site_name']}&month={$BAW_CURR['month']}&year={$BAW_CURR['year']}&action=get_fulltable&what=unknownos";
  878         }
  879         // iterate all the data
  880         foreach ($val as $os => $data) {
  881             $isnew = true; // this os has not been added to newval yet (not families)
  882             // iterate all the std. OS types and add the date to the curret one if matches
  883             foreach ($BAW_LIB['os']['codes'] as $code) {
  884                 if (stristr($os, $code) !== false) {
  885                     $newval_table[$code][2] += $data[0]; // found it, add stats
  886                     $iconid = $code;
  887                     $isnew = false; // we have the stats now
  888                 }
  889             }
  890             if ($isnew) { // this is an additional, non-family os
  891                 $iconid = $os;
  892                 $os_link = $BAW_LIB['os']['list'][$os];
  893                 $newval_table[$os] = array('', $os_link, $data[0]);
  894             }
  895             if ($os == 'Unknown') {
  896                 $newval_table[$os][1] = baw_create_link($BAW_MES[0], $url);
  897             }
  898             $icon = baw_create_image(
  899                 $BAW_CONF['icons_url'] . "/os/" . str_replace('/', '',
  900                 strtolower($iconid)) . '.png',
  901                 array('title' => strip_tags($newval_table[$iconid][1]))
  902             );
  903             $newval_table[$iconid][0] = $icon;
  904         }
  905         $newval_table = baw_array_sorting($newval_table, $set['sort'], $set['sort_dir']);
  906         // clean out data with 0 hits
  907         foreach ($newval_table as $id => $data) {
  908             if ($data[2] == 0) {
  909                 unset ($newval_table[$id]);
  910             } else { // copy valid points into chart array
  911                 $newval_chart[$id] = array(
  912                     $data[0],
  913                     $data[2]
  914                 );
  915             }
  916         }
  917     } else if ($BAW_CONF['hideempty']){
  918         return '';
  919     }
  920 
  921     $out = '';
  922     if ($set['chart']) {
  923         $out .= baw_render_htmlchart($newval_chart, $format_chart, $set['avg'], $set['top_x']);
  924     }
  925     if ($set['table']) {
  926         $out .= baw_render_table($set['name'], $newval_table, $format_table, $set['avg'], $set['total'], $set['top_x'], false);
  927     }
  928     return $out;
  929 }
  930 
  931 function baw_display_osversions($set) {
  932     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
  933     $format_table = array(
  934         0 => array ('title'=> $BAW_MES[59], 'format' => 'layout_text', 'colspan' => 2),
  935         1 => array ('format' => 'layout_text'),
  936         2 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
  937     );
  938     $format_chart = array(
  939         0 => array ('title'=> $BAW_MES[59], 'format' => 'layout_text'),
  940         1 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits')
  941     );
  942     if ($val = baw_data($BAW_CURR['site_name'], 'OS', $BAW_CURR['yearmonth'])) {
  943         if ($BAW_CONF['module'] == 'drupal') {
  944             $url = "/{$BAW_CONF['drupal_base']}/details/unknownos/{$BAW_CURR['month']}/{$BAW_CURR['year']}";
  945         } else {
  946             $url = "{$BAW_CONF['site_url']}/index.php?site={$BAW_CURR['site_name']}&month={$BAW_CURR['month']}&year={$BAW_CURR['year']}&action=get_fulltable&what=unknownos";
  947         }
  948         $newval_table = array();
  949         foreach ($val as $os => $data) {
  950             $iconid = $os;
  951             $os_link = $BAW_LIB['os']['list'][$os];
  952             $icon = baw_create_image(
  953                 $BAW_CONF['icons_url'] . "/os/" . str_replace('/', '',
  954                 strtolower($iconid)) . '.png',
  955                 array('title' => strip_tags($os_link))
  956             );
  957             $newval_table[$os] = array($icon, $os_link, $data[0]);
  958             if ($os == 'Unknown') {
  959                 $newval_table[$os][1] = baw_create_link($BAW_MES[0], $url);
  960             }
  961         }
  962     } else if ($BAW_CONF['hideempty']){
  963         return '';
  964     }
  965     $newval_table = baw_array_sorting($newval_table, 2, $set['sort_dir']);
  966     $out = '';
  967     if ($set['chart']) {
  968         $newval_chart = array();
  969         foreach ($newval_table as $os => $data) {
  970             $newval_chart[$os] = array($data[0], $data[2]);
  971         }
  972         $out .= baw_render_htmlchart($newval_chart, $format_chart, $set['avg'], $set['top_x']);
  973     }
  974     if ($set['table']) {
  975         $out .= baw_render_table($set['name'], $newval_table, $format_table, $set['avg'], $set['total'], $set['top_x'], false);
  976     }
  977     return $out;
  978 }
  979 
  980 function baw_display_unknownos($set) {
  981     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
  982     $format = array(
  983         0 => array ('title'=> $BAW_MES[46], 'format' => 'layout_text'),
  984         1 => array ('percent' => false, 'title'=> $BAW_MES[9], 'format' => 'layout_date')
  985     );
  986     $val = array();
  987     if ($val = baw_data($BAW_CURR['site_name'], 'UNKNOWNREFERER', $BAW_CURR['yearmonth'])) {
  988         $newval = array();
  989         foreach ($val as $os_ver => $data) {
  990             $os_ver = strip_tags($os_ver);
  991             $newval[] = array($os_ver, $data[0]);
  992         }
  993         $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
  994     } else if ($BAW_CONF['hideempty']){
  995         return '';
  996     }
  997     $out = '';
  998     if ($set['table']) {
  999         $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], $set['top_x'], false);
 1000     }
 1001     return $out;
 1002 }
 1003 
 1004 function baw_display_browsers($set) {
 1005     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
 1006     $format_table = array(
 1007         0 => array ('title'=> $BAW_MES[21], 'format' => 'layout_text', 'colspan' => 2),
 1008         1 => array ('format' => 'layout_text'),
 1009         2 => array ('title'=> $BAW_MES[111], 'format' => 'layout_text'),
 1010         3 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1011     );
 1012     $format_chart = array(
 1013         0 => array ('title'=> $BAW_MES[21], 'format' => 'layout_text',),
 1014         1 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1015     );
 1016     $search = array(
 1017         '\\s',
 1018         '\\-'
 1019     );
 1020     $replace  = array(
 1021         "_",
 1022         "-"
 1023     );
 1024     $newval_table = array();
 1025     if ($val = baw_data($BAW_CURR['site_name'], 'BROWSER', $BAW_CURR['yearmonth'])) {
 1026         $lib = $BAW_LIB['browser']['names'];
 1027         if ($BAW_CONF['module'] == 'drupal') {
 1028             $url = "/{$BAW_CONF['drupal_base']}/details/unknownbrowser/{$BAW_CURR['month']}/{$BAW_CURR['year']}";
 1029         } else {
 1030             $url = "{$BAW_CONF['site_url']}/index.php?site={$BAW_CURR['site_name']}&month={$BAW_CURR['month']}&year={$BAW_CURR['year']}&action=get_fulltable&what=unknownbrowser";
 1031         }
 1032         // iterate all browsers in the library
 1033         foreach ($lib as $browser => $description) {
 1034             // get the icon
 1035             $icon = '';
 1036             if (isset($BAW_LIB['browser']['icons'][$browser])) {
 1037                 $icon = $BAW_LIB['browser']['icons'][$browser];
 1038                 $icon = str_replace($search, $replace, $icon);
 1039                 $icon = baw_create_image(
 1040                     $BAW_CONF['icons_url'] . "/browser/$icon.png",
 1041                     array('title' => strip_tags($description))
 1042                 );
 1043             } else {
 1044                 // we have to create an icon since the chart is indexed by the icon
 1045                 // html. they have to be different each.
 1046                 $icon = baw_create_image(
 1047                     $BAW_CONF['site_url'] . "/icons/empty.png",
 1048                     array('title' => strip_tags($description))
 1049                 );
 1050             }
 1051             // grabber ?
 1052             $grabber = $BAW_MES[113];
 1053             if (isset($BAW_LIB['browser']['grabbers'][$browser])) {
 1054                 $grabber = $BAW_MES[112];
 1055             }
 1056             // create table line for this browser since we dont need versions
 1057             $newval_table[$browser] = array($icon, $description, $grabber, 0);
 1058             if ($browser == 'Unknown') {
 1059                 $newval_table[$browser][1] = baw_create_link($BAW_MES[0], $url);
 1060                 $newval_table[$browser][2] = '?';
 1061             }
 1062             // summ all occurences of this browser
 1063             foreach ($val as $browser_ver => $hits) {
 1064                 // only add if hits and if the browser matches
 1065                 if (($hits > 0) and stristr($browser_ver, $browser) !== false) {
 1066                     @$newval_table[$browser][3] += $hits[0];
 1067                 }
 1068             }
 1069             // kill zero-value browsers
 1070             if ($newval_table[$browser][3] == 0) {
 1071                 unset($newval_table[$browser]);
 1072             }
 1073         }
 1074         $newval_table = baw_array_sorting($newval_table, $set['sort'], $set['sort_dir']);
 1075     } else if ($BAW_CONF['hideempty']){
 1076         return '';
 1077     }
 1078 
 1079     $out = '';
 1080     if ($set['chart']) {
 1081         foreach ($newval_table as $browser => $data) {
 1082             $newval_chart[$browser] = array($data[0], $data[3]);
 1083         }
 1084         $out .= baw_render_htmlchart($newval_chart, $format_chart, $set['avg'], $set['top_x']);
 1085     }
 1086     if ($set['table']) {
 1087         $out .= baw_render_table($set['name'], $newval_table, $format_table, $set['avg'], $set['total'], $set['top_x'], false);
 1088     }
 1089     return $out;
 1090 }
 1091 
 1092 function baw_display_browserversions($set) {
 1093     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
 1094     $format_table = array(
 1095         0 => array ('title'=> $BAW_MES['browser_versions'], 'format' => 'layout_text', 'colspan' => 3),
 1096         1 => array ('format' => 'layout_text'),
 1097         2 => array ('format' => 'layout_text'),
 1098         3 => array ('title'=> $BAW_MES[111], 'format' => 'layout_text'),
 1099         4 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1100     );
 1101     $format_chart = array(
 1102         0 => array ('title'=> $BAW_MES['browser_versions'], 'format' => 'layout_text'),
 1103         1 => array ('format' => 'layout_text'),
 1104         2 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1105     );
 1106     $search = array(
 1107         '\\s',
 1108         '\\-'
 1109     );
 1110     $replace  = array(
 1111         "_",
 1112         "-"
 1113     );
 1114     $newval_table = array();
 1115     if ($val = baw_data($BAW_CURR['site_name'], 'BROWSER', $BAW_CURR['yearmonth'])) {
 1116         if ($BAW_CONF['module'] == 'drupal') {
 1117             $url = "/{$BAW_CONF['drupal_base']}/details/unknownbrowser/{$BAW_CURR['month']}/{$BAW_CURR['year']}";
 1118         } else {
 1119             $url = "{$BAW_CONF['site_url']}/index.php?site={$BAW_CURR['site_name']}&month={$BAW_CURR['month']}&year={$BAW_CURR['year']}&action=get_fulltable&what=unknownbrowser";
 1120         }
 1121         $lib = $BAW_LIB['browser']['names'];
 1122         // iterate all browsers in the library
 1123         foreach ($val as $browser_ver => $hits) {
 1124             // separate text from numbers/points
 1125             preg_match('/([a-zA-Z\W]+)((.?([0-9]))*)/', $browser_ver, $matches);
 1126             $browser = $matches[1];
 1127             $version = $matches[2];
 1128 
 1129             $icon = '';
 1130             $grabber = $BAW_MES[113];
 1131             if (isset($BAW_LIB['browser']['names'][$browser])) {
 1132                 $description = $lib[$browser];
 1133                 if (isset($BAW_LIB['browser']['icons'][$browser])) {
 1134                     $icon = $BAW_LIB['browser']['icons'][$browser];
 1135                     $icon = str_replace($search, $replace, $icon);
 1136                     $icon = baw_create_image(
 1137                         $BAW_CONF['icons_url'] . "/browser/$icon.png",
 1138                         array('title' => strip_tags($description) . " " . $version)
 1139                     );
 1140                 } else {
 1141                     $icon = baw_create_image(
 1142                         $BAW_CONF['site_url'] . "/icons/empty.png",
 1143                         array('title' => strip_tags($description) . " " . $version)
 1144                     );
 1145                 }
 1146             } else {
 1147                 $description = $browser_ver;
 1148                 $grabber = '?';
 1149             }
 1150             // grabber ?
 1151             if (isset($BAW_LIB['browser']['grabbers'][$browser])) {
 1152                 $grabber = $BAW_MES[112];
 1153             }
 1154             @$newval_table[$browser_ver] = array($icon, $description , $version, $grabber, $hits[0]);
 1155             if ($browser == 'Unknown') {
 1156                 $newval_table[$browser][1] = baw_create_link($BAW_MES[0], $url);
 1157                 $newval_table[$browser][2] = '?';
 1158             }
 1159         }
 1160     } else if ($BAW_CONF['hideempty']){
 1161         return '';
 1162     }
 1163     $newval_table = baw_array_sorting($newval_table, $set['sort'], $set['sort_dir']);
 1164     $out = '';
 1165     if ($set['chart']) {
 1166         $newval_chart = array();
 1167         foreach ($newval_table as $browser => $data) {
 1168             $newval_chart[$browser] = array($data[0], $data[2], $data[4]);
 1169         }
 1170         $out .= baw_render_htmlchart($newval_chart, $format_chart, $set['avg'], $set['top_x']);
 1171     }
 1172     if ($set['table']) {
 1173         $out .= baw_render_table($set['name'], $newval_table, $format_table, $set['avg'], $set['total'], $set['top_x'], false);
 1174     }
 1175     return $out;
 1176 }
 1177 
 1178 function baw_display_unknownbrowser($set) {
 1179     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
 1180     $format = array(
 1181         0 => array ('title'=> $BAW_MES[50], 'format' => 'layout_text'),
 1182         1 => array ('percent' => false, 'title'=> $BAW_MES[9], 'format' => 'layout_date')
 1183     );
 1184     $val = array();
 1185     if ($val = baw_data($BAW_CURR['site_name'], 'UNKNOWNREFERERBROWSER', $BAW_CURR['yearmonth'])) {
 1186         $newval = array();
 1187         foreach ($val as $browser_ver => $data) {
 1188             $browser_ver = strip_tags($browser_ver);
 1189             $newval[] = array($browser_ver, $data[0]);
 1190         }
 1191         $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
 1192     } else if ($BAW_CONF['hideempty']){
 1193         return '';
 1194     }
 1195     $out = '';
 1196     if ($set['table']) {
 1197         $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], $set['top_x'], false);
 1198     }
 1199     return $out;
 1200 }
 1201 
 1202 function baw_display_screensizes($set) {
 1203     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
 1204     $format = array(
 1205         0 => array ('title'=> $BAW_MES[135], 'format' => 'layout_text', 'colspan' => 2),
 1206         1 => array ('format' => 'layout_text'),
 1207         2 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1208     );
 1209     $format_chart = array(
 1210         0 => array ('title'=> $BAW_MES[135], 'format' => 'layout_text'),
 1211         1 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1212     );
 1213     $val = array();
 1214     $newval = array();
 1215     $url = $BAW_CONF['site_url'] . "/icons/screen.png";
 1216     if ($val = baw_data($BAW_CURR['site_name'], 'SCREENSIZE', $BAW_CURR['yearmonth'])) {
 1217         foreach ($val as $size => $data) {
 1218             $size_arr = explode("x", $size);
 1219             $sizex = $size_arr[0] / 80;
 1220             $sizey = $size_arr[1] / 80;
 1221             $img_arr = array(
 1222                 'height'=> $sizey,
 1223                 'width' => $sizex,
 1224                 'title' => $size,
 1225                 'class' => 'screensize'
 1226             );
 1227             $newval[$size] = array(
 1228                 baw_create_image($url, $img_arr),
 1229                 $size,
 1230                 $data[0],
 1231             );
 1232         }
 1233     } else if ($BAW_CONF['hideempty']){
 1234         return '';
 1235     }
 1236     $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
 1237     $out = '';
 1238     if ($set['chart']) {
 1239         $newval_chart = array();
 1240         foreach ($newval as $size => $data) {
 1241             $newval_chart[$size] = array($data[0], $data[2]);
 1242         }
 1243         $out .= baw_render_htmlchart($newval_chart, $format_chart, $set['avg'], $set['top_x']);
 1244     }
 1245     if ($set['table']) {
 1246         $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], $set['top_x'], false);
 1247     }
 1248     return $out;
 1249 }
 1250 
 1251 function baw_display_se_referers($set) {
 1252     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
 1253     if ($set['favicon']) {
 1254         $format = array(
 1255             0 => array ('title'=> $BAW_MES[126], 'format' => 'layout_text', 'colspan' => 2),
 1256             1 => array ('format' => 'layout_text'),
 1257             2 => array ('percent' => true, 'title'=> $BAW_MES[56], 'format' => 'layout_pages'),
 1258             3 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1259         );
 1260         $set['sort']++;
 1261     } else {
 1262         $format = array(
 1263             0 => array ('title'=> $BAW_MES[126], 'format' => 'layout_text'),
 1264             1 => array ('percent' => true, 'title'=> $BAW_MES[56], 'format' => 'layout_pages'),
 1265             2 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1266         );
 1267     }
 1268     $val = array();
 1269     $newval = array();
 1270     if ($val = baw_data($BAW_CURR['site_name'], 'SEREFERRALS', $BAW_CURR['yearmonth'])) {
 1271         foreach ($val as $id => $data) {
 1272             $sename = @$BAW_LIB['searchengines']['names'][$id];
 1273             if ($set['favicon']) {
 1274                 $image = baw_get_favicon($sename);
 1275                 $newval[$id] = array(
 1276                     $image,
 1277                     $sename,
 1278                     $data[0],
 1279                     $data[1]
 1280                 );
 1281             } else {
 1282                 $newval[$id] = array(
 1283                     $sename,
 1284                     $data[0],
 1285                     $data[1]
 1286                 );
 1287             }
 1288 
 1289         }
 1290         $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
 1291     } else if ($BAW_CONF['hideempty']){
 1292         return '';
 1293     }
 1294     $out = '';
 1295     if ($set['table']) {
 1296         $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], $set['top_x'], false);
 1297     }
 1298     return $out;
 1299 }
 1300 
 1301 function baw_display_referers($set) {
 1302     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
 1303     if ($set['favicon']) {
 1304         $format = array(
 1305             0 => array ('title'=> $BAW_MES[127], 'format' => 'layout_text', 'colspan' => 2),
 1306             1 => array ('format' => 'layout_text'),
 1307             2 => array ('title'=> $BAW_MES[56], 'format' => 'layout_pages'),
 1308             3 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1309         );
 1310         $set['sort']++;
 1311     } else {
 1312         $format = array(
 1313             0 => array ('title'=> $BAW_MES[127], 'format' => 'layout_text'),
 1314             1 => array ('title'=> $BAW_MES[56], 'format' => 'layout_pages'),
 1315             2 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1316         );
 1317     }
 1318     $newval = array();
 1319     if ($val = baw_data($BAW_CURR['site_name'], 'PAGEREFS', $BAW_CURR['yearmonth'])) {
 1320         foreach ($val as $id => $data) {
 1321             if ($data[0] > 0) {
 1322                 $link = baw_create_link($id, $id, array(), true, true);
 1323                 if ($set['favicon']) {
 1324                     $image = baw_get_favicon($id);
 1325                     $newval[$id] = array($image,$link,$data[0],$data[1]);
 1326 
 1327                 } else {
 1328                     $newval[$id] = array($link,$data[0],$data[1]);
 1329                 }
 1330             }
 1331         }
 1332         $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
 1333     } else if ($BAW_CONF['hideempty']){
 1334         return '';
 1335     }
 1336     $out = '';
 1337     if ($set['table']) {
 1338         $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], $set['top_x'], false);
 1339     }
 1340     return $out;
 1341 }
 1342 
 1343 function baw_display_referer_domains($set) {
 1344     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB, $BAW_CONF_DIS;
 1345     if ($set['favicon']) {
 1346         $format = array(
 1347             0 => array ('title'=> sprintf($BAW_MES['by_domains'], $BAW_MES[127]) , 'format' => 'layout_text', 'colspan' => 2),
 1348             1 => array ('format' => 'layout_text'),
 1349             2 => array ('title'=> $BAW_MES[56], 'format' => 'layout_pages'),
 1350             3 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1351         );
 1352         $set['sort']++;
 1353     } else {
 1354         $format = array(
 1355             0 => array ('title'=> sprintf($BAW_MES['by_domains'], $BAW_MES[127]) , 'format' => 'layout_text'),
 1356             1 => array ('title'=> $BAW_MES[56], 'format' => 'layout_pages'),
 1357             2 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1358         );
 1359     }
 1360     $newval = array();
 1361     $length = $BAW_CONF_DIS['referer_domains']['domain_lvls'];
 1362     if ($val = baw_data($BAW_CURR['site_name'], 'PAGEREFS', $BAW_CURR['yearmonth'])) {
 1363         foreach ($val as $id => $data) {
 1364             if ($data[0] > 0) {
 1365                 $tld = @parse_url($id);
 1366                 // we create & flip the array
 1367                 if ($length !== -1) {
 1368                     $domain_array = explode(".", $tld['host']);
 1369                     // we add the x number of elements to the new array
 1370                     if (!is_numeric(implode("",$domain_array))) {
 1371 
 1372                         $domain_array = array_slice($domain_array, -$length);
 1373                     }
 1374                     $domain = implode(".", $domain_array);
 1375                 } else {
 1376                     $domain = $tld['host'];
 1377                 }
 1378                 $tld = $tld['scheme'] ."://". $domain;
 1379                 // $tld = str_replace("http://www.", "http://", $tld);
 1380                 if ($set['favicon']) {
 1381                     if (!isset($newval[$tld])) {
 1382                         $image = baw_get_favicon($tld);
 1383                         $link = baw_create_link($tld, $tld);
 1384                         $newval[$tld] = array($image, $link, $data[0],$data[1]);
 1385                     } else {
 1386                         $newval[$tld][2] += $data[0];
 1387                         $newval[$tld][3] += $data[1];
 1388                     }
 1389                 } else {
 1390                     if (!isset($newval[$tld])) {
 1391                         $link = baw_create_link($tld, $tld);
 1392                         $newval[$tld] = array($link, $data[0],$data[1]);
 1393                     } else {
 1394                         $newval[$tld][1] += $data[0];
 1395                         $newval[$tld][2] += $data[1];
 1396                     }
 1397                 }
 1398             }
 1399         }
 1400         $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
 1401     } else if ($BAW_CONF['hideempty']){
 1402         return '';
 1403     }
 1404     $out = '';
 1405     if ($set['table']) {
 1406         $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], $set['top_x'], false);
 1407     }
 1408     return $out;
 1409 }
 1410 
 1411 
 1412 function baw_display_hotlinks($set) {
 1413     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
 1414     if ($set['favicon']) {
 1415         $format = array(
 1416             0 => array ('title'=> $BAW_MES['referer_hotlinks'], 'format' => 'layout_text', 'colspan' => 2),
 1417             1 => array ('format' => 'layout_text'),
 1418             2 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1419         );
 1420         $set['sort']++;
 1421     } else {
 1422         $format = array(
 1423             0 => array ('title'=> $BAW_MES['referer_hotlinks'], 'format' => 'layout_text'),
 1424             1 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1425         );
 1426     }
 1427     $newval = array();
 1428     if ($val = baw_data($BAW_CURR['site_name'], 'PAGEREFS', $BAW_CURR['yearmonth'])) {
 1429         foreach ($val as $id => $data) {
 1430             if ($data[0] == 0) {
 1431                 $link = baw_create_link($id, $id, array(), true);
 1432                 if ($set['favicon']) {
 1433                     $image = baw_get_favicon($id);
 1434                     $newval[$id] = array($image, $link, $data[1]);
 1435                 } else {
 1436                     $newval[$id] = array($link, $data[1]);
 1437                 }
 1438             }
 1439         }
 1440         if ($BAW_CONF['hideempty'] && count($newval) == 0 ) {
 1441             return '';
 1442         }
 1443         $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
 1444     } else if ($BAW_CONF['hideempty']){
 1445         return '';
 1446     }
 1447     $out = '';
 1448     if ($set['table']) {
 1449         $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], $set['top_x'], false);
 1450     }
 1451     return $out;
 1452 }
 1453 
 1454 function baw_display_hotlink_domains($set) {
 1455     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB, $BAW_CONF_DIS;
 1456     if ($set['favicon']) {
 1457         $format = array(
 1458             0 => array ('title'=> sprintf($BAW_MES['hl_by_domains '], $BAW_MES[127]), 'format' => 'layout_text', 'colspan' => 2),
 1459             1 => array ('format' => 'layout_text'),
 1460             2 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1461         );
 1462         $set['sort']++;
 1463     } else {
 1464         $format = array(
 1465             0 => array ('title'=> sprintf($BAW_MES['hl_by_domains '], $BAW_MES[127]), 'format' => 'layout_text'),
 1466             1 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1467         );
 1468     }
 1469     $length = $BAW_CONF_DIS['hotlink_domains']['domain_lvls'];
 1470     $newval = array();
 1471     if ($val = baw_data($BAW_CURR['site_name'], 'PAGEREFS', $BAW_CURR['yearmonth'])) {
 1472         foreach ($val as $id => $data) {
 1473             if ($data[0] == 0) {
 1474                 $tld = @parse_url($id);
 1475                 if ($length !== -1) {
 1476                     $domain_array = explode(".", $tld['host']);
 1477                     // we add the x number of elements to the new array
 1478                     if (!is_numeric(implode("",$domain_array))) {
 1479 
 1480                         $domain_array = array_slice($domain_array, -$length);
 1481                     }
 1482                     $domain = implode(".", $domain_array);
 1483                 } else {
 1484                     $domain = $tld['host'];
 1485                 }
 1486                 $tld = $tld['scheme'] ."://". $domain;
 1487                 if ($set['favicon']) {
 1488                     if (!isset($newval[$tld])) {
 1489                         $link = baw_create_link($tld, $tld);
 1490                         $image = baw_get_favicon($tld);
 1491                         $newval[$tld] = array($image, $link, $data[1]);
 1492                     } else {
 1493                         // $newval[$tld][1] += $data[1];
 1494                         $newval[$tld][2] += $data[1];
 1495                     }
 1496                 } else {
 1497                     if (!isset($newval[$tld])) {
 1498                         $link = baw_create_link($tld, $tld);
 1499                         $newval[$tld] = array($link, $data[1]);
 1500                     } else {
 1501                         // $newval[$tld][1] += $data[1];
 1502                         $newval[$tld][1] += $data[1];
 1503                     }
 1504                 }
 1505             }
 1506         }
 1507         // check again since none of the domains might be hotlinking
 1508         if ($BAW_CONF['hideempty'] && count($newval) == 0 ) {
 1509             return '';
 1510         }
 1511         $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
 1512     } else if ($BAW_CONF['hideempty']){
 1513         return '';
 1514     }
 1515     $out = '';
 1516     if ($set['table']) {
 1517         $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], $set['top_x'], false);
 1518     }
 1519     return $out;
 1520 }
 1521 
 1522 
 1523 function baw_display_searchphrases($set) {
 1524     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
 1525     $format = array(
 1526         0 => array ('title'=> $BAW_MES[103], 'format' => 'layout_text'),
 1527         1 => array ('percent'=> true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1528     );
 1529     $val = array();
 1530     $newval = array();
 1531     if ($val = baw_data($BAW_CURR['site_name'], 'SEARCHWORDS', $BAW_CURR['yearmonth'])) {
 1532         foreach ($val as $id => $data) {
 1533             $newval[$id] = array(
 1534                 urldecode($id),
 1535                 $data[0]
 1536             );
 1537         }
 1538         $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
 1539     } else if ($BAW_CONF['hideempty']){
 1540         return '';
 1541     }
 1542     $out = '';
 1543     if ($set['table']) {
 1544         $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], $set['top_x'], false);
 1545     }
 1546     return $out;
 1547 }
 1548 
 1549 function baw_display_searchwords($set) {
 1550     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
 1551     $format = array(
 1552         0 => array ('title'=> $BAW_MES[13], 'format' => 'layout_text'),
 1553         1 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits')
 1554     );
 1555     $val = array();
 1556     $newval = array();
 1557     if ($val = baw_data($BAW_CURR['site_name'], 'KEYWORDS', $BAW_CURR['yearmonth'])) {
 1558         foreach ($val as $id => $data) {
 1559             $newval[$id] = array(
 1560                 urldecode($id),
 1561                 $data[0],
 1562             );
 1563         }
 1564         $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
 1565     } else if ($BAW_CONF['hideempty']){
 1566         return '';
 1567     }
 1568     $out = '';
 1569     if ($set['table']) {
 1570         $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], $set['top_x'], false);
 1571     }
 1572     return $out;
 1573 }
 1574 
 1575 function baw_display_misc($set) {
 1576     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
 1577     $format = array(
 1578         0 => array ('title'=> $BAW_MES[139], 'format' => 'layout_text'),
 1579         1 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits'),
 1580         2 => array ('title'=> $BAW_MES[15], 'format' => 'layout_percent')
 1581     );
 1582     $newval = array();
 1583     if ($val = baw_data($BAW_CURR['site_name'], 'MISC', $BAW_CURR['yearmonth'])) {
 1584         foreach ($BAW_LIB['misc'] as $type => $msg) {
 1585             @$percent = $val[$type][1] / ($val['TotalMisc'][1]  / 100);
 1586             $newval[$type] = array($BAW_MES[$msg], @$val[$type][1], $percent);
 1587         }
 1588     } else if ($BAW_CONF['hideempty']){
 1589         return '';
 1590     }
 1591     $out = '';
 1592     if ($set['table']) {
 1593         $out .= baw_render_table($set['name'], $newval, $format);
 1594     }
 1595     return $out;
 1596 }
 1597 
 1598 function baw_display_errors($set) {
 1599     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
 1600     $format = array(
 1601         0 => array ('title'=> $BAW_MES[32], 'format' => 'layout_text', 'colspan'=> 2),
 1602         1 => array ('format' => 'layout_text'),
 1603         2 => array ('percent' => true, 'title'=> $BAW_MES[57], 'format' => 'layout_hits'),
 1604         3 => array ('title'=> $BAW_MES[106], 'format' => 'layout_bytes')
 1605     );
 1606     $newval = array();
 1607     if ($val = baw_data($BAW_CURR['site_name'], 'ERRORS', $BAW_CURR['yearmonth'])) {
 1608         foreach ($val as $type => $data) {
 1609             $ntype = $type;
 1610             if ($type == '404') {
 1611                 if ($BAW_CONF['module'] == 'drupal') {
 1612                     $ntype = baw_create_link('404', "/{$BAW_CONF['drupal_base']}/details/errors404/{$BAW_CURR['month']}/{$BAW_CURR['year']}");
 1613                 } else {
 1614                     $ntype = baw_create_link('404', "{$BAW_CONF['site_url']}/index.php?site={$BAW_CURR['site_name']}&month={$BAW_CURR['month']}&year={$BAW_CURR['year']}&action=get_fulltable&what=errors404");
 1615                 }
 1616             }
 1617             $newval[$type] = array(
 1618                 $ntype, $BAW_LIB['http_status'][$type], $data[0], $data[1]
 1619             );
 1620         }
 1621     } else if ($BAW_CONF['hideempty']){
 1622         return '';
 1623     }
 1624     $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
 1625     $out = '';
 1626     if ($set['table']) {
 1627         $out .= baw_render_table($set['name'], $newval, $format);
 1628     }
 1629     return $out;
 1630 }
 1631 
 1632 function baw_display_errors404($set) {
 1633     global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB;
 1634     $format = array(
 1635         0 => array ('title'=> $BAW_MES[49], 'format' => 'layout_text'),
 1636         1 => array ('title'=> $BAW_MES[57], 'format' => 'layout_hits'),
 1637         2 => array ('title'=> $BAW_MES[127], 'format' => 'layout_text')
 1638     );
 1639     $newval = array();
 1640     if ($val = baw_data($BAW_CURR['site_name'], 'SIDER_404', $BAW_CURR['yearmonth'])) {
 1641         foreach ($val as $type => $data) {
 1642             $newval[$type] = array(
 1643                 baw_create_link($type, "http://{$BAW_CURR['site_name']}", array(), true),
 1644                 $data[0],
 1645                 baw_create_link($data[1],$data[1], array(), true)
 1646             );
 1647         }
 1648     } else if ($BAW_CONF['hideempty']){
 1649         return '';
 1650     }
 1651     $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']);
 1652     $out = '';
 1653     if ($set['table']) {
 1654         $out .= baw_render_table($set['name'], $newval, $format, false, $set['total'], $set['top_x']);
 1655     }
 1656     return $out;
 1657 }
 1658 /*
 1659 
 1660   From0 6240 13402
 1661 From1 3 11 // unknown
 1662 From2 5471 8003 // search engine
 1663 From3 1956 3723 // external page
 1664 From4 10544 208546 // bookmarks/direct
 1665 From5 0 0 // newsgroups
 1666 
 1667 */
 1668 ?>