//INCLUDE DAS FUNÇÕES PADRÕES DO SISTEMA
$acao = $_GET["acao"];
$acao2 = $_GET["acao2"];
if ($acao2 == "salva") {
$id = $_POST["id"];
$nome = trim($_POST["nome"]);
$telefone = trim($_POST["telefone"]);
$tipo = trim($_POST["tipo"]);
$posicao = trim($_POST["posicao"]);
$ramal = trim($_POST["ramal"]);
if ($acao == 'inseri') {
//VALIDACAO PARA EXISTENCIA DE POSICÕES CADASTRADAS NO SISTEMA
if ($tipo == 'P') {
//SE TIPO = PUBLICA
$query = "SELECT * FROM pbx_agenda where posicao='$posicao' and tipo='$tipo'";
} else {
//SE TIPO = RAMAL
$query = "SELECT * FROM pbx_agenda where posicao='$posicao' and tipo='$tipo' and ramal='$ramal'";
}
} else {
//SE TIPO = ATUALIZAÇÃO
$query = "SELECT * FROM pbx_agenda where posicao='$posicao' and id <> $id and tipo='$tipo'";
}
$result = pg_query($dbcon, $query);
while ($dados = pg_fetch_array($result)) {
$existe = trim($dados['telefone']);
}
if ($existe != '') {
?>
} else {
if ($acao == "inseri") {
$query = "INSERT INTO pbx_agenda(nome,telefone,tipo,posicao,ramal)
VALUES ('$nome','$telefone','$tipo','$posicao','$ramal')";
//ACAO DE INSERT NO BANCO
pg_query($dbcon, $query);
if ($tipo == 'R') {
//CADASTRA AGENDA DO RAMAL NO ASTERISK//executa inserção na base interna do asterisk
CommandAsterisk2($dbcon, 'AGENDA_RAMAL', $ramal . '/' . $posicao, $telefone);
} else {
//CADASTRA AGENDA PUBLICA NO ASTERISK//executa inserção na base interna do asterisk
CommandAsterisk2($dbcon, 'AGENDA_RAMAL', $posicao, $telefone);
}
}
if ($acao == "edita") {
//REALIZA BACKUP BO BANCO
//backup($dbcon,'pbx_agenda','U',$id,'update','AGENDA');
$query = "UPDATE pbx_agenda
SET nome='$nome', telefone='$telefone',tipo='$tipo',posicao='$posicao',ramal='$ramal'
WHERE id=$id";
pg_query($dbcon, $query);
$tipo2 = $_POST['tipo2'];
$ramal2 = $_POST['ramal2'];
$posicao2 = $_POST['posicao2'];
if ($tipo2 == 'R') {
//SE TIPO DE AGENDA = RAMAL , APAGA O REGISTRO DO BANCO ASTERISK//executa inserção na base interna do asterisk
CommandAsterisk2($dbcon, 'DEL AGENDA', $ramal2 . '/' . $posicao2, '');
} else {
//SE TIPO DE AGENDA = PUBLICA , APAGA O REGISTRO DO BANCO ASTERISK//executa inserção na base interna do asterisk
CommandAsterisk2($dbcon, 'DEL AGENDA', $posicao2, '');
}
if ($tipo == 'R') {
//SE TIPO DE AGENDA = RAMAL , REGISTRA DO BANCO ASTERISK//executa inserção na base interna do asterisk
CommandAsterisk2($dbcon, 'AGENDA_RAMAL', $ramal . '/' . $posicao, $telefone);
} else {
//SE TIPO DE AGENDA = PUBLICA , REGISTRA DO BANCO ASTERISK//executa inserção na base interna do asterisk
CommandAsterisk2($dbcon, 'AGENDA_RAMAL', $posicao, $telefone);
}
}
?>
}
}
if ($acao == "edita") {
$id = $_GET["id"];
$query = "SELECT * FROM pbx_agenda where id=$id";
$result = pg_query($dbcon, $query);
} else {
$query = "SELECT * FROM pbx_agenda where id is null";
}
$result = pg_query($dbcon, $query);
//SELECIONA REGISTROS PARA APRESENTACAO NA TELA DE CADASTRO
while ($dados = pg_fetch_array($result)) {
$id = $dados["id"];
$nome = $dados["nome"];
$telefone = $dados["telefone"];
$tipo = $dados["tipo"];
$ramal = $dados["ramal"];
$posicao = $dados["posicao"];
}
?>
if ($tipo == 'P') { ?>
}?>