function change_month_popup()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $q = new mysql_squid_builder();
    $t = $_GET["t"];
    $members = $tpl->_ENGINE_parse_body("{members}");
    $month = $tpl->_ENGINE_parse_body("{month}");
    $array = array();
    $tables = $q->LIST_TABLES_MONTH();
    while (list($index, $tablez) = each($tables)) {
        $array[$tablez] = $q->MONTH_TITLE_FROM_TABLENAME($tablez);
    }
    $field = Field_array_Hash($array, "table-m-{$t}", $table, " DayMemberChangeMonthPanel{$t}()", null, 0, "font-size:14px");
    $array = array();
    $html = "\n\t<table style='width:99%' class=form>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t<td class=legend style='font-size:16px;'>{month}:</td>\n\t\t\t\t<td>{$field}</td>\n\t\t\t</tr>\n\t</table>\n\n\t<script>\n\t\tfunction DayMemberChangeMonthPanel{$t}(){\n\t\t\tvar xday=document.getElementById('table-m-{$t}').value;\n\t\t\t\$('.ftitle').html('{$members}&raquo;{$month}&raquo;table:'+xday);\n\t\t\t\$('#{$t}').flexOptions({url: '{$page}?search=yes&table='+xday,title:'{$members}'+xday}).flexReload();\n\t\t\n\t\t}\n\t\n\t</script>";
    echo $tpl->_ENGINE_parse_body($html);
}
function sitenames()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $field = $_GET["field"];
    $value = $_GET["value"];
    $MyTableMonth = date("Ym") . "_day";
    $MyMonthText = date("{F}");
    $q = new mysql_squid_builder();
    $tableQuery = $_GET["table"];
    if (isset($_GET["table"])) {
        $MyTableMonth = $_GET["table"];
    }
    if (!$q->TABLE_EXISTS($MyTableMonth)) {
        echo FATAL_ERROR_SHOW_128("&laquo;{$MyTableMonth}&raquo; {table_does_not_exists}");
        return;
    }
    if (preg_match("#_week#", $_GET["table"])) {
        $title_add = "&raquo;" . $tpl->_ENGINE_parse_body($q->WEEK_TITLE_FROM_TABLENAME($_GET["table"]));
    }
    if (preg_match("#_day\$#", $_GET["table"])) {
        $title_add = "&raquo;" . $tpl->_ENGINE_parse_body($q->MONTH_TITLE_FROM_TABLENAME($_GET["table"]));
    }
    if (preg_match("#_hour\$#", $_GET["table"])) {
        $title_add = "&raquo;" . $tpl->_ENGINE_parse_body($q->DAY_TITLE_FROM_TABLENAME($_GET["table"]));
    }
    if ($field == "ipaddr") {
        $field = "client";
    }
    $title = $tpl->_ENGINE_parse_body("{where} ? &raquo;&raquo;{{$field}}::{$value} {$title_add}");
    $t = time();
    $sitename = $tpl->_ENGINE_parse_body("{sitename}");
    $category = $tpl->_ENGINE_parse_body("{category}");
    $hits = $tpl->_ENGINE_parse_body("{hits}");
    $size = $tpl->_ENGINE_parse_body("{size}");
    $sitename = $tpl->_ENGINE_parse_body("{sitename}");
    $ipaddr = $tpl->_ENGINE_parse_body("{ipaddr}");
    $members = $tpl->_ENGINE_parse_body("{members}");
    $hostname = $tpl->_ENGINE_parse_body("{hostname}");
    $mac = $tpl->_ENGINE_parse_body("{MAC}");
    $week = $tpl->_ENGINE_parse_body("{week}");
    $month = $tpl->_ENGINE_parse_body("{month}");
    $TB_WIDTH = 550;
    $t = time();
    $buttons = "\n\tbuttons : [\n\t{name: '<b>{$day}</b>', bclass: 'Calendar', onpress : ChangeDay{$t}},\n\t{name: '<b>{$week}</b>', bclass: 'Calendar', onpress : ChangeWeek{$t}},\n\t{name: '<b>{$month}</b>', bclass: 'Calendar', onpress : ChangeMonth{$t}},\n\t\n\t\t],";
    $buttons = null;
    $html = "\n\t<table class='{$t}' style='display: none' id='{$t}' style='width:99%'></table>\n\n<script>\n\n\$(document).ready(function(){\n\$('#{$t}').flexigrid({\n\turl: '{$page}?sitenames-items=yes&field={$field}&value={$value}&table={$_GET["table"]}&familysite={$_GET["familysite"]}',\n\tdataType: 'json',\n\tcolModel : [\n\t\t{display: '{$sitename}', name : 'sitename', width : 181, sortable : true, align: 'left'},\n\t\t{display: '{$category}', name : 'category', width : 245, sortable : true, align: 'left'},\n\t\t{display: '{$size}', name : 'size', width : 109, sortable : true, align: 'left'},\n\t\t{display: '{$hits}', name : 'hits', width : 94, sortable : true, align: 'left'},\n\n\t\t\n\t\t\n\t],{$buttons}\n\tsearchitems : [\n\t\t{display: '{$sitename}', name : 'sitename'},\n\t\t{display: '{$category}', name : 'category'},\n\t\t],\n\tsortname: 'size',\n\tsortorder: 'desc',\n\tusepager: true,\n\ttitle: '{$title}',\n\tuseRp: true,\n\trp: 15,\n\tshowTableToggleBtn: false,\n\twidth: 700,\n\theight: 450,\n\tsingleSelect: true\n\t\n\t});\n});\n</script>";
    echo $tpl->_ENGINE_parse_body($html);
}
function what_popup()
{
    $q = new mysql_squid_builder();
    $tpl = new templates();
    $tableQuery = $_GET["table"];
    $tpl = new templates();
    $page = 1;
    $FORCE_FILTER = null;
    $total = 0;
    $field = $_GET["field"];
    $value = $_GET["value"];
    if (preg_match("#quotamonth#", $tableQuery)) {
        $xtime = $q->TIME_FROM_QUOTAMONTH_TABLE($tableQuery);
        $tableQuery = date("Ym", $xtime) . "_day";
    }
    if ($tableQuery == null) {
        $MyTableMonth = date("Ym") . "_day";
        $tableQuery = $MyTableMonth;
    }
    if (preg_match("#_week#", $_GET["table"])) {
        $title_add = "&raquo;" . $tpl->_ENGINE_parse_body($q->WEEK_TITLE_FROM_TABLENAME($_GET["table"]));
    }
    if (preg_match("#_day\$#", $_GET["table"])) {
        $title_add = "&raquo;" . $tpl->_ENGINE_parse_body($q->MONTH_TITLE_FROM_TABLENAME($_GET["table"]));
    }
    if (preg_match("#_hour\$#", $_GET["table"])) {
        $title_add = "&raquo;" . $tpl->_ENGINE_parse_body($q->DAY_TITLE_FROM_TABLENAME($_GET["table"]));
    }
    if ($_GET["field"] == "ipaddr") {
        $_GET["field"] = "client";
    }
    $sql = "SELECT familysite,{$_GET["field"]},SUM(hits) as hits,category FROM {$tableQuery}\n\tWHERE {$_GET["field"]}='{$_GET["value"]}' GROUP BY familysite,{$_GET["field"]} ORDER BY hits DESC LIMIT 0,10";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error_html();
    }
    if ($GLOBALS["VERBOSE"]) {
        echo mysql_num_rows($results) . " entries <br>";
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if (strpos($ligne["category"], ",") > 0) {
            $tp = explode(",", $ligne["category"]);
            while (list($index, $cat) = each($tp)) {
                if (isset($valsz[$cat])) {
                    continue;
                }
                $valsz[$cat] = $ligne["hits"];
            }
            continue;
        }
        $valsz[$cat] = $ligne["hits"];
    }
    while (list($cat, $count) = each($valsz)) {
        $xdata[] = $count;
        $ydata[] = $cat;
    }
    $targetedfilePie = "ressources/logs/" . basename(__FILE__) . "." . __FUNCTION__ . "." . md5($sql) . ".pie.png";
    $gp = new artica_graphs($targetedfilePie);
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->width = 750;
    $gp->height = 550;
    $gp->ViewValues = true;
    $gp->x_title = $tpl->_ENGINE_parse_body("{what} ? {$MyMonthText}");
    $gp->pie();
    if (!is_file($targetedfilePie)) {
        $html = "<center>{$targetedfilePie} no such file</center>";
        writelogs("Fatal \"{$targetedfilePie}\" no such file!", __FUNCTION__, __FILE__, __LINE__);
    } else {
        $html = $html . "\n\t\t<center>\n\t\t\t<div style='width:99%' class=form>\n\t\t\t\t<div style='font-size:18px;margin:8px'>&laquo;{$value}&raquo;&nbsp;{what} {$title_add}</div>\n\t\t\t\t<img src='{$targetedfilePie}'>\n\t\t\t</div>\n\t\t\t\n\t\t\t\n\t\t</center>\n\t\t\n\t\t";
    }
    echo $tpl->_ENGINE_parse_body($html);
}