<h2><strong><i class="fa fa-database fa-1x" aria-hidden="true"></i> ถ่ายโอนข้อมูลจากระบบ rms</strong> </h2>
<div align="right"><a href="?op=dues&module=item" class="btn btn-secondary" role="button"><i class="fa fa-share" aria-hidden="true"></i> ขั้นตอนต่อไป</a> </div><br>

<?php
if($_POST['action']=="syc"){
	//echo "<center><img src=\"images/reload.gif\" width=\"48\" height=\"48\" alt=\"\"/><br>ถ่ายโอนข้อมูลจากระบบ rms</center>";
	//echo "<meta http-equiv=\"refresh\" content=\"1;url=?op=system&module=data\">";
	if($_POST['fdata']=="1"){
		echo"<center><a href=\"?op=system&module=data\" class=\"btn btn-success\" role=\"button\"><i class=\"fa fa-database\" aria-hidden=\"true\"></i> โอนข้อมูลนักเรียน นักศึกษา (std2018_student) จากระบบ RMS เรียบร้อยแล้ว</a></center><hr>";
		require("pages/getRMSdata-std2018_student.php"); 
	}
	if($_POST['fdata']=="2"){
		echo"<center><a href=\"?op=system&module=data\" class=\"btn btn-success\" role=\"button\"><i class=\"fa fa-database\" aria-hidden=\"true\"></i> โอนข้อมูลกลุ่มเรียน (std2018_studentgroup) จากระบบ RMS เรียบร้อยแล้ว</a></center><hr>";
		
		require("pages/getRMSdata-std2018_studentgroup.php"); 
	}
	if($_POST['fdata']=="3"){
		//echo "<div class=\"alert alert-success\">  <strong>รอสักครู่</strong> กำลังถ่ายโอนข้อมูลแผนการเรียน (std2018_curi_plan) จากระบบ RMS</div>";
		echo"<center><a href=\"?op=system&module=data\" class=\"btn btn-success\" role=\"button\"><i class=\"fa fa-database\" aria-hidden=\"true\"></i> โอนข้อมูลแผนการเรียน (std2018_curi_plan) จากระบบ RMS เรียบร้อยแล้ว</a></center><hr>";
		require("pages/getRMSdata-std2018_curi_plan.php"); 
	}
		
	//exit();

}
else
{

?>

   

<!-- ถ่ายโอนข้อมูลจาก RMS -->
		
		<form role="form" name="ss02" id="ss02" class="form-group" method="post" action="">    	

  <div class="row">  
	
	  <div class="col-lg-12">

		<div class="form-group" align="left">
	 <?php
global $connect;	
$sql="Select * From regis_database order by database_id  ASC";
$db_query=mysqli_query($connect,$sql);
$num_rows=mysqli_num_rows($db_query); /* นับ Reccord ที่พบ */
//echo "มีจำนวน <b>$num_rows</b> รายการ <font color=\"#9E0002\">คลิก ปุ่มรายละเอียด เพื่อแสดงกลุ่มเรียน </font>";

?>		
			
	 <table class="table table-hover table-striped table-condensed table-sm">
    <thead>
      <tr>
		 <th><center>#</center></th> 
        <th>ข้อมูล</th>
        <th style="text-align: right"><center>จำนวน record</center> </th>
		 <th>วัน เวลา ถ่ายโอนข้อมูล </th> 
      </tr>
    </thead>
    <tbody>
	<?php
$a=0;
$no=1;
while($a < $num_rows)
{
	$result = mysqli_fetch_array($db_query);
	$database_id=$result['database_id'];
	$database_name=$result['database_name'];
	$database_table=$result['database_table'];
	$result_num=num_record("$database_table","where 1"); 
	//วันที่ update ข้อมูล
	$result_regis_database_log=select("regis_database_log","where database_id='$database_id' order by id DESC ");
	$day_updateData=$result_regis_database_log["day"];
	

	?>	
      <tr>
		<td align="center"><?=$no?></td>  
        <td><?php echo"$database_name ($database_table)"; ?></td>
        <td align="center" style="text-align: right"><?php echo number_format($result_num);    ?> record

</td>
		 <td><?php echo thai22($day_updateData);?></td>  
      </tr>
       <?php
		$no++;
		$a++;
}
	
	?>
    </tbody>
  </table>

		  </div>	
	  </div>	  
	  	<div class="col-lg-12">
		
		
											<div class="form-group" align="left">
                                            <label>เลือกข้อมูลที่ต้องการ </label>
                                          <select name="fdata" required="required" class="form-control"  id="fdata">
											<option value="" >===เลือกข้อมูล===</option>
		 <?php
global $connect;	
$sql="Select * From regis_database order by database_id  ASC";
$db_query=mysqli_query($connect,$sql);
$num_rows=mysqli_num_rows($db_query); /* นับ Reccord ที่พบ */
//echo "มีจำนวน <b>$num_rows</b> รายการ <font color=\"#9E0002\">คลิก ปุ่มรายละเอียด เพื่อแสดงกลุ่มเรียน </font>";
$a=0;
while($a < $num_rows)
{
	$result = mysqli_fetch_array($db_query);
	$database_id=$result['database_id'];
	$database_name=$result['database_name'];
	$database_table=$result['database_table'];
	$result_num=num_record("$database_table","where 1"); 
	//วันที่ update ข้อมูล
	$result_regis_database_log=select("regis_database_log","where database_id='$database_id' order by id DESC ");
	$day_updateData=$result_regis_database_log["day"];
?>											  
                                             <option value="<?=$database_id?>" ><?php echo"$database_name ($database_table)"; ?></option>
<?php
	$a++;
}
?>
                                            </select>
											</div>
    </div>
	  
	  
      	<div class="col-lg-12">                              

										<div class="form-group" >
						<button type="submit" class="btn btn-warning" id="btnsys" ><i class="fa fa-refresh fa-fw"></i>ถ่ายโอนข้อมูลจากระบบ rms (<?=$url_rms?>)</button>
						<input name="action" type="hidden" id="action" value="syc">
                                      </div>
                                
                                      
    </div>
</div>



</form>
<?php
	}
?>