function smarty_function_html_table($params, &$smarty)
{
    $table_attr = 'border="1"';
    $tr_attr = '';
    $td_attr = '';
    $cols = 3;
    $trailpad = ' ';
    extract($params);
    if (!isset($loop)) {
        $smarty->trigger_error("html_table: missing 'loop' parameter");
        return;
    }
    $output = "<table {$table_attr}>\n";
    $output .= "<tr " . smarty_function_html_table_cycle('tr', $tr_attr) . ">\n";
    for ($x = 0, $y = count($loop); $x < $y; $x++) {
        $output .= "<td " . smarty_function_html_table_cycle('td', $td_attr) . ">" . $loop[$x] . "</td>\n";
        if (!(($x + 1) % $cols) && $x < $y - 1) {
            // go to next row
            $output .= "</tr>\n<tr " . smarty_function_html_table_cycle('tr', $tr_attr) . ">\n";
        }
        if ($x == $y - 1) {
            // last row, pad remaining cells
            $cells = $cols - $y % $cols;
            if ($cells != $cols) {
                for ($padloop = 0; $padloop < $cells; $padloop++) {
                    $output .= "<td " . smarty_function_html_table_cycle('td', $td_attr) . ">{$trailpad}</td>\n";
                }
            }
            $output .= "</tr>\n";
        }
    }
    $output .= "</table>\n";
    return $output;
}
/**
 * Smarty {html_table} function plugin
 *
 * Type:     function<br>
 * Name:     html_table<br>
 * Date:     Feb 17, 2003<br>
 * Purpose:  make an html table from an array of data<br>
 * Input:<br>
 *         - loop = array to loop through
 *         - cols = number of columns
 *         - rows = number of rows
 *         - table_attr = table attributes
 *         - tr_attr = table row attributes (arrays are cycled)
 *         - td_attr = table cell attributes (arrays are cycled)
 *         - trailpad = value to pad trailing cells with
 *         - vdir = vertical direction (default: "down", means top-to-bottom)
 *         - hdir = horizontal direction (default: "right", means left-to-right)
 *         - inner = inner loop (default "cols": print $loop line by line,
 *                   $loop will be printed column by column otherwise)
 *
 *
 * Examples:
 * <pre>
 * {table loop=$data}
 * {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
 * {table loop=$data cols=4 tr_attr=$colors}
 * </pre>
 * @author   Monte Ohrt <*****@*****.**>
 * @version  1.0
 * @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}
 *          (Smarty online manual)
 * @param array
 * @param Smarty
 * @return string
 */
function smarty_function_html_table($params, &$smarty)
{
    $table_attr = 'border="1"';
    $tr_attr = '';
    $td_attr = '';
    $cols = 3;
    $rows = 3;
    $trailpad = '&nbsp;';
    $vdir = 'down';
    $hdir = 'right';
    $inner = 'cols';
    extract($params);
    if (!isset($loop)) {
        $smarty->trigger_error("html_table: missing 'loop' parameter");
        return;
    }
    $loop_count = count($loop);
    if (empty($params['rows'])) {
        /* no rows specified */
        $rows = ceil($loop_count / $cols);
    } elseif (empty($params['cols'])) {
        if (!empty($params['rows'])) {
            /* no cols specified, but rows */
            $cols = ceil($loop_count / $rows);
        }
    }
    $output = "<table {$table_attr}>\n";
    for ($r = 0; $r < $rows; $r++) {
        $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
        $rx = $vdir == 'down' ? $r * $cols : ($rows - 1 - $r) * $cols;
        for ($c = 0; $c < $cols; $c++) {
            $x = $hdir == 'right' ? $rx + $c : $rx + $cols - 1 - $c;
            if ($inner != 'cols') {
                /* shuffle x to loop over rows*/
                $x = floor($x / $cols) + $x % $cols * $rows;
            }
            if ($x < $loop_count) {
                $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n";
            } else {
                $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">{$trailpad}</td>\n";
            }
        }
        $output .= "</tr>\n";
    }
    $output .= "</table>\n";
    return $output;
}
/**
 * Smarty {html_table} function plugin
 *
 * Type:     function<br>
 * Name:     html_table<br>
 * Date:     Feb 17, 2003<br>
 * Purpose:  make an html table from an array of data<br>
 * Input:<br>
 *         - loop = array to loop through
 *         - cols = number of columns, comma separated list of column names
 *                  or array of column names
 *         - rows = number of rows
 *         - table_attr = table attributes
 *         - th_attr = table heading attributes (arrays are cycled)
 *         - tr_attr = table row attributes (arrays are cycled)
 *         - td_attr = table cell attributes (arrays are cycled)
 *         - trailpad = value to pad trailing cells with
 *         - caption = text for caption element 
 *         - vdir = vertical direction (default: "down", means top-to-bottom)
 *         - hdir = horizontal direction (default: "right", means left-to-right)
 *         - inner = inner loop (default "cols": print $loop line by line,
 *                   $loop will be printed column by column otherwise)
 *
 *
 * Examples:
 * <pre>
 * {table loop=$data}
 * {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
 * {table loop=$data cols="first,second,third" tr_attr=$colors}
 * </pre>
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @author credit to Messju Mohr <messju at lammfellpuschen dot de>
 * @author credit to boots <boots dot Smarty at yahoo dot com>
 * @version  1.1
 * @link http://Smarty.php.net/manual/en/language.function.html.table.php {html_table}
 *          (Smarty online manual)
 * @param array
 * @param smarty
 * @return string
 */
