/**
 * return html for Space Usage And Row Statistic
 *
 * @param array  $showtable       showing table information
 * @param string $db              database
 * @param string $table           table
 * @param int    $cell_align_left cell align left
 *
 * @return string
 */
function PMA_getHtmlForSpaceUsageAndRowStatistics($showtable, $db, $table, $cell_align_left)
{
    $html = '';
    $nonisam = false;
    if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
        $nonisam = true;
    }
    if ($nonisam == false) {
        // Gets some sizes
        $mergetable = PMA_Table::isMerge($db, $table);
        list($data_size, $data_unit) = PMA_Util::formatByteDown($showtable['Data_length']);
        if ($mergetable == false) {
            list($index_size, $index_unit) = PMA_Util::formatByteDown($showtable['Index_length']);
        }
        if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
            list($free_size, $free_unit) = PMA_Util::formatByteDown($showtable['Data_free']);
            list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
        } else {
            unset($free_size);
            unset($free_unit);
            list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
        }
        list($tot_size, $tot_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
        $num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
        if ($num_rows > 0) {
            list($avg_size, $avg_unit) = PMA_Util::formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
        }
        // Displays them
        $html .= '<br /><br />';
        $html .= PMA_getHtmlForSpaceUsage($data_size, $data_unit, isset($index_size) ? $index_size : null, isset($index_unit) ? $index_unit : null, isset($free_size) ? $free_size : null, isset($free_unit) ? $free_unit : null, isset($effect_size) ? $effect_size : null, isset($effect_unit) ? $effect_unit : null, isset($tot_size) ? $tot_size : null, isset($tot_unit) ? $tot_unit : null, $mergetable);
        $html .= '</td>';
        $html .= PMA_getHtmlForRowStatistics($showtable, $cell_align_left, isset($avg_size) ? $avg_size : 0, isset($avg_unit) ? $avg_unit : 0, $mergetable);
        $html .= "\n";
        $html .= '</table>';
        $html .= '</td>';
        $html .= '</tr>';
        $html .= '</table>';
    }
    // end if ($nonisam == false)
    return $html;
}
 /**
  * Tests for PMA_getHtmlForRowStatistics() method.
  *
  * @return void
  * @test
  */
 public function testPMAGetHtmlForRowStatistics()
 {
     $showtable = array('Row_format' => "Fixed", 'Rows' => 10, 'Avg_row_length' => 123, 'Data_length' => 345, 'Auto_increment' => 1234, 'Create_time' => "today", 'Update_time' => "time2", 'Check_time' => "yesterday");
     $cell_align_left = "cell_align_left";
     $avg_size = 12;
     $avg_unit = 45;
     $mergetable = false;
     $html = PMA_getHtmlForRowStatistics($showtable, $cell_align_left, $avg_size, $avg_unit, $mergetable);
     $this->assertContains(__('Row Statistics:'), $html);
     //validation 1 : Row_format
     $this->assertContains(__('Format'), $html);
     $this->assertContains($cell_align_left, $html);
     //$showtable['Row_format'] == 'Fixed'
     $this->assertContains(__('static'), $html);
     //validation 2 : Avg_row_length
     $length = PMA_Util::formatNumber($showtable['Avg_row_length'], 0);
     $this->assertContains($length, $html);
     $this->assertContains(__('Row size'), $html);
     $this->assertContains($avg_size . ' ' . $avg_unit, $html);
     //validation 3 : Auto_increment
     $average = PMA_Util::formatNumber($showtable['Auto_increment'], 0);
     $this->assertContains($average, $html);
     $this->assertContains(__('Next autoindex'), $html);
     //validation 4 : Create_time
     $time = PMA_Util::localisedDate(strtotime($showtable['Create_time']));
     $this->assertContains(__('Creation'), $html);
     $this->assertContains($time, $html);
     //validation 5 : Update_time
     $time = PMA_Util::localisedDate(strtotime($showtable['Update_time']));
     $this->assertContains(__('Last update'), $html);
     $this->assertContains($time, $html);
     //validation 6 : Check_time
     $time = PMA_Util::localisedDate(strtotime($showtable['Check_time']));
     $this->assertContains(__('Last check'), $html);
     $this->assertContains($time, $html);
 }