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' ) ) { 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 ) ) if ( !is_array( $data ) )
$data = array(); $data = array();
?> ?>
@@ -187,6 +187,7 @@ if ( ! function_exists( 'sp_data_table' ) ) {
<?php foreach ( $columns as $column ): ?> <?php foreach ( $columns as $column ): ?>
<th><?php echo $column; ?></th> <th><?php echo $column; ?></th>
<?php endforeach; ?> <?php endforeach; ?>
<th><?php _e( 'Auto', 'sportspress' ); ?></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -194,6 +195,10 @@ if ( ! function_exists( 'sp_data_table' ) ) {
$i = 0; $i = 0;
foreach ( $data as $key => $values ): foreach ( $data as $key => $values ):
if ( !$key ) continue; if ( !$key ) continue;
if ( array_key_exists( 'auto', $values ) )
$auto = (int)$values[ 'auto' ];
else
$auto = 0;
?> ?>
<tr class="sp-post<?php <tr class="sp-post<?php
if ( $i % 2 == 0 ) if ( $i % 2 == 0 )
@@ -206,15 +211,18 @@ if ( ! function_exists( 'sp_data_table' ) ) {
else else
$value = 0; $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; ?> <?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> </tr>
<?php <?php
$i++; $i++;
endforeach; endforeach;
if ( $total ):
$values = array_key_exists( 0, $data ) ? $data[0] : array();
$auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : 0;
?> ?>
<tr<?php <tr<?php
$values = $data[0];
if ( $i % 2 == 0 ) if ( $i % 2 == 0 )
echo ' class="alternate"'; echo ' class="alternate"';
?>> ?>>
@@ -225,9 +233,11 @@ if ( ! function_exists( 'sp_data_table' ) ) {
else else
$value = 0; $value = 0;
?> ?>
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][0][]" value="<?php echo $value; ?>" /></td> <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; ?> <?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> </tr>
<?php endif; ?>
</tbody> </tbody>
</table> </table>
<?php <?php

View File

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