1<?php 2 3/** 4 * This file is part of the Froxlor project. 5 * Copyright (c) 2003-2009 the SysCP Team (see authors). 6 * Copyright (c) 2010 the Froxlor Team (see authors). 7 * 8 * For the full copyright and license information, please view the COPYING 9 * file that was distributed with this source code. You can also view the 10 * COPYING file online at http://files.froxlor.org/misc/COPYING.txt 11 * 12 * @copyright (c) the authors 13 * @author Florian Lippert <flo@syscp.org> (2003-2009) 14 * @author Froxlor team <team@froxlor.org> (2010-) 15 * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt 16 * @package Panel 17 * 18 */ 19 20define('AREA', 'customer'); 21$intrafficpage = 1; 22require './lib/init.php'; 23 24// redirect if this customer page is hidden via settings 25if (Settings::IsInList('panel.customer_hide_options','traffic')) { 26 redirectTo('customer_index.php'); 27} 28 29$traffic = ''; 30$month = null; 31$year = null; 32 33if (isset($_POST['month']) && isset($_POST['year'])) { 34 $month = intval($_POST['month']); 35 $year = intval($_POST['year']); 36} elseif (isset($_GET['month']) && isset($_GET['year'])) { 37 $month = intval($_GET['month']); 38 $year = intval($_GET['year']); 39} 40//BAM! $_GET??? 41elseif (isset($_GET['page']) && $_GET['page'] == 'current') { 42 if (date('d') != '01') { 43 $month = date('m'); 44 $year = date('Y'); 45 } else { 46 if (date('m') == '01') { 47 $month = 12; 48 $year = date('Y') - 1; 49 } else { 50 $month = date('m') - 1; 51 $year = date('Y'); 52 } 53 } 54} 55 56if (!is_null($month) && !is_null($year)) { 57 $traf['byte'] = 0; 58 $result_stmt = Database::prepare("SELECT SUM(`http`) as 'http', SUM(`ftp_up`) AS 'ftp_up', SUM(`ftp_down`) as 'ftp_down', SUM(`mail`) as 'mail', `day`, `month`, `year` 59 FROM `" . TABLE_PANEL_TRAFFIC . "` 60 WHERE `customerid`= :customerid 61 AND `month` = :month 62 AND `year` = :year 63 GROUP BY `day` 64 ORDER BY `day` DESC" 65 ); 66 $params = array( 67 "customerid" => $userinfo['customerid'], 68 "month" => $month, 69 "year" => $year 70 ); 71 Database::pexecute($result_stmt, $params); 72 $traffic_complete['http'] = 0; 73 $traffic_complete['ftp'] = 0; 74 $traffic_complete['mail'] = 0; 75 $show = ''; 76 77 while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { 78 $http = $row['http']; 79 $ftp = $row['ftp_up'] + $row['ftp_down']; 80 $mail = $row['mail']; 81 $traf['byte'] = $http + $ftp + $mail; 82 $traffic_complete['http'] += $http; 83 $traffic_complete['ftp'] += $ftp; 84 $traffic_complete['mail'] += $mail; 85 $traf['day'] = $row['day'] . '.'; 86 87 if (extension_loaded('bcmath')) { 88 $traf['ftptext'] = bcdiv($row['ftp_up'], 1024, Settings::Get('panel.decimal_places')) . " MiB up/ " . bcdiv($row['ftp_down'], 1024, Settings::Get('panel.decimal_places')) . " MiB down (FTP)"; 89 $traf['httptext'] = bcdiv($http, 1024, Settings::Get('panel.decimal_places')) . " MiB (HTTP)"; 90 $traf['mailtext'] = bcdiv($mail, 1024, Settings::Get('panel.decimal_places')) . " MiB (Mail)"; 91 $traf['ftp'] = bcdiv($ftp, 1024, Settings::Get('panel.decimal_places')); 92 $traf['http'] = bcdiv($http, 1024, Settings::Get('panel.decimal_places')); 93 $traf['mail'] = bcdiv($mail, 1024, Settings::Get('panel.decimal_places')); 94 $traf['byte'] = bcdiv($traf['byte'], 1024, Settings::Get('panel.decimal_places')); 95 } else { 96 $traf['ftptext'] = round($row['ftp_up'] / 1024, Settings::Get('panel.decimal_places')) . " MiB up/ " . round($row['ftp_down'] / 1024, Settings::Get('panel.decimal_places')) . " MiB down (FTP)"; 97 $traf['httptext'] = round($http / 1024, Settings::Get('panel.decimal_places')) . " MiB (HTTP)"; 98 $traf['mailtext'] = round($mail / 1024, Settings::Get('panel.decimal_places')) . " MiB (Mail)"; 99 $traf['http'] = round($http, Settings::Get('panel.decimal_places')); 100 $traf['ftp'] = round($ftp, Settings::Get('panel.decimal_places')); 101 $traf['mail'] = round($mail, Settings::Get('panel.decimal_places')); 102 $traf['byte'] = round($traf['byte'] / 1024, Settings::Get('panel.decimal_places')); 103 } 104 105 eval("\$traffic.=\"" . getTemplate('traffic/traffic_month') . "\";"); 106 $show = $lng['traffic']['months'][intval($row['month'])] . ' ' . $row['year']; 107 } 108 109 $traffic_complete['http'] = size_readable($traffic_complete['http'] * 1024, 'GiB', 'bi', '%01.'.(int)Settings::Get('panel.decimal_places').'f %s'); 110 $traffic_complete['ftp'] = size_readable($traffic_complete['ftp'] * 1024, 'GiB', 'bi', '%01.'.(int)Settings::Get('panel.decimal_places').'f %s'); 111 $traffic_complete['mail'] = size_readable($traffic_complete['mail'] * 1024, 'GiB', 'bi', '%01.'.(int)Settings::Get('panel.decimal_places').'f %s'); 112 113 eval("echo \"" . getTemplate('traffic/traffic_details') . "\";"); 114} else { 115 $result_stmt = Database::prepare("SELECT `month`, `year`, SUM(`http`) AS http, SUM(`ftp_up`) AS ftp_up, SUM(`ftp_down`) AS ftp_down, SUM(`mail`) AS mail 116 FROM `" . TABLE_PANEL_TRAFFIC . "` 117 WHERE `customerid` = :customerid 118 GROUP BY `year` DESC, `month` DESC 119 LIMIT 12" 120 ); 121 Database::pexecute($result_stmt, array("customerid" => $userinfo['customerid'])); 122 $traffic_complete['http'] = 0; 123 $traffic_complete['ftp'] = 0; 124 $traffic_complete['mail'] = 0; 125 126 while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { 127 $http = $row['http']; 128 $ftp_up = $row['ftp_up']; 129 $ftp_down = $row['ftp_down']; 130 $mail = $row['mail']; 131 $traffic_complete['http'] += $http; 132 $traffic_complete['ftp'] += $ftp_up + $ftp_down; 133 $traffic_complete['mail'] += $mail; 134 $traf['month'] = $row['month']; 135 $traf['year'] = $row['year']; 136 $traf['monthname'] = $lng['traffic']['months'][intval($row['month'])] . " " . $row['year']; 137 $traf['byte'] = $http + $ftp_up + $ftp_down + $mail; 138 139 if (extension_loaded('bcmath')) { 140 $traf['ftptext'] = bcdiv($ftp_up, 1024, Settings::Get('panel.decimal_places')) . " MiB up/ " . bcdiv($ftp_down, 1024, Settings::Get('panel.decimal_places')) . " MiB down (FTP)"; 141 $traf['httptext'] = bcdiv($http, 1024, Settings::Get('panel.decimal_places')) . " MiB (HTTP)"; 142 $traf['mailtext'] = bcdiv($mail, 1024, Settings::Get('panel.decimal_places')) . " MiB (Mail)"; 143 $traf['ftp'] = bcdiv(($ftp_up + $ftp_down), 1024, Settings::Get('panel.decimal_places')); 144 $traf['http'] = bcdiv($http, 1024, Settings::Get('panel.decimal_places')); 145 $traf['mail'] = bcdiv($mail, 1024, Settings::Get('panel.decimal_places')); 146 $traf['byte'] = bcdiv($traf['byte'], 1024 * 1024, Settings::Get('panel.decimal_places')); 147 } else { 148 $traf['ftptext'] = round($ftp_up / 1024, Settings::Get('panel.decimal_places')) . " MiB up/ " . round($ftp_down / 1024, Settings::Get('panel.decimal_places')) . " MiB down (FTP)"; 149 $traf['httptext'] = round($http / 1024, Settings::Get('panel.decimal_places')) . " MiB (HTTP)"; 150 $traf['mailtext'] = round($mail / 1024, Settings::Get('panel.decimal_places')) . " MiB (Mail)"; 151 $traf['ftp'] = round(($ftp_up + $ftp_down) / 1024, Settings::Get('panel.decimal_places')); 152 $traf['http'] = round($http / 1024, Settings::Get('panel.decimal_places')); 153 $traf['mail'] = round($mail / 1024, Settings::Get('panel.decimal_places')); 154 $traf['byte'] = round($traf['byte'] / (1024 * 1024), Settings::Get('panel.decimal_places')); 155 } 156 157 eval("\$traffic.=\"" . getTemplate('traffic/traffic_traffic') . "\";"); 158 } 159 160 $traffic_complete['http'] = size_readable($traffic_complete['http'] * 1024, 'GiB', 'bi', '%01.'.(int)Settings::Get('panel.decimal_places').'f %s'); 161 $traffic_complete['ftp'] = size_readable($traffic_complete['ftp'] * 1024, 'GiB', 'bi', '%01.'.(int)Settings::Get('panel.decimal_places').'f %s'); 162 $traffic_complete['mail'] = size_readable($traffic_complete['mail'] * 1024, 'GiB', 'bi', '%01.'.(int)Settings::Get('panel.decimal_places').'f %s'); 163 164 eval("echo \"" . getTemplate('traffic/traffic') . "\";"); 165} 166