function checkCoal($id)
{
    global $l;
    $l->a('Begun checking coal...');
    sleep(12);
    $coal = retrieveCoal($id);
    $l->a('checkCoal returned status: ' . $coal['status'] . '.<br>');
    return check($coal['status']);
}
function CoalRetrieveHandler()
{
    global $l;
    $l = new llog();
    $l->a("Started CoalRetrieveHandler<br>");
    $status = 0;
    global $generalAuthKey;
    if (authorized($generalAuthKey)) {
        $coal = retrieveCoal($_REQUEST['coalId'], true);
        if (is_object($coal) || is_int($coal)) {
            $status = 20;
        } else {
            if (is_null($coal)) {
                $status = 7;
            }
        }
        if (!is_array($coal)) {
            $status = 45;
        }
        if (check($status, true)) {
            $filename = $coal['filename'];
            if (isset($_REQUEST['cs'])) {
                $filename = $filename . '.coalarc';
            }
            start_file_download($filename, strlen($coal['data']));
            if (isset($_REQUEST['cs'])) {
                echo $coal['md5'] . '|' . $coal['sha'] . '|' . $coal['s512'] . '|';
            }
            echo $coal['data'];
        }
    }
}
 function retrieve($id)
 {
     return retrieveCoal($id);
 }