$nm_vaga = mysql_real_escape_string(utf8_decode($job['title'])); $dc_vaga = mysql_real_escape_string(utf8_decode($job['description'])); $nm_empresa = mysql_real_escape_string(utf8_decode($job['company'])); $job['company']; //$dt_vaga = $job['link']; $dt_vaga = substr($job['date'], 6, 4) . "-" . substr($job['date'], 3, 2) . "-" . substr($job['date'], 0, 2); $dc_area = mysql_real_escape_string(utf8_decode($job['branch'])); $job['branch']; $vl_link = urldecode($job['link']); $cd_vaga = rand(); $cd_vaga = substr($vl_link, strpos($vl_link, 'vag_id=') + 7); foreach ($job['city'] as $field => $value) { $nm_cidade = mysql_real_escape_string(utf8_decode($value['name'])); $qt_vaga = $value['amount']; //`CD_VAGA`, `NM_VAGA`, `DC_VAGA`, `NM_EMPRESA`, `DT_VAGA`, `DC_AREA`, `VL_LINK`, `NM_CIDADE`, `QT_VAGAS` $sql = "INSERT INTO s_catho VALUES ({$cd_vaga}, '{$nm_vaga}', '{$dc_vaga}','{$nm_empresa}', '{$dt_vaga}', '{$dc_area}', '{$vl_link}', '{$nm_cidade}', '{$qt_vaga}')"; //echo $sql."\n"; if (!ChecaIndice($cd_vaga, $nm_cidade)) { ExecutaQuery($sql); } //echo $cd_vaga."-".$vl_link."<br>\n"; } } $page++; echo "<script> document.location = 'catho.php?page={$page}';</script>"; } ?> </body> </html>
<?php $get_lat = $_GET['lat']; $get_lon = $_GET['lon']; require_once "../extras/basico.php"; if ($get_lat == "" || $get_lon == "") { $get_lat = -23.5489; $get_lon = -46.6388; } $sql_max_dist = 100000; $sql = "\n SELECT\n cd.*,\n 1000*6371*2*ATAN2(SQRT(sin((({$get_lat} * 3.1415926535897932384626433832795 / 180 ) - (cd.VL_LATITUDE * 3.1415926535897932384626433832795 / 180))/2)*sin((({$get_lat} * 3.1415926535897932384626433832795 / 180 ) - (cd.VL_LATITUDE * 3.1415926535897932384626433832795 / 180))/2) + cos({$get_lat} * 3.1415926535897932384626433832795 / 180)*cos(cd.VL_LATITUDE * 3.1415926535897932384626433832795 / 180)*sin(((cd.VL_LONGITUDE * 3.1415926535897932384626433832795 / 180) - ({$get_lon} * 3.1415926535897932384626433832795 / 180))/2)*sin(((cd.VL_LONGITUDE * 3.1415926535897932384626433832795 / 180) - ({$get_lon} * 3.1415926535897932384626433832795 / 180))/2)), SQRT(1-(sin((({$get_lat} * 3.1415926535897932384626433832795 / 180 ) - (cd.VL_LATITUDE * 3.1415926535897932384626433832795 / 180))/2)*sin((({$get_lat} * 3.1415926535897932384626433832795 / 180 ) - (cd.VL_LATITUDE * 3.1415926535897932384626433832795 / 180))/2) + cos({$get_lat} * 3.1415926535897932384626433832795 / 180)*cos(cd.VL_LATITUDE * 3.1415926535897932384626433832795 / 180)*sin(((cd.VL_LONGITUDE * 3.1415926535897932384626433832795 / 180) - ({$get_lon} * 3.1415926535897932384626433832795 / 180))/2)*sin(((cd.VL_LONGITUDE * 3.1415926535897932384626433832795 / 180) - ({$get_lon} * 3.1415926535897932384626433832795 / 180))/2)))) as VL_DISTANCIA\n FROM\n s_cidades cd \n WHERE\n 1000*6371*2*ATAN2(SQRT(sin((({$get_lat} * 3.1415926535897932384626433832795 / 180 ) - (cd.VL_LATITUDE * 3.1415926535897932384626433832795 / 180))/2)*sin((({$get_lat} * 3.1415926535897932384626433832795 / 180 ) - (cd.VL_LATITUDE * 3.1415926535897932384626433832795 / 180))/2) + cos({$get_lat} * 3.1415926535897932384626433832795 / 180)*cos(cd.VL_LATITUDE * 3.1415926535897932384626433832795 / 180)*sin(((cd.VL_LONGITUDE * 3.1415926535897932384626433832795 / 180) - ({$get_lon} * 3.1415926535897932384626433832795 / 180))/2)*sin(((cd.VL_LONGITUDE * 3.1415926535897932384626433832795 / 180) - ({$get_lon} * 3.1415926535897932384626433832795 / 180))/2)), SQRT(1-(sin((({$get_lat} * 3.1415926535897932384626433832795 / 180 ) - (cd.VL_LATITUDE * 3.1415926535897932384626433832795 / 180))/2)*sin((({$get_lat} * 3.1415926535897932384626433832795 / 180 ) - (cd.VL_LATITUDE * 3.1415926535897932384626433832795 / 180))/2) + cos({$get_lat} * 3.1415926535897932384626433832795 / 180)*cos(cd.VL_LATITUDE * 3.1415926535897932384626433832795 / 180)*sin(((cd.VL_LONGITUDE * 3.1415926535897932384626433832795 / 180) - ({$get_lon} * 3.1415926535897932384626433832795 / 180))/2)*sin(((cd.VL_LONGITUDE * 3.1415926535897932384626433832795 / 180) - ({$get_lon} * 3.1415926535897932384626433832795 / 180))/2)))) < {$sql_max_dist} \n GROUP BY\n 1\n ORDER BY\n VL_DISTANCIA\n LIMIT 0, 100"; //echo $sql; $rs = ExecutaQuery($sql, true); $row = mysql_fetch_array($rs); //echo "Cidade maius p'roximo ".$row['NM_CIDADE']; $nm_cidade = $row['NM_CIDADE']; $sql = "SELECT * FROM `s_catho` WHERE NM_CIDADE = '{$nm_cidade}' LIMIT 0, 40"; $rs = ExecutaQuery($sql, true); for ($i = 0; $i < mysql_num_rows($rs); $i++) { $row = mysql_fetch_array($rs); $content[] = array("cd_vaga" => $row["CD_VAGA"], "nm_vaga" => $row["NM_VAGA"], "dc_vaga" => $row["DC_VAGA"], "nm_empresa" => $row["NM_EMPRESA"], "dt_vaga" => $row["DT_VAGA"], "dc_area" => $row["DC_AREA"], "vl_link" => $row["VL_LINK"], "nm_cidade" => $row["NM_CIDADE"], "qt_vagas" => $row["QT_VAGAS"], "distancia" => $row["VL_DISTANCIA"]); } $result = json_encode(array("data" => $content)); //echo $result; $get_callback = $_GET['callback']; if ($get_callback != "") { echo $get_callback . "(" . $result . ");"; } else { echo $result; }
function ChecaIndice($cd_vaga, $nm_cidade) { $sql = "SELECT * FROM s_catho WHERE CD_VAGA = {$cd_vaga} AND NM_CIDADE = '{$nm_cidade}'"; $result = ExecutaQuery($sql); if (mysql_num_rows($result) > 0) { return TRUE; } return FALSE; }