Conn2Flow
Docs navigation

Reference / Libraries

interface.php library

The CRUD engine of the admin modules: the start/finish cycle per option, Tailwind or DataTables listing according to framework, forms, validation, history, field backups, alerts and the Tailwind component variants.

Path in the Gestor bibliotecas/interface.php

interface.php is the admin panel's CRUD engine. An admin module does not build listing, editing and deletion screens by hand: it states what it wants (table, columns, fields, validations, buttons), and the library draws the screen from components (interface-listar, interface-formulario-edicao…), records history, handles the standard AJAX calls and fires the hooks.

Request the library in the module JSON ("bibliotecas": ["interface", …]).

A module's cycle

Every module controller follows the same skeleton:

function my_module_start(){
    global $_GESTOR;
    gestor_incluir_bibliotecas();
    if($_GESTOR['ajax']){
        interface_ajax_iniciar();
        switch($_GESTOR['ajax-opcao']){ /* the module's own AJAX */ }
        interface_ajax_finalizar();          // standard AJAX: list, history, backup, verify-field
    } else {
        my_module_interfaces_padroes();      // fills $_GESTOR['interface'][<option>]
        interface_iniciar();
        switch($_GESTOR['opcao']){
            case 'adicionar': my_module_add(); break;
            case 'editar':    my_module_edit(); break;
        }
        interface_finalizar();
    }
}
  • interface_iniciar() runs before the module code. It reads $_GESTOR['opcao'] (and $_GESTOR['interface-opcao'] when present), calls the matching interface_<option>_iniciar() with the parameters in $_GESTOR['interface'][<option>]['iniciar'] and sets the flags the module checks:

    • $_GESTOR['adicionar-banco'] when the add form was submitted (_gestor-adicionar);

    • $_GESTOR['atualizar-banco'] when the edit form was submitted (_gestor-atualizar);

    • $_GESTOR['modulo-registro-id'] with the record id (?id= on GET, or _gestor-registro-id). Without an id on options that need one, it redirects to the module root.

  • interface_finalizar() runs afterwards. It calls interface_<option>_finalizar() with $_GESTOR['interface'][<option>]['finalizar'], which draws the screen into $_GESTOR['pagina'], then prints the pending alert and renders the marked components.

  • With $_GESTOR['interface-nao-aplicar'], both do nothing.

Options

opcao / interface-opcao What the finisher does
listar Paginated table (Tailwind; DataTables in the classic variant) with search, sorting, per-row actions and a delete modal
adicionar, clonar Add form (interface-formulario-inclusao). clonar requires id and starts from the existing record
editar Edit form (interface-formulario-edicao, with a Tailwind variant), metadata and history
visualizar Read-only screen (interface-formulario-visualizacao)
status Changes the record's status (?id=…&status=A|I), increments versao, records history
excluir Soft delete: status='D', versao+1, history and redirect
config The module's configuration screen, without a record (interface-formulario-configuracoes)
alteracoes, simples, adicionar-incomum, editar-incomum Only via interface-opcao: variations for screens that do not follow the standard CRUD

The handlers of each option:

Option Start Finish
listar interface_listar_iniciar() (empty) interface_listar_finalizar()
adicionar interface_adicionar_iniciar() interface_adicionar_finalizar()
clonar interface_clonar_iniciar() (accepts forcarId) interface_adicionar_finalizar()
editar interface_editar_iniciar() (accepts forcarId) interface_editar_finalizar()
visualizar interface_visualizar_iniciar() interface_visualizar_finalizar()
status interface_status_iniciar() (requires id and status on GET) interface_status_finalizar()
excluir interface_excluir_iniciar() (requires id on GET) interface_excluir_finalizar()
config interface_config_iniciar() interface_config_finalizar()
alteracoes interface_alteracoes_iniciar() (falls back to modulo-registro-padrao-id without id) interface_alteracoes_finalizar()
simples interface_simples_iniciar() interface_simples_finalizar()
adicionar-incomum interface_adicionar_incomum_iniciar() interface_adicionar_incomum_finalizar()
editar-incomum interface_editar_incomum_iniciar() interface_editar_incomum_finalizar()

Hooks fired

For module X and option O (and also for the interface-opcao):

  • hook_do_action('X', 'O.pre-banco') on every POST, before the module code;

  • O.parametros on GET, before the finisher;

  • O.pagina on GET, after the finisher;

  • excluir.banco (with the id) after deletion, and status.banco (with id and new status) after a status change.

See the hooks doc to register listeners.

