*/
global $sugar_config;
global $locale;
global $current_user;
global $app_list_strings;
$filename = "SweetDBExport-" . date("m-d-Y(h:i:s)");
if ($sugar_config['disable_export'] || !empty($sugar_config['admin_export_only']) && !(is_admin($current_user) || ACLController::moduleSupportsACL($the_module) && ACLAction::getUserAccessLevel($current_user->id, $the_module, 'access') == ACL_ALLOW_ENABLED && (ACLAction::getUserAccessLevel($current_user->id, $the_module, 'admin') == ACL_ALLOW_ADMIN || ACLAction::getUserAccessLevel($current_user->id, $the_module, 'admin') == ACL_ALLOW_ADMIN_DEV))) {
    die($GLOBALS['app_strings']['ERR_EXPORT_DISABLED']);
}
ini_set('zlib.output_compression', 'Off');
ob_end_clean();
ob_start();
$header = FALSE;
$headerArray = array();
$content = "";
$sql = trim(SweetDB::getRequestVar('sql', ''));
$result = $GLOBALS['db']->query($sql, TRUE);
while ($hash = $GLOBALS['db']->fetchByAssoc($result)) {
    if (!$header) {
        $header = TRUE;
        foreach ($hash as $colName => $colValue) {
            $headerArray[] = $colName;
        }
        $content = '"' . implode('", "', $headerArray) . '"';
        $content .= "\r\n";
    }
    $lineArray = array();
    $lineData = "";
    foreach ($hash as $colName => $colValue) {
        array_push($lineArray, preg_replace("/\"/", "\"\"", $colValue));
    }
function getCurrentModule($table)
{
    $SweetDB = new SweetDB();
    $beanSearch = $SweetDB->getBean($table);
    return $beanSearch['moduleName'];
}