<link rel="stylesheet" href="<?php echo base_url().'resources/css/1.11.4.jquery-ui.css';?>">
<script src="<?php echo base_url();?>resources/js/1.11.4.jquery-ui.js"></script>
<style>
  .ui-progressbar {
    position: relative;
  }
  .progress-label {
    position: absolute;
    left: 49%;
    top: 4px;
    font-weight: bold;
    text-shadow: 1px 1px 0 #fff;
  }
</style>
<?php 
  $mig =&get_instance();
  $mig->load->model('migrasi/migrasi');
  $cek = $mig->migrasi->cek_perkara()->result();  
  $tot_perkara=$cek[0]->jml_perkara;
if($tot_perkara==0){ ?>
<hr class="thick-line" style="clear:both;">
<div style="padding:20px;"></div>
<div class="detil" style="font-size:14px;margin-top:25px;width: 40%;margin: 0 auto;border-color: #FFFFFF;">
	<form id="frm_migrasi" style="background:white;margin:0;" method="post" action="<?php echo base_url().'migrasi_siadmil/validateUpdate';?>">
		<table id="tableDetilPerkara" style="font-size:14px;">
			<col width="20%">
			<col width="80%">
			<tbody>
				<tr>
					<td>Database Asal</td>
					<td><?php echo $data_asal;?></td>
				</tr>
				<tr>
					<td>Database Tujuan</td>
					<td><?php echo 'SIPP';?></td>
				</tr>
				<tr>
					<td style="vertical-align:top">Update Notes</td>
					<td><?php echo 'Mohon Melakukan Backup Databases SIADMil Sebelum Melakukan Migrasi Database';?></td>
				</tr>
        <tr id="space">
          <td colspan="2" style="background:white;" align="center">
            <font color="blue">Tunggu..</font>
          </td>
        </tr>				
				<tr id="tombol">
					<td colspan="2" style="background:white;" align="center">
						<input id="kembali" type="button" value="Kembali" class="btn">
						<input id="patch" class="btn" type="submit" value="Migrasi">
					</td>
				</tr>
			</tbody>
		</table>
	</form>
	<div id="progressbar" class="progress_bar" hidden><div class="progress-label">Loading...</div></div>
</div>
<?php }else{ echo "</br></br></br><h1><p align='center'><font color='red'>Data Sudah di Migrasi..!</font></h1></p>"; }?>
<script type="text/javascript">
$(function() {
$('#space').hide();

	$('#kembali').click(function(){
		window.open("<?php echo base_url();?>","_self");
	});


	var postComplete = false;
	var progressbar = $( "#progressbar" ),
	progressLabel = $( ".progress-label" );
	progressbar.progressbar({
		value: false,
      	change: function() {
      		progressLabel.text( progressbar.progressbar( "value" ) + "%" );
      		$(".progress-label").css({left: '50%'});
      	},
      	complete: function() {
      		var vals = parseInt(progressbar.progressbar("value"));
      		if(vals>=100){
      			$(".progress-label").css({left: '41%'});
      			progressLabel.text( "Completed!" );
      		}else{
      			$(".progress-label").css({left: '50%'});
      			//progressLabel.text( "Error!" );
      		}
      	}
    });
    var ask = function() {
    	var time = new Date().getTime();
	    $.ajax({
	    	type: 'POST',
	    	url: "<?php echo base_url('migrasi_siadmil/check_progress');?>",
	    	success: function(data) {
	    		if(parseInt(data)>0){
	    			progressbar.progressbar("value", parseInt(data));
	    		}
	    		if (!postComplete)
	    			setTimeout(ask, 500);
	        }
	    });
  	}
  	$("#frm_migrasi").submit(function(event) {
  		progressbar.progressbar("value", 0);
  		postComplete = false;
  		$('.progress_bar').show();
      $('#tombol').hide();
      $('#space').show();      
  		$.ajax({
  			type: 'post',
  			url: $(this).attr('action'),
  			data: {'data':'data'},
  			success: function(data) {
  				if(data.st==1){
  					postComplete = true;
            $('#tombol').show();
            $('#patch').prop('disabled',true);
            $('#space').hide();            
  					message_show(data.msg);
  				}else{
  					message_error_show_parent(data.msg);
  					postComplete = true;
  				}
  				
  			},
  			error: function(XMLHttpRequest, textStatus, errorThrown) {
  				postComplete = true;
  				var json = jQuery.parseJSON(XMLHttpRequest.responseText);
                    if(json.st==0){
                        $('#pesan-container').html(json.msg);
                    }
  			},
  			dataType: 'json'
  		});

  		if (!postComplete){
  			setTimeout(ask, 500);
  		}
  		event.preventDefault();
  	});
});

</script>