function baw_display_screensizes($set) { global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_LIB; $format = array(0 => array('title' => $BAW_MES[135], 'format' => 'layout_text', 'colspan' => 2), 1 => array('format' => 'layout_text'), 2 => array('percent' => true, 'title' => $BAW_MES[57], 'format' => 'layout_hits')); $format_chart = array(0 => array('title' => $BAW_MES[135], 'format' => 'layout_text'), 1 => array('title' => $BAW_MES[57], 'format' => 'layout_hits')); $val = array(); $newval = array(); $url = $BAW_CONF['site_url'] . "/icons/screen.png"; if ($val = baw_data($BAW_CURR['site_name'], 'SCREENSIZE', $BAW_CURR['yearmonth'])) { foreach ($val as $size => $data) { $size_arr = explode("x", $size); $sizex = $size_arr[0] / 80; $sizey = $size_arr[1] / 80; $img_arr = array('height' => $sizey, 'width' => $sizex, 'title' => $size, 'class' => 'screensize'); $newval[$size] = array(baw_create_image($url, $img_arr), $size, $data[0]); } } else { if ($BAW_CONF['hideempty']) { return ''; } } $newval = baw_array_sorting($newval, $set['sort'], $set['sort_dir']); $out = ''; if ($set['chart']) { $newval_chart = array(); foreach ($newval as $size => $data) { $newval_chart[$size] = array($data[0], $data[2]); } $out .= baw_render_htmlchart($newval_chart, $format_chart, $set['avg'], $set['top_x']); } if ($set['table']) { $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], $set['top_x'], false); } return $out; }
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_show_expand_collapse($name, $collapse) { global $BAW_CONF, $BAW_MES; $url = $BAW_CONF['site_url'] . "/icons/expand.gif"; $arr_show = array('class' => "showhidebutton", 'onclick' => "showElement('{$name}');", 'title' => $BAW_MES['show'], 'id' => "button_show_{$name}"); $arr_hide = array('class' => "showhidebutton", 'onclick' => "hideElement('{$name}');", 'id' => "button_hide_{$name}", 'title' => $BAW_MES['hide']); if ($collapse) { $arr_hide += array('style' => "display:none"); } else { $arr_show += array('style' => "display:none"); } $url = $BAW_CONF['site_url'] . "/icons/expand.gif"; $out = baw_create_image($url, $arr_show); $url = $BAW_CONF['site_url'] . "/icons/collapse.gif"; $out .= baw_create_image($url, $arr_hide); return $out; }