📄 ad_statistics.php
字号:
<?php
class ad_stats
{
var $base_url;
var $month_names = array( );
function ad_stats( )
{
global $IN;
global $INFO;
global $DB;
global $SKIN;
global $ADMIN;
global $std;
global $MEMBER;
global $GROUP;
$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
foreach ( $tmp_in as $k => $v )
{
}
$this->month_names = array( 1 => "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" );
switch ( $IN['code'] )
{
case "show_reg" :
$this->result_screen( "reg" );
break;
case "show_topic" :
$this->result_screen( "topic" );
break;
case "topic" :
$this->main_screen( "topic" );
break;
case "show_post" :
$this->result_screen( "post" );
break;
case "post" :
$this->main_screen( "post" );
break;
case "show_msg" :
$this->result_screen( "msg" );
break;
case "msg" :
$this->main_screen( "msg" );
break;
case "show_views" :
$this->show_views( );
break;
case "views" :
$this->main_screen( "views" );
break;
default :
$this->main_screen( "reg" );
break;
}
}
function show_views( )
{
global $IN;
global $INFO;
global $DB;
global $SKIN;
global $ADMIN;
global $std;
global $MEMBER;
global $GROUP;
$ADMIN->page_title = "论坛统计中心";
$ADMIN->page_detail = "主题查看统计";
if ( !checkdate( $IN['to_month'], $IN['to_day'], $IN['to_year'] ) )
{
$ADMIN->error( "统计'结束日期:'选项不正确,请检查你的输入后再试!" );
}
if ( !checkdate( $IN['from_month'], $IN['from_day'], $IN['from_year'] ) )
{
$ADMIN->error( "统计'开始日期:'选项不正确,请检查你的输入后再试!" );
}
$to_time = mktime( 12, 0, 0, $IN['to_month'], $IN['to_day'], $IN['to_year'] );
$from_time = mktime( 12, 0, 0, $IN['from_month'], $IN['from_day'], $IN['from_year'] );
$human_to_date = getdate( $to_time );
$human_from_date = getdate( $from_time );
$DB->query( "SELECT SUM(t.views) as result_count, t.forum_id, f.name as result_name\n\t\t\t\t FROM ibf_topics t, ibf_forums f\n\t\t\t\t WHERE t.start_date > '{$from_time}'\n\t\t\t\t AND t.start_date < '{$to_time}'\n\t\t\t\t AND t.forum_id=f.id\n\t\t\t\t GROUP BY t.forum_id\n\t\t\t\t ORDER BY result_count {$IN['sortby']}" );
$running_total = 0;
$max_result = 0;
$results = array( );
$SKIN->td_header[] = array( "论坛栏目名称", "40%" );
$SKIN->td_header[] = array( "统计结果", "50%" );
$SKIN->td_header[] = array( "主题查看", "10%" );
$ADMIN->html .= $SKIN->start_table( "主题查看统计"."({$human_from_date['year']}年 {$this->month_names[$human_from_date['mon']]} {$human_from_date['mday']}日 - "."{$human_to_date['year']}年 {$this->month_names[$human_to_date['mon']]} {$human_to_date['mday']}日)" );
if ( $DB->get_num_rows( ) )
{
while ( $row = $DB->fetch_row( ) )
{
if ( $max_result < $row['result_count'] )
{
$max_result = $row['result_count'];
}
$running_total += $row['result_count'];
$results[] = array(
"result_name" => $row['result_name'],
"result_count" => $row['result_count']
);
}
foreach ( $results as $pOOp => $data )
{
$img_width = intval( $data['result_count'] / $max_result * 100 - 8 );
if ( $img_width < 1 )
{
$img_width = 1;
}
$img_width .= "%";
$ADMIN->html .= $SKIN->add_td_row( array(
$data['result_name'],
"<img src='{$SKIN->img_url}/bar_left.gif' border='0' width='4' height='11' align='middle' alt=''><img src='{$SKIN->img_url}/bar.gif' border='0' width='{$img_width}' height='11' align='middle' alt=''><img src='{$SKIN->img_url}/bar_right.gif' border='0' width='4' height='11' align='middle' alt=''>",
"<center>".$data['result_count']."</center>"
) );
}
$ADMIN->html .= $SKIN->add_td_row( array(
" ",
"<div align='right'><b>总计:</b></div>",
"<center><b>".$running_total."</b></center>"
) );
}
else
{
$ADMIN->html .= $SKIN->add_td_basic( "没有找到统计数据", "center" );
}
$ADMIN->html .= $SKIN->end_table( );
$ADMIN->output( );
}
function result_screen( $mode = "reg" )
{
global $IN;
global $INFO;
global $DB;
global $SKIN;
global $ADMIN;
global $std;
global $MEMBER;
global $GROUP;
$ADMIN->page_title = "论坛统计中心";
$ADMIN->page_detail = " ";
if ( !checkdate( $IN['to_month'], $IN['to_day'], $IN['to_year'] ) )
{
$ADMIN->error( "统计'结束日期:'选项不正确,请检查你的输入后再试!" );
}
if ( !checkdate( $IN['from_month'], $IN['from_day'], $IN['from_year'] ) )
{
$ADMIN->error( "统计'开始日期:'选项不正确,请检查你的输入后再试!" );
}
$to_time = mktime( 12, 0, 0, $IN['to_month'], $IN['to_day'], $IN['to_year'] );
$from_time = mktime( 12, 0, 0, $IN['from_month'], $IN['from_day'], $IN['from_year'] );
$human_to_date = getdate( $to_time );
$human_from_date = getdate( $from_time );
if ( $mode == "reg" )
{
$table = "用户注册统计";
$sql_table = "ibf_members";
$sql_field = "joined";
$ADMIN->page_detail = "显示用户注册统计数据(注意:所有时间都是基于 GMT 标准时间)";
}
else if ( $mode == "topic" )
{
$table = "主题发表统计";
$sql_table = "ibf_topics";
$sql_field = "start_date";
$ADMIN->page_detail = "显示主题发表统计数据(注意:所有时间都是基于 GMT 标准时间)";
}
else if ( $mode == "post" )
{
$table = "主题回复统计";
$sql_table = "ibf_posts";
$sql_field = "post_date";
$ADMIN->page_detail = "显示主题回复统计数据(注意:所有时间都是基于 GMT 标准时间)";
}
else if ( $mode == "msg" )
{
$table = "短信发送统计";
$sql_table = "ibf_messages";
$sql_field = "msg_date";
$ADMIN->page_detail = "显示短信发送统计数据(注意:所有时间都是基于 GMT 标准时间)";
}
switch ( $IN['timescale'] )
{
case "daily" :
$sql_date = "%w %U %m %Y";
$php_date = "F jS - Y";
break;
case "monthly" :
$sql_date = "%m %Y";
$php_date = "F Y";
break;
default :
$sql_date = "%U %Y";
$php_date = " [F Y]";
break;
}
$DB->query( "SELECT MAX({$sql_field}) as result_maxdate,\n\t\t\t\t COUNT(*) as result_count,\n\t\t\t\t DATE_FORMAT(from_unixtime({$sql_field}),'{$sql_date}') AS result_time\n\t\t\t\t FROM {$sql_table}\n\t\t\t\t WHERE {$sql_field} > '{$from_time}'\n\t\t\t\t AND {$sql_field} < '{$to_time}'\n\t\t\t\t GROUP BY result_time\n\t\t\t\t ORDER BY {$sql_field} {$IN['sortby']}" );
$running_total = 0;
$max_result = 0;
$results = array( );
$SKIN->td_header[] = array( "日期", "20%" );
$SKIN->td_header[] = array( "结果", "70%" );
$SKIN->td_header[] = array( "统计", "10%" );
$ADMIN->html .= $SKIN->start_table( ucfirst( $IN['timescale'] )." ".$table."({$human_from_date['year']}年 {$this->month_names[$human_from_date['mon']]} {$human_from_date['mday']}日 - "."{$human_to_date['year']}年{$this->month_names[$human_to_date['mon']]} {$human_to_date['mday']}日)" );
if ( $DB->get_num_rows( ) )
{
while ( $row = $DB->fetch_row( ) )
{
if ( $max_result < $row['result_count'] )
{
$max_result = $row['result_count'];
}
$running_total += $row['result_count'];
$results[] = array(
"result_maxdate" => $row['result_maxdate'],
"result_count" => $row['result_count'],
"result_time" => $row['result_time']
);
}
foreach ( $results as $pOOp => $data )
{
$img_width = intval( $data['result_count'] / $max_result * 100 - 8 );
if ( $img_width < 1 )
{
$img_width = 1;
}
$img_width .= "%";
if ( $IN['timescale'] == "weekly" )
{
$date = "Week #".strftime( "%W", $data['result_maxdate'] ).date( $php_date, $data['result_maxdate'] );
}
else
{
$date = date( $php_date, $data['result_maxdate'] );
}
$ADMIN->html .= $SKIN->add_td_row( array(
$date,
"<img src='{$SKIN->img_url}/bar_left.gif' border='0' width='4' height='11' align='middle' alt=''><img src='{$SKIN->img_url}/bar.gif' border='0' width='{$img_width}' height='11' align='middle' alt=''><img src='{$SKIN->img_url}/bar_right.gif' border='0' width='4' height='11' align='middle' alt=''>",
"<center>".$data['result_count']."</center>"
) );
}
$ADMIN->html .= $SKIN->add_td_row( array(
" ",
"<div align='right'><b>总计:</b></div>",
"<center><b>".$running_total."</b></center>"
) );
}
else
{
$ADMIN->html .= $SKIN->add_td_basic( "没有找到统计数据", "center" );
}
$ADMIN->html .= $SKIN->end_table( );
$ADMIN->output( );
}
function main_screen( $mode = "reg" )
{
global $IN;
global $INFO;
global $DB;
global $SKIN;
global $ADMIN;
global $std;
global $MEMBER;
global $GROUP;
$ADMIN->page_title = "论坛统计中心";
$ADMIN->page_detail = "请在下面定义生成统计数据的时间范围。<br>注意:统计数据生成是根据数据库中保存的数据信息。";
if ( $mode == "reg" )
{
$form_code = "show_reg";
$table = "用户注册统计";
}
else if ( $mode == "topic" )
{
$form_code = "show_topic";
$table = "主题发表统计";
}
else if ( $mode == "post" )
{
$form_code = "show_post";
$table = "主题回复统计";
}
else if ( $mode == "msg" )
{
$form_code = "show_msg";
$table = "私人短信统计";
}
else if ( $mode == "views" )
{
$form_code = "show_views";
$table = "主题查看统计";
}
$old_date = getdate( time( ) - 7776000 );
$new_date = getdate( time( ) + 86400 );
$ADMIN->html .= $SKIN->start_form( array(
1 => array(
"code",
$form_code
),
2 => array( "act", "stats" )
) );
$SKIN->td_header[] = array( " ", "40%" );
$SKIN->td_header[] = array( " ", "60%" );
$ADMIN->html .= $SKIN->start_table( $table );
$ADMIN->html .= $SKIN->add_td_row( array(
"<b>开始日期:</b>",
$SKIN->form_dropdown( "from_month", $this->make_month( ), $old_date['mon'] )." ".$SKIN->form_dropdown( "from_day", $this->make_day( ), $old_date['mday'] )." ".$SKIN->form_dropdown( "from_year", $this->make_year( ), $old_date['year'] )
) );
$ADMIN->html .= $SKIN->add_td_row( array(
"<b>结束日期:</b>",
$SKIN->form_dropdown( "to_month", $this->make_month( ), $new_date['mon'] )." ".$SKIN->form_dropdown( "to_day", $this->make_day( ), $new_date['mday'] )." ".$SKIN->form_dropdown( "to_year", $this->make_year( ), $new_date['year'] )
) );
if ( $mode != "views" )
{
$ADMIN->html .= $SKIN->add_td_row( array(
"<b>时间范围:</b>",
$SKIN->form_dropdown( "timescale", array(
0 => array( "daily", "每日" ),
1 => array( "weekly", "每周" ),
2 => array( "monthly", "每月" )
) )
) );
}
$ADMIN->html .= $SKIN->add_td_row( array(
"<b>结果排序:</b>",
$SKIN->form_dropdown( "sortby", array(
0 => array( "asc", "升序排列 - 旧的日期在前面" ),
1 => array( "desc", "降序排列 - 新的日期在前面" )
), "desc" )
) );
$ADMIN->html .= $SKIN->end_form( "显示" );
$ADMIN->html .= $SKIN->end_table( );
$ADMIN->output( );
}
function make_year( )
{
$time_now = getdate( );
$return = array( );
$start_year = 2002;
$latest_year = intval( $time_now['year'] );
if ( $latest_year == $start_year )
{
$start_year -= 1;
}
$y = $start_year;
for ( ; $y <= $latest_year; ++$y )
{
$return[] = array(
$y,
$y
);
}
return $return;
}
function make_month( )
{
$return = array( );
$m = 1;
for ( ; $m <= 12; ++$m )
{
$return[] = array(
$m,
$this->month_names[$m]
);
}
return $return;
}
function make_day( )
{
$return = array( );
$d = 1;
for ( ; $d <= 31; ++$d )
{
$return[] = array(
$d,
$d
);
}
return $return;
}
}
ad_stats( );
$idx = new ad_stats( );
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -