'none') { $dialog = GetTranscription($key); $text4file = ''; // Тут у нас будет текст, который сохраним во внешний файл $filename = 'Протокол встречи.txt'; // Имя файла аттача // А здесь html-код таблицы для внутреннего хранения в Документе $htmltable = ''; foreach ($dialog as $key => $value) { $name = $value['name']; $text = $value['text']; $start = $value['start']; // Добавляем строку в таблицу $htmltable .= ''; // И строку в файл для аттача $text4file .= $start.', '.$name.': '.$text.PHP_EOL; } $htmltable .= '
Время Имя Реплика
'.$start.' '.$name.' '.$text.'
'; // Создаем Документ с таблицей в качестве внутреннего содержимого $notesid = $adb->getUniqueID("vtiger_crmentity"); $date_var = date('Y-m-d H:i:s'); $ownerid = getUserId($crmid); // Достаем ответственного по Проекту $sql1 = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,createdtime,modifiedtime) values(?,?,?,?,?,?)"; $params1 = array($notesid, $ownerid, $ownerid, 'Documents', $adb->formatDate($date_var, true), $adb->formatDate($date_var, true)); $adb->pquery($sql1, $params1); $sql2 = "insert into vtiger_notes(notesid, title, filename, notecontent, folderid, filetype, filelocationtype, filestatus, filesize) values(?,?,?,?,?,?,?,?,?)"; $params2 = array($notesid, 'Трансрибация видеовстречи', $filename, $htmltable, 1, 'text/plain', 'I', 1, mb_strlen($text4file)); $adb->pquery($sql2, $params2); // Линкуем его к Проекту $sql3 = "insert into vtiger_senotesrel(crmid, notesid) values(?,?)"; $adb->pquery($sql3, array($crmid, $notesid)); // Теперь создадим сам файл для Документа $attachid = $adb->getUniqueID("vtiger_crmentity"); $date_var = date('Y-m-d H:i:s'); $upload_file_path = decideFilePath(); file_put_contents($upload_file_path . $attachid . "_" . $filename, $text4file); $sql1 = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,createdtime,modifiedtime) values(?,?,?,?,?,?)"; $params1 = array($attachid, $ownerid, $ownerid, 'Documents Attachment', $adb->formatDate($date_var, true), $adb->formatDate($date_var, true)); $adb->pquery($sql1, $params1); $sql2 = "insert into vtiger_attachments(attachmentsid, name, type, path, storedname) values(?,?,?,?,?)"; $params2 = array($attachid, $filename, 'text/plain', $upload_file_path, $filename); $adb->pquery($sql2, $params2); // Линкуем его к Документу $sql3 = "insert into vtiger_seattachmentsrel(crmid, attachmentsid) values(?,?)"; $adb->pquery($sql3, array($notesid, $attachid)); $result = 'ok'; } else { $result = 'none'; } echo $result; function getUserId($projectid) { global $adb; $query = 'select e.smownerid as userid from vtiger_project p where p.projectid = ?'; $result = $adb->pquery($query, array($projectid)); if ($adb->num_rows($result) == 1) { // Единственный активный Проект - вытащим оттуда ответственного $output = $adb->query_result($result, 0, 'userid'); } else { // Почему-то проектов нет - значит ответственным будет владелец админ $output = 1; } return $output; } ?>