Código de: api/setup.php


<?
# Variáveis
$ID $_POST['ID'] == 'false' false $_POST['ID'];
$tabela $_POST['tabela'];
$acao $_POST['acao'];
$nome $_POST['nome'];



# EDITAR
if ($acao == 'editar' AND $ID AND $nome and $tabela) {
    
$data = array(
        
'nome' => $nome,
        
'entidade' => $AUTH->entidade->id,
    );
    if ( 
$ID $IMAGEM->setSetup($tabela$ID$data) ) {
        
$return = array(
            
'success' => true,
            
'ID' => $ID,
            
'msg' => 'Atualizado com sucesso!',
            
'reset' => 'form',
            
'mtipo' => 'info',
        );

    } else {
        
$return = array(
            
'success' => false,
            
'msg' => 'Não foi possível confirmar algumas informações. Atualize a página e tente novamente.',
            
'mtipo' => 'error',
        );
    }


# EDITAR
} else if ($acao == 'novo' AND $nome) {
    
$data = array(
        
'nome' => $nome,
        
'entidade' => $AUTH->entidade->id,
    );
    if ( 
$ID $IMAGEM->addSetup($tabela$ID$data) ) {
        
$return = array(
            
'success' => true,
            
'ID' => $ID,
            
'msg' => 'Cadastrado com sucesso!',
            
'reset' => 'form',
            
'mtipo' => 'info',
        );

    } else {
        
$return = array(
            
'success' => false,
            
'msg' => 'Não foi possível confirmar algumas informações. Atualize a página e tente novamente.',
            
'mtipo' => 'error',
        );
    }


# DELETAR
} else if ($acao == 'deletar' AND $ID) {

    if ( 
$ID $IMAGEM->delSetup($tabela$ID) ) {
        
$return = array(
            
'success' => true,
            
'ID' => $ID,
            
'msg' => 'Excluido com sucesso!',
            
'reset' => 'form',
            
'mtipo' => 'info',
        );
        if(
$tabela == 'grupos') {
            
$return['msg'] .= ' Sua página será atualizada.';
            
$return['href'] = 'reload';
        }

    } else {
        
$return = array(
            
'success' => false,
            
'msg' => 'Não foi possível confirmar algumas informações. Atualize a página e tente novamente.',
            
'mtipo' => 'error',
        );
    }



} else {

    
$return = array(
        
'success' => false,
        
'msg' => 'Dados inválidos. Atualize a página e tente novamente.',
        
'mtipo' => 'error',
    );
}

header("Content-Type: application/json; charset=utf-8");
echo 
json_encode($return);