Code Search for Developers
 
 
  

graph_pie.php from freePBX at Krugle


Show graph_pie.php syntax highlighted

<?php /* $Id: graph_pie.php 3052 2006-11-13 01:16:37Z qldrob $ */
include_once(dirname(__FILE__) . "/lib/defines.php");
include_once(dirname(__FILE__) . "/lib/Class.Table.php");
include_once(dirname(__FILE__) . "/jpgraph_lib/jpgraph.php");
include_once(dirname(__FILE__) . "/jpgraph_lib/jpgraph_pie.php");
include_once(dirname(__FILE__) . "/jpgraph_lib/jpgraph_pie3d.php");


/*
NOTE GENERER LES SOUSTRACTIONS SUR LES DATES NOUS-MEME
RAPIDE
cdrasterisk=> SELECT sum(duration) FROM cdr WHERE calldate < '2005-02-01' AND calldate >= '2005-01-01';
   sum
----------
 69076793
(1 row)
 
 TRES LENT
cdrasterisk=> SELECT sum(duration) FROM cdr WHERE calldate < date '2005-02-01'  - interval '0 months' AND calldate >=  date '2005-02-01'  - interval '1 months' ;
   sum
----------
 69076793
(1 row)
*/

getpost_ifset(array('months_compare', 'min_call', 'fromstatsday_sday', 'days_compare', 'fromstatsmonth_sday', 'dsttype', 'sourcetype', 'clidtype', 'channel', 'resulttype', 'dst', 'src', 'clid', 'userfieldtype', 'userfield', 'accountcodetype', 'accountcode'));

$FG_DEBUG = 0;
$months = Array ( 0 => 'Jan', 1 => 'Feb', 2 => 'Mar', 3 => 'Apr', 4 => 'May', 5 => 'Jun', 6 => 'Jul', 7 => 'Aug', 8 => 'Sep', 9 => 'Oct', 10 => 'Nov', 11 => 'Dec' );

if (!isset($months_compare)) $months_compare = 3;
if (!isset($fromstatsmonth_sday)) $fromstatsmonth_sday = date("Y-m");	



//print_r (array_reverse ($mylegend));

// http://localhost/Asterisk/asterisk-stat-v1_4/graph_stat.php?min_call=0&fromstatsday_sday=11&days_compare=2&fromstatsmonth_sday=2005-02&dsttype=1&sourcetype=1&clidtype=1&channel=&resulttype=&dst=1649&src=&clid=&userfieldtype=1&userfield=&accountcodetype=1&accountcode=

// The variable FG_TABLE_NAME define the table name to use
$FG_TABLE_NAME=DB_TABLENAME;

//$link = DbConnect();
$DBHandle  = DbConnect();

// The variable Var_col would define the col that we want show in your table
// First Name of the column in the html page, second name of the field
$FG_TABLE_COL = array();

/*******
Calldate Clid Src Dst Dcontext Channel Dstchannel Lastapp Lastdata Duration Billsec Disposition Amaflags Accountcode Uniqueid Serverid
*******/


// The variable LIMITE_DISPLAY define the limit of record to display by page
$FG_LIMITE_DISPLAY=100;

// Number of column in the html table
$FG_NB_TABLE_COL=count($FG_TABLE_COL);



$FG_COL_QUERY = ' sum(duration) ';
if ($FG_DEBUG == 3) echo "<br>Table : $FG_TABLE_NAME  	- 	Col_query : $FG_COL_QUERY";
$instance_table_graph = new Table($FG_TABLE_NAME, $FG_COL_QUERY);


