<?php
$sql_query = 'UPDATE ' . $config['table_prefix'] . 'calc_template SET ';
$sql_query .= <<<'EOT'
calculate_tpl = '$form = sql_select_array(FORMS_TABLE, \'id = \' . get_form_id({$print_tpl}));\r\n$form[\'doc_name\'] = form_template($form, $line, \'doc_name\');\r\nif ($form[\'type_form\'] == 2 && $form[\'pdf_import\'] == 1) {\r\n    include_once $config[\'site_path\'] . \'/include/mpdf/mpdf.php\';\r\n    $mpdf = new mPDF(\'\', \'A4\' . $form[\'orientation\'], \'\', \'\', $form[\'margin_left\'], $form[\'margin_right\'], $form[\'margin_top\'], $form[\'margin_bottom\']);\r\n    $mpdf->SetDisplayMode(\'fullwidth\');\r\n    $form[\'head_page\'] = str_replace([\'[[\', \']]\'], [\'{ldelim}ldelim{rdelim}\', \'{ldelim}rdelim{rdelim}\'], $form[\'head_page\']);\r\n    $form[\'foot_page\'] = str_replace([\'[[\', \']]\'], [\'{ldelim}ldelim{rdelim}\', \'{ldelim}rdelim{rdelim}\'], $form[\'foot_page\']);\r\n    $mpdf->SetHTMLHeader(form_template($form, $line, \'head_page\'));\r\n    $mpdf->SetHTMLFooter(form_template($form, $line, \'foot_page\'));\r\n    if ($form[\'head_form\'] != \'\') {\r\n        $mpdf->WriteHTML(form_template($form, $line, \'head_form\'));\r\n    }\r\n    $mpdf->WriteHTML(form_template($form, $line, \'body_form\'));\r\n    if ($form[\'foot_form\'] != \'\') {\r\n        $mpdf->WriteHTML(form_template($form, $line, \'foot_form\'));\r\n    }\r\n    $file_name = $form[\'doc_name\'] . \'.pdf\';\r\n    $form_text = $mpdf->Output($file_name, \'S\');\r\n    $save_link = substr(\'{$field}\', 1);\r\n    save_data_file($save_link, $ID, $file_name, $form_text);\r\n    $line[\'{$field}\'] = $file_name;\r\n} else {\r\n    if ($form[\'type_form\'] == 5) {\r\n        $file_name = $form[\'doc_name\'] . \'.docx\';\r\n    } else if ($form[\'type_form\'] == 3) {\r\n        $file_name = $form[\'doc_name\'] . \'.rtf\';\r\n    } else if ($form[\'type_form\'] == 4) {\r\n        $file_name = $form[\'doc_name\'] . \'.odt\';\r\n    } else if ($form[\'type_form\'] == 6) {\r\n        $file_name = $form[\'doc_name\'] . \'.xls\';\r\n    }\r\n    $save_link = substr(\'{$field}\', 1);\r\n    save_data_file($save_link, $ID, $file_name, form_template($form, $line, \'body_form\'));\r\n    $line[\'{$field}\'] = $file_name;\r\n}'
WHERE id = 51
EOT;
run_query($sql_query);