Files
ads-faltas-2025/Example/Telas/cadCliente.php

293 lines
15 KiB
PHP

<?php
header("Content-Type: text/html; charset=utf-8", true);
//include '../Includes/valida_sessao.inc';
//include '../Includes/geradorAleatorio.inc';
require_once ("../Controle/ControleEstado.php");
$objEstado = new Estado;
$objEstados = $objEstado->buscarTodos();
$contadorEstado = count($objEstados);
require_once ("../Controle/ControleCidade.php");
$objCidade = new Cidade;
$objCidades = $objCidade->buscarTodos();
$contadorCidade = count($objCidades);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../CSS/estilo.css" media="screen" />
<title>Cadastro de Cliente</title>
<script language="JavaScript" type="text/javascript" src="../AJAX/BibliotecaAJAX.js"></script>
<script language="JavaScript" type="text/javascript" src="../Js/ajaxInit.js"></script>
<script language="JavaScript" type="text/javascript" src="../Js/FuncoesAjaxCidades.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$('input').keypress(function(e) {
var code = null;
code = (e.keyCode ? e.keyCode : e.which);
return (code == 13) ? false : true;
});
});
function voltar() {
location.href = 'listCliente.php';
}
function mascaraTel(telefone) {
if (telefone.value.length == '0') {
document.form.telefone.value = '(' + telefone.value;
}
if (telefone.value.length == '3') {
document.form.telefone.value = telefone.value + ') ';
}
if (telefone.value.length == '9') {
document.form.telefone.value = telefone.value + '-';
}
}
function mascaraCel(celular) {
if (celular.value.length == '0') {
document.form.celular.value = '(' + celular.value;
}
if (celular.value.length == '3') {
document.form.celular.value = celular.value + ') ';
}
if (celular.value.length == '9') {
document.form.celular.value = celular.value + '-';
}
}
function mascaraCPF(cpf) {
if (cpf.value.length == '3') {
document.form.cpf.value = cpf.value + '.';
}
if (cpf.value.length == '7') {
document.form.cpf.value = cpf.value + '.';
}
if (cpf.value.length == '11') {
document.form.cpf.value = cpf.value + '-';
}
}
function mascaraData(datNascimento) {
if (datNascimento.value.length == '2') {
document.form.datNascimento.value = datNascimento.value + '/';
}
if (datNascimento.value.length == '5') {
document.form.datNascimento.value = datNascimento.value + '/';
}
}
function mascaraCEP(cep) {
if (cep.value.length == '2') {
document.form.cep.value = cep.value + '.';
}
if (cep.value.length == '6') {
document.form.cep.value = cep.value + '-';
}
}
function buscaEndereco(CEP) {
if (CEP != "") {
$('#spanLogradouro').html('<progress></progress>');
$('#spanLogradouro').load("../AJAX/enderecoPorCEP.php?cep=" + CEP + "&campo=logradouro", "",
function(responseText, textStatus, XMLHttpRequest) {
if (textStatus == 'error') {
$('#spanLogradouro').html('<font color="red">(Erro de conexão com servidor. Tente novamente)</font>');
}
}
);
$('#spanBairro').html('<progress></progress>');
$('#spanBairro').load("../AJAX/enderecoPorCEP.php?cep=" + CEP + "&campo=bairro", "",
function(responseText, textStatus, XMLHttpRequest) {
if (textStatus == 'error') {
$('#spanBairro').html('<font color="red">(Erro de conexão com servidor. Tente novamente)</font>');
}
}
);
$('#spanEstado').html('<progress></progress>');
$('#spanEstado').load("../AJAX/enderecoPorCEP.php?cep=" + CEP + "&campo=uf_sigla", "",
function(responseText, textStatus, XMLHttpRequest) {
if (textStatus == 'error') {
$('#spanEstado').html('<font color="red">(Erro de conexão com servidor. Tente novamente)</font>');
}
}
);
$('#spanCidade').html('<progress></progress>');
$('#spanCidade').load("../AJAX/enderecoPorCEP.php?cep=" + CEP + "&campo=cidade", "",
function(responseText, textStatus, XMLHttpRequest) {
if (textStatus == 'error') {
$('#spanCidade').html('<font color="red">(Erro de conexão com servidor. Tente novamente)</font>');
}
}
);
document.getElementById('numero').focus();
}
}
function contOBS(qtCaracteres) {
if (qtCaracteres > 1000) {
document.getElementById("contOBS").innerHTML = (1000 - qtCaracteres) * (-1) + " caracteres excedidos";
} else {
document.getElementById("contOBS").innerHTML = 1000 - qtCaracteres + " caracteres restantes";
}
}
function buscaAJAX(busca, idResultado) {
////busca é o atributo informado para buscaAJAX.php
//idResultado é o id do elemento que receberá a resposta.
$('#' + idResultado).html('<progress></progress>');
$('#' + idResultado).load("../AJAX/verificaCPF.php?campo1=" + busca, "",
function(responseText, textStatus, XMLHttpRequest) {
if (textStatus == 'error') {
$('#' + idResultado).html('<font color="red">(Erro de conexão com servidor. Tente novamente)</font>');
}
}
);
}
function validaForm() {
d = document.form;
if (d.cpf.value == "") {
alert("O campo CPF deve ser preenchido!");
d.cpf.focus();
return false;
}
if (document.getElementById("contCPF").value != 0){
alert("CPF já cadastrado!");
return false;
}
}
function geraUsuario2(campo) {
var frase = campo.value;
var palavras = frase.split(" ");
tamanho = palavras.length;
var usuario = (palavras[0]);
usuario = usuario.substr(0, 4);
numero = parseInt(Math.random() * 10000);
usuario = usuario + numero;
usuario = usuario.toUpperCase();
document.getElementById('usuario').value = usuario;
}
</script>
</head>
<body>
<div id="menuInterno">
<?php
include '../Includes/MenuPrincipal.php';
?>
</div>
<div id="topo">
<div id="rodape">
</div>
</div>
<div id="conteudo">
<form id="form" name="form" method="post" action="../FilesOk/cadClienteOK.php" onsubmit=" return validaForm(this);">
<div id="menuInterno">
<input type="submit" name="btnCadastrar" value="Cadastrar" class="gmailButton"/>
<input type="button" name="btnVoltar" value="Voltar" onclick="voltar()" class="gmailButton"/>
</div>
<table class="list">
<tr>
<td>Nome:</td>
<td><input name="nome" type="text" id="nome" autofocus onblur="geraUsuario2(this);" /></td>
<td>Logradouro:</td>
<td><span id="spanLogradouro"><input name="logradouro" type="text" id="logradouro" /></span></td>
</tr>
<tr>
<td>Número da casa:</td>
<td><input name="numero" type="text" id="numero" /></td>
<td>Bairro:</td>
<td><span id="spanBairro"><input name="bairro" type="text" id="bairro" /></span></td>
</tr>
<tr>
<td>Estado:</td>
<td>
<!--<span id="spanEstado"><select name="estado" id="estado" onchange="selecionaCidade();">
<option value="">Selecione um Estado</option>
<?php
for ($x = 0; $x < $contadorEstado; $x++) {
$objEstado = $objEstados[$x];
?>
<option value="<?php echo $objEstado->get('uf'); ?>"><?php echo $objEstado->get('nome'); ?></option>
<?php
}
?>
</select>
</span>-->
<span id="spanEstado"><input type="text" name="estado" id="estado" value="MG" /></span>
</td>
<td>Cidade:</td>
<td>
<!--<span id="spanCidade"><label id="caixaCidade">
<select name="cidade" id="cidade" disabled="disabled">
<option value="Todos" selected="selected">Selecione um estado</option>
</select>
</label>
<label id="carregando"></label>
</span>-->
<span id="spanCidade"><input type="text" name="cidade" id="cidade" value="Ribeirao das Neves" /></span>
</td>
</tr>
<tr>
<td>Telefone:</td>
<td><input name="telefone" type="text" id="telefone" maxlength="14" onkeypress="mascaraTel(this);" /></td>
<td>Celular:</td>
<td><input name="celular" type="text" id="celular" maxlength="14" onkeypress="mascaraCel(this);" /></td>
</tr>
<tr>
<td>CPF:</td>
<td>
<input name="cpf" type="text" id="cpf" maxlength="14" onkeypress="mascaraCPF(this);" onblur="buscaAJAX(this.value, 'infoCPF')"/>
<span id="infoCPF"><input type='hidden' value='0' id='contCPF'/></span>
</td>
<td>Email:</td>
<td><input name="email" type="text" id="email" /></td>
</tr>
<tr>
<td>CEP:</td>
<td colspan="3">
<input name="cep" type="text" id="cep" size="10" maxlength="10" onkeypress="mascaraCEP(this);" />
<a href="#" class="gmailButton" onClick="window.open('buscaCEP.php', 'Janela', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=1000, height=400');
return false;" title="Clique aqui para buscar um CEP">Buscar...</a>
<a href="#" class="gmailButton" onClick="buscaEndereco(cep.value)" title="Clique aqui para preencher os campos com dados referentes ao CEP informado">Preencher...</a>
</td>
</tr>
<tr>
<td>Data de Nascimento:</td>
<td><input name="datNascimento" type="date" id="datNascimento" maxlength="10" onkeypress="mascaraData(this);" /></td>
<td>Identidade:</td>
<td><input name="identidade" type="text" id="identidade" size="15" maxlength="15" /></td>
</tr>
<tr>
<td>Sexo:</td>
<td>
<select name="sexo" id="sexo">
<option></option>
<option value="F">Feminino</option>
<option value="M">Masculino</option>
</select>
</td>
<td>Profissão:</td>
<td><input name="profissao" type="text" id="profissao" size="15" maxlength="30" /></td>
</tr>
<tr>
<td>
<label for="usuario">Usuário:</label>
<input type="text" name="usuario" id="usuario" maxlength="10" />
</td><td>
<label for="senha">Senha:</label>
<input type="text" name="senha" id="senha" maxlength="10"
value="<?php echo gerar_sequencia(6, true, false, true, false); ?>"
/>
</td>
</tr>
<tr>
<td>OBS:</td>
<td colspan="3">
<textarea name="obs" id="obs" cols="60" rows="7" onkeyup="contOBS(this.value.length)"></textarea><span id="contOBS" ></span>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>