• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Smarty/libs/plugins/function.html_table.php

00001 <?php
00044 function smarty_function_html_table($params, &$smarty)
00045 {
00046     $table_attr = 'border="1"';
00047     $tr_attr = '';
00048     $td_attr = '';
00049     $cols = 3;
00050     $rows = 3;
00051     $trailpad = '&nbsp;';
00052     $vdir = 'down';
00053     $hdir = 'right';
00054     $inner = 'cols';
00055 
00056     if (!isset($params['loop'])) {
00057         $smarty->trigger_error("html_table: missing 'loop' parameter");
00058         return;
00059     }
00060 
00061     foreach ($params as $_key=>$_value) {
00062         switch ($_key) {
00063             case 'loop':
00064                 $$_key = (array)$_value;
00065                 break;
00066 
00067             case 'cols':
00068             case 'rows':
00069                 $$_key = (int)$_value;
00070                 break;
00071 
00072             case 'table_attr':
00073             case 'trailpad':
00074             case 'hdir':
00075             case 'vdir':
00076             case 'inner':
00077                 $$_key = (string)$_value;
00078                 break;
00079 
00080             case 'tr_attr':
00081             case 'td_attr':
00082                 $$_key = $_value;
00083                 break;
00084         }
00085     }
00086 
00087     $loop_count = count($loop);
00088     if (empty($params['rows'])) {
00089         /* no rows specified */
00090         $rows = ceil($loop_count/$cols);
00091     } elseif (empty($params['cols'])) {
00092         if (!empty($params['rows'])) {
00093             /* no cols specified, but rows */
00094             $cols = ceil($loop_count/$rows);
00095         }
00096     }
00097 
00098     $output = "<table $table_attr>\n";
00099 
00100     for ($r=0; $r<$rows; $r++) {
00101         $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
00102         $rx =  ($vdir == 'down') ? $r*$cols : ($rows-1-$r)*$cols;
00103 
00104         for ($c=0; $c<$cols; $c++) {
00105             $x =  ($hdir == 'right') ? $rx+$c : $rx+$cols-1-$c;
00106             if ($inner!='cols') {
00107                 /* shuffle x to loop over rows*/
00108                 $x = floor($x/$cols) + ($x%$cols)*$rows;
00109             }
00110 
00111             if ($x<$loop_count) {
00112                 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n";
00113             } else {
00114                 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">$trailpad</td>\n";
00115             }
00116         }
00117         $output .= "</tr>\n";
00118     }
00119     $output .= "</table>\n";
00120     
00121     return $output;
00122 }
00123 
00124 function smarty_function_html_table_cycle($name, $var, $no) {
00125     if(!is_array($var)) {
00126         $ret = $var;
00127     } else {
00128         $ret = $var[$no % count($var)];
00129     }
00130     
00131     return ($ret) ? ' '.$ret : '';
00132 }
00133 
00134 
00135 /* vim: set expandtab: */
00136 
00137 ?>

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2