top.window.location = '../../index.php'"; exit; } require_once __DIR__ . "/" . "../../includes/include_basics_only.php"; require_once __DIR__ . "/" . "../../includes/classes/ConnectPDO.php"; use includes\classes\ConnectPDO; $conn = ConnectPDO::getInstance(); $post = $_POST; $screenNotification = ""; $exception = ""; $data = []; $data['success'] = true; $data['message'] = ""; $data['cod'] = (isset($post['cod']) ? intval($post['cod']) : ""); $data['action'] = $post['action']; $data['field_id'] = ""; /* Status que não devem ser excluidos */ $data['system_status'] = [1,2,4,7,12]; /* Status que não podem ser marcados como ignored */ $data['cant_ignore'] = [1,2,4,7]; $data['status'] = (isset($post['status']) ? noHtml($post['status']) : ""); $data['categoria'] = (isset($post['categoria']) ? noHtml($post['categoria']) : ""); $data['painel'] = (isset($post['painel']) ? noHtml($post['painel']) : ""); $data['bgcolor'] = (isset($post['bgcolor']) && !empty($post['bgcolor']) ? noHtml($post['bgcolor']) : "#FFFFFF"); $data['textcolor'] = (isset($post['textcolor']) && !empty($post['textcolor']) ? noHtml($post['textcolor']) : "#212529"); $data['time_freeze'] = (isset($post['time_freeze']) ? ($post['time_freeze'] == "yes" ? 1 : 0) : 0); $data['time_freeze'] = ($data['painel'] == '3' || $data['cod'] == '4' ? 1 : $data['time_freeze']); $data['ignored'] = (isset($post['ignored']) ? ($post['ignored'] == "yes" ? 1 : 0) : 0); if ($data['ignored'] == 1) { $data['time_freeze'] = 1; } /* Validações */ if ($data['action'] == "new") { if (empty($data['status'])) { $data['success'] = false; $data['field_id'] = "status"; } elseif (empty($data['categoria'])) { $data['success'] = false; $data['field_id'] = "categoria"; } elseif (empty($data['painel'])) { $data['success'] = false; $data['field_id'] = "painel"; } } if ($data['action'] == "edit") { if (empty($data['status'])) { $data['success'] = false; $data['field_id'] = "status"; } } if ($data['success'] == false) { $data['message'] = message('warning', 'Ooops!', TRANS('MSG_EMPTY_DATA'),''); echo json_encode($data); return false; } if ($data['action'] == 'new') { $sql = "SELECT stat_id FROM `status` WHERE `status` = '" . $data['status'] . "' "; $res = $conn->query($sql); if ($res->rowCount()) { $data['success'] = false; $data['field_id'] = "status"; $data['message'] = message('warning', '', TRANS('MSG_RECORD_EXISTS'), ''); echo json_encode($data); return false; } if (!csrf_verify($post)) { $data['success'] = false; $data['message'] = message('warning', 'Ooops!', TRANS('FORM_ALREADY_SENT'),''); echo json_encode($data); return false; } $sql = "INSERT INTO status ( status, stat_cat, stat_painel, stat_time_freeze, stat_ignored, bgcolor, textcolor ) VALUES ( '" . $data['status'] . "', '" . $data['categoria'] . "', '" . $data['painel'] . "', '" . $data['time_freeze'] . "', '" . $data['ignored'] . "', '{$data['bgcolor']}', '{$data['textcolor']}' )"; try { $conn->exec($sql); $data['success'] = true; $data['message'] = TRANS('MSG_SUCCESS_INSERT'); $_SESSION['flash'] = message('success', '', $data['message'] . $exception, ''); echo json_encode($data); return false; } catch (Exception $e) { $exception .= "