if ( is_null ($order) || is_null($sens) ){
	$order = $FG_TABLE_DEFAULT_ORDER;
	$sens  = $FG_TABLE_DEFAULT_SENS;
}


	
  function do_field($sql,$fld){
  		$fldtype = $fld.'type';
		global $$fld;
		global $$fldtype;
        if (isset($$fld) && ($$fld!='')){
                if (strpos($sql,'WHERE') > 0){
                        $sql = "$sql AND ";
                }else{
                        $sql = "$sql WHERE ";
                }
				$sql = "$sql $fld";
				if (isset ($$fldtype)){                
                        switch ($$fldtype) {
							case 1:	$sql = "$sql='".$$fld."'";  break;
							case 2: $sql = "$sql LIKE '".$$fld."%'";  break;
							case 3: $sql = "$sql LIKE '%".$$fld."%'";  break;
							case 4: $sql = "$sql LIKE '%".$$fld."'";
						}
                }else{ $sql = "$sql LIKE '%".$$fld."%'"; }
		}
        return $sql;
  }  
  $SQLcmd = '';

  if ($_GET['before']) {
    if (strpos($SQLcmd, 'WHERE') > 0) { 	$SQLcmd = "$SQLcmd AND ";
    }else{     								$SQLcmd = "$SQLcmd WHERE "; }
    $SQLcmd = "$SQLcmd calldate<'".addslashes($_GET['before'])."'";
  }
  if ($_GET['after']) {    if (strpos($SQLcmd, 'WHERE') > 0) {      $SQLcmd = "$SQLcmd AND ";
  } else {      $SQLcmd = "$SQLcmd WHERE ";    }
    $SQLcmd = "$SQLcmd calldate>'".addslashes($_GET['after'])."'";
  }
  $SQLcmd = do_field($SQLcmd, 'clid');
  $SQLcmd = do_field($SQLcmd, 'src');
  $SQLcmd = do_field($SQLcmd, 'dst');
  $SQLcmd = do_field($SQLcmd, 'channel');
  
  $SQLcmd = do_field($SQLcmd, 'userfield');
  $SQLcmd = do_field($SQLcmd, 'accountcode');

$date_clause='';

$min_call= intval($min_call);
if (($min_call!=0) && ($min_call!=1)) $min_call=0;

if (!isset($fromstatsday_sday)){	
	$fromstatsday_sday = date("d");
	$fromstatsmonth_sday = date("Y-m");	
}

if (!isset($days_compare) ){		
	$days_compare=2;
}

 

list($myyear, $mymonth)= split ("-", $fromstatsmonth_sday);

$mymonth = $mymonth +1;
if ($mymonth==13) {
		$mymonth=1;		
		$myyear = $myyear + 1;
}


for ($i=0; $i<$months_compare+1; $i++){
	// creer un table legende	
	$current_mymonth = $mymonth -$i;
	if ($current_mymonth<=0) {
		$current_mymonth=$current_mymonth+12;		
		$minus_oneyar = 1;
	}
	$current_myyear = $myyear - $minus_oneyar;
	
	$current_mymonth2 = $mymonth -$i -1;
	if ($current_mymonth2<=0) {
		$current_mymonth2=$current_mymonth2+12;		
		$minus_oneyar = 1;
	}
	$current_myyear2 = $myyear - $minus_oneyar;

	//echo "<br>$current_myyear-".sprintf("%02d",intval($current_mymonth));
	
	
	
	
	//echo '<br>'.$date_clause;
	
	if (DB_TYPE == "postgres"){	
		$date_clause= " AND calldate >= '$current_myyear2-".sprintf("%02d",intval($current_mymonth2))."-01' AND calldate < '$current_myyear-".sprintf("%02d",intval($current_mymonth))."-01'";				
	}else{
		$date_clause= " AND calldate >= '$current_myyear2-".sprintf("%02d",intval($current_mymonth2))."-01' AND calldate < '$current_myyear-".sprintf("%02d",intval($current_mymonth))."-01'";		
	}
		
	  
	if (strpos($SQLcmd, 'WHERE') > 0) { 
		$FG_TABLE_CLAUSE = substr($SQLcmd,6).$date_clause; 
	}elseif (strpos($date_clause, 'AND') > 0){
		$FG_TABLE_CLAUSE = substr($date_clause,5); 
	}
	
	if ($FG_DEBUG == 3) echo $FG_TABLE_CLAUSE;
	
	/* --AMP BEGIN-- */
	//enforce restrictions for this AMP User
	session_start();
	$AMP_CLAUSE = $_SESSION['AMP_SQL'];
	if (!isset($AMP_CLAUSE)) {
		$AMP_CLAUSE = " AND src = 'NeverReturnAnything'";
	}
	$FG_TABLE_CLAUSE .= $AMP_CLAUSE;
	/* --AMP END-- */	
	
	$list_total = $instance_table_graph -> Get_list ($FG_TABLE_CLAUSE, null, null, null, null, null, null);
	$data[] = $list_total[0][0];	
	$mylegend[] = $months[$current_mymonth2-1]." $current_myyear : ".intval($list_total[0][0]/60)." min";

}
//print_r($data);

