Example #1
0
function baw_display_list_icons($section, $exclude, $btn)
{
    global $BAW_CONF_DIS, $BAW_CONF_DIS_DEF, $BAW_CONF, $BAW_MES, $BAW_CURR, $BAW_MES;
    if ($btn) {
        $btn_str = '_btn';
    } else {
        $btn_str = '';
    }
    $links_arr = array('info' => array('check' => @$BAW_MES["hlp_{$section}"], 'image' => $BAW_CONF['site_url'] . "/icons/help.png", 'msg' => htmlentities(@$BAW_MES["hlp_{$section}"]), 'what' => 'span'), 'full_list' => array('check' => @$BAW_CONF_DIS[$section]['top_x'], 'image' => $BAW_CONF['site_url'] . "/icons/fulllist{$btn_str}.png", 'msg' => $BAW_MES[80], 'what' => $section), 'versions' => array('check' => @$BAW_CONF_DIS_DEF[$section]['hasversions'], 'image' => $BAW_CONF['site_url'] . "/icons/versions{$btn_str}.png", 'msg' => $BAW_MES['version_info'], 'what' => @$BAW_CONF_DIS_DEF[$section]['hasversions']), 'unknown' => array('check' => @$BAW_CONF_DIS_DEF[$section]['hasunknown'], 'image' => $BAW_CONF['site_url'] . "/icons/unknown{$btn_str}.png", 'msg' => $BAW_MES['unknown_list'], 'what' => @$BAW_CONF_DIS_DEF[$section]['hasunknown']));
    $out = '';
    $i = 1;
    foreach ($links_arr as $link => $settings) {
        if (!in_array($link, $exclude) && isset($settings['check'])) {
            $icon = baw_create_image($settings['image'], array('title' => $settings['msg'], 'alt' => $settings['msg'])) . " ";
            $class = "icon_indent_{$i}";
            // we indent more for each icon
            if ($link == 'info') {
                // we have a hover-text
                $out .= "    <span class=\"section_help {$class}\">{$icon}<span>{$settings['msg']}</span></span>\n";
                $i++;
            } else {
                // we have a link
                $out .= "            " . baw_display_list_link($icon, $settings['msg'], $settings['what'], $class) . "\n";
                $i++;
            }
        }
    }
    return $out;
}
Example #2
0
function baw_render_table($section_name, $table, $format, $get_avg = false, $get_sum = false, $top_x = false, $dataformat = false)
{
    global $BAW_CONF, $BAW_LIB, $BAW_MES, $BAW_CONF_DIS;
    baw_debug("rendering table");
    $out = '';
    $theader = "\n<table class=\"datatable\">\n";
    // HEADER -----------------------------------------------------------------
    $out .= "    <tr>\n";
    $format_arr = array();
    $column = 0;
    $itemcount = count($table);
    $ratio_set = array();
    // iterate formats for header
    foreach ($format as $cell => $attr) {
        $class = '';
        $tags = '';
        $percent_header = '';
        // iterate one formats attributes
        foreach ($attr as $name => $value) {
            if ($name == 'title') {
                $data = $value;
            } else {
                if ($name == 'format') {
                    $format_arr[] = $value;
                    $class_arr[] = $value;
                    $class = " {$value}";
                } else {
                    if ($name == 'ratio') {
                        $ratio_set[$cell] = $value;
                        // percentage header insert ... this could be set per column in the config?
                    } else {
                        if ($name == 'percent' && $value) {
                            $percent_header = "        <th class=\"layout_percent\">{$BAW_MES[15]}</th>\n";
                        } else {
                            if (strlen($value) > 0) {
                                $tags .= " {$name}=\"{$value}\"";
                            }
                        }
                    }
                }
            }
        }
        // find out how many items in whole table
        if ($column == 0) {
            // add only to first column
            $data = sprintf($BAW_MES['records'], baw_num_format($itemcount));
        }
        if (isset($attr['title'])) {
            $out .= "        <th class=\"header_wrap{$class}\"{$tags}>{$data}</th>\n{$percent_header}";
            $column++;
        }
    }
    $out .= "    </tr>\n";
    // SUM & averages calculation ----------------------------------------------
    // the sum has to be calculated before so the percentages can be calculated
    // iterate all the table and count the sums of all numeric data
    $sum_arr = array(0 => $BAW_MES[102]);
    // we set the text here to make sure its in the right position
    $avg_arr = array(0 => $BAW_MES[96]);
    $others = array();
    $filled_lines = $itemcount;
    // get the value for substraction
    $row_no = 0;
    $othercount = 0;
    $hasothers = false;
    foreach ($table as $lineid => $row) {
        $cell_no = 0;
        $rowsum = 0;
        foreach ($row as $cell) {
            // sum calculation
            $sum_arr[$cell_no] = baw_process_cell($cell, @$format_arr[$cell_no], @$sum_arr[$cell_no]);
            // average calculation
            if (is_numeric($cell) && $get_avg) {
                $rowsum += $cell;
                if ($row_no == $itemcount - 1 && $filled_lines >= 1) {
                    // last line, assume sums are done
                    if ($rowsum == 0 && $cell_no == 0) {
                        // do once again for last line, dont substract further after first cell
                        $filled_lines--;
                    }
                    if ($format_arr[$cell_no] == 'layout_date') {
                        $avg_arr[$cell_no] = false;
                        // this will prevent formatting, averages on date not possible?
                    } else {
                        $avg_arr[$cell_no] = $sum_arr[$cell_no] / $filled_lines;
                    }
                }
            } else {
                if ($get_avg) {
                    $avg_arr[$cell_no] = '';
                }
            }
            // others calculation
            if ($top_x && $row_no >= $top_x) {
                $hasothers = true;
                $others[$cell_no] = baw_process_cell($cell, @$format_arr[$cell_no], @$others[$cell_no]);
            }
            $cell_no++;
        }
        // we processes the line, if we are already in the 'others' remove the line
        if ($hasothers) {
            $othercount++;
            unset($table[$lineid]);
        }
        // remove one line from avg-count if data empty
        if ($rowsum == 0) {
            $filled_lines--;
        }
        $row_no++;
        // count to find out if we are ready to do averages
    }
    // add others to the table
    if ($hasothers) {
        // we got others, add them to the end
        if ($top_x < $BAW_CONF['maxlines']) {
            $text = baw_display_list_link($BAW_MES[2], $BAW_MES[2], $section_name, false, 'full_list') . " (" . baw_num_format($othercount) . ")";
        } else {
            $text = $BAW_MES[2] . " (" . baw_num_format($othercount) . ")<br>" . sprintf($BAW_MES['table_max_hits_exceed'], baw_num_format($BAW_CONF['maxlines']));
        }
        $others = baw_calc_ratio($others, $ratio_set);
        $others[0] = $text;
        $table += array('layout_others' => $others);
    }
    // add averages to the table
    if ($get_avg) {
        // re-set the value here since it might have been overwritten
        $avg_arr[0] = $BAW_MES[96];
        $avg_arr = baw_calc_ratio($avg_arr, $ratio_set);
        $table += array('layout_avg' => $avg_arr);
    }
    // add the sum to the table
    if ($get_sum) {
        $sum_arr[0] = $BAW_MES[102];
        $sum_arr = baw_calc_ratio($sum_arr, $ratio_set);
        $table += array('layout_sum' => $sum_arr);
    }
    // these are set later to make sure they are not overwritten in the func before
    // this saves one more check
    // DATA --------------------------------------------------------------------
    $lastlineid = '';
    $rowspan = array();
    foreach ($table as $lineid => $row) {
        $cell_no = 0;
        $class = '';
        // get the class for the whole row
        if (isset($dataformat[$lineid])) {
            $class = " class=\"{$dataformat[$lineid]}\"";
            // for some _STRANGE_ reason, the 403-error lineid is equal to the string here, so use ===
        } else {
            if ($lineid === 'layout_others' || $lineid === 'layout_avg' || $lineid === 'layout_sum') {
                $class = " class=\"{$lineid}\"";
            }
        }
        $out .= "    <tr{$class}>\n";
        $iteration = 0;
        foreach ($row as $cell) {
            $class = '';
            // get the class for the column (set by field)
            // for some _STRANGE_ reason, the 403-error lineid is equal to the string here, so use ===
            if ($lineid === 'layout_others' || $lineid === 'layout_avg' || $lineid === 'layout_sum') {
                $span = 0;
                $attr = '';
                if ($cell_no > $iteration) {
                    $iteration++;
                    continue;
                }
                if (isset($format[$cell_no]['colspan'])) {
                    $span = $format[$cell_no]['colspan'];
                    $class .= " colspan=\"{$span}\"";
                    $span--;
                    $cell_no += $span;
                }
                $iteration++;
            } else {
                $class = '';
            }
            // check if the row has data, otherwise remove 1 line for average count
            $function = $BAW_LIB['formats'][$format_arr[$cell_no]]['frm'];
            $cell_str = exec_function($function, $cell);
            if (isset($class_arr[$cell_no]) && strlen($class_arr[$cell_no]) > 0) {
                $class .= " class=\"{$class_arr[$cell_no]}\"";
            }
            // do rowspan
            $doline = true;
            $rowspan_str = '';
            if ($format_arr[$cell_no] === 'layout_text' && ($lineid !== 'layout_others' && $lineid !== 'layout_avg' && $lineid !== 'layout_sum')) {
                if (isset($table[$lastlineid][$cell_no]) && $cell === $table[$lastlineid][$cell_no]) {
                    $rowspan[$lineid][$cell_no] = $rowspan[$lastlineid][$cell_no] + 1;
                    $search = " rowspan=\"{$rowspan[$lastlineid][$cell_no]}\">{$cell_str}</td>";
                    $replace = " rowspan=\"{$rowspan[$lineid][$cell_no]}\">{$cell_str}</td>";
                    // we search the last time we had this data and replace it
                    $pos = strrpos($out, $search);
                    $out = substr_replace($out, $replace, $pos, strlen($search));
                    $doline = false;
                } else {
                    // no match, restart with 1
                    $rowspan_str = ' rowspan="1"';
                    // do =1 always so we can replace later
                    $rowspan[$lineid][$cell_no] = 1;
                }
            }
            if ($doline) {
                $out .= "        <td{$class}{$rowspan_str}>{$cell_str}</td>\n";
            }
            if (isset($format[$cell_no]['percent']) && $format[$cell_no]['percent'] == true && $sum_arr[$cell_no] !== 0) {
                $percent = $cell / ($sum_arr[$cell_no] / 100);
                $out .= "        <td{$class}>" . @baw_percent_format($percent) . "</td>\n";
            }
            $cell_no++;
        }
        $lastlineid = $lineid;
        $out .= "    </tr>\n";
    }
    $out .= "</table>\n";
    baw_debug("rendering table finished");
    return $theader . $out;
}