<?php
/*********************************************************      
 程序说明：         
    功能说明：进行话务查询

    调用关系：调用:header.inc     
              被调用:      
 
    变量说明：
     返回值：无

 作者：    
      
修改注释：      
NO.1      
姓名：            
时间：      
修改说明：      
*********************************************************/  
require("../../inc/header.inc");
?>
<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('down');" onresize="javascript:adjust_frame('down');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php
adjust_head_frame("down");
adjust_title_head_frame("down");
adjust_title_tail_frame("down");

adjust_content_head_frame("down");	
echo "<br>";

$DEBUG = 0;

$db=$csta_db;
$showDate = date("d",mktime(0,0,0,date("m"),date("d")-$sel_date,date("Y")));
$timeItem = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date,date("Y")));
$showDate = omc_keep_length($showDate,0,2);
$sort_field = 'csta_datetime';		//排序所依赖的字段名
$sort_direction = 'DESC';			//排序顺序
$number_records_to_display = 200;	//每页纪录数
$time_column = "csta_datetime";
$table_name='smscDetail'."_".$showDate;

 $sel_field_list= @mysql_list_fields($db,$table_name);
 if(!$sel_field_list)
 {
	echo "<br>$strNotFindRecord.";
	exit();
 }

if($call_type==0)//MS && SMSC
{
	$headName_1 = "MS->SMSC";
	$headName_2 = "SMSC->MS";
}
elseif($call_type==1)//VMS && SMSC
{
	$headName_1 = "VMS->SMSC";
	$headName_2 = "SMSC->VMS";

}
elseif($call_type==2)//PPS && SMSC
{
	$headName_1 = "PPS->SMSC";
	$headName_2 = "SMSC->PPS";

}
elseif($call_type==3)//SMPP && SMSC
{
	$headName_1 = "SMPP->SMSC";
	$headName_2 = "SMSC->SMPP";
}

$where = isset($where) ? urldecode($where) : '';  //传回变量后解url码
$where = isset($where) ? stripslashes($where) : ''; //解除一些'/'
//删除所查询的内容
if($delete){    
      $sql_query="DELETE FROM $table_name ".$where;               
      $sql_query=urlencode($sql_query); //将该字符串编码，适合传递
      echo " <meta http-equiv=\"refresh\" content=\"0; url=./csta_del.php?del_sql=$sql_query\"> ";
}//end of delete
?>

<script LANGUAGE="JavaScript">  
function goto(){      
		var url_1,url_2,url_3,url_4,url_5,initial_record,gotopage,number_records_to_display,where,number_of_records,sort_field,sel_date;
		gotopage=document.selectform.gotopage.value;
		number_records_to_display=<?php echo $number_records_to_display; ?>;
		where=document.selectform.where.value;
		initial_record=number_records_to_display*(gotopage-1);
		number_of_records=document.selectform.number_of_records.value;
		sort_field=document.selectform.sort_field.value;
		sel_date=document.selectform.sel_date.value;
		url_1='<?php echo $PHP_SELF;?>?initial_record='+initial_record;
		url_2="&where="+where;
		url_3="&number_of_records="+number_of_records;
		url_4="&sort_field="+sort_field;
		url_5="&sel_date="+sel_date;
		window.location.href=url_1+url_2+url_3+url_4+url_5;     
}      
</script>
<?php
// 初始化变量
if (!$number_of_records){//跳转页面不进行初始化
	//-------确定日期范围-----
	if($sel_date<0){
		$bgn_date=date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d")-6,date("Y")));
		$end_date=date("Y-m-d H:i:s", mktime());
	}elseif($sel_date>0){
		if($sel_time){
			$bgn_date=date("Y-m-d H:i:s", mktime($hou_1,$mid_1,$sec_1,date("m"),date("d")-$sel_date,date("Y")));
			$end_date=date("Y-m-d H:i:s", mktime($hou_2,$mid_2,$sec_2,date("m"),date("d")-$sel_date,date("Y")));
		}else{
			$bgn_date=date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d")-$sel_date,date("Y")));
			$end_date=date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d")-$sel_date+1,date("Y")));
		}
	}else{
		if($sel_time){
			$bgn_date=date("Y-m-d H:i:s", mktime($hou_1,$mid_1,$sec_1,date("m"),date("d")-$sel_date,date("Y")));
			$end_date=date("Y-m-d H:i:s", mktime($hou_2,$mid_2,$sec_2,date("m"),date("d")-$sel_date,date("Y")));
		}else{
			$bgn_date=date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d"),date("Y")));
			$end_date=date("Y-m-d H:i:s", mktime());
		}
	}

	/* where语句的时间限制组成部分为$w1,系统id限制为$w2 */
	$w1=" $time_column >='$bgn_date' AND $time_column <= '$end_date'";
	
	//合成where语句
	$where=" WHERE".$w1;
	
	$initial_record = 0;//初始纪录号

	$str_sql_all="SELECT count(*) as number_of_records FROM $table_name ".$where;
	$csta_result= mysqli_query($pubConn,$str_sql_all);
	$record = mysql_fetch_object($csta_result);
	$number_of_records = $record->number_of_records;
	if(!$number_of_records)
	{      
		echo "<br>$strNotFindRecord";
		exit();
	}
 
}//endif

