function CONDENSED()
{
    $q = new mysql_squid_builder();
    if (!$q->CreateFamilyCondensed()) {
        return false;
    }
    if (!$q->CreateFamilyMainTable()) {
        return false;
    }
    $q->QUERY_SQL("TRUNCATE TABLE FamilyCondensed");
    $LIST_TABLES_FAMILY = $q->LIST_TABLES_FAMILY();
    while (list($tablename, $ligne) = each($LIST_TABLES_FAMILY)) {
        build_progress("Calculating master table on {$tablename}", 80);
        CONDENSED_perform($tablename);
    }
    $q->QUERY_SQL("TRUNCATE TABLE main_websites");
    $sql = "SELECT SUM(size) as size,SUM(hits) AS `hits`, familysite FROM FamilyCondensed GROUP BY familysite";
    $results = $q->QUERY_SQL($sql);
    $prefix = "INSERT IGNORE INTO main_websites (size,hits,familysite) VALUES ";
    build_progress("Builing  main_websites table on", 90);
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $familysite = mysql_escape_string2($ligne["familysite"]);
        $zmd5 = md5(serialize($ligne));
        $size = $ligne["size"];
        $hits = $ligne["hits"];
        echo "'{$size}','{$hits}','{$familysite}'\n";
        $f[] = "('{$size}','{$hits}','{$familysite}')";
        if (count($f) > 500) {
            $q->QUERY_SQL($prefix . @implode(",", $f));
            if (!$q->ok) {
                return false;
            }
            $f = array();
        }
    }
    if (count($f) > 0) {
        $q->QUERY_SQL($prefix . @implode(",", $f));
        if (!$q->ok) {
            return false;
        }
        $f = array();
    }
    return true;
}
function start($xtime = 0)
{
    build_progress("Loading...", 10);
    $unix = new unix();
    if ($GLOBALS["VERBOSE"]) {
        "echo Loading done...\n";
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($GLOBALS["VERBOSE"]) {
        echo "Timefile = {$timefile}\n";
    }
    $pid = @file_get_contents($pidfile);
    if (!$GLOBALS["FORCE"]) {
        if ($pid < 100) {
            $pid = null;
        }
        $unix = new unix();
        if ($unix->process_exists($pid, basename(__FILE__))) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            return;
        }
        $timeexec = $unix->file_time_min($timefile);
        if (!$GLOBALS["SCHEDULED"]) {
            if ($timeexec < 2880) {
                return;
            }
        }
        $mypid = getmypid();
        @file_put_contents($pidfile, $mypid);
    }
    if ($GLOBALS["RESTART"]) {
        REBUILD_FULL_MEMBERS();
        exit;
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $php = $unix->LOCATE_PHP5_BIN();
    if (!$GLOBALS["VERBOSE"]) {
        build_progress("Execute exec.squid.stats.members.hours.php {please_wait}", 20);
        $repaircmd = "{$php} /usr/share/artica-postfix/exec.squid.stats.members.hours.php --repair --verbose --force 2>&1";
        system($repaircmd);
    }
    $q = new mysql_squid_builder();
    if (!$q->FIELD_EXISTS("tables_day", "usersday")) {
        $q->QUERY_SQL("ALTER TABLE `tables_day` ADD `usersday` TINYINT( 1 ) NOT NULL DEFAULT '0', ADD INDEX ( `usersday` )");
    }
    $sql = "SELECT tablename, usersday,DATE_FORMAT(zDate,'%Y%m%d') AS `suffix` FROM tables_day \n\t\t\tWHERE usersday=0 AND DAY(zDate)<DAY(NOW()) AND YEAR(zDate) = YEAR(NOW()) AND MONTH(zDate) = MONTH(NOW())";
    $q->CheckTables();
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error;
        build_progress("MySQL error", 110);
        return;
    }
    build_progress("tables_day =  " . mysql_num_rows($results) . " rows {please_wait}", 30);
    if ($GLOBALS["VERBOSE"]) {
        echo mysql_num_rows($results) . " rows\n";
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $worktable = "{$ligne["suffix"]}_members";
        $SourceTable = "{$ligne["suffix"]}_hour";
        if (!$q->TABLE_EXISTS($worktable)) {
            continue;
        }
        $desttable = "{$ligne["suffix"]}_users";
        build_progress("{$desttable} {please_wait}", 30);
        if (!perform($worktable, $desttable)) {
            continue;
        }
        $q->QUERY_SQL("UPDATE tables_day SET usersday=1 WHERE tablename='{$ligne["tablename"]}'");
    }
    $currentdestable = date("Ymd") . "_users";
    if (!$q->CreateUsersTempTable()) {
        build_progress("CreateUsersTempTable failed", 110);
        return false;
    }
    if (!$q->CreateUsersFullTable()) {
        build_progress("CreateUsersFullTable failed", 110);
        return false;
    }
    build_progress("Empty working tables", 40);
    $q->QUERY_SQL("TRUNCATE TABLE UsersTMP");
    $q->QUERY_SQL("TRUNCATE TABLE UsersToTal");
    $LIST_TABLES_MEMBERS = $q->LIST_TABLES_MEMBERS();
    while (list($tablename, $ligne) = each($LIST_TABLES_MEMBERS)) {
        $xtime = $q->TIME_FROM_DAY_TABLE($tablename);
        $desttable = date("Ymd", $xtime) . "_users";
        build_progress("Scanning {$tablename} -> {$desttable}", 50);
        if ($desttable == $currentdestable) {
            continue;
        }
        if (!$q->TABLE_EXISTS($desttable)) {
            if (!perform($tablename, $desttable)) {
                continue;
            }
        }
        MONTH_TABLE_FROM_MEMBER_DAY($tablename);
        CONDENSED_perform($desttable);
    }
    CONDENSED();
    build_progress("Empty table UsersTMP", 90);
    $q->QUERY_SQL("TRUNCATE TABLE UsersTMP");
    build_progress("{done}", 100);
}