/**************************************/




//$data = array(40,60,21,33, 10, NULL);

$graph = new PieGraph(475,200,"auto");
$graph->SetShadow();

$graph->title->Set("Traffic Last $months_compare Months");
$graph->title->SetFont(FF_FONT1,FS_BOLD);

$p1 = new PiePlot3D($data);
$p1->ExplodeSlice(1);
$p1->SetCenter(0.35);
//print_r($gDateLocale->GetShortMonth());
//Array ( [0] => Jan [1] => Feb [2] => Mar [3] => Apr [4] => May [5] => Jun [6] => Jul [7] => Aug [8] => Sep [9] => Oct [10] => Nov [11] => Dec )
//$p1->SetLegends($gDateLocale->GetShortMonth());
$p1->SetLegends($mylegend);


// Format the legend box
$graph->legend->SetColor('navy');
$graph->legend->SetFillColor('gray@0.8');
$graph->legend->SetLineWeight(1);
//$graph->legend->SetFont(FF_ARIAL,FS_BOLD,8);
$graph->legend->SetShadow('gray@0.4',3);
//$graph->legend->SetAbsPos(10,80,'right','bottom');


$graph->Add($p1);
$graph->Stroke();




?>




See more files for this project here

freePBX

FreePBX is the most powerful GUI (Web Based) configuration tool for Asterisk. It provides everything that a standard legacy phone system can, plus a huge amount of new features. All documentation and information is avalable from http://www.freepbx.org

Project homepage: http://sourceforge.net/projects/amportal
Programming language(s): PHP,Shell Script,SQL
License: other

  css/
    images/
      corner-bl.png
      corner-br.png
      corner-tl.png
      corner-tr.png
    content.css
    docbook.css
    layout.css
  images/
    asterisk.gif
    btn_top_12x12.gif
    button-search.gif
    call-compare.png
    call-logs.png
    excel.png
    fleche-d.gif
    fleche-g.gif
    header-download.png
    header-faq.png
    header-projects.png
    header-search.png
    icon_down_12x12.GIF
    icon_up_12x12.GIF
    jukebox_ti60.gif
    pdf.png
    print.css
    printable.png
    sidenav-selected.gif
    spacer.gif
    th_call-compare.png
    th_call-logs.png
  jpgraph_lib/
    imgdata_balls.inc
    imgdata_bevels.inc
    imgdata_diamonds.inc
    imgdata_pushpins.inc
    imgdata_squares.inc
    imgdata_stars.inc
    jpg-config.inc
    jpgraph.php
    jpgraph_antispam-digits.php
    jpgraph_antispam.php
    jpgraph_bar.php
    jpgraph_canvas.php
    jpgraph_canvtools.php
    jpgraph_error.php
    jpgraph_flags.php
    jpgraph_gantt.php
    jpgraph_gb2312.php
    jpgraph_gradient.php
    jpgraph_iconplot.php
    jpgraph_imgtrans.php
    jpgraph_line.php
    jpgraph_log.php
    jpgraph_pie.php
    jpgraph_pie3d.php
    jpgraph_plotband.php
    jpgraph_plotmark.inc
    jpgraph_polar.php
    jpgraph_radar.php
    jpgraph_regstat.php
    jpgraph_scatter.php
    jpgraph_stock.php
  lib/
    DB-modules/
      ciaosql.php
      phplib_mssql.php
      phplib_mysql.php
      phplib_oci8.php
      phplib_odbc.php
      phplib_oracle.php
      phplib_postgres.php
      phplib_sybase.php
    font/
      makefont/
      courier.php
      helvetica.php
      helveticab.php
      helveticabi.php
      helveticai.php
      symbol.php
      times.php
      timesb.php
      timesbi.php
      timesi.php
      zapfdingbats.php
    Class.Table.php
    defines.php
    fpdf.php
    iam_csvdump.php
  CHANGELOG.txt
  about.php
  call-comp.php
  call-daily-load.php
  call-last-month.php
  call-log.php
  cdr.php
  counter.txt
  encrypt.js
  export_csv.php
  export_pdf.php
  graph_hourdetail.php
  graph_pie.php
  graph_stat.php
  graph_statbar.php
  info.txt