if (preg_match("#--rebuild#", implode(" ", $argv))) {
    $GLOBALS["REBUILD"] = true;
}
if ($GLOBALS["VERBOSE"]) {
    "******* echo Loading... *******\n";
}
include_once dirname(__FILE__) . '/ressources/class.mysql.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql.squid.builder.php';
include_once dirname(__FILE__) . '/framework/class.unix.inc';
include_once dirname(__FILE__) . '/ressources/class.os.system.inc';
include_once dirname(__FILE__) . "/framework/frame.class.inc";
if ($GLOBALS["VERBOSE"]) {
    "echo Parsing arguments...\n";
}
$sock = new sockets();
$sock->SQUID_DISABLE_STATS_DIE();
$GLOBALS["Q"] = new mysql_squid_builder();
if ($argv[1] == "--table") {
    _xprocess_table($argv[2]);
    exit;
}
if ($argv[1] == "--all") {
    process_all_tables();
    exit;
}
if ($argv[1] == "--xtime") {
    process_xtable($argv[2]);
    exit;
}
if ($argv[1] == "--repair-tables") {
    repair_tables();
function start()
{
    $unix = new unix();
    $pidfile = "/var/run/squid-stats-central.pid";
    $timefile = $GLOBALS["TIMEFILE"];
    $sock = new sockets();
    if (!$unix->is_socket("/var/run/mysqld/squid-db.sock")) {
        stats_admin_events(0, "MySQL server not ready, delay task...", null, __FILE__, __LINE__);
        $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " " . __FILE__);
        die;
    }
    $WizardStatsApplianceDisconnected = intval($sock->GET_INFO("WizardStatsApplianceDisconnected"));
    if ($WizardStatsApplianceDisconnected == 1) {
        $export_stamp = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".EXPORT.time";
        $export_time = $unix->file_time_min($export_stamp);
        if ($export_time > 60) {
            start_export();
            export_push();
            @unlink($export_stamp);
            @file_put_contents($export_stamp, time());
        }
        die;
    }
    if (!$GLOBALS["NOTIME"]) {
        @unlink($timefile);
        @file_put_contents($timefile, time());
    }
    stats_admin_events(2, " **** STARTING Statistics Engine ****", null, __FILE__, __LINE__);
    percentage("**** STARTING Statistics Engine ****", 0);
    percentage("**** Importing tables ****", 2);
    start_import(true);
    $sock->SQUID_DISABLE_STATS_DIE();
    $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;
        }
        $mypid = getmypid();
        @file_put_contents($pidfile, $mypid);
    }
    $DisableArticaProxyStatistics = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisableArticaProxyStatistics"));
    if ($DisableArticaProxyStatistics == 1) {
        percentage("{disabled}", 100);
        stats_admin_events(1, "100%) Statistics are disabled");
        StampDone(1000, "Statistics are disabled");
        return;
    }
    @unlink("/var/run/squid-stats-central.stop");
    if (!$GLOBALS["NOTIME"]) {
        @unlink($timefile);
        @file_put_contents($timefile, time());
    }
    $tSource = time();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $EXEC_NICE = $unix->EXEC_NICE();
    $Prefix = "/usr/share/artica-postfix";
    $q = new mysql_squid_builder();
    $GLOBALS["Q"] = $q;
    @mkdir("/home/artica/categories_databases", 0755, true);
    $unix->chmod_func(0755, "/home/artica/categories_databases/*");
    $unix->chmod_func(0755, "/home/artica/categories_perso/*");
    if (!StampOK(5)) {
        percentage("Reloading categories Daemon...", 2);
        shell_exec("/etc/init.d/ufdbcat reload");
    }
    $t = time();
    if (!StampOK(10)) {
        percentage("Purge old days", 1);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squidlogs.purge.php"));
        stats_admin_events(2, "1%) Purge days took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(10, "Purge old days");
    }
    if (!StampOK(20)) {
        percentage("Compile personal tables...", 2);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.compile_category_perso.php"));
        Step2();
        StampDone(20, "Compile personal tables");
    }
    $t = time();
    if (!StampOK(30)) {
        percentage("Running Quota day", 2);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.quotaday.php"));
        stats_admin_events(2, "2%) Quota day executed took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(30, "Running Quota day");
    }
    if (SquidStatisticsTasksOverTime()) {
        stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
        return;
    }
    if (!StampOK(40)) {
        percentage("Running Youtube Hours", 2);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.youtube.days.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "2%) Youtube Hours executed took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(40, "Running Youtube Hours");
    }
    shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.squid.stats.php --thumbs-parse >/dev/null 2>&1 &");
    if (!StampOK(50)) {
        percentage("table_days()", 2);
        table_days();
        StampDone(50, "table days");
    }
    if (!StampOK(60)) {
        percentage("Repair Members tables", 2);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.members.hours.php --repair --byschedule --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        StampDone(60, "Repair Members tables");
    }
    if (!StampOK(70)) {
        percentage("Repair Sum tables", 2);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.totals.php --repair --byschedule --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.repair.php --coherences-tables --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        StampDone(70, "Repair Sum tables");
    }
    if (!StampOK(80)) {
        percentage("WeekDaysNums()", 2);
        WeekDaysNums();
        stats_admin_events(2, "2%) Fix tables executed took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(80, "WeekDaysNums");
    }
    if (!StampOK(90)) {
        $t = time();
        percentage("Scanning nodes", 3);
        nodes_scan();
        stats_admin_events(2, "3%) Scanning nodes executed took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(90, "Scanning nodes");
    }
    if (!StampOK(100)) {
        $t = time();
        percentage("Scanning Active Directory", 4);
        shell_exec(trim("{$nohup} {$EXEC_NICE} {$php5} {$Prefix}/exec.clientad.php >/dev/null 2>&1 &"));
        stats_admin_events(2, "4%) Scanning Active Directory executed took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(100, "Scanning Active Directory");
    }
    if (!StampOK(110)) {
        $t = time();
        percentage("Running Active directory translation", 7);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.ad.ous.php"));
        stats_admin_events(2, "7%) Active directory translation took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(110, "Running Active directory translation");
    }
    if (!StampOK(120)) {
        $t = time();
        percentage("Running Search Words hourly", 8);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid-searchwords.php --hour"));
        stats_admin_events(2, "8%) Running Search Words hourly took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(120, "Running Search Words hourly");
    }
    if (!StampOK(130)) {
        $t = time();
        percentage("Repair tables", 9);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.hours.php --repair --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "9%) Running Search Words hourly took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(130, "Repair tables");
    }
    if (!StampOK(140)) {
        $t = time();
        percentage("Running Clients Hourly (clients_hours())", 10);
        clients_hours();
        stats_admin_events(2, "10%) Running Clients Hourly took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(130, "Running Clients Hourly (clients_hours())");
    }
    if (!StampOK(150)) {
        $t = time();
        percentage("Search Words Hourly", 10);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}//usr/share/artica-postfix/exec.squid-searchwords.php --hour --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "10%)  Search Words Hourly:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(150, "Search Words Hourly");
    }
    if (!StampOK(160)) {
        $t = time();
        percentage("Running Members hour", 11);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --members --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "11%) Running Members hour took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(160, "Running Members hour");
    }
    if (!StampOK(170)) {
        $t = time();
        percentage("Repair UserSizeD", 11);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --UserSizeD --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "11%) Repair UserSizeD took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(170, "Repair UserSizeD");
    }
    if (!StampOK(180)) {
        $t = time();
        percentage("UserAuthDaysGrouped", 11);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --members-central-grouped --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "11%) Repair UserAuthDaysGrouped took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(180, "UserAuthDaysGrouped");
    }
    if (!StampOK(190)) {
        $t = time();
        percentage("quotaday (quotamonth)...", 11);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.quotaday.php --quotamonth --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "33%)  Months tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(190, "quotaday (quotamonth)");
    }
    if (!StampOK(200)) {
        $t = time();
        percentage("Repair Youtube Ids", 11);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.repair.php --youtube --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "12%) Repair Youtube Ids took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(200, "Repair Youtube Ids");
    }
    if (!StampOK(210)) {
        $t = time();
        percentage("Running Youtube statistics", 11);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.youtube.days.php --youtube-dayz --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "12%) Running Search Words hourly took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(210, "Running Youtube statistics");
    }
    if (!StampOK(220)) {
        $t = time();
        percentage("Summarize days", 12);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --summarize-days --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "11%) Summarize days took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(220, "Summarize days");
    }
    if (!StampOK(230)) {
        $t = time();
        percentage("Running Blocked threats day", 13);
        stats_admin_events(2, "13%) Blocked threats day:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(230, "Running Blocked threats day");
    }
    if (!StampOK(240)) {
        $t = time();
        percentage("Running Visited day", 15);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --visited-days --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "15%) Visited day took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(240, "Running Visited day");
    }
    if (!StampOK(245)) {
        $t = time();
        percentage("Running Global Family sites", 16);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.familyday.php --scheduled"));
        stats_admin_events(2, "10%) Running exec.squid.stats.familyday.php took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(245, "Running Global Family sites ok");
    }
    if (!StampOK(246)) {
        $t = time();
        percentage("Running Global Users", 17);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.usersday.php --scheduled"));
        stats_admin_events(2, "10%) Running exec.squid.stats.usersday.php took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(246, "Running Global Users ok");
    }
    if (!StampOK(250)) {
        $t = time();
        percentage("Running Days Websites", 20);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.days.websites.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "20%)  Days Websites took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(250, "Running Days Websites");
    }
    if (!StampOK(260)) {
        $t = time();
        percentage("Week tables...", 21);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --week --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "29%)  Week tables... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(260, "Week tables...");
    }
    if (!StampOK(270)) {
        $t = time();
        percentage("Repair tables", 26);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.totals.php --repair --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "26%)  Repair tables took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(270, "Repair tables");
    }
    if (!StampOK(280)) {
        percentage("Youtube All", 26);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.youtube_uid.php --all --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "26%)  Youtube All took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(280, "Youtube All");
    }
    if (!StampOK(290)) {
        $t = time();
        percentage("Cache performances", 27);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --webcacheperfs --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "27%)  Cache performances took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(290, "Cache performances");
    }
    if (!StampOK(300)) {
        $t = time();
        percentage("Interface elements", 28);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.totals.php --interface --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "28%)  Interface elements took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(300, "Interface elements");
    }
    if (!StampOK(310)) {
        $t = time();
        percentage("Members central...", 29);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --members-central --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "29%)  Members central... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(310, "Members central...");
    }
    if (!StampOK(320)) {
        $t = time();
        percentage("Search Words Weekly", 29);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}//usr/share/artica-postfix/exec.squid-searchwords.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "29%)  Search Words Weekly... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(320, "Search Words Weekly");
    }
    if (!StampOK(330)) {
        $t = time();
        percentage("Week tables ( blocked )...", 30);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.blocked.week.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "30%)  Week tables ( blocked ).... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(330, "Week tables ( blocked )...");
    }
    if (!StampOK(340)) {
        $t = time();
        percentage("Months tables (1) ...", 31);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --scan-months --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "31%)  Months tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(340, "Months tables (1)");
    }
    if (!StampOK(350)) {
        $t = time();
        percentage("Months tables (2) ...", 32);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.month.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "32%)  Months tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(350, "Months tables (2)");
    }
    if (!StampOK(360)) {
        $t = time();
        percentage("Categorize Month tables (3) ...", 32);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.not-categorized.php --months --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "31%)  Months tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(360, "Categorize last 7 days");
    }
    if (!StampOK(370)) {
        $t = time();
        percentage("Months tables by users (4)...", 35);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.uid-month.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "35%)  Months tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(370, "Months tables by users (4");
    }
    if (!StampOK(380)) {
        $t = time();
        percentage("Repair categories", 40);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --repair-categories --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "40%)  Repair categories.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(370, "Repair categories");
    }
    if (!StampOK(390)) {
        $t = time();
        percentage("Categorize last days", 45);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.categorize-table.php --last-days --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "45%)  Categorize last days.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(390, "Categorize last days");
    }
    if (!StampOK(400)) {
        $t = time();
        percentage("Visited Websites", 46);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --visited-sites2 --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "25%)  Visited Websites took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(400, "Visited Websites");
    }
    if (!StampOK(410)) {
        $t = time();
        percentage("Dangerous elements", 46);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.dangerous.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "28%)  Interface elements took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(410, "Dangerous elements");
    }
    if (!StampOK(420)) {
        $t = time();
        percentage("Categorize all tables", 46);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.categorize-table.php --all --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "46%)  Categorize all tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(420, "Categorize all tables");
    }
    if (!StampOK(430)) {
        $t = time();
        percentage("Scanning Not categorized", 47);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.not-categorized.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "47%)  Categorize all tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(430, "Scanning Not categorized");
    }
    if (!StampOK(440)) {
        $t = time();
        percentage("Recategorize", 48);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.recategorize.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "48%) Recategorize.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(440, "Recategorize");
    }
    if (!StampOK(450)) {
        $t = time();
        percentage("Sync categories", 49);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --sync-categories --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "49%) Recategorize.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(450, "Sync categories");
    }
    if (!StampOK(460)) {
        $t = time();
        percentage("Global categories", 50);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.global.categories.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "50%) Global categories.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(460, "Global categories");
    }
    if (!StampOK(470)) {
        $t = time();
        percentage("Parse thumbs", 55);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --thumbs-parse --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "50%) Parse thumbs.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(470, "Parse thumbs");
    }
    if (!StampOK(480)) {
        percentage("Repair not categorized", 55);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.recategorize.missed.php --repair --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        StampDone(480, "Repair not categorized");
    }
    if (!StampOK(490)) {
        percentage("Not categorized - last 7 days", 55);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.recategorize.missed.php --last7-days --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "5%) Parse thumbs.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(490, "Not categorized - last 7 days");
    }
    if (!StampOK(500)) {
        $t = time();
        percentage("Reports", 60);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.reports.php --all --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "60%) Reports.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(500, "Reports");
    }
    if (!StampOK(510)) {
        $t = time();
        percentage("Statistics by User", 70);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.members_uid.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "70%) Statistics by user took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(510, "Statistics by User");
    }
    if (!StampOK(520)) {
        $t = time();
        percentage("Statistics by Users/Websites", 71);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.websites_uid.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "71%) Statistics by user/Websites took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(520, "Statistics by Users/Websites");
    }
    if (!StampOK(530)) {
        $t = time();
        percentage("Statistics by Users/MAC", 73);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.members_mac.php  --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "73%) Statistics by user/mac took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(530, "Statistics by Users/MAC");
    }
    if (!StampOK(540)) {
        $t = time();
        percentage("Statistics by Users/MAC/IP", 73);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.members_macip.php  --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "73%) Statistics by user/mac/ip took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(530, "Statistics by Users/MAC/IP");
    }
    if (!StampOK(550)) {
        $t = time();
        percentage("Statistics by Users/Blocked", 74);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.blocked_uid.php  --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "74%) Statistics by user/blocked:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(550, "Statistics by Users/Blocked");
    }
    if (!StampOK(560)) {
        $t = time();
        percentage("Statistics by Users/Blocked", 75);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.youtube_uid.php  --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "74%) Statistics by user/youtube:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(550, "Statistics by Users/Blocked");
    }
    percentage("{finish}:" . date("Y-m-d H:i:s"), 100);
    StampDone(1000, "{done}");
    @unlink($GLOBALS["TIMEFILE"]);
}