$page_num= ($initial_record / $number_records_to_display) +1;  //该页页码
$all_page_num= ceil($number_of_records / $number_records_to_display);  //总页码
if ($number_of_records >= 1){
	$next_index = $initial_record + $number_records_to_display;  //本页的结束数目
	if ($next_index > $number_of_records)   
	{
		$next_index = $number_of_records;
	}
	$t1 = $initial_record + 1;
	$prev_index = $initial_record - $number_records_to_display;
	if ($prev_index < 0){
		$prev_index = 0;
	} 
}  
$show_initital_record=$initial_record+1;
?>
<TABLE  border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">   
<TR>   
<TD width="50%"><?php echo "$strDisplayRecords:<FONT color=#0000ff>&nbsp;$show_initital_record - $next_index</FONT>, ($strTotalRecords:$number_of_records ) &nbsp;&nbsp;"; ?></TD>   
<TD width="100" align="center">&nbsp; 
<?php     
//$number_of_records_on_current_page = mysqli_num_rows($csta_result);
//echo "$number_of_records_on_current_page<br>";
//下面是控制分页显示，传递变量
if ($initial_record != 0)
{
	$t1 = "initial_record=$prev_index&number_of_records=$number_of_records&table_name=$table_name&sel_date=$sel_date";
    $where=urlencode($where); //将该字符串编码，适合传递
	echo "<a href=\"$PHP_SELF?$t1&where=$where&now_date=$end_date&last_date=$bgn_date&call_type=$call_type\">";
	?>
	<IMG alt=前一页 src="../../images/pre_page.gif"    border="0"></a>&nbsp; 
	<?php
}
// NEW: Display a link for the next set of records.
if ($next_index != $number_of_records && $number_of_records >0 && $number_of_records > $number_records_to_display )
{
	$t1 = "initial_record=$next_index&number_of_records=$number_of_records&table_name=$table_name&sel_date=$sel_date";
    $where=urlencode($where); //将该字符串编码，适合传递
	echo "<a href=\"$PHP_SELF?$t1&where=$where&now_date=$end_date&last_date=$bgn_date&call_type=$call_type\">";
    ?>
	<IMG alt=下一页  src="../../images/next_page.gif"   border="0"></a>
	<?php
    }
    ?> 
</TD>  
<form name="selectform" method="post" action="<?php echo "$PHP_SELF?initial_record=$prev_index&number_of_records=$number_of_records&where=$where&table_name=$table_name&call_type=$call_type";?>" 
> 
  <TD align="center">
  <?php echo "$strPage"; ?>
  <select size="1" name="gotopage" onChange="javascript:goto()">       
  <?php
  for($i=1;$i<=$all_page_num;$i++){
        if($i== $page_num ){
	      echo "<option  selected  value=\"$i\" >$i</option>";
	}else{
	      echo "<option value=\"$i\">$i</option>";
	}
  }
  ?>
      </select></td>
</TR>
</TABLE>
<?php 
$where = isset($where) ? urldecode($where) : '';  //传回变量后解url码
$where = isset($where) ? urldecode($where) : '';  //传回变量后解url码
$where = isset($where) ? stripslashes($where) : ''; //解除一些'/'

//查询数据并放入myrows数租中。
//合成sql语句
$order=" ORDER BY $sort_field   $sort_direction";
$limit=" LIMIT $initial_record, $number_records_to_display";
 
$csta_sql="SELECT * FROM $table_name"."\n".$where.$order.$limit; 
if($DEBUG)	echo "csta_sql = $csta_sql<br>";
$csta_result = mysqli_query($pubConn,$csta_sql);
$csta_rows = @mysqli_fetch_array($csta_result);
echo mysqli_error($pubConn);

echo "<table border=\"1\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";  

echo "<tr bgcolor=\"#E6E6E6\" align=\"center\" valign=\"top\">";
echo "<td>&nbsp;</td>";
echo "<td colspan=\"6\">$headName_1</td>";
echo "<td colspan=\"6\">$headName_2</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";

echo "<tr bgcolor=\"#E6E6E6\" align=\"center\" valign=\"top\">";
echo "<td>$strSystem</td>";
echo "<td>Attempt</td>";
echo "<td>Success</td>";
echo "<td>Unsuccess</td>";
echo "<td>SubFail</td>";
echo "<td>SMFail</td>";
echo "<td>TotalBytes</td>";
echo "<td>Attempt</td>";
echo "<td>Success</td>";
echo "<td>Unsuccess</td>";
echo "<td>SubFail</td>";
echo "<td>SMFail</td>";
echo "<td>TotalBytes</td>";
echo "<td>$strTime($timeItem)</td>";
echo "</tr>";

