$ebody = 0;
if (!($res = $db->get_results("SELECT HASH,EDIT_OF,(HASH <> EDIT_OF) AS IS_EDIT,AUTORE,`DATE`,TITLE,BODY,REP_OF FROM {$sesorg}_reply ORDER BY HASH=EDIT_OF DESC, `DATE`", ARRAY_A))) {
    die("Non riesco a fare la select in {$sesorg}_reply :(");
}
$togo = $db->num_rows;
echo "{$togo} records selected<br>";
foreach ($res as $msg) {
    $riga = array();
    if ($msg[IS_EDIT]) {
        $riga[EDIT_OF] = cambia($msg[EDIT_OF]);
        $riga[IS_EDIT] = 1;
    } else {
        $riga[EDIT_OF] = '';
    }
    $riga[AUTORE] = cambia($msg[AUTORE]);
    $riga[REP_OF] = cambia($msg[REP_OF]);
    $riga['DATE'] = $msg['DATE'];
    $riga['TYPE'] = 4;
    $riga['TITLE'] = $msg['TITLE'];
    // body vuoti ?
    if (!$msg['BODY']) {
        $ebody++;
        $msg['BODY'] = "{empty}";
    }
    $riga['BODY'] = $msg['BODY'];
    $riga[_PRIVATE] = $PRIVKEY;
    $riga[CPSIGN] = 'ADMIN_SIGN';
    $risp = $core->AddMsg($riga, 0);
    if ($risp[MD5]) {
        $db->doQuery("INSERT INTO hash_tmp (OLD_HASH,NEW_HASH) VALUES(?,?)", array($msg['HASH'], $risp[MD5]));
        // feedback
<?php

include_once "/proxies/required.php";
$strCnx = "host={$host} port={$port} dbname={$db} user={$user} password={$passwd}";
$cuestionario = cambia($_COOKIE["cookie_cuestionarios0"], true);
$idUser = cambia($_COOKIE["cookie_id"], true);
$posicio = -1;
$mediana = 0;
$fech = strtotime("now");
$matrizSalidaMed = array();
$matrizDistanciasT = array();
//*************************  Conectando la base de datos
$conbd = pg_connect($strCnx) or die('No se ha podido conectar: ' . pg_last_error());
$query_Idpreguntas = "SELECT * FROM pregunta WHERE activa = 1 AND idcuestionario = '{$cuestionario}' AND geoconsenso = 1 ORDER BY idpregunta ASC";
$result = pg_query($query_Idpreguntas) or die('La consulta fallo: ' . pg_last_error());
for ($i = 0; $i < pg_num_rows($result); ++$i) {
    $row = pg_fetch_array($result, $i);
    $matrizidpreguntas[] = $row["idpregunta"];
    $matrizPgtas[] = array('idpregunta' => $row["idpregunta"], 'idcuestionario' => $row["idcuestionario"], 'tiporesp' => $row["tiporesp"], 'geoconsenso' => $row["geoconsenso"], 'activa' => $row["activa"], 'x_cen' => $row["x_cen"], 'y_cen' => $row["y_cen"], 'dist_ini' => $row["dist_ini"]);
}
$matrizGids = array();
$idP = 0;
for ($ii = 0; $ii < count($matrizPgtas); $ii++) {
    $idPregta = $matrizPgtas[$ii]["idpregunta"];
    $idP = $idP + 1;
    $query = "SELECT a.gid as gida, b.gid as gidb, ST_Distance(ST_Transform(a.the_geom,900913), ST_Transform(b.the_geom,900913)) \n\t\t\tas dist, a.the_geom as the_geom, b.the_geom as the_geomb, a.x as x_a, a.y as y_a, a.z as z_a, b.x as x_b, b.y as y_b, b.z as z_b, a.idpanel as idpanel\n\t\t\tFROM respuesta a INNER JOIN respuesta b ON a.gid != b.gid WHERE a.idpregunta='{$idPregta}' AND a.estado=1 AND b.idpregunta='{$idPregta}' AND b.estado=1 \n\t\t\tORDER BY gida ASC";
    $result = pg_query($query) or die('La consulta fallo: ' . pg_last_error());
    $matrizDistancias1p = array();
    if (pg_num_rows($result) >= 3) {
        // crea un array por cada pregunta con todas los vectores de distancias, es decir selecciona todas
        // las opiniones o respuestas a una solo prgunta
<!doctype html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<?php 
function cambia(&$num)
{
    $num = 9;
}
$x = 7;
cambia($x);
echo "<p>{$x}</p>";
$array = array("Juan" => 9, "Diego" => 8.99, "Victor" => 9.02, "Rafa" => 3);
asort($array);
print_r($array);
$b = array_keys($array);
print_r($array);
print_r($b);
?>
</body>
</html>
<?php

include "proxies/required.php";
$idPgta = isset($_GET['idPgta']) ? $_GET['idPgta'] : "";
$idPanel = isset($_GET['idPgtaPanel']) ? $_GET['idPgtaPanel'] : "";
$cuestionario = cambia($_COOKIE["cookie_cuestionarios0"], true);
$strCnx = "host={$host} port={$port} dbname={$db} user={$user} password={$passwd}";
$conbd = pg_connect($strCnx) or die('No se ha podido conectar: ' . pg_last_error());
$query = "SELECT DISTINCT idpregunta, idpanel, mediana, the_geom, x, y, z, areacons, fecha, idcons,\tidcuestionario,\tiduser \n\tFROM consensos WHERE idcuestionario = '{$cuestionario}' AND idpregunta = '{$idPgta}' ORDER BY idpanel ASC, fecha ASC";
$result = pg_query($query) or die('La consulta fallo: ' . pg_last_error());
$registros = pg_num_rows($result);
if ($registros > 0) {
    $arr0 = array();
    for ($i = 0; $i < $registros; $i++) {
        $row = pg_fetch_array($result, $i);
        $arr0 = array('idpregunta' => $row["idpregunta"], 'idpanel' => $row["idpanel"], 'mediana' => $row["mediana"], 'the_geom' => $row["the_geom"], 'x' => $row["x"], 'y' => $row["y"], 'z' => $row["z"], 'areacons' => $row["areacons"], 'idcons' => $row["idcons"], 'idcuestionario' => $row["idcuestionario"], 'iduser' => $row["iduser"], 'fecha' => date("d M Y, H:m:s", $row["fecha"]));
    }
    $ar = $arr0["mediana"];
    $xa = $arr0["x"];
    $ya = $arr0["y"];
    $arCon = $arr0["areacons"];
    pg_free_result($result);
    $query = "SELECT * FROM respuesta as A WHERE ST_DWithin(ST_GeomFromText('POINT(" . $xa . " " . $ya . ")', 4326)::geography, A.the_geom::geography," . $ar . ") AND idpregunta= " . $idPgta . " AND estado=1 ORDER BY fecha DESC";
    $result = pg_query($query) or die('La consulta fallo: ' . pg_last_error());
    $registros = pg_num_rows($result);
    $arr1 = array();
    for ($i = 0; $i < $registros; $i++) {
        $row = pg_fetch_array($result, $i);
        $area = 0;
        $idUser = $row["iduser"];
        $query2 = "SELECT areacons, mediana FROM consensos WHERE idpregunta = {$idPgta} AND iduser = {$idUser} ORDER BY fecha DESC LIMIT 1";