Browse Source

Ajustes para licença do sistema

1.8-dev
douglas.strappasson 1 year ago
parent
commit
7ff9bb4338
  1. 21
      configGeral.php
  2. 4
      contacteFunc.php
  3. 47
      include/util/funcoesApl.php
  4. 250
      include/util/funcoesLicenca.php
  5. 8
      login.php
  6. 238
      seguranca/licencaUsuarioFixo.php
  7. 6
      templates/confSistema.tpl
  8. 87
      templates/configLicenca.tpl

21
configGeral.php

@ -526,25 +526,24 @@ if ($idSubProg == CONFIG_BASE_DADOS) {
DispRel($smarty, $tpl);
} else if ($idSubProg == CONFIG_LICENCA) {
include "util/funcoesLicenca.php";
$fields = filter_input_array(INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS);
$query = sprintf("SELECT perm_licenca FROM pbx_usuarios WHERE matricula = '%s';", GetMatricula());
$result = pg_query($query);
$infoUser = pg_fetch_assoc($result);
$mensagem = null;
if ($fields['document'] && $fields['lcnca_perfil'] && $fields['btGerar']) {
$contacts = [];
foreach ($fields as $k => $p) {
if (strpos($k, 'lcnca_contato') !== false) {
$contacts[] = $p;
}
if ($fields['btGerar']){
if ($fields['document'] && $fields['perfil']) {
$fields['document'] = preg_replace('/[^0-9]/', '', $fields['document']);
GerarArquivo($fields);
} else {
$jsStartup[] = "alert('Preencha as Informações da Licença!')";
}
$licenca = __dadosLicenca($fields['document'], $contacts);
GerarArquivo($licenca, $fields['lcnca_perfil']);
}
if (isset($fields['btValidar'])) {
try {
$json = validarArquivo($_FILES);

4
contacteFunc.php

@ -763,8 +763,8 @@ function VerificaMaxAgenteLogado($db) {
$matriculaAgente = GetMatricula();
$result = pg_query($db, "SELECT coalesce(pa_fixo,0) as pa_fixo FROM pbx_usuarios WHERE matricula = '$matriculaAgente'");
$dadosAgente = pg_fetch_assoc($result);
$licencaFixa = $dadosLicenca['pa_fixo'] > 0;
$licencaFixa = $dadosAgente['pa_fixo'] > 0;
/*
* Numero de PAs setado como zero permite ilimitada conexões.

47
include/util/funcoesApl.php

@ -408,7 +408,8 @@ function VerificaCadastroMenu($conn) {
$query = "select count(*) from pbx_funcoes";
$result = pg_query($conn, $query);
$row = pg_fetch_row($result);
if ($row[0] != count($menuUsuario)) {
if ($row[0] != count($menuUsuario) || IsAdmin()) {
$result = pg_query($conn, 'begin');
//transacao iniciada com sucesso
if ($result) {
@ -421,13 +422,36 @@ function VerificaCadastroMenu($conn) {
}
//registro apgados com sucesso
if ($result) {
//verifica o grupo de permissoes de acordo com o tipo da licença
$query = "SELECT a.fun_id
FROM pbx_grupo_funcoes a
INNER JOIN pbx_grupo b ON a.gp_id = b.gp_id
WHERE a.gp_id IN ( '28'
--SELECT clto_perfil_aplicacao_id
--FROM pbx_controle_licenciamento
)
GROUP BY a.fun_id
ORDER BY a.fun_id";
$result = pg_query($conn, $query);
while ($row = pg_fetch_assoc($result)) {
$permissions[] = $row['fun_id'];
}
foreach ($menuUsuario as $key => $value) {
if (!in_array($value[0], $permissions) && ($value[0] != '112')) {
unset($menuUsuario[$key]);
}
}
//recria o menu no banco de dados
for ($i = 0; $i < count($menuUsuario); $i++) {
foreach ($menuUsuario as $key => $value) {
$query = "insert into pbx_funcoes(fun_id, fun_nome, fun_menu, fun_menu_text, fun_menu_url, fun_menu_img, fun_id_pai, fun_status, fun_public, ord, id_prog)
values( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s )";
//pega valores do menu
$vMenu = $menuUsuario[$i];
$vMenu = $menuUsuario[$key];
//Verifica se é um link para nova janela
//$novaJan = (stripos($vMenu[4], 'NovaJanela') !== false);
$query = sprintf($query, QuotedStr($vMenu[0]), empty($vMenu[1]) ? 'null' : QuotedStr($vMenu[1]), empty($vMenu[2]) ? '0' : QuotedStr($vMenu[2]), empty($vMenu[3]) ? 'null' : QuotedStr(($vMenu[3])), //utf8_encode
@ -561,9 +585,18 @@ function IsAdmin() {
return strtoupper(GetLogin()) == 'ADMIN';
}
function AgenteON() {
$query = sprintf("select '' from pbx_supervisor_agentes where matricula = '%s' and ramal = '%s' ", GetMatricula(), GetRamalMonitorar(RAMAL_MONITOR_AGENTE));
return pg_num_rows(pg_query($query));
function AgenteON($idUser = null) {
if ($idUser != null) {
$query = sprintf("SELECT '' FROM pbx_supervisor_agentes a
INNER JOIN pbx_usuarios b ON a.matricula = b.matricula
WHERE b.id = '%s'", $idUser);
return pg_num_rows(pg_query($query));
} else {
$query = sprintf("select '' from pbx_supervisor_agentes where matricula = '%s' and ramal = '%s' ", GetMatricula(), GetRamalMonitorar(RAMAL_MONITOR_AGENTE));
return pg_num_rows(pg_query($query));
}
//return GetStatusAgente() && pg_num_rows(pg_query($query));
//return isset($_SESSION[SS_AGENTE_CONECTADO]) && $_SESSION[SS_AGENTE_CONECTADO];
}
@ -3773,7 +3806,7 @@ function PaginacaoTotalReg($sql, $idProg, $force) {
return ($_SESSION[$idxPagina] = $force ? $row : $row[0]);
}
function PaginaDados($idProg, $sql, &$params, &$regPagina, &$offSet, &$pagMostra, $force=false) {
function PaginaDados($idProg, $sql, &$params, &$regPagina, &$offSet, &$pagMostra, $force = false) {
global $totalReg;
/*
* Quantas paginas são mostrados no rodape.

250
include/util/funcoesLicenca.php

@ -3,65 +3,46 @@
include "util/Crypt.php";
define("CONF_KEY_LICENCA", md5("S1MPL3S_IP"));
define("CONF_FILE_PATH", "/var/www/html/aplicativo/cadastros/licenca/");
define("CONF_FILE_PATH", "/var/www/html/pabx-app/cadastros/licenca/");
define("CONF_FILE_UUID", 'uuid.lca');
/**
* COLETA AS INFORMAÇÕES DO VENDA MAIS E GERA O TOTAL DE LICENCA EM UM ARQUIVO CRIPTOGRAFADO
* @param type $licenca
* @param type $perfil
/*
* RECEBE OS DADOS DO FORMULÁRIO E GERA O TOTAL DE LICENCA EM UM ARQUIVO CRIPTOGRAFADO
* @param type $fields
*/
function GerarArquivo($licenca, $perfil) {
$company = [
"perfil_aplicacao_id" => $perfil,
];
function GerarArquivo($fields) {
/** ARRAY PARA GUARDAR INFORMACOES DOS CONTRATOS * */
$info = [
'licenca_pa' => 0,
'licenca_ramal' => 0,
'licenca_supervisor' => 0,
'licenca_discador_preview' => 0,
'licenca_discador_powerdial' => 0,
'licenca_discador_predictive' => 0,
'licenca_pesquisa' => 0,
'licenca_tarifador' => 0,
'licenca_whatsapp' => 0,
'licenca_workflow' => 0,
'licenca_mesaoperadora' => 0,
'licenca_mult_channel' => 0,
'licenca_helpdesk' => 0,
'licenca_crm' => 0,
'licenca_manager_one' => 0,
'licenca_help_custom' => 0,
'data_registro' => date('Y-m-d'),
'user_registro' => 0,
'server_registro' => 0,
'confirma_registro' => date('Y-m-d')
'document',
'razao_social',
'perfil',
'pa',
'pa_fixo',
'ramais',
'supervisor',
'pesquisa',
'tarifador',
'mesaoperadora',
'manager_one'
];
$clto_data = ["contrato_assinatura", "contrato_inicio", "contrato_fim"];
$data = [];
//LIMPA O ARRAY, SETA O PREFIXO NAS CHAVES E INSERE VALOR ZERO PARA OS VAZIOS
$unfix = 'lca_';
$prefix = "clto_";
foreach ($licenca as $clto) {
foreach ($clto as $k => $v) {
$data[$prefix . $k] = $v;
if (array_key_exists($k, $company)) {
$data[$prefix . $k] = $company[$k];
}
if (array_key_exists($k, $info) && is_int($v)) {
$data[$prefix . $k] += $v;
}
foreach ($fields as $key => $value) {
$key = str_replace($unfix, '', $key);
if (in_array($k, $clto_data)) {
$data[$prefix . $k] = date('Y-d-m', strtotime($v));
}
if (in_array($key, $info)) {
$data[$prefix . $key] = empty($value) ? '0' : $value;
}
}
$fileName = $data['clto_razao_social'] . $data['clto_cnpj'];
$data['clto_server_registro'] = 0;
$data['clto_contrato_numero'] = 0;
$data['clto_date_record'] = date('Y-m-d');
$fileName = $data['clto_razao_social'] . $data['clto_document'];
$file = criarArquivo($fileName, $data);
DownloadArquivo($file);
}
@ -73,7 +54,7 @@ function GerarArquivo($licenca, $perfil) {
* @return string
*/
function GerarUUID($tmp = false) {
$file = CONF_FILE_PATH . ($tmp ? '/tmp/' . md5(date('Y-m-d') . CONF_KEY_LICENCA) . "_" : '') . CONF_FILE_UUID;
$file = CONF_FILE_PATH . ($tmp ? 'tmp/' . md5(date('Y-m-d') . CONF_KEY_LICENCA) . "_" : '') . CONF_FILE_UUID;
if (!file_exists($file) && $tmp) {
foreach (glob('*_' . CONF_FILE_UUID) as $f) {
@ -248,74 +229,84 @@ function __getLicencaVMais($document) {
}
/**
* INSERE AS INFORMACOES PASSADAS NO ARQUIVO DE LICENCA PARA O BANCO DO SIMPLESIP E VENDA MAIS
* INSERE AS INFORMACOES PASSADAS NO ARQUIVO DE LICENCA PARA O BANCO DO SIMPLESIP
* @param type $dbcon
* @param type $data
* @return boolean
* @throws Exception
*/
function __validLicenca($dbcon, $data) {
if (!$data['clto_cnpj']) {
if (!$data['clto_document']) {
throw new Exception("As informações do arquivo está corrompido!");
}
$respbx = __getLicencaPBX($dbcon);
$resVmais = __getLicencaVMais($data['clto_cnpj']);
$table = 'pbx_controle_licenciamento';
$where = 'clto_cnpj';
$filter = $data['clto_document'];
$columns = array(
'clto_cnpj',
'clto_razao_social',
'clto_perfil_aplicacao_id',
'clto_licenca_pa',
'clto_licenca_pa_fixo',
'clto_licenca_ramal',
//'clto_licenca_supervisor',
//'clto_licenca_pesquisa',
//'clto_licenca_tarifador',
//'clto_licenca_mesaoperadora',
//'clto_licenca_manager_one',
'clto_server_registro',
'clto_contrato_numero',
'clto_data_registro',
'clto_data_log'
);
$vendamais = $resVmais['clto_cnpj'] == $data['clto_cnpj'] ? 'vendamais' : '';
try {
if (!pg_query($dbcon, 'BEGIN')) {
throw new Exception("Não foi possivel iniciar a transação!");
}
if ($respbx['clto_cnpj'] == $data['clto_cnpj'] || $vendamais) {
__updateLicenca($dbcon, $data, $vendamais);
return true;
}
recordParams($dbcon, $data);
if ($respbx['clto_cnpj'] == $data['clto_document']) {
__updateLicenca($dbcon, $data, $columns, $table, $where, $filter);
} else {
__sendLicenca($dbcon, $data, $columns, $table, $where, $filter);
}
if (__sendLicenca($dbcon, $data)) {
if (!pg_query($dbcon, 'COMMIT')) {
throw new Exception("Não foi possivel realizar o commit da transação!");
}
return true;
} catch (Exception $ex) {
pg_query($dbcon, 'ROLLBACK');
$GLOBALS['jsStartup'][] = sprintf("alert('%s');", $ex->getMessage());
throw new Exception($ex->getMessage());
}
return false;
}
function __updateLicenca($dbcon, $data, $t = null) {
$msql = ConectaMssql();
$info = "";
foreach ($data as $k => $v) {
$info .= "$k = '$v',";
function __updateLicenca($dbcon, $data, $columns, $table, $where, $filter) {
$values = array_combine($columns, $data);
foreach ($values as $key => $value) {
$values[$key] = " {$key} = '{$value}'";
}
$set = substr($info, 0, -1);
$table = ["pbx" => 'pbx_controle_licenciamento', "vendamais" => 'sip_controle_licenciamento'];
foreach ($table as $k => $v) {
$query = sprintf("UPDATE $v SET %s WHERE clto_cnpj = '%s';", $set, $data['clto_cnpj']);
if ($k == 'pbx' && (empty($t) || $t == $k)) {
$result = pg_query($dbcon, $query);
if (!$result) {
throw new Exception("Não foi possível atualizar as informações da licença!");
}
}
if ($k == 'vendamais' && (empty($t) || $t == $k)) {
__execSQLServer($query, false);
}
$query = sprintf("UPDATE %s SET %s WHERE %s = '%s'", $table, implode(',', $values), $where, $filter);
$result = pg_query($dbcon, $query);
if (!$result) {
throw new Exception("Não foi possível atualizar as informações da licença!");
}
return true;
}
function __sendLicenca($dbcon, $data) {
$column = array_keys($data);
function __sendLicenca($dbcon, $data, $columns, $table, $where, $filter) {
$values = array_values($data);
$table = ["pbx" => 'pbx_controle_licenciamento', "vendamais" => 'sip_controle_licenciamento'];
$query = sprintf("INSERT INTO %s (%s) VALUES('%s');", $table, implode(',', $columns), implode("','", $values));
foreach ($table as $k => $v) {
$query = sprintf("INSERT INTO {$v} (%s) VALUES('%s');", implode(',', $column), implode("','", $values));
if ($k == 'pbx') {
if (!pg_query($dbcon, $query)) {
throw new Exception("Não foi possível inserir as informações da licença no [Simples IP]!");
}
} else {
__execSQLServer($query, false);
}
if (!pg_query($dbcon, $query)) {
throw new Exception("Não foi possível inserir as informações da licença no [Simples IP]!");
}
return true;
}
function GetPerfilApl() {
@ -324,6 +315,79 @@ function GetPerfilApl() {
return $resp;
}
/*
* REALIZA A INSERÇÃO DAS INFORMAÇÕES DA LICENÇA NA TABELA DE PARAMETROS DO SISTEMA
*/
function recordParams($dbcon, $data) {
$columns = array(
'prm_max_licenca',
'prm_max_licenca_fixo',
'prm_max_ramal'
);
$values = array(
$data['clto_pa'],
$data['clto_pa_fixo'],
$data['clto_ramais']
);
$table = 'pbx_parametros';
$where = 'id';
$filter = '1';
managePaFixo($dbcon, $data);
if (!VerificaRamaisCriados($data['clto_ramais'])) {
throw new Exception("O número de ramais criados é superior ao parametro informado na licença!");
}
__updateLicenca($dbcon, $values, $columns, $table, $where, $filter);
$_SESSION['prm_max_licenca_fixo'] = $data['clto_pa_fixo'];
}
/*
* RESPONSÁVEL POR GERENCIAR AS LICENÇAS PA FIXO
*/
function managePaFixo($dbcon, $data) {
$query = "SELECT COUNT(*) AS qtd_pa_fixo FROM pbx_licenca_pa_fixo WHERE id_user IS NOT NULL";
$result = pg_query($dbcon, $query);
$result = pg_fetch_assoc($result);
if ($data['clto_pa_fixo'] < $result['qtd_pa_fixo']) {
throw new Exception("O número de P.A. fixos criados é superior ao parametro informado na licença!");
} else {
$query = "DELETE FROM pbx_licenca_pa_fixo WHERE id_user IS NULL";
if (!pg_query($dbcon, $query)) {
throw new Exception('A operação não pode ser realizada!');
}
$rows = $data['clto_pa_fixo'] - $result['qtd_pa_fixo'];
for ($cont = 0; $cont < $rows; $cont++) {
$query = sprintf("INSERT INTO pbx_licenca_pa_fixo (licenca) VALUES ('%s')", generateRandomKey());
if (!pg_query($dbcon, $query)) {
throw new Exception('A operação não pode ser realizada!');
}
}
}
}
/*
* GERADOR DE CHAVES ALEATÓRIAS UTILIZADOS PARA LICENÇA PA FIXO
*/
function generateRandomKey() {
return bin2hex(random_bytes(10));
}
########################################
#### CONEXÃO VENDA+ ####
########################################
function __dadosLicenca($document, $contracts = []) {
$ctact = implode("','", $contracts);
$data = date('Y-m-d');
@ -417,10 +481,6 @@ function __dadosLicenca($document, $contracts = []) {
return $resp;
}
########################################
#### CONEXÃO VENDA+ ####
########################################
/**
* Realiza conexao com o banco do venda+
* @return type

8
login.php

@ -35,10 +35,10 @@ if (!isset($_POST["loginUser"])) {
$jsStartup[] = $setFocus;
DispLogin($smarty);
return;
// } else if (!validarLicenca($dbcon) && ($_POST["loginUser"] != 'admin')) {
// $jsStartup[] = "alert('Sua licença é inválida por favor entre em contato com o suporte da Simples IP para ativar sua central!');";
// DispLogin($smarty);
// return;
} else if (!validarLicenca($dbcon) && ($_POST["loginUser"] != 'admin')) {
$jsStartup[] = "alert('Sua licença é inválida por favor entre em contato com o suporte da Simples IP para ativar sua central!');";
DispLogin($smarty);
return;
}
$query = "select id, nome, apelido, matricula,

238
seguranca/licencaUsuarioFixo.php

@ -1,115 +1,179 @@
<?php
require('funcoesFormulario.php');
$templateName = 'seguranca/licencaUsuarioFixo.tpl';
//define tipo de formulario
$tpLayout = 1;
$fieldsForm = IsPostBack() ? $_POST : $_GET;
/**
* INFORMAÇÕES DO HTML DO SELECT
*/
$infos = [
'size' => 8,
'name' => 'licencafixo',
'width' => '200',
'disable' => '0',
'multiple' => '1'
];
if (isset($fieldsForm['btInclui'])) {
AtualizaLicenca($dbcon, $fieldsForm['licencafixoinc'], 1);
} else if (isset($fieldsForm['btRemove'])) {
AtualizaLicenca($dbcon, $fieldsForm['licencafixorm'], 0);
}
$fieldsForm['listagrupos'] = GetUser($dbcon, 1, $infos);
$fieldsForm['gruposinc'] = GetGrupoUser($dbcon, 1, $infos);
require('funcoesFormulario.php');
$templateName = 'seguranca/licencaUsuarioFixo.tpl';
//define tipo de formulario
$tpLayout = 1;
$fieldsForm = IsPostBack() ? $_POST : $_GET;
/**
* INFORMAÇÕES DO HTML DO SELECT
*/
$infos = [
'size' => 8,
'name' => 'licencafixo',
'width' => '200',
'disable' => '0',
'multiple' => '1'
];
if (isset($fieldsForm['btInclui'])) {
AtualizaLicenca($dbcon, $fieldsForm['licencafixoinc'], 1);
} else if (isset($fieldsForm['btRemove'])) {
AtualizaLicenca($dbcon, $fieldsForm['licencafixorm'], 0);
}
$fieldsForm['listagrupos'] = GetUser($dbcon, 1, $infos);
$fieldsForm['gruposinc'] = GetGrupoUser($dbcon, 1, $infos);
/*
* Atualiza templates templates
*/
foreach ($fieldsForm as $key => $value) {
$smarty->assign($key, $value);
}
GetTemplate($smarty, $templateName);
function AtualizaLicenca($dbcon, $field, $status) {
try {
if (!$field) {
//fmtMsg('Selecione um usuário!');
throw new Exception('Selecione um usuário');
}
/*
* Atualiza templates templates
*/
foreach ($fieldsForm as $key => $value) {
$smarty->assign($key, $value);
}
@pg_query($dbcon, 'begin');
GetTemplate($smarty, $templateName);
foreach ($field as $idUser) {
if (AgenteON($idUser)) {
throw new Exception('Não é possível editar um agente conectado!');
}
function AtualizaLicenca($dbcon, $field, $status) {
$cont = 0;
try {
if($status == 1){
$query = "select count(*) as num_licenca from pbx_usuarios where pa_fixo = 1;";
$result = pg_query($dbcon, $query);
$re = pg_fetch_assoc($result)['num_licenca'];
$query = sprintf("SELECT id_user, last_update, limit_update, NOW() as current_time FROM pbx_licenca_pa_fixo WHERE id_user = '%s' ", $idUser);
$result = pg_query($dbcon, $query);
if ($result && pg_num_rows($result) > 0) {
$result = pg_fetch_assoc($result);
if($re >= $_SESSION['prm_max_licenca_fixo']){
fmtMsg('A licença de PA Fixo foi excedida!');
throw new Exception('A licença de PA Fixo foi excedida!');
$limitUpdate = strtotime($result['limit_update']);
$freeUpadate = strtotime($result['last_update'] . '+24 hours');
$currentTime = strtotime($result['current_time']);
if ($currentTime > $limitUpdate && $currentTime < $freeUpadate) {
throw new Exception('O tempo limite para edição se esgotou, tente novamente mais tarde!');
}
}
if(!$field){
fmtMsg('Selecione um usuário!');
throw new Exception('Selecione um usuário');
}
pg_query($dbcon, 'begin');
foreach ($field as $id) {
$query = "update pbx_usuarios set pa_fixo = {$status} where id = {$id};";
if ($status == 1) {
$query = "SELECT COUNT(*) AS qtd_pa_fixo FROM pbx_licenca_pa_fixo WHERE id_user IS NOT NULL;";
$result = pg_query($dbcon, $query);
$cont++;
$result = pg_fetch_assoc($result);
if ($result['qtd_pa_fixo'] >= $_SESSION['prm_max_licenca_fixo']) {
//fmtMsg('A licença de PA Fixo foi excedida!');
throw new Exception('A licença de PA Fixo foi excedida!');
}
}
$result = $result && pg_query($dbcon, 'commit');
$query = sprintf("UPDATE pbx_licenca_pa_fixo SET id_user = %s, last_update = NOW(), limit_update = NOW() + INTERVAL '5 MINUTE' ", $status == 1 ? "'" . $idUser . "'" : 'NULL');
$status == 1 ? $query .= "WHERE id = (SELECT id FROM pbx_licenca_pa_fixo WHERE id_user IS NULL ORDER BY id LIMIT 1)" :
$query .= sprintf("WHERE id_user = '%s' ", $idUser);
//print_r($query);
if (!pg_query($dbcon, $query)) {
throw new Exception('A operação não pode ser realizada!');
}
if (!$result) {
$query = "update pbx_usuarios set pa_fixo = {$status} where id = {$idUser};";
if (!pg_query($dbcon, $query)) {
throw new Exception('A operação não pode ser realizada!');
}
}
$field['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));
if (!@pg_query($dbcon, 'commit')) {
throw new Exception('A operação não pode ser realizada!');
}
} catch (Exception $e) {
@pg_query($dbcon, 'rollback');
fmtErro($e->getMessage(), pg_last_error($dbcon));
}
}
function GetGrupoUser($dbcon, $codSel, $infos) {
$sel = "";
$infos['name'] = $infos['name'] . "rm";
$query = "SELECT * FROM pbx_usuarios WHERE pa_fixo = 1 ORDER BY apelido;";
$result = pg_query($dbcon, $query);
function AtualizaLicencaX($dbcon, $field, $status) {
$cont = 0;
$lista = '<select name="%s%s" id="%s" size="%s" style="width:%spx;" %s>%s';
$lista = sprintf($lista, $infos['name'], ($infos['multiple'] ? "[]" : ""), $infos['name'], $infos['size'], $infos['width'], ($infos['multiple'] ? 'multiple="multiple"' : ''), "\n");
try {
while (($row = @pg_fetch_array($result))) {
$sel = ($codSel == $row["id"]) ? "selected" : "";
$lista .= "<option value=\"{$row["id"]}\" $sel>{$row["apelido"]}</option>\n";
if ($status == 1) {
$query = "SELECT COUNT(*) AS qtd_pa_fixo FROM pbx_licenca_pa_fixo WHERE matricula IS NOT NULL;";
$result = pg_query($dbcon, $query);
$result = pg_fetch_assoc($result);
if ($result >= $_SESSION['prm_max_licenca_fixo']) {
fmtMsg('A licença de PA Fixo foi excedida!');
throw new Exception('A licença de PA Fixo foi excedida!');
}
}
$lista .= "</select>";
return $lista;
}
function GetUser($dbcon, $codSel, $infos) {
$sel = "";
$infos['name'] = $infos['name'] . "inc";
$query = "SELECT * FROM pbx_usuarios WHERE pa_fixo = 0 AND id NOT IN(342,341,356,357,466) ORDER BY apelido;";
$result = pg_query($dbcon, $query);
if (!$field) {
fmtMsg('Selecione um usuário!');
throw new Exception('Selecione um usuário');
}
$lista = '<select name="%s%s" id="%s" size="%s" style="width:%spx" %s >%s';
$lista = sprintf($lista, $infos['name'], ($infos['multiple'] ? "[]" : ""), $infos['name'], $infos['size'], $infos['width'], ($infos['multiple'] ? 'multiple="multiple"' : ''), "\n");
@pg_query($dbcon, 'begin');
while (($row = @pg_fetch_array($result))) {
$sel = ($codSel == $row["apelido"]) ? "selected" : "";
$lista .= "<option value=\"{$row["id"]}\" $sel>{$row["apelido"]}</option>\n";
foreach ($field as $id) {
$query = "update pbx_usuarios set pa_fixo = {$status} where id = {$id};";
$result = @pg_query($dbcon, $query);
$cont++;
}
$lista .= "</select>\n";
return $lista;
$result = $result && @pg_query($dbcon, 'commit');
if (!$result) {
throw new Exception('A operação não pode ser realizada!');
}
$field['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));
}
}
function GetGrupoUser($dbcon, $codSel, $infos) {
$sel = "";
$infos['name'] = $infos['name'] . "rm";
$query = "SELECT * FROM pbx_usuarios WHERE pa_fixo = 1 ORDER BY apelido;";
$result = @pg_query($dbcon, $query);
$lista = '<select name="%s%s" id="%s" size="%s" style="width:%spx;" %s>%s';
$lista = sprintf($lista, $infos['name'], ($infos['multiple'] ? "[]" : ""), $infos['name'], $infos['size'], $infos['width'], ($infos['multiple'] ? 'multiple="multiple"' : ''), "\n");
while (($row = @pg_fetch_array($result))) {
$sel = ($codSel == $row["id"]) ? "selected" : "";
$lista .= "<option value=\"{$row["id"]}\" $sel>{$row["apelido"]}</option>\n";
}
$lista .= "</select>";
return $lista;
}
function GetUser($dbcon, $codSel, $infos) {
$sel = "";
$infos['name'] = $infos['name'] . "inc";
$query = "SELECT * FROM pbx_usuarios WHERE pa_fixo = 0 AND id NOT IN(342,341,356,357,466) ORDER BY apelido;";
$result = @pg_query($dbcon, $query);
$lista = '<select name="%s%s" id="%s" size="%s" style="width:%spx" %s >%s';
$lista = sprintf($lista, $infos['name'], ($infos['multiple'] ? "[]" : ""), $infos['name'], $infos['size'], $infos['width'], ($infos['multiple'] ? 'multiple="multiple"' : ''), "\n");
while (($row = @pg_fetch_array($result))) {
$sel = ($codSel == $row["apelido"]) ? "selected" : "";
$lista .= "<option value=\"{$row["id"]}\" $sel>{$row["apelido"]}</option>\n";
}
$lista .= "</select>\n";
return $lista;
}
?>

6
templates/confSistema.tpl

@ -272,15 +272,15 @@
<tr>
<th align="left">Licença de P.A.</th>
<td align="left"><input name="prm_max_licenca" type="text" id="prm_max_licenca" value="{$prm_max_licenca}" size="10" maxlength="3" /></td>
<td align="left"><input name="prm_max_licenca" type="text" id="prm_max_licenca" value="{$prm_max_licenca}" size="10" maxlength="3" readonly title="Não editável"/></td>
</tr>
<tr>
<th align="left">Licença de P.A Fixo</th>
<td align="left"><input name="prm_max_licenca_fixo" type="text" id="prm_max_licenca_fixo" value="{$prm_max_licenca_fixo}" size="10" maxlength="3" /></td>
<td align="left"><input name="prm_max_licenca_fixo" type="text" id="prm_max_licenca_fixo" value="{$prm_max_licenca_fixo}" size="10" maxlength="3" readonly title="Não editável"/></td>
</tr>
<tr>
<th align="left">Licença de Ramais</th>
<td align="left"><input name="prm_max_ramal" type="text" id="prm_max_ramal" value="{$prm_max_ramal}" size="10" maxlength="4" /></td>
<td align="left"><input name="prm_max_ramal" type="text" id="prm_max_ramal" value="{$prm_max_ramal}" size="10" maxlength="4" readonly title="Não editável"/></td>
</tr>
<tr>
<th align="left">Habilitar Normalização de Agenda</th>

87
templates/configLicenca.tpl

@ -45,24 +45,81 @@
<input name="document" type="text" id="lca_document" value="{$document}" size="50" maxlength="255">
</td>
</tr>
<tr>
<th align="left">Razão Social:</th>
<td>
<input name="razao_social" type="text" id="lca_razao" value="{$razao_social}" size="50" maxlength="255">
</td>
</tr>
<tr>
<th align="left">Perfil Central:</th>
<td>
<select name="lcnca_perfil" style="width:400px;">
<select name="perfil" style="width:400px;">
{$select_perfil}
</select>
</td>
</tr>
<tr>
<th align="left">Licença de P.A.:</th>
<td>
<input name="lca_pa" type="text" id="lca_pa" value="{$lca_pa}" size="10" maxlength="4">
</td>
</tr>
<tr>
<th align="left">Licença de P.A. Fixo:</th>
<td>
<input name="lca_pa_fixo" type="text" id="lca_pa_fixo" value="{$lca_pa_fixo}" size="10" maxlength="4">
</td>
</tr>
<tr>
<th align="left">Nº Contrato 1:</th>
<th align="left">Licença de Ramais:</th>
<td>
<input name="lca_ramais" type="text" id="lca_ramais" value="{$lca_ramais}" size="10" maxlength="4">
</td>
</tr>
{if '1' == '2'}
<tr>
<th align="left">Licença de Supervisor:</th>
<td>
<input name="lcnca_contato1" type="text" id="contrato1" value="{$lcnca_contato1}" size="50" maxlength="255" title="">
<a id="addcontract" href="#" title="Adicionar mais um campo para informar o contrato">
<img src="images/novo.gif" width="20" height="20" border="0" align="absmiddle" title="">
</a>
<input name="lca_supervisor" type="text" id="lca_supervisor" value="{$lca_supervisor}" size="10" maxlength="4">
</td>
</tr>
<tr>
<th align="left">Licença de Pesquisa:</th>
<td>
<input name="lca_pesquisa" type="text" id="lca_pesquisa" value="{$lca_pesquisa}" size="10" maxlength="4">
</td>
</tr>
<tr>
<th align="left">Licença de Tarifador:</th>
<td>
<input name="lca_tarifador" type="text" id="lca_tarifador" value="{$lca_tarifador}" size="10" maxlength="4">
</td>
</tr>
<tr>
<th align="left">Licença de Mesa Operadora:</th>
<td>
<input name="lca_mesaoperadora" type="text" id="lca_mesaoperadora" value="{$lca_mesaoperadora}" size="10" maxlength="4">
</td>
</tr>
<tr>
<th align="left">Licença Manager One:</th>
<td>
<input name="lca_manager_one" type="text" id="lca_manager_one" value="{$lca_manager_one}" size="10" maxlength="4">
</td>
</tr>
{/if}
</tbody>
</table>
</td>
@ -93,22 +150,4 @@
</tr>
</table>
{/if}
{literal}
<script>
$(function () {
let cont = 2;
$("#addcontract").on('click', function () {
$("#tablelca").append(`
<tr>
<th align="left">Nº Contrato ${cont}:</th>
<td>
<input name="lcnca_contato${cont}" type="text" id="lcnca_contato${cont}" size="50" maxlength="255" title="">
</td>
</tr>`);
cont++;
})
})
</script>
{/literal}
{/capture}
Loading…
Cancel
Save