"Fossies" - the Fresh Open Source Software Archive

Member "betterawstats/modules/render_jpgraph.inc.php" (17 Mar 2008, 4478 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   2007 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 // this file can't be used on its own
   32 if (isset($_GET['getgraph'])) {
   33     baw_render_jpgraph_img();
   34 } else if (strpos ($_SERVER['PHP_SELF'], 'reder_map.inc.php') !== false) {
   35     die ('This file can not be used on its own!');
   36 }
   37 
   38 // $out .= baw_render_jpgraph ($set['name'], $newval, $format, 'pie', false, $set['top_x']);
   39 
   40 function baw_render_jpgraph ($name, $chart, $format, $type='pie', $get_avg=false, $top_x=false, $sort=0) {
   41     global $BAW_CONF, $BAW_MES;
   42     $dir = $BAW_CONF['jpgraph_path'] . '/jpgraph.php';
   43 
   44     if (!file_exists($dir)) {
   45         return baw_raise_error('jpgraph_path', array($dir));
   46     }
   47 
   48     $jp_data = array();
   49     // $jp_legend = array();
   50     $entries = 0;
   51     if (count($chart) == 0) {
   52         return "";
   53     }
   54     // calc others
   55     $f = '';
   56     $d = '';
   57     $others = 0;
   58     $other_arr = array();
   59 
   60     foreach ($chart as $id => $data) {
   61         $count = count($data);
   62         if ($entries < $top_x) {
   63             foreach ($format as $fid => $fdata) {
   64                 $d .= "&amp;d[$fid][]={$data[$fid]}";
   65             }
   66         } else { // 'others'
   67             foreach ($format as $fid => $fdata) {
   68                 if ($fdata['format'] !== 'layout_text' &&
   69                     $fdata['format'] !== 'layout_date') {
   70                     @$other_arr[$fid] += $data[$fid];
   71                 } else {
   72                     if ($fid == 0) {
   73                         $other_arr[$fid] = $BAW_MES[2];
   74                     } else {
   75                         $other_arr[$fid] = '';
   76                     }
   77                 }
   78             }
   79         }
   80         $entries ++;
   81     }
   82     foreach ($other_arr as $oid => $odata) {
   83         $d .= "&amp;d[$oid][$top_x]=$odata";
   84     }
   85     foreach ($format as $fid => $fdata) {
   86         $f .= "&amp;f[]= {$fdata['title']}";
   87     }
   88 
   89     // $count = count($jp_data);
   90 
   91     $img_url = $BAW_CONF['site_url'] . "/modules/render_jpgraph.inc.php?getgraph=true&amp;type=$type$d$f";
   92     $out = "<div class=\"aligncenter\"><img width=\"575\" height=\"286\" alt=\"chart: $name\" src=\"$img_url\"></div>";
   93     return $out;
   94 }
   95 
   96 function baw_render_jpgraph_img() {
   97     include_once("../config.php");
   98 
   99     if (isset($_GET['type'])) {
  100         $type = $_GET['type'];
  101     } else {
  102         return;
  103     }
  104 
  105     $d = $_GET['d'];
  106     $f = $_GET['f'];
  107 
  108     $count = count($d);
  109     $dir = $BAW_CONF['jpgraph_path'] . '/jpgraph.php';
  110     include_once ($dir);
  111     switch($type){
  112         case 'bar':
  113             include_once ($BAW_CONF['jpgraph_path'] . '/jpgraph_bar.php');
  114         break;
  115         case 'pie':
  116             include_once ($BAW_CONF['jpgraph_path'] . "/jpgraph_pie.php");
  117             $size = 0.17;
  118             $graph = new PieGraph(600,250,"auto");
  119             for ($i=0; $i<1; $i++) {
  120                 $p1 = new PiePlot($d[$i]);
  121                 if ($i == 0) {
  122                     $p1->SetLegends($d[0]);
  123                 }
  124                 $p1->title->Set($f[1]);
  125                 $p1->SetSize($size);
  126                 $vert = 0.15 + (($size + 0.1) * $i);
  127                 $p1->SetCenter($vert,0.3);
  128                 $p1->SetStartAngle(0);
  129                 $p1->SetTheme("sand");
  130                 $graph->Add($p1);
  131             }
  132             $graph->Stroke();
  133             break;
  134         case 'line':
  135             include_once ($BAW_CONF['jpgraph_path'] . "/jpgraph_line.php");
  136         break;
  137     }
  138     return $out;
  139 }
  140 
  141 
  142 ?>