Commit 3f09f843 authored by Vitaly Lipatov's avatar Vitaly Lipatov

server.php: divide accept typo request and send emails

parent 92494a78
......@@ -63,7 +63,7 @@ if (!validate()) {
return false;
}
//TODO - работу со старыми бразуерами будем подерживать или нет? Если будем, то надо доработать работу на стороне сервера (закрытие окна)
//TODO - работу со старыми браузерами будем подерживать или нет? Если будем, то надо доработать работу на стороне сервера (закрытие окна)
$userdata['old_browser'] = getRequest('old_browser', 0);
$userdata['comment'] = htmlspecialchars(rawurldecode(getRequest('comment', '')));
$userdata['corrected'] = htmlspecialchars(rawurldecode(getRequest('corrected', '')));
......@@ -85,64 +85,21 @@ if (!isset($mas_url['host'])) {
* - отправка писем
* ******************************** */
/* Достаем номер сайта и email-ы пользователей */
try {
/*
$query_emails = "SELECT r.id_site AS id_site,
u.email AS email
FROM users AS u, responsible AS r
WHERE r.id IN (
SELECT r.id
FROM responsible AS r
JOIN sites AS s
WHERE s.site REGEXP ?
AND r.id_site = s.id
AND r.status = '1')
AND r.id_user = u.id";
$STH = $DBH->prepare($query_emails);
// 08.06.17: supports every protocol
// ^(https?://)*(www.)*etersoft.com/?$
$STH->execute(array("^(https?://)*(www.)*" . $mas_url["host"] . "/?$"));
*/
$id_site = get_site_id($DBH, $userdata['url']);
$query_emails = "SELECT r.id_site AS id_site,
u.email AS email
FROM users AS u
INNER JOIN responsible AS r ON r.id_user = u.id
WHERE r.id_site = $id_site
AND r.status = '1'";
//error_log($query_emails);
$STH = $DBH->prepare($query_emails);
$STH->execute(array($id_site));
if ($STH->rowCount() > 0) {
$email_users = array();
while ($row = $STH->fetch(PDO::FETCH_ASSOC)) {
$email_users[] = array(
'id_site' => $row['id_site'],
'email' => $row['email']
);
}
} else {
$email_users = false;
}
} catch (PDOException $e) {
error_log($e);
echoJsonData(array('success' => 'false', 'message' => $_language[$code_language]["error_support_site"]));
return;
}
/* Если активных пользователей за сайт нет, то возвращаем сообщение об ошибке */
if ($email_users) {
try {
$data = array(null, $email_users[0]['id_site'], $userdata['url'], $userdata['text'], $userdata['context'], $userdata['corrected'], $userdata['comment'], 0, getIp());
$data = array(null, $id_site, $userdata['url'], $userdata['text'], $userdata['context'], $userdata['corrected'], $userdata['comment'], 0, getIp());
$STH = $DBH->prepare("INSERT INTO messages (id, site_id, link, text, context, corrected, comment, date, status, user_ip) VALUES (?, ?, ?, ?, ?, ?, ?, DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s'), ?, ?)");
$result = $STH->execute($data);
if ($result !== true) {
// TODO: повторение с catch ниже
$errorInfo = $STH->errorInfo();
error_log("Возникла ошибка при добавлении опечатки в базу данных. Код SQLSTATE: {$errorInfo[0]}.
Код ошибки драйвера: {$errorInfo[1]}. Текст ошибки: {$errorInfo[2]}");
......@@ -156,6 +113,32 @@ if ($email_users) {
return;
}
try {
$email_users = array();
$query_emails = "SELECT r.id_site AS id_site,
u.email AS email
FROM users AS u
INNER JOIN responsible AS r ON r.id_user = u.id
WHERE r.id_site = $id_site
AND r.status = '1'";
$STH = $DBH->prepare($query_emails);
$STH->execute(array($id_site));
if ($STH->rowCount() > 0) {
while ($row = $STH->fetch(PDO::FETCH_ASSOC)) {
$email_users[] = array(
'id_site' => $row['id_site'],
'email' => $row['email']
);
}
}
} catch (PDOException $e) {
error_log($e);
return;
}
if ($email_users) {
$controlPanelUrl = getControlPanelUrl();
$message_email = "";
......@@ -181,8 +164,10 @@ if ($email_users) {
echoJsonData(array('success' => 'false', 'message' => $_language[$code_language]['mail_error']));
return;
}
/*
} else {
error_log("No active users for {$mas_url["scheme"]}://{$mas_url["host"]}");
echoJsonData(array('success' => 'false', 'message' => $_language[$code_language]['error_support_site']));
return;
*/
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment