|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require('funcoesFormulario.php');
|
|
|
|
|
$templateName = 'discador/campanhaAtivacao.htm';
|
|
|
|
|
//define tipo de formulario
|
|
|
|
|
$tpLayout = 1;
|
|
|
|
|
|
|
|
|
|
//Id da campanha
|
|
|
|
|
$idCampanha = $_REQUEST['cmp_id'];
|
|
|
|
|
$_REQUEST['erro'] = "";
|
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['btAtivar'])) {
|
|
|
|
|
try {
|
|
|
|
|
$inTran = 0;
|
|
|
|
|
$ativar = $_REQUEST['cmp_status'] == 1;
|
|
|
|
|
$concluir = $_REQUEST['cmp_status'] == 3;
|
|
|
|
|
|
|
|
|
|
$result = pg_query($dbcon, 'begin');
|
|
|
|
|
if (!$result)
|
|
|
|
|
throw new Exception('N<EFBFBD>o foi poss<EFBFBD>vel inciar a opera<EFBFBD><EFBFBD>o!');
|
|
|
|
|
$inTran = 1;
|
|
|
|
|
if ($ativar || $concluir) {
|
|
|
|
|
|
|
|
|
|
if($ativar){
|
|
|
|
|
$query = " select count(*) from pbx_campanha a where a.id_dac = (select id_dac from pbx_campanha where cmp_id = '$idCampanha')and a.cmp_status = '1'";
|
|
|
|
|
$result = pg_query($dbcon, $query);
|
|
|
|
|
$row = pg_fetch_row($result);
|
|
|
|
|
if($row[0]){
|
|
|
|
|
throw new Exception('J<EFBFBD> existe uma lista ativa para a "Fila(DAC)" ligada a esta campanha!');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$query = "select count(*) as lista from pbx_campanha_lista where cmp_id = '$idCampanha' and list_status = '1'";
|
|
|
|
|
$result = pg_query($dbcon, $query);
|
|
|
|
|
$row = pg_fetch_array($result);
|
|
|
|
|
$statuslista = $row['lista'];
|
|
|
|
|
|
|
|
|
|
if (!$statuslista)
|
|
|
|
|
throw new Exception('N<EFBFBD>o Existe uma lista ativa para essa Campanha!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($concluir) {
|
|
|
|
|
PendenciasDiscador($dbcon, $idCampanha);
|
|
|
|
|
DesativaLista($dbcon, $idCampanha);
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* Excluir cmp_status = 0, apenas muda o status das listas.
|
|
|
|
|
*/
|
|
|
|
|
$query = "update pbx_campanha set cmp_status = '%s' where cmp_id = '%s' ";
|
|
|
|
|
$query = sprintf($query, $_REQUEST['cmp_status'], $idCampanha);
|
|
|
|
|
$result = pg_query($dbcon, $query);
|
|
|
|
|
|
|
|
|
|
if (!$result)
|
|
|
|
|
throw new Exception('A opera<EFBFBD><EFBFBD>o n<EFBFBD>o pode ser realizada!');
|
|
|
|
|
|
|
|
|
|
$_REQUEST['erro'] = fmtMsg("Campanha foi alterada com sucesso!", 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$GLOBALS['jsStartup'][] = "window.close()";
|
|
|
|
|
$GLOBALS['jsStartup'][] = "window.opener.ResetForm();";
|
|
|
|
|
|
|
|
|
|
$result = pg_query($dbcon, 'commit');
|
|
|
|
|
if (!$result)
|
|
|
|
|
throw new Exception('N<EFBFBD>o foi encerrar a opera<EFBFBD><EFBFBD>o!');
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
if ($inTran)
|
|
|
|
|
pg_query($dbcon, 'rollback');
|
|
|
|
|
$_REQUEST['erro'] = fmtErro($e->getMessage() . (IsAdmin() ? ('Erro: ' . pg_last_error($dbcon) ) : ''));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$query = "select * from pbx_campanha where cmp_id = %s ";
|
|
|
|
|
$query = sprintf($query, $idCampanha);
|
|
|
|
|
$result = pg_query($dbcon, $query);
|
|
|
|
|
$dados = pg_fetch_array($result);
|
|
|
|
|
|
|
|
|
|
foreach ($dados as $key => $value) {
|
|
|
|
|
$_REQUEST[$key] = $dados[$key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$codSel = $_REQUEST['cmp_status'];
|
|
|
|
|
$_REQUEST['cmp_old_status'] = $codSel;
|
|
|
|
|
/*
|
|
|
|
|
* Campanha com status 0-Cancelada ou 5-Concluida n<EFBFBD>o pode ser reativada.
|
|
|
|
|
*/
|
|
|
|
|
$desabStatus = ($codSel == 0);
|
|
|
|
|
$_REQUEST['cmp_status'] = GetStatusCampanha($dbcon, $codSel, $desabStatus, "'$codSel'");
|
|
|
|
|
|
|
|
|
|
$jsJQuery[] = "\$('#cmp_status').change(function(){document.getElementById(\"btAtivar\").disabled = (this.value == -1);}) ";
|
|
|
|
|
$GLOBALS['jsStartup'][] = "document.getElementById(\"btAtivar\").disabled = true;";
|
|
|
|
|
/*
|
|
|
|
|
* Atualiza templates templates
|
|
|
|
|
*/
|
|
|
|
|
foreach ($_REQUEST as $key => $value) {
|
|
|
|
|
$smarty->assign($key, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GetTemplate($smarty, $templateName);
|
|
|
|
|
?>
|