function guifi_device_links_print($device, $ltype = '%') { guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_links_print(%s)', $ltype), $device); $oGC = new GeoCalc(); $dtotal = 0; $ltotal = 0; if ($ltype == '%') { $title = t('network information'); } else { $title = t('network information') . ' (' . $ltype . ')'; } $rows_wds = array(); $rows_ap_client = array(); $rows_cable = array(); $loc1 = db_fetch_object(db_query('SELECT lat, lon, nick ' . 'FROM {guifi_location} WHERE id=%d', $device['nid'])); $curr_radio = 0; switch ($ltype) { case '%': case 'wds': case 'ap/client': $dname_curr = ''; if ($device['radios']) { foreach ($device['radios'] as $radio_id => $radio) { if ($radio['interfaces']) { foreach ($radio['interfaces'] as $interface_id => $interface) { if ($interface['ipv4']) { foreach ($interface['ipv4'] as $ipv4_id => $ipv4) { if ($ipv4['links']) { foreach ($ipv4['links'] as $link_id => $link) { guifi_log(GUIFILOG_TRACE, 'going to list link', $link); $loc2 = db_fetch_object(db_query('SELECT lat, lon, nick FROM {guifi_location} WHERE id=%d', $link['nid'])); $gDist = round($oGC->EllipsoidDistance($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon), 3); $dAz = round($oGC->GCAzimuth($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon)); // Calculo orientacio if ($dAz < 23) { $dOr = t("N"); } else { if ($dAz < 68) { $dOr = t("NE"); } else { if ($dAz < 113) { $dOr = t("E"); } else { if ($dAz < 158) { $dOr = t("SE"); } else { if ($dAz < 203) { $dOr = t("S"); } else { if ($dAz < 248) { $dOr = t("SW"); } else { if ($dAz < 293) { $dOr = t("W"); } else { if ($dAz < 338) { $dOr = t("NW"); } else { $dOr = t("N"); } } } } } } } } $item = _ipcalc($ipv4['ipv4'], $ipv4['netmask']); $ipdest = explode('.', $link['interface']['ipv4']['ipv4']); $status_url = guifi_cnml_availability(array('device' => $link['device_id'], 'format' => 'short')); $cr = db_fetch_object(db_query("SELECT count(*) count FROM {guifi_radios} r WHERE id=%d", $link['device_id'])); if ($cr->count > 1) { $rn = db_fetch_object(db_query("SELECT ssid FROM {guifi_radios} r WHERE r.id=%d AND r.radiodev_counter=%d", $link['device_id'], $link['interface']['radiodev_counter'])); $dname = guifi_get_hostname($link['device_id']) . '<br />' . $rn->ssid; } else { $dname = guifi_get_hostname($link['device_id']); } $wrow = array($dname_curr != $radio['ssid'] ? array('data' => '<strong>' . $radio['ssid'] . '</strong>', 'header') : '<small>' . $radio['ssid'] . '</small>', array('data' => $link_id, 'align' => 'right'), '<a href="' . base_path() . 'guifi/device/' . $link['device_id'] . '">' . $dname . '</a>', '<a href="' . base_path() . 'node/' . $link['nid'] . '">' . $loc2->nick . '</a>', $ipv4['ipv4'] . '/' . $item['maskbits'], '.' . $ipdest[3], array('data' => t($link['flag']) . $status_url, 'class' => $link['flag']), $link[routing], $gDist, $dAz . '-' . $dOr); $dname_curr = $radio['ssid']; if ($interface['interface_type'] == 'wds/p2p' or $interface['interface_class'] == 'wds/p2p') { $rows_wds[] = $wrow; } if ($link['link_type'] == 'ap/client') { $rows_ap_client[] = $wrow; } $dtotal = $dtotal + $gDist; $ltotal++; } } } } } } } } if ($ltype != '%') { break; } case 'cable': $iname_curr = ''; if ($device['interfaces']) { foreach ($device['interfaces'] as $interface_id => $interface) { if ($interface['ipv4']) { foreach ($interface['ipv4'] as $ipv4_id => $ipv4) { if ($ipv4['links']) { foreach ($ipv4['links'] as $link_id => $link) { $loc2 = db_fetch_object(db_query('SELECT lat, lon, nick FROM {guifi_location} WHERE id=%d', $link['nid'])); $gDist = round($oGC->EllipsoidDistance($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon), 3); $item = _ipcalc($ipv4['ipv4'], $ipv4['netmask']); $ipdest = explode('.', $link['interface']['ipv4']['ipv4']); if ($gs->var['url'] != NULL) { $img_url = ' <img src=' . $gs->var['url'] . '?device=' . $link['device_id'] . '&type=availability&format=short>'; } else { $img_url = NULL; } $rows_cable[] = array($iname_curr != $interface['interface_type'] ? $interface['interface_type'] : null, array('data' => $link_id, 'align' => 'right'), l(guifi_get_hostname($link['device_id']), 'guifi/device/' . $link['device_id']), $link['interface']['interface_type'], $ipv4['ipv4'] . '/' . $item['maskbits'], '.' . $ipdest[3], array('data' => t($link['flag']) . $img_url, 'class' => $link['flag']), $link[routing]); $ltotal++; $iname_curr = $interface['interface_type']; } } else { $rows_cable[] = array($iname_curr != $interface['interface_type'] ? $interface['interface_type'] : null, null, null, null, $ipv4['ipv4'] . '/' . $item['maskbits']); $ltotal++; $iname_curr = $interface['interface_type']; } } } // foreach link $iname_curr = $interface['interface_type']; } } // foreach ipv4 if ($ltype == 'cable') { break; } } $header_cable = array(t('interface'), array('data' => t('id'), 'align' => 'right'), t('device'), t('remote<br>interface'), t('ip address'), ' ', t('status'), t('routing')); $header_wireless = array_merge($header_cable, array(t('kms.'), t('az.'))); $header_wireless[3] = t('node'); $output = ''; $attr = array('class' => 'list-links'); if ($rows_ap_client) { $output .= theme_box('<hr>' . t('ap/client'), theme_table($header_wireless, $rows_ap_client, $attr)); } if ($rows_wds) { $output .= theme_box('<hr>' . t('wds/p2p'), theme_table($header_wireless, $rows_wds, $attr)); } if ($rows_cable) { $output .= theme_box('<hr>' . t('cable'), theme_table($header_cable, $rows_cable, $attr)); } if ($output) { return '<h2>' . $title . '</h2>' . '<h3>' . t('Totals') . ': ' . $ltotal . ' ' . t('links') . ', ' . $dtotal . ' ' . t('kms.') . '</h3><br>' . $output; } else { return; } }
function theme_guifi_node_links_by_type($id = 0, $ltype = '%') { $oGC = new GeoCalc(); $total = 0; if ($ltype == '%') { $titlebox = t('links'); } else { $titlebox = t('links') . ' (' . $ltype . ')'; } $header = array(t('linked nodes (device)'), t('ip'), t('status'), t('kms.'), t('az.')); $listed = array('0'); $queryloc1 = db_query("SELECT c.id, l.id nid, l.nick, c.device_id, d.nick device_nick, a.ipv4 ip," . " c.flag, l.lat, l.lon, r.ssid " . "FROM {guifi_links} c " . " LEFT JOIN {guifi_devices} d ON c.device_id=d.id " . " LEFT JOIN {guifi_interfaces} i ON c.interface_id = i.id " . " LEFT JOIN {guifi_location} l ON d.nid = l.id " . " LEFT JOIN {guifi_ipv4} a ON i.id=a.interface_id " . " AND a.id=c.ipv4_id " . " LEFT JOIN {guifi_radios} r ON d.id=r.id " . " AND i.radiodev_counter=r.radiodev_counter " . "WHERE d.nid = %d AND link_type like '%s' " . "ORDER BY c.device_id, i.id", $id, $ltype); $devant = ' '; while ($loc1 = db_fetch_object($queryloc1)) { $queryloc2 = db_query("SELECT c.id, l.id nid, l.nick, r.ssid, c.device_id, d.nick device_nick, " . " a.ipv4 ip, l.lat, l.lon " . "FROM {guifi_links} c " . " LEFT JOIN {guifi_devices} d ON c.device_id=d.id " . " LEFT JOIN {guifi_interfaces} i ON c.interface_id = i.id " . " LEFT JOIN {guifi_location} l ON d.nid = l.id " . " LEFT JOIN {guifi_ipv4} a ON i.id=a.interface_id " . " AND a.id = c.ipv4_id " . " LEFT JOIN {guifi_radios} r ON d.id=r.id " . " AND i.radiodev_counter=r.radiodev_counter " . "WHERE c.id = %d " . " AND c.device_id <> %d " . " AND c.id NOT IN (%s)", $loc1->id, $loc1->device_id, implode(",", $listed)); $listed[] = $loc1->device_id; $devact = $loc1->device_nick; if ($loc1->ssid) { $devact .= ' - ' . $loc1->ssid; } while ($loc2 = db_fetch_object($queryloc2)) { $gDist = round($oGC->EllipsoidDistance($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon), 3); if ($gDist) { $total = $total + $gDist; $dAz = round($oGC->GCAzimuth($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon)); // Calculo orientacio if ($dAz < 23) { $dOr = t("N"); } else { if ($dAz < 68) { $dOr = t("NE"); } else { if ($dAz < 113) { $dOr = t("E"); } else { if ($dAz < 158) { $dOr = t("SE"); } else { if ($dAz < 203) { $dOr = t("S"); } else { if ($dAz < 248) { $dOr = t("SW"); } else { if ($dAz < 293) { $dOr = t("W"); } else { if ($dAz < 338) { $dOr = t("NW"); } else { $dOr = t("N"); } } } } } } } } } else { $gDist = 'n/a'; } if ($loc1->nid != $loc2->nid) { $cr = db_fetch_object(db_query("SELECT count(*) count FROM {guifi_radios} r WHERE id=%d", $loc2->device_id)); if ($cr->count > 1) { $dname = $loc2->device_nick . '/' . $loc2->ssid; } else { $dname = $loc2->device_nick; } $linkname = $loc1->id . '-' . '<a href=' . base_path() . 'node/' . $loc2->nid . '>' . $loc2->nick . '</a> (<a href=' . base_path() . 'guifi/device/' . $loc2->device_id . '>' . $dname . '</a>)'; } else { $linkname = $loc1->id . '-' . '<a href=' . base_path() . 'guifi/device/' . $loc1->device_id . '>' . $loc1->device_nick . '</a>/<a href=' . base_path() . 'guifi/device/' . $loc2->device_id . '>' . $loc2->device_nick . '</a>'; } $status_url = guifi_cnml_availability(array('device' => $loc2->device_id, 'format' => 'short')); if ($devant != $devact) { $devant = $devact; $rows[] = array(array('data' => '<b><a href=' . base_path() . 'guifi/device/' . $loc1->device_id . '>' . $devact . '</a></b>', 'colspan' => 5)); } $rows[] = array($linkname, $loc1->ip . '/' . $loc2->ip, array('data' => t($loc1->flag) . $status_url, 'class' => $loc1->flag), array('data' => $gDist, 'class' => 'number'), $dAz . '-' . $dOr); } // whhile loc2 } // while loc1 if (count($rows)) { $output .= theme('table', $header, $rows, array('class' => 'device-data')); if ($total) { $output .= t('Total:') . ' ' . $total . ' ' . t('kms.'); } } else { if ($ltype == '%') { $output .= '<p align="right">' . t('No links defined') . '</p>'; } else { return; } } // $output .= '<p align="right">'. // t('No %type links defined', // array('%type' => $ltype)). // '</p>'; return theme('box', $titlebox, $output); }
function guifi_list_services_query($param, $typestr = 'by zone', $service = '%') { $rows = array(); $sqlprefix = "SELECT s.*,z.title zonename " . "FROM {guifi_services} s " . " LEFT JOIN {guifi_devices} d ON s.device_id=d.id " . " LEFT JOIN {guifi_zone} z ON s.zone_id=z.id " . " LEFT JOIN {guifi_location} l ON d.nid=l.id " . "WHERE "; switch ($typestr) { case t('by zone'): $childs = guifi_zone_childs($param->id); $sqlwhere = sprintf('s.zone_id IN (%s) ', implode(',', $childs)); break; case t('by node'): $sqlwhere = sprintf('d.nid = %d ', $param->nid); break; case t('by device'): $sqlwhere = sprintf('d.id = %d ', $param); break; } $query = db_query($sqlprefix . $sqlwhere . ' ORDER BY s.service_type, s.zone_id, s.nick'); $current_service = ''; while ($service = db_fetch_object($query)) { $node = node_load(array('nid' => $service->id)); if ($current_service != $service->service_type) { $typedescr = db_fetch_object(db_query("SELECT * FROM {guifi_types} WHERE type='service' AND text = '%s'", $service->service_type)); $rows[] = array('<strong>' . t($typedescr->description) . '</strong>', NULL, NULL, NULL, NULL); $current_service = $service->service_type; } $status_url = guifi_cnml_availability(array('device' => $service->device_id, 'format' => 'short')); $rows[] = array('<a href="' . base_path() . 'node/' . $service->id . '">' . $node->title . '</a>', '<a href="' . base_path() . 'node/' . $service->zone_id . '">' . $service->zonename . '</a>', '<a href="' . base_path() . 'guifi/device/' . $service->device_id . '">' . guifi_get_hostname($service->device_id) . '</a>', array('data' => t($node->status_flag), 'class' => $node->status_flag), $status_url); } return array_merge($rows); }
function _guifi_user_queue_devices($u) { $query = db_query('SELECT d.id ' . 'FROM {guifi_devices} d ' . 'WHERE d.nid=%d' . ' AND type="radio"', $u['nid']); $rows = array(); while ($d = db_fetch_array($query)) { $d = guifi_device_load($d['id']); $d['uid'] = $u['id']; if (guifi_device_access('update', $d['id'])) { $edit_device_icon = l(guifi_img_icon('edit.png'), 'guifi/device/' . $d['id'] . '/edit', array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'guifi/device/' . $d['id'] . '/delete', array('html' => TRUE, 'attributes' => array('target' => '_blank'))); } else { $edit_device_icon = ''; } if (user_access('administer guifi users')) { $edit_ok_icon = drupal_get_form('_guifi_user_queue_device_form', $d); } else { $edit_ok_icon = $d['flag']; if (count($d['radios']) == 1 and $d['radios'][0]['mode'] == 'client') { $edit_ok_icon .= ' ' . $d['radios'][0]['mac']; } } $ip = guifi_main_ip($d['id']); $status_url = guifi_cnml_availability(array('device' => $d['id'], 'format' => 'short')); $rows[] = array($edit_device_icon . l($d['nick'], 'guifi/device/' . $d['id'], array('attributes' => array('target' => '_blank'))), array('data' => l($ip['ipv4'] . '/' . $ip['maskbits'], guifi_device_admin_url($d, $ip['ipv4']), array('attributes' => array('title' => t('Connect to the device on a new window'), 'target' => '_blank'))), 'align' => 'right'), array('data' => $edit_ok_icon, 'class' => $d['flag']), array('data' => $status_url, 'class' => $d['flag'])); } return $rows; }
function _guifi_zone_availability_devices($nid) { $oneyearfromnow = time() - '31622400'; $qry = db_query('SELECT d.id did, d.nick dnick, d.flag dflag, d.timestamp_changed changed ' . 'FROM {guifi_devices} d ' . 'WHERE d.type = "radio" ' . ' AND d.nid=%d ' . 'ORDER BY d.nick', $nid); $rows = array(); while ($d = db_fetch_array($qry)) { $dev = guifi_device_load($d['did']); if (guifi_device_access('update', $dev)) { $edit = l(guifi_img_icon('edit.png'), 'guifi/device/' . $d['did'] . '/edit', array('html' => TRUE, 'attributes' => array('title' => t('edit device'), 'target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'guifi/device/' . $d['did'] . '/delete', array('html' => TRUE, 'attributes' => array('title' => t('delete device'), 'target' => '_blank'))); } else { $edit = NULL; } $ip = guifi_main_ip($d['did']); $status_url = guifi_cnml_availability(array('device' => $d['did'], 'format' => 'long')); if (!empty($d['changed'])) { if ($d['changed'] < $oneyearfromnow) { $dchanged = array('data' => '<b><font color="#AA0000">' . format_date($d['changed'], 'custom', t('d/m/Y')) . '</font></b>'); } else { $dchanged = array('data' => format_date($d['changed'], 'custom', t('d/m/Y'))); } } else { $dchanged = array('data' => t('never changed')); } $rows[] = array(array('data' => $edit . l($d['dnick'], 'guifi/device/' . $d['did'])), array('data' => l($ip['ipv4'] . '/' . $ip['maskbits'], guifi_device_admin_url($d['did'], $ip['ipv4']), array('attributes' => array('title' => t('Connect to the device on a new window'), 'target' => '_blank'))), 'align' => 'right'), array('data' => $d['dflag'] . $status_url, 'class' => $d['dflag']), $dchanged); } guifi_log(GUIFILOG_TRACE, 'function guifi_zone_availability_device()', $rows); return $rows; }