Finisher parameters

The form finishers (adicionar, editar, visualizar, config, alteracoes, simples, *-incomum) accept, depending on the case:

Parameter Effect
formulario ['validacao' => [...], 'campos' => [...], 'opcao' => …]: client-side validation and generated fields (below)
botoes Header buttons: [id => ['url','rotulo','tooltip','icon','cor', 'callback'?]]
botoes_rodape Extra buttons at the bottom of the form, same format
sem_botao_padrao Removes the default submit button
metaDados List [['titulo' => …, 'dado' => …]] shown next to the form
removerNaoAlterarId / removerBotaoEditar Remove the "do not change id" checkbox and the edit button
variaveisTrocarDepois ['key' => 'value'] replaced as #key# at the end of the build
campoTitulo / forcarSemID visualizar: field used in the title, or no record at all
banco, historico, callbackFunction status/excluir: another table, no history, and a function called after writing

Forms automatically replace every #form-…# in the HTML with the module variables whose id contains form (gestor_variaveis(['conjunto' => true, 'padrao' => 'form'])).

Listing

$_GESTOR['interface']['listar']['finalizar'] = Array(
    'banco' => Array(
        'nome' => 'paginas', 'id' => 'id', 'status' => 'status',
        'campos' => Array('nome', 'caminho', 'data_modificacao'),
        'where' => "language='".$_GESTOR['linguagem-codigo']."'",
    ),
    'tabela' => Array(
        'rodape' => true,
        'colunas' => Array(
            Array('id' => 'nome', 'nome' => 'Name', 'ordenar' => 'asc'),
            Array('id' => 'data_modificacao', 'nome' => 'Modified', 'formatar' => 'dataHora', 'nao_procurar' => true),
        ),
    ),
    'opcoes' => Array(
        'editar' => Array('url' => 'editar/', 'tooltip' => '…', 'icon' => 'edit', 'cor' => 'basic blue'),
        'excluir' => Array('opcao' => 'excluir', 'tooltip' => '…', 'icon' => 'trash', 'cor' => 'basic red'),
    ),
    'botoes' => Array( /* "Add" button etc. */ ),
);
  • interface_listar_finalizar() draws the interface-listar layout and the interface-delecao-modal modal, and includes DataTables. interface_listar_tabela() builds the first page on the server and publishes the configuration in javascript-vars.interface.lista.

  • The actions column is the first one (req-147) and uses its own key (INTERFACE_COLUNA_ACOES), so that button ids never come from a formatted column.

  • Columns: ordenar (asc/desc), nao_ordenar, nao_procurar, nao_visivel, className and formatar (see Formatting).

  • Records with status='D' never show up. The current page, total and page size live in a per-user session variable (<module>-<option>-interface-<user>), which later AJAX calls use.

  • Subsequent pagination, search and sorting come via AJAX (ajax-opcao=listar) in interface_ajax_listar() → interface_listar_ajax(). The search runs UCASE(column) LIKE UCASE('%term%') on each searchable column and on columnsExtraSearch (id by default). Columns, sorting and extra columns come only from the configuration stored in the session by the server; the columns sent by DataTables is used just as an index, a column name must be a plain identifier (interface_listar_coluna_segura()) and the term is escaped, with % and _ treated as text (req-189).

Forms

Generated fields (formulario.campos)

interface_formulario_campos() inserts each field into the page's <span>#<id>#</span> marker, according to its tipo:

tipo Generates
select A Fomantic <select> from tabela (nome, campo, id_numerico or id, where, id_selecionado/valor_selecionado) or from dados ([['texto','valor','icone'?]]). Options: menu, procurar, limpar, multiple, fluid, disabled, placeholder and icons
imagepick / imagepick-hosts Image picker from the file manager (id_arquivos/id_hosts_arquivos)
templates-hosts Template picker by categoria_id (template_id, template_tipo gestor/hosts)

Browser validation (formulario.validacao)

interface_formulario_validacao() publishes rules for the Fomantic/Tailwind validator. Each item is ['regra', 'campo', 'label', 'identificador'?], and the rules are:

  • texto-obrigatorio (3 to 255 characters) and texto-obrigatorio-verificar-campo (which also checks whether the value already exists);

  • selecao-obrigatorio, nao-vazio, maior-ou-igual-a-zero;

  • email, email-comparacao, email-comparacao-verificar-campo;

  • senha, senha-comparacao, dominio;

  • regexPermited and regexNecessary, with regrasExtra for custom regexes.

