-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore_request.php
More file actions
executable file
·96 lines (76 loc) · 2.87 KB
/
core_request.php
File metadata and controls
executable file
·96 lines (76 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
include('database.php');
$instance_conn = Database::getInstance();
$opcion = $_POST['opcion'];
$lugar = $_POST['lugar'];
if ($opcion == 'total') {
echo lista_total($instance_conn, $lugar);
}
else if($opcion == 'detail_place') {
echo detail_place($instance_conn, $lugar);
}
mysqli_close($instance_conn->get_connection());
function ingresar_nuevo($conn, $lugar)
{
$user = $lugar;
$patron = "/@/";
if (preg_match($patron, $user))
{
$user = substr($user,1);
}
$query = "SELECT from_user FROM users where from_user = '$user'";
$matriz = mysql_query($query, $conn) or die(mysql_error());
$total_resultados = mysql_num_rows($matriz);
if ($total_resultados > 0)
{
return json_encode(array('data'=>array('res'=>'ya estaba en db')));
}
$query = "SELECT name FROM pendientes where name = '$user'";
$matriz = mysql_query($query, $conn) or die(mysql_error());
$total_resultados = mysql_num_rows($matriz);
if ($total_resultados > 0)
{
return json_encode(array('data'=>array('res'=>'ya estaba')));
}
$query = "INSERT INTO pendientes(name, id) VALUES('$user', '')";
if (mysql_query($query, $conn) or die(mysql_error()))
{
return json_encode(array('data'=>array('res'=>'ok')));
}
return json_encode(array('data'=>array('res'=>'problema db')));
}
function lista_total($instance_conn, $lugar)
{
$extra_param = "";
if ($lugar != 'region')
{
$extra_param .= "AND ciudades.slug = '$lugar'";
}
$query = "SELECT count(users.from_user_id) as total, ciudades.name, ciudades.lat, ciudades.lon, ciudades.slug as slug from users, ciudades where users.ciudad = ciudades.id group by ciudades.id order by ciudades.name asc";
$matriz = $instance_conn->get_connection()->query($query);
$total_resultados = $matriz->num_rows;
$total_cities = array();
if ($total_resultados > 0)
{
while ($col = $matriz->fetch_assoc())
{
array_push($total_cities, array('total'=>$col['total'], 'name'=> htmlentities(($col['name'])), 'lat'=>$col['lat'], 'lon'=>$col['lon'], 'slug' => $col['slug']));
}
}
return json_encode(array('data'=>array('total_cities'=>$total_cities)));
}
function detail_place($instance_conn, $lugar) {
$query = "SELECT users.from_user as name_user, ciudades.name as city_name from users, ciudades where users.ciudad = ciudades.id and ciudades.slug = '$lugar' order by users.from_user asc";
$matriz = $instance_conn->get_connection()->query($query);
$total_resultados = $matriz->num_rows;
$total_twitters = array();
$city_name;
if ($total_resultados > 0) {
while ($col = $matriz->fetch_assoc()) {
$city_name = htmlentities($col['city_name']);
array_push($total_twitters, array('name'=>htmlentities($col['name_user'])));
}
}
return json_encode(array('data'=>array('city_name' => $city_name, 'users'=>$total_twitters)));
}
?>