<?php
$sql_query = 'INSERT INTO `' . $config["table_prefix"] . 'calc_template` ';
$sql_query .= <<<'EOT'
(`id`, `name`, `calculate_tpl`, `params`, `type`, `tpl_name`, `javascript_tpl`, `tpl_category`, `calc_types`) VALUES
(51,	'Сохранение шаблона печати в поле типа файл',	'$form = sql_select_array(FORMS_TABLE,\r\n    \'id = {$print_tpl}\'\r\n);\r\nif ($form[\'type_form\'] == 2 && $form[\'pdf_import\'] == 1) {\r\n    include $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    $file_name = $form[\'doc_name\'] . \'.pdf\';\r\n    $form_text = \'\';\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, $ID, \"body_form\"));\r\n    if ($form[\'foot_form\'] != \'\') {\r\n        $mpdf->WriteHTML(form_template($form, $line, \"foot_form\"));\r\n    }\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}',	'{\r\n    \"title\": \"Сохранение шаблона печати в поле типа файл\",\r\n    \"help\": \"tpl_print_save\",\r\n    \"parameters\": {\r\n        \"print_tpl\": {\r\n            \"type\": \"Template\",\r\n            \"name\": \"print_tpl\",\r\n            \"description\": \"Выберите шаблон печати\",\r\n            \"tpl_type\": \"print\",\r\n            \"help\": \"tpl_print_help_save\"\r\n        },\r\n        \"field\": {\r\n            \"type\": \"Field\",\r\n            \"name\": \"field\",\r\n            \"description\": \"Выберите поле для сохранения шаблона\",\r\n            \"type_field\": \"6\",\r\n            \"help\": \"tpl_field\"\r\n        }\r\n    }\r\n}',	'calc',	'save_tpl_in_field.tpl',	'',	6,	'[1]'),
(61,	'Печать шаблона',	'$print_tpl = {$print_tpl};\n?>\n<script>\nvar url = location[\'origin\'] + \'/forms.php?table=<?=$table_id?>&mode=print&form=<?=$print_tpl?>\';\nlocation.href = url;\n</script>\n<?php',	'{\n    \"title\": \"Печать шаблона\",\n    \"help\": \"tpl_print\",\n    \"parameters\": {\n        \"print_tpl\": {\n            \"type\": \"Template\",\n            \"name\": \"print_tpl\",\n            \"description\": \"Выберите шаблон печати\",\n            \"tpl_type\": \"print\",\n            \"help\": \"tpl_print_help\"\n        }\n    }\n}',	'calc',	'tpl_print.tpl',	'',	6,	'[1]');
EOT;
run_query($sql_query);