function smarty_function_html_table($params, &$smarty)
{
    $table_attr = 'border="1"';
    $tr_attr = '';
    $th_attr = '';
    $td_attr = '';
    $cols = $cols_count = 3;
    $rows = 3;
    $trailpad = '&nbsp;';
    $vdir = 'down';
    $hdir = 'right';
    $inner = 'cols';
    $caption = '';
    if (!isset($params['loop'])) {
        $smarty->trigger_error("html_table: missing 'loop' parameter");
        return;
    }
    foreach ($params as $_key => $_value) {
        switch ($_key) {
            case 'loop':
                ${$_key} = (array) $_value;
                break;
            case 'cols':
                if (is_array($_value) && !empty($_value)) {
                    $cols = $_value;
                    $cols_count = count($_value);
                } elseif (!is_numeric($_value) && is_string($_value) && !empty($_value)) {
                    $cols = explode(',', $_value);
                    $cols_count = count($cols);
                } elseif (!empty($_value)) {
                    $cols_count = (int) $_value;
                } else {
                    $cols_count = $cols;
                }
                break;
            case 'rows':
                ${$_key} = (int) $_value;
                break;
            case 'table_attr':
            case 'trailpad':
            case 'hdir':
            case 'vdir':
            case 'inner':
            case 'caption':
                ${$_key} = (string) $_value;
                break;
            case 'tr_attr':
            case 'td_attr':
            case 'th_attr':
                ${$_key} = $_value;
                break;
        }
    }
    $loop_count = count($loop);
    if (empty($params['rows'])) {
        /* no rows specified */
        $rows = ceil($loop_count / $cols_count);
    } elseif (empty($params['cols'])) {
        if (!empty($params['rows'])) {
            /* no cols specified, but rows */
            $cols_count = ceil($loop_count / $rows);
        }
    }
    $output = "<table {$table_attr}>\n";
    if (!empty($caption)) {
        $output .= '<caption>' . $caption . "</caption>\n";
    }
    if (is_array($cols)) {
        $cols = $hdir == 'right' ? $cols : array_reverse($cols);
        $output .= "<thead><tr>\n";
        for ($r = 0; $r < $cols_count; $r++) {
            $output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>';
            $output .= $cols[$r];
            $output .= "</th>\n";
        }
        $output .= "</tr></thead>\n";
    }
    $output .= "<tbody>\n";
    for ($r = 0; $r < $rows; $r++) {
        $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
        $rx = $vdir == 'down' ? $r * $cols_count : ($rows - 1 - $r) * $cols_count;
        for ($c = 0; $c < $cols_count; $c++) {
            $x = $hdir == 'right' ? $rx + $c : $rx + $cols_count - 1 - $c;
            if ($inner != 'cols') {
                /* shuffle x to loop over rows*/
                $x = floor($x / $cols_count) + $x % $cols_count * $rows;
            }
            if ($x < $loop_count) {
                $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n";
            } else {
                $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">{$trailpad}</td>\n";
            }
        }
        $output .= "</tr>\n";
    }
    $output .= "</tbody>\n";
    $output .= "</table>\n";
    return $output;
}
Ejemplo n.º 4
0
/**
 * Smarty {html_table} function plugin
 *
 * Type:     function<br>
 * Name:     html_table<br>
 * Date:     Feb 17, 2003<br>
 * Purpose:  make an html table from an array of data<br>
 * Params:
 * <pre>
 * - loop       - array to loop through
 * - cols       - number of columns, comma separated list of column names
 *                or array of column names
 * - rows       - number of rows
 * - table_attr - table attributes
 * - th_attr    - table heading attributes (arrays are cycled)
 * - tr_attr    - table row attributes (arrays are cycled)
 * - td_attr    - table cell attributes (arrays are cycled)
 * - trailpad   - value to pad trailing cells with
 * - caption    - text for caption element
 * - vdir       - vertical direction (default: "down", means top-to-bottom)
 * - hdir       - horizontal direction (default: "right", means left-to-right)
 * - inner      - inner loop (default "cols": print $options['loop'] line by line,
 *                $options['loop'] will be printed column by column otherwise)
 * </pre>
 * Examples:
 * <pre>
 * {table loop=$data}
 * {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
 * {table loop=$data cols="first,second,third" tr_attr=$colors}
 * </pre>
 *
 * @author Monte Ohrt <monte at ohrt dot com>
 * @author credit to Messju Mohr <messju at lammfellpuschen dot de>
 * @author credit to boots <boots dot smarty at yahoo dot com>
 * @version 1.1
 * @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table}
 *          (Smarty online manual)
 * @param array                    $params   parameters
 * @param Template $template template object
 * @return string
 */
