function guifi_stats_growthmap()
{
    $output = "";
    if (guifi_gmap_key()) {
        drupal_add_js(drupal_get_path('module', 'guifi') . '/js/guifi_gmap_growthmap.js', 'module');
        $output .= '<form>' . '<input type=hidden value=' . base_path() . drupal_get_path('module', 'guifi') . '/js/' . ' id=edit-jspath />' . '<input type=hidden value=' . variable_get('guifi_wms_service', '') . ' id=guifi-wms />' . '</form>';
        $output .= drupal_get_form('guifi_growthmap_map_form');
        $output .= '<div id="map" style="width: 800px; height: 600px; margin:5px;"></div>';
        $output .= '<div id="footmap" style="margin:5px;">' . t('Mode:') . '</div>';
        $output .= '<canvas id="testcanvas" width="1px" height="1px"></canvas>';
        if (isset($_GET['id'])) {
            $output .= '<form><input type=hidden value=1 id=maprun /></form>';
        } else {
            $output .= '<form><input type=hidden value=0 id=maprun /></form>';
        }
    }
    guifi_log(GUIFILOG_TRACE, 'growthmap', 1);
    return $output;
}
function theme_guifi_node_map($node)
{
    if (guifi_gmap_key()) {
        drupal_add_js(drupal_get_path('module', 'guifi') . '/js/guifi_gmap_point.js', 'module');
        $output = '<div id="map" style="width: 100%; height: 340px; margin:5px;"></div>';
        $output .= guifi_node_hidden_map_fileds($node);
    } else {
        $output = '<IFRAME FRAMEBORDER="0" ALIGN=right SRC="' . variable_get("guifi_maps", 'http://maps.guifi.net') . '/world.phtml?IFRAME=Y&MapSize=300,240&Lat=' . $node->lat . '&Lon=' . $node->lon . '&Layers=all" WIDTH="350" HEIGHT="290" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="AUTO">';
        $output .= t('Sorry, your browser can\'t display the embedded map');
        $output .= '</IFRAME>';
    }
    return $output;
}
function guifi_traceroute_search($params = NULL)
{
    if (count($params)) {
        $to = explode(',', $params);
        $from = array_shift($to);
    }
    $output = drupal_get_form('guifi_traceroute_search_form', $from, $to);
    if (!count($to)) {
        return $output;
    }
    if (is_numeric($to[0])) {
        $dto = guifi_get_devicename($to[0], 'nick');
    } else {
        $dto = $to[0];
        $qry = db_query('SELECT device_id FROM {guifi_services} WHERE service_type="%s"', $to[0]);
        $nto = array();
        while ($service = db_fetch_object($qry)) {
            $nto[] = $service->device_id;
        }
        $to = $nto;
    }
    $routes = array();
    $btime = microtime(TRUE);
    $explored = guifi_traceroute(array($from => array()), $to, $routes);
    $tracetit = t('%results routes found. %explored routes analyzed in %secs seconds', array('%results' => count($routes), '%explored' => number_format($explored), '%secs' => number_format(microtime(TRUE) - $btime, 4)));
    $tracetit .= '<br /><small>' . t('Note that this is a software traceroute generated by the information currently available at the database, it might be distinct than the real routes at the network, however this information could be helpful in cleaning the data and network planning.') . '</small><hr>';
    sort($routes);
    $linkslist = array();
    $nodeslist = array();
    $nroute = 0;
    $trace = '';
    $collapsed = FALSE;
    foreach ($routes as $route) {
        end($route[1]);
        $target = key($route[1]);
        $trace .= theme('fieldset', array('#title' => t('Route from !oname to !dname, !hops hops, cost !cost', array('!cost' => $route[0], '!oname' => guifi_get_devicename($from, 'nick'), '!hops' => count($route[1]) - 1, '!dname' => guifi_get_devicename($target, 'nick'))), '#value' => theme_guifi_traceroute($route[1]), '#collapsible' => TRUE, '#collapsed' => $collapsed));
        $collapsed = TRUE;
        guifi_traceroute_dataexport($route[1], ++$nroute, $linkslist, $nodeslist);
    }
    if (guifi_gmap_key()) {
        drupal_add_js(drupal_get_path('module', 'guifi') . '/js/guifi_gmap_traceroute.js', 'module');
        $datalinks = guifi_export_arraytojs($linkslist);
        $datanodes = guifi_export_arraytojs($nodeslist);
        $lat1 = 99;
        $lon1 = 190;
        $lat2 = -99;
        $lon2 = -190;
        foreach ($nodeslist as $value) {
            if ($value[lat] < $lat1) {
                $lat1 = $value[lat];
            }
            if ($value[lon] < $lon1) {
                $lon1 = $value[lon];
            }
            if ($value[lat] > $lat2) {
                $lat2 = $value[lat];
            }
            if ($value[lon] > $lon2) {
                $lon2 = $value[lon];
            }
        }
        if ($lat1 == 99) {
            $lat1 = 'NA';
            $lon1 = 'NA';
            $lat2 = 'NA';
            $lon2 = 'NA';
        }
        $tracetit .= '<form>' . '<input type=hidden value=' . $lat1 . ' id=lat />' . '<input type=hidden value=' . $lon1 . ' id=lon />' . '<input type=hidden value=' . $lat2 . ' id=lat2 />' . '<input type=hidden value=' . $lon2 . ' id=lon2 />' . '<input type=hidden value="' . $datalinks . '" id=datalinks />' . '<input type=hidden value="' . $datanodes . '" id=datanodes />' . '<input type=hidden value=' . base_path() . drupal_get_path('module', 'guifi') . '/js/' . ' id=edit-jspath />' . '<input type=hidden value=' . variable_get('guifi_wms_service', '') . ' id=guifi-wms />' . '</form>';
        $tracetit .= drupal_get_form('guifi_traceroute_map_form');
        $tracetit .= '<div id="map" style="width: 100%; height: 600px; margin:5px;"></div>';
    }
    $output .= theme('box', t('Software traceroute result from %from to %to', array('%from' => guifi_get_devicename($from, 'nick'), '%to' => $dto)), $tracetit . $trace);
    guifi_log(GUIFILOG_TRACE, 'Routes', $routes);
    return $output;
}
function guifi_routingmap_all_init()
{
    $output = "";
    if (guifi_gmap_key()) {
        drupal_add_js(drupal_get_path('module', 'guifi') . '/js/guifi_gmap_routingmapall.js', 'module');
        $output .= '<form>' . '<input type=hidden value=' . base_path() . drupal_get_path('module', 'guifi') . '/js/' . ' id=edit-jspath />' . '<input type=hidden value=' . variable_get('guifi_wms_service', '') . ' id=guifi-wms />' . '</form>';
        $output .= '<div id="topmap" style="margin:5px;text-align:center;font-size:14px"></div>';
        $output .= '<div id="map" style="width: 100%; height: 600px; margin:5px;"></div>';
        $output .= '<div id="bottommap" style="margin:5px;"></div>';
    }
    guifi_log(GUIFILOG_TRACE, 'routingmap', 1);
    return $output;
}
/** * guifi_zone_map(): Print de page show de zone map and nodes.
 */
function theme_guifi_zone_map($node)
{
    drupal_set_breadcrumb(guifi_zone_ariadna($node->id, 'node/%d/view/map'));
    $node = node_load(array('nid' => $node->id));
    if (guifi_gmap_key()) {
        drupal_add_js(drupal_get_path('module', 'guifi') . '/js/guifi_gmap_zone.js', 'module');
        $output = '<div id="map" style="width: 100%; height: 640px; margin:5px;"></div>';
        $output .= guifi_zone_hidden_map_fileds($node);
    } else {
        $output = guifi_zone_map_help($node->id);
        $output .= '<IFRAME FRAMEBORDER="0" SRC="' . variable_get("guifi_maps", 'http://maps.guifi.net') . '/world.phtml?IFRAME=Y&MapSize=600,450&REGION_ID=' . $node->id . '" ALIGN="CENTER" WIDTH="670" HEIGHT="500" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="AUTO">';
        $output .= t('Sorry, your browser can\'t display the embedded map');
        $output .= '</IFRAME>';
    }
    $output .= theme_links(module_invoke_all('link', 'node', $node, FALSE));
    print theme('page', $output, FALSE);
    return;
}