00001 <?php 00049 function smarty_function_html_table($params, &$smarty) 00050 { 00051 $table_attr = 'border="1"'; 00052 $tr_attr = ''; 00053 $th_attr = ''; 00054 $td_attr = ''; 00055 $cols = $cols_count = 3; 00056 $rows = 3; 00057 $trailpad = ' '; 00058 $vdir = 'down'; 00059 $hdir = 'right'; 00060 $inner = 'cols'; 00061 $caption = ''; 00062 00063 if (!isset($params['loop'])) { 00064 $smarty->trigger_error("html_table: missing 'loop' parameter"); 00065 return; 00066 } 00067 00068 foreach ($params as $_key=>$_value) { 00069 switch ($_key) { 00070 case 'loop': 00071 $$_key = (array)$_value; 00072 break; 00073 00074 case 'cols': 00075 if (is_array($_value) && !empty($_value)) { 00076 $cols = $_value; 00077 $cols_count = count($_value); 00078 } elseif (!is_numeric($_value) && is_string($_value) && !empty($_value)) { 00079 $cols = explode(',', $_value); 00080 $cols_count = count($cols); 00081 } elseif (!empty($_value)) { 00082 $cols_count = (int)$_value; 00083 } else { 00084 $cols_count = $cols; 00085 } 00086 break; 00087 00088 case 'rows': 00089 $$_key = (int)$_value; 00090 break; 00091 00092 case 'table_attr': 00093 case 'trailpad': 00094 case 'hdir': 00095 case 'vdir': 00096 case 'inner': 00097 case 'caption': 00098 $$_key = (string)$_value; 00099 break; 00100 00101 case 'tr_attr': 00102 case 'td_attr': 00103 case 'th_attr': 00104 $$_key = $_value; 00105 break; 00106 } 00107 } 00108 00109 $loop_count = count($loop); 00110 if (empty($params['rows'])) { 00111 /* no rows specified */ 00112 $rows = ceil($loop_count/$cols_count); 00113 } elseif (empty($params['cols'])) { 00114 if (!empty($params['rows'])) { 00115 /* no cols specified, but rows */ 00116 $cols_count = ceil($loop_count/$rows); 00117 } 00118 } 00119 00120 $output = "<table $table_attr>\n"; 00121 00122 if (!empty($caption)) { 00123 $output .= '<caption>' . $caption . "</caption>\n"; 00124 } 00125 00126 if (is_array($cols)) { 00127 $cols = ($hdir == 'right') ? $cols : array_reverse($cols); 00128 $output .= "<thead><tr>\n"; 00129 00130 for ($r=0; $r<$cols_count; $r++) { 00131 $output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>'; 00132 $output .= $cols[$r]; 00133 $output .= "</th>\n"; 00134 } 00135 $output .= "</tr></thead>\n"; 00136 } 00137 00138 $output .= "<tbody>\n"; 00139 for ($r=0; $r<$rows; $r++) { 00140 $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n"; 00141 $rx = ($vdir == 'down') ? $r*$cols_count : ($rows-1-$r)*$cols_count; 00142 00143 for ($c=0; $c<$cols_count; $c++) { 00144 $x = ($hdir == 'right') ? $rx+$c : $rx+$cols_count-1-$c; 00145 if ($inner!='cols') { 00146 /* shuffle x to loop over rows*/ 00147 $x = floor($x/$cols_count) + ($x%$cols_count)*$rows; 00148 } 00149 00150 if ($x<$loop_count) { 00151 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n"; 00152 } else { 00153 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">$trailpad</td>\n"; 00154 } 00155 } 00156 $output .= "</tr>\n"; 00157 } 00158 $output .= "</tbody>\n"; 00159 $output .= "</table>\n"; 00160 00161 return $output; 00162 } 00163 00164 function smarty_function_html_table_cycle($name, $var, $no) { 00165 if(!is_array($var)) { 00166 $ret = $var; 00167 } else { 00168 $ret = $var[$no % count($var)]; 00169 } 00170 00171 return ($ret) ? ' '.$ret : ''; 00172 } 00173 00174 00175 /* vim: set expandtab: */ 00176 00177 ?>
| Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|