function smarty_function_html_table($params, $template)
{
    $template->assert_is_not_strict('`{html_table}` is a deprecated plugin and is not allowed in strict mode');
    $options = array('table_attr' => 'border="1"', 'tr_attr' => '', 'th_attr' => '', 'td_attr' => '', 'cols' => 3, 'cols_count' => 3, 'rows' => 3, 'trailpad' => '&nbsp;', 'vdir' => 'down', 'hdir' => 'right', 'inner' => 'cols', 'caption' => '', 'loop' => null);
    if (!isset($params['loop'])) {
        trigger_error("html_table: missing 'loop' parameter", E_USER_WARNING);
        return;
    }
    foreach ($params as $_key => $_value) {
        switch ($_key) {
            case 'loop':
                $options[$_key] = (array) $_value;
                break;
            case 'cols':
                if (is_array($_value) && !empty($_value)) {
                    $options['cols'] = $_value;
                    $cols_count = count($_value);
                } elseif (!is_numeric($_value) && is_string($_value) && !empty($_value)) {
                    $options['cols'] = explode(',', $_value);
                    $cols_count = count($options['cols']);
                } elseif (!empty($_value)) {
                    $cols_count = (int) $_value;
                } else {
                    $cols_count = $options['cols'];
                }
                break;
            case 'rows':
                $options[$_key] = (int) $_value;
                break;
            case 'table_attr':
            case 'trailpad':
            case 'hdir':
            case 'vdir':
            case 'inner':
            case 'caption':
                $options[$_key] = (string) $_value;
                break;
            case 'tr_attr':
            case 'td_attr':
            case 'th_attr':
                $options[$_key] = $_value;
                break;
        }
    }
    $loop_count = count($options['loop']);
    if (empty($params['rows'])) {
        /* no rows specified */
        $options['rows'] = ceil($loop_count / $cols_count);
    } elseif (empty($params['cols'])) {
        if (!empty($params['rows'])) {
            /* no cols specified, but rows */
            $cols_count = ceil($loop_count / $options['rows']);
        }
    }
    $output = "<table {$options['table_attr']}>\n";
    if (!empty($options['caption'])) {
        $output .= '<caption>' . $options['caption'] . "</caption>\n";
    }
    if (is_array($options['cols'])) {
        $options['cols'] = $options['hdir'] == 'right' ? $options['cols'] : array_reverse($options['cols']);
        $output .= "<thead><tr>\n";
        for ($r = 0; $r < $cols_count; $r++) {
            $output .= '<th' . smarty_function_html_table_cycle('th', $options['th_attr'], $r) . '>';
            $output .= $options['cols'][$r];
            $output .= "</th>\n";
        }
        $output .= "</tr></thead>\n";
    }
    $output .= "<tbody>\n";
    for ($r = 0; $r < $options['rows']; $r++) {
        $output .= "<tr" . smarty_function_html_table_cycle('tr', $options['tr_attr'], $r) . ">\n";
        $rx = $options['vdir'] == 'down' ? $r * $cols_count : ($options['rows'] - 1 - $r) * $cols_count;
        for ($c = 0; $c < $cols_count; $c++) {
            $x = $options['hdir'] == 'right' ? $rx + $c : $rx + $cols_count - 1 - $c;
            if ($options['inner'] != 'cols') {
                /* shuffle x to loop over rows*/
                $x = floor($x / $cols_count) + $x % $cols_count * $options['rows'];
            }
            if ($x < $loop_count) {
                $output .= "<td" . smarty_function_html_table_cycle('td', $options['td_attr'], $c) . ">" . $options['loop'][$x] . "</td>\n";
            } else {
                $output .= "<td" . smarty_function_html_table_cycle('td', $options['td_attr'], $c) . ">{$options['trailpad']}</td>\n";
            }
        }
        $output .= "</tr>\n";
    }
    $output .= "</tbody>\n";
    $output .= "</table>\n";
    return $output;
}
/**
 * Smarty {html_table} function plugin
 *
 * Type:     function<br>
 * Name:     html_table<br>
 * Date:     Feb 17, 2003<br>
 * Purpose:  make an html table from an array of data<br>
 * Input:<br>
 *         - loop = array to loop through
 *         - cols = number of columns, comma separated list of column names
 *                  or array of column names
 *         - rows = number of rows
 *         - table_attr = table attributes
 *         - th_attr = table heading attributes (arrays are cycled)
 *         - tr_attr = table row attributes (arrays are cycled)
 *         - td_attr = table cell attributes (arrays are cycled)
 *         - trailpad = value to pad trailing cells with
 *         - caption = text for caption element 
 *         - vdir = vertical direction (default: "down", means top-to-bottom)
 *         - hdir = horizontal direction (default: "right", means left-to-right)
 *         - inner = inner loop (default "cols": print $loop line by line,
 *                   $loop will be printed column by column otherwise)
 *
 *
 * Examples:
 * <pre>
 * {table loop=$data}
 * {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
 * {table loop=$data cols="first,second,third" tr_attr=$colors}
 * </pre>
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @author credit to Messju Mohr <messju at lammfellpuschen dot de>
 * @author credit to boots <boots dot smarty at yahoo dot com>
 * @author modified by Paul Bukowski <*****@*****.**>
 * @version  1.1
 * @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}
 *          (Smarty online manual)
 * @param array
 * @param Smarty
 * @return string
 */
