<?php
    echo '<table>';
        echo '<tr>';
            echo '<td>';
                $this->widget('ext.widgets.QRGenerator.QRGenerator', array('content'=>$content));
            echo '</td>';
            echo '<td style="width:48%;">';
                echo __('PHONESETTINGS_MYPHONE_QRCODE_DESCRIPTION');
            echo '</td>';
        echo '</tr>';
    echo '</table>';
    
    echo '</br>';
    echo __('PHONESETTINGS_MYPHONE_QRCODE_TIMELEFT_INFOTEXT');
    
    $currentDateTime = strtotime(PhonalisaDate::newServerDate());
    $addedTime = strtotime($model->added);
    
    $maxCount = 300;

    $initTimeLeft = $maxCount - ($currentDateTime - $addedTime);
    $percentLeft = $initTimeLeft/$maxCount*100;

    $this->widget('bootstrap.widgets.TbProgress', array(
                'percent'=>$percentLeft, // the progress1
                'striped'=>true,
                'animated'=>true,
                'htmlOptions' => array(
                    'id'=>'my-phones-grid_Modal_progressBar',
                    'style' => 'margin-bottom:0'
                )
            ));
?>

<script>
var initTime = <?php echo $maxCount; ?>;
var timeLeft = <?php echo $initTimeLeft; ?>;
clearInterval(counter);
var counter = setInterval(timer, 1000);

function timer()
{
  var isEnabled = '<?php echo $model->accessToken; ?>';
  if (isEnabled !== '') {
    $('#my-phones-grid_Modal').modal("hide");
    return;
  }
  timeLeft=timeLeft-1;
  if (timeLeft <= 0) {
      clearInterval(counter);
      $('#my-phones-grid_Modal').modal("hide");
      $.fn.yiiGridView.update('authDevice-grid');
      return;
  }
  $('#my-phones-grid_Modal_progressBar div.bar').css({width:(timeLeft/initTime*100)+"%"});
  $('#my-phones-grid_Modal_progressBar div.bar').text(timeLeft+'s');

}
</script>