mysql_connection_overwrite(DATABASE);
mysql_query('set character set binary');
$res = mysql_query('select * from recUploadedFiles order by ulf_ID');
// where ulf_ID>12000 11710     12060
$current_file;
$cnt_jpg = 0;
$cnt_png = 0;
$cnt_gif = 0;
$cnt_broken = 0;
$cnt_missed = 0;
$cnt_img = 0;
$cnt_files = 0;
$cnt_external = 0;
$mem_usage = memory_get_usage();
$mem_limit = ini_get('memory_limit');
$mem_limit = _get_config_bytes($mem_limit);
print 'Memory limit: ' . $mem_limit . ' Used: ' . $mem_usage . '<br>';
//$mem_limit = $mem_limit - $mem_usage;
set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) {
    global $current_file, $cnt_broken;
    print 'Can\'t load file ID:' . $current_file . '<br>' . 'Error: ' . $errstr . '<br>';
    $cnt_broken = $cnt_broken + 0.5;
    if (0 === error_reporting()) {
        //suppression with @
    }
    return false;
    //return false && throwErrorException($errstr, 0, $errno, $errfile, $errline);
    //throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
});
//, E_WARNING);
while ($file = mysql_fetch_assoc($res)) {
//18-dty_FieldSetRectypeID
//19-rst_NonOwnerVisibility]....]
//rst_DisplayName, rst_DisplayHelpText, rst_DisplayExtendedDescription,
// rst_DefaultValue, rst_RequirementType, rst_MaxValues, rst_MinValues, rst_DisplayWidth, rst_RecordMatchOrder,
// rst_DisplayOrder, rst_DisplayDetailTypeGroupID, rst_FilteredJsonTermIDTree, rst_PtrFilteredIDs,
// rst_TermIDTreeNonSelectableIDs, rst_CalcFunctionID, rst_Status, rst_OrderForThumbnailGeneration,
// dty_TermIDTreeNonSelectableIDs, dty_FieldSetRectypeID, rst_NonOwnerVisibility] ...]
$rstC2I = getColumnNameToIndex(getRectypeStructureFieldColNames());
foreach ($rec_types as $rec_type) {
    foreach (getRectypeFields($rec_type) as $dtyID => $rdr) {
        // saw TODO need to represent the trm ids  and rectype pointer ids that are valid for this rectype.detailtype.
        array_push($detailRequirements, array($rec_type, $dtyID, $rstC2I['rst_RequirementType'] ? $rdr[$rstC2I['rst_RequirementType']] : null, $rstC2I['rst_MaxValues'] && $rdr[$rstC2I['rst_MaxValues']] ? intval($rdr[$rstC2I['rst_MaxValues']]) : null, array_key_exists('rst_DisplayName', $rstC2I) ? $rdr[$rstC2I['rst_DisplayName']] : null, $rstC2I['rst_DisplayHelpText'] ? $rdr[$rstC2I['rst_DisplayHelpText']] : null, $rstC2I['rst_RecordMatchOrder'] ? intval($rdr[$rstC2I['rst_RecordMatchOrder']]) : 0, $rstC2I['rst_DisplayWidth'] ? intval($rdr[$rstC2I['rst_DisplayWidth']]) : 0, $rstC2I['rst_DisplayOrder'] ? intval($rdr[$rstC2I['rst_DisplayOrder']]) : 0, $rstC2I['rst_DisplayExtendedDescription'] ? $rdr[$rstC2I['rst_DisplayExtendedDescription']] : null, $rstC2I['rst_DefaultValue'] ? $rdr[$rstC2I['rst_DefaultValue']] : null, $rstC2I['rst_MinValues'] ? intval($rdr[$rstC2I['rst_MinValues']]) : 0, $rstC2I['rst_DisplayDetailTypeGroupID'] ? $rdr[$rstC2I['rst_DisplayDetailTypeGroupID']] : null, $rstC2I['rst_FilteredJsonTermIDTree'] ? $rdr[$rstC2I['rst_FilteredJsonTermIDTree']] : null, $rstC2I['rst_TermIDTreeNonSelectableIDs'] ? $rdr[$rstC2I['rst_TermIDTreeNonSelectableIDs']] : null, $rstC2I['dty_TermIDTreeNonSelectableIDs'] ? $rdr[$rstC2I['dty_TermIDTreeNonSelectableIDs']] : null, $rstC2I['rst_PtrFilteredIDs'] ? $rdr[$rstC2I['rst_PtrFilteredIDs']] : null, $rstC2I['rst_CalcFunctionID'] ? $rdr[$rstC2I['rst_CalcFunctionID']] : null, $rstC2I['rst_OrderForThumbnailGeneration'] ? $rdr[$rstC2I['rst_OrderForThumbnailGeneration']] : null, $rstC2I['rst_Status'] ? $rdr[$rstC2I['rst_Status']] : null, $rstC2I['rst_NonOwnerVisibility'] ? $rdr[$rstC2I['rst_NonOwnerVisibility']] : null));
        //20-Non-Owner Visibility
    }
}
$commonData = array("users" => $users, "workgroups" => $workgroups, "ratings" => array("0" => "not rated", "1" => "*", "2" => "**", "3" => "***", "4" => "****", "5" => "*****"), "recordTypes" => $recordTypes, "detailTypes" => $detailTypes, "detailRequirements" => $detailRequirements, 'max_post_size' => _get_config_bytes(ini_get('post_max_size')), 'max_file_size' => _get_config_bytes(ini_get('upload_max_filesize')));
if (!@$_REQUEST["json"]) {
    print "var HAPI_commonData = ";
}
print json_encode($commonData);
if (!@$_REQUEST["json"]) {
    print ";\n";
}
function _fix_integer_overflow($size)
{
    if ($size < 0) {
        $size += 2.0 * (PHP_INT_MAX + 1);
    }
    return $size;
}
function _get_config_bytes($val)