コード例 #1
0
ファイル: plugin.php プロジェクト: precurse/netharbour
 function render_report()
 {
     if (isset($_GET['pid']) && is_numeric($_GET['pid'])) {
         $pid = $_GET['pid'];
     } else {
         return "<b>Sorry invalid profile id " . $_GET['pid'] . "</b>";
     }
     $profile_name = $this->get_accounting_profile_name($pid);
     // Menu bar
     $content .= "<div style='font-size:10px; font-weight:100px;'>\n\t\t\t<a href='{$this->url}'>Accounting</a> >> <a href='{$this->url}&pid={$pid}&action=show_accounting_profile'>{$profile_name}</a></div>";
     $content .= '<h2>Accounting Report</h2>';
     $from = $_GET[date1];
     $to = $_GET[date2];
     // Now render data
     $archives = '';
     $files = array();
     $query = "select accounting_sources.title, accounting_sources.scu_profile, \n\t\t\taccounting_sources.file \n\t\t\tFROM accounting_sources, accounting_profiles_files\n\t\t\tWHERE accounting_sources.id = accounting_profiles_files.accounting_source \n\t\t\tAND accounting_profiles_files.profile_id = '{$pid}' ";
     $result = mysql_query($query);
     if (!$result) {
         return "<b>Graph  information not found </b>";
     }
     while ($obj = mysql_fetch_object($result)) {
         $file = $obj->file;
         $title = $obj->title;
         $url2 .= "&RRA[accounting/{$file}]={$title}";
         array_push($files, "{$this->rrd_dir}/accounting/{$file}");
         $archives["{$this->rrd_dir}/accounting/{$file}"] = $title;
     }
     // Get summary
     list($year1, $month1, $day1) = split("-", $from);
     list($year2, $month2, $day2) = split("-", $to);
     $rrd_from = @mktime(0, 0, 0, $month1, $day1, $year1);
     #$rrd_from = "12am $month1/$day1/$year1";
     $rrd_to = @mktime(0, 0, 0, $month2, $day2, $year2);
     // -1 sec, so it aligns perfect
     $rrd_to = $rrd_to - 1;
     #print " $rrd_from  $rrd_to ->";
     #echo date("i:H M/d/Y",$rrd_from);
     if (!is_numeric($rrd_from)) {
         return "Invalid From date";
     }
     if (!is_numeric($rrd_to)) {
         return "Invalid To date";
     }
     $rrd_width = round(($rrd_to - $rrd_from) / 300) + 10;
     $rrd = new RRD($files, $this->rrdtool);
     $summary = $rrd->get_summary($rrd_from, $rrd_to, $archives);
     // Determine highest 95% number => Billing
     $billing_number = "N/A";
     $in_95 = $this->si_to_int($summary['95IN']);
     $out_95 = $this->si_to_int($summary['95OUT']);
     if ($in_95 > $out_95) {
         $billing_number = $summary['95IN'];
     } elseif ($out_95 >= $in_95) {
         $billing_number = $summary['95OUT'];
     }
     /* if ($summary{'95IN'} > $summary{'95OUT'}) {
     			$billing_number = $summary{'95IN'};
     		} elseif  ($summary{'95OUT'} > $summary{'95IN'}) {
     			$billing_number = $summary{'95OUT'};
     		} */
     $content .= "<p><form><b>Save this report as: </b><input type=hidden name=pid value={$pid}>\n\t\t\t\t<input type=hidden name=pluginID value=" . $_GET['pluginID'] . ">\n\t\t\t\t<input type=hidden name=tab value=" . $_GET['tab'] . ">\n\t\t\t\t<input type=hidden name=from value={$rrd_from}>\n\t\t\t\t<input type=hidden name=to value={$rrd_to}>\n\t\t\t\t<input type=hidden name=action value=save_report>\n\t\t\t\t<input type=text name=report_name id=report_name size='40'>";
     $content .= " <input type='submit' name='mysubmit' value='Save Report'></form></p> <br>  ";
     #$content.= "<a href='$url&action=save_report&pid=$pid&from=$rrd_from&to=$rrd_to'><b>Save Report</b></a>";
     $content .= "<table><th colspan=2><b>Reporting Period {$from} - {$to}</b></th><tr><td>";
     $content .= "<img src='rrdgraph.php?type=aggr_traf" . $url2 . "&title=Reporting Period {$from} - {$to}&height=150&width=700&from={$rrd_from}&to={$rrd_to}&showtotal=0'>";
     $content .= "</td><td valign='top'><b><center>Summary</b></center><br>";
     $content .= "<table valign='top'><tr><th></th><th>In</th><th>Out</th></tr>";
     $content .= "<tr><td>Average</td><td>" . $summary['AVERAGEIN'] . "bs</td><td>" . $summary['AVERAGEOUT'] . "bs</td></tr>";
     $content .= "<tr><td>Max</td><td>" . $summary['MAXIN'] . "bs</td><td>" . $summary['MAXOUT'] . "bs</td></tr>";
     $content .= "<tr><td>95th Percentile</td><td>" . $summary['95IN'] . "bs</td><td>" . $summary['95OUT'] . "bs</td></tr>";
     $content .= "<tr><td>Total</td><td>" . $summary['TOTALIN'] . "B</td><td>" . $summary['TOTALOUT'] . "B</td></tr>";
     $content .= "</table><hr><table>";
     $content .= "<tr><td>First Measurement <br>sample</td><td>" . $summary['FROM'] . "</td></tr>";
     $content .= "<tr><td>Last Measurement <br>sample</td><td>" . $summary['TO'] . "</td></tr>";
     $content .= "<tr><td><p>Total Traffic for <br>this accounting period</td><td>  " . $summary['TOTAL'] . "B</td></tr>";
     $content .= "<tr><td>Billed 95th% for <br>for this accounting period</td><td>  " . $billing_number . "bs</td></tr></table>";
     $content .= "</td></tr></table>";
     return $content;
 }