/**
 * get rectype usageCount and update cache value if exist
 * usageCount = {rtyID:nonzero-count,...}
 * @return    object non-zero usage counts indexed by rtyID
 * @uses      DATABASE
 * @uses      getCachedData()
 * @uses      setCachedData()
 * @uses      getAllRectypeStructures()
 */
function updateRecTypeUsageCount()
{
    $cacheKey = DATABASE . ":AllRecTypeInfo";
    $rtStructs = getCachedData($cacheKey);
    if ($rtStructs) {
        $usageCount = getRecTypeUsageCount();
        $rtStructs['usageCount'] = $usageCount;
        //save into cache
        setCachedData($cacheKey, $rtStructs);
        return $usageCount;
    } else {
        //there is no cache - create entire structure
        $rtStructs = getAllRectypeStructures(true);
        return $rtStructs['usageCount'];
    }
}
} else {
    $is_direct_call = false;
}
if (!defined('SAVE_URI')) {
    define("SAVE_URI", "disabled");
}
// using ob_gzhandler makes this stuff up on IE6-
//ini_set("zlib.output_compression_level", 5);
//ob_start('ob_gzhandler');
require_once dirname(__FILE__) . "/../connect/applyCredentials.php";
require_once dirname(__FILE__) . "/getRecordInfoLibrary.php";
mysql_connection_select(DATABASE);
if ($is_direct_call) {
    ob_start();
    header("Content-type: text/javascript");
}
$rv = array();
if (@$_REQUEST['action'] == 'usageCount') {
    $rv = getRecTypeUsageCount();
} else {
    $rv['rectypes'] = getAllRectypeStructures(false);
    $rv['detailTypes'] = getAllDetailTypeStructures(false);
    $rv['terms'] = getTerms(false);
    $rv['icon_url'] = HEURIST_ICON_URL;
    //HEURIST_SERVER_URL.
}
print json_encode($rv);
//print json_format($rv);
if ($is_direct_call) {
    ob_end_flush();
}