function smarty_function_html_scrolled_table_epesi($params, &$smarty)
{
    $table_attr = 'border="1"';
    $tr_attr = '';
    $th_attr = '';
    $td_attr = '';
    $cols = $cols_count = 3;
    $rows = 3;
    $trailpad = '&nbsp;';
    $vdir = 'down';
    $hdir = 'right';
    $inner = 'cols';
    $caption = '';
    $height = '300';
    if (!isset($params['loop'])) {
        $smarty->trigger_error("html_table: missing 'loop' parameter");
        return;
    }
    foreach ($params as $_key => $_value) {
        switch ($_key) {
            case 'loop':
                $loop = array();
                $td_attr = array();
                foreach ($_value as $k => $v) {
                    $loop[] = $v['label'];
                    $td_attr[] = $v['attrs'];
                }
                break;
            case 'cols':
                if (is_array($_value) && !empty($_value)) {
                    $cols = array();
                    $th_attr = array();
                    foreach ($_value as $k => $v) {
                        $cols[] = $v['label'];
                        $th_attr[] = $v['attrs'];
                    }
                    $cols_count = count($cols);
                } elseif (!is_numeric($_value) && is_string($_value) && !empty($_value)) {
                    $cols = explode(',', $_value);
                    $cols_count = count($cols);
                } elseif (!empty($_value)) {
                    $cols_count = (int) $_value;
                } else {
                    $cols_count = $cols;
                }
                break;
            case 'rows':
                ${$_key} = (int) $_value;
                break;
            case 'table_attr':
            case 'trailpad':
            case 'hdir':
            case 'vdir':
            case 'inner':
            case 'height':
            case 'caption':
                ${$_key} = (string) $_value;
                break;
            case 'tr_attr':
                ${$_key} = $_value;
                break;
        }
    }
    $loop_count = count($loop);
    if (empty($params['rows'])) {
        /* no rows specified */
        $rows = ceil($loop_count / $cols_count);
    } elseif (empty($params['cols'])) {
        if (!empty($params['rows'])) {
            /* no cols specified, but rows */
            $cols_count = ceil($loop_count / $rows);
        }
    }
    $output = "<table {$table_attr} rel='scrolled_table' body_height='{$height}'>\n";
    if (!empty($caption)) {
        $output .= '<caption>' . $caption . "</caption>\n";
    }
    if (is_array($cols)) {
        $cols = $hdir == 'right' ? $cols : array_reverse($cols);
        $output .= "<thead><tr>\n";
        for ($r = 0; $r < $cols_count; $r++) {
            $output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>';
            $output .= $cols[$r];
            $output .= "</th>\n";
        }
        $output .= "</tr></thead>\n";
    }
    $output .= "<tbody>\n";
    for ($r = 0; $r < $rows; $r++) {
        $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r);
        if (isset($params['row_attrs'][$r])) {
            $output .= ' ' . $params['row_attrs'][$r];
        }
        $output .= ">\n";
        $rx = $vdir == 'down' ? $r * $cols_count : ($rows - 1 - $r) * $cols_count;
        for ($c = 0; $c < $cols_count; $c++) {
            $x = $hdir == 'right' ? $rx + $c : $rx + $cols_count - 1 - $c;
            if ($inner != 'cols') {
                /* shuffle x to loop over rows*/
                $x = floor($x / $cols_count) + $x % $cols_count * $rows;
            }
            if ($x < $loop_count) {
                $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $x) . ">" . $loop[$x] . "</td>\n";
            } else {
                $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $x) . ">{$trailpad}</td>\n";
            }
        }
        $output .= "</tr>\n";
    }
    $output .= "</tbody>\n";
    $output .= "</table>\n";
    load_js('modules/Base/Theme/smarty/plugins/function.html_scrolled_table_epesi.js');
    eval_js('libs_theme__scrolled_table_fix_cols()');
    return $output;
}
/**
 * Smarty {html_table} function plugin
 *
 * Type:     function<br/>
 * Name:     html_table<br/>
 * Date:     Feb 17, 2003<br/>
 * Purpose:  make an html table from an array of data<br/>
 * Input:<br/>
 *         - loop = array to loop through
 *         - cols = number of columns
 *         - rows = number of rows
 *         - table_attr = table attributes
 *         - tr_attr = table row attributes (arrays are cycled)
 *         - td_attr = table cell attributes (arrays are cycled)
 *         - trailpad = value to pad trailing cells with
 *         - vdir = vertical direction (default: "down", means top-to-bottom)
 *         - hdir = horizontal direction (default: "right", means left-to-right)
 *         - inner = inner loop (default "cols": print $loop line by line,
 *                   $loop will be printed column by column otherwise)
 *
 *
 * Examples:
 * <pre>
 * {table loop=$data}
 * {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
 * {table loop=$data cols=4 tr_attr=$colors}
 * </pre>
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @version  1.0
 * @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}
 *          (Smarty online manual)
 * @param array
 * @param Smarty
 * @return string
 */
