'%s'", QuotedStr(strtoupper($_POST["motivo"])), $id))) { $msgUser = sprintf("alert('O \"Motivo: %s\" já existe na base de dados!');", $_POST["motivo"]); } else { //string para inserção do registro $query = "update pbx_motivos_pausas set motivo = %s, flag = %s, produtiva = %s, tempo_alerta = %s where id = %d"; //GetGpValues(null); //Prepara a query para inserir o registro no banco $query = sprintf($query, QuotedStr($motivo), QuotedStr($flag), QuotedStr($produtiva),QuotedStr($tempo_alerta), $id); $tempo_alerta = $tempo_alerta / 60; //Executa a query no banco $result = pg_query($dbcon, $query); if ($result) { //GetGpValues(null); $msgUser = "alert('Registro alterado com sucesso');"; $jsStartup[] = "window.opener.ResetForm();"; $jsStartup[] = "window.close();"; } else { $erroBd = @pg_last_error($dbcon); $msgUser = "alert('A operação não pode ser realizada!Erro: $erroBd');"; $msgErro = "A operação não pode ser realizada!Erro: $erroBd"; } } } if (!empty($msgUser)) $jsStartup[] = $msgUser; $smarty->assign("id", $id); $smarty->assign("motivo", $motivo); $smarty->assign("flag", $flag); $smarty->assign("produtiva", $produtiva); $smarty->assign("tempoAlerta", $tempo_alerta); $smarty->assign("acaoUser", $acaoUser); $smarty->assign("formAction", FORM_SAVE); $smarty->assign("erro", $msgErro); GetTemplate($smarty, 'cadastros/motivosPausa/motivosPausaCadastro.tpl'); function GetGpValues($db) { if (!empty($db)) { $id = $_GET["id"] ?? "0"; $query = "select id, motivo, flag, produtiva,tempo_alerta from pbx_motivos_pausas where id = $id"; $result = pg_query($db, $query); if ($result) $row = pg_fetch_array($result, $row); } $GLOBALS["id"] = empty($db) ? $_POST["id"] : $row["id"]; $GLOBALS["flag"] = empty($db) ? ($_POST["flag"] ? 1 : 0) : $row["flag"]; $GLOBALS["motivo"] = mb_strtoupper(RemoveAcentos(empty($db) ? $_POST["motivo"] : $row["motivo"])); $GLOBALS["produtiva"] = empty($db) ? $_POST["produtiva"] : $row["produtiva"]; $GLOBALS["tempo_alerta"] = empty($db) ? $_POST["tempo_alerta"] * 60 : $row["tempo_alerta"] / 60; } ?>