function guifi_devel_paramusc($id = null, $op = null) { switch ($id) { case 'add': $id = 'New'; return drupal_get_form('guifi_devel_paramusc_form', $id); } switch ($op) { case 'edit': return drupal_get_form('guifi_devel_paramusc_form', $id); case 'delete': guifi_log(GUIFILOG_TRACE, 'guifi_devel_paramusc_delete()', $id); return drupal_get_form('guifi_devel_paramusc_delete_confirm', $id); guifi_devel_paramusc_delete($id); } $rows = array(); $value = t('Add a new firmware parameter'); $output = '<from>'; $output .= '<input type="button" id="button" value="' . $value . '" onclick="location.href=\'/guifi/menu/devel/parameter/add\'"/>'; $output .= '</form>'; $headers = array(t('ID'), t('Parameter'), t('Origen'), t('Edit'), t('Delete')); $sql = db_query('SELECT * FROM {guifi_parametres}'); while ($parameter = db_fetch_object($sql)) { $rows[] = array($parameter->id, $parameter->nom, $parameter->origen, l(guifi_img_icon('edit.png'), 'guifi/menu/devel/parameter/' . $parameter->id . '/edit', array('html' => TRUE, 'title' => t('edit parameter'))) . '</td><td>' . l(guifi_img_icon('drop.png'), 'guifi/menu/devel/parameter/' . $parameter->id . '/delete', array('html' => TRUE, 'title' => t('delete parameter')))); } $output .= theme('table', $headers, $rows); print theme('page', $output, FALSE); return; }
function theme_guifi_node_devices_list($node, $links = FALSE) { $id = $node->id; $rows = array(); $header = array('<h2>' . t('device') . '</h2>', t('type'), t('ip'), t('status'), array('data' => t('last available'), 'style' => 'text-align: right;'), t('unsolclic')); // Form for adding a new device $form = drupal_get_form('guifi_device_create_form', $node); $query = db_query("SELECT d.id FROM {guifi_devices} d WHERE nid=%d", $id); while ($d = db_fetch_object($query)) { $device = guifi_device_load($d->id); // Edit and delete buttons if (guifi_device_access('update', $device['id'])) { $edit_device = l(guifi_img_icon('edit.png'), 'guifi/device/' . $device['id'] . '/edit', array('html' => TRUE, 'attributes' => array('target' => '_blank', 'title' => t('edit device')))); $delete_device = l(guifi_img_icon('drop.png'), 'guifi/device/' . $device['id'] . '/delete', array('html' => TRUE, 'attributes' => array('target' => '_blank', 'title' => t('delete device')))); } else { $edit_device = ''; $delete_device = ''; } // Traceroute button if (user_access('create guifi nodes')) { $traceroute = l(guifi_img_icon('discover-routes.png'), 'guifi/menu/ip/traceroute/' . $device['id'], array('html' => TRUE, 'attributes' => array('target' => '_blank', 'title' => t('trace routes, discover services from this device')))); } else { $traceroute = ''; } // Firmware text which links to unsolclic feature if ($device->variable['firmware'] != "n/d") { $unsolclic = l($device[variable]['firmware'], 'guifi/device/' . $device['id'] . '/view/unsolclic', array('attributes' => array('title' => t("Get radio configuration with singleclick")))); } // Get IP assigned to the device $ip = guifi_main_ip($device[id]); // Availability image $status_url = guifi_cnml_availability(array('device' => $device['id'], 'format' => 'short')); // Device main attributes if (!empty($device['manufacturer'])) { $mDescr = $device['manufacturer'] . '-' . $device['model']; } else { $mDescr = ''; } $uCreated = db_fetch_object(db_query('SELECT u.name FROM {users} u WHERE u.uid = %d', $device[user_created])); $deviceAttr = $device[id] . ' ' . $mDescr . ' ' . t('created by') . ': ' . $uCreated->name . ' ' . t('at') . ' ' . format_date($device[timestamp_created], 'small'); if (!empty($device[timestamp_changed])) { $uChanged = db_fetch_object(db_query('SELECT u.name FROM {users} u WHERE u.uid = %d', $device[user_changed])); $deviceAttr .= ' ' . t('updated by') . ': ' . $uChanged->name . ' ' . t('at') . ' ' . format_date($device[timestamp_changed], 'small'); } // Groups all this data in an array for the theme() function $rows[] = array(l($device[nick], 'guifi/device/' . $device[id], array('attributes' => array('title' => $deviceAttr))), $device[type], array('data' => $ip[ipv4] . '/' . $ip[maskbits], 'align' => 'left'), empty($ip[ipv4]) ? ' ' : array('data' => t($device[flag]), 'class' => $device['flag']), empty($ip[ipv4]) ? ' ' : array('data' => $status_url, 'class' => $device['flag']), $unsolclic, $edit_device, $delete_device, empty($ip[ipv4]) ? ' ' : $traceroute); } // Creates the table with devices if any, otherwise just outputs the node has not devices if (count($rows)) { $output = '<h4>' . t('devices') . '</h4>' . theme('table', $header, $rows, array('class' => 'device-data')) . $form; } else { $output = theme('box', t('This node does not have any device'), $form); } // Again, it creates a table with the links, if they exist if ($links) { $node = node_load(array('nid' => $node->id)); drupal_set_title(t('devices @ %node', array('%node' => $node->title))); drupal_set_breadcrumb(guifi_node_ariadna($node)); $output .= theme_links(module_invoke_all('link', 'node', $node, FALSE)); print theme('page', $output, FALSE); return; } return $output; }
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; }
/** * outputs the node information **/ function guifi_service_view($node, $teaser = FALSE, $page = FALSE, $block = FALSE) { node_prepare($node); if ($teaser) { return $node; } if ($block) { return $node; } if ($page) { drupal_set_breadcrumb(guifi_zone_ariadna($node->zone_id, 'node/%d/view/services')); $node->content['body']['#value'] = theme('box', t('Description'), $node->content['body']['#value']); $node->content['body']['#weight'] = 1; $service_data = array('#value' => theme('box', t('service information'), theme_guifi_service_data($node, FALSE)), '#weight' => -0); if ($node->service_type == 'DNS') { $form = drupal_get_form('guifi_domain_create_form', $node); $id = $node->id; $rows = array(); $header = array('<h2>' . t('Domain') . '</h2>', array('data' => t('type'), 'style' => 'text-align: left;'), array('data' => t('Scope'))); $query = db_query("SELECT d.id FROM {guifi_dns_domains} d WHERE sid=%d", $id); while ($d = db_fetch_object($query)) { $domain = guifi_domain_load($d->id); if (guifi_domain_access('update', $domain['id'])) { $edit_domain = l(guifi_img_icon('edit.png'), 'guifi/domain/' . $domain['id'] . '/edit', array('html' => TRUE, 'title' => t('edit domain'), 'attributes' => array('target' => '_blank'))) . '</td><td>' . l(guifi_img_icon('drop.png'), 'guifi/domain/' . $domain['id'] . '/delete', array('html' => TRUE, 'title' => t('delete domain'), 'attributes' => array('target' => '_blank'))); } $rows[] = array('<a href="' . url('guifi/domain/' . $domain[id]) . '">' . $domain['name'] . '</a>', array('data' => $domain['type'], 'style' => 'text-align: left;'), array('data' => $domain['scope']), $edit_domain); } if (count($rows)) { $node->content['data'] = array($service_data, array('#value' => theme('table', $header, $rows) . $form, '#weight' => 1)); } else { $node->content['data'] = array(array('#value' => theme('box', t('service information'), theme_guifi_service_data($node, FALSE)) . $form, '#weight' => -0)); } } else { $node->content['data'] = array(array('#value' => theme('box', t('service information'), theme_guifi_service_data($node, FALSE)) . $form, '#weight' => -0)); } } return $node; }
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 _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; }