예제 #1
0
function guifi_node_distances_list($filters, $node)
{
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_node_distances_list(%d)', $node->id), $_POST);
    $orig = $node->id;
    // storing lat/lon from the current node to be user for computing
    // distances with the other nodes
    $lat1 = $node->lat;
    $long1 = $node->lon;
    // store the node nickname to be used for literal at the profiles
    $node1 = $node->nick;
    //  $filters = $form_state['values']['filters'];
    // get the nodes and compute distances
    /***
      $result = db_query(
          "SELECT " .
            "n.id, n.lat, n.lon, n.nick, n.status_flag, n.zone_id  " .
          "FROM {guifi_location} n " .
          "WHERE n.id !=%d " .
            "AND (n.lat != '' " .
            "AND n.lon != '') " .
            "AND (n.lat != 0 " .
            "AND n.lon != 0)",
          $node->id);
    ***/
    $result = db_query("SELECT n.id, n.lat, n.lon, n.nick, n.status_flag, n.zone_id, n.timestamp_changed, count(*) radios FROM {guifi_location} n LEFT JOIN {guifi_radios} r ON n.id = r.nid WHERE n.id !=%d AND (n.lat != '' AND n.lon != '')AND (n.lat != 0 AND n.lon != 0) GROUP BY 1", $node->id);
    $oGC = new GeoCalc();
    $nodes = array();
    $rows = array();
    $totals[] = NULL;
    if (isset($_POST['op'])) {
        if ($_POST['op'] == t('Next page')) {
            $filters['skip'] = $filters['skip'] + $filters['max'];
        }
        if ($_POST['op'] == t('Previous page')) {
            $filters['skip'] = $filters['skip'] - $filters['max'];
        }
        $nc = 0;
        $allow_next = FALSE;
        if ($filters['skip']) {
            $allow_prev = TRUE;
        } else {
            $allow_prev = FALSE;
        }
    }
    while ($node = db_fetch_array($result)) {
        $distance = round($oGC->EllipsoidDistance($lat1, $long1, $node["lat"], $node["lon"]), 3);
        // Apply filters
        if ($filters['sn'] and $node["radios"] < 2) {
            continue;
        }
        if ($distance <= $filters['dmax']) {
            if ($distance >= $filters['dmin']) {
                if ($filters['status'] == 'All' or $filters['status'] == $node['status_flag']) {
                    $nodes[] = array_merge(array('distance' => $distance), $node);
                }
            }
        }
    }
    // Filter form
    $fw = 0;
    //  guifi_devices_select_filter($form,$form_state,$fw);
    $form = array('#type' => 'fieldset', '#collapsible' => FALSE, '#collapsed' => FALSE, '#prefix' => '<div id="list-devices">', '#suffix' => '</div>');
    if (count($nodes) == 0) {
        $form['empty'] = array('#type' => 'item', '#title' => t('No nodes found. The list is empty'), '#value' => t('Th given query has returned no rows.'), '#description' => t('Use the filters to get some results'), '#weight' => $fw++);
        return $form;
    }
    asort($nodes);
    // header
    $form['z'] = array('#type' => 'fieldset', '#tree' => TRUE, '#weight' => $fw++);
    $form['z'][-1]['h_node'] = array('#type' => 'item', '#title' => t('Node'), '#description' => t('Zone'), '#prefix' => '<table><tr><th>', '#suffix' => '</th>', '#weight' => $fw++);
    $form['z'][-1]['h_distance'] = array('#type' => 'item', '#title' => t('Distance'), '#value' => t('Status'), '#description' => t('Azimuth'), '#prefix' => '<th>', '#suffix' => '</th>', '#weight' => $fw++);
    $form['z'][-1]['h_heights'] = array('#type' => 'item', '#title' => t('Heights image'), '#description' => t('Click over the image to view in large format<br>
      Visit <a href="http://wisp.heywhatsthat.com">HeyWhatsThat WISP</a> for tools
      for planning wireless networks.<br><a href="http://www.heywhatsthat.com">HeyWhatsThat</a>. Copyright 2012 Michael Kosowsky. <b>All rights reserved</b>'), '#prefix' => '<th>', '#suffix' => '</th></tr>', '#weight' => $fw++);
    $nc = 0;
    $tc = count($nodes);
    foreach ($nodes as $key => $node) {
        $dAz = round($oGC->GCAzimuth($lat1, $long1, $node["lat"], $node["lon"]));
        // Calculo orientacio
        if ($dAz < 23) {
            $dOr = t("North");
        } else {
            if ($dAz < 68) {
                $dOr = t("North East");
            } else {
                if ($dAz < 113) {
                    $dOr = t("East");
                } else {
                    if ($dAz < 158) {
                        $dOr = t("South East");
                    } else {
                        if ($dAz < 203) {
                            $dOr = t("South");
                        } else {
                            if ($dAz < 248) {
                                $dOr = t("South West");
                            } else {
                                if ($dAz < 293) {
                                    $dOr = t("West");
                                } else {
                                    if ($dAz < 338) {
                                        $dOr = t("North West");
                                    } else {
                                        $dOr = t("North");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        //    $output .=  _wifi_state_class($rows[$key]["state"]) .t($rows[$key]["state"]) ."</td>";
        // conversio de les coordenades a UTM
        $UTMnode1 = guifi_WG842UTM($long1, $lat1, 5, 31, 1);
        $UTMnode2 = guifi_WG842UTM($node["lon"], $node["lat"], 5, 31, 1);
        // genero URL del Perfil
        $height_url = base_path() . drupal_get_path('module', 'guifi') . '/guifi_heights.php?x1=' . $UTMnode1[0] . "&y1=" . $UTMnode1[1] . "&x2=" . $UTMnode2[0] . "&y2=" . $UTMnode2[1];
        $height_url_long = $height_url . "&node1=" . $node1 . "&node2=" . $node["nick"] . "&width=1100&height=700";
        //    $height_url_small = $height_url."&width=200&height=100";
        $height_url_small = 'http://www.heywhatsthat.com/bin/profile.cgi?axes=0&curvature=0&metric=1' . '&pt0=' . $lat1 . ',' . $long1 . ',ff0000,9' . '&pt1=' . $node[lat] . ',' . $node[lon] . ',00c000,9' . '&groundrelative=1' . '&src=guifi.net' . '&width=300&height=100';
        // heywhatsthat.com integration
        //    $height_url = "http://www.heywhatsthat.com/bin/profile.cgi?src=profiler&axes=1&curvature=1&metric=1&" .
        //        "pt0=".$20.96144,-9.84375,ff0000&pt1=42.293564,11.25,00c000";
        $height_url_long = base_path() . 'node/' . $orig . '/view/distancesmap?lat2=' . $node['lat'] . '&lon2=' . $node['lon'];
        $zone = node_load(array('nid' => $node['zone_id']));
        if ($filters['search']) {
            if (!stristr($zone->nick . $node['nick'], $filters['search'])) {
                continue;
            }
        }
        if ($filters['azimuth']) {
            $l = FALSE;
            foreach (explode('-', $filters['azimuth']) as $minmax) {
                list($min, $max) = explode(',', $minmax);
                if ($dAz <= $max and $dAz >= $min) {
                    $l = TRUE;
                }
            }
            if (!$l) {
                continue;
            }
        }
        // All filters applied, see if fits in the current chunk (skip/max)
        if ($nc >= $filters['skip'] + $filters['max']) {
            $allow_next = TRUE;
            break;
        }
        $nc++;
        if ($nc < $filters['skip']) {
            continue;
        }
        $suffix = '</td></tr>';
        if (!$allow_prev and !$allow_next) {
            if ($nc == $tc) {
                $suffix = '</td></tr></table>';
            }
        }
        //    $form['z'][$nc]['d_nid'] = array (
        //      '#type' => 'hidden',
        //      '#parents'=> array('z',$nc,'d_nid'),
        //      '#value' => $node['id'],
        //      '#weight' => $fw++,
        //    );
        $form['z'][$nc]['d_node'] = array('#type' => 'item', '#parents' => array('z', $nc, 'd_node'), '#title' => l($node['nick'], 'node/' . $node['id']), '#description' => l($zone->nick, 'node/' . $node['zone_id']), '#prefix' => '<tr><td>', '#suffix' => '</td>', '#weight' => $fw++);
        $form['z'][$nc]['d_distance'] = array('#type' => 'item', '#parents' => array('z', $nc, 'd_distance'), '#title' => $node['distance'] . ' ' . t('kms'), '#value' => $node['status_flag'] . " (" . date('d/m/Y', $node["timestamp_changed"]) . ")", '#description' => $dAz . 'º - ' . $dOr, '#prefix' => '<td>', '#suffix' => '</td>', '#weight' => $fw++);
        $form['z'][$nc]['d_status'] = array('#type' => 'item', '#parents' => array('z', $nc, 'd_status'), '#value' => '<a href="' . $height_url_long . '" alt="' . t('Click to view in large format') . '" target="_blank">' . '<img src="' . $height_url_small . '"></a>', '#prefix' => '<td>', '#suffix' => $suffix, '#weight' => $fw++);
    }
    // eof while distance < max:distance
    if (!$allow_next) {
        $suffix = '</td></tr></table>';
    } else {
        $suffix = '<td>';
    }
    if ($allow_prev) {
        $prefix = '<td>';
        $form['z'][$nc++]['prev'] = array('#type' => 'submit', '#parents' => array('z', $nc++, 'prev'), '#value' => t('Previous page'), '#name' => 'op', '#prefix' => '<tr><td>', '#suffix' => $suffix, '#weight' => $fw++);
    } else {
        $prefix = '<tr><td>';
    }
    if ($allow_next) {
        $form['z'][$nc++]['next'] = array('#type' => 'submit', '#parents' => array('z', $nc++, 'next'), '#value' => t('Next page'), '#prefix' => $prefix, '#suffix' => '</td></tr></table>', '#name' => 'op', '#weight' => $fw++);
    }
    return $form;
}
예제 #2
0
function guifi_get_map_info($node)
{
    $map_info = array();
    // Obtenim les variables de retall del mapa.
    //  - (X,Y) ó (UTMx, UTMy) ó (Lon,Lat)
    $map_info['datum'] = 5;
    $map_info['zone'] = 31;
    $map_info['nord'] = 1;
    $map_info['xPixel'] = isset($_GET["xPixel"]) ? $_GET["xPixel"] : $_POST["xPixel"];
    $map_info['yPixel'] = isset($_GET["yPixel"]) ? $_GET["yPixel"] : $_POST["yPixel"];
    $map_info['xUTM'] = isset($_GET["xUTM"]) ? $_GET["xUTM"] : $_POST["xUTM"];
    $map_info['yUTM'] = isset($_GET["yUTM"]) ? $_GET["yUTM"] : $_POST["yUTM"];
    $map_info['londec'] = isset($_GET["londec"]) ? $_GET["londec"] : $_POST["londec"];
    $map_info['latdec'] = isset($_GET["latdec"]) ? $_GET["latdec"] : $_POST["latdec"];
    $map_info['lon'] = isset($_GET["lon"]) ? $_GET["lon"] : $_POST["lon"];
    $map_info['lat'] = isset($_GET["lat"]) ? $_GET["lat"] : $_POST["lat"];
    //  - Zoom ó Dist
    $map_info['zoom'] = isset($_GET["zoom"]) ? $_GET["zoom"] : $_POST["zoom"];
    $map_info['dist'] = isset($_GET["dist"]) ? $_GET["dist"] : $_POST["dist"];
    if (!isset($map_info['xPixel']) || !isset($map_info['yPixel'])) {
        $map_info['xPixel'] = 0;
        $map_info['yPixel'] = 0;
    }
    if (!isset($map_info['zoom'])) {
        $map_info['zoom'] = 0;
    }
    // Comprovem les dades i les transformem en X, Y, S
    $map_info['width'] = $map_info['height'] = 500;
    // This variables will are in drupal
    $map_info['quadrants'] = 3;
    // This variables will are in drupal
    $image_info = guifi_get_image_info(guifi_get_file_map_zone($node));
    // Find max scale of de map to draw from zoom of this view
    $map_info['maxRel'] = $image_info['width'] / $map_info['width'];
    if ($map_info['maxRel'] < $image_info['height'] / $map_info['height']) {
        $map_info['maxRel'] = $image_info['height'] / $map_info['height'];
    }
    $map_info['maxScale'] = guifi_get_scale_relation($map_info['maxRel']);
    if ($node->valid) {
        // Calcule dist of original map and his relation
        $point_zero = guifi_pixel2UTM($node->coord, 0, 0);
        $point_right = guifi_pixel2UTM($node->coord, $image_info['width'] - 1, 0);
        $point_bottom = guifi_pixel2UTM($node->coord, 0, $image_info['height'] - 1);
        $map_info['distX'] = guifi_get_dist_UTM($point_zero[0], $point_zero[1], $point_right[0], $point_right[1]);
        $map_info['distY'] = guifi_get_dist_UTM($point_zero[0], $point_zero[1], $point_bottom[0], $point_bottom[1]);
    }
    // Find de scale to draw the map
    if ($node->valid && isset($map_info['dist']) && is_numeric($map_info['dist'])) {
        // Find scale of de map to draw from dist of this view
        $map_info['maxRel'] = $image_info['width'] * $map_info['dist'] / ($map_info['distX'] * $map_info['width']);
        if ($map_info['maxRel'] < $image_info['height'] * $map_info['dist'] / ($map_info['distY'] * $map_info['height'])) {
            $map_info['maxRel'] = $image_info['height'] * $map_info['dist'] / ($map_info['distY'] * $map_info['height']);
        }
        $map_info['scale'] = guifi_get_scale_relation($map_info['maxRel']);
        if ($map_info['scale'] > $map_info['maxScale']) {
            $map_info['scale'] = $map_info['maxScale'];
        }
        $map_info['zoom'] = $map_info['maxScale'] - $map_info['scale'];
    }
    if (isset($map_info['zoom'])) {
        // Recalcule de zoom to a correct zoom
        if ($map_info['zoom'] > $map_info['maxScale']) {
            $map_info['zoom'] = $map_info['maxScale'];
        }
        $map_info['scale'] = $map_info['maxScale'] - $map_info['zoom'];
    }
    if ($node->valid) {
        if (isset($map_info['lon']) && isset($map_info['lat'])) {
            // Transform Geo's corrdinates to UTM Coordinates
            $map_info['londec'] = text2Coord($map_info['lon']);
            $map_info['latdec'] = text2Coord($map_info['lat']);
        }
        if (isset($map_info['londec']) && isset($map_info['latdec'])) {
            // Transform Geo's corrdinates to UTM Coordinates
            $point = guifi_WG842UTM($map_info['londec'], $map_info['latdec'], $map_info['datum'], $map_info['zone'], $map_info['nord']);
            $map_info['xUTM'] = $point[0];
            $map_info['yUTM'] = $point[1];
        }
        if (isset($map_info['xUTM']) && isset($map_info['yUTM'])) {
            // Transform UTM's corrdinates to Pixel Coordinates
            $point = guifi_UTM2pixel($node->coord, $map_info['xUTM'], $map_info['yUTM']);
            $map_info['xPixel'] = $point[0];
            $map_info['yPixel'] = $point[1];
        }
    }
    // Find quadrants of de map scaled.
    $map_info['width_quadrant'] = $map_info['width'] / $map_info['quadrants'];
    $map_info['height_quadrant'] = $map_info['height'] / $map_info['quadrants'];
    $quadrantsX = ceil($image_info['width'] / guifi_get_rel_scale($map_info['scale']) / $map_info['width_quadrant']);
    $quadrantsY = ceil($image_info['height'] / guifi_get_rel_scale($map_info['scale']) / $map_info['height_quadrant']);
    // Find de quadrant center of de map scaled from pixel x,y in center.
    $quadCentX = floor($map_info['xPixel'] / guifi_get_rel_scale($map_info['scale']) / $map_info['width_quadrant']);
    $quadCentY = floor($map_info['yPixel'] / guifi_get_rel_scale($map_info['scale']) / $map_info['height_quadrant']);
    // Find de quadrant top-left of de map scaled from pixel x,y in center.
    $map_info['quadX'] = $quadCentX - floor($map_info['quadrants'] / 2);
    $map_info['quadY'] = $quadCentY - floor($map_info['quadrants'] / 2);
    if ($map_info['quadX'] > $quadrantsX - $map_info['quadrants']) {
        $map_info['quadX'] = $quadrantsX - $map_info['quadrants'];
    }
    if ($map_info['quadY'] > $quadrantsY - $map_info['quadrants']) {
        $map_info['quadY'] = $quadrantsY - $map_info['quadrants'];
    }
    if ($map_info['quadX'] < 0) {
        $map_info['quadX'] = 0;
    }
    if ($map_info['quadY'] < 0) {
        $map_info['quadY'] = 0;
    }
    // Recalcule the width and heigth of scaled image
    if ($map_info['quadX'] >= $quadrantsX - $map_info['quadrants']) {
        $map_info['width'] = floor($image_info['width'] / guifi_get_rel_scale($map_info['scale']) - $map_info['quadX'] * $map_info['width_quadrant']);
    }
    if ($map_info['quadY'] >= $quadrantsY - $map_info['quadrants']) {
        $map_info['height'] = floor($image_info['height'] / guifi_get_rel_scale($map_info['scale']) - $map_info['quadY'] * $map_info['height_quadrant']);
    }
    // Calculem la distància de la màxima de la imatge
    if ($node->valid) {
        if ($map_info['width'] < $map_info['height']) {
            $map_info['dist'] = floor($map_info['distX'] * ($map_info['width'] * guifi_get_rel_scale($map_info['scale'])) / $image_info['width']);
        } else {
            $map_info['dist'] = floor($map_info['distY'] * ($map_info['height'] * guifi_get_rel_scale($map_info['scale'])) / $image_info['height']);
        }
    }
    /*
      echo "<br />quadrantsX: ".$quadrantsX;
      echo "<br />quadrantsY: ".$quadrantsY;
      echo "<br />map_width: ".$image_info['width'];
      echo "<br />map_height: ".$image_info['height'];
    */
    /*
      echo "<br />datum: ".$map_info['datum'];
      echo "<br />zone: ".$map_info['zone'];
      echo "<br />nord: ".$map_info['nord'];
      echo "<br />zoom: ".$map_info['zoom'];
      echo "<br />dist: ".$map_info['dist'];
      echo "<br />scale: ".$map_info['scale'];
      echo "<br />xPixel: ".$map_info['xPixel'];
      echo "<br />yPixel: ".$map_info['yPixel'];
      echo "<br />xUTM: ".$map_info['xUTM'];
      echo "<br />yUTM: ".$map_info['yUTM'];
      echo "<br />lon: ".$map_info['londec'];
      echo "<br />lan: ".$map_info['latdec'];
    
      echo "<br />quadX: ".$map_info['quadX'];
      echo "<br />quadY: ".$map_info['quadY'];
      echo "<br />width: ".$map_info['width'];
      echo "<br />height: ".$map_info['height'];
    */
    return $map_info;
}