* * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo * sob os termos da Licença Pública Geral GNU conforme publicada pela Free * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) * qualquer versão posterior. * * Este programa é distribuí­do na expectativa de que seja útil, porém, SEM * NENHUMA GARANTIA; nem mesmo a garantia implí­cita de COMERCIABILIDADE OU * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral * do GNU para mais detalhes. * * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto * com este programa; se não, escreva para a Free Software Foundation, Inc., no * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. * * @author Prefeitura Municipal de Itajaí * @category i-Educar * @license @@license@@ * @package iEd_Include * @since Arquivo disponível desde a versão 1.0.0 * @version $Id$ */ require_once 'include/clsCampos.inc.php'; if (class_exists('clsPmiajudaPagina')) { require_once 'include/pmiajuda/clsPmiajudaPagina.inc.php'; } require_once 'Portabilis/View/Helper/Application.php'; require_once 'Portabilis/View/Helper/Inputs.php'; require_once 'Portabilis/Utils/User.php'; require_once 'include/localizacaoSistema.php'; /** * clsCadastro class. * * @author Prefeitura Municipal de Itajaí * @category i-Educar * @license @@license@@ * @package iEd_Include * @since Classe disponível desde a versão 1.0.0 * @version @@package_version@@ */ class clsCadastro extends clsCampos { var $__nome = 'formcadastro'; var $banner; var $bannerLateral; var $titulo_barra; var $target = '_self'; var $largura; var $tipoacao; var $campos; var $erros; var $mensagem; var $nome_pai; var $chave; var $item_campo_pai; var $fexcluir; var $excluir_Img; var $nome_excluirImg; var $url_cancelar; var $nome_url_cancelar; var $url_sucesso; var $nome_url_sucesso; var $action; var $script_sucesso; var $script_cancelar; var $script; var $submete = FALSE; var $acao_executa_submit = TRUE; var $executa_submete = FALSE; var $bot_alt = FALSE; var $nome_url_alt; var $url_alt; var $help_images = FALSE; var $locale = null; var $array_botao; var $array_botao_url; var $array_botao_id; var $array_botao_url_script; var $controle; var $acao_enviar ='acao()'; var $botao_enviar = TRUE; var $onSubmit = 'acao()'; var $form_enctype; function addBanner($strBannerUrl = '', $strBannerLateralUrl = '', $strBannerTitulo = '', $boolFechaBanner = TRUE) { if ($strBannerUrl != '') { $this->banner = $strBannerUrl; } if ($strBannerLateralUrl != '') { $this->bannerLateral = $strBannerLateralUrl; } if ($strBannerTitulo != '') { $this->titulo_barra = $strBannerTitulo; } $this->bannerClose = $boolFechaBanner; } function clsCadastro() { parent::__construct(); $this->tipoacao = @$_POST['tipoacao']; } function enviaLocalizacao($localizao){ if($localizao) $this->locale = $localizao; } function PreCadastrar() { } function Processar() { $this->excluir = @$_GET['excluir']; if ($this->excluir) { $this->tipoacao = "Excluir"; } if (empty($this->tipoacao)) { $this->tipoacao = $this->Inicializar(); $this->Formular(); } else { reset($_POST); while (list($variavel, $valor) = each($_POST)) { $this->$variavel = $valor; } reset($_FILES); while (list($variavel, $valor) = each($_FILES)) { $this->$variavel = $valor; } // Realiza cadastro $this->PreCadastrar(); $sucesso = FALSE; if ($this->tipoacao == 'Novo') { $sucesso = $this->Novo(); if ($sucesso && !empty($this->script_sucesso)) { $this->script = ""; } if (!$sucesso && empty($this->erros) && empty($this->mensagem)) { $this->mensagem = "Não foi possível inserir a informação. [CAD01]"; } } elseif ($this->tipoacao == 'Editar') { $sucesso = $this->Editar(); if (!$sucesso && empty($this->erros) && empty($this->mensagem)) { $this->mensagem = "Não foi possível editar a informação. [CAD02]"; } } elseif ($this->tipoacao == 'Excluir') { $sucesso = $this->Excluir(); if (!$sucesso && empty($this->erros) && empty($this->mensagem)) { $this->mensagem = "Não foi possível excluir a informação. [CAD03]"; } } elseif ($this->tipoacao == 'ExcluirImg') { $sucesso = $this->ExcluirImg(); if (!$sucesso && empty( $this->erros ) && empty( $this->mensagem )) { $this->mensagem = "Não foi possível excluir a informação. [CAD04]"; } } if (empty($script) && $sucesso && !empty($this->url_sucesso)) { redirecionar( $this->url_sucesso ); } else { $this->Formular(); } } } function Inicializar() { } function Formular() { } function Novo() { return FALSE; } function Editar() { return FALSE; } function Excluir() { return FALSE; } function ExcluirImg() { return FALSE; } function Gerar() { return FALSE; } protected function flashMessage() { if (empty($this->mensagem) && isset($_GET['mensagem']) && $_GET['mensagem'] == 'sucesso') { $this->mensagem = 'Registro incluido com sucesso!'; } return empty($this->mensagem) ? "" : "

$this->mensagem

"; } function RenderHTML() { $this->_preRender(); $this->bannerLateral = 'imagens/nvp_vert_intranet.jpg'; $this->titulo_barra = 'Intranet'; $this->Processar(); $retorno = ''; if ($this->banner) { $retorno .= ""; $retorno .= ""; $flashMessage = $this->flashMessage(); if (! empty($flashMessage)) { $retorno .= ""; } if (empty($this->campos)) { $retorno .= ""; } else { // Verifica se houve erros no controller $retorno .= $this->_getControllerErrors(); $retorno .= $this->MakeCampos(); } $retorno .= "\n\n"; $retorno .= "
bannerLateral}\" align=\"right\" border=\"0\" alt=\"$this->titulo_barra\" title=\"$this->titulo_barra\">"; } $this->Gerar(); $script = explode("/", $_SERVER["PHP_SELF"]); $script = $script[count($script)-1]; $this->nome_excluirImg = empty( $this->nome_excluirImg ) ? "Excluir Imagem" : $this->nome_excluirImg; $this->nome_url_cancelar = empty( $this->nome_url_cancelar ) ? "Cancelar" : $this->nome_url_cancelar; $this->nome_url_sucesso = empty( $this->nome_url_sucesso ) ? "Salvar" : $this->nome_url_sucesso; $width = empty($this->largura) ? "width='100%'" : "width='$this->largura'"; $retorno .= "\n\n"; $retorno .= "
form_enctype>\n"; $retorno .= "\n"; $retorno .= ""; if ($this->campos) { reset($this->campos); while (list($nome, $componente) = each($this->campos)) { if ($componente[0] == 'oculto' || $componente[0] == 'rotulo') { $retorno .= "\n"; } } } if ($this->locale){ $retorno .= " "; $retorno .= ""; $retorno .= "
{$this->locale}
"; } $retorno .= "
\n\n"; $titulo = $this->titulo ? $this->titulo : "{$this->tipoacao} {$this->titulo_aplication}"; /** * Adiciona os botoes de help para a pagina atual */ $url = parse_url($_SERVER['REQUEST_URI']); $url = preg_match('^/', '', $url['path']); if (strpos($url, '_det.php') !== FALSE) { $tipo = 'det'; } elseif(strpos($url,'_lst.php') !== FALSE) { $tipo = 'lst'; } elseif(strpos($url,'_pdf.php') !== FALSE) { $tipo = 'pdf'; } else { $tipo = 'cad'; } $barra = $titulo; // @todo Remover código, funcionalidade não existente. if (class_exists('clsPmiajudaPagina')) { $ajudaPagina = new clsPmiajudaPagina(); $lista = $ajudaPagina->lista(null,null,$url); if ($lista) { $barra = "
\"Botão {$titulo} \"Botão
"; } } $retorno .= "
{$barra}
{$flashMessage}
Não existe informação disponível
\n"; if ($this->acao_enviar && $this->botao_enviar) { $retorno .= "  "; } if ($this->fexcluir) { $retorno .= "  "; } if ($this->bot_alt) { $retorno .= "  "; } if ($this->excluir_Img) { $retorno .= "  "; } if ($this->acao) { $retorno .= "  "; } if ($this->url_cancelar || $this->script_cancelar) { $retorno .= "  "; } if ($this->array_botao_url) { for ($i = 0; $i < count($this->array_botao); $i++) { if($this->array_botao_id[$i]) { $retorno .= " array_botao_id[$i]}\"> "; } else { $retorno .= " array_botao[$i]}\"> "; } } } elseif ($this->array_botao_url_script) { for ($i = 0; $i < count($this->array_botao); $i++) { if ($this->array_botao_id[$i]) { $id = $this->array_botao_id[$i]; $retorno .= " array_botao_url_script[$i]."\" value=\"".$this->array_botao[$i]."\" id=\"{$id}\"> \n"; } else { $id = $this->array_botao[$i]; $retorno .= " array_botao_url_script[$i]."\" value=\"".$this->array_botao[$i]."\" id=\"arr_bot_{$id}\"> \n"; } } } $retorno .= "
\n\n\n"; $retorno .= "\n"; if ($this->bannerClose) { $retorno .= ""; } if ($this->executa_script) { $retorno .= ""; } Portabilis_View_Helper_Application::embedJavascriptToFixupFieldsWidth($this); return $retorno; } function isNullNow() { $args = func_get_args(); foreach ($args as $ind => $arg) { if (empty($arg)) { $args[$ind] = 'NULL'; } } return ($args); } function isOnNow() { $args = func_get_args(); foreach ($args as $ind => $arg) { $args[$ind] = $arg == 'on' ? 1 : 0; } return ($args); } /** * Retorna uma lista formatada de erros que possam ter sido lançadas pela * integração CoreExt_Controller_Page_Interface com CoreExt_DataMapper e * CoreExt_Entity. * * @return string|NULL */ protected function _getControllerErrors() { try { $hasErrors = $this->hasErrors(); } catch (Core_Controller_Page_Exception $e) { return NULL; } // Verifica se houve erros if ($hasErrors) { $htmlError = '

Por favor, verifique a lista de erros e corrija as informações necessárias no formulário.

    %s
'; $errors = ''; foreach ($this->getErrors() as $key => $error) { if (!is_null($error)) { $errors .= sprintf('
  • %s: %s
  • %s', $this->_getEntityLabel($key), $error, PHP_EOL); } } return sprintf($htmlError, $errors); } return NULL; } protected function inputsHelper() { if (! isset($this->_inputsHelper)) $this->_inputsHelper = new Portabilis_View_Helper_Inputs($this); return $this->_inputsHelper; } protected function currentUserId() { return Portabilis_Utils_User::currentUserId(); } }