if($call_type==0)//MS && SMSC
{
	do
	{
		echo "<tr>";
		echo "<td align=\"center\">";
		echo "SMSC"."_"."$csta_rows[key_sys_id]";
		echo "</td>";
		echo "<td align=\"center\">$csta_rows[MS_to_SMSC_attempt]</td>";
		echo "<td align=\"center\">$csta_rows[MS_to_SMSC_success]</td>";
		echo "<td align=\"center\">$csta_rows[MS_to_SMSC_sysfail]</td>";
		echo "<td align=\"center\">$csta_rows[MS_to_SMSC_userfail]</td>";
		echo "<td align=\"center\">$csta_rows[MS_to_SMSC_smfail]</td>";
		echo "<td align=\"center\">$csta_rows[MS_to_SMSC_byte]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_MS_attempt]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_MS_success]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_MS_sysfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_MS_userfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_MS_smfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_MS_byte]</td>";
		$tmpArray = explode(" ",$csta_rows[csta_datetime]);
		echo "<td align=\"center\">$tmpArray[1]</td>";
		echo "</tr>";
     }while($csta_rows= mysqli_fetch_array($csta_result));
}
elseif($call_type==1)//VMS && SMSC
{
	do
	{
		echo "<tr>";
		echo "<td align=\"center\">";
		echo "SMSC"."_"."$csta_rows[key_sys_id]";
		echo "</td>";
		echo "<td align=\"center\">$csta_rows[VMS_to_SMSC_attempt]</td>";
		echo "<td align=\"center\">$csta_rows[VMS_to_SMSC_success]</td>";
		echo "<td align=\"center\">$csta_rows[VMS_to_SMSC_sysfail]</td>";
		echo "<td align=\"center\">$csta_rows[VMS_to_SMSC_userfail]</td>";
		echo "<td align=\"center\">$csta_rows[VMS_to_SMSC_smfail]</td>";
		echo "<td align=\"center\">$csta_rows[VMS_to_SMSC_byte]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_VMS_attempt]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_VMS_success]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_VMS_sysfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_VMS_userfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_VMS_smfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_VMS_byte]</td>";
		$tmpArray = explode(" ",$csta_rows[csta_datetime]);
		echo "<td align=\"center\">$tmpArray[1]</td>";
		echo "</tr>";
     }while($csta_rows= mysqli_fetch_array($csta_result));
}
elseif($call_type==2)//PPS && SMSC
{
	do
	{
		echo "<tr>";
		echo "<td align=\"center\">";
		echo "SMSC"."_"."$csta_rows[key_sys_id]";
		echo "</td>";
		echo "<td align=\"center\">$csta_rows[PPS_to_SMSC_attempt]</td>";
		echo "<td align=\"center\">$csta_rows[PPS_to_SMSC_success]</td>";
		echo "<td align=\"center\">$csta_rows[PPS_to_SMSC_sysfail]</td>";
		echo "<td align=\"center\">$csta_rows[PPS_to_SMSC_userfail]</td>";
		echo "<td align=\"center\">$csta_rows[PPS_to_SMSC_smfail]</td>";
		echo "<td align=\"center\">$csta_rows[PPS_to_SMSC_byte]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_PPS_attempt]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_PPS_success]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_PPS_sysfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_PPS_userfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_PPS_smfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_PPS_byte]</td>";
		$tmpArray = explode(" ",$csta_rows[csta_datetime]);
		echo "<td align=\"center\">$tmpArray[1]</td>";
		echo "</tr>";
     }while($csta_rows= mysqli_fetch_array($csta_result));
}
elseif($call_type==3)//SMPP && SMSC
{
	do
	{
		echo "<tr>";
		echo "<td align=\"center\">";
		echo "SMSC"."_"."$csta_rows[key_sys_id]";
		echo "</td>";
		echo "<td align=\"center\">$csta_rows[SMPP_to_SMSC_attempt]</td>";
		echo "<td align=\"center\">$csta_rows[SMPP_to_SMSC_success]</td>";
		echo "<td align=\"center\">$csta_rows[SMPP_to_SMSC_sysfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMPP_to_SMSC_userfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMPP_to_SMSC_smfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMPP_to_SMSC_byte]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_SMPP_attempt]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_SMPP_success]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_SMPP_sysfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_SMPP_userfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_SMPP_smfail]</td>";
		echo "<td align=\"center\">$csta_rows[SMSC_to_SMPP_byte]</td>";
		$tmpArray = explode(" ",$csta_rows[csta_datetime]);
		echo "<td align=\"center\">$tmpArray[1]</td>";
		echo "</tr>";
     }while($csta_rows= mysqli_fetch_array($csta_result));
}


?>
</table>
<input type="hidden" name="where" value="<?php echo $where; ?>">
<input type="hidden" name="number_of_records" value="<?php echo $number_of_records; ?>">
<input type="hidden" name="sort_field" value="<?php echo $sort_field; ?>">
<input type="hidden" name="sel_date" value="<?php echo $sel_date; ?>">
</form>
<?php
adjust_content_tail("down");
?>
</body>
</html>