<? global $gdb, $config, $user;?>
<!--<div class="row">
  <div class="col col-xs-12 col-lg-6">
    <div class="panel panel-info panel-border top">
      <div class="panel-heading">
        <span class="panel-title">Monitoring pozycji</span>
      </div>
      <div class="progress progress-bar-xl">
        <div class="progress-bar progress-bar-system" role="progressbar" aria-valuenow="<?= round( $this -> ranker['ok'] / ( $this -> ranker['ok'] + $this -> ranker['bad'] ) * 100 );?>" aria-valuemin="0" aria-valuemax="100" style="width: <?= round( $this -> ranker['ok'] / ( $this -> ranker['ok'] + $this -> ranker['bad'] ) * 100 );?>%; min-width: 250px;">
          <span>Sprawdzone: <b><?= round( $this -> ranker['ok'] / ( $this -> ranker['ok'] + $this -> ranker['bad'] ) * 100 );?>%</b> (<?= $this -> ranker['ok'] . '/' . ( $this -> ranker['ok'] + $this -> ranker['bad'] );?>)</span>
        </div>
      </div>
    </div>
  </div>    
  <div class="col col-xs-12 col-lg-6">
    <div class="panel panel-info panel-border top">
      <div class="panel-heading">
        <span class="panel-title">Proxy PHP</span>
      </div>
      <div class="progress progress-bar-xl">
        <div class="progress-bar progress-bar-system" role="progressbar" aria-valuenow="<?= round( $this -> proxy['ok'] / ( $this -> proxy['ok'] + $this -> proxy['bad'] ) * 100 );?>" aria-valuemin="0" aria-valuemax="100" style="width: <?= round( $this -> proxy['ok'] / ( $this -> proxy['ok'] + $this -> proxy['bad'] ) * 100 );?>%; min-width: 250px;">
          <span>Działające: <b><?= round( $this -> proxy['ok'] / ( $this -> proxy['ok'] + $this -> proxy['bad'] ) * 100 );?>%</b> (<?= $this -> proxy['ok'] . '/' . ( $this -> proxy['ok'] + $this -> proxy['bad'] );?>)</span>
        </div>
      </div>
    </div>
  </div>
</div>-->
<div class="row">
  <div class="col col-xs-12 col-lg-6">
    <div class="panel panel-info panel-border top">
      <div class="panel-heading">
        <span class="panel-title">Ranking wzrostów</span>
      </div>
      <div class="panel-body">        
        <?          
          $grid = new \grid( 'pro_rr_phrases', 'phrases_up' );
          $grid -> debug        = true;
          $grid -> gdb_opt      = $gdb;
          $grid -> src          = $this -> phrases_diffs;
          $grid -> order        = [ 'column' => 'diff', 'type' => 'DESC' ];
          $grid -> columns_view = [
                                    [
                                      'name'  => 'Fraza',
                                      'db'    => 'phrase',
                                      'th'    => [ 'style' => 'background: #666; color: #FFF' ],
                                    ],
                                    [
                                      'name'  => 'Domena',
                                      'db'    => 'domain',
                                      'th'    => [ 'style' => 'background: #666; color: #FFF' ],
                                    ],
                                    [
                                      'name'  => 'Wzrost',
                                      'db'    => 'diff',
                                      'th'    => [ 'style' => 'text-align: right; background: #666; color: #FFF' ],
                                      'td'    => [ 'style' => 'text-align: right; font-weight: bold;' ],
                                      'php'   => 'echo "[today]";'
                                                  . 'if ( [diff] > 0 ) echo "<i class=\'ml10 mr10 fa-lg text-system fa fa-arrow-circle-o-up\'></i>[diff]";'
                                                  . 'if ( [diff] < 0 ) echo "<i class=\'ml10 mr10 fa-lg text-danger fa fa-arrow-circle-o-down\'></i>[diff]";'
                                    ]
                                  ];
          $grid -> hide_columns = false;
          $grid -> condensed    = true;
          $grid -> limit        = 25;
          echo $grid -> draw();
        ?>
      </div>
    </div>
  </div>    
  <div class="col col-xs-12 col-lg-6">
    <div class="panel panel-info panel-border top">
      <div class="panel-heading">
        <span class="panel-title">Ranking spadków</span>
      </div>
      <div class="panel-body">        
        <?          
          $grid = new \grid( 'pro_rr_phrases', 'phrases_down' );
          $grid -> debug        = true;
          $grid -> gdb_opt      = $gdb;
          $grid -> src          = $this -> phrases_diffs;
          $grid -> order        = [ 'column' => 'diff', 'type' => 'ASC' ];
          $grid -> columns_view = [
                                    [
                                      'name'  => 'Fraza',
                                      'db'    => 'phrase',
                                      'th'    => [ 'style' => 'background: #666; color: #FFF' ],
                                    ],
                                    [
                                      'name'  => 'Domena',
                                      'db'    => 'domain',
                                      'th'    => [ 'style' => 'background: #666; color: #FFF' ],
                                    ],
                                    [
                                      'name'  => 'Spadek',
                                      'db'    => 'diff',
                                      'th'    => [ 'style' => 'text-align: right; background: #666; color: #FFF' ],
                                      'td'    => [ 'style' => 'text-align: right; font-weight: bold;' ],
                                      'php'   => 'echo "[today]"; '
                                                  . 'if ( [diff] > 0 ) echo "<i class=\'ml10 mr10 fa-lg text-system fa fa-arrow-circle-o-up\'></i>[diff]";'
                                                  . 'if ( [diff] < 0 ) echo "<i class=\'ml10 mr10 fa-lg text-danger fa fa-arrow-circle-o-down\'></i>[diff]";'
                                    ]
                                  ];
          $grid -> hide_columns = false;
          $grid -> condensed    = true;
          $grid -> limit        = 25;
          echo $grid -> draw();
        ?>
      </div>
    </div>
  </div>
