Example #1
0
function baw_display_days($set)
{
    global $BAW_MES, $BAW_CURR, $BAW_CONF, $BAW_DFILES;
    $sum = array(0, 0, 0, 0, 0);
    // summ all overall data
    // this 3 lines is only for collecting data for weekdays
    $wdsum_arr = array();
    // summ all weekday data
    $wdcount_arr = array(0, 0, 0, 0, 0, 0, 0);
    // count the number of sat, sun etc
    $wdavg_arr = array();
    // values of avg
    $daysoflastmonth = 30;
    // assemble date
    $daysofmonth = date("t", strtotime("{$BAW_CURR['year']}{$BAW_CURR['month']}01000000"));
    //$thisyear = date("Y", strtotime("-1 month"));
    //$lastyear = date("Y", strtotime("-1 month -1 year"));
    $current_month = date('m');
    $current_day = date('d');
    $daydiff = 0;
    $data_format = array();
    // find how may days we have to go back
    if ($BAW_CURR['month'] == $current_month) {
        // if we have the current month, get some data from the last month
        $daydiff = abs($current_day - $daysofmonth);
        // calculate how many days are missing
    }
    $format = array(0 => array('format' => 'layout_text', 'title' => $BAW_MES[4], 'colspan' => 3), 1 => array('format' => 'layout_text'), 2 => array('format' => 'layout_text'), 3 => array('format' => 'layout_visits', 'title' => $BAW_MES[10]), 4 => array('format' => 'layout_pages', 'title' => $BAW_MES[56]), 5 => array('format' => 'layout_hits', 'title' => $BAW_MES[57]), 6 => array('format' => 'layout_bytes', 'title' => $BAW_MES[75]));
    // check if we do all sites or just one
    $allsites = false;
    if ($BAW_CURR['site_name'] !== 'all_days') {
        $sites = array($BAW_CURR['site_name']);
    } else {
        $sites = array_keys($BAW_DFILES);
        $allsites = true;
    }
    $out = '';
    // iterate all sites, normally only one
    foreach ($sites as $site) {
        // we have to add the days of the previous month
        // this has to be inside the loop so we get the variables again for next site
        if ($daydiff > 0) {
            if ($BAW_CURR['month'] !== '01') {
                $prevyear = $BAW_CURR['year'];
                $prevmonth = sprintf('%02d', $BAW_CURR['month'] - 1);
                // date('m', strtotime("-1 month"));
                $daysoflastmonth = date("t", strtotime("{$BAW_CURR['year']}{$prevmonth}01000000"));
            } else {
                $prevyear = $BAW_CURR['year'] - 1;
                $prevmonth = '12';
            }
        }
        $val = array();
        // get the data for this site if available
        if ($val = baw_data($site, 'DAY', $BAW_CURR['yearmonth'])) {
            // in case we need last months data, get it too
            if ($daydiff > 0) {
                if ($prevdate_data = baw_data($site, 'DAY', $prevyear . $prevmonth)) {
                    $date_cut = $prevyear . $prevmonth . ($prevmonth = sprintf('%02d', $daysoflastmonth - $daydiff));
                    $val_prev = baw_cut_date_array($prevdate_data, $date_cut);
                    $val = $val_prev + $val;
                }
            }
            $newval = array();
            $lastmonth = 0;
            for ($j = 0; $j < $daysofmonth; $j++) {
                $class = '';
                // foreach ($val as $date => $data) {
                $date = date("Ymd", mktime(0, 0, 0, $BAW_CURR['month'], 1 + $j - $daydiff, $BAW_CURR['year']));
                $month = date("m", mktime(0, 0, 0, $BAW_CURR['month'], 1 + $j - $daydiff, $BAW_CURR['year']));
                $today = date("Ymd");
                if ($date == $today) {
                    $class = "currentday";
                }
                if (!isset($val[$date])) {
                    $val[$date] = array(0, 0, 0, 0, 0);
                }
                $data = $val[$date];
                $xdate = $date . "000000";
                $tstamp = strtotime($xdate);
                $wday = date("w", $tstamp);
                if ($wday == 0 or $wday == 6) {
                    $class = "{$class} weekend";
                    $class = trim($class);
                }
                // these lines is only for collecting data for weekdays
                $wdcount_arr[$wday]++;
                // count no of one weekday for avg division
                for ($i = 0; $i <= 3; $i++) {
                    // iterate data types
                    if (!isset($wdsum_arr[$wday][$i])) {
                        $wdsum_arr[$wday][$i] = 0;
                    }
                    $wdsum_arr[$wday][$i] += $data[$i];
                }
                if (!isset($from)) {
                    $from = $xdate;
                }
                $BAW_CURR['wdays']['count'] = $wdcount_arr;
                $BAW_CURR['wdays']['avg'] = $wdsum_arr;
                $BAW_CURR['wdays']['from'] = $from;
                $BAW_CURR['wdays']['to'] = $xdate;
                if ($j !== $daysofmonth) {
                    $newval[$xdate] = array(date("Y", strtotime($xdate)), date("M", strtotime($xdate)), date("d", strtotime($xdate)), $data[3], $data[0], $data[1], $data[2]);
                }
                $class .= baw_even($month, ' evenmonth', ' oddmonth');
                if ($class !== '') {
                    $data_format[$xdate] = $class;
                }
            }
            if ($set['chart']) {
                if ($allsites) {
                    // make a link to the actual statistics from the overview
                    $full_url = "{$BAW_CONF['site_url']}/index.php?site={$site}&amp;month={$BAW_CURR['month']}&amp;year={$BAW_CURR['year']}";
                    $out .= "<h3 id=\"site_{$site}\"><a href=\"{$full_url}\">{$site}</a></h3>";
                    // $html .= baw_display_updatestats($site);
                }
                $out .= baw_render_htmlchart($newval, $format, $set['avg'], false, $data_format);
            }
            if ($set['table']) {
                $out .= baw_render_table($set['name'], $newval, $format, $set['avg'], $set['total'], false, $data_format);
            }
        }
    }
    return $out;
}
Example #2
0
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;
}