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.
104 lines
4.9 KiB
104 lines
4.9 KiB
<?php |
|
|
|
$mes = ""; |
|
$acao = isset($_GET['acao']) ? trim($_GET['acao']) : 'select'; |
|
$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') || (GetFormAcao() == FORM_DELETE) || isset($_POST['pesquisa']); |
|
$tpl = "agendaRamais/depto/deptoRamais.htm"; |
|
|
|
if ($acao == "deletaDep") { |
|
try { |
|
/* |
|
* VERIFICA SE EXISTE O RAMAL NA TABELA |
|
*/ |
|
$departamento = $_GET['dpto']; |
|
$query = "SELECT dpto_nome FROM rma_departamentos WHERE dpto_id='$departamento' "; |
|
$result = pg_query($dbcon, $query); |
|
if (!pg_num_rows($result)) { |
|
GeraExcept('Departamento Inválido, não foi possível excluir o registro!'); |
|
} |
|
|
|
$busca = "SELECT a.dpto_nome FROM rma_departamentos a,rma_depto_ramais b WHERE a.dpto_id=b.dpto_id AND b.dpto_id='$departamento'"; |
|
$result = pg_query($dbcon, $busca); |
|
if (!pg_num_rows($result)) { |
|
GeraExcept('O "Departamento" possui ramais vinculados, remova antes essas referências!'); |
|
} |
|
|
|
/* |
|
* DELETA O RAMAL |
|
*/ |
|
$deleta = "DELETE FROM rma_departamentos WHERE dpto_id='$departamento'"; |
|
$result = pg_query($dbcon, $deleta); |
|
/* |
|
* VERIFICA SE O RAMAL FOI DELETADO |
|
*/ |
|
$query = "SELECT dpto_nome FROM rma_departamento WHERE dpto_id='$departamento'"; |
|
$result = pg_query(dbcon, $query); |
|
if (!$result || !pg_affected_rows($result)) { |
|
GeraExcept('Erro ao excluir o "Departamento"!'); |
|
} |
|
|
|
Alert('O "Departamento" foi excluido com sucesso!'); |
|
} catch (Exception $ex) { |
|
Alert($ex->getMessage()); |
|
} |
|
} |
|
|
|
|
|
$compl = ''; |
|
if (isset($_REQUEST['paramPesquisa']) && $_REQUEST['paramPesquisa']) { |
|
$compl = PreparaLike($filtro, true); |
|
$compl = sprintf("and (b.dpto_nome ilike %s)", $compl); |
|
} |
|
|
|
$query = " SELECT b.dpto_nome,b.dpto_id, (select count(*) from rma_depto_ramais c where c.dpto_id = b.dpto_id ) as n_dep |
|
FROM rma_departamentos b |
|
where 1=1 $compl |
|
GROUP BY b.dpto_nome,b.dpto_id ORDER BY dpto_nome ASC"; |
|
|
|
$resultados = ''; |
|
$params = "¶mPesquisa=$filtro"; |
|
$links = PaginaDados($idProg, $query, $params, $regPagina, $offSet, $pagMostra, true); |
|
$query .= " limit $regPagina offset $offSet"; |
|
$result = pg_query($dbcon, $query); |
|
while ($rowDepto = pg_fetch_array($result)) { |
|
$dptoNome = $rowDepto['dpto_nome']; |
|
$dptoId = $rowDepto['dpto_id']; |
|
$relacionamento = $rowDepto['n_dep']; |
|
$depMostra = "<a style=\"color: #000;\" href=\"javaScript:NovaJanela('index.php?idProg=144&dpto=$dptoId', 'EditaDepartamento', '500', '150', 'resizable=NO,scrollbars=1');\">$dptoNome</a>"; |
|
$resultados .= "<tr> |
|
<td width=\"50\" align=\"center\">$dptoId</td> |
|
<td>$depMostra</td> |
|
<td width=\"20\" align=\"right\">$relacionamento</td> |
|
<td width=\"20\" style=\"text-align: center; border-right:0;\"><a href=\"javaScript:NovaJanela('index.php?idProg=147&dpto=$dptoId', 'RelacionarRamais', '630', '300', 'resizable=NO,scrollbars=1');\"><img src=\"imgSite/usuarios.gif\" width=\"15\" height=\"15\" border=\"0\"></a></td> |
|
<td width=\"20\" style=\"text-align: center; border-right:0; border-left:0;\"><a href=\"javaScript:NovaJanela('index.php?idProg=144&dpto=$dptoId', 'EditaDepartamento', '500', '150', 'resizable=NO,scrollbars=1');\"><img src=\"imgSite/editaUser.png\" border=\"0\"></a></td> |
|
<td width=\"20\" style=\"text-align: center; border-left:0;\"><a href=\"javaScript:DeletaDep('$dptoId', '$params');\"><img src=\"imgSite/deletaUser.png\" border=\"0\"></a></td> |
|
</tr>"; |
|
} |
|
|
|
$imgNovo = "<a href=\"javaScript:NovaJanela('index.php?idProg=143$filtroNovo', 'Cadastro de Departamentos', '500', '150', 'resizable=NO,scrollbars=1');\"><img src=\"images/novo.gif\" border=\"0\" align=\"absmiddle\"> Novo Departamento</a>"; |
|
$smarty->assign('linhas', $resultados); |
|
$smarty->assign('erro', $mes); |
|
$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 RetornaMensagem($mes) { |
|
if ($mes == "") { |
|
$alert = ""; |
|
} else { |
|
$alert = "<script type=\"text/javascript\">alert('$mes');</script>"; |
|
return $alert; |
|
} |
|
} |
|
|
|
?>
|
|
|