<?php define("USE_GZIP", 1); require_once "overall.php"; $url = preg_replace('/\\?.*/s', '', $_SERVER['REQUEST_URI']); setSetting("index_url", ($_SERVER['SERVER_PORT'] == 443 ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $url); list($to, $back, $period) = parseToBackPeriod($_GET); $data = generateTableData($to, getSetting("cols", 30) + 1, $period, @$_GET['tag'], null, @$_GET['re']); $html = generateHtmlTableFromData($data); $SELECT_PERIODS = getPeriods(); $name = getSetting("instance"); template("index", array("title" => ($name ? $name . ": " : "") . $SELECT_PERIODS[$period] . " statistics for " . date("Y-m-d", trunkTime($to) - 1), "to" => $to, "htmlTable" => $html));
// // Command-line usage: // php sendmail.php [period] ['reName'] // define("NO_AUTH", 1); require_once "overall.php"; list($to, $back, $period) = parseToBackPeriod($_GET); if (isset($_SERVER['argv'][1])) { $period = $_SERVER['argv'][1]; } $onlyReName = null; if (isset($_SERVER['argv'][2])) { $onlyReName = $_SERVER['argv'][2]; } $to = trunkTime($to); // mail is always sent for WHOLE periods $emails = trim(getSetting('emails')); if ($period == 'month' && trim($emailsMonth = getSetting('emails_month'))) { $emails .= ($emails ? ", " : "") . $emailsMonth; } if (!$emails) { die("Please specify E-mails to send stats at Settings page!\n"); } // Generate the table data. $data = generateTableData($to, $back, $period, null, null, $onlyReName); // Remove archived rows. foreach ($data['groups'] as $gName => $gRows) { foreach ($gRows as $rName => $rInfo) { if ($rInfo['archived']) { unset($data['groups'][$gName][$rName]);
function parseToBackPeriod($arr, $wholeIntervalByDefault = false) { if (@$arr['to']) { $to = @strtotime($arr['to']); if (!$to) { throw new Exception("Invalid date format: {$arr['to']}"); } // ATTENTION! // If somebody enters "2010-05-02", he means "2010-05-02 23:59:59", not "2010-05-02 00:00:00". if ($to == trunkTime($to)) { $to = trunkTime($to + 3600 * 24) - 1; } } else { if ($wholeIntervalByDefault) { $to = trunkTime(time()) - 1; } else { $to = time(); } } $period = strlen(@$arr['period']) ? $arr['period'] : 'day'; $back = @$arr['back'] ? $arr['back'] : getSetting(isCgi() ? "cols" : "cols_email", 30) + 1; return array($to, $back, $period); }