public function inserir(Endereco &$end, $ligacao) { parent::inserir($end); $e = $end->getEstado(); if ($e->getId() <= 0) { $lE = new ListaEstados(); $lE->inserir($e); $end->setEstado($e); } $end->getCidade()->setEstado($e); $c = $end->getCidade(); if ($c->getId() <= 0) { $lC = new ListaCidades(); $lC->inserir($c); $end->setCidade($c); } else { $lC = new ListaCidades(); $lC->condicoes('', $c->getId(), ListaCidades::ID); if ($lC->getTotal() <= 0) { if ($c->getPais()->getId() <= 0) { $c->setPais($end->getPais()); } if ($c->getEstado()->getId() <= 0) { $c->setEstado($end->getEstado()); } $this->con->executar("INSERT INTO " . Sistema::$BDPrefixo . $lC->getTabela() . "(" . ListaCidades::ID . ", " . ListaCidades::PAIS . ", " . ListaCidades::ESTADO . ", " . ListaCidades::NOME . ", " . ListaCidades::DDD . ") VALUES('" . $c->getId() . "','" . $c->getPais()->getId() . "','" . $c->getEstado()->getId() . "','" . $c->nome . "','" . $c->ddd . "')"); $id = $this->con->getId(); $lC->condicoes('', $id, ListaCidades::ID); if ($lC->getTotal() > 0) { $end->setCidade($lC->listar()); } } } $this->con->executar("INSERT INTO " . Sistema::$BDPrefixo . $this->tabela . "(" . self::IDSESSAO . ", " . self::LOGRADOURO . ", " . self::NUMERO . ", " . self::COMPLEMENTO . ", " . self::BAIRRO . ", " . self::CIDADE . ", " . self::ESTADO . ", " . self::PAIS . ", " . self::CEP . ") VALUES('" . $ligacao->getId() . "','" . $end->logradouro . "','" . $end->numero . "','" . $end->complemento . "','" . $end->bairro . "','" . $end->getCidade()->getId() . "','" . $end->getEstado()->getId() . "','" . $end->getPais()->getId() . "','" . $end->getCep() . "')"); $id = $this->con->getId(); $class = __CLASS__; $l = new $class(); $l->condicoes('', $id, self::ID); $end = $l->listar(); parent::alterar($end); }
} if (!empty($_POST['CEP'])) { $end = $p->getEndereco(); $end->setCep($_POST['CEP']); $lE = new ListaEstados(); $lE->condicoes('', strtoupper($_POST['estado']), ListaEstados::UF); if ($lE->getTotal() > 0) { $end->setEstado($lE->listar()); } else { $end->getEstado()->uf = strtoupper($_POST['estado']); $end->getEstado()->setPais(new Pais(1)); } $lC = new ListaCidades(); $lC->condicoes('', $_POST['cidade'], ListaCidades::NOME); if ($lC->getTotal() > 0) { $end->setCidade($lC->listar()); } else { $end->getCidade()->nome = $_POST['cidade']; $end->getCidade()->setEstado($end->getEstado()); } $end->logradouro = $_POST['Logradouro']; $end->numero = $_POST['Numero']; $end->complemento = $_POST['Complemento']; $end->bairro = $_POST['Bairro']; $end->loadCep(); $p->setEndereco($end); try { $p->getEndereco()->setValor(0); $p->calcularFrete(); } catch (Exception $e) { }
$iTCL->enterRepeticao()->trocar("id.Estado", $rs['id']); $iTCL->enterRepeticao()->trocar("nome.Estado", $rs['nome']); $iTCL->enterRepeticao()->trocar("uf.Estado", $rs['uf']); if($rs['id'] == $estado) $iTCL->enterRepeticao()->trocar("selected.Estado", 'selected'); } */ $lC = new ListaCidades(); $iTCL->createRepeticao("repetir->Cidade"); if (!empty($_GET['estado'])) { $lC->condicoes('', $_GET['estado'], ListaCidades::ESTADO); if (isset($_GET['json'])) { $a = array(); while ($c = $lC->listar("ASC", ListaCidades::NOME)) { $a[] = array('id' => $c->getId(), 'nome' => $c->nome); } echo JSON::_Encode($a); exit; } } /* while($rs = $con->listar()){ $iTCL->repetir(); $iTCL->enterRepeticao()->trocar("id.Cidade", $rs['id']); $iTCL->enterRepeticao()->trocar("nome.Cidade", $rs['nome']); if($rs['id'] == $cidade) $iTCL->enterRepeticao()->trocar("selected.Cidade", 'selected');