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.

161 lines
5.4 KiB

<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
$tpLayout = 1;
$matricula = GetMatricula();
$pesqAgenda = isset($_POST["pesqAgenda"]) ? $_POST["pesqAgenda"] : "";
$btAgenda = isset($_POST["btAgenda"]) ? $_POST["btAgenda"] : "";
$acao = !isset($_GET["acao"]) ? 0 : $_GET["acao"]; //1 = inserir 2= alterar 3= exluir
$idEdita = !isset($_GET["idCli"]) ? 0 : $_GET["idCli"];
$id = "";
$nome = "";
$telefone = "";
$celular = "";
$email = "";
$endereco = "";
$result = "";
$msg = "";
$org_id = GetOrganizacao();
if (isset($_GET["formAction"])) {
$idDel = $_GET["id"];
$query = "delete from pbx_agendas where id = '$idDel'";
pg_query($dbcon, $query);
}
if (strtoupper($btAgenda) == "PESQUISAR") {
$query = "SELECT id, nome, telefone, celular, email, endereco
FROM pbx_agendas
WHERE (nome LIKE '%$pesqAgenda%'
OR telefone LIKE '%$pesqAgenda%'
OR celular LIKE '%$pesqAgenda%'
OR email LIKE '%$pesqAgenda%'
OR endereco LIKE '%$pesqAgenda%')
AND org_id = $org_id ";
$result = pg_query($dbcon, $query);
$linha = "";
while ($row = pg_fetch_array($result)) {
$id = $row["id"];
$nome = "<a style=\"color: #000;\" href=\"javaScript:NovaJanela('index.php?idProg=18&acao=2&idCli=$id', 'AgendaEdita', '420', '350', 'resizable=NO,scrollbars=NO');\"> " . $row["nome"] . "</a>";
$telefone = $row["telefone"];
$celular = $row["celular"];
$email = $row["email"];
$endereco = $row["endereco"];
$imgDel = GetLinkFormDelete($id, "DeletaAgenda");
$linha .= "<tr align=\"left\">
<td nowrap>$nome</td>
<td>$telefone</td>
<td>$celular</td>
<td nowrap>$email</td>
<td>$endereco</td>
<td align=\"center\">$imgDel</td>
</tr>";
}
}
if (isset($_POST["btEditaAgenda"])) {
$idEdita = $_POST["idCli"];
$nome = $_POST["nomeCli"];
$telefone = soNumero($_POST["foneCli"]);
$celular = soNumero($_POST["celularCli"]);
$email = $_POST["emailCli"];
$endereco = $_POST["endCli"]; //substr($_POST["endCli"], 0, 80);
}
if (strtoupper($_POST["btEditaAgenda"]) == "INSERIR") {
$acao = 3;
if (empty($nome)) {
$msg = "alert('Informe o nome!');";
} else if (strlen($endereco) > 80) {
$msg = "alert('Informe no m<EFBFBD>ximo 80 caracteres no campo endere<EFBFBD>o!');";
} else {
$query = "INSERT INTO pbx_agendas(nome, telefone, celular, email, endereco, org_id)
VALUES('$nome', '$telefone', '$celular', '$email', '$endereco', $org_id)";
$result = pg_query($dbcon, $query);
if ($result) {
$result = pg_affected_rows($result);
}
$msg = $result ? "alert('Opera<EFBFBD><EFBFBD>o realizada com sucesso!'); window.close();" : "alert('A opera<EFBFBD><EFBFBD>o n<EFBFBD>o pode ser realizada!');";
}
if ($msg) {
$jsStartup[] = $msg;
}
} else if (strtoupper($_POST["btEditaAgenda"]) == "ALTERAR") {
$acao = 4;
if (empty($nome)) {
$msg = "Informe o nome!";
} else if (strlen($endereco) > 80) {
$msg = "Informe no m<EFBFBD>ximo 80 caracteres no campo endere<EFBFBD>o!";
} else {
$query = "UPDATE pbx_agendas
SET nome = '$nome',
telefone = '$telefone',
celular = '$celular',
email = '$email',
endereco = '$endereco'
WHERE id = $idEdita";
$result = pg_query($dbcon, $query);
if ($result)
$result = pg_affected_rows($result);
$msg = $result ? "Opera<EFBFBD><EFBFBD>o realizada com sucesso!" : "A opera<EFBFBD><EFBFBD>o n<EFBFBD>o pode ser realizada!";
}
if ($msg)
$jsStartup[] = "alert('$msg');";
}
if ($acao == 2) {
$query = "SELECT id, nome, telefone, celular, email, endereco
FROM pbx_agendas
WHERE id = $idEdita
AND org_id = $org_id ";
$result = pg_query($dbcon, $query);
$row = pg_fetch_array($result);
$id = $row["id"];
$nome = $row["nome"];
$telefone = $row["telefone"];
$celular = $row["celular"];
$email = $row["email"];
$endereco = $row["endereco"];
}
if (empty($linha))
$linha = "<tr align=\"center\"><td colspan=5>Nenhum registro encontrado!</td></tr>";
if ($acao == 0) {
$smarty->assign("pesqAgenda", $pesqAgenda);
$smarty->assign("linhas", $linha);
} else {
$acaoCli = ($acao == 1) || ($acao == 3) ? "Inserir" : "Alterar";
$acaoDesc = $acao == 1 || ($acao == 3) ? "Novo Registro" : "Altera<EFBFBD><EFBFBD>o de Registro";
$smarty->assign("idCli", $idEdita);
$smarty->assign("nomeCli", $nome);
$smarty->assign("foneCli", $telefone);
$smarty->assign("celularCli", $celular);
$smarty->assign("emailCli", $email);
$smarty->assign("endCli", $endereco);
$smarty->assign("acao", $acaoDesc);
$smarty->assign("acaoCli", $acaoCli);
}
DispLogin($smarty, $acao);
function DispLogin($smarty, $acao)
{
if ($acao == 0) {
$smarty->display('callcenter/agente/agenteAgenda.tpl');
} else {
$smarty->display('callcenter/agente/agenteAgendaEdita.tpl');
}
}