"Fossies" - the Fresh Open Source Software Archive

Member "betterawstats/modules/render_htmlchart2.inc.php" (17 Mar 2008, 7659 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 // this file can't be used on its own
   31 if (strpos ($_SERVER['PHP_SELF'], 'render_htmlchart.inc.php') !== false) {
   32     die ('This file can not be used on its own!');
   33 }
   34 
   35 function baw_render_htmlchart2($chart, $get_avg, $top_x) {
   36     baw_debug("rendering chart");
   37     global $BAW_CONF, $BAW_LIB, $BAW_MES;
   38     $out = '';
   39     // in case this is a full list, dont make it too wide
   40     $top_x = min($BAW_CONF['max_chart_items'], $top_x);
   41     // find out max values
   42     $max = array();
   43     $avg = array();
   44     $sum = array();
   45     $other = array();
   46     $count_val = count($chart);
   47     // take out topx so we can manipulate it for width calculation
   48     $top_x_count = $top_x;
   49     // if its not set, use count of items (day, month etc)
   50     if (!$top_x_count) {
   51         $top_x_count = $count_val;
   52     }
   53     // find the smaller one to know the resulting lines
   54     if (min($top_x_count, $count_val) > 12) {
   55         $width = 4;
   56     } else {
   57         $width = 6;
   58     }
   59     // get maximum values for scaling
   60     $count_up = 0;
   61     $count_val_static = $count_val;
   62     foreach ($chart as $lineid => $row) { // get the first set of data (one month/day/etc)
   63         $rowsum = 0;
   64         $count_val--; // this is used to find the final line
   65         foreach ($row as $cell => $attr) { // iterate through all the different data of one set
   66             $data = $attr['data'];
   67             @$max[$attr['format']] = max(@$max[$attr['format']], $data);
   68             // add others to chart
   69             if ($top_x && $count_up >= $top_x) {
   70                 @$other[$attr['format']] += $data;
   71                 if ($count_val == 0) { // do this only for the last value
   72                     // adding averages to the end of the data
   73                     $chart[$BAW_MES[2]][] = array(
   74                         'data'=> $other[$attr['format']],
   75                         'format' => $attr['format']
   76                     );
   77                     // add one more line so that others gets displayed
   78                     // get max again for others value
   79                     @$max[$attr['format']] = max(@$max[$attr['format']], $other[$attr['format']]);
   80                 }
   81             }
   82             if ($get_avg) {
   83                 // add avg to charts
   84                 @$sum[$attr['format']] += $data;
   85                 //if ($count_val >= 0) { // sum all values of this row
   86                     $rowsum += $data;
   87                 //}
   88                 if ($count_val == 0) { // do this only for the last value
   89                     @$avg[$attr['format']] = $sum[$attr['format']] / $count_val_static;
   90                     // adding averages to the end of the data
   91                     $chart[$BAW_MES[96]][] = array(
   92                         'data'=> $avg[$attr['format']],
   93                         'format' => $attr['format']
   94                     );
   95                 }
   96             }
   97         }
   98         if ($top_x && $count_up >= $top_x) {
   99             // remove 'other' data from chart after its processed
  100             unset($chart[$lineid]);
  101         }
  102         if ($rowsum == 0) { // substract line if all values zero
  103             $count_val_static--;
  104         }
  105         $count_up++;
  106     }
  107     // we need extra lines if we have this data
  108     if (isset($chart[$BAW_MES[2]])) { // others
  109         $top_x++;
  110     }
  111     if ($get_avg) {
  112         $top_x++;
  113     }
  114     // create actual chart
  115     $legend = '';
  116     $out .= "\n<table class=\"charttable\">\n";
  117     $out .= "    <tr>\n";
  118     $c = 0;
  119     $others = false;
  120     $otherdata = array();
  121     foreach ($chart as $lineid => $row) {
  122         if (!$top_x or $c < $top_x) {
  123             $out .= "        <td class=\"chartcell\">\n";
  124             foreach ($row as $cell => $attr) {
  125                 $tags = '';
  126                 // create attributes
  127                 foreach ($attr as $name => $value){
  128                     if ($name == 'data') {
  129                         $data = $value;
  130                     } else if ($name != 'format') {
  131                         $tags .= " $name=\"$value\"";
  132                     }
  133                 }
  134                 $format = $BAW_LIB['formats'][$attr['format']];
  135                 $function = $format['frm'];
  136                 $alt = "{$BAW_MES[$format['txt']]}: ". exec_function($function, $data);
  137                 // insert here the scaling figure
  138                 $max_string = str_replace('layout_', '', $attr['format']);
  139                 $max_val_field = $BAW_CONF["max_$max_string"];
  140                 if ((isset($max[$max_val_field])) && ($max[$max_val_field]>0)) {
  141                     $height = $data / ($max[$max_val_field] / 100); //( / ) * 100;
  142                 } else {
  143                     $height = 1;
  144                 }
  145                 if ($height < 1) {
  146                     $height = 1;
  147                 }
  148                 $attr = array(
  149                     'height'=> $height,
  150                     'width' => $width,
  151                     'alt' => $alt,
  152                     'title' => $alt,
  153                     'class' => 'chartimg'
  154                 );
  155                 $out .= baw_create_image($BAW_CONF['icons_url'] . "/other/{$format['img']}", $attr);
  156             }
  157             $out .= "\n        </td>\n";
  158             $legend_arr = explode("|",$lineid);
  159             if (!isset($legendcount)) {
  160                 $legendcount = count($legend_arr);
  161             }
  162             $f = 1;
  163             for ($i=0; $i<$legendcount; $i++) {
  164                 if ($i > 0) {
  165                    $tags = '';
  166                 }
  167                 @$legend[$i][$c] ="        <td$tags colspan=\"1\">{$legend_arr[$i]}</td>\n";
  168                 if (isset($legend[$i][$c-1]) && isset($legend_arr[$i])) {
  169                     $f ++;
  170                     if (preg_match('#colspan=\\"(\d+)\\">'. $legend_arr[$i].'</td>#', $legend[$i][$c-1], $number)) {
  171                         $number[1]++;
  172                         @$legend[$i][$c] ="        <td$tags colspan=\"{$number[1]}\">{$legend_arr[$i]}</td>\n";
  173                         $legend[$i][$c-1] ="";
  174                     }
  175                 } else {
  176                     $f = 1;
  177                 }
  178             }
  179         }
  180         $c ++;
  181     }
  182     if ($top_x and $c > $top_x) {
  183         $c = $top_x;
  184     }
  185     $out .= "    </tr>\n";
  186     // Display legend
  187     if (!isset($legendcount)) {
  188         $legendcount = 0;
  189     }
  190 
  191     for ($i=0; $i<$legendcount; $i++) {
  192         $out .= "    <tr class=\"chartlegend\">\n";
  193         for ($j=0; $j<$c; $j++) {
  194             $out .= $legend[$i][$j];
  195         }
  196         $out .= "    </tr>\n";
  197     }
  198     $out .= "</table>\n";
  199     baw_debug("rendering chart finished");
  200     return $out;
  201 }
  202 ?>