<?php // ========= CALCULAR COOPERATIVA MAIS PRÓXIMA ========= // //INSTANCIA A CLASSE $Cooperativa = new Cooperativa(); $oCooperativaVO = new CooperativaVO(); //CARREGA RESÍDUOS $oCooperativas = $Cooperativa->carregarCooperativas(" AND coo_cidade='São Paulo' ", "coo_nome ASC", ""); header('Content-type: text/html; charset=UTF-8'); $cont = 0; $distances = ""; foreach ($oCooperativas as $coo) { //CONVERTE ENDEREÇO PRA STRING ÚNICA $cooEnderecoFormatado = $ApiMaps->formatAddress($coo->getEndereco(), $coo->getNumero(), $coo->getCidade(), $coo->getEstado(), $coo->getCep()); //CHAMA FUNÇÃO QUE RETORNA LATITUDE E LONGITUDE $cooLatLng = $ApiMaps->getLatLng($cooEnderecoFormatado); $usuEndereco = $LatLng['lat'] . "," . $LatLng['lng']; $cooEndereco = $cooLatLng['lat'] . "," . $cooLatLng['lng']; echo $cooEndereco; echo "<br>"; echo $usuEndereco; echo "<br>"; //CHAMA FUNÇÃO QUE RETORNA LATITUDE E LONGITUDE $distance = $ApiMaps->getDistance($cooEndereco, $usuEndereco); echo $coo->getCooperativaID(); echo " / "; echo $coo->getNome(); echo " / "; echo $coo->getLatitude(); echo " / "; echo $coo->getLongitude();
if ($oUsuario) { // ========= CALCULAR COOPERATIVA MAIS PRÓXIMA ========= // //INSTANCIA A CLASSE $Cooperativa = new Cooperativa(); $oCooperativaVO = new CooperativaVO(); //RAIO DE BUSCA $modifiers = array("0.01", "0.03", "0.05", "0.07", "0.1", "0.2", "0.3", "0.5", "0.7", "0.9"); $distances = ""; //LOOP ATÉ ENCONTRAR COOPERATIVA while (true) { //LOOP NOS MODIFICADORES A PARTIR DO MAIS PERTO foreach ($modifiers as $modifier) { //WHERE EM COORDENADAS COM BASE NO MODIFICADOR $search = " AND (coo_lat >= '" . ($LatLng['lat'] - $modifier) . "' AND coo_lat <= '" . ($LatLng['lat'] + $modifier) . "') AND (coo_lng >= '" . ($LatLng['lng'] - $modifier) . "' AND coo_lng <= '" . ($LatLng['lng'] + $modifier) . "')"; //CARREGA COOPERATIVAS $oCooperativas = $Cooperativa->carregarCooperativas(" AND coo_ativo='1'" . $search, "coo_nome ASC", ""); //LOOP EM TODAS COOPERATIVAS NESSE RAIO if ($oCooperativas) { foreach ($oCooperativas as $coo) { //COORDENADAS DO ENDEREÇO DA COOPERATIVAS $cooEndereco = number_format($coo->getLatitude(), 6) . "," . number_format($coo->getLongitude(), 6); //CHAMA FUNÇÃO QUE CALCULA DISTÂNCIA E TEMPO $distance = $ApiMaps->getDistance($cooEndereco, $usuEndereco); if ($distance) { //POPULA ARRAY COM TEMPO E ID DE CADA COOPERATIVA $distances[$coo->getCooperativaID()] = $distance['durationValue']; } } } //SE ENCONTRAR COOPERATIVAS SAIR DO LOOP if (!empty($distances)) {
if (preg_match("/^([[:alnum:]_.-]){2,}@([[:lower:][:digit:]_.-]{2,})(\\.[[:lower:]]{2,3})(\\.[[:lower:]]{2})?\$/", $mail)) { return true; } else { return false; } } if (!validaEmail($email)) { echo "email_incorreto"; exit; } if (empty($senha)) { echo "senha_vazia"; exit; } $Cooperativa = new Cooperativa(); $oCooperativa = $Cooperativa->carregarCooperativas(' AND coo_email = "' . $email . '" AND coo_senha = "' . hash('sha512', $senha) . '"', '', ''); if ($oCooperativa) { $Log = new Log(); $oLogVO = new LogVO(); $oLogVO->setUsuarioID($oCooperativa[0]->getCooperativaID()); $oLogVO->setUsuario($oCooperativa[0]->getNome()); $oLogVO->setAcao('Acesso: Cooperativa ' . $oCooperativa[0]->getNome() . ' logou no sistema'); $oLogVO->setPagina($pagina); $oLogVO->setIP(getIP()); $oLogVO->setAcesso(1); $oLogVO->setData('Y-m-d H:i:s'); $Log->inserirLog($oLogVO); // INICIA SESSÃO session_start(); $_SESSION["login_cooperativa"]["id"] = $oCooperativa[0]->getCooperativaID(); $_SESSION["login_cooperativa"]["nome"] = $oCooperativa[0]->getNome();