forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
253 lines
11 KiB
253 lines
11 KiB
<?php |
|
|
|
require_once('funcoesFormulario.php'); |
|
/* |
|
* Nome e tamanho da janela popup |
|
*/ |
|
$janW = 600; |
|
$janH = 340; |
|
$nomeJanela = "IntegAtiva"; |
|
|
|
$formAction = isset($_POST["formAction"]) ? $_POST["formAction"] : (isset($_GET["formAction"]) ? $_GET["formAction"] : 0); |
|
if (($formAction > 0) && ($formAction < 6)) { |
|
$jsPage[] = "admin/js/pbxAjax.js"; |
|
$tpLayout = 1; |
|
$tpl = "cadastros/integAtiva/integAtivaCad.tpl"; |
|
|
|
/* |
|
* Campos usados no formulário |
|
*/ |
|
$fields = array('itgc_id' => 0, "itgt_id" => 1, 'itgp_id' => 0, 'itgc_nome' => '', 'itgc_host' => '', 'itgc_port' => 0, |
|
'itgc_database' => '', 'itgc_user' => '', 'itgc_password' => '', 'itgc_timeout' => 10, 'opcao' => '', 'acao' => '', |
|
'itgp_descricao' => '', 'opcao_descricao' => '', 'acao_descricao' => '', "formAction" => 0); |
|
|
|
|
|
$fieldsInsert = array('itgt_id', 'itgp_id', 'itgc_nome', 'itgc_host', 'itgc_port', 'itgc_database', 'itgc_user', 'itgc_password', 'itgc_timeout', 'opcao', 'acao'); |
|
$fieldsUpdate = array('itgp_id', 'itgc_nome', 'itgc_host', 'itgc_port', 'itgc_database', 'itgc_user', 'itgc_password', 'itgc_timeout', 'opcao', 'acao'); |
|
$fieldsWhere = array('itgc_id'); |
|
$fieldsDisplay = array('itgc_id', 'itgt_id', 'itgp_descricao', 'itgc_nome', 'itgc_host', 'itgc_port', 'itgc_database', 'itgc_user', 'itgc_password', 'itgc_timeout', 'opcao_descricao', 'acao_descricao'); |
|
$fieldsRequest = array('itgt_id' => 'Tipo de Integração', 'itgp_id' => 'Protocolo', 'itgc_nome' => 'Nome Conexão', 'itgc_host' => 'Host', 'itgc_port' => 'Porta', 'itgc_database' => 'Base de Dados', 'itgc_user' => 'Usuário', 'itgc_password' => 'Senha', 'itgc_timeout' => 'Timeout'); |
|
|
|
GetDadosPost($fields, $_POST); |
|
/* |
|
$fields['itgp_descricao'] = GetIntegracaoProto($dbcon, $fields['itgp_id']); |
|
$fields['opcao_descricao'] = GetOpcaoAlt($dbcon, $fields['opcao']); |
|
$fields['acao_descricao'] = GetAcaoAlt($dbcon, $fields['opcao'], $fields['acao']); |
|
*/ |
|
if ($formAction == FORM_NEW) { |
|
$fields['formAction'] = FORM_INSERT; |
|
} else if ($formAction == FORM_INSERT) { |
|
$msg = ''; |
|
$msgEmpty = ''; |
|
if (IsRequestField($fieldsRequest, $fields, $msgEmpty)) { |
|
$msg = $msgEmpty; |
|
} else if (!is_numeric($fields['itgc_port'])) { |
|
$msg = "Informe apenas números para a \"Porta\"!"; |
|
} else if (!is_numeric($fields['itgc_timeout'])) { |
|
$msg = "Informe apenas números para o \"Timeout\"!"; |
|
} else if (ExisteRegistro($dbcon, 'pbx_integracao_configuracao', ' itgc_nome', $fields['itgc_nome'])) { |
|
$itgc_nome = $fields['itgc_nome']; |
|
$msg = "Já existe uma configuração com o mesmo nome: \"$itgc_nome\"!"; |
|
} else { |
|
$query = "insert into pbx_integracao_configuracao(%s)values(%s);"; |
|
$campos = ''; |
|
$valores = ''; |
|
foreach ($fieldsInsert as $field) { |
|
$campos .= !$campos ? $field : ", $field"; |
|
$valores .= !$valores ? QuotedStr($fields[$field]) : ", " . QuotedStr($fields[$field]); |
|
} |
|
$query = sprintf($query, $campos, $valores); |
|
|
|
$result = pg_query($dbcon, $query); |
|
|
|
if (!$result) { |
|
$erros = error_get_last(); |
|
$msg = 'A operação não pode ser realizada!'; |
|
//$msg = 'A operação não pode ser realizada! Erro: ' . $erros['message']; |
|
} |
|
} |
|
|
|
if ($msg) { |
|
$jsJQuery[] = "alert('$msg');"; |
|
} else { |
|
$msg = 'Registro inserido com sucesso!'; |
|
$jsJQuery[] = "alert('$msg');"; |
|
$jsStartup[] = "window.opener.ResetForm();"; |
|
$jsJQuery[] = "window.close();"; |
|
} |
|
} else if ($formAction == FORM_UPDATE) { |
|
$fields['formAction'] = FORM_SAVE; |
|
$jsJQuery[] = "document.getElementById('itgc_nome').readOnly = true;"; |
|
// $fieldsUpdate = array('itgp_id','itgc_nome','itgc_host','itgc_port','itgc_database','itgc_user','itgc_password','itgc_timeout','opcao','acao'); |
|
$query = "select "; |
|
$campos = ''; |
|
foreach ($fieldsUpdate as $fieldUpd) { |
|
$campos .= !$campos ? $fieldUpd : ", $fieldUpd"; |
|
} |
|
$id = $_GET["itgc_id"]; |
|
$query = "select $campos from pbx_integracao_configuracao where itgc_id = '$id'"; |
|
|
|
$result = pg_query($dbcon, $query); |
|
$dados = pg_fetch_array($result); |
|
GetDadosPost($fields, $dados); |
|
|
|
$fields["itgc_id"] = $id; |
|
} else if ($formAction == FORM_SAVE) { |
|
$fields['formAction'] = FORM_SAVE; |
|
$jsJQuery[] = "document.getElementById('itgc_nome').readOnly = true;"; |
|
$msg = ''; |
|
$msgEmpty = ''; |
|
if (IsRequestField($fieldsRequest, $fields, $msgEmpty)) { |
|
$msg = $msgEmpty; |
|
} else if (!is_numeric($fields['itgc_port'])) { |
|
$msg = "Informe apenas números para a \"Porta\"!"; |
|
} else if (!is_numeric($fields['itgc_timeout'])) { |
|
$msg = "Informe apenas números para o \"Timeout\"!"; |
|
} else { |
|
$query = "update pbx_integracao_configuracao set %s where itgc_id = '%s'"; |
|
$campos = ''; |
|
$valor = ''; |
|
foreach ($fieldsUpdate as $field) { |
|
$valor = QuotedStr($fields[$field]); |
|
$campos .= !$campos ? sprintf("%s = %s", $field, $valor) : sprintf(", %s = %s", $field, $valor); |
|
} |
|
$query = sprintf($query, $campos, $fields["itgc_id"]); |
|
|
|
$result = pg_query($dbcon, $query); |
|
|
|
if (!$result) { |
|
$erros = error_get_last(); |
|
$msg = 'A operação não pode ser realizada! Erro: ' . $erros['message']; |
|
} |
|
} |
|
|
|
if ($msg) { |
|
$jsJQuery[] = "alert('$msg');"; |
|
} else { |
|
$msg = 'Registro alterado com sucesso!'; |
|
$jsJQuery[] = "alert('$msg');"; |
|
$jsJQuery[] = "window.close();"; |
|
} |
|
} |
|
|
|
$fields['itgp_descricao'] = GetIntegracaoProto($dbcon, $fields['itgp_id']); |
|
$fields['opcao_descricao'] = GetOpcaoAlt($dbcon, $fields['opcao']); |
|
$fields['acao_descricao'] = GetAcaoAlt($dbcon, $fields['opcao'], $fields['acao']); |
|
|
|
|
|
|
|
foreach ($fields as $key => $value) { |
|
$smarty->assign($key, $value); |
|
} |
|
|
|
GetTemplate($smarty, $tpl); |
|
} else { |
|
$paramPesquisa = isset($_REQUEST['paramPesquisa']) ? $_REQUEST['paramPesquisa'] : ''; |
|
$filtro = isset($_REQUEST["paramPesquisa"]) ? trim($_REQUEST["paramPesquisa"]) : ''; |
|
$filtroNovo = !isset($_REQUEST["pgn"]) ? '' : sprintf("¶mPesquisa%s&pgn=%s&bloco=%s&pg=%s", $_REQUEST["paramPesquisa"], $_REQUEST["pgn"], $_REQUEST["bloco"], $_REQUEST["pg"]); |
|
$recontaPag = ($acao == 'inseri') || ($formAction == FORM_DELETE) || isset($_POST['pesquisa']); |
|
$imgNovo = GetLinkFormInsert($nomeJanela, "images/novo.gif", $filtroNovo, ' Nova Integração'); |
|
|
|
if ($formAction == FORM_DELETE) { |
|
$idDel = $_GET["id"]; |
|
|
|
$result = pg_query($dbcon, 'begin'); |
|
|
|
$query = "delete from pbx_integracao_metodo where itgc_id = '$idDel'"; |
|
$result = $result && pg_query($dbcon, $query); |
|
|
|
$query = "delete from pbx_integracao_configuracao where itgc_id = '$idDel'"; |
|
$result = $result && pg_query($dbcon, $query); |
|
|
|
if ($result) { |
|
$result = pg_query($dbcon, 'commit'); |
|
$jsJQuery[] = $result ? "alert('Registro apagado com sucesso!');" : "alert('Erro ao tentar remover registro!');"; |
|
} else { |
|
pg_query($dbcon, 'rollback'); |
|
$erros = error_get_last(); |
|
$msg = 'A operação não pode ser realizada!'; // Erro: ' . $erros['message']; |
|
$jsJQuery[] = "alert('$msg');"; |
|
} |
|
} |
|
|
|
$linha = " <tr > |
|
<td width=\"50\" align=\"center\">%s</td> |
|
<td align=\"left\">%s</td> |
|
<td align=\"left\">%s</td> |
|
<td width=\"80\" align=\"left\">%s</td> |
|
<td width=\"20\" align=\"center\">%s</td> |
|
<td width=\"20\" align=\"center\">%s</td> |
|
<td width=\"20\" align=\"center\">%s</td> |
|
</tr>"; |
|
|
|
$compl = ''; |
|
if (isset($_REQUEST['paramPesquisa']) && $_REQUEST['paramPesquisa']) { |
|
$compl = PreparaLike($filtro, true); |
|
$compl = sprintf("and (a.itgc_nome ilike %s or a.itgc_host ilike %s)", $compl, $compl); |
|
} |
|
|
|
$query = "select itgc_id, itgc_nome, itgc_host, itgc_port from pbx_integracao_configuracao a where 1=1 $compl order by 1"; |
|
|
|
$linhas = ""; |
|
$params = "¶mPesquisa=$filtro"; |
|
$links = PaginaDados($idProg, $query, $params, $regPagina, $offSet, $pagMostra, true); |
|
$query .= " limit $regPagina offset $offSet"; |
|
$result = pg_query($dbcon, $query); |
|
while ($dados = pg_fetch_array($result)) { |
|
$id = $dados['itgc_id']; |
|
$edit = GetLinkFormUpdate("&itgc_id=$id", $nomeJanela); |
|
$nomeMostra = GetLinkFormUpdate("&itgc_id=$id", $nomeJanela, '', 0, 1, $dados['itgc_nome']); |
|
$delete = GetLinkFormDelete($id . '|' . $params, 'DeletaIntegAtiva'); |
|
$metodos = GetLinkForm("&itgc_id=$id", 191, 'IntegAtivaMetodo', "Métodos", $wJan = $janW, $hJan = $janH, "imgSite/cliente16.gif"); |
|
$status = ''; |
|
$linhas .= sprintf($linha, $dados['itgc_id'], $nomeMostra, $dados['itgc_host'], $dados['itgc_port'], $edit, $delete, $metodos); |
|
$imp++; |
|
} |
|
|
|
$tpl = "cadastros/integAtiva/integAtiva.tpl"; |
|
$smarty->assign("linhas", $linhas); |
|
$smarty->assign("paramPesquisa", $paramPesquisa); |
|
$smarty->assign("imgNovo", $imgNovo); |
|
$smarty->assign("links", $links); |
|
$smarty->assign("pagMostra", $pagMostra); |
|
$smarty->assign("totalReg", $totalReg); |
|
$smarty->assign("pgn", $_REQUEST["pgn"]); |
|
$smarty->assign("bloco", $_REQUEST["bloco"]); |
|
$smarty->assign("pg", $_REQUEST["pg"]); |
|
GetTemplate($smarty, $tpl); |
|
} |
|
|
|
function GetIntegracaoProto($db, $id) { |
|
$query = "select itgp_id, itgp_descricao from pbx_integracao_protocolo where itgp_status = 0"; |
|
$query = sprintf($query, $param); |
|
$result = pg_query($db, $query); |
|
|
|
$sel = ''; |
|
|
|
if (!$id) |
|
$sel = 'selected="selected"'; |
|
$ret = "<option value=\"0\" $sel>-----------------</option>"; |
|
$sel = ''; |
|
|
|
while ($dados = pg_fetch_array($result)) { |
|
$idProto = $dados['itgp_id']; |
|
$desc = $dados['itgp_descricao']; |
|
$sel = $id == $idProto ? ' selected="selected"' : ''; |
|
$ret .= "<option value=\"$idProto\"$sel>$desc</option>\n"; |
|
} |
|
return $ret; |
|
} |
|
|
|
function IsRequestField($request, $source, &$msg) { |
|
foreach ($request as $key => $value) { |
|
$field = trim($source[$key]); |
|
if ($field == '') { |
|
$msg = sprintf('O campo: "%s" é rquerido!', $value); |
|
return true; |
|
} |
|
} |
|
$msg = ''; |
|
return false; |
|
} |
|
|
|
?>
|
|
|