global $current_user;
// get settings
$answer = array();
$officeParams = array();
$patternSettings = 'officeTemplate';
foreach ($_REQUEST as $key => $val) {
    if (strpos($key, $patternSettings) === 0) {
        $officeParams[strtolower(substr($key, strlen($patternSettings)))] = $val;
    }
}
$record_id = $_REQUEST['record'];
if (empty($record_id) or empty($officeParams['record'])) {
    sugar_die($mod_strings['ERR_REPORT_BEAN']);
}
$bean = new OfficeReportMerge();
$bean->retrieve($record_id);
$format = strtolower($bean->extension_template);
// check user rights on this report
if (!Reports_Utils::check_access_report($currentModule, $record_id, 'detail')) {
    sugar_die($mod_strings['ERR_REPORT_BEAN']);
}
// check user rights on this record
if (!Reports_Utils::check_access_report($bean->report_module, $officeParams['record'], 'export')) {
    sugar_die($mod_strings['ERR_REPORT_BEAN']);
}
$officeConfig = Reports_Utils::get_config();
if (isset($officeParams['link'])) {
    //need download template
    //generate link for this
    $answer['download'] = $mod_strings['BOX_DOWNLOAD_LINK'] . ':&nbsp;<a href="index.php?module=' . $bean->module_dir . '&action=processOfficeReport&to_pdf=true&officeTemplateDownload=on&record=' . $record_id . '&officeTemplateRecord=' . $officeParams['record'] . '" target="_blank" title="' . $mod_strings['BOX_DOWNLOAD_ON_LOCAL_PC'] . '">' . $mod_strings['BOX_DOWNLOAD_ON_LOCAL_PC'] . '</a>';
}