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; $exception = ""; $screenNotification = ""; $data = []; $data['success'] = true; $data['message'] = ""; $data['cod'] = (isset($post['cod']) ? intval($post['cod']) : ""); $data['action'] = $post['action']; $data['field_id'] = ""; $data['csrf_session_key'] = (isset($post['csrf_session_key']) ? $post['csrf_session_key'] : ""); $data['cat_name'] = (isset($post['cat_name']) ? noHtml($post['cat_name']) : ""); $data['cat_description'] = (isset($post['cat_description']) ? noHtml($post['cat_description']) : ""); $data['cat_default_profile'] = (isset($post['cat_default_profile']) ? noHtml($post['cat_default_profile']) : ""); $data['is_digital'] = (isset($post['is_digital']) ? ($post['is_digital'] == "yes" ? 1 : 0) : 0); $data['is_product'] = (isset($post['is_product']) ? ($post['is_product'] == "yes" ? 1 : 0) : 0); $data['bgcolor'] = (isset($post['bgcolor']) && !empty($post['bgcolor']) ? noHtml($post['bgcolor']) : '#3A4D56'); $data['textcolor'] = (isset($post['textcolor']) && !empty($post['textcolor']) ? noHtml($post['textcolor']) : '#FFFFFF'); /* Validações */ if ($data['action'] == "new" || $data['action'] == "edit") { if (empty($data['cat_name'])) { $data['success'] = false; $data['field_id'] = "cat_name"; } if ($data['success'] == false) { $data['message'] = message('warning', 'Ooops!', TRANS('MSG_EMPTY_DATA'),''); echo json_encode($data); return false; } } if ($data['action'] == 'new') { /* verifica se um registro com esse nome já existe */ $sql = "SELECT id FROM assets_categories WHERE cat_name = '" . $data['cat_name'] . "' "; $res = $conn->query($sql); if ($res->rowCount()) { $data['success'] = false; $data['field_id'] = "cat_name"; $data['message'] = message('warning', '', TRANS('MSG_RECORD_EXISTS'), ''); echo json_encode($data); return false; } 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; } $sql = "INSERT INTO assets_categories ( cat_name, cat_description, cat_default_profile, cat_is_digital, cat_is_product, cat_bgcolor, cat_textcolor ) VALUES ( '" . $data['cat_name'] . "', " . dbField($data['cat_description'], 'text') . ", " . dbField($data['cat_default_profile']) . ", {$data['is_digital']}, {$data['is_product']}, '{$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 .= "