</div>
<!--<div class="row mb20">
  <div class="col col-xs-12">
    <div class="table-responsive">
      <table class="table table-hover table-striped table-bordered table-condensed" style="background: #FFF;">
        <thead>
          <tr>
            <th style="width: 100px;"></th>
            <? for ( $i = 1; $i <= 15; $i++ ):?>
              <th class="text-right" style="background: #666; color: #FFF"><?= $i;?></th>
            <? endfor;?>
          </tr>
        </thead>
        <tbody>
          <? for ( $z = 0; $z < count( $this -> phrases_positions ); $z++ ):?>
            <tr>
              <th class="text-right">
                <?
                  echo $date = date( 'Y-m-d', strtotime( '-' . $z . ' days', strtotime( date( 'Y-m-d' ) ) ) );
                  $date_prev = date( 'Y-m-d', strtotime( '-' . ( $z + 1 ) . ' days', strtotime( date( 'Y-m-d' ) ) ) );
                ?>
              </th>
              <? for ( $i = 1; $i <= 15; $i++ ):?>
                <td class="text-right">
                  <? 
                    $sum      = 0;
                    $sum_prev = 0;
                        
                    for ( $j = 1; $j <= $i; $j++ )
                      $sum += $this -> phrases_positions[$date][$j];                        

                    for ( $j = 1; $j <= $i; $j++ )
                      $sum_prev += $this -> phrases_positions[$date_prev][$j];
                        
                    if ( $sum < $sum_prev )
                      echo '<span class="text-danger">' . $sum . '</span>';

                    if ( $sum > $sum_prev )
                      echo '<span class="text-system">' . $sum . '</span>';

                    if ( $sum == $sum_prev )
                      echo $sum;
                    
                    if ( $user['type'] == 'admin' )
                    {                      
                      if ( $i > 1 )
                      {                        
                        $all      = array_sum( $this -> phrases_positions[$date] );
                        $all_prev = array_sum( $this -> phrases_positions[$date_prev] );
                        
                        $percent        = $sum / $all * 100;
                        $percent_prev   = $sum_prev / $all_prev * 100;
                        
                        if ( $percent < $percent_prev )
                          echo ' | <span class="text-danger">' . number_format( $percent, 1, '.', ' ' ) . '%</span>';
                        
                        if ( $percent > $percent_prev )
                          echo ' | <span class="text-system">' . number_format( $percent, 1, '.', ' ' ) . '%</span>';
                        
                        if ( $percent == $percent_prev )
                          echo ' | ' . number_format( $percent, 1, '.', ' ' ) . '%';
                      }
                      else
                      {
                        $all      = array_sum( $this -> phrases_positions[$date] );
                        $all_prev = array_sum( $this -> phrases_positions[$date_prev] );
                        
                        $percent        = $this -> phrases_positions[$date][$i] / $all * 100;
                        $percent_prev   = $this -> phrases_positions[$date_prev][$i] / $all_prev * 100;
                        
                        if ( $percent < $percent_prev )
                          echo ' | <span class="text-danger">' . number_format( $percent, 1, '.', ' ' ) . '%</span>';
                        
                        if ( $percent > $percent_prev )
                          echo ' | <span class="text-success">' . number_format( $percent, 1, '.', ' ' ) . '%</span>';
                        
                        if ( $percent == $percent_prev )
                          echo ' | ' . number_format( $percent, 1, '.', ' ' ) . '%';
                      }
                    }  
                  ?>
                </td>
              <? endfor;?>
            </tr>
          <? endfor;?>
        </tbody>
      </table>
    </div>
  </div>
</div>-->
<script type="text/javascript">
  $( document ).ready( function() 
  {    
    $( 'body' ).on( 'click', '.panel-heading .fa-trash', function()
    {
      var type  = $( this ).attr( 'type' );
      var kind  = $( this ).attr( 'kind' );
      
      $.prompt( 'Na pewno chcesz usunąć wybraną grupę?', 
      { 
        title: 'Potwierdź?', 
        submit: function(e,v,m,f) 
        { 
          if ( v === true ) 
          {
            $.ajax(
            {
              type: 'POST',
              cache: false,
              url: 'ajax.php',
              data: 
              {
                type: type,
                kind: kind,
                a: 'delete_logs'
              },
              success: function( data )
              {
                document.location.href = './?p=dashboard';
              }
            });
          }
        }, 
        buttons: { 
          'tak': true, 'nie': false 
        }, 
        focus: 1 
      });
      
    });
  });
</script>