function templateToLatex($templateFilename, $variables) { $smarty = new Sugar_Smarty(); $smarty->left_delimiter = '<'; $smarty->right_delimiter = '>'; if (!$smarty->template_exists($templateFilename)) { $GLOBALS['log']->error('Failed to open smarty template ' . $templateFilename); return null; } // insert some translated labels into the variables array to make sure we can use translation in the latex templates if (!array_key_exists('language', $variables)) { global $app_list_strings; $variables['language'] = $app_list_strings['oqc']; // insert sugarcrm default langauge as well because we have to do some language specific includes in the latex templates global $sugar_config; $variables['default_language'] = $sugar_config['default_language']; } require_once 'include/oqc/common/Configuration.php'; $conf = Configuration::getInstance(); // add some company-specific data that might be useful in all latex templates $variables['pdfCompanyName'] = $conf->get('pdfCompanyName'); $variables['pdfCompanyAddress'] = $conf->get('pdfCompanyAddress'); $variables['pdfCompanyContactPhone'] = $conf->get('pdfCompanyContactPhone'); $variables['pdfCompanyContactFax'] = $conf->get('pdfCompanyContactFax'); $variables['pdfCompanyContactMail'] = $conf->get('pdfCompanyContactMail'); $variables['pdfCompanyContactInternet'] = $conf->get('pdfCompanyContactInternet'); $variables['pdfCopyrightNotice'] = $conf->get('pdfCopyrightNotice'); //$GLOBALS['log']->error('Smarty variables: '. var_export($variables,true)); $smarty->assign($variables); $latex = $smarty->fetch($templateFilename); $latexFilename = tempnam(TMP_DIR, TEMPLATE_TMP_PREFIX); //$GLOBALS['log']->error('OQC: Temp directory name: '.TMP_DIR); // TODO: open_basedir restriction?? if (!file_put_contents($latexFilename, $latex)) { return null; } return str_replace("\\", "/", $latexFilename); //make sure only / will be ever used. }