<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: 50%;
    top: 4px;
    font-weight: bold;
    text-shadow: 1px 1px 0 #fff;
  }
  </style>
<?php 
    $PN_versions=$this->session->userdata('app_version');
    $ver_updates='';
    $pesan='';
    $update=true;
    $sock = false;
    if($source_path!=''){
        if ($sock == @fsockopen($source_path.'current-release-versions.php', 80, $num, $error, 5)){
            $getVersions = @file_get_contents($source_path.'current-release-versions.php');

            if($getVersions===false){
                $ver_updates = '<font color="red">'.$error.'<br/></font>';
                $update=false;    

            }else{
                $arr_versions=json_decode($getVersions, true);
                foreach ($arr_versions as $k=>$v) {
                    if ($PN_versions<$k){
                        $ver_updates.=$k.' <strong>Penting: </strong><i>'.$v[2].'</i></br>';
                    }
                }
                if($ver_updates==''){
                    $ver_updates='<i>Latest Version Installed</i>';
                    $update=false;
                }
            }
        }else{
            $ver_updates = '<font color="red">'.$error.'<br/></font>';
            $update=false;    
        }
    }else{
        $ver_updates = '<font color="red">Kesalahan pada table updates<br/></font>';
        $update=false;    
    }
?>
<hr class="thick-line" style="clear:both;">
<div style="padding:20px;"></div>
<div class="detil" style="padding:10px 10px 0 10px;font-size:14px;margin-top:25px;width: 40%;margin: 0 auto;border-color: #eee;">
		<table id="tableDetilPerkara" style="font-size:14px;background:#fff">
			<col width="40%">
			<col width="80%">
			<tbody>
				<tr>
					<th colspan="2" style="font-size:50px;color:#259fd3">SIPP</th>
				</tr>
				<tr>
					<th colspan="2" style="font-size:14px;">Sistsem Informasi Penelusuran Perkara</th>
				</tr>
				<tr>
					<th colspan="2" style="font-size:10px;">Hak Cipta © Mahkamah Agung Republik Indonesia 2015</th>
				</tr>
				<tr>
					<th colspan="2" style="font-size:10px;"><br></th>
				</tr>
				<tr>
					<td>Current Version</td>
					<td><strong><?php echo $this->session->userdata('app_version');?></strong></td>
          <input type='hidden' name='current_ver' value='<?php echo $this->session->userdata('app_version');?>'>
				</tr>
				<tr>
					<td>Update Version Available</td>
					<td><?php echo $ver_updates;?></td>
				</tr>
				<tr>
					<td colspan="2" style="background:white;" align="center">
                        <?php
                        if($update){
                            echo '<input id="patch" class="btn" type="submit" value="Update">';
                        }
                        ?>		
					</td>
				</tr>
			</tbody>
		</table>
	<div class='progress_teks bar'></div>
	<div id="progressbar" class="progress_bar bar" hidden><div class="progress-label">Loading...</div></div>
</div>
<div id='response'></div>

<script type="text/javascript">
$(function() {
	var progressbar = $( "#progressbar" ),
      progressLabel = $( ".progress-label" );
 
    progressbar.progressbar({
      value: false,
      change: function() {
        progressLabel.text( progressbar.progressbar( "value" ) + "%" );
      },
      complete: function() {
        progressLabel.text( "Complete!" );
      }
    });

  var postComplete = false;
  var progressbar = $( "#progressbar" ),
      progressLabel = $( ".progress-label" );
      progressbar.progressbar({
      value: false,
      change: function() {
        progressLabel.text( progressbar.progressbar( "value" ) + "%" );
      },
      complete: function() {
        progressLabel.text( "Complete!" );
      }
    });
  	var val = progressbar.progressbar( "value" ) || 0;
  	var ask = function() {
    var time = new Date().getTime();
    $.ajax({
      type: 'POST',
      url: "<?php echo base_url('progress/cek_session');?>",
      success: function(data) {
      	isi = (JSON.parse(data));
	    progressbar.progressbar( "value", parseInt(isi.progress));
	    $('.progress_teks').text('Downloading '+isi.lbl);
        if (!postComplete){
        	setTimeout(ask, 500);
        }else{
        	$('.progress_teks').text('Download completed');
        }
      }
    });
  }

  $("#patch").click(function() {
    postComplete=false;
    var time = new Date().getTime();
    $('#response').text('');
    $('.bar').show();
    $.ajax({
      type: 'post',
      url: "<?php echo base_url().'update_dl_ekstract/download';?>",
      data: {},
      success: function(data) {
      	postComplete = true;
      	$('#response').append(data);
        $('.bar').hide();
      }
    });

    if (!postComplete){
      setTimeout(ask, 500);
    }
  });
});
</script>