"; $imgNovo = "$imgNovo"; 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 = "¶mPesquisa=$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 = ""; $nomeMostra = "$ctst_nome"; $imgDelete = $ctst_status ? "" : ""; // $delete = "" . $imgDelete . ""; $imgStatus = sprintf("", ($ctst_status ? 'ok16.gif' : 'fecha16.png')); $linha .= " $ctst_id $nomeMostra $imgStatus $imgDelete $imgEdit "; } $imgNovo = ""; $imgNovo = "$imgNovo Novo Status"; // $semResult = "
NÃo foram encontrados registros
"; $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);