function guifi_stats_nodes_form($form_state, $zone_id) { $form['#action'] = ''; $form['zone_id'] = guifi_zone_select_field((int) $zone_id, 'zone_id'); $form['zone_id']['#weight'] = 1; return $form; }
/** * Select zone * * URL: http://guifi.net/guifi/js/select-zone/% */ function guifi_ahah_select_zone() { if (arg(4) == 'select') { $cid = 'form_' . $_POST['form_build_id']; $cache = cache_get($cid, 'cache_form'); $fname = arg(3); $zid = $_POST[$fname]; if ($cache) { $form = $cache->data; $form[$fname] = guifi_zone_select_field($zid, $fname); cache_set($cid, $form, 'cache_form', $cache->expire); // Build and render the new select element, then return it in JSON format. $form_state = array(); $form['#post'] = array(); $form = form_builder($form['form_id']['#value'], $form, $form_state); $output = drupal_render($form[$fname]); drupal_json(array('status' => TRUE, 'data' => $output)); } else { drupal_json(array('status' => FALSE, 'data' => '')); } exit; } else { $matches = array(); $string = strtoupper(arg(3)); $query = 'SELECT ' . ' CONCAT(z.id,"-",z.title) str, m.title master ' . 'FROM {guifi_zone} z, {guifi_zone} m ' . 'WHERE z.master=m.id ' . ' AND CONCAT(z.id,"-",upper(z.title)) LIKE "%' . $string . '%"'; $qry = db_query($query); $c = 0; $matches = array(); while ($value = db_fetch_array($qry) and $c < 50) { $c++; $matches[$value['str']] = $value['str'] . ' (' . $value['master'] . ')'; } print drupal_to_js($matches); exit; } }
/** * IP subrange search form. */ function guifi_tools_ip_rangesearch_form($form_state, $params = array()) { if (empty($params)) { $mask = '255.255.255.224'; $network_type = 'public'; $zone_id = guifi_zone_root(); } else { list($mask, $network_type, $zone_id, $allocate) = explode(',', $params); } $form['mask'] = array('#type' => 'select', '#title' => t("Mask"), '#required' => TRUE, '#default_value' => $mask, '#options' => guifi_types('netmask', 30, 0), '#description' => t('The mask of the network to search for. The number of the available hosts of each masks is displayed in the list box.')); $form['network_type'] = array('#type' => 'select', '#title' => t("Type"), '#required' => TRUE, '#default_value' => $network_type, '#options' => drupal_map_assoc(array('public', 'backbone')), '#description' => t('The type of network addresses you are looking for. <ul><li><em>public:</em> is for addresses which will allow the users connect to the services, therefore must be unique across all the network and assigned with care for not being wasted.</li><li><em>backbone:</em> internal addresses for network operation, could be shared across distinct network segments, do not neet to be known as a service address to the users</li></ul>')); $form['zone_id'] = guifi_zone_select_field($zone_id, 'zone_id'); $form['allocate'] = array('#type' => 'select', '#title' => t("Allocate"), '#required' => TRUE, '#access' => user_access('administer guifi networks'), '#default_value' => 'No', '#options' => drupal_map_assoc(array('Yes', 'No')), '#description' => t('If yes, the network found will be allocated at the database being assigned to the zone')); $form['submit'] = array('#type' => 'submit', '#value' => t('Find space for the subnetwork')); return $form; }
/** * Present the guifi zone editing form. */ function guifi_ipv4_form($form_state, $params = array()) { guifi_log(GUIFILOG_TRACE, 'guifi_ipv4_form()', $params); $network_types = array('public' => t('public - for any device available to everyone'), 'backbone' => t("backbone - used for internal management, links..."), 'mesh' => t('mesh - for any device in Mesh'), 'reserved' => t('reserved - used for reserved addressing')); // $network_types = array_merge($network_types,guifi_types('adhoc')); if (empty($form_state['values'])) { // first execution, initializing the form // if new network, initialize the zone if ($params['add']) { $zone_id = $params['add']; $zone = guifi_zone_load($zone_id); // if is root zone, don't find next value' if ($zone_id != guifi_zone_root()) { // not root zone, fill default values looking to next available range $zone = guifi_zone_load($zone_id); $ndefined = db_fetch_object(db_query('SELECT count(*) c FROM guifi_networks WHERE zone=%d', $zone_id)); switch ($ndefined->c) { case 0: $mask = '255.255.255.0'; break; case 1: $mask = '255.255.254.0'; break; case 2: $mask = '255.255.252.0'; break; case 3: $mask = '255.255.248.0'; break; default: $mask = '255.255.240.0'; } $form_state['values']['zone'] = $zone_id; $ips_allocated = guifi_ipcalc_get_ips('0.0.0.0', '0.0.0.0', NULL, 1); $network_type = 'public'; $allocate = 'No'; $net = guifi_ipcalc_get_subnet_by_nid($zone->master, $mask, $network_type, $ips_allocated, $allocate, TRUE); // verbose output if ($net) { $item = _ipcalc($net, $mask); $form_state['values']['base'] = $net; $form_state['values']['mask'] = $mask; } else { drupal_set_message(t('It was not possible to find %type space for %mask', array('%type' => $network_type, '%mask' => $mask)), 'error'); } } // if is not the root zone } // if existent network, get the network and edit if ($params['edit']) { $form_state['values'] = db_fetch_array(db_query('SELECT * FROM {guifi_networks} WHERE id = %d', $params['edit'])); } } $form['base'] = array('#type' => 'textfield', '#title' => t('Network base IPv4 address'), '#required' => TRUE, '#default_value' => $form_state['values']['base'], '#size' => 16, '#maxlength' => 16, '#description' => t('A valid base ipv4 network address.'), '#weight' => 0); $form['mask'] = array('#type' => 'select', '#title' => t("Mask"), '#required' => TRUE, '#default_value' => $form_state['values']['mask'], '#options' => guifi_types('netmask', 24, 0), '#description' => t('The mask of the network. The number of valid hosts of each masks is displayed in the list box.'), '#weight' => 1); $form['zone'] = guifi_zone_select_field($form_state['values']['zone'], 'zone'); $form['zone']['#weight'] = 2; $form['network_type'] = array('#type' => 'select', '#title' => t("Network type"), '#required' => TRUE, '#default_value' => $form_state['values']['network_type'], '#options' => $network_types, '#description' => t('The type of usage that this network will be used for.'), '#weight' => 3); $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'), '#weight' => 4); $form['id'] = array('#type' => 'hidden', '#value' => $form_state['values']['id'], '#weight' => 5); $form['valid'] = array('#type' => 'hidden', '#value' => $form_state['values']['valid'], '#weight' => 6); return $form; }