PABX da Simples IP
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.
 
 
 
 
 
 

133 lines
6.7 KiB

<?php
include_once 'funcoesFormulario.php';
$param = '';
$erro = '';
// echo VerificaAgenteLogadoAstrisk('elvis') ? 'Deslogado' : 'Logado';
$janW = 500;
$janH = 285;
$tpl = 'discador/campanhaContatoStatus.tpl';
$acao = isset($_REQUEST["acao"]) ? trim($_REQUEST["acao"]) : 'select';
$paramPesquisa = isset($_REQUEST['paramPesquisa']) ? $_REQUEST['paramPesquisa'] : '';
$filtro = isset($_REQUEST["paramPesquisa"]) ? trim($_REQUEST["paramPesquisa"]) : '';
$filtroNovo = !isset($_REQUEST["pgn"]) ? '' : sprintf("&paramPesquisa%s&pgn=%s&bloco=%s&pg=%s", $_REQUEST["paramPesquisa"], $_REQUEST["pgn"], $_REQUEST["bloco"], $_REQUEST["pg"]);
$recontaPag = ($acao == 'novo') || ($acao == 'apagar') || ($acao == 'ativar') || isset($_POST['pesquisa']);
$org_id = GetOrganizacao();
$compl = '';
$imgNovo = "<img src=\"images/novo.gif\" width=\"16\" height=\"16\" border=\"0\" title=\"Inclui novo usuário\">";
$imgNovo = "<a href=\"javaScript:NovaJanela('index.php?idProg=22&idUser=0', 'usuarioCad', '$janW', '$janH', 'resizable=NO,scrollbars=NO');\">$imgNovo</a>";
if ($acao) {
if (($acao == 'apagar') || ($acao == 'ativar')) {
$id = $_GET["ctst_id"];
if ($id) {
$apaga = false;
if ($acao == 'apagar') {
$query = "SELECT case when(exists(select '' from pbx_campanha_contato where cont_status = '$id') or exists(select '' from pbx_campanha_contato_fone where conf_status = '$id'))then 1 else 0 end as existe";
$result = pg_query($dbcon, $query);
$dados = @pg_fetch_array($result);
$apaga = $dados['existe'] == 0;
}
$status = ($acao == 'ativar') ? 1 : 0;
$query = "UPDATE pbx_campanha_contato_status SET ctst_status = '$status' WHERE ctst_id = $id";
if ($apaga) {
$query = "DELETE FROM pbx_campanha_contato_status WHERE ctst_id = $id";
}
$result = pg_query($dbcon, $query);
}
if ($result) {
$msg = "Operação realizada com sucesso!";
} else {
$msg = "A operação não pode ser realizada!";
}
$jsStartup[] = sprintf("alert('%s');", $msg);
} else if ($acao == 'novo') {
$compl = " and org_id = $org_id ";
$status = QuotedStr(strtoupper(trim($_GET['status'])));
$query = "SELECT * FROM pbx_campanha_contato_status where upper(ctst_nome) = $status $compl ";
$result = pg_query($dbcon, $query);
if (pg_num_rows($result)) {
$msg = "Status já cadastrado!";
} else {
$query = "SELECT max(ctst_id) FROM pbx_campanha_contato_status";
$result = pg_query($dbcon, $query);
$dados = @pg_fetch_array($result);
$id = $dados[0] + 1;
$query = "INSERT INTO pbx_campanha_contato_status(ctst_id, ctst_nome, ctst_status, org_id) values($id, $status, 1, $org_id);";
$result = pg_query($dbcon, $query);
if ($result) {
$msg = "Operação realizada com sucesso!";
} else {
$msg = "A operação não pode ser realizada!";
}
}
$jsStartup[] = sprintf("alert('%s');", $msg);
} else if ($acao == 'update') {
$id = $_GET["ctst_id"];
$status = QuotedStr(trim($_GET['status']));
$query = "UPDATE pbx_campanha_contato_status SET ctst_nome = $status WHERE ctst_id = '$id'";
$result = pg_query($dbcon, $query);
if ($result) {
$msg = "Operação realizada com sucesso!";
} else {
$msg = "A operação não pode ser realizada!";
}
$jsStartup[] = sprintf("alert('%s');", $msg);
}
}
$compl = '';
if (isset($_REQUEST['paramPesquisa']) && $_REQUEST['paramPesquisa']) {
$compl = PreparaLike($filtro, true);
$compl = sprintf("and (a.ctst_nome ilike %s)", $compl);
}
$query = "SELECT ctst_id, ctst_nome, ctst_status FROM pbx_campanha_contato_status a WHERE ctst_status <> 2 $compl order by 1";
$params = "&paramPesquisa=$filtro";
$links = PaginaDados($idProg, $query, $params, $regPagina, $offSet, $pagMostra, true);
$query .= " limit $regPagina offset $offSet";
$result = pg_query($dbcon, $query);
$linha = "";
while ($dados = @pg_fetch_array($result)) {
$ctst_id = $dados["ctst_id"];
$ctst_nome = $dados["ctst_nome"];
$ctst_status = $dados["ctst_status"];
$imgEdit = "<img src=\"imgSite/editaUser.png\" width=\"16\" height=\"16\" border=\"0\" title=\"Edita o registro: $ctst_nome\" onclick=\"ContatoStatusAtualiza('$ctst_id', '$ctst_nome', '$params');\">";
$nomeMostra = "<a href=# style=\"color: #000;\" title=\"Edita o registro: $ctst_nome\" onclick=\"ContatoStatusAtualiza('$ctst_id', '$ctst_nome', '$params');\">$ctst_nome</a>";
$imgDelete = $ctst_status ? "<img src=\"imgSite/deletaUser.png\" width=\"16\" height=\"16\" border=\"0\" title=\"Apaga o Stastus: $ctst_nome\" onclick=\"DeletaCadastro('274', '&ctst_id=$ctst_id$params', '$ctst_nome');\">" :
"<img src=\"imgSite/volta16.gif\" width=\"16\" height=\"16\" border=\"0\" title=\"Ativa o Stastus: $ctst_nome\" onclick=\"AtivaCadastro('274', '&ctst_id=$ctst_id$params', '$ctst_nome');\">";
// $delete = "<a href=\"index.php?idProg=274&idDelete=$ctst_id\">" . $imgDelete . "</a>";
$imgStatus = sprintf("<img src=\"imgSite/%s\" width=\"12\" height=\"12\ border=\"0\">", ($ctst_status ? 'ok16.gif' : 'fecha16.png'));
$linha .= " <tr>
<td width=\"50\" align=\"center\">$ctst_id</td>
<td align=\"left\" nowrap>$nomeMostra</td>
<td align=\"center\" width=\"18\">$imgStatus</td>
<td align=\"center\" width=\"40\">$imgDelete $imgEdit</td>
</tr>";
}
$imgNovo = "<img src=\"images/novo.gif\" width=\"16\" height=\"16\" border=\"0\" title=\"Inclui novo usuário\" align=\"absmiddle\">";
$imgNovo = "<a href=\"#\" onclick=\"ContatoStatusNovo('$filtroNovo');\">$imgNovo Novo Status</a>";
//<img src="imgSite/novoUser.png" width="16" height="16" border="0" title="Inclui novo Status" onclick="ContatoStatusNovo();" align="absbottom">
$semResult = "<tr align=\"center\" valign=\"middle\" bordercolor=\"#999999\" class=\"labels\">
<td colspan=\"8\"><div align=\"center\" class=\"info\"><img src=\"images/shutdown.gif\" width=\"24\" height=\"24\" border=\"0\" align=\"absmiddle\" /> N&Atilde;o foram encontrados registros </div></td></tr>";
$smarty->assign('erro', $msg);
$smarty->assign("linhas", $linha ? $linha : $semResult);
$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);