<?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;
$helpId="6.4.2";
if($sysTypeNo == 360)
{
	$db='PPS_DB';
	$table_name="used_card_info";			//查询的表名
}
else
{
	$db='RCM_RC_DB';
	$table_name="used_card_info";			//查询的表名
}

//$card_num_len 电话号码长度
$cardStatDef=array(
	array(value =>'0',remark =>'Not Used'),
	array(value =>'1',remark =>'Used')
);
if($DEBUG)	echo "sort_field=$sort_field<br>";
if(!$sort_field ){
	$sort_field='card_no';			//排序所依赖的字段名
}    
if(!$sort_direction){
	$sort_direction= 'ASC ';		//排序顺序
}
$number_records_to_display = 100;	//每页纪录数
$moneyPara = getMoneyPara();		//显示的货币单位是最小货币单位的倍数
if ($DEBUG)echo "selKeyFieldName=$selKeyFieldName<br>";
if ($DEBUG)echo "initial_record=$initial_record,number_records_to_display=$number_records_to_display";
if ($selKeyValue <> '')
	$where=" where card_status=1 AND $selKeyFieldName like '%$selKeyValue%'";
else
	$where=" where card_status=1";
?>

<script LANGUAGE="JavaScript">  
function goto(){      
	var iurl_1,url_2,url_3,url_4,nitial_record;
	var gotopage,number_records_to_display,bgn_num,number_of_records,sort_field;
	gotopage=document.selectform.gotopage.value;
	number_records_to_display=<?php echo $number_records_to_display; ?>;
	//bgn_num=document.selectform.bgn_num.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;
	url_1='<?php echo $PHP_SELF;?>?initial_record='+initial_record;
	//url_2="&bgn_num="+bgn_num;
	url_3="&number_of_records="+number_of_records;
	url_4="&sort_field="+sort_field;
	//window.location.href=url_1+url_2+url_3+url_4;
	window.location.href=url_1+url_3+url_4;
}      
</script>

<?php
if(!isset($number_of_records) || $number_of_records == 0){
	$initial_record=0;
	$str_sql="SELECT  count(*) FROM $table_name $where";
	$result = mysqli_query($pubConn,$str_sql);
	$record = mysqli_fetch_array($result);
	$number_of_records = $record[0];
	if(!$number_of_records){ 
		//echo "<br><font size =\"3\" color=\"#000000\">$strNotFindRecord!</font>";  
		echo "No record.<BR>";
		exit();
	}
}

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_initial_record=$initial_record+1;
$sql = "SELECT * FROM $table_name $where ORDER BY $sort_field 
					LIMIT $initial_record,$number_records_to_display";
if($DEBUG)echo "<br>sql=$sql<br>";
$result = mysqli_query($pubConn,$sql);
echo mysqli_error($pubConn);
?>


<form name="selectform">
<TABLE  border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">      
  <TR >     
    <TD><?php echo"$strDisplayRecords<FONT color=#0000ff>&nbsp;$show_initial_record - $next_index</FONT>, ($strTotal:<font color=#0000FF>$number_of_records</font>)";?></TD>   
    <TD align="center">&nbsp;   
 <?php       
    
 // NEW: Display a link for the previous set of records.  
 if ($initial_record != 0) {  
       $t1 = "initial_record=$prev_index&number_of_records=$number_of_records&sort_field=$sort_field";  
       $t2 = "bgn_num=$bgn_num&end_num=$end_num";  
       echo "<a href=\"$PHP_SELF?$t1&$t2\">";   
       echo "<IMG alt=\"$strPreviousPage\" border=\"0\"  src=\"../../images/prePage.gif\" ></a>&nbsp;"; 
 }  
  
 // NEW: Display a link for the next set of records.  
 if ($next_index != $number_of_records && $number_of_records >0) {  
      $t1 = "initial_record=$next_index&number_of_records=$number_of_records&sort_field=$sort_field";  
      $t2 = "bgn_num=$bgn_num&end_num=$end_num";  
      echo "<a href=\"$PHP_SELF?$t1&$t2\">";  
      echo "<IMG alt=\" $strNextPage \" border=\"0\"  src=\"../../images/nextPage.gif\" ></a>&nbsp;";  
 }
 if($DEBUG) echo "number_of_records=$number_of_records";
 if($number_of_records > 0){
      $this_page = $initial_record / $number_records_to_display + 1;
	  $all_page = ceil($number_of_records / $number_records_to_display );

 /*   $all_page = round($number_of_records / $number_records_to_display );
      if($number_of_records % $number_records_to_display > 0){
              $all_page = $all_page + 1;
      }
*/
 }
 if($DEBUG) echo "<br>all_page=$all_page";
 ?>   
    </TD>  
	<TD align="center"><?php echo "$strToPage";?> 
	<SELECT size="1" name="gotopage" onChange="javasript:goto()"> 
	<?php
	for($i=1;$i<=$all_page;$i++){
		if($i== $this_page){
		echo "<option  selected  value=\"$i\" >$i</option>";
		}else{
			echo "<option value=\"$i\">$i</option>";
		}
	}
	?>
	</SELECT>
	</TD>
  </TR>  
