root/freepbx/trunk/amp_conf/htdocs/admin/cdr/graph_pie.php

Revision 5360, 6.9 kB (checked in by p_lindheimer, 6 years ago)

#2484 CDR Reports SOURCE column was not differntiating it's search for the differnt radio button choices, everything was 'LIKE %<pattern>% - changed sourcetype to srctype across the entire application to fix (it depends on the src part of srctype to be the table field name - pretty ugly

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $Id$ */
2 include_once(dirname(__FILE__) . "/lib/defines.php");
3 include_once(dirname(__FILE__) . "/lib/Class.Table.php");
4 include_once(dirname(__FILE__) . "/jpgraph_lib/jpgraph.php");
5 include_once(dirname(__FILE__) . "/jpgraph_lib/jpgraph_pie.php");
6 include_once(dirname(__FILE__) . "/jpgraph_lib/jpgraph_pie3d.php");
7
8
9 /*
10 NOTE GENERER LES SOUSTRACTIONS SUR LES DATES NOUS-MEME
11 RAPIDE
12 cdrasterisk=> SELECT sum(duration) FROM cdr WHERE calldate < '2005-02-01' AND calldate >= '2005-01-01';
13    sum
14 ----------
15  69076793
16 (1 row)
17  
18  TRES LENT
19 cdrasterisk=> SELECT sum(duration) FROM cdr WHERE calldate < date '2005-02-01'  - interval '0 months' AND calldate >=  date '2005-02-01'  - interval '1 months' ;
20    sum
21 ----------
22  69076793
23 (1 row)
24 */
25
26 getpost_ifset(array('months_compare', 'min_call', 'fromstatsday_sday', 'days_compare', 'fromstatsmonth_sday', 'dsttype', 'srctype', 'clidtype', 'channel', 'resulttype', 'dst', 'src', 'clid', 'userfieldtype', 'userfield', 'accountcodetype', 'accountcode'));
27
28 $FG_DEBUG = 0;
29 $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' );
30
31 if (!isset($months_compare)) $months_compare = 3;
32 if (!isset($fromstatsmonth_sday)) $fromstatsmonth_sday = date("Y-m");   
33
34
35
36 //print_r (array_reverse ($mylegend));
37
38 // 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&srctype=1&clidtype=1&channel=&resulttype=&dst=1649&src=&clid=&userfieldtype=1&userfield=&accountcodetype=1&accountcode=
39
40 // The variable FG_TABLE_NAME define the table name to use
41 $FG_TABLE_NAME=DB_TABLENAME;
42
43 //$link = DbConnect();
44 $DBHandle  = DbConnect();
45
46 // The variable Var_col would define the col that we want show in your table
47 // First Name of the column in the html page, second name of the field
48 $FG_TABLE_COL = array();
49
50 /*******
51 Calldate Clid Src Dst Dcontext Channel Dstchannel Lastapp Lastdata Duration Billsec Disposition Amaflags Accountcode Uniqueid Serverid
52 *******/
53
54
55 // The variable LIMITE_DISPLAY define the limit of record to display by page
56 $FG_LIMITE_DISPLAY=100;
57
58 // Number of column in the html table
59 $FG_NB_TABLE_COL=count($FG_TABLE_COL);
60
61
62
63 $FG_COL_QUERY = ' sum(duration) ';
64 if ($FG_DEBUG == 3) echo "<br>Table : $FG_TABLE_NAME      -     Col_query : $FG_COL_QUERY";
65 $instance_table_graph = new Table($FG_TABLE_NAME, $FG_COL_QUERY);
66
67
68 if ( is_null ($order) || is_null($sens) ){
69     $order = $FG_TABLE_DEFAULT_ORDER;
70     $sens  = $FG_TABLE_DEFAULT_SENS;
71 }
72
73
74     
75   function do_field($sql,$fld){
76           $fldtype = $fld.'type';
77         global $$fld;
78         global $$fldtype;
79         if (isset($$fld) && ($$fld!='')){
80                 if (strpos($sql,'WHERE') > 0){
81                         $sql = "$sql AND ";
82                 }else{
83                         $sql = "$sql WHERE ";
84                 }
85                 $sql = "$sql $fld";
86                 if (isset ($$fldtype)){               
87                         switch ($$fldtype) {
88                             case 1:    $sql = "$sql='".$$fld."'";  break;
89                             case 2: $sql = "$sql LIKE '".$$fld."%'";  break;
90                             case 3: $sql = "$sql LIKE '%".$$fld."%'";  break;
91                             case 4: $sql = "$sql LIKE '%".$$fld."'";
92                         }
93                 }else{ $sql = "$sql LIKE '%".$$fld."%'"; }
94         }
95         return $sql;
96   } 
97   $SQLcmd = '';
98
99   if ($_GET['before']) {
100     if (strpos($SQLcmd, 'WHERE') > 0) {     $SQLcmd = "$SQLcmd AND ";
101     }else{                                     $SQLcmd = "$SQLcmd WHERE "; }
102     $SQLcmd = "$SQLcmd calldate<'".addslashes($_GET['before'])."'";
103   }
104   if ($_GET['after']) {    if (strpos($SQLcmd, 'WHERE') > 0) {      $SQLcmd = "$SQLcmd AND ";
105   } else {      $SQLcmd = "$SQLcmd WHERE ";    }
106     $SQLcmd = "$SQLcmd calldate>'".addslashes($_GET['after'])."'";
107   }
108   $SQLcmd = do_field($SQLcmd, 'clid');
109   $SQLcmd = do_field($SQLcmd, 'src');
110   $SQLcmd = do_field($SQLcmd, 'dst');
111   $SQLcmd = do_field($SQLcmd, 'channel');
112  
113   $SQLcmd = do_field($SQLcmd, 'userfield');
114   $SQLcmd = do_field($SQLcmd, 'accountcode');
115
116 $date_clause='';
117
118 $min_call= intval($min_call);
119 if (($min_call!=0) && ($min_call!=1)) $min_call=0;
120
121 if (!isset($fromstatsday_sday)){   
122     $fromstatsday_sday = date("d");
123     $fromstatsmonth_sday = date("Y-m");   
124 }
125
126 if (!isset($days_compare) ){       
127     $days_compare=2;
128 }
129
130  
131
132 list($myyear, $mymonth)= split ("-", $fromstatsmonth_sday);
133
134 $mymonth = $mymonth +1;
135 if ($mymonth==13) {
136         $mymonth=1;       
137         $myyear = $myyear + 1;
138 }
139
140
141 for ($i=0; $i<$months_compare+1; $i++){
142     // creer un table legende   
143     $current_mymonth = $mymonth -$i;
144     if ($current_mymonth<=0) {
145         $current_mymonth=$current_mymonth+12;       
146         $minus_oneyar = 1;
147     }
148     $current_myyear = $myyear - $minus_oneyar;
149     
150     $current_mymonth2 = $mymonth -$i -1;
151     if ($current_mymonth2<=0) {
152         $current_mymonth2=$current_mymonth2+12;       
153         $minus_oneyar = 1;
154     }
155     $current_myyear2 = $myyear - $minus_oneyar;
156
157     //echo "<br>$current_myyear-".sprintf("%02d",intval($current_mymonth));
158     
159     
160     
161     
162     //echo '<br>'.$date_clause;
163     
164     if (DB_TYPE == "postgres"){   
165         $date_clause= " AND calldate >= '$current_myyear2-".sprintf("%02d",intval($current_mymonth2))."-01' AND calldate < '$current_myyear-".sprintf("%02d",intval($current_mymonth))."-01'";               
166     }else{
167         $date_clause= " AND calldate >= '$current_myyear2-".sprintf("%02d",intval($current_mymonth2))."-01' AND calldate < '$current_myyear-".sprintf("%02d",intval($current_mymonth))."-01'";       
168     }
169         
170       
171     if (strpos($SQLcmd, 'WHERE') > 0) {
172         $FG_TABLE_CLAUSE = substr($SQLcmd,6).$date_clause;
173     }elseif (strpos($date_clause, 'AND') > 0){
174         $FG_TABLE_CLAUSE = substr($date_clause,5);
175     }
176     
177     if ($FG_DEBUG == 3) echo $FG_TABLE_CLAUSE;
178     
179     /* --AMP BEGIN-- */
180     //enforce restrictions for this AMP User
181     session_start();
182     $AMP_CLAUSE = $_SESSION['AMP_SQL'];
183     if (!isset($AMP_CLAUSE)) {
184         $AMP_CLAUSE = " AND src = 'NeverReturnAnything'";
185     }
186     $FG_TABLE_CLAUSE .= $AMP_CLAUSE;
187     /* --AMP END-- */   
188     
189     $list_total = $instance_table_graph -> Get_list ($FG_TABLE_CLAUSE, null, null, null, null, null, null);
190     $data[] = $list_total[0][0];   
191     $mylegend[] = $months[$current_mymonth2-1]." $current_myyear : ".intval($list_total[0][0]/60)." min";
192
193 }
194 //print_r($data);
195
196 /**************************************/
197
198
199
200
201 //$data = array(40,60,21,33, 10, NULL);
202
203 $graph = new PieGraph(475,200,"auto");
204 $graph->SetShadow();
205
206 $graph->title->Set("Traffic Last $months_compare Months");
207 $graph->title->SetFont(FF_FONT1,FS_BOLD);
208
209 $p1 = new PiePlot3D($data);
210 $p1->ExplodeSlice(1);
211 $p1->SetCenter(0.35);
212 //print_r($gDateLocale->GetShortMonth());
213 //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 )
214 //$p1->SetLegends($gDateLocale->GetShortMonth());
215 $p1->SetLegends($mylegend);
216
217
218 // Format the legend box
219 $graph->legend->SetColor('navy');
220 $graph->legend->SetFillColor('gray@0.8');
221 $graph->legend->SetLineWeight(1);
222 //$graph->legend->SetFont(FF_ARIAL,FS_BOLD,8);
223 $graph->legend->SetShadow('gray@0.4',3);
224 //$graph->legend->SetAbsPos(10,80,'right','bottom');
225
226
227 $graph->Add($p1);
228 $graph->Stroke();
229
230
231
232
233 ?>
234
Note: See TracBrowser for help on using the browser.