Files
crm.clientright.ru/GetMeetingText.php

114 lines
4.8 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 27 Nov 2077 05:00:00 GMT"); // Date in the past
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers", "origin, x-requested-with, content-type");
header("Access-Control-Allow-Methods", "GET, POST");
error_reporting(E_ALL);
ini_set('display_errors', '1');
include_once 'modules/Users/Users.php';
include_once 'include/utils/CommonUtils.php';
require_once('include/Webservices/Utils.php');
require_once 'include/Webservices/Create.php';
require_once 'include/utils/Kontur.php';
require_once 'includes/Loader.php';
vimport ('includes.runtime.Globals');
vimport ('includes.runtime.BaseModel');
vimport ('includes.runtime.LanguageHandler');
$crmid = $_REQUEST['id'];
$key = GetMeetingKey($crmid);
if ($key <> 'none') {
$dialog = GetTranscription($key);
$text4file = ''; // Тут у нас будет текст, который сохраним во внешний файл
$filename = 'Протокол встречи.txt'; // Имя файла аттача
// А здесь html-код таблицы для внутреннего хранения в Документе
$htmltable = '<table style="border: 1px solid black;">
<tr>
<td style="border: 1px solid black; text-align: center;" width="7%"><strong>Время</strong></td>
<td style="border: 1px solid black; text-align: center;" width="10%"><strong>Имя</strong></td>
<td style="border: 1px solid black; text-align: center;" width="83%"><strong>Реплика</strong></td>
</tr>';
foreach ($dialog as $key => $value) {
$name = $value['name'];
$text = $value['text'];
$start = $value['start'];
// Добавляем строку в таблицу
$htmltable .= '<tr>
<td style="border: 1px solid black; text-align: center;">'.$start.'</td>
<td style="border: 1px solid black; text-align: center;">'.$name.'</td>
<td style="border: 1px solid black;">'.$text.'</td>
</tr>';
// И строку в файл для аттача
$text4file .= $start.', '.$name.': '.$text.PHP_EOL;
}
$htmltable .= '</table>';
// Создаем Документ с таблицей в качестве внутреннего содержимого
$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;
}
?>