Handle default tables and auto checkbox

This commit is contained in:
Takumi
2013-07-29 18:15:14 +10:00
parent b12e4a7043
commit 86bb9e6f03
2 changed files with 26 additions and 17 deletions

View File

@@ -177,7 +177,7 @@ if ( ! function_exists( 'sp_post_checklist' ) ) {
}
if ( ! function_exists( 'sp_data_table' ) ) {
function sp_data_table( $data = array(), $index = 0, $columns = array( 'Name' ) ) {
function sp_data_table( $data = array(), $index = 0, $columns = array( 'Name' ), $total = true ) {
if ( !is_array( $data ) )
$data = array();
?>
@@ -187,6 +187,7 @@ if ( ! function_exists( 'sp_data_table' ) ) {
<?php foreach ( $columns as $column ): ?>
<th><?php echo $column; ?></th>
<?php endforeach; ?>
<th><?php _e( 'Auto', 'sportspress' ); ?></th>
</tr>
</thead>
<tbody>
@@ -194,6 +195,10 @@ if ( ! function_exists( 'sp_data_table' ) ) {
$i = 0;
foreach ( $data as $key => $values ):
if ( !$key ) continue;
if ( array_key_exists( 'auto', $values ) )
$auto = (int)$values[ 'auto' ];
else
$auto = 0;
?>
<tr class="sp-post<?php
if ( $i % 2 == 0 )
@@ -206,28 +211,33 @@ if ( ! function_exists( 'sp_data_table' ) ) {
else
$value = 0;
?>
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][]" value="<?php echo $value; ?>" /></td>
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][]" value="<?php echo $value; ?>"<?php if ( $auto ) echo ' readonly="readonly"'; ?> /></td>
<?php endfor; ?>
<td><input type="checkbox" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][auto]" value="1"<?php if ( $auto ) echo ' checked="checked"'; ?> /></td>
</tr>
<?php
$i++;
endforeach;
?>
<tr<?php
$values = $data[0];
if ( $total ):
$values = array_key_exists( 0, $data ) ? $data[0] : array();
$auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : 0;
?>
<tr<?php
if ( $i % 2 == 0 )
echo ' class="alternate"';
?>>
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
<?php for ( $j = 0; $j < sizeof( $columns ) - 1; $j ++ ):
if ( array_key_exists( $j, $values ) )
$value = (int)$values[ $j ];
else
$value = 0;
?>
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][0][]" value="<?php echo $value; ?>" /></td>
<?php endfor; ?>
</tr>
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
<?php for ( $j = 0; $j < sizeof( $columns ) - 1; $j ++ ):
if ( array_key_exists( $j, $values ) )
$value = (int)$values[ $j ];
else
$value = 0;
?>
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][0][]" value="<?php echo $value; ?>"<?php if ( $auto ) echo ' readonly="readonly"'; ?> /></td>
<?php endfor; ?>
<td><input type="checkbox" name="sportspress[sp_stats][<?php echo $index; ?>][0][auto]" value="1"<?php if ( $auto ) echo ' checked="checked"'; ?> /></td>
</tr>
<?php endif; ?>
</tbody>
</table>
<?php

View File

@@ -51,7 +51,6 @@ function sp_table_stats_meta( $post ) {
else
$data[ $id ] = array();
endforeach;
sp_data_table( $data, 0, array( 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ) );
sp_post_adder( 'sp_team' );
sp_data_table( $data, 0, array( 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), false );
}
?>