forked from bruno/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.
137 lines
5.3 KiB
137 lines
5.3 KiB
<?php |
|
|
|
/* |
|
* To change this template, choose Tools | Templates |
|
* and open the template in the editor. |
|
*/ |
|
$tpLayout = 1; |
|
$matricula = GetMatricula(); |
|
$consultar = isset($_POST["btPesquisa"]); |
|
$valida = isset($_POST["btAnota"]) && (trim($_POST["AnotaTexto"]) != ""); |
|
$agtAnota = isset($_POST["AnotaTexto"]) ? $_POST["AnotaTexto"] : ""; |
|
$agtFone = isset($_POST["AnotaFone"]) ? soNumero($_POST["AnotaFone"]) : (isset($_SESSION[RAMAL_DESTINO]) ? soNumero($_SESSION[RAMAL_DESTINO]) : ''); |
|
$btAnota = isset($_POST["btAnota"]) ? $_POST["btAnota"] : ""; |
|
$listaAgente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : GetMatricula(); |
|
$dataIni = !isset($_POST["dataIni"]) ? date('d/m/Y') : $_POST["dataIni"]; |
|
$dataFim = !isset($_POST["dataFim"]) ? date('d/m/Y') : $_POST["dataFim"]; |
|
$org_id = GetOrganizacao(); |
|
$msg = ""; |
|
$pesquisa = ""; |
|
|
|
if (isset($_GET["formAction"])) { |
|
$idDel = $_GET["id"]; |
|
$query = "DELETE FROM pbx_anotacoes WHERE id_text = '$idDel'"; |
|
pg_query($dbcon, $query); |
|
} |
|
|
|
if (!is_date($dataIni)) { |
|
$jsStartup[] = "alert('Data inicial inválida!');"; |
|
$msg = "Data inicial inválida!"; |
|
$isValid = 0; |
|
} else if (!is_date($dataFim)) { |
|
$jsStartup[] = "alert('Data final inválida!');"; |
|
$msg = "Data final inválida!"; |
|
$isValid = 0; |
|
} else if (!$consultar && $valida && empty($agtFone)) { |
|
$msg = GetAnotacoesKey() ? "Informe o número do telefone!" : "Informe o número do protocolo!"; |
|
} else if ($valida && empty($agtAnota)) { |
|
$msg = "Insira uma anotação!"; |
|
} else if (!$consultar && $valida) { |
|
$query = "INSERT INTO pbx_anotacoes(conteudo, matricula_agente, fone_cliente, org_id) VALUES('$agtAnota', '$matricula', '$agtFone', $org_id)"; |
|
$result = pg_query($dbcon, $query); |
|
if ($result) { |
|
$agtAnota = ""; |
|
$msg = "Operação realizada com sucesso!"; |
|
} |
|
} |
|
|
|
$pesquisa = PesquisaFone($dbcon, $agtFone); |
|
if (empty($pesquisa)) { |
|
$pesquisa = "<tr><td colspan=4>Nenhum registro encontrado!</td></tr>"; |
|
} |
|
|
|
$cor = !$msg || stripos($msg, 'sucesso') ? '#0000FF' : '#FF0000'; |
|
$smarty->assign("AnotaFone", $agtFone); |
|
$smarty->assign("AnotaTexto", $agtAnota); |
|
$smarty->assign("corErro", $cor); |
|
$smarty->assign("msg", $msg); |
|
$smarty->assign("linhas", $pesquisa); |
|
$smarty->assign("isFone", GetAnotacoesKey()); |
|
$smarty->assign("isSuper", IsSuper()); |
|
$smarty->assign("dataIni", $dataIni); |
|
$smarty->assign("dataFim", $dataFim); |
|
$smarty->assign("prm_label_protoco_pesquisa", $_SESSION['prm_label_protoco_pesquisa']); |
|
$smarty->assign("prm_label_protoco_texto", $_SESSION['prm_label_protoco_texto']); |
|
$smarty->assign("prm_label_protoco_grid", $_SESSION['prm_label_protoco_grid']); |
|
if (IsSuper()) { |
|
$agentes = GetAgentesAnotacoes($dbcon, $listaAgente); |
|
$smarty->assign("listaAgente", $agentes); |
|
} |
|
DispLogin($smarty); |
|
|
|
function PesquisaFone($db, $num) |
|
{ |
|
global $listaAgente, $dataIni, $dataFim; |
|
$org_id = GetOrganizacao(); |
|
|
|
$mat = IsSuper() ? $listaAgente : GetMatricula(); |
|
$query = "SELECT a.id_text, a.conteudo, a.matricula_agente, a.fone_cliente, a.data, b.apelido |
|
FROM pbx_anotacoes a, pbx_usuarios b |
|
WHERE b.matricula = a.matricula_agente::text "; |
|
$query .= $mat ? " AND a.matricula_agente::text = '$mat' " : ""; |
|
$query .= sprintf(" AND data::date >= %s AND data::date <= %s ", FormatDtMssql($dataIni, true), FormatDtMssql($dataFim, true)); |
|
|
|
if ($num) { |
|
$query .= " AND fone_cliente LIKE '%" . $num . "%'"; |
|
} |
|
$query .= " AND org_id = $org_id "; |
|
$query .= " ORDER BY b.apelido, a.data desc"; |
|
|
|
$result = pg_query($db, $query); |
|
//if(IsAdmin()) echo $query; |
|
$linha = ""; |
|
while (($result) && ($row = pg_fetch_array($result))) { |
|
$fone = GetAnotacoesKey() ? FormataFone($row["fone_cliente"]) : $row["fone_cliente"]; |
|
$content = $row["conteudo"]; |
|
$matAgt = $row["matricula_agente"] . '-' . $row["apelido"]; |
|
$data = date('d/m/Y', strtotime($row["data"])); |
|
$imgDel = GetLinkFormDelete($row["id_text"], 'DeletaAnotacao'); |
|
$linha .= "<tr><td align=left>$data</td>"; |
|
if (IsSuper()) { |
|
$linha .= "<td align=left>$matAgt</td>"; |
|
} |
|
$linha .= "<td align=left>$fone</td> |
|
<td align=left>$content</td> |
|
<td align=center>$imgDel</td> |
|
</tr>"; |
|
} |
|
$colspan = IsSuper() ? 4 : 3; |
|
if (empty($linha)) { |
|
$linha = "<tr><td colspan=\"$colspan\">Nenhum registro encontrado!</td></tr>"; |
|
} |
|
return $linha; |
|
} |
|
|
|
function DispLogin($smarty) |
|
{ |
|
$smarty->display('callcenter/agente/agenteAnota.tpl'); |
|
} |
|
|
|
function GetAgentesAnotacoes($dbcon, $matricula) |
|
{ |
|
$query = "SELECT id, apelido, nome, matricula |
|
FROM pbx_usuarios |
|
WHERE delete_ = 0 |
|
AND apelido |
|
NOT IN('sinccontasenha')"; //'admin', |
|
$result = pg_query($dbcon, $query); |
|
$sel = $matricula == "0" ? ' Selected="selected" ' : ''; |
|
$item = "<option value=\"0\"$sel>Todos</option>\n"; |
|
while ($dados = pg_fetch_array($result, null, PGSQL_ASSOC)) { |
|
$mat = $dados['matricula']; |
|
$apelido = $dados['apelido']; |
|
$sel = $mat == $matricula ? ' Selected="selected" ' : ''; |
|
$item .= "<option value=\"$mat\"$sel>$apelido-[$mat]</option>\n"; |
|
} |
|
return $item; |
|
}
|
|
|