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ção nã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 = '" : "\n\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 = '\n"; return $lista; } ?>