/** * @param int $month * @param int $year */ function generate_page($month, $year) { $tpl = EasySCP_TemplateEngine::getInstance(); $sql = EasySCP_Registry::get('Db'); if ($month == date('m') && $year == date('Y')) { $curday = date('j'); } else { $tmp = mktime(1, 0, 0, $month + 1, 0, $year); $curday = date('j', $tmp); } $all[0] = 0; $all[1] = 0; $all[2] = 0; $all[3] = 0; $all[4] = 0; $all[5] = 0; $all[6] = 0; $all[7] = 0; for ($i = 1; $i <= $curday; $i++) { $ftm = mktime(0, 0, 0, $month, $i, $year); $ltm = mktime(0, 0, 0, $month, $i + 1, $year); $query = "\n\t\t\tSELECT\n\t\t\t\tCOUNT(`bytes_in`) AS cnt\n\t\t\tFROM\n\t\t\t\t`server_traffic`\n\t\t\tWHERE\n\t\t\t\t`traff_time` > ? AND `traff_time` <= ?\n\t\t"; $rs = exec_query($sql, $query, array($ftm, $ltm)); // if ($rs->fields['cnt'] > 0) { if ($rs->recordCount() > 0) { list($web_in, $web_out, $smtp_in, $smtp_out, $pop_in, $pop_out, $other_in, $other_out, $all_in, $all_out) = get_server_trafic($ftm, $ltm); $tpl->append(array('DAY' => $i, 'YEAR' => $year, 'MONTH' => $month, 'WEB_IN' => sizeit($web_in), 'WEB_OUT' => sizeit($web_out), 'SMTP_IN' => sizeit($smtp_in), 'SMTP_OUT' => sizeit($smtp_out), 'POP_IN' => sizeit($pop_in), 'POP_OUT' => sizeit($pop_out), 'OTHER_IN' => sizeit($other_in), 'OTHER_OUT' => sizeit($other_out), 'ALL_IN' => sizeit($all_in), 'ALL_OUT' => sizeit($all_out), 'ALL' => sizeit($all_in + $all_out))); $all[0] = $all[0] + $web_in; $all[1] = $all[1] + $web_out; $all[2] = $all[2] + $smtp_in; $all[3] = $all[3] + $smtp_out; $all[4] = $all[4] + $pop_in; $all[5] = $all[5] + $pop_out; $all[6] = $all[6] + $all_in; $all[7] = $all[7] + $all_out; } // if count } // end for $all_other_in = $all[6] - ($all[0] + $all[2] + $all[4]); $all_other_out = $all[7] - ($all[1] + $all[3] + $all[5]); $tpl->assign(array('WEB_IN_ALL' => sizeit($all[0]), 'WEB_OUT_ALL' => sizeit($all[1]), 'SMTP_IN_ALL' => sizeit($all[2]), 'SMTP_OUT_ALL' => sizeit($all[3]), 'POP_IN_ALL' => sizeit($all[4]), 'POP_OUT_ALL' => sizeit($all[5]), 'OTHER_IN_ALL' => sizeit($all_other_in), 'OTHER_OUT_ALL' => sizeit($all_other_out), 'ALL_IN_ALL' => sizeit($all[6]), 'ALL_OUT_ALL' => sizeit($all[7]), 'ALL_ALL' => sizeit($all[6] + $all[7]))); }
function generate_page(&$tpl) { global $sql, $month, $year; if ($month == date('m') && $year == date('Y')) { $curday = date('j'); } else { $tmp = mktime(1, 0, 0, $month + 1, 0, $year); $curday = date('j', $tmp); } $curtimestamp = time(); $firsttimestamp = mktime(0, 0, 0, $month, 1, $year); $all[0] = 0; $all[1] = 0; $all[2] = 0; $all[3] = 0; $all[4] = 0; $all[5] = 0; $all[6] = 0; $all[7] = 0; for ($i = 1; $i <= $curday; $i++) { $ftm = mktime(0, 0, 0, $month, $i, $year); $ltm = mktime(23, 59, 59, $month, $i, $year); $query = <<<SQL_QUERY select count(bytes_in) as cnt from server_traffic where traff_time > ? and traff_time < ? SQL_QUERY; $rs = exec_query($sql, $query, array($ftm, $ltm)); $has_data = false; // if ($rs -> fields['cnt'] > 0) { if ($rs->RecordCount() > 0) { list($web_in, $web_out, $mail_in, $mail_out, $pop_in, $pop_out, $other_in, $other_out, $all_in, $all_out) = get_server_trafic($ftm, $ltm); $has_data = true; if ($i % 2 == 0) { $tpl->assign('ITEM_CLASS', 'content'); } else { $tpl->assign('ITEM_CLASS', 'content2'); } $tpl->assign(array('DAY' => $i, 'YEAR' => $year, 'MONTH' => $month, 'WEB_IN' => make_hr($web_in), 'WEB_OUT' => make_hr($web_out), 'MAIL_IN' => make_hr($mail_in), 'MAIL_OUT' => make_hr($mail_out), 'POP_IN' => make_hr($pop_in), 'POP_OUT' => make_hr($pop_out), 'OTHER_IN' => make_hr($other_in), 'OTHER_OUT' => make_hr($other_out), 'ALL_IN' => make_hr($all_in), 'ALL_OUT' => make_hr($all_out), 'ALL' => make_hr($all_in + $all_out))); $all[0] = $all[0] + $web_in; $all[1] = $all[1] + $web_out; $all[2] = $all[2] + $mail_in; $all[3] = $all[3] + $mail_out; $all[4] = $all[4] + $pop_in; $all[5] = $all[5] + $pop_out; $all[6] = $all[6] + $all_in; $all[7] = $all[7] + $all_out; $tpl->parse('DAY_LIST', '.day_list'); } // if count } //for if (!$has_data) { $tpl->assign('DAY_LIST', ''); } $all_other_in = $all[6] - ($all[0] + $all[2] + $all[4]); $all_other_out = $all[7] - ($all[1] + $all[3] + $all[5]); $tpl->assign(array('WEB_IN_ALL' => make_hr($all[0]), 'WEB_OUT_ALL' => make_hr($all[1]), 'MAIL_IN_ALL' => make_hr($all[2]), 'MAIL_OUT_ALL' => make_hr($all[3]), 'POP_IN_ALL' => make_hr($all[4]), 'POP_OUT_ALL' => make_hr($all[5]), 'OTHER_IN_ALL' => make_hr($all_other_in), 'OTHER_OUT_ALL' => make_hr($all_other_out), 'ALL_IN_ALL' => make_hr($all[6]), 'ALL_OUT_ALL' => make_hr($all[7]), 'ALL_ALL' => make_hr($all[6] + $all[7]))); }