Exemplo n.º 1
0
 protected function processActionImportTemplate()
 {
     if ($this->request->getPost('import_template') == 'Y') {
         $res = 0;
         $error = '';
         if (is_uploaded_file($_FILES['import_template_file']['tmp_name'])) {
             $f = fopen($_FILES['import_template_file']['tmp_name'], "rb");
             $datum = fread($f, filesize($_FILES['import_template_file']['tmp_name']));
             if ($this->request->getPost('old_template')) {
                 $this->arResult['DOCUMENT_COMPLEX_TYPE'] = \Bitrix\Disk\BizProcDocumentCompatible::generateDocumentComplexType($this->arParams['STORAGE_ID']);
             }
             fclose($f);
             try {
                 $res = CBPWorkflowTemplateLoader::importTemplate($this->arResult['ID'], $this->arResult['DOCUMENT_COMPLEX_TYPE'], $this->request->getPost('import_template_autostart'), $this->request->getPost('import_template_name'), $this->request->getPost('import_template_description'), $datum);
             } catch (Exception $e) {
                 $error = preg_replace("#[\r\n]+#", " ", $e->getMessage());
             }
         }
         if (intval($res) <= 0) {
             $response = "\n\t\t\t\t\t<script>\n\t\t\t\t\t\talert('" . Loc::getMessage('BIZPROC_WFEDIT_IMPORT_ERROR') . (strlen($error) > 0 ? ': ' . $error : '') . "');\n\t\t\t\t\t\twindow.location = '" . str_replace('#ID#', $this->arResult['ID'], $this->arResult['EDIT_PAGE_TEMPLATE']) . "';\n\t\t\t\t\t</script>\n\t\t\t\t";
         } else {
             $response = "\n\t\t\t\t\t<script>\n\t\t\t\t\t\twindow.location = '" . str_replace('#ID#', $res, $this->arResult['EDIT_PAGE_TEMPLATE']) . "';\n\t\t\t\t\t</script>\n\t\t\t\t";
         }
         $this->sendResponse($response);
     }
 }