|
|
<?php |
|
|
|
|
|
class FormGenerator |
|
|
{ |
|
|
private $__prog; |
|
|
private $title; |
|
|
private $acao; |
|
|
private $param; |
|
|
private $id_form; |
|
|
private $conexao_banco; |
|
|
private $dados = []; |
|
|
private $formulario_js; |
|
|
|
|
|
public function __construct($__prog, $title, $acao, $param, $id_form, $conexao_banco) |
|
|
{ |
|
|
$this->__prog = $__prog; |
|
|
$this->title = $title; |
|
|
$this->acao = $acao; |
|
|
$this->param = $param; |
|
|
$this->id_form = $id_form; |
|
|
$this->conexao_banco = $conexao_banco; |
|
|
$this->formulario_js = file_get_contents('/var/www/html/aplicativo/admin/js/formularios.js'); |
|
|
} |
|
|
|
|
|
public function createForms() |
|
|
{ |
|
|
echo $this->generateForms($this->dados); |
|
|
} |
|
|
|
|
|
private function generateForms($configuracao) |
|
|
{ |
|
|
$formulario = ''; |
|
|
$formulario .= $this->generateHeadForms($configuracao); |
|
|
|
|
|
foreach ($configuracao as $grupo) { |
|
|
$formulario .= $this->generateDivRow($grupo); |
|
|
} |
|
|
$formulario .= '</div>'; |
|
|
$formulario .= $this->createButtonsForms(); |
|
|
$formulario .= $this->showLoading(); |
|
|
|
|
|
$formulario .= '</div></form>'; |
|
|
$formulario .= $this->createJavaScript($this->formulario_js); |
|
|
$formulario .= '</body></html>'; |
|
|
|
|
|
return $formulario; |
|
|
} |
|
|
|
|
|
private function generateHeadForms($dados) |
|
|
{ |
|
|
$enctype = $this->formContainsFileUpload($dados) ? ' enctype="multipart/form-data"' : ''; |
|
|
$html = ' |
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
|
<html> |
|
|
<head> |
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> |
|
|
<script type="text/javascript" src="scriptApl/functions15.js"></script> |
|
|
<link rel="stylesheet" href="admin/css/forms_style.css"> |
|
|
<script src="admin/js/jquery.min.js" type="text/javascript"></script> |
|
|
</head> |
|
|
<body> |
|
|
<form name="form1" method="post" action="index.php?idProg=' . $this->__prog . '&pbxRequest=1&acao=' . $this->acao . '&acao2=salva' . $this->param . '" id="form1"' . $enctype . '> |
|
|
<div class="container"> |
|
|
' . $this->generateTitleForms() . ' |
|
|
' . $this->generateInputHidden() . ' |
|
|
<div class="container-content"> |
|
|
'; |
|
|
|
|
|
return $html; |
|
|
} |
|
|
|
|
|
private function showLoading() |
|
|
{ |
|
|
$div_loading = '<div id="overlay"></div>'; |
|
|
$div_loading .= '<div id="loading" alt="Carregando..."></div>'; |
|
|
|
|
|
return $div_loading; |
|
|
} |
|
|
|
|
|
private function generateTitleForms() |
|
|
{ |
|
|
$html = '<div class="titulo"> ' . '<h1>' . $this->title . '</h1></div>'; |
|
|
return $html; |
|
|
} |
|
|
|
|
|
private function generateInputHidden() |
|
|
{ |
|
|
$html = ''; |
|
|
$html .= '<input name="id" type="hidden" id="id2" value="' . (($this->acao == "edita") ? $this->id_form : null) . '" />'; |
|
|
$html .= '<input name="acao" type="hidden" id="acao" value="' . $this->acao . '" />'; |
|
|
return $html; |
|
|
} |
|
|
|
|
|
public function createButtonsForms() |
|
|
{ |
|
|
$html = ''; |
|
|
$html .= '<div class="row-bn">'; |
|
|
$html .= '<div class="bn-submit">'; |
|
|
$html .= '<input class="button-submit" name="Submit" type="submit" value="Salvar" onclick="marca_todos();">'; |
|
|
$html .= '</div>'; |
|
|
$html .= '<div class="bn-close">'; |
|
|
$html .= '<input class="button-close" name="Submit2" type="button" onclick="fecha_popup();" value="Fechar" id="btfechar">'; |
|
|
$html .= '</div>'; |
|
|
$html .= '</div>'; |
|
|
|
|
|
return $html; |
|
|
} |
|
|
|
|
|
private function generateDivRow($grupo) |
|
|
{ |
|
|
$html = ''; |
|
|
|
|
|
if ($grupo['collapse'] === 'abrir') { |
|
|
$html .= '<div class="collapse-config-advanced">'; |
|
|
$html .= '<button id="' . $grupo['botao-collapse-id'] . '" class="collapse-btn" onclick="toggleCollapse(\'' . $grupo['div-collapse-id'] . '\')" type="button">' . $grupo['botao-collapse-nome'] . '</button>'; |
|
|
$html .= '<div class="collapse-config-advanced-content" id="' . $grupo['div-collapse-id'] . '">'; |
|
|
return $html; |
|
|
} |
|
|
|
|
|
switch ($grupo['estilo-linha']) { |
|
|
case 'border-color': |
|
|
$html .= '<div class="row head-tabela">'; |
|
|
break; |
|
|
|
|
|
case 'background-color': |
|
|
$html .= '<div class="row content-tabela">'; |
|
|
break; |
|
|
|
|
|
default: |
|
|
$html .= '<div class="row">'; |
|
|
break; |
|
|
} |
|
|
|
|
|
if (isset($grupo['coluna']) && is_array($grupo['coluna'])) { |
|
|
foreach ($grupo['coluna'] as $elemento) { |
|
|
if ($elemento['abrir-div'] != null) { |
|
|
$html .= $this->generateDivOpening($elemento['abrir-div']); |
|
|
continue; |
|
|
} elseif ($elemento['fechar-div'] == 'fechar') { |
|
|
$html .= ' </div>'; |
|
|
continue; |
|
|
} |
|
|
$html .= $this->generateColumn($elemento); |
|
|
} |
|
|
} |
|
|
|
|
|
if ($grupo['collapse'] === 'fechar') { |
|
|
$html .= '</div></div>'; |
|
|
} |
|
|
$html .= '</div>'; |
|
|
|
|
|
return $html; |
|
|
} |
|
|
|
|
|
public function addDiv(?string $funcao = null, ?array $attributes = null) |
|
|
{ |
|
|
if ($funcao == 'abrir') { |
|
|
return [ |
|
|
'abrir-div' => $attributes |
|
|
]; |
|
|
} elseif ($funcao == 'fechar') { |
|
|
return [ |
|
|
'fechar-div' => 'fechar' |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
private function generateFirstDiv($elemento) |
|
|
{ |
|
|
$tipo = isset($elemento['tipo-conteudo']) ? $elemento['tipo-conteudo'] : 'coluna-content'; |
|
|
$classe = isset($elemento['classe-coluna']) ? $elemento['classe-coluna'] : 'coluna'; |
|
|
|
|
|
switch ($classe) { |
|
|
case 'toggle': |
|
|
$classe = 'coluna-toggle'; |
|
|
break; |
|
|
case '': |
|
|
$classe = null; |
|
|
break; |
|
|
default: |
|
|
$classe = 'coluna'; |
|
|
break; |
|
|
} |
|
|
switch ($tipo) { |
|
|
|
|
|
case 'titulo': |
|
|
$divContent = 'coluna-titulo'; |
|
|
break; |
|
|
case 'toggle': |
|
|
$divContent = 'coluna-content-toggle'; |
|
|
break; |
|
|
case 'codecs': |
|
|
$divContent = 'codecs-content'; |
|
|
break; |
|
|
case '': |
|
|
$divContent = null; |
|
|
break; |
|
|
default: |
|
|
$divContent = 'coluna-content'; |
|
|
break; |
|
|
} |
|
|
if ($classe != null) { |
|
|
$divInicial = '<div class="' . $classe . '">'; |
|
|
} else { |
|
|
$divInicial = ''; |
|
|
} |
|
|
|
|
|
return array($divInicial, $divContent); |
|
|
} |
|
|
|
|
|
private function generateColumn($elemento) |
|
|
{ |
|
|
$html = ''; |
|
|
list($divInicial, $divContent) = $this->generateFirstDiv($elemento); |
|
|
$html .= $divInicial; |
|
|
if ($elemento['titulo'] != null) { |
|
|
$html .= '<div class="coluna-titulo">' . '<h1>' . $elemento['titulo'] . '</h1>' . '</div>'; |
|
|
} |
|
|
if ($divContent != null) { |
|
|
$html .= '<div class="' . $divContent . '">' . $this->generateElement($elemento) . '</div>'; |
|
|
} |
|
|
$html .= '</div>'; |
|
|
|
|
|
return $html; |
|
|
} |
|
|
|
|
|
private function generateDivOpening($attributes) |
|
|
{ |
|
|
$html = '<div'; |
|
|
foreach ($attributes as $key => $value) { |
|
|
$html .= ' ' . $key . '="' . $value . '"'; |
|
|
} |
|
|
$html .= '>'; |
|
|
|
|
|
return $html; |
|
|
} |
|
|
|
|
|
private function generateElement($elemento) |
|
|
{ |
|
|
$tipo = is_array($elemento) && isset($elemento['tipo-conteudo']) ? $elemento['tipo-conteudo'] : 'coluna-content'; |
|
|
$formato = isset($elemento['formato']) ? $elemento['formato'] : 'input'; |
|
|
$props = $elemento['propriedades']; |
|
|
|
|
|
switch ($tipo) { |
|
|
case 'file': |
|
|
return '<div class="file-class"> <div class="file-label"><p>' . $elemento['text'] . '</p></div> |
|
|
<label class="custom-file" for="' . $props[0]['id'] . '"> |
|
|
<input ' . $this->generateAttributes($props[0]) . ' />Upload |
|
|
<span class="custom-file-span"></span> |
|
|
</label></div>'; |
|
|
break; |
|
|
|
|
|
case 'toggle': |
|
|
return '<div class="toggle-bn"> |
|
|
<label class="switch" for="' . $props[0]['id'] . '"> |
|
|
<input ' . $this->generateAttributes($props[0]) . ' /> |
|
|
<span class="slider round"></span> |
|
|
</label> |
|
|
</div>'; |
|
|
|
|
|
case 'codecs': |
|
|
$codecs = ''; |
|
|
foreach ($props as $set) { |
|
|
$codecs .= '<div class="codecs-check">'; |
|
|
$codecs .= '<input ' . $this->generateAttributes($set) . ' />' . ucfirst($set['value']) . '</div>'; |
|
|
} |
|
|
return $codecs; |
|
|
|
|
|
default: |
|
|
switch ($formato) { |
|
|
case 'select': |
|
|
return $this->generateSelect($props[0]); |
|
|
break; |
|
|
case 'textarea': |
|
|
return $this->generateTextarea($props[0]); |
|
|
break; |
|
|
case 'botaoSelect': |
|
|
return $this->generateSelectButton($props); |
|
|
break; |
|
|
default: |
|
|
if (count($props) > 1) { |
|
|
$inputs = ''; |
|
|
foreach ($props as $set) { |
|
|
if (isset($set['image'])) { |
|
|
$inputs .= '<img ' . $this->generateAttributes($set) . ' />'; |
|
|
} else { |
|
|
$inputs .= '<input ' . $this->generateAttributes($set) . ' />'; |
|
|
} |
|
|
} |
|
|
return $inputs; |
|
|
} else { |
|
|
if (isset($props[0]['image'])) { |
|
|
return '<img ' . $this->generateAttributes($props[0]) . ' />'; |
|
|
} else { |
|
|
return '<input ' . $this->generateAttributes($props[0]) . ' />'; |
|
|
} |
|
|
} |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
private function generateAttributes($props) |
|
|
{ |
|
|
$atributos = ''; |
|
|
|
|
|
foreach ($props as $atributo => $valor) { |
|
|
// Verificar se o atributo <EFBFBD> 'selected' ou 'checked' e o valor <EFBFBD> falso |
|
|
if ($valor == null || $valor === '') { |
|
|
continue; // Ignorar o atributo se o valor for falso |
|
|
} |
|
|
|
|
|
// Adicionar o nome do atributo |
|
|
$atributos .= $atributo; |
|
|
|
|
|
// Adicionar valor apenas se a chave for 'checked' ou 'selected' |
|
|
if ($atributo === 'checked' || $atributo === 'selected' || $atributo === 'disabled') { |
|
|
// N<EFBFBD>o adicionar valor mesmo se for verdadeiro |
|
|
$atributos .= null; |
|
|
} elseif (!is_bool($valor) || $valor) { |
|
|
// Adicionar valor se n<EFBFBD>o for booleano (true/false) ou se for verdadeiro para outros atributos |
|
|
$atributos .= '="' . $valor . '"'; |
|
|
} |
|
|
|
|
|
$atributos .= ' '; |
|
|
} |
|
|
|
|
|
return trim($atributos); // Remover espa<EFBFBD>o extra no final, se houver |
|
|
} |
|
|
|
|
|
private function generateSelect($props) |
|
|
{ |
|
|
$options = isset($props['options']) ? $props['options'] : []; |
|
|
$selectHtml = '<select ' . $this->generateAttributes($props) . '>'; |
|
|
|
|
|
foreach ($options as $value => $optionInfo) { |
|
|
$label = $optionInfo['label']; |
|
|
$attributes = isset($optionInfo['attributes']) ? $this->generateAttributes($optionInfo['attributes']) : ''; |
|
|
$selected = is_array($optionInfo) && isset($optionInfo['selected']) && $optionInfo['selected'] ? 'selected' : ''; |
|
|
|
|
|
$selectHtml .= '<option value="' . $value . '" ' . $attributes . ' ' . $selected . '>' . $label . '</option>'; |
|
|
} |
|
|
|
|
|
$selectHtml .= '</select>'; |
|
|
|
|
|
return $selectHtml; |
|
|
} |
|
|
|
|
|
private function generateTextarea($props) |
|
|
{ |
|
|
$attributes = $this->generateAttributes($props); |
|
|
$value = isset($props['value']) ? $props['value'] : ''; |
|
|
|
|
|
$textareaHtml = '<textarea ' . $attributes . '>' . $value . '</textarea>'; |
|
|
|
|
|
return $textareaHtml; |
|
|
} |
|
|
|
|
|
private function generateSelectButton($props) |
|
|
{ |
|
|
$attributesAdd = $this->generateAttributes($props[0]); |
|
|
$attributesRemove = $this->generateAttributes($props[1]); |
|
|
|
|
|
$botaoSelect = '<div class="select-bn"> |
|
|
<div ' . $attributesAdd . '> |
|
|
<h3> > </h3> |
|
|
</div> |
|
|
<div ' . $attributesRemove . '> |
|
|
<h3> < </h3> |
|
|
</div> |
|
|
</div>'; |
|
|
|
|
|
return $botaoSelect; |
|
|
} |
|
|
|
|
|
// Funca que busca os codecs e gera eles para apresentar no formulario |
|
|
public function getOptionsCodecs($allow) |
|
|
{ |
|
|
$options = ['all' => |
|
|
[ |
|
|
'class' => 'codecs-check', |
|
|
'name' => 'marcaTodos', |
|
|
'type' => 'checkbox', |
|
|
'id' => 'marcaTodos', |
|
|
'value' => 'all', |
|
|
'onclick' => 'seleciona_tudo(this.checked)', |
|
|
]]; |
|
|
$numCodec = 0; |
|
|
if (is_array($allow)) { |
|
|
$allow = implode(",", $allow); |
|
|
} |
|
|
foreach (GetCodecs(true) as $codec) { |
|
|
$check = ((strpos($allow, $codec) !== false)) ? true : false; |
|
|
$options[$codec] = [ |
|
|
'name' => 'allow[]', |
|
|
'type' => 'checkbox', |
|
|
'id' => 'allow' . ++$numCodec, |
|
|
'value' => $codec, |
|
|
'checked' => $check, |
|
|
]; |
|
|
} |
|
|
return $options; |
|
|
} |
|
|
|
|
|
public function addTableRoutes($query) |
|
|
{ |
|
|
$resultRotas = pg_query($this->conexao_banco, $query); |
|
|
$rotasEncontradas = [ |
|
|
'estilo-linha' => 'border-color', |
|
|
'coluna' => [ |
|
|
[ |
|
|
'titulo' => 'Rota', |
|
|
'tipo-conteudo' => 'normal', |
|
|
'classe-coluna' => 'toggle', |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'style' => 'display: none', |
|
|
] |
|
|
], |
|
|
], |
|
|
[ |
|
|
'titulo' => 'Sim', |
|
|
'classe-coluna' => 'toggle', |
|
|
'tipo-conteudo' => 'normal', |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => 'opcao-rota', |
|
|
'type' => 'radio', |
|
|
'id' => 'simCheck', |
|
|
'title' => 'Clique para marcar todos!', |
|
|
'style' => 'cursor: pointer', |
|
|
] |
|
|
] |
|
|
], |
|
|
[ |
|
|
'titulo' => 'N<EFBFBD>o', |
|
|
'classe-coluna' => 'toggle', |
|
|
'tipo-conteudo' => 'normal', |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => 'opcao-rota', |
|
|
'type' => 'radio', |
|
|
'id' => 'naoCheck', |
|
|
'title' => 'Clique para marcar todos!', |
|
|
'style' => 'cursor: pointer', |
|
|
] |
|
|
] |
|
|
], |
|
|
[ |
|
|
'titulo' => 'Conta/Senha', |
|
|
'classe-coluna' => 'toggle', |
|
|
'tipo-conteudo' => 'normal', |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => 'opcao-rota', |
|
|
'type' => 'radio', |
|
|
'id' => 'senhaCheck', |
|
|
'title' => 'Clique para marcar todos!', |
|
|
'style' => 'cursor: pointer', |
|
|
] |
|
|
] |
|
|
], |
|
|
[ |
|
|
'titulo' => 'Agente', |
|
|
'classe-coluna' => 'toggle', |
|
|
'tipo-conteudo' => 'normal', |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => 'opcao-rota', |
|
|
'type' => 'radio', |
|
|
'id' => 'agenteCheck', |
|
|
'title' => 'Clique para marcar todos!', |
|
|
'style' => 'cursor: pointer', |
|
|
] |
|
|
] |
|
|
], |
|
|
] |
|
|
]; |
|
|
$this->dados[] = $rotasEncontradas; |
|
|
|
|
|
while ($dadosRota = pg_fetch_array($resultRotas)) { |
|
|
$tipoAcesso = $dadosRota["tipo_acesso"]; |
|
|
$idRota = $dadosRota["id_rota"]; |
|
|
$nomeRota = $dadosRota["nome_rota"]; |
|
|
|
|
|
$rotasEncontradas = [ |
|
|
'estilo-linha' => 'background-color', |
|
|
'coluna' => [ |
|
|
[ |
|
|
'titulo' => $nomeRota, |
|
|
'classe-coluna' => 'normal', |
|
|
'tipo-conteudo' => '', |
|
|
], |
|
|
[ |
|
|
'titulo' => '', |
|
|
'classe-coluna' => 'normal', |
|
|
'tipo-conteudo' => 'titulo', |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'type' => 'radio', |
|
|
'name' => 'tipoRota[' . $idRota . ']', |
|
|
'class' => 'tipoRotaSim', |
|
|
'value' => '1;' . $idRota, |
|
|
'checked' => ($tipoAcesso == 1) ? true : false, |
|
|
] |
|
|
] |
|
|
], |
|
|
[ |
|
|
'titulo' => '', |
|
|
'classe-coluna' => 'normal', |
|
|
'tipo-conteudo' => 'titulo', |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'type' => 'radio', |
|
|
'name' => 'tipoRota[' . $idRota . ']', |
|
|
'class' => 'tipoRotaNao', |
|
|
'value' => '0;' . $idRota, |
|
|
'checked' => ($tipoAcesso == 0) ? true : false, |
|
|
] |
|
|
] |
|
|
], |
|
|
[ |
|
|
'titulo' => '', |
|
|
'classe-coluna' => 'normal', |
|
|
'tipo-conteudo' => 'titulo', |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'type' => 'radio', |
|
|
'name' => 'tipoRota[' . $idRota . ']', |
|
|
'class' => 'tipoRotaSenha', |
|
|
'value' => '2;' . $idRota, |
|
|
'checked' => ($tipoAcesso == 2) ? true : false, |
|
|
] |
|
|
] |
|
|
], |
|
|
[ |
|
|
'titulo' => '', |
|
|
'classe-coluna' => 'normal', |
|
|
'tipo-conteudo' => 'titulo', |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'type' => 'radio', |
|
|
'name' => 'tipoRota[' . $idRota . ']', |
|
|
'class' => 'tipoRotaAgente', |
|
|
'value' => '3;' . $idRota, |
|
|
'checked' => ($tipoAcesso == 3) ? true : false, |
|
|
] |
|
|
] |
|
|
], |
|
|
] |
|
|
]; |
|
|
$this->dados[] = $rotasEncontradas; |
|
|
} |
|
|
} |
|
|
|
|
|
public function getOptions($query, $valorAtual, $colunaBanco, $defaultLabel = null) |
|
|
{ |
|
|
$result = pg_query($this->conexao_banco, $query); |
|
|
$options = []; |
|
|
|
|
|
if ($defaultLabel !== null) { |
|
|
$options['default'] = [ |
|
|
'label' => $defaultLabel, |
|
|
'attributes' => [], |
|
|
]; |
|
|
} |
|
|
|
|
|
while ($dados = pg_fetch_array($result)) { |
|
|
$selected = ($this->acao == 'edita') && ($valorAtual == $dados[$colunaBanco]) ? true : false; |
|
|
$options[$dados[$colunaBanco]] = [ |
|
|
'label' => $dados[$colunaBanco], |
|
|
'attributes' => [ |
|
|
'selected' => $selected, |
|
|
] |
|
|
]; |
|
|
} |
|
|
|
|
|
return $options; |
|
|
} |
|
|
|
|
|
|
|
|
private function createJavaScript($javascriptContent) |
|
|
{ |
|
|
$scripts = '<script>' . $javascriptContent . '</script>'; |
|
|
|
|
|
return $scripts; |
|
|
} |
|
|
|
|
|
public function inputText( |
|
|
$title = null, |
|
|
$class_column = 'normal', |
|
|
$name = null, |
|
|
$value = null, |
|
|
$value_banco = null, |
|
|
$size = null, |
|
|
$maxlength = null, |
|
|
$oninput = null, |
|
|
$required = null, |
|
|
$pattern = null, |
|
|
$placeholder = null, |
|
|
$disabled = null, |
|
|
$criarCampoOculto = false, |
|
|
$name_oculto = null, |
|
|
$id_oculto = null, |
|
|
$value_oculto = null, |
|
|
$value_banco_oculto = null, |
|
|
$style = null, |
|
|
?array $div_open = null, |
|
|
?string $div_close = null |
|
|
) { |
|
|
$campos = [ |
|
|
$this->inputPropsText($name, $value, $value_banco, $size, $maxlength, $oninput, $required, $pattern, $placeholder, $disabled, $style, $div_open, $div_close), |
|
|
]; |
|
|
|
|
|
if ($criarCampoOculto) { |
|
|
$campos[] = $this->inputHidden($name_oculto, $id_oculto, $value_oculto, $value_banco_oculto); |
|
|
} |
|
|
|
|
|
return [ |
|
|
'tipo-conteudo' => 'normal', |
|
|
'titulo' => $title, |
|
|
'classe-coluna' => $class_column, |
|
|
'abrir-div' => $div_open, |
|
|
'fechar-div' => $div_close, |
|
|
'propriedades' => $campos, |
|
|
]; |
|
|
} |
|
|
|
|
|
public function inputFile( |
|
|
?string $class_column = 'normal', |
|
|
?string $title = null, |
|
|
?string $text = null, |
|
|
?string $name = null, |
|
|
?bool $required = false, |
|
|
?array $div_open = null, |
|
|
?string $div_close = null, |
|
|
?bool $multiple = false, |
|
|
string $accept = null, |
|
|
) { |
|
|
return [ |
|
|
'tipo-conteudo' => 'file', |
|
|
'titulo' => $title, |
|
|
'classe-coluna' => $class_column, |
|
|
'abrir-div' => $div_open, |
|
|
'fechar-div' => $div_close, |
|
|
'text' => $text, |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => $name, |
|
|
'id' => $this->removeSquareBrackets($name), |
|
|
'type' => 'file', |
|
|
'multiple' => $multiple, |
|
|
'required' => $required, |
|
|
'onchange' => 'updateFileLabel(this)', |
|
|
'accept' => $accept, |
|
|
'style' => 'display: none;', |
|
|
], |
|
|
|
|
|
], |
|
|
]; |
|
|
} |
|
|
|
|
|
// Fun<EFBFBD><EFBFBD>o para criar um campo de texto |
|
|
private function inputPropsText($name, $value, $value_banco, $size, $maxlength, $oninput, $required, $pattern, $placeholder, $disabled, $style) |
|
|
{ |
|
|
$value = ($this->acao == 'edita') ? $value_banco : $value; |
|
|
return [ |
|
|
'name' => $name, |
|
|
'id' => $name, |
|
|
'type' => 'text', |
|
|
'value' => $value, |
|
|
'size' => $size, |
|
|
'maxlength' => $maxlength, |
|
|
'oninput' => $oninput, |
|
|
'required' => $required, |
|
|
'pattern' => $pattern, |
|
|
'placeholder' => $placeholder, |
|
|
'disabled' => $disabled, |
|
|
'style' => $style, |
|
|
]; |
|
|
} |
|
|
|
|
|
// Fun<EFBFBD><EFBFBD>o para criar um campo oculto |
|
|
private function inputHidden($name_oculto, $id_oculto, $value_oculto, $value_banco_oculto) |
|
|
{ |
|
|
$value_oculto = ($this->acao == 'edita') ? $value_banco_oculto : $value_oculto; |
|
|
return [ |
|
|
'name' => $name_oculto, |
|
|
'id' => $id_oculto, |
|
|
'type' => 'hidden', |
|
|
'value' => $value_oculto, |
|
|
]; |
|
|
} |
|
|
|
|
|
public function inputNumber($title = null, $name = null, $value_default = '1', $onchange = null) |
|
|
{ |
|
|
return [ |
|
|
'tipo-conteudo' => 'normal', |
|
|
'classe-coluna' => 'normal', |
|
|
'titulo' => $title, |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => $name, |
|
|
'type' => 'number', |
|
|
'min' => '0', |
|
|
'step' => 'any', |
|
|
'required' => 'required', |
|
|
'id' => $name, |
|
|
'value' => $value_default, |
|
|
'size' => '5', |
|
|
'maxlength' => '10', |
|
|
'onchange' => $onchange, |
|
|
], |
|
|
], |
|
|
]; |
|
|
} |
|
|
|
|
|
|
|
|
public function inputPasswordWithButton($title = null, $class_column = 'normal', $name = null, $value = null, $value_banco = null, $nome_ramal = null) |
|
|
{ |
|
|
$value = ($this->acao == "edita") ? $value_banco : $value; |
|
|
|
|
|
return [ |
|
|
'tipo-conteudo' => 'normal', |
|
|
'classe-coluna' => $class_column, |
|
|
'titulo' => $title, |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => $name, |
|
|
'type' => 'password', |
|
|
'required' => 'optional', |
|
|
'id' => $name, |
|
|
'value' => $value, |
|
|
'size' => '10', |
|
|
'maxlength' => '100', |
|
|
], |
|
|
[ |
|
|
'image' => true, |
|
|
'id' => 'hide-password-ramal', |
|
|
'title' => 'Clique para exibir a senha do ramal!', |
|
|
'onclick' => "MostraSenhaRamal('$this->__prog','$nome_ramal');", |
|
|
'src' => 'imgSite/hide-password-16.png', |
|
|
'border' => '0', |
|
|
'style' => 'vertical-align: middle; cursor:pointer', |
|
|
], |
|
|
], |
|
|
]; |
|
|
} |
|
|
|
|
|
public function inputPasswordWithoutButton($title = null, $class_column = 'normal', $name = null, $value = null, $value_banco = null, $placeholder = null, $disabled = null, $style = null) |
|
|
{ |
|
|
$value = ($this->acao == "edita") ? $value_banco : $value; |
|
|
|
|
|
return [ |
|
|
'tipo-conteudo' => 'normal', |
|
|
'classe-coluna' => $class_column, |
|
|
'titulo' => $title, |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => $name, |
|
|
'autocomplete' => 'new-password', |
|
|
'type' => 'password', |
|
|
'required' => 'optional', |
|
|
'id' => $name, |
|
|
'value' => $value, |
|
|
'size' => '10', |
|
|
'maxlength' => '20', |
|
|
'placeholder' => $placeholder, |
|
|
'disabled' => $disabled, |
|
|
'style' => $style, |
|
|
], |
|
|
], |
|
|
]; |
|
|
} |
|
|
|
|
|
|
|
|
public function inputButton($title = null, $name = null, $value = null, $value_banco = null, $checked = false, $disabled = null, $onclick = null) |
|
|
{ |
|
|
if ($this->acao == 'inseri' && $checked == true) { |
|
|
$checked = true; |
|
|
} elseif (($this->acao == 'edita') && ($value_banco == $value)) { |
|
|
$checked = true; |
|
|
} |
|
|
return [ |
|
|
'tipo-conteudo' => 'toggle', |
|
|
'titulo' => $title, |
|
|
'classe-coluna' => 'toggle', |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => $name, |
|
|
'type' => 'checkbox', |
|
|
'id' => $name, |
|
|
'value' => $value, |
|
|
'checked' => $checked, |
|
|
'disabled' => $disabled, |
|
|
'onclick' => $onclick, |
|
|
], |
|
|
], |
|
|
]; |
|
|
} |
|
|
|
|
|
public function inputTipoLigacao($title = null, $class_column = 'normal', $name = null, $value_banco = null) |
|
|
{ |
|
|
return [ |
|
|
'tipo-conteudo' => 'normal', |
|
|
'classe-coluna' => $class_column, |
|
|
'formato' => 'select', |
|
|
'titulo' => $title, |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => $name, |
|
|
'id' => $name, |
|
|
'class' => 'selecao', |
|
|
'options' => [ |
|
|
'user' => [ |
|
|
'label' => 'Faz liga<EFBFBD><EFBFBD>es', |
|
|
'attributes' => ['data-custom' => 'value'], |
|
|
'selected' => ($this->acao == 'edita' && $value_banco == 'user') ? true : false, |
|
|
], |
|
|
'peer' => [ |
|
|
'label' => 'Recebe liga<EFBFBD><EFBFBD>es', |
|
|
'attributes' => ['data-custom' => 'value'], |
|
|
'selected' => ($this->acao == 'edita' && $value_banco == 'peer') ? true : false, |
|
|
], |
|
|
'friend' => [ |
|
|
'label' => 'Ambos', |
|
|
'attributes' => ['data-custom' => 'value'], |
|
|
'selected' => ($this->acao == 'edita' && $value_banco == 'friend') || ($this->acao != 'edita') ? true : false, |
|
|
], |
|
|
], |
|
|
], |
|
|
], |
|
|
]; |
|
|
} |
|
|
|
|
|
public function select($title = null, $class_column = null, $name = null, $options = null, $size = null, $multiple = null) |
|
|
{ |
|
|
return [ |
|
|
'tipo-conteudo' => 'normal', |
|
|
'classe-coluna' => $class_column, |
|
|
'formato' => 'select', |
|
|
'titulo' => $title, |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => $name, |
|
|
'id' => $this->removeSquareBrackets($name), |
|
|
'class' => 'selecao', |
|
|
'options' => $options, |
|
|
'size' => $size, |
|
|
'multiple' => $multiple, |
|
|
], |
|
|
], |
|
|
]; |
|
|
} |
|
|
|
|
|
private function removeSquareBrackets($name) |
|
|
{ |
|
|
if (strpos($name, '[') !== false && strpos($name, ']') !== false) { |
|
|
// Remove os colchetes da string |
|
|
return preg_replace('/[\[\]]/', '', $name); |
|
|
} |
|
|
return $name; |
|
|
} |
|
|
|
|
|
public function inputCodecs($title = null, $options = null) |
|
|
{ |
|
|
return [ |
|
|
'tipo-conteudo' => 'codecs', |
|
|
'classe-coluna' => 'normal', |
|
|
'titulo' => $title, |
|
|
'propriedades' => $options, |
|
|
]; |
|
|
} |
|
|
|
|
|
public function inputConexoesPeers($title = null, $class_column = 'normal', $name = null, $value_banco = null) |
|
|
{ |
|
|
return [ |
|
|
'tipo-conteudo' => 'normal', |
|
|
'classe-coluna' => $class_column, |
|
|
'formato' => 'select', |
|
|
'titulo' => $title, |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => $name, |
|
|
'id' => $name, |
|
|
'class' => 'selecao', |
|
|
'options' => [ |
|
|
'default' => [ |
|
|
'label' => 'Default', |
|
|
'attributes' => [ |
|
|
'selected' => ($value_banco == 'default' && $this->acao == 'edita') ? true : false, |
|
|
], |
|
|
], |
|
|
'port' => [ |
|
|
'label' => 'port', |
|
|
'attributes' => [ |
|
|
'selected' => ($value_banco == 'port' && $this->acao == 'edita') ? true : false, |
|
|
] |
|
|
], |
|
|
'invite' => [ |
|
|
'label' => 'invite', |
|
|
'attributes' => [ |
|
|
'selected' => ($value_banco == 'invite' && $this->acao == 'edita') ? true : false, |
|
|
] |
|
|
], |
|
|
'very' => [ |
|
|
'label' => 'very', |
|
|
'attributes' => [ |
|
|
'selected' => ($value_banco == 'very' && $this->acao == 'edita') ? true : false, |
|
|
] |
|
|
], |
|
|
'yes' => [ |
|
|
'label' => 'yes', |
|
|
'attributes' => [ |
|
|
'selected' => ($value_banco == 'yes' && $this->acao == 'edita') ? true : false, |
|
|
] |
|
|
], |
|
|
'no' => [ |
|
|
'label' => 'no', |
|
|
'attributes' => [ |
|
|
'selected' => ($value_banco == 'no' && $this->acao == 'edita') ? true : false, |
|
|
] |
|
|
] |
|
|
] |
|
|
], |
|
|
], |
|
|
]; |
|
|
} |
|
|
|
|
|
public function inputDtmf($title = null, $class_column = 'normal', $name = null, $value_banco = null) |
|
|
{ |
|
|
return [ |
|
|
'tipo-conteudo' => 'normal', |
|
|
'classe-coluna' => $class_column, |
|
|
'formato' => 'select', |
|
|
'titulo' => $title, |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => $name, |
|
|
'id' => $name, |
|
|
'class' => 'selecao', |
|
|
'options' => [ |
|
|
'rfc2833' => [ |
|
|
'label' => 'rfc2833', |
|
|
'attributes' => [ |
|
|
'selected' => ($value_banco == 'rfc2833' && $this->acao == 'edita') ? true : false, |
|
|
], |
|
|
], |
|
|
'inband' => [ |
|
|
'label' => 'inband', |
|
|
'attributes' => [ |
|
|
'selected' => ($value_banco == 'inband' && $this->acao == 'edita') ? true : false |
|
|
], |
|
|
], |
|
|
'info' => [ |
|
|
'label' => 'info', |
|
|
'attributes' => [ |
|
|
'selected' => ($value_banco == 'info' && $this->acao == 'edita') ? true : false |
|
|
], |
|
|
], |
|
|
'auto' => [ |
|
|
'label' => 'auto', |
|
|
'attributes' => [ |
|
|
'selected' => ($value_banco == 'auto' && $this->acao == 'edita') ? true : false |
|
|
], |
|
|
], |
|
|
] |
|
|
], |
|
|
], |
|
|
]; |
|
|
} |
|
|
|
|
|
public function inputTextarea($title = null, $class_column = null, $name = null, $value = null, $cols = '80', $rows = '3') |
|
|
{ |
|
|
return [ |
|
|
'tipo-conteudo' => 'normal', |
|
|
'titulo' => $title, |
|
|
'classe-coluna' => $class_column, |
|
|
'formato' => 'textarea', |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => $name, |
|
|
'cols' => $cols, |
|
|
'style' => 'width:100%', |
|
|
'rows' => $rows, |
|
|
'value' => $value, |
|
|
'min-height' => '95px', |
|
|
] |
|
|
] |
|
|
]; |
|
|
} |
|
|
|
|
|
public function inputButtonSelect( |
|
|
?string $name_include, |
|
|
?string $name_remove, |
|
|
?string $onClick_include, |
|
|
?string $onClick_remove, |
|
|
?string $value_include, |
|
|
?string $value_remove, |
|
|
?string $class = 'toggle', |
|
|
) { |
|
|
return [ |
|
|
'titulo' => '', |
|
|
'classe-coluna' => $class, |
|
|
'tipo-conteudo' => 'normal', |
|
|
'formato' => 'botaoSelect', |
|
|
'propriedades' => [ |
|
|
[ |
|
|
'name' => $name_include, |
|
|
'onClick' => $onClick_include, |
|
|
'style' => 'cursor:pointer', |
|
|
'value' => $value_include, |
|
|
], |
|
|
[ |
|
|
'name' => $name_remove, |
|
|
'onClick' => $onClick_remove, |
|
|
'style' => 'cursor:pointer', |
|
|
'value' => $value_remove, |
|
|
] |
|
|
] |
|
|
]; |
|
|
} |
|
|
|
|
|
public function addRow( |
|
|
?string $style = null, |
|
|
?array $columns = null, |
|
|
) { |
|
|
$linha = [ |
|
|
'estilo-linha' => $style, |
|
|
'coluna' => $columns, |
|
|
]; |
|
|
$this->dados[] = $linha; |
|
|
} |
|
|
|
|
|
public function addCollapse( |
|
|
?string $funcao = null, |
|
|
?string $title = null, |
|
|
) { |
|
|
$id = uniqid(); |
|
|
$linhaCollapse = [ |
|
|
'collapse' => $funcao, |
|
|
'botao-collapse-nome' => $title, |
|
|
'botao-collapse-id' => 'botao-collapse-id' . $id, |
|
|
'div-collapse-id' => 'div-collapse-id' . $id, |
|
|
]; |
|
|
$this->dados[] = $linhaCollapse; |
|
|
} |
|
|
|
|
|
private function formContainsFileUpload($dados) |
|
|
{ |
|
|
foreach ($dados as $linha) { |
|
|
foreach ($linha['coluna'] as $coluna) { |
|
|
foreach ($coluna['propriedades'] as $props) { |
|
|
if (isset($props['type']) && $props['type'] == 'file') { |
|
|
return true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return false; |
|
|
} |
|
|
}
|
|
|
|