/** * Generate page * * @param iMSCP_pTemplate $tpl Template engine instance * @param int $userId User unique identifier * @return void */ function generatePage($tpl, $userId) { $stmt = exec_query(' SELECT admin_name, domain_id FROM admin INNER JOIN domain ON(domain_admin_id = admin_id) WHERE admin_id = ? ', $userId); if (!$stmt->rowCount()) { showBadRequestErrorPage(); } $row = $stmt->fetchRow(PDO::FETCH_ASSOC); $domainId = $row['domain_id']; $adminName = decode_idna($row['admin_name']); if (isset($_POST['month']) && isset($_POST['year'])) { $year = intval($_POST['year']); $month = intval($_POST['month']); } else { $month = date('m'); $year = date('y'); } $stmt = exec_query('SELECT dtraff_time FROM domain_traffic WHERE domain_id = ? ORDER BY dtraff_time ASC LIMIT 1', $domainId); if ($stmt->rowCount()) { $row = $stmt->fetchRow(PDO::FETCH_ASSOC); $numberYears = date('y') - date('y', $row['dtraff_time']); $numberYears = $numberYears ? $numberYears + 1 : 1; } else { $numberYears = 1; } generateMonthsAndYearsHtmlList($tpl, $month, $year, $numberYears); $stmt = exec_query('SELECT domain_id FROM domain_traffic WHERE domain_id = ? AND dtraff_time BETWEEN ? AND ? LIMIT 1', array($domainId, getFirstDayOfMonth($month, $year), getLastDayOfMonth($month, $year))); if ($stmt->rowCount()) { $requestedPeriod = getLastDayOfMonth($month, $year); $toDay = $requestedPeriod < time() ? date('j', $requestedPeriod) : date('j'); $all = array_fill(0, 8, 0); $dateFormat = iMSCP_Registry::get('config')->DATE_FORMAT; for ($fromDay = 1; $fromDay <= $toDay; $fromDay++) { $beginTime = mktime(0, 0, 0, $month, $fromDay, $year); $endTime = mktime(23, 59, 59, $month, $fromDay, $year); list($webTraffic, $ftpTraffic, $smtpTraffic, $popTraffic) = _getUserTraffic($domainId, $beginTime, $endTime); $tpl->assign(array('DATE' => date($dateFormat, strtotime($year . '-' . $month . '-' . $fromDay)), 'WEB_TRAFFIC' => tohtml(bytesHuman($webTraffic)), 'FTP_TRAFFIC' => tohtml(bytesHuman($ftpTraffic)), 'SMTP_TRAFFIC' => tohtml(bytesHuman($smtpTraffic)), 'POP3_TRAFFIC' => tohtml(bytesHuman($popTraffic)), 'ALL_TRAFFIC' => tohtml(bytesHuman($webTraffic + $ftpTraffic + $smtpTraffic + $popTraffic)))); $all[0] += $webTraffic; $all[1] += $ftpTraffic; $all[2] += $smtpTraffic; $all[3] += $popTraffic; $tpl->parse('TRAFFIC_TABLE_ITEM', '.traffic_table_item'); } $tpl->assign(array('USER_ID' => tohtml($userId), 'USERNAME' => tohtml($adminName), 'ALL_WEB_TRAFFIC' => tohtml(bytesHuman($all[0])), 'ALL_FTP_TRAFFIC' => tohtml(bytesHuman($all[1])), 'ALL_SMTP_TRAFFIC' => tohtml(bytesHuman($all[2])), 'ALL_POP3_TRAFFIC' => tohtml(bytesHuman($all[3])), 'ALL_ALL_TRAFFIC' => tohtml(bytesHuman(array_sum($all))))); } else { set_page_message(tr('No statistics found for the given period. Try another period.'), 'static_info'); $tpl->assign(array('USERNAME' => tohtml($adminName), 'USER_ID' => tohtml($userId), 'RESELLER_USER_STATISTICS_DETAIL_BLOCK' => '')); } }
/** * Generate statistics for the given period * * @param iMSCP_pTemplate $tpl Template engine instance * @return void */ function generatePage($tpl) { $domainId = get_user_domain_id($_SESSION['user_id']); if (isset($_POST['month']) && isset($_POST['year'])) { $year = intval($_POST['year']); $month = intval($_POST['month']); } else { if (isset($_GET['month']) && isset($_GET['year'])) { $month = intval($_GET['month']); $year = intval($_GET['year']); } else { $month = date('m'); $year = date('Y'); } } $stmt = exec_query('SELECT dtraff_time FROM domain_traffic WHERE domain_id = ? ORDER BY dtraff_time ASC LIMIT 1', $domainId); if ($stmt->rowCount()) { $row = $stmt->fetchRow(PDO::FETCH_ASSOC); $numberYears = date('y') - date('y', $row['dtraff_time']); $numberYears = $numberYears ? $numberYears + 1 : 1; } else { $numberYears = 1; } generateMonthsAndYearsHtmlList($tpl, $month, $year, $numberYears); $stmt = exec_query('SELECT domain_id FROM domain_traffic WHERE domain_id = ? AND dtraff_time >= ? AND dtraff_time <= ? LIMIT 1', array($domainId, getFirstDayOfMonth($month, $year), getLastDayOfMonth($month, $year))); if ($stmt->rowCount()) { $requestedPeriod = getLastDayOfMonth($month, $year); $toDay = $requestedPeriod < time() ? date('j', $requestedPeriod) : date('j'); $all = array_fill(0, 8, 0); $dateFormat = iMSCP_Registry::get('config')->DATE_FORMAT; for ($fromDay = 1; $fromDay <= $toDay; $fromDay++) { $beginTime = mktime(0, 0, 0, $month, $fromDay, $year); $endTime = mktime(23, 59, 59, $month, $fromDay, $year); list($webTraffic, $ftpTraffic, $smtpTraffic, $popTraffic) = _getUserTraffic($domainId, $beginTime, $endTime); $tpl->assign(array('DATE' => tohtml(date($dateFormat, strtotime($year . '-' . $month . '-' . $fromDay))), 'WEB_TRAFF' => tohtml(bytesHuman($webTraffic)), 'FTP_TRAFF' => tohtml(bytesHuman($ftpTraffic)), 'SMTP_TRAFF' => tohtml(bytesHuman($smtpTraffic)), 'POP_TRAFF' => tohtml(bytesHuman($popTraffic)), 'SUM_TRAFF' => tohtml(bytesHuman($webTraffic + $ftpTraffic + $smtpTraffic + $popTraffic)))); $all[0] += $webTraffic; $all[1] += $ftpTraffic; $all[2] += $smtpTraffic; $all[3] += $popTraffic; $tpl->parse('TRAFFIC_TABLE_ITEM', '.traffic_table_item'); } $tpl->assign(array('WEB_ALL' => tohtml(bytesHuman($all[0])), 'FTP_ALL' => tohtml(bytesHuman($all[1])), 'SMTP_ALL' => tohtml(bytesHuman($all[2])), 'POP_ALL' => tohtml(bytesHuman($all[3])), 'SUM_ALL' => tohtml(bytesHuman(array_sum($all))))); } else { set_page_message(tr('No statistics found for the given period. Try another period.'), 'static_info'); $tpl->assign('STATISTICS_BLOCK', ''); } }