|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
//define o label do botao
|
|
|
|
|
$acaoUser = 'Gravar';
|
|
|
|
|
|
|
|
|
|
// Define mensagem para o usuario
|
|
|
|
|
$msgUser = "";
|
|
|
|
|
|
|
|
|
|
// Define mensagens de erro
|
|
|
|
|
$msgErro = "";
|
|
|
|
|
|
|
|
|
|
$setFocus = "document.getElementById('motivo').focus();";
|
|
|
|
|
$jsStartup[] = $setFocus;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Verifica se o usuario pressionou o bot<EFBFBD>o para inserir
|
|
|
|
|
* o registro
|
|
|
|
|
*/
|
|
|
|
|
if ($formAction == FORM_UPDATE) {
|
|
|
|
|
GetGpValues($dbcon);
|
|
|
|
|
} else {
|
|
|
|
|
GetGpValues(null);
|
|
|
|
|
if (trim($_POST["motivo"] == "")) {
|
|
|
|
|
//GetGpValues(null);
|
|
|
|
|
$msgUser = "alert('\"Motivo\" <EFBFBD> campo de preenchimento obrigat<EFBFBD>rio!');";
|
|
|
|
|
} else if (RegistroInc($dbcon, sprintf("select count(*) from pbx_motivos_pausas where upper(motivo) = %s and id <> '%s'", QuotedStr(strtoupper($_POST["motivo"])), $id))) {
|
|
|
|
|
$msgUser = sprintf("alert('O \"Motivo: %s\" j<EFBFBD> existe na base de dados!');", $_POST["motivo"]);
|
|
|
|
|
} else {
|
|
|
|
|
//string para inser<EFBFBD><EFBFBD>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<EFBFBD><EFBFBD>o n<EFBFBD>o pode ser realizada!Erro: $erroBd');";
|
|
|
|
|
$msgErro = "A opera<EFBFBD><EFBFBD>o n<EFBFBD>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"];
|
|
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|