Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * classe ServidorFormFoto
- * Cadastro de Servidor: Contem o formularo da Foto
- */
- ini_set('display_errors', 1);
- ini_set('display_startup_erros', 1);
- error_reporting(E_ALL);
- class ServidorFormFoto extends TPage {
- private $form; // formulario de cadastro
- /*
- * metodo construtor
- * Cria a pagina do formulario
- */
- public function __construct() {
- parent::__construct();
- // instancia um formulario
- // creates the form
- $this->form = new TForm('form_Servidor');
- //$this->form = new TQuickForm;
- // $this->form->setEnctype("multipart/form-data");
- $this->form->class = 'form_Servidor_foto';
- $table = new TTable;
- $table->width = '100%';
- $table_buttons = new TTable;
- // add the table inside the form
- $this->form->add($table);
- // creates a label with the title
- $titulo = new TLabel('Formulario Servidor');
- $titulo->setFontSize(18);
- $titulo->setFontFace('Arial');
- $titulo->setFontColor('red');
- // cria os campos do formulario
- $id = new THidden('servidor_id');
- $id->setValue(filter_input(INPUT_GET, 'fk'));
- $foto = new TFile('foto');
- $foto->setProperty("accept", "image/jpg");
- $usuarioalteracao = new THidden('usuarioalteracao');
- $dataalteracao = new THidden('dataalteracao');
- //cria a colecao da tabela estrangeira do Cabecalho
- // inicia transacao com o banco 'pg_ceres'
- TTransaction::open('pg_ceres');
- // instancia objeto da Classe Record
- $cadastro = new ServidorRecord(filter_input(INPUT_GET, 'fk'));
- // cria um criterio de selecao, ordenado pelo id do servidor
- //adiciona os objetos na tela com as informacoes do servidor
- if ($cadastro) {
- $nome = new TLabel($cadastro->nome);
- $matricula = new TLabel($cadastro->matricula);
- }
- // finaliza a transacao
- TTransaction::close();
- // define os tamanhos dos campos
- $foto->setSize(400);
- // add the form fields
- ################ Pagina 01 - Dados Pessoais ################
- $table->addRowSet('', $id);
- $table->addRowSet('', $usuarioalteracao);
- $table->addRowSet('', $dataalteracao);
- // adiciona campos
- $table->addRowSet('', $titulo);
- $table->addRowSet(new TLabel('Matricula:'), $matricula);
- $table->addRowSet("<b>Nome <font color=red>*</font></b>", $nome);
- $table->addRowSet(new TLabel('Foto'), $foto);
- //mostra a foto do servidor se o metodo eh onEdit
- if (filter_input(INPUT_GET, 'method') == 'onEdit') {
- $foto2 = new TImage('app/images/servidor/servidor_' . filter_input(INPUT_GET, 'fk') . '.jpg', 'foto', 150, 150);
- $table->addRowSet('', $foto2);
- }
- //Define o auto-sugerir
- $nome->setProperty('placeholder', 'Informe o Nome');
- // create an action button (save)
- $save_button = new TButton('save');
- // create an action servidor (save)
- $action = new TAction(array($this, 'onSave'));
- $action->setParameter('fk', '' . filter_input(INPUT_GET, 'fk') . '');
- $save_button->setAction($action, 'Save');
- $save_button->setImage('ico_save.png');
- // create an action button (new)
- $new_button = new TButton('list');
- $new_button->setAction(new TAction(array("ServidorList", 'onReload')), 'Voltar');
- $new_button->setImage('ico_datagrid.png');
- // add a row for the form action
- $row = $table_buttons->addRow();
- $row->addCell($save_button);
- $row->addCell($new_button);
- // add a row for the form action
- $row = $table->addRow();
- $row->class = 'tformaction';
- $cell = $row->addCell($table_buttons);
- $cell->colspan = 2;
- // define wich are the form fields
- $this->form->setFields(array($id, $foto, $save_button, $new_button));
- // wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->add($this->form);
- parent::add($vbox);
- }
- /*
- * metodo onSave()
- * Executada quando o usuario clicar no botao salvar do formulario
- */
- function onSave() {
- // $arqtmp = $_FILES["foto"]["tmp_name"];
- $servidor_id = $_REQUEST['servidor_id'];
- $foto = $_REQUEST['foto'];
- $msg = "";
- ############ Exemplo 01 ############
- // have attachments
- if ($foto) {
- $nome_foto = 'servidor_' . $servidor_id;
- $target_folder = 'app/images/servidor/';
- $target_file = $target_folder . '/' . $foto;
- @mkdir($target_folder);
- rename('app/images/servidor/' . $nome_foto, $target_file);
- $msg = 'OK';
- }
- ############ Exemplo 02 ############
- /* Defina aqui o tamanho maximo do arquivo em bytes: */
- if ($_FILES['foto']['size'] > 1024000) {
- $msg = "O Arquvio deve no maximo 1Mb";
- } else {
- /* Defina aqui o diretorio destino do upload */
- if (!empty($_FILES['foto']['tmp_name']) and is_file($_FILES['foto']['tmp_name'])) {
- $caminho = 'app/images/servidor/servidor_' . $servidor_id . '.jpg';
- /* Defina aqui o tipo de arquivo suportado */
- if (eregi(".jpg$", $_FILES['foto']['name'])) {
- copy($_FILES['foto']['tmp_name'], $caminho);
- $msg = 'OK';
- } else {
- $msg = 'Apenas aquivo do tipo JPG';
- }
- } else {
- $msg = 'Caminho ou nome de arquivo Invalido!';
- }
- }
- // exibe um dialogo ao usuario
- //$msg = 'Dados armazenados com sucesso';
- if ($msg == 'OK') {
- new TMessage("info", "Registro salvo com sucesso!");
- TApplication::gotoPage('ServidorList', 'onReload'); // reload
- } else {
- new TMessage("error", "Erro ao salvar a foto!");
- }
- }
- /*
- * metodo onEdit()
- * Edita os dados de um registro
- */
- function onEdit($param) {
- try {
- if (isset($param['key'])) {
- // get the parameter $key
- $key = $param['key'];
- TTransaction::open('pg_ceres'); // open a transaction with database 'samples'
- $object = new ServidorRecord($key); // instantiates object Servidor
- //$fotoimg = new TImage('app.img/servidor/servidor_'.$key.'.jpg','foto',50,50);
- //$this->form->add($fotoimg);
- $this->form->setData($object); // fill the form with the active record data
- TTransaction::close(); // close the transaction
- } else {
- $this->form->clear();
- }
- } catch (Exception $e) { // in case of exception
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement