/** * guifi_csvproxy **/ function guifi_csvproxy($zoneid, $action = 'help') { // load nodes and zones in memory for faster execution $searchStatusFlag = 'Working'; $searchServiceType = 'Proxy'; $subzoneIds = implode(guifi_zone_childs($zoneid), ','); $sql_services = sprintf("SELECT\n s.nick,\n s.extra,\n z.title as ZoneTitle\n FROM guifi_services s,\n guifi_zone z\n WHERE\n s.status_flag = '%s'\n AND s.zone_id = z.id\n AND s.service_type = '%s'\n AND (s.zone_id = %s or s.zone_id in (%s))\n ORDER BY ZoneTitle asc, s.timestamp_created ASC", $searchStatusFlag, $searchServiceType, $zoneid, $subzoneIds); drupal_set_header('Content-Type: text/csv; charset=utf-8'); $qservices = db_query($sql_services); while ($service = db_fetch_object($qservices)) { if (!empty($service->extra)) { $extraData = unserialize($service->extra); if (isset($extraData['proxy']) && isset($extraData['port']) && $extraData['proxy'] != '' && $extraData['port'] != '') { echo $service->nick . ";" . $extraData['proxy'] . ";" . $extraData['port'] . "\n"; } } } }
function budgets_supplier_list_budgets_by_supplier($supplier, $params = null) { guifi_log(GUIFILOG_TRACE, 'list_budgets_by_supplier (supplier)', $supplier); $btypes = guifi_types('budget_type'); $bstatus = guifi_types('budget_status'); if (empty($params)) { $vars['details'][0] = 'detailed'; $vars['url'][0] = 'budgets'; $vars['id'][0] = $supplier->id; $vars['types'] = array_keys($btypes); $vars['status'] = array_keys($bstatus); $vars['from'] = array_combine(array('year', 'month', 'day'), explode(' ', date('Y n j', time() - 60 * 60 * 24 * 365))); $vars['to'] = array_combine(array('year', 'month', 'day'), explode(' ', date('Y n j'))); } else { $p = explode(',', $params); foreach ($p as $v) { $v = explode('=', $v); if ($v[0] == 'from' or $v[0] == 'to') { $vars[$v[0]] = array_combine(array('year', 'month', 'day'), explode('|', $v[1])); } else { $vars[$v[0]] = explode('|', $v[1]); } } $vars['id'][0] = $supplier->id; } guifi_log(GUIFILOG_TRACE, 'budgets_by_supplier (zone)', $vars); $output = drupal_get_form('budgets_list_form', $vars); $where = ''; if (!empty($vars['zone_id'][0])) { $zlist = guifi_zone_childs($vars['zone_id'][0]); $where .= ' AND (b.zone_id IN (' . implode(',', $zlist) . ')) '; } if (!empty($vars['location_id'][0])) { $where .= ' AND b.node_id =' . $vars['location_id'][0] . ' '; } if ($vars['types']) { $where .= " AND b.budget_type in ('" . implode("','", $vars['types']) . "') "; } if ($vars['status']) { $where .= " AND b.budget_status in ('" . implode("','", $vars['status']) . "') "; } $f = mktime(0, 0, 0, $vars['from']['month'], $vars['from']['day'], $vars['from']['year']); $where .= sprintf(' AND IFNULL(b.accdate,b.expires) >= %d', $f); $t = mktime(23, 59, 59, $vars['to']['month'], $vars['to']['day'], $vars['to']['year']); $where .= sprintf(' AND IFNULL(b.accdate,b.expires) <= %d ', $t); $qquery = 'SELECT b.id, b.accdate ' . 'FROM {budgets} b ' . 'WHERE b.supplier_id=' . $supplier->id . ' ' . $where . 'ORDER BY b.accdate desc '; guifi_log(GUIFILOG_TRACE, 'list_budgets_by_supplier (budgets query)', $qquery); $query = db_query($qquery); $subtotals = array(); $time_subtotals = array(); while ($s = db_fetch_object($query)) { $budget = node_load(array('nid' => $s->id)); $subtotals[$budget->supplier_id] += $budget->total; if (is_null($s->accdate)) { $tdate = $budget->expires; } else { $tdate = $budget->accdate; } $time_subtotals[date('Y', $tdate)][date('n', $tdate)][$budget->supplier_id] += $budget->total; if (budgets_access('view', $budget)) { if ($vars['details'][0] == 'detailed') { $doutput .= node_view($budget, TRUE, FALSE, TRUE); } } } $output .= budgets_list_totals($subtotals, $vars) . budgets_list_monthly_totals($subtotals, $time_subtotals, $vars) . $doutput; //theme('pager', NULL, variable_get('default_nodes_main', 10)); // drupal_set_breadcrumb(guifi_zone_ariadna($zone->id,'node/%d/view/suppliers')); // $output .= theme_pager(NULL, variable_get("guifi_pagelimit", 50)); // $node = node_load(array('nid' => $zone->id)); // $output .= theme_links(module_invoke_all('link', 'node', $node, FALSE)); print theme('page', $output, FALSE); return; }
function guifi_stats_chart07() { include drupal_get_path('module', 'guifi') . '/contrib/phplot/phplot.php'; $gDirTTFfonts = drupal_get_path('module', 'guifi') . '/contrib/fonts/'; if (isset($_GET['width'])) { $gwidth = $_GET['width']; } else { $gwidth = 500; } if (isset($_GET['height'])) { $gheight = $_GET['height']; } else { $gheight = 450; } $today = getdate(); $year = $today[year]; $month = $today[mon]; $month = $month - 12; $n = 0; $tot = 0; if ($month < 1) { $year = $year - 1; $month = 12 + $month; } $datemin = mktime(0, 0, 0, $month, 1, $year); if (isset($_GET['zone'])) { $zone_id = $_GET['zone']; if ($zone_id == "0") { $zone_id = "0"; } //"3671"; } else { $zone_id = "0"; } $avalue = array(); $adata = array(); for ($i = 0; $i < 10; $i++) { $adata[] = array(0, 0); } $vsql = "select sum(if(timestamp_created >= " . $datemin . ",1,0)) as num, count(*) as total, zone_id\n from {guifi_location}\n where status_flag='Working' "; if ($zone_id != "0") { $achilds = guifi_zone_childs($zone_id); $v = ""; foreach ($achilds as $key => $child) { if ($v == "") { $v .= "zone_id=" . $child; } else { $v .= " or zone_id=" . $child; } } $vsql .= "AND (" . $v . ") "; } $vsql .= "GROUP BY zone_id "; $result = db_query($vsql); while ($record = db_fetch_object($result)) { if ($record->total >= 20) { $vn = $record->num / $record->total * 100; $vmin = 0; for ($i = 1; $i < 10; $i++) { if ($adata[$vmin][1] > $adata[$i][1]) { $vmin = $i; } } if ($vn > $adata[$vmin][1]) { $adata[$vmin][0] = $record->zone_id; $adata[$vmin][1] = $vn; } } } for ($i = 0; $i < 10; $i++) { if ($adata[$i][1] != 0) { $avalue[$adata[$i][0]] = $adata[$i][1]; } } arsort($avalue); foreach ($avalue as $key => $value) { if ($value != 0) { $data[] = array(substr(guifi_get_zone_name($key), 0, 20) . " �", $value); } } $shapes = array('none'); $plot = new PHPlot($gwidth, $gheight); $plot->SetPlotAreaWorld(0, 0, NULL, NULL); $plot->SetFileFormat('png'); $plot->SetDataType("text-data"); $plot->SetDataValues($data); $plot->SetPlotType("bars"); $plot->SetXTickIncrement(1); $plot->SetSkipBottomTick(TRUE); $plot->SetSkipLeftTick(TRUE); $plot->SetTickLength(0); //$plot->SetXTickPos('none'); $plot->SetYDataLabelPos('plotin'); $plot->SetYLabelType('data', 0); $plot->SetTickColor('grey'); $plot->SetTTFPath($gDirTTFfonts); $plot->SetFontTTF('title', 'Vera.ttf', 12); $plot->SetFontTTF('x_label', 'Vera.ttf', 8); if (isset($_GET['title'])) { $plot->SetTitle("guifi.net \n" . t($_GET['title'])); } else { if ($zone_id == "0") { $plot->SetTitle("guifi.net \n" . t('Largest annual increase')); } else { $plot->SetTitle("guifi.net " . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Largest annual increase')); } } //$plot->SetXTitle(t('Zones')); $plot->SetYTitle(t('% increase')); $plot->SetXDataLabelPos('plotdown'); //$plot->SetXLabelAngle(45); $plot->SetXDataLabelAngle(75); $plot->SetGridColor('red'); $plot->SetPlotBorderType('left'); $plot->SetDataColors(array('orange')); $plot->SetTextColor('DimGrey'); $plot->SetTitleColor('DimGrey'); $plot->SetLightGridColor('grey'); $plot->SetBackgroundColor('white'); $plot->SetTransparentColor('white'); $plot->SetIsInline(TRUE); $plot->DrawGraph(); }
function guifi_users_queue($zone) { function _guifi_user_queue_device_form($form_state, $d = array()) { guifi_log(GUIFILOG_TRACE, 'function guifi_user_queue_device_form()', $d); if (count($d['radios']) != 1) { return; } if ($d['radios'][0]['mode'] != 'client') { return; } if (!isset($d['radios'][0]['interfaces'])) { return; } $iid = key($d['radios'][0]['interfaces']); if (!isset($d['radios'][0]['interfaces'][$iid]['ipv4'][0]['links'])) { return; } $lid = key($d['radios'][0]['interfaces'][$iid]['ipv4'][0]['links']); if (empty($iid) or empty($lid)) { return; } if (empty($form_state['values'])) { $form_state['values'] = $d; } $f['flag'] = array('#type' => 'item', '#value' => $form_state['values']['flag'], '#prefix' => '<table><tr><td>', '#suffix' => '</td>'); $f['mac'] = array('#type' => 'textfield', '#required' => TRUE, '#size' => 17, '#maxlength' => 17, '#default_value' => $form_state['values']['radios'][0]['mac'], '#element_validate' => array('guifi_mac_validate'), '#prefix' => '<td>', '#suffix' => '</td>'); $f['did'] = array('#type' => 'hidden', '#value' => $form_state['values']['id']); $f['nid'] = array('#type' => 'hidden', '#value' => $form_state['values']['nid']); $f['uid'] = array('#type' => 'hidden', '#value' => $form_state['values']['uid']); $f['iid'] = array('#type' => 'hidden', '#value' => $iid); $f['lid'] = array('#type' => 'hidden', '#value' => $lid); $f['approve'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/ok.png', '#attributes' => array('title' => t('Set the device and link Online, confirm MAC & approve user.')), '#prefix' => '<td>', '#suffix' => '</td></tr></table>'); return $f; } function _guifi_user_queue_form($form_state, $params = array()) { guifi_log(GUIFILOG_TRACE, 'function guifi_user_queue_form()', $params); if (empty($form_state['values'])) { $form_state['values'] = $params; } $f['status'] = array('#type' => 'select', '#options' => guifi_types('user_status'), '#default_value' => $form_state['values']['status'], '#prefix' => '<table><tr><td>', '#suffix' => '</td>'); $f['uid'] = array('#type' => 'hidden', '#value' => $form_state['values']['id']); $f['saveUser'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/save.png', '#attributes' => array('title' => t('Change & Save users Status.')), '#submit' => array('_guifi_user_queue_device_form_submit'), '#prefix' => '<td>', '#suffix' => '</td></tr></table>'); return $f; } 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; } global $user; $owner = $user->uid; guifi_log(GUIFILOG_TRACE, 'function guifi_users_node_list()', $zone); drupal_set_breadcrumb(guifi_zone_ariadna($zone->id, 'node/%d/view/userqueue')); $title = t('Queue of pending users @') . ' ' . $zone->title; drupal_set_title($title); $childs = guifi_zone_childs($zone->id); $childs[] = $zone->id; $sql = 'SELECT ' . ' u.*, l.id nid, l.nick nnick, l.status_flag nflag, l.zone_id ' . 'FROM {guifi_users} u, {guifi_location} l ' . 'WHERE u.nid=l.id' . ' AND (l.status_flag != "Working" OR u.status != "Approved") ' . ' AND l.zone_id IN (' . implode(',', $childs) . ') ' . 'ORDER BY FIND_IN_SET(u.status,"New,Pending,Approved,Rejected"),' . ' u.timestamp_created'; $query = pager_query($sql, variable_get("guifi_pagelimit", 50)); $rows = array(); $nrow = 0; if (user_access('administer guifi networks') || user_access('administer guifi zones') || user_access('administer guifi users')) { $administer = TRUE; } else { $administer = FALSE; } while ($u = db_fetch_array($query)) { $pUser = (object) guifi_user_load($u['id']); $proxy = node_load(array('nid' => $pUser->services['proxy'])); $srows = _guifi_user_queue_devices($u); $nsr = count($srows); if (empty($nsr)) { $nsr = 1; } $node = node_load(array('nid' => $u['nid'])); if (guifi_node_access('update', $node)) { $edit_node_icon = l(guifi_img_icon('edit.png'), 'node/' . $u['nid'] . '/edit', array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'node/' . $u['nid'] . '/delete', array('html' => TRUE, 'attributes' => array('target' => '_blank'))); } else { $edit_node_icon = ''; } if (guifi_user_access('update', $u)) { $edit_user_icon = l(guifi_img_icon('edit.png'), 'guifi/user/' . $u['id'] . '/edit', array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'guifi/user/' . $u['id'] . '/delete', array('html' => TRUE, 'attributes' => array('target' => '_blank'))); } else { $edit_user_icon = ''; } if ($administer) { $edit_user_form = drupal_get_form('_guifi_user_queue_form', $u); } else { $edit_user_form = $u['status']; } if (user_access('administer guifi users') or $node->uid == $owner) { $rn3 = $u['lastname'] . ", " . $u['firstname']; $u3 = $u['username']; } else { $rn3 = ereg_replace("_", " ", $u['lastname'] . ", " . $u['firstname']); if (strlen($rn3) > 3) { $rn3 = substr($u['lastname'] . ", " . $u['firstname'], 0, 3); $rn3 .= ".."; } $u3 = $u['username']; if (strlen($u3) > 3) { $u3 = substr($u['username'], 0, 5); $u3 .= ".."; } } $rows[] = array(array('data' => $edit_user_icon . l($u3, 'node/' . $u['nid'] . '/view/users', array('attributes' => array('title' => $rn3, 'target' => '_blank'))) . "\n<br />" . '<small>' . format_date($u['timestamp_created']) . '<br />' . l($proxy->nick, "node/" . $proxy->id, array('attributes' => array('title' => $proxy->title))), 'rowspan' => $nsr), array('data' => guifi_get_zone_nick($u['zone_id']) . "<br /><strong>" . $edit_node_icon . l($u['nnick'], 'node/' . $u['nid'], array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . '</strong><br /><small>' . l(t('add a comment'), 'comment/reply/' . $u['nid'], array('fragment' => 'comment-form', 'html' => TRUE, 'attributes' => array('title' => t('Add a comment to the page of this node'), 'target' => '_blank'))) . '</small>', 'class' => $u['nflag'], 'rowspan' => $nsr), array('data' => $edit_user_form, 'rowspan' => $nsr)); end($rows); $krow = key($rows); if (count($srows)) { // merge current row with first element $rows[$krow] = array_merge($rows[$krow], array_shift($srows)); // adding rest og the elements foreach ($srows as $k => $v) { $rows[] = $v; } } } $header = array(t('Username'), t('Node'), t('User status'), t('Device'), t('IP v4 address'), t('Status & MAC'), t('Current status')); $output .= theme('table', $header, $rows); $output .= theme_pager(NULL, variable_get("guifi_pagelimit", 50)); // Full screen (no lateral bars, etc...) print theme('page', $output, FALSE); // If normal output, retrurn $output... }
function guifi_gml_links($zid, $type) { $oGC = new GeoCalc(); $minx = 180; $miny = 90; $maxx = -180; $maxy = -90; $res = db_query("SELECT id,link_type,flag " . "FROM {guifi_links} " . "WHERE link_type != 'cable' " . "GROUP BY 1,2 " . "HAVING count(*) = 2"); $zchilds = guifi_zone_childs($zid); $zchilds[$zid] = 'Top'; while ($row = db_fetch_object($res)) { $resnode = db_query("SELECT n.id, n.zone_id, n.nick,n.lat, n.lon, n.status_flag " . "FROM {guifi_links} l, {guifi_location} n " . "WHERE l.id = %d AND l.nid=n.id", $row->id); $nl = array(); while ($n = db_fetch_object($resnode)) { $nl[] = $n; } if (count($nl) == 2) { if (in_array($nl[0]->zone_id, $zchilds) || in_array($nl[1]->zone_id, $zchilds)) { $distance = round($oGC->EllipsoidDistance($nl[0]->lat, $nl[0]->lon, $nl[1]->lat, $nl[1]->lon), 3); $status = $row->flag; if ($type == 'gml') { $output .= ' <gml:featureMember> <dlinks fid="' . $row->id . '"> <NODE1_ID>' . $nl[0]->id . '</NODE1_ID> <NODE1_NAME>' . $nl[0]->nick . '</NODE1_NAME> <NODE2_ID>' . $nl[1]->id . '</NODE2_ID> <NODE2_NAME>' . $nl[1]->nick . '</NODE2_NAME> <KMS>' . $distance . '</KMS> <LINK_TYPE>' . $row->link_type . '</LINK_TYPE> <STATUS>' . $status . '</STATUS> <ogr:geometryProperty><gml:LineString><gml:coordinates>' . $nl[0]->lon . ',' . $nl[0]->lat . ' ' . $nl[1]->lon . ',' . $nl[1]->lat . '</gml:coordinates></gml:LineString></ogr:geometryProperty> </dlinks> </gml:featureMember>'; } else { $output .= $row->id . ',' . $nl[0]->id . ',' . $nl[0]->nick . ',' . $nl[1]->id . ',' . $nl[1]->nick . ',' . $distance . ',' . $row->link_type . ',' . $status . ',' . $nl[0]->lon . ',' . $nl[0]->lat . ',' . $nl[1]->lon . ',' . $nl[1]->lat . "\n"; } if ($nl[0]->lon > $maxx) { $maxx = $nl[0]->lon; } if ($nl[0]->lat > $maxy) { $maxy = $nl[0]->lat; } if ($nl[0]->lon < $minx) { $minx = $nl[0]->lon; } if ($nl[0]->lat < $miny) { $miny = $nl[0]->lat; } if ($nl[1]->lon > $maxx) { $maxx = $nl[1]->lon; } if ($nl[1]->lat > $maxy) { $maxy = $nl[1]->lat; } if ($nl[1]->lon < $minx) { $minx = $nl[1]->lon; } if ($nl[1]->lat < $miny) { $miny = $nl[1]->lat; } } } } drupal_set_header('Content-Type: application/xml; charset=utf-8'); if ($type == 'gml') { print '<?xml version="1.0" encoding="utf-8" ?> <ogr:FeatureCollection xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance" xsi:schemaLocation=". dlinks.xsd" xmlns:ogr="http://ogr.maptools.org/" xmlns:gml="http://www.opengis.net/gml"> <gml:boundedBy> <gml:Box> <gml:coord><gml:X>' . $minx . '</gml:X><gml:Y>' . $miny . '</gml:Y></gml:coord> <gml:coord><gml:X>' . $maxx . '</gml:X><gml:Y>' . $maxy . '</gml:Y></gml:coord> </gml:Box> </gml:boundedBy>'; } print $output; if ($type == 'gml') { print '</ogr:FeatureCollection>'; } }
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_ipv4_print_data($zone, $list = 'parents', $ips_allocated) { global $user; $header = array(array('data' => t('network')), t('start / end'), array('data' => t('hosts'), 'style' => 'text-align: right;'), t('type'), t('min / max'), array('data' => t('ips used'), 'style' => 'text-align: right;'), array('data' => t('used %'), 'style' => 'text-align: right;')); if (user_access('administer guifi networks')) { $header = array_merge($header, array(t('operations'))); } if ($list == 'childs') { $zones = guifi_zone_childs($zone->id); $pager = 1; $k = array_search($zone->id, $zones); unset($zones[$k]); } else { $zones = guifi_zone_get_parents($zone->id); $pager = 0; } if (empty($zones)) { return t('There is no zones to look at'); } $sql = 'SELECT zone, id, base, mask, network_type FROM {guifi_networks} WHERE zone IN (' . implode(',', $zones) . ') ORDER BY FIND_IN_SET(zone,"' . implode(',', $zones) . '")'; $rows = array(); $result = pager_query($sql, variable_get('guifi_pagelimit', 10)); $current_zoneid = -1; while ($net = db_fetch_object($result)) { $item = _ipcalc($net->base, $net->mask); // obtaing the used ip's $min = ip2long($item['netstart']); $max = ip2long($item['netend']); $ips = 0; $k = $min; $amin = NULL; $amax = NULL; while ($k <= $max) { if (isset($ips_allocated[$k])) { $ips++; $amax = $k; if ($ips == 1) { $amin = $k; } } $k++; } if ($current_zoneid != $net->zone) { $current_zoneid = $net->zone; $rows[] = array(array('data' => l(guifi_get_zone_name($net->zone), 'node/' . $net->zone . '/view/ipv4'), 'colspan' => '0')); } $row = array($net->base . '/' . $item['maskbits'] . ' (' . $net->mask . ')', $item['netstart'] . ' / ' . $item['netend'], array('data' => number_format($item['hosts']), 'align' => 'right'), $net->network_type, long2ip($amin) . ' / ' . long2ip($amax), array('data' => number_format($ips), 'align' => 'right'), array('data' => round($ips * 100 / $item['hosts']) . '%', 'align' => 'right')); if (user_access('administer guifi networks')) { $row[] = array('data' => l(guifi_img_icon('edit.png'), 'guifi/ipv4/' . $net->id . '/edit', array('html' => TRUE, 'title' => t('edit network'), 'attributes' => array('target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'guifi/ipv4/' . $net->id . '/delete', array('html' => TRUE, 'title' => t('delete device'), 'attributes' => array('target' => '_blank'))), 'align' => 'center'); } $rows[] = $row; } if (count($rows)) { $output .= theme('table', $header, $rows); $output .= theme('pager', NULL, variable_get('guifi_pagelimit', 10)); } else { $output .= t('None'); } return $output; }
function theme_guifi_zone_nodes($node, $links = TRUE) { if (!isset($node->id)) { $node->id = $node->nid; } $output = '<h2>' . t('Nodes listed at') . ' ' . $node->title . '</h2>'; // Going to list child zones totals $result = db_query('SELECT z.id, z.title FROM {guifi_zone} z WHERE z.master = %d ORDER BY z.weight, z.title', $node->id); $rows = array(); $header = array(array('data' => t('Zone name')), array('data' => t('Online'), NULL, NULL, 'style' => 'text-align: right'), array('data' => t('Planned'), NULL, NULL, 'style' => 'text-align: right'), array('data' => t('Building'), NULL, NULL, 'style' => 'text-align: right'), array('data' => t('Testing'), NULL, NULL, 'style' => 'text-align: right'), array('data' => t('Inactive'), NULL, NULL, 'style' => 'text-align: right'), array('data' => t('Total'), NULL, NULL, 'style' => 'text-align: right')); while ($zone = db_fetch_object($result)) { $summary = guifi_zone_totals(guifi_zone_childs($zone->id)); $rows[] = array(array('data' => guifi_zone_l($zone->id, $zone->title, 'node/'), 'class' => 'zonename'), array('data' => number_format($summary['Working'], 0, NULL, variable_get('guifi_thousand', '.')), 'class' => 'Working', 'align' => 'right'), array('data' => number_format($summary['Planned'], 0, NULL, variable_get('guifi_thousand', '.')), 'class' => 'Planned', 'align' => 'right'), array('data' => number_format($summary['Building'], 0, NULL, variable_get('guifi_thousand', '.')), 'class' => 'Building', 'align' => 'right'), array('data' => number_format($summary['Testing'], 0, NULL, variable_get('guifi_thousand', '.')), 'class' => 'Testing', 'align' => 'right'), array('data' => number_format($summary['Inactive'], 0, NULL, variable_get('guifi_thousand', '.')), 'class' => 'Inactive', 'align' => 'right'), array('data' => number_format($summary['Total'], 0, NULL, variable_get('guifi_thousand', '.')), 'class' => 'Total', 'align' => 'right')); if (!empty($summary)) { foreach ($summary as $key => $sum) { $totals[$key] = $totals[$key] + $sum; } } } $rows[] = array(array('data' => NULL, 'class' => 'zonename'), array('data' => number_format($totals['Working'], 0, NULL, variable_get('guifi_thousand', '.')), 'class' => 'Online', 'align' => 'right'), array('data' => number_format($totals['Planned'], 0, NULL, variable_get('guifi_thousand', '.')), 'class' => 'Planned', 'align' => 'right'), array('data' => number_format($totals['Building'], 0, NULL, variable_get('guifi_thousand', '.')), 'class' => 'Building', 'align' => 'right'), array('data' => number_format($totals['Testing'], 0, NULL, variable_get('guifi_thousand', '.')), 'class' => 'Testing', 'align' => 'right'), array('data' => number_format($totals['Inactive'], 0, NULL, variable_get('guifi_thousand', '.')), 'class' => 'Inactive', 'align' => 'right'), array('data' => number_format($totals['Total'], 0, NULL, variable_get('guifi_thousand', '.')), 'class' => 'Total', 'align' => 'right')); if (count($rows) > 1) { $output .= theme('table', $header, $rows); } // Going to list the zone nodes $rows = array(); $result = pager_query(' SELECT l.id,l.nick, l.notification, l.zone_description, l.status_flag, count(*) radios FROM {guifi_location} l LEFT JOIN {guifi_radios} r ON l.id = r.nid WHERE l.zone_id = %d GROUP BY 1,2,3,4,5 ORDER BY radios DESC, l.nick', 50, 0, 'SELECT count(*) FROM {guifi_location} WHERE zone_id = %d', $node->id); $header = array(array('data' => t('nick (shortname)')), array('data' => t('supernode')), array('data' => t('area')), array('data' => t('status'))); while ($loc = db_fetch_object($result)) { if ($loc->radios == 1) { $loc->radios = t('No'); } $rows[] = array(array('data' => guifi_zone_l($loc->id, $loc->nick, 'node/')), array('data' => $loc->radios), array('data' => $loc->zone_description), array('data' => t($loc->status_flag), 'class' => $loc->status_flag)); } if (count($rows) > 0) { $output .= theme('table', $header, $rows); $output .= theme_pager(NULL, 50); } if ($links) { drupal_set_breadcrumb(guifi_zone_ariadna($node->id, 'node/%d/view/nodes')); $node = node_load(array('nid' => $node->id)); $output .= theme_links(module_invoke_all('link', 'node', $node, FALSE)); print theme('page', $output, FALSE); return; } return $output; }