86 lines
3.0 KiB
PHP
86 lines
3.0 KiB
PHP
<?php
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
|
|
|
|
set_time_limit(0);
|
|
ini_set('memory_limit', '8192M');
|
|
|
|
if (isset($_POST['event_id']) && $_SESSION['id']) {
|
|
|
|
$user_id = $_SESSION['id'];
|
|
$post = clearInputData($_POST);
|
|
$event_id = (!empty($post['event_id'])) ? $post['event_id'] : null;
|
|
$client_id = (!empty($post['client_id'])) ? $post['client_id'] : null;
|
|
$email = (!empty($post['email'])) ? $post['email'] : null;
|
|
$theme = (!empty($post['theme'])) ? $post['theme'] : null;
|
|
$text = (!empty($post['text'])) ? $post['text'] : "";
|
|
|
|
if (!is_null($client_id)) {
|
|
$email = mysql_result(mysql_query("SELECT email FROM clients WHERE id = $client_id"),0);
|
|
} else if (!is_null($email)) {
|
|
$email = explode(',', $email);
|
|
}
|
|
|
|
if (!is_null($event_id)) {
|
|
|
|
$docs_q = '';
|
|
$files = [];
|
|
|
|
if ($post['from'] == 'clients')
|
|
$docs_q = mysql_query("SELECT * FROM clients_files WHERE event_id = '". $event_id ."'");
|
|
|
|
if (!empty($docs_q)) {
|
|
while ($file = mysql_fetch_assoc($docs_q)) {
|
|
|
|
$path = 'https://uf.joywork.ru/upload/clients/'.$file['client_id'].'/'.$file['guid'].'.'.$file['type'];
|
|
if ($file['req_id'] > 0) {
|
|
$path = 'https://uf.joywork.ru/upload/reqs/' . $file['req_id'] . '/' . $file['guid'] . '.' . $file['type'];
|
|
}
|
|
|
|
if (!is_dir($_SERVER['DOCUMENT_ROOT'] . "/upload/temp")) {
|
|
mkdir($_SERVER['DOCUMENT_ROOT'] . "/upload/temp");
|
|
}
|
|
if (!is_dir($_SERVER['DOCUMENT_ROOT'] . "/upload/temp/" . $file['req_id'])) {
|
|
mkdir($_SERVER['DOCUMENT_ROOT'] . "/upload/temp/" . $file['req_id']);
|
|
}
|
|
|
|
$newPath = $_SERVER['DOCUMENT_ROOT'] . "/upload/temp/" . $file['req_id'] . '/' . $file['guid'] . '.' . $file['type'];
|
|
|
|
file_put_contents($newPath, fopen($path, 'r'));
|
|
|
|
$path = $newPath;
|
|
|
|
|
|
$files['paths'][] = $path;
|
|
$files['names'][] = $file['name'];
|
|
}
|
|
}
|
|
|
|
if (!empty($files) && $email && $theme) {
|
|
$result = true;
|
|
if (is_array($email)) {
|
|
foreach ($email as $addr) {
|
|
if (!mailClientByIdWithConfirm($user_id, trim($addr), $theme, $text, $files['paths'], $files['names'], false, false)) {
|
|
$result = false;
|
|
}
|
|
}
|
|
} else {
|
|
if (!mailClientByIdWithConfirm($user_id, trim($email), $theme, $text, $files['paths'], $files['names'], false, false)) {
|
|
$result = false;
|
|
}
|
|
}
|
|
|
|
foreach ($files['paths'] as $i => $path) {
|
|
if (strpos($path, "upload/temp/") !== false) {
|
|
unlink($path);
|
|
}
|
|
}
|
|
|
|
echo json_encode(['result' => $result]);
|
|
exit();
|
|
}
|
|
}
|
|
|
|
echo json_encode(['result' => false]);
|
|
}
|