removerRegra drops default rules.

Server validation

interface_validacao_campos_obrigatorios(['campos' => [...], 'redirect' => …]) checks $_REQUEST before saving. On the first failure it stores an alert and redirects (to redirect, or reloads the URL), ending the request.

Rule Checks
texto-obrigatorio Length between min (default 3) and max (default 255), in bytes (strlen)
selecao-obrigatorio Field is filled in
email-obrigatorio Its own e-mail regex
  • interface_verificar_campos(['campo', 'valor', 'language'?]) tells whether another active record already holds that value. When editing it ignores the record itself, and it can look into another table via verificarCamposOutraTabela in the module JSON. This is what the verificar-campo AJAX (interface_ajax_verificar_campo()) uses. The function's docblock describes other parameters; the real ones are these.

History

  • interface_historico_incluir(['alteracoes' => [['campo','alteracao','alteracao_txt','valor_antes','valor_depois','tabela','filtro']], …]) stores in the historico table who changed what, linked to the module and the record. It accepts deletar (counts the next version), sem_id, versao, an alternative tabela and manual ids (id_numerico_manual, id_usuarios_manual, id_hosts_manual, modulo_id).

  • interface_historico(['id','modulo','pagina','sem_id'?]) draws the paginated history on the edit screen. interface_ajax_historico_mais_resultados() loads the next pages.

CRUDs use the banco_select_campos_antes_iniciar()/banco_select_campos_antes() pair to know the "before" (see banco.php).

Field backups

For long fields (HTML, CSS), each version can be kept and restored:

  • interface_backup_campo_incluir(['campo','id_numerico','versao','valor','modulo'?,'maxCopias'?]) stores the version and deletes the oldest ones beyond maxCopias;

  • interface_backup_campo_select([...]) draws the version dropdown;

  • interface_ajax_backup_campo() returns the chosen value.

Alerts

interface_alerta(['msg' => …]) schedules a message for the screen. With redirect, it survives the next redirect (it is kept in the session). interface_finalizar() calls interface_alerta(['imprimir' => true]), which publishes the alert in javascript-vars.interface.alert and includes modal-alerta.

Data formatting

interface_formatar_dado(['dado' => …, 'formato' => …]) is used by the listing's formatar columns. The formats are:

  • data and dataHora: DD/MM/YYYY and DD/MM/YYYY HHhMM;

  • dinheiroReais and dinheiroUSD;

  • telefone;

  • outraTabela: replaces the id with a name from another table, through interface_trocar_valor_outra_tabela();

  • outroConjunto and outroArray: replace through a map (interface_trocar_valor_outro_conjunto() and interface_trocar_valor_outro_array());

  • encapsular: wraps the value in a text, through interface_encapsular_valor().

formato may also be a list, applied in sequence, with valor_senao_existe and valor_substituir_por_rotulo.

The formatting helpers:

  • interface_data_hora_from_datetime_to_text($dt, $format = false) uses the D/ME/A HhMI format by default (D, ME, A, H, MI and S are replaced by the date parts);

  • interface_data_from_datetime_to_text($dt) returns DD/MM/YYYY;

  • interface_formatar_telefone($phone) formats Brazilian numbers with and without +55 and the North American +1 pattern; anything else just gets a leading +.

Components and assets

  • interface_componentes_incluir(['componente' => [...]]) marks components (loading, delete and alert modals…), and interface_componentes() renders them at the end of the page, in the right variant.

  • interface_componente_variante($id) returns <id>-tailwind on a Tailwind-only request; interface_componente_canonico($id) strips the suffix. That way the same module serves Fomantic and Tailwind without code changes (req-118).

  • interface_assets_incluir() includes interface/interface-tailwind.js (pure Tailwind) or interface/interface.css + interface/interface.js (Fomantic/hybrid).

  • interface_botoes_cabecalho() and interface_botoes_rodape() draw the buttons from botoes/botoes_rodape, through interface_botoes_html($botoes). On a Tailwind-only page they output <a>/<button> with utilities and a Lucide icon (req-190): interface_botao_tailwind_classes($cor) maps the Fomantic color (blue, green, red, basic …) to one of four tones, and interface_botao_tailwind_icone($icone) maps the icon name (with no match, the button keeps only its label). excluir carries the URL in data-href and opens the delete modal. The classes live in the <template data-c2f-botoes> of the interface-formulario-*-tailwind components; a new class in the PHP must be added there too, or it renders unstyled. Add and edit have a Tailwind variant; the listing is still Fomantic.

  • interface_modulo_variavel_valor(['variavel' => …]) reads a field of the module's current record (used to build the "Name - …" title).