</TABLE> 

<table border="1" width="100%"  cellpadding="1" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF">
  <tr bgcolor="#E6E6E6">
    <td align="center"><?php echo "<a href=\"$PHP_SELF?sort_field=card_no&bgn_num=$bgn_num\">Card no.</a>"; ?></td>
    <td align="center"><?php echo "<a href=\"$PHP_SELF?sort_field=card_status&bgn_num=$bgn_num\">Status</a>"; ?></td>
    <td align="center"><?php echo "<a href=\"$PHP_SELF?sort_field=face_value&bgn_num=$bgn_num\">Face value</a>"; ?></td>
    <td align="center"><?php echo "<a href=\"$PHP_SELF?sort_field=expiry_date&bgn_num=$bgn_num\"> Expriation date</a>"; ?></td>
    <td align="center"><?php echo "<a href=\"$PHP_SELF?sort_field=updated_date &bgn_num=$bgn_num\">Updated time</a>"; ?></td>
    <td align="center"><?php echo "<a href=\"$PHP_SELF?sort_field=msisdn_used&bgn_num=$bgn_num\">Recharged number</a>"; ?></td>
  </tr>
 
  <?php  
	while($rows = mysqli_fetch_array($result)){
		echo"<tr>";
		echo "<td align=\"center\">$rows[card_no]</td>";
		echo "<td align=\"center\">";
		for($i=0;$i < sizeof($cardStatDef);$i++){
			if($rows[card_status] == $cardStatDef[$i][value]){
				echo "{$cardStatDef[$i][remark]}";
				break;
			}	
		}
		echo "</td>";
		
		$rows[face_value]=$rows[face_value];//$moneyPara;
		echo "<td align=\"center\">$rows[face_value]</td>";
		
		//$year	=substr($rows[expiry_date],0,4);
		//$mon	=substr($rows[expiry_date],4,2);
		//$day	=substr($rows[expiry_date],6,2);
		//$expiry_date=$year."-".$mon."-".$day;
		echo "<td align=\"center\">$rows[expiry_date]</td>";

		//$year	=substr($rows[updated_date],0,4);
		//$mon	=substr($rows[updated_date],4,2);
		//$day	=substr($rows[updated_date],6,2);
		//$updated_date=$year."-".$mon."-".$day;
		echo "<td align=\"center\">$rows[updated_date]</td>";
		
		if(!$rows[msisdn_used]){
			  $msisden_used = '----';
		}else{
			  $msisden_used = $rows[msisdn_used];
		}
		echo "<td align=\"center\">$msisden_used</td>";
	}
	echo "<input type=\"hidden\" name=\"number_of_records\" value=\"$number_of_records\">";
	echo "<input type=\"hidden\" name=\"sort_field\" value=\"$sort_field\">";
	echo "<input type=\"hidden\" name=\"sysTypeNo\" value=\"$sysTypeNo\">";
  ?>
</table>
<?php
adjust_content_tail("down");
?>
</form>
</body>