return $datetime->format("Y-m-d H:i:s.u");
}
echo "\n" . timestamp() . ": Starting class totals check.\n";
// rootpath my be required depending on web server setup.
//$rootpath =  basename(dirname(dirname(__FILE__)));
$rootpath = '';
$userresult = $mysqli->prepare("SELECT id FROM users WHERE username = ? LIMIT 1");
$userresult->bind_param('s', $cfg_cron_user);
$userresult->execute();
$userresult->bind_result($userid);
$userresult->fetch();
$userresult->close();
$end_dateSQL = 'NOW()';
$start_dateSQL = 'SUBDATE(NOW(), INTERVAL 1 DAY)';
$server = 'https://' . $cfg_web_host . '/';
$class_totals = new class_totals();
// Process the papers in range checking the totals.
$class_totals->process_papers($mysqli, $cfg_cron_user, $cfg_cron_passwd, $rootpath, $userid, $start_dateSQL, $end_dateSQL, $server);
// Get any failures.
$status = 'failure';
$testresult = $mysqli->prepare("SELECT user_id, paper_id, errors FROM class_totals_test_local WHERE status = ? and user_id = {$userid}");
$testresult->bind_param('s', $status);
$testresult->execute();
$testresult->bind_result($user_id, $paper_id, $errors);
// Log and email errors to support.
$message = '';
while ($testresult->fetch()) {
    $errors = strip_tags($errors);
    $message .= 'Failure: user - ' . $user_id . ', paper - ' . $paper_id . ', error - ' . $errors . "\n";
}
$testresult->close();
    } elseif ($_POST['period'] == 'year') {
        $start_dateSQL = 'SUBDATE(NOW(), INTERVAL 1 YEAR)';
    } elseif ($_POST['period'] == '2year') {
        $start_dateSQL = 'SUBDATE(NOW(), INTERVAL 2 YEAR)';
    } elseif ($_POST['period'] == '3year') {
        $start_dateSQL = 'SUBDATE(NOW(), INTERVAL 3 YEAR)';
    } elseif ($_POST['period'] == '6year') {
        $start_dateSQL = 'SUBDATE(NOW(), INTERVAL 6 YEAR)';
    }
} else {
    $start_dateSQL = 'SUBDATE(NOW(), INTERVAL 5 YEAR)';
}
if (!isset($protocol)) {
    $protocol = 'https://';
}
if (isset($_POST['server']) and $_POST['server'] != '') {
    $server = $_POST['server'];
} else {
    $server = $protocol . $_SERVER['SERVER_ADDR'];
}
$userid = $userObject->get_user_ID();
$rootpath = $configObject->get('cfg_root_path');
$username = $userObject->get_username();
$password = $_POST['passwd'];
if (isset($_POST['paper']) and $_POST['paper'] != '') {
    $class_totals = new class_totals();
    $class_totals->process_papers($mysqli, $username, $password, $rootpath, $userid, $start_dateSQL, $end_dateSQL, $server, $_POST['paper']);
} else {
    $class_totals = new class_totals();
    $class_totals->process_papers($mysqli, $username, $password, $rootpath, $userid, $start_dateSQL, $end_dateSQL, $server);
}