Security and known defects

Delete and status require the CSRF token. These two actions run on GET (?opcao=excluir&id=…, ?opcao=status&status=I&id=…), and the global CSRF check only covers POST/PUT/PATCH/DELETE. So interface_excluir_iniciar() and interface_status_iniciar() call interface_acao_get_exigir_csrf(), which requires the session token in the query (_csrf_token); without it they show an alert and go back to the module root without changing anything (req-189). Panel links already carry the token: interface_url_csrf($url) on buttons rendered by the server and window.interfaceUrlCsrf(url) on links built by interface.js/interface-v2.js. A delete or status link built by hand in a module must go through one of them.

Other defects: interface_editar_finalizar() and interface_alteracoes_finalizar() pass 'id' => $id to the history without defining $id (undefined variable warning). It has no effect on the result, because interface_historico() ignores that parameter and filters by the current record's id_numerico.

See also

Functions (generated reference)

Generated from gestor/bibliotecas/interface.php · 65 functions

65 of 65

interface_data_hora_from_datetime_to_text

view source · line 38 ↗
interface_data_hora_from_datetime_to_text(string $data_hora, string|false $format = false): string

Converte data/hora do formato datetime (YYYY-MM-DD HH:MM:SS) para texto formatado.

Parameters

$data_horastring
Data/hora no formato datetime (YYYY-MM-DD HH:MM:SS)
$formatstring|false
Formato personalizado usando marcadores ou false para formato padrão

Returns

string
Data/hora formatada ou string vazia se não houver data

interface_data_from_datetime_to_text

view source · line 91 ↗
interface_data_from_datetime_to_text(string $data_hora): string

Converte data do formato datetime (YYYY-MM-DD) para texto no formato brasileiro (DD/MM/YYYY).

Parameters

$data_horastring
Data/hora no formato datetime (YYYY-MM-DD HH:MM:SS)

Returns

string
Data formatada (DD/MM/YYYY)

interface_trocar_valor_outra_tabela

view source · line 122 ↗
interface_trocar_valor_outra_tabela(array|false $params = false): string|array

Busca e substitui valores de um campo usando referência de outra tabela.

Parameters

$paramsarray|false
Parâmetros da função:

Returns

string|array
Valor trocado, array de valores (se camposExtras) ou resultado encapsulado

interface_trocar_valor_outro_conjunto

view source · line 260 ↗
interface_trocar_valor_outro_conjunto(array|false $params = false): string

Troca um valor por outro baseado em um conjunto de mapeamentos.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

string
O valor trocado se encontrado no conjunto, ou o dado original caso contrário.

interface_trocar_valor_outro_array

view source · line 296 ↗
interface_trocar_valor_outro_array(array|false $params = false): string

Troca um valor por outro baseado em array de valores com campos específicos.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

string
O valor do campo alvo se encontrado, ou o dado original caso contrário.

interface_encapsular_valor

view source · line 331 ↗
interface_encapsular_valor(array|false $params = false): string

Encapsula um valor dentro de uma cápsula de texto.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

string
O valor encapsulado se encontrado, ou o dado original caso contrário.

interface_formatar_telefone

view source · line 356 ↗
interface_formatar_telefone(string $telefone): string

Formata um número de telefone para exibição.

Parameters

$telefonestring
Número de telefone (pode conter +, espaços, hífens, parênteses).

Returns

string
Telefone formatado ou valor original se não for possível formatar.

interface_formatar_dado

view source · line 437 ↗
interface_formatar_dado(array|false $params = false): string

Formata um dado de acordo com o formato especificado.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

string
O dado formatado de acordo com as especificações, ou valor padrão se dado estiver vazio.

interface_alerta

view source · line 548 ↗
interface_alerta(array|false $params = false): void|string

Gerencia alertas de mensagens para o usuário na interface.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

void|string
Retorna HTML do alerta se $imprimir for true, caso contrário não retorna nada.

interface_historico

view source · line 766 ↗
interface_historico(array|false $params = false): void

Exibe o histórico de alterações de um registro do sistema.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

void
Exibe o HTML do histórico diretamente.

interface_componente_variante

view source · line 1235 ↗
interface_componente_variante(string $id, string|null $modo = null): string

Devolve o id da variante Tailwind de um componente quando a requisição é Tailwind pura.

Parameters

$idstring
Id canônico do componente.
$modostring|null
Modo resolvido; quando omitido, usa o da requisição corrente.

