|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require('funcoesFormulario.php');
|
|
|
|
|
$templateName = 'cadastros/prevenda/listaReferenciaStatus.htm';
|
|
|
|
|
//define tipo de formulario
|
|
|
|
|
$tpLayout = 1;
|
|
|
|
|
$upload = 1;
|
|
|
|
|
|
|
|
|
|
$fieldsForm = array();
|
|
|
|
|
$fieldsForm = IsPostBack() ? $_POST : $_GET;
|
|
|
|
|
|
|
|
|
|
if (isset($fieldsForm['ctst_id']) && (strpos($fieldsForm['ctst_id'], '|') !== false)) {
|
|
|
|
|
$search = strpbrk($fieldsForm['ctst_id'], '|');
|
|
|
|
|
$fieldsForm['ctst_id'] = str_replace($search, '', $fieldsForm['ctst_id']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Id da campanha
|
|
|
|
|
$idCampanha = $fieldsForm['cmp_id'];
|
|
|
|
|
$fieldsForm['erro'] = "";
|
|
|
|
|
|
|
|
|
|
if (isset($fieldsForm['btInclui'])) {
|
|
|
|
|
if (empty($fieldsForm['ctst_id'])) {
|
|
|
|
|
$fieldsForm['erro'] = fmtMsg('Selecione um Status!');
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
$result = @pg_query($dbcon, 'begin');
|
|
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
|
$cont = 0;
|
|
|
|
|
foreach ($fieldsForm['ctst_id'] as $idUser) {
|
|
|
|
|
$query = "insert into pbx_campanha_referencia_status(ctst_id) values(%s)";
|
|
|
|
|
$query = sprintf($query, $idUser);
|
|
|
|
|
$result = @pg_query($dbcon, $query);
|
|
|
|
|
if (!$result)
|
|
|
|
|
break;
|
|
|
|
|
$cont++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = $result && @pg_query($dbcon, 'commit');
|
|
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
|
throw new Exception('A opera<EFBFBD><EFBFBD>o n<EFBFBD>o pode ser realizada!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$fieldsForm['erro'] = $cont > 1 ? fmtMsg('Status incluidos com sucesso!') : fmtMsg('Status incluido com sucesso!');
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
@pg_query($dbcon, 'rollback');
|
|
|
|
|
fmtErro($e->getMessage(), pg_last_error($dbcon));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (isset($fieldsForm['btRemove'])) {
|
|
|
|
|
if (empty($fieldsForm['gruposinc'])) {
|
|
|
|
|
$fieldsForm['erro'] = fmtMsg('Selecione um Status!');
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
$result = @pg_query($dbcon, 'begin');
|
|
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
|
$userAdmin = IsAdmin() ? 1 : 0;
|
|
|
|
|
$cont = 0;
|
|
|
|
|
foreach ($fieldsForm['gruposinc'] as $id) {
|
|
|
|
|
$query = "delete from pbx_campanha_referencia_status where ctst_id = '%s'";
|
|
|
|
|
$query = sprintf($query, $id);
|
|
|
|
|
|
|
|
|
|
$result = @pg_query($dbcon, $query);
|
|
|
|
|
if (!$result)
|
|
|
|
|
break;
|
|
|
|
|
$cont++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = $result && @pg_query($dbcon, 'commit');
|
|
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
|
throw new Exception('A opera<EFBFBD><EFBFBD>o n<EFBFBD>o pode ser realizada!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$fieldsForm['erro'] = $cont > 1 ? fmtMsg('Status removidos com sucesso!') : fmtMsg('Status removido com sucesso!');
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
@pg_query($dbcon, 'rollback');
|
|
|
|
|
fmtErro($e->getMessage(), pg_last_error($dbcon));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$fieldsForm['listagrupos'] = GetUser($dbcon, $fieldsForm['ctst_id'], $fieldsForm['ctst_id'], 8, "ctst_id", "240", 0, 1);
|
|
|
|
|
$fieldsForm['gruposinc'] = GetGrupoUser($dbcon, $fieldsForm['ctst_id'], 0, 8, "gruposinc", "240", 0, 1);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Atualiza templates templates
|
|
|
|
|
*/
|
|
|
|
|
foreach ($fieldsForm as $key => $value) {
|
|
|
|
|
$smarty->assign($key, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GetTemplate($smarty, $templateName);
|
|
|
|
|
|
|
|
|
|
function GetGrupoUser($dbcon, $codGp, $codSel, $size = 1, $nomeLista = "ctst_id", $tamPx = "200", $desabilita = 0, $multiple = 0) {
|
|
|
|
|
if (strpos($codGp, '|') !== false) {
|
|
|
|
|
$codG = explode('|', $codGp);
|
|
|
|
|
$codGp = $codG[0];
|
|
|
|
|
}
|
|
|
|
|
$query = "SELECT a.ctst_id,ctst_nome FROM pbx_campanha_referencia_status a INNER JOIN pbx_campanha_contato_status b ON a.ctst_id = b.ctst_id";
|
|
|
|
|
|
|
|
|
|
$result = @pg_query($dbcon, $query);
|
|
|
|
|
$cont = 0;
|
|
|
|
|
$sel = "";
|
|
|
|
|
|
|
|
|
|
$lista = '<select name="%s%s" id="%s" size="%s" style="width:%spx;" %s>%s';
|
|
|
|
|
$lista = sprintf($lista, $nomeLista, ($multiple ? "[]" : ""), $nomeLista, $size, $tamPx, ($multiple ? 'multiple="multiple"' : ''), "\n");
|
|
|
|
|
|
|
|
|
|
while (($row = @pg_fetch_array($result))) {
|
|
|
|
|
$cod = $row["ctst_id"];
|
|
|
|
|
$sel = ($codSel == $cod) ? "selected" : "";
|
|
|
|
|
|
|
|
|
|
$desc = $row["ctst_nome"];
|
|
|
|
|
$lista .= "<option value=\"$cod\" $sel>$desc</option>\n";
|
|
|
|
|
$cont++;
|
|
|
|
|
}
|
|
|
|
|
$lista .= $cont ? "</select>" : "<option value=\"0\" selected></option>\n</select>\n";
|
|
|
|
|
return $lista;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetUser($dbcon, $codGrupo, $codSel, $size = 1, $nomeLista = "ctst_id", $tamPx = "200", $desabilita = 0, $multiple = 0) {
|
|
|
|
|
$sel = "";
|
|
|
|
|
if (strpos($codGrupo, '|') !== false) {
|
|
|
|
|
$codG = explode('|', $codGrupo);
|
|
|
|
|
$codGrupo = $codG[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$query = "SELECT * FROM pbx_campanha_contato_status WHERE ctst_id NOT IN(
|
|
|
|
|
SELECT ctst_id FROM (SELECT CASE WHEN(COUNT(ctst_id) > 1) THEN ctst_id END AS ctst_id
|
|
|
|
|
FROM pbx_grupo_campanha_contato_status
|
|
|
|
|
GROUP BY ctst_id ORDER BY 1) AS DATA
|
|
|
|
|
WHERE ctst_id IS NOT NULL) AND ctst_id NOT IN (SELECT ctst_id FROM pbx_campanha_referencia_status)";
|
|
|
|
|
$result = @pg_query($dbcon, $query);
|
|
|
|
|
|
|
|
|
|
$lista = '<select name="%s%s" id="%s" size="%s" style="width:%spx" %s >%s';
|
|
|
|
|
$lista = sprintf($lista, $nomeLista, ($multiple ? '[]' : ''), $nomeLista, $size, $tamPx, ($multiple ? 'multiple="multiple"' : ''), "\n");
|
|
|
|
|
|
|
|
|
|
while (($row = @pg_fetch_array($result))) {
|
|
|
|
|
$cod = $row["ctst_id"];
|
|
|
|
|
$desc = $row["ctst_nome"];
|
|
|
|
|
$sel = ($codSel == $cod) ? "selected" : "";
|
|
|
|
|
$lista .= "<option value=\"$cod\" $sel>$desc</option>\n";
|
|
|
|
|
}
|
|
|
|
|
$lista .= "</select>\n";
|
|
|
|
|
return $lista;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|