top.window.location = '../../index.php'"; exit; } require_once __DIR__ . "/" . "../../includes/include_basics_only.php"; require_once __DIR__ . "/" . "../../includes/classes/ConnectPDO.php"; use OcomonApi\Support\Email; use includes\classes\ConnectPDO; $conn = ConnectPDO::getInstance(); $auth = new AuthNew($_SESSION['s_logado'], $_SESSION['s_nivel'], 2, 1); if (!isset($_POST['numero'])) { exit(); } $post = $_POST; $exception = ""; $sent = false; $numero = (int) $post['numero']; $user = (int) $_SESSION['s_uid']; $now = date("Y-m-d H:i:s"); $data['success'] = true; $data['message'] = ""; $data['csrf_session_key'] = (isset($post['csrf_session_key']) ? $post['csrf_session_key'] : ""); $data['entry'] = (isset($post['entry']) && !empty($post['entry']) ? noHtml($post['entry']) : ""); $data['status'] = (isset($post['status']) && !empty($post['status']) ? (int)$post['status'] : ""); if (empty($data['entry'])) { $data['success'] = false; $data['message'] = message('warning', '', TRANS('MSG_EMPTY_DATA'), ''); $data['field_id'] = "entryRequestFeedback"; echo json_encode($data); return false; } if (empty($data['status'])) { $data['success'] = false; $data['message'] = message('warning', '', TRANS('MSG_EMPTY_DATA'), ''); $data['field_id'] = "statusRequestFeedback"; echo json_encode($data); return false; } $row = getTicketData($conn, $numero); if (!count($row)) { $data['success'] = false; $data['message'] = message('danger', '', TRANS('NO_RECORDS_FOUND'), ''); echo json_encode($data); return false; } $config = getConfig($conn); $isRequester = $_SESSION['s_uid'] == $row['aberto_por']; $isResponsible = isTicketTreater($conn, $numero, $_SESSION['s_uid']); $isClosed = ($row['status'] == 4 ? true : false); $isDone = ($row['status'] == $config['conf_status_done'] ? true : false); $isScheduled = ($row['oco_scheduled'] == 1 ? true : false); $statusAnswered = $config['stat_out_inactivity']; $statusToMonitor = $config['stats_to_close_by_inactivity']; $arrayStatusToMonitor = []; if (!empty($statusToMonitor)) { $arrayStatusToMonitor = explode(',', (string)$statusToMonitor); $alreadyRequestedFeedback = (in_array($row['status'], $arrayStatusToMonitor) ? true : false); $alreadyAnswered = ($row['status'] == $statusAnswered ? true : false); $allowRequestFeedback = (!$isClosed && !$isDone && !$isScheduled && !$isRequester && $isResponsible && !$alreadyRequestedFeedback && !$alreadyAnswered); } if (!$allowRequestFeedback) { $data['success'] = false; $data['message'] = message('warning', '', TRANS('MSG_NOT_ALLOW_REQUEST_FEEDBACK'), ''); echo json_encode($data); return false; } /* Para pegar o estado da ocorrência antes da atualização e permitir a gravação do log de modificações com recordLog() */ $arrayBeforePost = []; $arrayBeforePost['status_cod'] = $row['status']; /* Configurações de e-mail */ $rowconfmail = getMailConfig($conn); /* E-mail de quem abriu o chamado */ $openerEmail = getOpenerEmail($conn, $numero); //Checa se já existe algum registro de log - caso não existir grava o estado atual $firstLog = firstLog($conn, $numero, 'NULL', 1); if (!csrf_verify($post, $data['csrf_session_key'])) { $data['success'] = false; $data['message'] = message('warning', 'Ooops!', TRANS('FORM_ALREADY_SENT'),''); echo json_encode($data); return false; } if (!empty($row['data_atendimento'])) { $sql = "UPDATE ocorrencias SET `status` = {$data['status']}, operador = {$user} WHERE numero = '{$numero}'"; } else { $sql = "UPDATE ocorrencias SET `status` = 2, operador = {$user}, data_atendimento = '{$now}' WHERE numero = '{$numero}'"; } try { $result = $conn->exec($sql); /* Tipo de assentamento: 2 - Edição para atendimento */ $sql = "INSERT INTO assentamentos (ocorrencia, assentamento, created_at, responsavel, tipo_assentamento) values ({$numero}, '" . $data['entry'] . "', '{$now}', {$user}, 31 )"; try { $result = $conn->exec($sql); $notice_id = $conn->lastInsertId(); if ($_SESSION['s_uid'] != $row['aberto_por']) { setUserTicketNotice($conn, 'assentamentos', $notice_id); } } catch (Exception $e) { $exception .= '