diff --git a/core/helper_api.php b/core/helper_api.php index 493a59be27..97f315d881 100644 --- a/core/helper_api.php +++ b/core/helper_api.php @@ -76,6 +76,28 @@ function helper_alternate_colors( $p_index, $p_odd_color, $p_even_color ) { } } +/** + * alternate classes for table rows + * If no index is given, continue alternating based on the last index given + * @param int $p_index + * @param string $p_odd_class default: row-1 + * @param string $p_even_class default: row-2 + * @return string + */ +function helper_alternate_class( $p_index = null, $p_odd_class = 'row-1', $p_even_class = 'row-2' ) { + static $t_index = 1; + + if( null !== $p_index ) { + $t_index = $p_index; + } + + if( 1 == $t_index++ % 2 ) { + return "class=\"$p_odd_class\""; + } else { + return "class=\"$p_even_class\""; + } +} + /** * Transpose a bidimensional array *