PHP Classes

File: index.php

Recommend this page to a friend!
  Packages of Eric Sakamoto   Formularios   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example
Class: Formularios
Manipulate database table records using Web forms
Author: By
Last change:
Date: 20 years ago
Size: 2,495 bytes
 

 

Contents

Class file image Download
<?
require_once 'Smarty.class.php';
require_once 'Form.php';
require_once('DB.php');
$DNS = array(
    'phptype'  => 'mysql',
    'username' => 'root',
    'password' => 'ess',
    'hostspec' => 'localhost',
    'database' => 'florence',
);
$db = DB :: connect($DNS);
if (PEAR :: isError($db)) {
  die($db->getMessage());
}
$smarty = & new Smarty;
$acao = isset ($_GET['acao']) ? $_GET['acao'] : '';
switch($acao){
  case '':
    include_once('cliente.class.php');
    switch($c_cliente->Monta()){
      case ACAO_FIM:
        $dados = $c_cliente->getDados();
        $res = $db->autoExecute('cliente', $dados,DB_AUTOQUERY_INSERT);
        if(PEAR::isError($res))
          echo $res->getMessage();
        header("location:".basename($_SERVER['SCRIPT_NAME'])."?id=formulario_cliente&acao=lista");
        break;
    }
    break;
  case 'lista':
    $c = FORM::paginaQuery($db,'Select * from cliente order by cli_nome');
    $c->setConfig('basename_complemento','id=formulario_cliente&acao=lista');
    $c->setConfig('numero_linhas','20');
    $res = $c->getArray();
    $smarty->assign('alfabeto',$c->getAlfabeto());
    $smarty->assign('linha_lista',$res);
    $smarty->assign('pagina',$c->getIndice());
    $smarty->assign('include_file','cliente_index.htm');
    break;
  case 'altera':
    include_once('cliente.class.php');
    $c_cliente->setConf('action','id=formulario_cliente&acao=altera');
    $db->setFetchMode(DB_FETCHMODE_ASSOC);
    $c_cliente->desativarGravacao();
    switch($c_cliente->getAcao()){
      case '':
        $dados = $db->getRow("select * from cliente where cli_id = ".$db->quoteSmart($_GET['cli_id']));
        if(PEAR::isError($dados)){
          die($dados->getMessage());
        }
        $c_cliente->Monta($dados);
        break;
      case ACAO_GRAVA_ALTERA:
        switch($c_cliente->Monta()){
          case ACAO_FIM;
            $dados = $c_cliente->getDados();
            $c_cliente->formataDados();
//            print_r($c_cliente->dados_formatados);
            $cli_id = $c_cliente->getSFDados('cli_id');
            $res = $db->autoExecute('cliente', $dados,DB_AUTOQUERY_UPDATE,"cli_id = ".$db->quoteSmart($cli_id));
            if(PEAR::isError($res))
              echo $res->getMessage();
            header("location:".basename($_SERVER['SCRIPT_NAME'])."?id=formulario_cliente&acao=lista");
        }
        break;
    }
    break;

}
$smarty->display('index.htm');
?>