<?php require_once('../Connections/BE2.php'); ?>
<?php
 
$currentPage = "inpoint.html";//$_SERVER["PHP_SELF"];  
$maxRows_Rt2 = 10;
$pageNum_Rt2 = 0;
if (isset($_GET['pageNum_Rt2'])) {
  $pageNum_Rt2 = $_GET['pageNum_Rt2'];
}
$startRow_Rt2 = $pageNum_Rt2 * $maxRows_Rt2;

mysql_select_db($database_BE2, $BE2);
// eid, eccid(order_datas->ccid), emem_num, euid, e_type, e_ival, e_oval, e_date order_point 
/*
$query_Rt2 = sprintf("SELECT a.*,b.rdoc,c.mem_auto,d.p_title FROM order_point as a, order_rtype as b ,order_datas as c,product_data as d WHERE a.e_type=b.rid AND a.eccid=c.ccid AND c.mem_auto=d.mem_auto AND a.euid='%s'  ORDER BY a.eid DESC",$_SESSION['login_memid']);
*/
$query_Rt2 = sprintf("SELECT a.*,b.rdoc  FROM order_point as a, order_rtype as b   WHERE a.e_type=b.rid AND  a.euid='%s'  ORDER BY a.eid DESC",$_SESSION['login_memid']);


$query_limit_Rt2 = sprintf("%s LIMIT %d, %d", $query_Rt2, $startRow_Rt2, $maxRows_Rt2);
$Rt2 = mysql_query($query_limit_Rt2, $BE2) or die(mysql_error());
$row_Rt2 = mysql_fetch_assoc($Rt2);

if (isset($_GET['totalRows_Rt2'])) {
  $totalRows_Rt2 = $_GET['totalRows_Rt2'];
} else {
  $all_Rt2 = mysql_query($query_Rt2);
  $totalRows_Rt2 = mysql_num_rows($all_Rt2);
}
$totalPages_Rt2 = ceil($totalRows_Rt2/$maxRows_Rt2)-1;

$queryString_Rt2 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Rt2") == false && 
	    stristr($param, "menu") == false && 
        stristr($param, "totalRows_Rt2") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Rt2 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Rt2 = sprintf("&totalRows_Rt2=%d%s", $totalRows_Rt2, $queryString_Rt2);

mysql_select_db($database_BE2, $BE2);
$query_Rt3 = sprintf("SELECT sum(if(e_flag='N',e_ival,0)) AS e_i, sum(if(e_flag='Y',e_ival,0)) as e_u FROM order_point WHERE euid='%s' group by euid ",$_SESSION['login_memid']);

$Rt3 = mysql_query($query_Rt3, $BE2) or die(mysql_error());
$row_Rt3 = mysql_fetch_assoc($Rt3);
 