Returns

string
Id a carregar.

interface_status_selo

view source · line 1270 ↗
interface_status_selo(string $status): string

Selo de status (ativo/inativo) dos metadados da tela de edição (req-219).

Parameters

$statusstring
'A' (ativo) ou 'I' (inativo); outro valor devolve string vazia.

Returns

string
HTML do selo.

interface_backup_campo_select

view source · line 3057 ↗
interface_backup_campo_select(array|false $params = false): void

Renderiza dropdown de seleção de versões de backup de um campo.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

void
Renderiza HTML do dropdown diretamente.

interface_verificar_campos

view source · line 3180 ↗
interface_verificar_campos(array|false $params = false): array

Verifica alterações em campos comparando valores atuais com valores anteriores.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

array
Lista de campos que foram alterados.

interface_botoes_cabecalho

view source · line 3247 ↗
interface_botoes_cabecalho(array|false $params = false): void

Renderiza botões de ação no cabeçalho da interface administrativa.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

void
Renderiza HTML dos botões diretamente.

interface_botoes_rodape

view source · line 3266 ↗
interface_botoes_rodape(array|false $params = false): string

Renderiza botões de ação no rodapé da interface administrativa.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

string
HTML dos botões do rodapé.

interface_botoes_html

view source · line 3285 ↗
interface_botoes_html(array $botoes): string

Monta o HTML de um conjunto de botões (cabeçalho ou rodapé), no framework CSS da página.

Parameters

$botoesarray
Botões por id: cor, icon, icon2, rotulo, tooltip, url, callback, target.

Returns

string
HTML dos botões.

interface_botao_tailwind_icone

view source · line 3377 ↗
interface_botao_tailwind_icone(string $icone): string

Traduz o nome de ícone do Fomantic para o equivalente do Lucide (carregado pelo layout Tailwind).

Parameters

$iconestring
Nome do ícone no Fomantic.

Returns

string
Nome no Lucide ou ''.

interface_ajax_backup_campo

view source · line 3466 ↗
interface_ajax_backup_campo(array|false $params = false): void

Processa requisição AJAX para restaurar backup de campo.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

void
Define $_GESTOR['ajax-json'] com o valor do campo.

interface_acao_get_exigir_csrf

view source · line 3668 ↗
interface_acao_get_exigir_csrf()

req-189 (A2): excluir e status agem por GET (?opcao=excluir&id=…), e a validação global de CSRF só cobre POST/PUT/PATCH/DELETE. Com o cookie SameSite=Lax, um link aberto por um administrador logado bastava para excluir ou desativar registros. Essas ações passam a exigir o token da sessão na query (_csrf_token); os links do painel já saem com ele (interface_url_csrf() e window.interfaceUrlCsrf). Sem o token: alerta e volta à raiz do módulo, sem alterar nada.

interface_excluir_finalizar

view source · line 3723 ↗
interface_excluir_finalizar(array|false $params = false): void

Finaliza a interface de exclusão de registro (exclusão lógica).

Parameters

$paramsarray|false
Parâmetros da função.

Returns

void
Executa exclusão e redireciona para listagem.

interface_status_iniciar

view source · line 3839 ↗
interface_status_iniciar(array|false $params = false): void

Inicializa a interface de alteração de status de registro.

Parameters

$paramsarray|false
Parâmetros da função (não utilizado nesta função).

Returns

void
Prepara $_GESTOR para alteração de status ou redireciona.

interface_status_finalizar

view source · line 3875 ↗
interface_status_finalizar(array|false $params = false): void

Finaliza a interface de alteração de status de registro.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

void
Executa alteração de status e redireciona para listagem.

interface_listar_coluna_segura

view source · line 5229 ↗
interface_listar_coluna_segura(string $coluna): bool

Nome de coluna aceito em ORDER BY/WHERE da listagem: identificador simples (nome, t.nome), nunca a coluna de ações nem expressão. req-189 (A1).

Parameters

$colunastring

Returns

bool

Tailwind panel lists and status

Tailwind lists delegate to interface-listar-tailwind.php and its script, using server paging/ordering without DataTables. The classic variant retains DataTables. interface_status_selo accepts A/I and returns an active/inactive Tailwind badge; other values return empty. Forms and view pages choose component variants by effective framework. See Administrative interface.

The Future is Hybrid: Human + AI.

Conn2Flow is the tool. If you need the Architect to design your company's strategy using this technology...

Hire Specialized Consulting