function DBTableEntry($db, $table)
 {
     if ($this->tabled == false) {
         $this->append('<div style="background-color:#A8FFEC;left:50px;top:50px;bottom:50px;right:50px;position:fixed;overflow-x:scroll;overflow-y:scroll;z-index:1998;text-align:center;"> ');
     }
     $this->tabled = true;
     //$main->append('<div style="z-index:2001;left:10px;position:fixed;top:10px;background:#F954A2;"><b>what</b>: What the event/project is. <b>begin</b>: When it begins. <b>end</b>: When it ends or is due. <b>location</b>: Where it happens. <b>notes</b>: e.g. assignment details.</div> -->');
     $this->append('<!-- <div style="background-color:#A8FFEC;left:50px;top:50px;bottom:50px;right:50px;position:fixed;overflow-x:scroll;overflow-y:scroll;z-index:2000;text-align:center;"> --><div style="background-color:#A8FFEC;left:50px;top:50px;bottom:50px;right:50px;position:relative;overflow-x:scroll;overflow-y:scroll;z-index:2000;text-align:center;"><table><thead><tr>');
     $this->append('<h3>' . $table . "</h3>");
     $this->append('<table><thead><tr></tr></thead><tbody><tr style="z-index:2001;left:10px;position:fixed;top:10px;background:#F954A2;" id="' . $this->newId() . '"><td id="' . $this->newId() . '"><b>Fields:</b>');
     $result = $db->getRow($table, 'id', '0');
     $this->append($result[0]['COLUMN_NAME']);
     $this->append("\n" . '<td id="' . $this->newId() . '">');
     $this->append("</td></tr></tbody></table>");
     $this->state = 0;
     $idList = $db->listIds($table);
     if (strlen($idList) < 1) {
         //No available records; only create blank row entry form
     } else {
         $idData = explode_esc(',', $idList);
         foreach ($idData as $counter => $id) {
             //$this->append('Counter: ' . $counter . '<br>');
             //$this->append('Id: ' . $id . '<br>');
             $this->DBRowEntry($db, $table, $id);
             $this->state = $id;
         }
     }
     $this->append('</table>');
     $this->DBRowEntry($db, $table, $this->state + 1);
     // $counter=0;
     // $id=1;
     // $this->append('Counter: '.$counter.'<br>');
     // $this->append('Id: '.$id.'<br>');
     // $this->DBRowEntry($db,$table,$id);
     // $counter=1;
     // $id=2;
     // $this->append('Counter: '.$counter.'<br>');
     // $this->append('Id: '.$id.'<br>');
     // $this->DBRowEntry($db,$table,$id);
     $this->append('</div>');
     $this->getQueryCount($db);
 }
 function DBTableEntry($db, $table)
 {
     $idList = $db->listIds($table);
     $idData = explode_esc(',', $idList);
     foreach ($idData as $counter => $id) {
         $this->append('Counter: ' . $counter . '<br>');
         $this->append('Id: ' . $id . '<br>');
         $this->DBRowEntry($db, $table, $id);
     }
     // $counter=0;
     // $id=1;
     // $this->append('Counter: '.$counter.'<br>');
     // $this->append('Id: '.$id.'<br>');
     // $this->DBRowEntry($db,$table,$id);
     // $counter=1;
     // $id=2;
     // $this->append('Counter: '.$counter.'<br>');
     // $this->append('Id: '.$id.'<br>');
     // $this->DBRowEntry($db,$table,$id);
 }
function retrieveCoal($id)
{
    global $l;
    $l->a("Started retrieveCoal<br>");
    $db = new FractureDB('futuqiur_ember');
    $coalInfo = $db->getRow('strings', 'id', $id);
    $detailsChunkId = $coalInfo['chunk'];
    $coalmd5 = $coalInfo['md5'];
    $detailsChunk = retrieveChunk($detailsChunkId);
    $status = $detailsChunk['status'];
    $details = unserialize($detailsChunk['data']);
    if (!is_array($details)) {
        $l->a("Status 46<br>");
        $status = 46;
    }
    $csum = Csum_import($details['csum']);
    $chunks = $details['chunks'];
    $chunks_csum = Csum_import($details['chunks_csum']);
    $retr_chunks_csum = new Csum($chunks);
    $l->a("retrieveCoalcheckpointA<br>");
    if (!matches($chunks_csum, $retr_chunks_csum)) {
        $status = 47;
    }
    $l->a("retrieveCoalcheckpointB<br>");
    if (strlen($chunks) == 0) {
        $chunk_array = array();
    } else {
        $chunk_array = explode_esc(',', $chunks);
    }
    $data = '';
    foreach ($chunk_array as $chunk_id) {
        $l->a('<br>Retrieving chunk ' . $chunk_id . '...<br>');
        $chunk_details = retrieveChunk($chunk_id);
        $chunk = $chunk_details['data'];
        //$l->a("DATA OUT A: ".$chunk);
        $chunk_csum = Csum_import($chunk_details['csum']);
        $retr_chunk_csum = new Csum($chunk);
        if (!matches($chunk_csum, $retr_chunk_csum)) {
            $status = 48;
        }
        $data = $data . $chunk;
    }
    $data_csum = new Csum($data);
    //$l->a("DATA OUT FINAL: ".$data);
    // 	$l->a(print_r($data_csum,true));
    // 	$l->a(print_r($csum,true));
    if (!matches($csum, $data_csum)) {
        $status = 49;
    }
    $db->close();
    $filename = $details['filename'];
    if (isset($details['ulfilename'])) {
        $filename = base64_decode($details['ulfilename']);
    }
    $l->a("Finished retrieveCoal<br>");
    //TODO: $csum->export() — why isn't this working?!
    return array('data' => $data, 'csum' => $csum->export(), 'filename' => $filename, 'status' => $status);
}