Created
June 21, 2019 12:54
-
-
Save hackimov/143623fe01ec8505a29ec343f3c5c371 to your computer and use it in GitHub Desktop.
Edite Word File in Bitrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(isset($_REQUEST["WORD_ID"])) | |
{ | |
# подключим пролог | |
include($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php"); | |
# 1 Пользователи с Админкой, 8 Отдел кадров, 9 Руководство | |
$arGroupAvalaible = array(1,8,9); | |
# массив групп, в которых состоит пользователь | |
$arGroups = CUser::GetUserGroup($USER->GetID()); | |
# далее проверяем, если пользователь вошёл хотя бы в одну из групп, то позволяем ему что-либо делать | |
$result_intersect = array_intersect($arGroupAvalaible, $arGroups); | |
if(!empty($result_intersect)) | |
{ | |
# подключим модуль Сform | |
CModule::IncludeModule("form"); | |
$date = CFormResult::GetByID($_REQUEST["WORD_ID"]); | |
$arResult = $date->Fetch(); | |
# получаем подробные данные анкеты | |
$arAnswer = CFormResult::GetDataByID($_REQUEST["WORD_ID"],array(),$null,$null); | |
# удаляем старую не акутальную анкету | |
unlink('seeker_doc_print.docx'); | |
# создаём зип объект | |
$zip = new ZipArchive(); | |
# путь к файлу шаблону | |
$templateFilename = 'word/seeker_doc_template.docx'; | |
# результирующий файл | |
$inputFilename = 'word/seeker_doc_print.docx'; | |
if(!copy($templateFilename, $inputFilename)) { | |
die("Не могу скопировать '$templateFilename' to '$inputFilename'"); | |
} | |
# Открываем документ Microsoft Word .docx | |
if ($zip->open($inputFilename, ZipArchive::CREATE)!==TRUE) { | |
echo "Не могу открыть $inputFilename"; die; | |
} | |
# Парсим страничку | |
$xml = $zip->getFromName('word/document.xml'); | |
if(!empty($arAnswer["selectedVacancieSOIS"][0]["USER_TEXT"])) | |
{ | |
$arAnswer["selectedVacancieSOIS"][0]["ANSWER_VALUE"] = $arAnswer["selectedVacancieSOIS"][0]["USER_TEXT"]; | |
} | |
$pieces = explode("•", $arAnswer['lostlevelSOIS'][0]["USER_TEXT"]); | |
foreach ($pieces as $piece) | |
{ | |
$arPieces[] = "$piece<w:br/>"; | |
} | |
$lostlevelSOIS = implode("•", $arPieces); | |
$lostworkSOIS1 =$arAnswer['lostworkSOIS'][0]["USER_TEXT"]; | |
$lostworkSOIS2 =$arAnswer['lostworkSOIS'][1]["USER_TEXT"]; | |
$lostworkSOIS3 =$arAnswer['lostworkSOIS'][2]["USER_TEXT"]; | |
$lostworkSOIS4 = $arAnswer['lostworkSOIS'][3]["USER_TEXT"]; | |
$lostworkSOISMain = "$lostworkSOIS1 <w:br/>$lostworkSOIS2 <w:br/>$lostworkSOIS3 <w:br/>$lostworkSOIS4 <w:br/>"; | |
# Заменяем своими записями | |
$xml = str_replace('DATECREATE', $arResult["DATE_CREATE"], $xml); | |
$xml = str_replace('selectedVacancieSOIS', $arAnswer["selectedVacancieSOIS"][0]["ANSWER_VALUE"], $xml); | |
$xml = str_replace('LastnameSOIS', $arAnswer["LastnameSOIS"][0]["USER_TEXT"], $xml); | |
$xml = str_replace('NameSOIS', $arAnswer["NameSOIS"][0]["USER_TEXT"], $xml); | |
$xml = str_replace('2nameSOIS', $arAnswer["2nameSOIS"][0]["USER_TEXT"], $xml); | |
$xml = str_replace('gender', $arAnswer['gender'][0]["ANSWER_TEXT"], $xml); | |
$xml = str_replace('BirthdaySOIS', $arAnswer["BirthdaySOIS"][0]["USER_TEXT"], $xml); | |
$xml = str_replace('adresSOIS', $arAnswer["adresSOIS"][0]["USER_TEXT"], $xml); | |
$xml = str_replace('PhoneSOIS', $arAnswer["PhoneSOIS"][0]["USER_TEXT"], $xml); | |
$xml = str_replace('emailSOIS', $arAnswer["emailSOIS"][0]["USER_TEXT"], $xml); | |
$xml = str_replace('TypeeduSOIS', $arAnswer['TypeeduSOIS'][0]["ANSWER_TEXT"], $xml); | |
$xml = str_replace('NameeduSOIS', $arAnswer['NameeduSOIS'][0]["USER_TEXT"], $xml); | |
$xml = str_replace('PostGraduateDegreeSOIS', $arAnswer['PostGraduateDegreeSOIS'][0]["ANSWER_VALUE"], $xml); | |
$xml = str_replace('DopeduSOIS', $arAnswer['DopeduSOIS'][0]["USER_TEXT"], $xml); | |
$xml = str_replace('profeduSOIS', $arAnswer['profeduSOIS'][0]["USER_TEXT"], $xml); | |
$xml = str_replace('LangeduSOIS', $arAnswer['LangeduSOIS'][0]["USER_TEXT"], $xml); | |
$xml = str_replace('GuidingWorkSOISDescription', $arAnswer['GuidingWorkSOISDescription'][0]["USER_TEXT"], $xml); | |
$xml = str_replace('GuidingWorkSOIS', $arAnswer['GuidingWorkSOIS'][0]["ANSWER_TEXT"], $xml); | |
$xml = str_replace('lostworkSOIS', $lostworkSOISMain, $xml); # выводим несколько записей | |
$xml = str_replace('lostlevelSOIS', $lostlevelSOIS, $xml); | |
$xml = str_replace('portfoliotextSOIS', $arAnswer['portfoliotextSOIS'][0]["USER_TEXT"], $xml); | |
$xml = str_replace('newdoljSOIS', $arAnswer['newdoljSOIS'][0]["USER_TEXT"], $xml); | |
$xml = str_replace('departmentSOIS', $arAnswer['departmentSOIS'][0]["ANSWER_TEXT"], $xml); | |
$xml = str_replace('typetimeworkSOIS', $arAnswer['typetimeworkSOIS'][0]["ANSWER_TEXT"], $xml); | |
$xml = str_replace('whatisSOIS', $arAnswer['whatisSOIS'][0]["USER_TEXT"], $xml); | |
$xml = str_replace('priceSOIS', $arAnswer["priceSOIS"][0]["USER_TEXT"], $xml); | |
$xml = str_replace('rekomenSOIS', $arAnswer['rekomenSOIS'][0]["USER_TEXT"], $xml); | |
$xml = str_replace('aboutvakanSOIS', $arAnswer['aboutvakanSOIS'][0]["USER_TEXT"], $xml); | |
$xml = str_replace('addSOIS', $arAnswer['addSOIS'][0]["USER_TEXT"], $xml); | |
# Записываем файл | |
if ($zip->addFromString('word/document.xml', $xml)) { echo 'Файл Записан!'; } | |
else { echo 'Не могу записать файл! Проверьте права на запись в текущей дериктории'; } | |
$zip->close(); | |
# отправляем юзеру заголовок для скачивания | |
header("Location: $inputFilename"); | |
} | |
else{?> | |
<p style="color:#ff0000"> | |
<br> | |
Доступ Зарещен! | |
</p> | |
<?} | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment