<?php
/*********************************************************      
 ����˵����         
    ����˵����������־��ѯ��ʾ��ɾ������ѯ����־
    ���ù�ϵ������: header.inc     
              ������:      
    ����˵����
	����ֵ����
	���ߣ�
      
�޸�ע�ͣ�      
NO.1      
Name: Li Long
Date: Monday, March 01, 2004
Description: fix "Next" and "Previous" button display sort by different date.
NO.1      
Name: Li Long
Date: 2004-5-26
Description: fix show all log error after show each days' log.
*********************************************************/  
require("../../inc/header.inc");
$DEBUG=0;
$sel_date=$_REQUEST['sel_date'];
$sort_field=$_REQUEST['sort_field'];
$number_of_records=$_REQUEST['number_of_records'];
$initial_record=$_REQUEST['initial_record'];
$userName=$_REQUEST['userName'];
$operTypeNo=$_REQUEST['operTypeNo'];
$bgn_time=$_REQUEST['bgn_time'];
$end_time=$_REQUEST['end_time'];




?>
<html>
<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");	
$db=$omc_db;
/*********************************/
//ע�⣺������־������Ҫ�޸���Ӧ��case�ֵ����ݡ�
/*********************************/


if(!$sort_field){
	$sort_field = 'datetime';		//����������������
}


$sort_direction = 'DESC';			//����˳��
$number_records_to_display = 100;	//ÿҳ��¼��
$where = (isset($where)==1) ? urldecode($where) : '';  //���ر������url��
$where = (isset($where)==1) ? stripslashes($where) : ''; //���һЩ'/'
//ѡ�����԰汾
if($language == 'chn'){
	$show_log_def='name_1';
}else{
	$show_log_def='name_2';
}
?>
<script LANGUAGE="JavaScript">  
function goto(){      
		var url_1,url_2,url_3,url_4;
		var initial_record,gotopage,number_records_to_display,where,number_of_records,sort_field;
		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;
		sel_date=document.selectform.sel_date.value;
		sort_field=document.selectform.sort_field.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($DEBUG) echo "sel_date=$sel_date,bgn_time=$bgn_time<br>";
if( isset($sel_date) && ($sel_date != -1) && ($sel_date != '') ){
	$bgn_time=date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d")-$sel_date,date("Y")));
	$end_time=date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d")-$sel_date+1,date("Y")));
}
elseif($sel_date == -1 || $sel_date==''){
	$bgn_time=date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d")-6,date("Y")));
	$end_time=date("Y-m-d H:i:s", mktime());
}
$where=" WHERE datetime>='$bgn_time' AND datetime<='$end_time'";
if($DEBUG) echo "where = $where<br>";
if (isset($number_of_records)!=1){ 
	$initial_record = 0;
	$select_sql_all="SELECT  count(*) as number_of_records FROM $sysoperlog_table ".$where;
	if($DEBUG) echo "<br>select_sql_all=$select_sql_all";
	$result = mysqli_query($pubConn,$select_sql_all);
	$record = mysqli_fetch_object($result);
	$number_of_records = $record->number_of_records;
} 
$select = "SELECT $sysoperlog_table.userName as userName,
                  $sysoperlog_table.datetime as datetime,
                  $sysoperlog_table.remark as remark,
                  $sysoperconf_table.$show_log_def as logType
		   FROM $sysoperlog_table,$sysoperconf_table 
		  ";
$order  = " ORDER BY $sort_field  $sort_direction ";
$initial_record = isset($initial_record)?$initial_record:'0';
$limit  = " LIMIT $initial_record, $number_records_to_display ";
//echo "a=$order";
$log_sql= $select.$where.$order.$limit;
if($DEBUG) echo "<br>log_sql=$log_sql";
$log_result = @mysqli_query($pubConn,$log_sql);
$log_rows = @mysqli_fetch_array($log_result);
echo mysqli_error($pubConn);
if(!$log_rows){
	echo "$strNotFindRecord";
	exit();
}
//����ҳ��
if (!$all_page_num){
	$page_num= ($initial_record / $number_records_to_display) +1;  //��ҳҳ��
	$all_page_num= ceil($number_of_records / $number_records_to_display);  //��ҳ��
} 
?>


<?php 
  //$number_of_records_on_current_page = mysqli_num_rows($log_result);

  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;
?>     

<form name="selectform" method="post" action="<?php echo"$PHP_SELF";?>">
<table border="0" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#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 align="right">
	  <?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";
			$t2 = "userName=$userName&operTypeNo=$operTypeNo";
			$t3 = " bgn_time=$bgn_time&end_time=$end_time";
			if(isset($sel_date)==1){
				$t4 = "sel_date=$sel_date";
				echo "<a href=\"$PHP_SELF?$t1&$t2&$t3&$t4\">";
			}
			else{
				echo "<a href=\"$PHP_SELF?$t1&$t2&$t3\">";
			}
			echo "Previous&nbsp;<IMG alt=$strPreviousPage align=absBottom border=0  src=../../images/left.gif ></a>&nbsp;"; 
	  }else{
			echo "<font color=\"#808080\">Previous&nbsp;</font><IMG alt=$strPreviousPage align=absBottom border=0  src=../../images/left_1.gif ></a>&nbsp;"; 
	  }  

	  echo "<select size=\"1\" name=\"gotopage\" onChange=\"javascript:goto()\">";
	  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>";
		}
	  }
	  echo "</select>";

	  // 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";
			$t2 = "userName=$userName&operTypeNo=$operTypeNo";
			$t3 = " bgn_time=$bgn_time&end_time=$end_time";
			if(isset($sel_date)==1){
				$t4="sel_date=$sel_date";
				echo "<a href=\"$PHP_SELF?$t1&$t2&$t3&$t4\">";
			}else{
				echo "<a href=\"$PHP_SELF?$t1&$t2&$t3\">";
			}
			echo "<IMG alt=$strNextPage align=absBottom border=0  src=../../images/right.gif>&nbsp;Next</a>";
	  }else{
			echo "<IMG alt=$strNextPage align=absBottom border=0  src=../../images/right_1.gif ><font color=\"#808080\">&nbsp;Next</font>";
	  }
	  ?>
    </td>
  </tr>
</table>
<table border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666"  bgcolor="#FFFFFF" bordercolordark="#FFFFFF" style="table-layout:fixed;">
  <tr bgcolor="#E6E6E6" align="center"> 
    <td width="10%"><?php echo "<a href=\"$PHP_SELF?sort_field=userName&where=$where&number_of_records=$number_of_records&sel_date=$sel_date\">$strOperator</a>";?></td> 
    <td width="20%"><?php echo "<a href=\"$PHP_SELF?sort_field=datetime&where=$where&number_of_records=$number_of_records&sel_date=$sel_date\">$strTime</a>";?></td> 
    <td width="70%"><?php echo "$strDescription";?></td> 
    </tr> 
  <?php
  do{
  ?>
	<tr> 
    <td width="10%">&nbsp;<?php echo "$log_rows[userName]";?></td> 
    <td width="20%" align="center" >&nbsp;<?php echo"$log_rows[datetime]";?></td>  
    <td width="70%" align="left" style="word-wrap : break-word ;">&nbsp;<?php echo"$log_rows[remark]";?></td>  
  </tr>  
  <?php
  }while( $log_rows=mysqli_fetch_array($log_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>
