1 ? fmtMsg('Revendas incluidas com sucesso!') : fmtMsg('Revenda incluida com sucesso!'); } catch (Exception $e) { pg_query($dbcon, 'rollback'); fmtErro($e->getMessage(), pg_last_error($dbcon)); } } } else if (isset($fieldsForm['btRemove'])) { if (empty($fieldsForm['listaRevendasIncluidos'])) { $fieldsForm['erro'] = fmtMsg('Selecione um ramal!'); } else { try { $result = pg_query($dbcon, 'begin'); if ($result) { $userAdmin = IsAdmin() ? 1 : 0; $cont = 0; foreach ($fieldsForm['listaRevendasIncluidos'] as $empId) { $query = "delete from pbx_grupo_revendas where emp_id = '%s' and gp_id = '%s'"; $query = sprintf($query, $empId, $fieldsForm['gp_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('Revendas removidas com sucesso!') : fmtMsg('Revenda removida com sucesso!'); } catch (Exception $e) { pg_query($dbcon, 'rollback'); fmtErro($e->getMessage(), pg_last_error($dbcon)); } } } $fieldsForm['listaRevendasDisponiveis'] = GetRevendasDisponiveis($dbcon, $fieldsForm['gp_id'], 0, 8, "300", 0, 1); $fieldsForm['listaRevendasIncluidos'] = GetRevendasIncluidos($dbcon, $fieldsForm['gp_id'], 0, 8, "300", 0, 1); /* * Atualiza templates templates */ foreach ($fieldsForm as $key => $value) { $smarty->assign($key, $value); } GetTemplate($smarty, $templateName); function GetRevendasDisponiveis($dbcon, $codGp, $codSel, $size = 1, $tamPx = "200", $desabilita = 0, $multiple = 0) { if (strpos($codGp, '|') !== false) { $codG = explode('|', $codGp); $codGp = $codG[0]; } $nomeLista = 'listaRevendasDisponiveis'; $query = "select emp_id, emp_nome_fantasia from vds_empresas a where not exists(select '' from pbx_grupo_revendas where emp_id = a.emp_id and gp_id = '$codGp') order by 2"; $result = pg_query($dbcon, $query); $cont = 0; $sel = ""; $lista = '\n"; return $lista; } function GetRevendasIncluidos($dbcon, $codGp, $codSel, $size = 1, $tamPx = "200", $desabilita = 0, $multiple = 0) { if (strpos($codGp, '|') !== false) { $codG = explode('|', $codGp); $codGp = $codG[0]; } $nomeLista = 'listaRevendasIncluidos'; $query = " select emp_id, emp_nome_fantasia from vds_empresas a where exists(select '' from pbx_grupo_revendas where emp_id = a.emp_id and gp_id = '$codGp') order by 2"; $result = pg_query($dbcon, $query); $cont = 0; $sel = ""; $lista = '\n"; return $lista; } ?>