|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require('funcoesFormulario.php');
|
|
|
|
|
$templateName = 'discador/campanhaUsuario.htm';
|
|
|
|
|
//define tipo de formulario
|
|
|
|
|
$tpLayout = 1;
|
|
|
|
|
$upload = 1;
|
|
|
|
|
|
|
|
|
|
$fieldsForm = array();
|
|
|
|
|
$fieldsForm = $_REQUEST;
|
|
|
|
|
|
|
|
|
|
//Id da campanha
|
|
|
|
|
$idCampanha = $fieldsForm['cmp_id'];
|
|
|
|
|
$fieldsForm['erro'] = "";
|
|
|
|
|
$idDac = GetDacFromCampanha($dbcon, $idCampanha);
|
|
|
|
|
|
|
|
|
|
if (isset($fieldsForm['btIncAgente'])) {
|
|
|
|
|
if (empty($fieldsForm['listaAgentes'])) {
|
|
|
|
|
$fieldsForm['erro'] = fmtMsg('Selecione um agente!');
|
|
|
|
|
} else {
|
|
|
|
|
$query = "insert into pbx_campanha_usuarios(cmp_id, matricula)values(%s, '%s')";
|
|
|
|
|
$query = sprintf($query, $idCampanha, $fieldsForm['listaAgentes']);
|
|
|
|
|
$result = @pg_query($dbcon, $query);
|
|
|
|
|
$fieldsForm['erro'] = $result ? fmtMsg('Agente incluido com sucesso!') : fmtErro('O agente n<EFBFBD>o pode ser incluido!', pg_last_error($dbcon));
|
|
|
|
|
}
|
|
|
|
|
} else if (isset($fieldsForm['btRmAgente'])) {
|
|
|
|
|
if (empty($fieldsForm['listaAgenteInc'])) {
|
|
|
|
|
$fieldsForm['erro'] = fmtMsg('Selecione um agente!');
|
|
|
|
|
} else {
|
|
|
|
|
$query = "delete from pbx_campanha_usuarios where cmp_id = %s and matricula = '%s'";
|
|
|
|
|
$query = sprintf($query, $idCampanha, $fieldsForm['listaAgenteInc']);
|
|
|
|
|
$result = @pg_query($dbcon, $query);
|
|
|
|
|
$fieldsForm['erro'] = $result ? fmtMsg('Agente removido com sucesso!') : fmtErro('O agente n<EFBFBD>o pode ser removido!', pg_last_error($dbcon));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$fieldsForm['listaAgentes'] = GetAgentesCampanha($dbcon, 'listaAgentes', $idCampanha, $fieldsForm['listaAgentes'], $idDac);
|
|
|
|
|
$fieldsForm['listaAgenteInc'] = GetAgentesCampanha($dbcon, 'listaAgenteInc', $idCampanha, $fieldsForm['listaAgenteInc']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Atualiza templates templates
|
|
|
|
|
*/
|
|
|
|
|
foreach ($fieldsForm as $key => $value) {
|
|
|
|
|
$smarty->assign($key, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GetTemplate($smarty, $templateName);
|
|
|
|
|
|
|
|
|
|
function GetAgentesCampanha($dbcon, $nomeCombo, $idCampanha = 0, $codSel = 0, $idDac = 0) {
|
|
|
|
|
|
|
|
|
|
$agentes = "<select name=\"$nomeCombo\" style=\"width:280px\" id=\"$nomeCombo\" size=\"8\">";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($nomeCombo != 'listaAgentes') {
|
|
|
|
|
$query = "select matricula, nome || '(' || apelido || ')' as nome from pbx_usuarios u
|
|
|
|
|
where delete_ = 0
|
|
|
|
|
and exists(select '' from pbx_campanha_usuarios where matricula = u.matricula and cmp_id = $idCampanha)";
|
|
|
|
|
} else {
|
|
|
|
|
$query = "select matricula, nome || '(' || apelido || ')' as nome from pbx_usuarios u
|
|
|
|
|
where delete_ = 0
|
|
|
|
|
and not exists(select '' from pbx_campanha_usuarios where matricula = u.matricula and cmp_id = $idCampanha)
|
|
|
|
|
and exists(select '' from pbx_fila_grupos a, pbx_grupo_usuario b where b.gp_id = a.gp_id and a.id = '$idDac' and b.user_id = u.id)
|
|
|
|
|
order by 2 ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = pg_query($dbcon, $query);
|
|
|
|
|
|
|
|
|
|
while ($dados = pg_fetch_row($result)) {
|
|
|
|
|
if ($codSel == $dados[0]) {
|
|
|
|
|
$sel = "selected";
|
|
|
|
|
$i = 1;
|
|
|
|
|
} else {
|
|
|
|
|
$sel = "";
|
|
|
|
|
}
|
|
|
|
|
$agentes .= "<option value=\"$dados[0]\" $sel>$dados[1]</option>";
|
|
|
|
|
}
|
|
|
|
|
$agentes .= "</select>";
|
|
|
|
|
return $agentes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|