function smarty_function_html_table($params, &$smarty)
{
    $table_attr = 'border="1"';
    $tr_attr = '';
    $td_attr = '';
    $cols = 3;
    $rows = 3;
    $trailpad = HTML_NBSP;
    $vdir = 'down';
    $hdir = 'right';
    $inner = 'cols';
    if (!isset($params['loop'])) {
        $smarty->trigger_error("html_table: missing 'loop' parameter");
        return;
    }
    foreach ($params as $_key => $_value) {
        switch ($_key) {
            case 'loop':
                ${$_key} = (array) $_value;
                break;
            case 'cols':
            case 'rows':
                ${$_key} = (int) $_value;
                break;
            case 'table_attr':
            case 'trailpad':
            case 'hdir':
            case 'vdir':
            case 'inner':
                ${$_key} = (string) $_value;
                break;
            case 'tr_attr':
            case 'td_attr':
                ${$_key} = $_value;
                break;
        }
    }
    $loop_count = count($loop);
    if (empty($params['rows'])) {
        /* no rows specified */
        $rows = ceil($loop_count / $cols);
    } elseif (empty($params['cols'])) {
        if (!empty($params['rows'])) {
            /* no cols specified, but rows */
            $cols = ceil($loop_count / $rows);
        }
    }
    $output = "<table {$table_attr}>\n";
    for ($r = 0; $r < $rows; $r++) {
        $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
        $rx = $vdir == 'down' ? $r * $cols : ($rows - 1 - $r) * $cols;
        for ($c = 0; $c < $cols; $c++) {
            $x = $hdir == 'right' ? $rx + $c : $rx + $cols - 1 - $c;
            if ($inner != 'cols') {
                /* shuffle x to loop over rows*/
                $x = floor($x / $cols) + $x % $cols * $rows;
            }
            if ($x < $loop_count) {
                $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n";
            } else {
                $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">{$trailpad}</td>\n";
            }
        }
        $output .= "</tr>\n";
    }
    $output .= "</table>\n";
    return $output;
}