?>	
		<!-- start: Content -->
		<div class="main ">
		
			<div class="row">
				<div class="col-lg-12">
					<h3 class="page-header"><i class="fa fa-indent"></i>雲點數來源記錄</h3>
					<ol class="breadcrumb">
						<li><i class="fa fa-home"></i><a href="index.html">首頁</a></li>
						<li><i class="fa fa-list-alt"></i><a href="#">雲點數</a></li>
						<li><i class="fa fa-indent"></i>來源記錄</li>				
					</ol>
				</div>
			</div>



			<div class="row">	
				<div class="col-md-12">
					<div class="panel panel-default">
						<div class="panel-heading">
							<h2><i class="fa fa-list red"></i><span class="break"></span><strong>列出雲點數交易記錄</strong></h2>
						</div>


						<div class="panel-body">

					<h3 class="panel-title">&nbsp;</h3>
					            <div class="clearfix"></div>  
                    
                     <div style="overflow:scroll;">
				 <table class="table table-striped table-bordered" style="min-width:800px;">
 
						<thead>
							<tr class="replace-inputs">
								<th width="38" class="center">#</th>
								<th width="42">日期</th>
							<? /*	<th width="71">&nbsp;</th> */ ?>
								<th width="48">類別</th>
								<th width="76">雲點數來源點數</th>
								<th width="76">雲點數使用點數</th>
							</tr>
						</thead>
						<tbody>
                           <?php  
							if($totalRows_Rt2>0){
							$i=0;	
						 do { $i++;?>
							<tr>
								<td class="center"><?= $i ?></td>
                                <td><?= $row_Rt2['e_date'];?></td>
                            <? /*   <td><?= $row_Rt2['p_title'];?></td> */ ?>
                                <td><?= $row_Rt2['rdoc']; ;?></td>
                                <td><?= $row_Rt2['e_ival'];?></td>
                                <td><?= $row_Rt2['e_oval'];?></td>
							</tr>
						
                        <?php } while ($row_Rt2 = mysql_fetch_assoc($Rt2)); ?>
						    <tr>
								<td class="center">&nbsp;</td>
                                <td><span class="center">雲點數</span></td>
                                <td>&nbsp;</td>
                                <td>可用雲點數 : <?= $row_Rt3['e_u'];?></td>
                                <td>未結算雲點數 : <?= $row_Rt3['e_i'];?></td>
							</tr>
						<?	}  	?>
                        </tbody>
 
					</table>
				
                    
              	<? if($row_Rt3['e_u']>0){?>
            <div class="form-group form-actions">
				 <input type="button" name="Sub1" value="轉移 雲點數" class="btn btn-3d btn-black btn-md" onclick="location.href='sharepoint.html'">
				              
              </div>   				      
            <? }?>       
<div class="form-group form-actions">
									<? /*
                                    <input type="button" name="Sub2" value="更新 雲點數" class="btn btn-3d btn-black btn-md" onclick="renew_point();">
                                   */ ?>
				              
              </div>   
              	未結算之雲點數，將會在下一個月15日結算		      
                
                   <ul class="pagination">
                    <?    
                     if( $totalPages_Rt2 >0){	 
						    //分頁程式
if($totalPages_Rt2<5){
		 $start=0;
		 $end=$totalPages_Rt2;
		}else{  
	    $start=$pageNum_Rt2-5;
		$end=$pageNum_Rt2+5;
        if ($start<0){
		 $start=0;
		 $end=10; } 
		 else { $end=$start+10 ;}
		 if ($end>$totalPages_Rt2){ 
		   $start = $end-$totalPages_Rt2-5;
		   $end=$totalPages_Rt2;
		   }
		 if ($end-$start>10){ 
		   $start = $end-10;
		   }  
		 } ?> 
                     <?php if ($pageNum_Rt2 > 0) { // Show if not first page ?>
                     <li><a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, max(0, $pageNum_Rt2 - 1), $queryString_Rt2); ?>">上一頁</a></li><?php } // Show if not first page ?>
                    	<?	   
		for($i=$start;$i<=$end;$i++){
		if($i==$pageNum_Rt2){ echo '<li class="active"><a href="#">'.($i+1).'</a></li>';} else {?>
            <li><a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, min($totalPages_Rt2, $i), $queryString_Rt2); ?>"><? echo $i+1 ;?></a></li>
                 
                        <?	}   }  ?>

                      <?php if ($pageNum_Rt2 < $totalPages_Rt2) { // Show if not last page ?>
            <li><a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, min($totalPages_Rt2, $pageNum_Rt2 + 1), $queryString_Rt2); ?>">下一頁</a></li>
                        <?php }  
						             }  
									 
								 	 ?>
								
						  </ul>

                   </div>



					  </div>
					</div>
				</div><!--/col-->
			
			</div><!--/row-->

    
		</div>
		 
		<!-- end: Content -->
  <script type="text/javascript">
 function renew_point()
 {
 
   var pname=$('#pname').val();	
   $.ajax({
		method: "POST",
		url: "ajax_renew_point.php",
		data: {'MM_update': 'form1'}
		}).done(function( data ) {
 	      alert('OK..');
      });
 
  }
</script>          
        
  <?php
mysql_free_result($Rt2);
mysql_free_result($Rt3);  
?>        
    