/** * * @param $data * Page and hit data for each country * @param $top_x * The number of domains to display. If false, display all. * * @return * A string containing the HTML to include an image of the map. */ function baw_render_map($data, $top_x = false) { global $BAW_CONF; // if we don't have GD2 functions, we can't generate the image baw_debug("rendering map"); if (!function_exists('imagecreatetruecolor')) { echo baw_raise_error('gd2notavailable', array()); return; } $im = $BAW_CONF['site_path'] . '/icons/wmap.png'; if (!file_exists($im)) { echo baw_raise_error('mapnotavailable', array($im)); } // fix data for geography $us_domains = array('us', 'mil', 'edu', 'gov', 'arpa'); foreach ($us_domains as $us_domain) { if (isset($data[$us_domain][3])) { if (!isset($data['us'])) { $data['us'] = array(0, 0, 0, 0, 0); } $data['us'][3] += $data[$us_domain][3]; } if (isset($data[$us_domain][4])) { if (!isset($data['us'])) { $data['us'] = array(0, 0, 0, 0, 0); } $data['us'][4] += $data[$us_domain][4]; } } $new_data = ''; $doms = 0; foreach ($data as $country => $vars) { if ($doms >= $top_x && $top_x !== false) { break; } $new_data .= "&c[{$country}][0]={$vars[3]}&c[{$country}][1]={$vars[4]}"; $doms++; } $img_url = url("admin/reports/bawstats/modules/render_map") . $new_data; $out = "<div class=\"aligncenter\"><img width=\"574\" height=\"286\" alt=\"map of domains\" src=\"{$img_url}\"" . XHTML . "></div>"; baw_debug("rendering map finished"); return $out; }
function baw_read_lng_data($file, $alternative) { global $BAW_MES; $r = array(); baw_debug("reading language data: {$file}"); $lines = file($file); $encode_str = false; foreach ($lines as $line) { if (substr($line, 0, 7) == 'message') { $match = explode('=', $line); $match[0] = substr($match[0], 7); $r[$match[0]] = trim($match[1]); } else { if (substr($line, 0, 8) == 'PageCode') { $encode_str = substr($line, 9); $r['e'] = $encode_str; } } } // check that we have the whole file if (count($r) < 173) { baw_debug("The language file is incomplete, only " . count($r) . "entries. Filling the rest with english"); $lines = file($alternative); foreach ($lines as $line) { if (substr($line, 0, 7) == 'message') { $match = explode('=', $line); $match[0] = substr($match[0], 7); if (!isset($r[$match[0]])) { $r[$match[0]] = trim($match[1]); } } } } baw_debug("finished reading language data"); $BAW_MES += $r; }
function baw_render_htmlchart($chart, $format, $get_avg = false, $top_x = false, $dataformat = false) { baw_debug("rendering chart"); global $BAW_CONF, $BAW_LIB, $BAW_MES; // FORMATS ----------------------------------------------------------------- $format_arr = array(); $itemcount = count($chart); // we have time data, $top_x has to work from the back instead of the front $time_data = false; if ($top_x < 0) { $time_data = true; $top_x = abs($top_x); } if ($get_avg) { $top_x++; } $top_x = min($BAW_CONF['max_chart_items'], $top_x); $top_x_count = $top_x; // if its not set, use count of items (day, month etc) if (!$top_x_count) { $top_x_count = $itemcount; } // find the smaller one to know the resulting lines if (min($top_x_count, $itemcount) > 12) { $width = 4; } else { $width = 6; } // iterate formats for header $text_fields = 0; foreach ($format as $cell => $attr) { // iterate one formats attributes $format_arr[] = $attr['format']; // we need the number of textfields so we can prepend them to the averages array. // otherwise the fields for avg and others are not in the right columns if ($attr['format'] == 'layout_text') { $text_fields++; } // $title_arr[] = $attr['title']; } // Max & averages calculation ---------------------------------------------- // the max has to be calculated before so the bar height can be calculated // the sum has to be known for averages // iterate all the table and count the sums of all numeric data $max_arr = array(); $sum_arr = array(); $avg_arr = array(); $others = array(); $filled_lines = $itemcount; // get the value for substraction $row_no = 0; $othercount = 0; $hasothers = false; foreach ($chart as $lineid => $row) { $cell_no = 0; $rowsum = 0; $hasothers = false; foreach ($row as $cell) { if ($format_arr[$cell_no] != 'layout_text') { // we dont include the text // max calculation @($max_arr[$cell_no] = max($max_arr[$cell_no], $cell)); // sum calculation @($sum_arr[$cell_no] += $cell); // 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--; } $avg_arr[$cell_no] = $sum_arr[$cell_no] / $filled_lines; } } else { if ($get_avg) { $avg_arr[$cell_no] = ''; } } // others calculation if (!$time_data && $top_x && $row_no >= $top_x) { // max calculation @($max_arr[$cell_no] = max($max_arr[$cell_no], $others[$cell_no])); $hasothers = true; @($others[$cell_no] += $cell); } else { if ($time_data && $top_x && $itemcount - $row_no >= $top_x) { $hasothers = true; // for now, we do not accumulate old data for months/days -- optional? // risk is that 'others' is so big that it does not make sense //@$others[$cell_no] += $cell; //@$max_arr[$cell_no] = max($max_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($chart[$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 } // make the array longer to fit, first index is 1 since it comes after the array title if ($text_fields >= 1) { $empty_arr = array_pad(array(), $text_fields - 1, ''); } else { $empty_arr = array(); } // add others to the table if ($hasothers && !$time_data) { // we got others, add them to the end $row_no++; $others = $empty_arr + array($text_fields - 1 => $BAW_MES[2]) + $others; $chart += array('layout_others' => $others); } else { if ($hasothers && $time_data) { $row_no++; $others = $empty_arr + array($text_fields - 1 => $BAW_MES[2]) + $others; //$temp = array('layout_others' => $others); //$chart = $temp + $empty_arr + $chart; } } // add averages to the table if ($get_avg) { $row_no++; $avg_arr = $empty_arr + array($text_fields - 1 => $BAW_MES[96]) + $avg_arr; $chart += array('layout_avg' => $avg_arr); } $out = "\n<table class=\"charttable\">\n"; $out .= " <tr>\n"; // create the title if (isset($format[0]['title']) && $BAW_CONF['chart_titles']) { $count_str = sprintf($BAW_MES['records'], baw_num_format($itemcount)); $out .= " <tr>\n <th class=\"header_wrap\" colspan=\"{$row_no}\">{$format[0]['title']} ({$count_str})</th>\n </tr>\n"; } $l = 0; $fieldcount = 0; $legend = array(); foreach ($chart as $lineid => $row) { $class = ''; if (isset($dataformat[$lineid])) { $class = " {$dataformat[$lineid]}"; } else { if ($lineid === 'layout_others' || $lineid === 'layout_avg') { $class .= " {$lineid}"; } } $out .= " <td class=\"chartcell{$class}\">\n"; $cell_no = 0; foreach ($row as $cell) { // only take the numeric values if ($format_arr[$cell_no] != 'layout_text') { $tags = ''; $function = $BAW_LIB['formats'][$format_arr[$cell_no]]['frm']; $txt = $BAW_LIB['formats'][$format_arr[$cell_no]]['txt']; $img = $BAW_LIB['formats'][$format_arr[$cell_no]]['img']; $alt = "{$BAW_MES[$txt]}: " . exec_function($function, $cell); $max_string = str_replace('layout_', '', $format[$cell_no]['format']); // scale after what? $max_key = array_search($BAW_CONF["max_{$max_string}"], $format_arr); if (isset($max_arr[$max_key]) && $max_arr[$max_key] > 0) { $height = $cell / ($max_arr[$max_key] / 100); } else { $height = 1; } if ($height < 1) { $height = 1; } $attr = array('height' => $height, 'width' => $width, 'alt' => $alt, 'title' => $alt, 'class' => 'chartimg'); $out .= baw_create_image($BAW_CONF['icons_url'] . "/other/{$img}", $attr); } else { // write legend $fieldcount = max($cell_no, $fieldcount); @($legend[$l][$cell_no] = " <td{$tags} colspan=\"1\">{$cell}</td>\n"); if (isset($legend[$l - 1][$cell_no]) && isset($cell)) { if (preg_match('#colspan=\\"(\\d+)\\">' . $cell . '</td>#', $legend[$l - 1][$cell_no], $number)) { $number[1]++; @($legend[$l][$cell_no] = " <td{$tags} colspan=\"{$number[1]}\">{$cell}</td>\n"); $legend[$l - 1][$cell_no] = ""; } } } $cell_no++; } $out .= "\n </td>\n"; $f = 1; $l++; } $out .= " </tr>\n"; // Display legend $linecount = $l; // we inverse the order so the ones standing closer to the data in the table // are on top here for ($f = $fieldcount; $f >= 0; $f--) { $out .= " <tr class=\"chartlegend\">\n"; for ($l = 0; $l < $linecount; $l++) { $out .= $legend[$l][$f]; } $out .= " </tr>\n"; } $out .= "</table>\n"; baw_debug("rendering chart finished"); return $out; }
function baw_is_writable($path) { //will work in despite of Windows ACLs bug //NOTE: use a trailing slash for folders!!! //see http://bugs.php.net/bug.php?id=27609 //see http://bugs.php.net/bug.php?id=30931 baw_debug('dbg_test_writable', $path); if ($path[strlen($path) - 1] == '/') { // recursively return a temporary file path return baw_is_writable($path . uniqid(mt_rand()) . '.tmp'); } else { if (is_dir($path)) { return baw_is_writable($path . '/' . uniqid(mt_rand()) . '.tmp'); } } // check tmp file for read/write capabilities $rm = file_exists($path); $f = @fopen($path, 'a'); if ($f === false) { @fclose($f); baw_debug('dbg_test_writable_false', $path); return false; } if (!$rm) { unlink($path); } fclose($f); baw_debug('dbg_test_writable_true', $path); return true; }
function baw_read_filemap(&$f, $site, $date) { global $BAW_DFILES; // $f = fopen($file, 'r'); $str = ''; $check = 1; // read this file until we hit the offsets while ($check !== 0) { $str = fgets($f, 20000); // check for XML Data if (strstr($str, '<xml') !== false) { // we have XML echo baw_raise_error('xmldata'); exit; } $check = strpos($str, 'BEGIN_MAP'); } $check = explode(' ', $str); $lines_count = $check[1]; // line length of the map baw_debug("found data map for file, has {$lines_count} lines"); // now read x more lines for ($i = 0; $i < $lines_count; $i++) { // read the complete offset map $str = fgets($f, 512); // split the info in string - byte offset $check = explode(' ', $str); $type = substr($check[0], 4); $offset = $check[1]; if ($offset > 1) { baw_debug("data type {$type}, starts at offset {$offset}"); $BAW_DFILES[$site][$date]['map'][$type] = $offset; } else { echo baw_raise_error('datafileindex', $err_data); exit; } } baw_debug("map read"); }
function baw_display_visitors($set) { global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_CONF_DIS; $format = array(0 => array('title' => $BAW_MES[81], 'format' => 'layout_text'), 1 => array('percent' => true, 'title' => $BAW_MES[56], 'format' => 'layout_pages'), 2 => array('title' => $BAW_MES[57], 'format' => 'layout_hits'), 3 => array('title' => $BAW_MES[75], 'format' => 'layout_bytes'), 4 => array('title' => $BAW_MES['ratio_pages_hits'], 'format' => 'layout_ratio', 'ratio' => '2/1'), 5 => array('title' => $BAW_MES[9], 'format' => 'layout_date')); $h_data = array(0, 0, 0, 'latest_date' => 0); $s_data = array(0, 0, 0, 'latest_date' => 0); $i = 0; $hashotlinks = false; $hasbots = false; if ($val = baw_data($BAW_CURR['site_name'], "VISITOR", $BAW_CURR['yearmonth'])) { baw_debug("data loaded"); foreach ($val as $dns => $data) { // $infolink = baw_create_link("?", "javascript:neww('$dns','{$dns}XXX')"); // $line[] = array ('data'=> $infolink, 'class' => "aligncenter", 'format' => 'layout_index'); //if (!$set['hidebots'] or $data[1] !== $data[2]) { $ratio = 0; if ($data[0] > 0) { $ratio = $data[1] / $data[0]; } // hotlinks & Bots if ($data[3] == '') { $data[3] = 0; } // $data[3] = settype($data[3], 'int'); if ($data[0] == 0 && $data[1] !== 0) { $h_data['latest_date'] = max($data[3], $h_data['latest_date']); $h_data[0] += $data[0]; $h_data[1] += $data[1]; $h_data[2] += $data[2]; $hashotlinks = true; } else { if ($ratio <= $BAW_CONF_DIS['visitors']['assumebot']) { $s_data['latest_date'] = max($data[3], $s_data['latest_date']); $s_data[0] += $data[0]; $s_data[1] += $data[1]; $s_data[2] += $data[2]; $hasbots = true; } else { $val[$i] = array($dns, $data[0], $data[1], $data[2], baw_num_format($ratio, 2), $data[3]); } } // try extra to regain the memory here since this is the largest function $val[$dns] = NULL; unset($val[$dns]); $i++; } if ($hasbots) { $val['script'] = array($BAW_MES['assumedscript'], $s_data[0], $s_data[1], $s_data[2], $s_data[1] / $s_data[0], $s_data['latest_date']); } if ($hashotlinks) { $val['hotlinks'] = array($BAW_MES['hotlinks_proxies'], $h_data[0], $h_data[1], $h_data[2], 0, $h_data['latest_date']); } $val = baw_array_sorting($val, $set['sort'], $set['sort_dir']); baw_debug("data sorted"); } else { if ($BAW_CONF['hideempty']) { return ''; } } $out = ''; if ($set['table']) { $out .= baw_render_table($set['name'], $val, $format, $set['avg'], $set['total'], $set['top_x']); } return $out; }
function baw_display_index($settings = array()) { global $BAW_CONF, $BAW_CONF_DIS, $BAW_CONF_DIS_DEF, $BAW_MES, $BAW_LIB; global $BAW_DFILES, $BAW_CURR, $BAW_D; // this comes second since site_name is unknown otherwise echo baw_site_header($BAW_CURR['site_name']); $content = "<div class=\"contentbox\">\n"; $tmp = array(); // temp array where we record which section has data to show/hide menu options // sort the charts according to order in config $BAW_CONF_DIS = baw_array_sorting($BAW_CONF_DIS, 'order', SORT_ASC); // ---------- CONTENT BOX -------------------------------------------------- // this should be removed once we move to beta. if ($BAW_CURR['site_name'] == 'all_months') { $settings['section'] = "months"; $section = $settings['section']; $function = "baw_display_{$section}"; $temp_conf = $BAW_CONF_DIS[$section]; $temp_conf['chart'] = true; $temp_conf['table'] = false; $temp_conf['name'] = $BAW_CONF_DIS_DEF[$section]['name']; baw_debug("Printing Stats for: " . $BAW_CONF_DIS_DEF[$section]['name']); $content .= $function($temp_conf); } else { if ($BAW_CURR['site_name'] == 'all_days') { $settings['section'] = "days"; $section = $settings['section']; $function = "baw_display_{$section}"; $temp_conf = $BAW_CONF_DIS[$section]; $temp_conf['chart'] = true; $temp_conf['table'] = false; $temp_conf['name'] = $BAW_CONF_DIS_DEF[$section]['name']; baw_debug("Printing Stats for: " . $BAW_CONF_DIS_DEF[$section]['name']); $content .= $function($temp_conf); } else { if (isset($settings['section'])) { $section = $settings['section']; $function = "baw_display_{$section}"; $temp_conf = $BAW_CONF_DIS[$section]; $temp_conf['top_x'] = $BAW_CONF['maxlines']; $temp_conf['name'] = $BAW_CONF_DIS_DEF[$section]['name']; baw_debug("Printing Stats for: " . $BAW_CONF_DIS_DEF[$section]['name']); $content .= baw_section_header($section, $temp_conf['name'], false, 'menu_section') . $function($temp_conf) . baw_section_footer(); } else { $content .= "\n<!-- CONTENT START ++++++++++++++++++++++++++++++++++++++ -->\n"; if ($BAW_CONF['layout_type'] == 'horizontal') { foreach ($BAW_LIB['item_groups'] as $group => $group_details) { $group_items = $group_details['members']; $menubuttons = "<div class=\"clearfix\">"; $stats_section = ''; $item_id = 0; $count_members = count($group_details['members']); foreach ($group_details['members'] as $item) { $sect_data = $BAW_CONF_DIS[$item]; $sect_data['name'] = $item; $function = "baw_display_{$item}"; if (function_exists($function)) { baw_debug("Printing Stats for: {$function}"); $stats_html = $function($sect_data); if ($sect_data['show'] == true && (strlen($stats_html) > 1 || !$BAW_CONF['hideempty'])) { $stats_section .= "\n<!-- ITEM {$BAW_CONF_DIS_DEF[$item]['name']} START ++++++++++++++++++++++++++++++++++++++ -->\n"; $button_title = $BAW_CONF_DIS_DEF[$item]['name']; if ($item_id == 0) { $button_class = "menu_button_active"; } else { $button_class = "menu_button_inactive"; } $menubuttons .= "<div class=\"{$button_class}\" id=\"button_{$group}_{$item_id}\" onClick=\"toggleBox({$item_id}, '{$group}', {$count_members}, 'menu');\">{$button_title}</div>\n"; if ($item == 'weekdays' && !isset($BAW_CURR['wdays']['count'])) { $setarr = array('collapse' => false, 'chart' => false, 'table' => false); baw_display_weekdays($setarr); } $title = $BAW_CONF_DIS_DEF[$item]['name']; $collapse = $sect_data['collapse']; $name = "{$group}_{$item_id}"; $collapse = false; if ($item_id == 0) { $class = 'menu_section_active'; } else { $class = 'menu_section_inactive'; } $stats_section .= baw_section_header($name, $title, $collapse, $class) . $stats_html . baw_section_footer(); $tmp[$item] = true; $stats_section .= "\n<!-- ITEM {$item} END ++++++++++++++++++++++++++++++++++++++ -->\n"; $item_id++; } else { $tmp[$item] = false; } } } if (strlen($stats_section) > 1) { $content .= "\n<!-- GROUP {$group} START ++++++++++++++++++++++++++++++++++++++ -->\n"; $content .= baw_section_header($group, $group_details['title'], false, 'group_title'); $menubuttons .= "</div>"; $content .= $menubuttons . "\n{$stats_section}\n"; $content .= baw_section_footer(); $content .= "\n<!-- GROUP {$group} END ++++++++++++++++++++++++++++++++++++++ -->\n"; $tmp[$group] = true; } else { $tmp[$group] = false; } } } else { foreach ($BAW_CONF_DIS as $section => $sect_data) { $stats_html = ''; $content .= "\n<!-- ITEM {$section} START ++++++++++++++++++++++++++++++++++++++ -->\n"; $title = $BAW_CONF_DIS_DEF[$section]['name']; $collapse = $sect_data['collapse']; $name = $section; $sect_data['name'] = $section; $function = "baw_display_{$section}"; if ($sect_data['show'] == true && function_exists($function)) { baw_debug("Printing Stats for: baw_display_{$section}"); $stats_html = $function($sect_data); if (strlen($stats_html) > 1) { $content .= baw_section_header($name, $title, $collapse, 'menu_section') . $stats_html . baw_section_footer(); $tmp[$section] = true; } else { $tmp[$section] = false; } } $content .= "\n<!-- ITEM {$section} END ++++++++++++++++++++++++++++++++++++++ -->\n"; } } $content .= "\n<!-- CONTENT END ++++++++++++++++++++++++++++++++++++++ -->\n"; } } } $content .= "</div>"; baw_debug("Starting to build menu"); // ---- MENU BOX ----------------------------------------------------------- $menubox = "\n\n<!-- MENU START ++++++++++++++++++++++++++++++++++++++ -->\n" . "<div class=\"menubox\">\n" . baw_sites_dropdown(); $qstrng = ''; if (strlen($_SERVER['QUERY_STRING']) > 0) { $qstrng = '?' . $_SERVER['QUERY_STRING']; } $url = "{$BAW_CONF['site_url']}/index.php{$qstrng}"; $menubox .= " <ul class=\"menu\" >\n" . " <li class=\"menu_even\">\n" . " " . baw_create_link($BAW_MES[77], "{$url}#", array('class' => 'leftlink')) . "\n " . " </li>\n"; $c = 1; // top link was '0' if ($BAW_CURR['site_name'] == 'all_months' or $BAW_CURR['site_name'] == 'all_days') { $sites = array_keys($BAW_DFILES); foreach ($sites as $site) { $class = baw_even($c, 'menu_even', 'menu_odd'); $menubox .= " <li class=\"{$class}\">\n" . " " . baw_create_link($site, "{$url}#site_{$site}") . "\n" . " </li>\n"; $c++; } } else { if ($BAW_CONF['layout_type'] == 'horizontal') { foreach ($BAW_LIB['item_groups'] as $group => $group_details) { if ($tmp[$group]) { $class = baw_even($c, 'menu_even', 'menu_odd'); $name = $group_details['title']; $menubox .= " <li class=\"{$class}\">\n" . " " . baw_create_link($name, "{$url}#h2_{$group}") . "\n" . " </li>\n"; $c++; } } } else { if (isset($settings['section'])) { // we are doing a full list $url = str_replace('&action=get_fulltable&what=' . $settings['section'], '', $url); $menubox .= " <li class=\"menu_odd\">\n" . baw_create_link($BAW_MES['back'], $url) . "\n" . " </li>\n"; } else { $count_sections = count($BAW_CONF_DIS); foreach ($BAW_CONF_DIS as $section => $sect_data) { if ($sect_data['show'] && ($tmp[$section] || !$BAW_CONF['hideempty'])) { $class = baw_even($c, 'menu_even', 'menu_odd'); $name = $BAW_CONF_DIS_DEF[$section]['name']; $menubox .= " <li class=\"{$class}\">\n" . " " . baw_create_link($name, "{$url}#h2_{$section}", array('class' => 'leftlink')) . "\n" . baw_display_list_icons($section, array('info'), false) . "\n" . " </li>\n"; $c++; } } } } } $menubox .= " </ul>\n"; $menubox_end = "\n</div>\n<!-- MENU END - SITE/DATE MENU START ++++++++++++++++++++++++++++++++++++++ -->\n"; baw_debug("Menu finished"); $finaltime = baw_ptime(); $out = $menubox . baw_display_version("<br" . XHTML . "> in {$finaltime}, max menory: " . baw_byte_format(memory_get_peak_usage(true))) . $menubox_end . $content . baw_site_footer(); return $out; }
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; }