Пример #1
0
function guifi_radio_radio_form($radio, $key, &$form_weight = -200)
{
    guifi_log(GUIFILOG_TRACE, sprintf('function _guifi_radio_radio_form(key=%d)', $key), $radio);
    $f['storage'] = guifi_form_hidden_var($radio, array('radiodev_counter'), array('radios', $key));
    $f = array('#type' => 'fieldset', '#title' => t('Radio #') . $key . ' - ' . $radio['mode'] . ' - ' . $radio['ssid'] . ' - ' . count($radio['interfaces']) . ' ' . t('interface(s)'), '#collapsible' => TRUE, '#collapsed' => !isset($radio['unfold']), '#tree' => TRUE, '#weight' => $form_weight++);
    if ($radio['deleted']) {
        $f['deletedMsg'] = array('#type' => 'item', '#value' => guifi_device_item_delete_msg("This radio and has been deleted, " . "deletion will cascade to all properties, including interfaces, " . "links and ip addresses."), '#weight' => $form_weight++);
        $f['deleted'] = array('#type' => 'hidden', '#value' => TRUE);
    }
    if ($radio['new']) {
        $f['new'] = array('#type' => 'hidden', '#parents' => array('radios', $key, 'new'), '#value' => TRUE);
    }
    $f['mode'] = array('#type' => 'hidden', '#parents' => array('radios', $key, 'mode'), '#value' => $radio['mode']);
    $f['s'] = array('#type' => 'fieldset', '#title' => t('Radio main settings (SSID, MAC, Channel...)'), '#collapsible' => TRUE, '#collapsed' => !isset($radio['unfold_main']), '#tree' => FALSE);
    // DUMMY Radio MAC
    if (empty($radio['mac'])) {
        $radio['mac'] = "00:00:00:00:00:00";
    }
    $f['s']['mac'] = array('#type' => 'textfield', '#title' => t('MAC'), '#required' => TRUE, '#parents' => array('radios', $key, 'mac'), '#size' => 17, '#maxlength' => 17, '#default_value' => $radio["mac"], '#element_validate' => array('guifi_mac_validate'), '#description' => t("Wireless MAC Address.<br />Some configurations won't work if is blank"));
    switch ($radio['mode']) {
        case 'ap':
        case 'mesh':
            $f['s']['ssid'] = array('#type' => 'textfield', '#title' => t('SSID'), '#parents' => array('radios', $key, 'ssid'), '#required' => TRUE, '#size' => 22, '#maxlength' => 22, '#default_value' => $radio["ssid"], '#description' => t("SSID to identify this radio signal."));
            $f['s']['protocol'] = array('#type' => 'select', '#title' => t("Protocol"), '#parents' => array('radios', $key, 'protocol'), '#default_value' => $radio["protocol"], '#options' => guifi_types('protocol'), '#description' => t('Select the protocol where this radio will operate.'), '#ahah' => array('path' => 'guifi/js/channel/' . $key, 'wrapper' => 'select-channel-' . $key, 'method' => 'replace', 'effect' => 'fade'));
            $f['s']['channel'] = guifi_radio_channel_field($key, $radio["channel"], $radio['protocol']);
            $f['s']['chbandwith'] = guifi_radio_channel_bwith_field($key, $radio["chbandwith"]);
            if ($radio['mode'] == 'ap') {
                $f['ap'] = array('#type' => 'fieldset', '#title' => t('Connection acceptance policy'), '#description' => t('Please specify if this radio do accept simple client connections and if a funding is required to contribute for the coverage infrastructure'), '#collapsible' => TRUE, '#collapsed' => $radio["clients_accepted"] == 'Yes' ? false : true, '#tree' => TRUE, '#attributes' => array('class' => 'fieldset-radio'));
                $f['ap']['clients_accepted'] = array('#type' => 'select', '#title' => t("Clients accepted?"), '#parents' => array('radios', $key, 'clients_accepted'), '#default_value' => $radio["clients_accepted"], '#options' => drupal_map_assoc(array(0 => 'Yes', 1 => 'No')), '#description' => t('Do this radio accept connections from clients?'));
                $f['ap']['fund_required'] = array('#type' => 'select', '#title' => t("Policy"), '#parents' => array('radios', $key, 'fund_required'), '#default_value' => $radio["fund_required"], '#options' => guifi_types('contribution'), '#description' => t('Funding required?'));
                $f['ap']['fund_amount'] = array('#type' => 'textfield', '#size' => 12, '#maxlength' => 15, '#required' => false, '#title' => t("Amount"), '#parents' => array('radios', $key, 'fund_amount'), '#default_value' => $radio["fund_amount"], '#attributes' => array('' . 'class' => 'number required', 'min' => 1), '#description' => t('Funding if required'));
                $f['ap']['fund_currency'] = array('#type' => 'select', '#title' => t("Currency"), '#parents' => array('radios', $key, 'fund_currency'), '#default_value' => $radio["fund_currency"], '#options' => drupal_map_assoc(array('€' => 'Euros', '$' => 'US Dollar')));
            } else {
                $f['s']['clients_accepted'] = array('#type' => 'hidden', '#parents' => array('radios', $key, 'clients_accepted'), '#value' => $radio["clients_accepted"]);
                $f['s']['fund_required'] = array('#type' => 'hidden', '#parents' => array('radios', $key, 'fund_required'), '#value' => $radio["fund_required"]);
                $f['s']['fund_amount'] = array('#type' => 'hidden', '#parents' => array('radios', $key, 'fund_amount'), '#value' => $radio["fund_amount"]);
                $f['s']['fund_currency'] = array('#type' => 'hidden', '#parents' => array('radios', $key, 'fund_currency'), '#value' => $radio["fund_currency"]);
            }
            break;
        case 'client':
            $inherit_msg = t('Will take it from the connected AP.');
            $f['s']['ssid'] = array('#type' => 'hidden', '#parents' => array('radios', $key, 'ssid'), '#title' => t('SSID'), '#default_value' => $radio["ssid"], '#description' => $inherit_msg);
            $f['s']['protocol'] = array('#type' => 'hidden', '#title' => t("Protocol"), '#parents' => array('radios', $key, 'protocol'), '#value' => $radio["protocol"], '#description' => $inherit_msg);
            $f['s']['channel'] = array('#type' => 'hidden', '#title' => t("Channel"), '#parents' => array('radios', $key, 'channel'), '#default_value' => $radio["channel"], '#options' => guifi_types('channel', NULL, NULL, $radio['protocol']), '#description' => $inherit_msg);
            $f['s']['clients_accepted'] = array('#type' => 'hidden', '#parents' => array('radios', $key, 'clients_accepted'), '#value' => $radio["clients_accepted"]);
            break;
    }
    // Antenna settings group
    $f['antenna'] = array('#type' => 'fieldset', '#title' => t('Antenna settings'), '#collapsible' => TRUE, '#collapsed' => !isset($radio['unfold_antenna']), '#tree' => FALSE, '#attributes' => array('class' => 'fieldset-radio'));
    $fw2 = 0;
    $f['antenna']['antenna_angle'] = array('#type' => 'select', '#title' => t("Type (angle)"), '#parents' => array('radios', $key, 'antenna_angle'), '#default_value' => $radio["antenna_angle"], '#options' => guifi_types('antenna'), '#description' => t('Beam width angle'));
    $f['antenna']['antenna_gain'] = array('#type' => 'select', '#title' => t("Gain"), '#parents' => array('radios', $key, 'antenna_gain'), '#default_value' => $radio["antenna_gain"], '#options' => guifi_types('antenna_gain'), '#description' => t('Gain (Db)'));
    $f['antenna']['antenna_azimuth'] = array('#type' => 'textfield', '#title' => t('Degrees (º)'), '#parents' => array('radios', $key, 'antenna_azimuth'), '#size' => 3, '#maxlength' => 3, '#default_value' => $radio["antenna_azimuth"], '#description' => t('Azimuth<br>(0-360º)'));
    $f['antenna']['antenna_mode'] = array('#type' => 'select', '#title' => t("Connector"), '#parents' => array('radios', $key, 'antenna_mode'), '#default_value' => $radio["antenna_mode"], '#options' => array('' => 'Don\'t change', 'Main' => 'Main/Right/Internal', 'Aux' => 'Aux/Left/External'), '#description' => t('Examples:<br />MiniPci: Main/Aux<br />Linksys: Right/Left<br />Nanostation: Internal/External'));
    foreach ($radio['interfaces'] as $iid => $interface) {
        $f['interfaces'][$iid] = guifi_interfaces_form($interface, array('radios', $key, 'interfaces', $iid));
    }
    return $f;
}
Пример #2
0
function guifi_devices_select_filter($form_state, $action = '', &$fweight = -100)
{
    $form = array();
    $ahah = array('path' => 'guifi/js/select-device/' . $action, 'wrapper' => 'list-devices', 'method' => 'replace', 'event' => 'change', 'effect' => 'fade');
    $form['f'] = array('#type' => 'fieldset', '#title' => t('Filters'), '#weight' => 0, '#collapsible' => TRUE, '#collapsed' => FALSE, '#weight' => $fweight++);
    $form['f']['dmin'] = array('#type' => 'textfield', '#parents' => array('filters', 'dmin'), '#title' => t('Distance from'), '#size' => 5, '#maxlength' => 5, '#attributes' => array('class' => 'digits min(0)'), '#default_value' => $form_state['values']['filters']['dmin'], '#description' => t("List starts at this distance"), '#prefix' => '<table><tr><td>', '#suffix' => '</td>', '#ahah' => $ahah, '#weight' => $fweight++);
    $form['f']['dmax'] = array('#type' => 'textfield', '#parents' => array('filters', 'dmax'), '#title' => t('until'), '#size' => 5, '#maxlength' => 5, '#default_value' => $form_state['values']['filters']['dmax'], '#attributes' => array('class' => 'digits min(0)'), '#description' => t("...and finishes at this distance"), '#prefix' => '<td>', '#suffix' => '</td>', '#ahah' => $ahah, '#weight' => $fweight++);
    if (isset($form_state['values']['filters']['max'])) {
        $form['f']['max'] = array('#type' => 'textfield', '#parents' => array('filters', 'max'), '#title' => t('Stop list at'), '#size' => 5, '#maxlength' => 5, '#default_value' => $form_state['values']['filters']['max'], '#description' => t("Max. # of rows to list"), '#prefix' => '<td>', '#suffix' => '</td>', '#ahah' => $ahah, '#weight' => $fweight++);
    }
    $form['f']['search'] = array('#type' => 'textfield', '#parents' => array('filters', 'search'), '#title' => t('Search string'), '#size' => 25, '#maxlength' => 25, '#default_value' => $form_state['values']['filters']['search'], '#description' => t("Zone, node or device contains this string"), '#prefix' => '<td>', '#suffix' => '</td>', '#ahah' => $ahah, '#weight' => $fweight++);
    if (isset($form_state['values']['filters']['sn'])) {
        $form['f']['sn'] = array('#type' => 'checkbox', '#parents' => array('filters', 'sn'), '#title' => t('Only Supernodes'), '#size' => 1, '#maxlength' => 1, '#default_value' => $form_state['values']['filters']['sn'], '#description' => t("Search only for supernodes?"), '#prefix' => '<td>', '#suffix' => '</td>', '#ahah' => $ahah, '#weight' => $fweight++);
    }
    if (isset($form_state['values']['filters']['status'])) {
        $choices = array_merge(array('All' => t('All')), guifi_types('status'));
        $form['f']['status'] = array('#type' => 'select', '#parents' => array('filters', 'status'), '#title' => t("Status"), '#required' => TRUE, '#default_value' => $form_state['values']['filters']['status'], '#options' => $choices, '#description' => t("Status of the node"), '#prefix' => '<td>', '#suffix' => '</td>', '#ahah' => $ahah, '#weight' => $fweight++);
    }
    $form['f']['azimuth'] = array('#type' => 'select', '#parents' => array('filters', 'azimuth'), '#title' => t('Azimuth'), '#default_value' => $form_state['values']['filters']['azimuth'], '#options' => array('0,360' => t('All'), '292,360-0,67' => t('North'), '22,158' => t('East'), '112,248' => t('South'), '202,338' => t('West')), '#description' => t('List nodes at the selected orientation.'), '#prefix' => '<td>', '#suffix' => '</td></tr></table>', '#ahah' => $ahah, '#weight' => $fweight++);
    /*  $form['f']['action'] = array(
        '#type' => 'submit',
        '#parents' => array('action'),
        '#value' => t('Apply filter'),
        '#ahah' => array(
              'path' => 'guifi/js/select-device',
              'wrapper' => 'list-devices',
              'method' => 'replace',
              'effect' => 'fade',
             ),
        '#weight' => $fweight++,
      );*/
    if (isset($form_state['values']['filters']['type'])) {
        $form['f']['type'] = array('#type' => 'hidden', '#parents' => array('filters', 'type'), '#value' => $form_state['values']['filters']['type']);
    }
    if (isset($form_state['values']['filters']['mode'])) {
        $form['f']['mode'] = array('#type' => 'hidden', '#parents' => array('filters', 'mode'), '#value' => $form_state['values']['filters']['mode']);
    }
    if (isset($form_state['values']['filters']['from_node'])) {
        $form['f']['from_node'] = array('#type' => 'hidden', '#parents' => array('filters', 'from_node'), '#value' => $form_state['values']['filters']['from_node']);
    }
    if (isset($filters['from_device'])) {
        $form['f']['from_device'] = array('#type' => 'hidden', '#parents' => array('filters', 'from_device'), '#value' => $form_state['values']['filters']['from_device']);
    }
    if (isset($form_state['values']['filters']['from_radio'])) {
        $form['f']['from_radio'] = array('#type' => 'hidden', '#parents' => array('filters', 'from_radio'), '#value' => $form_state['values']['filters']['from_radio']);
    }
    if (isset($form_state['values']['filters']['skip'])) {
        $form['f']['skip'] = array('#type' => 'hidden', '#parents' => array('filters', 'skip'), '#value' => $form_state['values']['filters']['skip']);
    }
    return $form;
}
function guifi_maintainers_form($node, &$form_weight)
{
    guifi_log(GUIFILOG_TRACE, 'function guifi_maintainers_form(mantainers 1)', $node->maintainers);
    foreach ($node->maintainers as $km => $vm) {
        if ($vm['new'] and $vm['maintainer'] == '') {
            unset($node->maintainers[$km]);
        }
    }
    $form['maintainers'] = array('#type' => 'fieldset', '#title' => t('Maintainer(s)'), '#description' => t('If they are, maintainer(s) for this infrastructure.<br>' . 'If there aren\'t, either take from parents, or use notification contacts.<br>' . 'A maintainer is who takes care of this infrastructure. Can be also a founder, but is a distinct role.<br>' . 'Use "Preview" button if you need more rows to fill.'), '#collapsible' => TRUE, '#collapsed' => $node->maintainers[0] != '' ? TRUE : FALSE, '#attributes' => array('class' => 'maintainers'), '#weight' => $form_weight++, '#tree' => TRUE);
    $maintainer_id = 0;
    $nmaintainers = count($node->maintainers);
    //  guifi_log(GUIFILOG_BASIC, 'function guifi_zone_form(mantainers)', $node->maintainers[$maintainer_id]);
    guifi_log(GUIFILOG_TRACE, 'function guifi_maintainers_form(mantainers 2)', $node->maintainers);
    do {
        $form['maintainers'][$maintainer_id]['maintainer'] = array('#title' => t('maintainer'), '#type' => 'textfield', '#description' => $node->maintainers[$maintainer_id]['maintainer'] != '' ? t('Leave blank for delete this maintainer') : t('Fill for register a new maintainer'), '#size' => 40, '#default_value' => $node->maintainers[$maintainer_id]['maintainer'] != '' ? $node->maintainers[$maintainer_id]['maintainer'] : NULL, '#maxsize' => 256, '#autocomplete_path' => 'budgets/js/select-supplier', '#prefix' => '<div class="maintainer-item">', '#weight' => $form_weight++);
        $form['maintainers'][$maintainer_id]['id'] = array('#type' => 'hidden', '#value' => $node->maintainers[$maintainer_id]['id'], '#weight' => $form_weight++);
        $form['maintainers'][$maintainer_id]['commitment'] = array('#title' => t('commitment type'), '#type' => 'select', '#required' => FALSE, '#default_value' => $node->maintainers[$maintainer_id]['commitment'], '#options' => guifi_types('maintainer'), '#weight' => $form_weight++);
        $form['maintainers'][$maintainer_id]['sla'] = array('#title' => t('SLA'), '#description' => t('Service Level Objective'), '#type' => 'select', '#required' => FALSE, '#default_value' => $node->maintainers[$maintainer_id]['sla'], '#options' => guifi_types('sla'), '#weight' => $form_weight++);
        $form['maintainers'][$maintainer_id]['sla_resp'] = array('#title' => t('resp.'), '#description' => t('Hours'), '#type' => 'select', '#required' => FALSE, '#default_value' => $node->maintainers[$maintainer_id]['sla_resp'], '#options' => array('' => t('n/a'), 4 => 4, 6 => 6, 8 => 8, 12 => 12, 24 => 24, 48 => 48, 72 => 72), '#weight' => $form_weight++);
        $form['maintainers'][$maintainer_id]['sla_fix'] = array('#title' => t('fix'), '#description' => t('Hours'), '#type' => 'select', '#required' => FALSE, '#default_value' => $node->maintainers[$maintainer_id]['sla_fix'], '#options' => array('' => t('n/a'), 4 => 4, 6 => 6, 8 => 8, 12 => 12, 24 => 24, 48 => 48, 72 => 72), '#suffix' => '</div>', '#weight' => $form_weight++);
        if ($maintainer_id == $nmaintainers) {
            $form['maintainers'][$maintainer_id]['new'] = array('#type' => 'hidden', '#value' => true);
        }
        $maintainer_id++;
    } while ($maintainer_id < $nmaintainers + 1);
    return $form['maintainers'];
}
Пример #4
0
function guifi_device_print_interfaces($device)
{
    if (empty($device['interfaces'])) {
        return NULL;
    }
    $rows = array();
    $inamestr = '';
    $fo_connectors = guifi_types('fo_port');
    foreach ($device['interfaces'] as $inum => $if) {
        $ipstr = '';
        $rows_if = array();
        guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_print_interfaces(interface %s)', $if['id']), $if);
        $connto_dev = array('data' => '');
        if ($if['connto_did']) {
            $connto_dev['data'] = guifi_get_devicename($if['connto_did']);
            if ($if['connto_did']) {
                $rdev = db_fetch_object(db_query('SELECT interface_type FROM {guifi_interfaces} WHERE device_id=%d AND id=%d', $if['connto_did'], $if['connto_iid']));
                $connto_dev['data'] .= ' / ' . $rdev->interface_type;
            }
        }
        if (!empty($connto_dev['data'])) {
            $connto_dev['data'] = l($connto_dev['data'], 'guifi/device/' . $if['connto_did']);
        } else {
            $connto_dev['class'] = 'available';
        }
        if ($if['ipv4']) {
            foreach ($if['ipv4'] as $ipnum => $ipv4) {
                guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_print_interfaces(ip %s)', $ipv4['ipv4']), $ipv4);
                if ($ipv4['ipv4']) {
                    $ip = _ipcalc($ipv4['ipv4'], $ipv4['netmask']);
                    $ipstr = $ipv4['ipv4'] . '/' . $ip['maskbits'];
                } else {
                    $ipstr = t('n/a');
                }
                $rows_if[] = array($ipstr, $ipv4['netmask']);
            }
        } else {
            $rows_if[] = array(null, null);
        }
        $rspan = count($rows_if);
        if (empty($if['connector_type'])) {
            $if['connector_type'] = t('RJ45');
        }
        if ($if['connector_type'] != t('RJ45')) {
            $if['connector_type'] = $fo_connectors[$if['connector_type']];
        }
        $begin = array(array('data' => $if['interface_type']), array('data' => $connto_dev['data'], 'class' => $connto_dev['class']), array('data' => $if['connector_type']), array('data' => $if['comments']), array('data' => $if['mac']));
        foreach ($begin as $i => $r) {
            $begin[$i] = array_merge($r, array('rowspan' => $rspan, 'valign' => 'top'));
        }
        foreach ($rows_if as $i => $row) {
            if ($i == 0) {
                $rows[] = array_merge($begin, $row);
            } else {
                $rows[] = $row;
            }
        }
    }
    return $rows;
}
Пример #5
0
/**
 * @file guifi_links.inc.php
 */
function guifi_links_form($link, $ipv4, $tree, $multilink)
{
    $lweight = 0;
    // edit link details
    guifi_log(GUIFILOG_TRACE, 'guifi_links_form()', $link);
    $ki = $tree[count($tree) - 3];
    $ka = $tree[count($tree) - 1];
    if (count($tree) > 4) {
        $rk = $tree[1];
    } else {
        $rk = NULL;
    }
    // creating hidden form elements for non-edited fields
    if ($link['new']) {
        $link['id'] = -1;
    }
    // link hidden vars
    $f['storage'] = guifi_form_hidden_var($link, array('id', 'nid', 'device_id', 'interface_id', 'link_type'), array_merge($tree, array('links', $link['id'])));
    // remote interface hidden vars
    $f['interface'] = guifi_form_hidden_var($link['interface'], array('id', 'interface_type', 'radiodev_counter'), array_merge($tree, array('links', $link['id'], 'interface')));
    $f['remote_ipv4'] = guifi_form_hidden_var($link['interface']['ipv4'], array('id', 'interface_id', 'netmask'), array_merge($tree, array('links', $link['id'], 'interface', 'ipv4')));
    // linked node-device
    if ($link['type'] != 'cable') {
        $descr = guifi_get_ap_ssid($link['device_id'], $link['radiodev_counter']);
    } else {
        $descr = guifi_get_interface_descr($link['interface_id']);
    }
    $f['l'] = array('#type' => 'fieldset', '#title' => guifi_get_nodename($link['nid']) . '/' . guifi_get_hostname($link['device_id']), '#collapsible' => TRUE, '#collapsed' => !isset($link['unfold']));
    if ($link['deleted']) {
        $f['l']['#description'] = guifi_device_item_delete_msg('<b>Link deleted</b>.');
    }
    $f['l']['beginTable'] = array('#value' => '<table style="width: 0">');
    if (user_access('administer guifi networks')) {
        if (!$multilink) {
            $f['l']['ipv4'] = array('#type' => 'textfield', '#parents' => array_merge($tree, array('ipv4')), '#size' => 16, '#maxlength' => 16, '#default_value' => $ipv4['ipv4'], '#title' => t('Local IPv4'), '#element_validate' => array('guifi_validate_ip'), '#prefix' => '<td>', '#suffix' => '</td>');
        }
        $f['l']['ipv4_remote'] = array('#type' => 'textfield', '#parents' => array_merge($tree, array('links', $link['id'], 'interface', 'ipv4', 'ipv4')), '#size' => 16, '#maxlength' => 16, '#default_value' => $link['interface']['ipv4']['ipv4'], '#title' => t('Remote IPv4'), '#element_validate' => array('guifi_validate_ip', 'guifi_links_validate_subnet'), '#prefix' => '<td>', '#suffix' => '</td>');
        if (!$multilink) {
            $f['l']['netmask'] = array('#type' => 'select', '#parents' => array_merge($tree, array('netmask')), '#title' => t("Network mask"), '#default_value' => $ipv4['netmask'], '#options' => guifi_types('netmask', 30, 0), '#prefix' => '<td>', '#suffix' => '</td>');
        }
    } else {
        if (!$multilink) {
            $f['l']['ipv4'] = array('#type' => 'value', '#parents' => array_merge($tree, array('ipv4')), '#value' => $ipv4['ipv4']);
            $f['l']['netmask'] = array('#type' => 'value', '#parents' => array_merge($tree, array('netmask')), '#value' => $ipv4['netmask']);
        }
        $f['l']['ipv4_remote'] = array('#type' => 'value', '#parents' => array_merge($tree, array('links', $link['id'], 'interface', 'ipv4', 'ipv4')), '#value' => $link['interface']['ipv4']['ipv4']);
        $f['l']['ipv4_remote_display'] = array('#type' => 'item', '#parents' => array_merge($tree, array('links', $link['id'], 'interface', 'ipv4', 'ipv4')), '#title' => t('Remote IPv4'), '#value' => $link['interface']['ipv4']['ipv4'], '#description' => $link['interface']['ipv4']['netmask'], '#prefix' => '<td>', '#suffix' => '</td>');
    }
    // if network administrator
    $f['l']['overlap'] = array('#type' => 'hidden', '#parents' => array_merge($tree, array('overlap')), '#value' => $ipv4['netmask'], '#element_validate' => array('guifi_links_check_overlap'));
    // Routing
    $f['l']['routing'] = array('#type' => 'select', '#parents' => array_merge($tree, array('links', $link['id'], 'routing')), '#title' => t("Routing"), '#default_value' => $link['routing'], '#options' => guifi_types('routing'), '#prefix' => '<td>', '#suffix' => '</td>');
    // Status
    $f['l']['status'] = array('#type' => 'select', '#parents' => array_merge($tree, array('links', $link['id'], 'flag')), '#title' => t("Status"), '#default_value' => $link['flag'], '#options' => guifi_types('status'), '#prefix' => '<td>', '#suffix' => '</td>');
    // remote interface (cable links)
    if ($link['link_type'] == 'cable') {
        $f['l']['remote_interface_type'] = array('#type' => 'textfield', '#parents' => array_merge($tree, array('links', $link['id'], 'interface', 'interface_type')), '#title' => t("Remote interface"), '#default_value' => $link['interface']['interface_type'], '#size' => 10, '#maxzise' => 60, '#prefix' => '<td>', '#suffix' => '</td>');
    }
    // delete link button
    if ($link['deleted']) {
        $f['deleted_link'] = array('#type' => 'hidden', '#parents' => array_merge($tree, array('deleted_link')), '#value' => TRUE);
    } else {
        $f['l']['delete_link'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/drop.png', '#parents' => array_merge($tree, array('delete_link', $link['id'], $link['nid'], $link['device_id'])), '#attributes' => array('title' => t('Delete link with') . ': ' . guifi_get_interface_descr($link['interface_id'])), '#executes_submit_callback' => TRUE, '#submit' => array('guifi_links_delete_submit'), '#prefix' => '<td>');
    }
    $f['l']['endTable'] = array('#value' => '</td></tr></table>');
    return $f;
}
Пример #6
0
function guifi_devel_devices_form($form_state, $devid)
{
    global $user;
    if ($devid == 'New') {
        $form['new'] = array('#type' => 'hidden', '#value' => TRUE);
    } else {
        $sql = db_query('SELECT * FROM {guifi_model_specs} WHERE mid = %d', $devid);
        $dev = db_fetch_object($sql);
        $dev->arr_model_class = explode('|', $dev->model_class);
        $form['mid'] = array('#type' => 'hidden', '#value' => $devid);
    }
    $query = db_query('SELECT * FROM {guifi_manufacturer}');
    while ($manufacturers = db_fetch_array($query)) {
        $manuf_array[$manufacturers["fid"]] = $manufacturers["name"];
    }
    $form_weight = 0;
    $form['general'] = array('#type' => 'fieldset', '#title' => isset($form['new']) ? t('General') : t('General') . ' (' . $dev->model . ' - ' . implode(', ', $dev->arr_model_class) . ')', '#attributes' => array('class' => "model-item"), '#collapsible' => TRUE, '#collapsed' => isset($form['new']) ? FALSE : TRUE);
    $form['general']['model'] = array('#type' => 'textfield', '#title' => t('Model Name'), '#required' => TRUE, '#default_value' => $dev->model, '#size' => 32, '#maxlength' => 50, '#description' => t('Device model name, please,<br>use a clear and short description.'), '#weight' => $form_weight++);
    $form['general']['fid'] = array('#type' => 'select', '#title' => t('Manufacturer'), '#required' => TRUE, '#default_value' => $dev->fid, '#options' => $manuf_array, '#description' => t('Select Device Manufacturer.'), '#weight' => $form_weight++);
    $form['general']['arr_model_class'] = array('#type' => 'select', '#title' => t('Model Class'), '#required' => TRUE, '#options' => guifi_types('model_class'), '#multiple' => true, '#size' => 8, '#default_value' => explode('|', $dev->model_class), '#description' => t('Once saved, available fieldsets will change depending on the class selected.'), '#prefix' => '<div>', '#suffix' => '</div>', '#weight' => $form_weight++);
    $form['general']['url'] = array('#type' => 'textfield', '#title' => t('URL'), '#required' => TRUE, '#default_value' => $dev->url, '#size' => 80, '#maxlength' => 128, '#description' => t('Url where we can see a specs from device model.'), '#weight' => $form_weight++);
    $form['general']['rackeable'] = array('#type' => 'select', '#title' => t('Rackeable'), '#required' => TRUE, '#default_value' => $dev->rackeable, '#options' => array('no', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), '#description' => t("Not rackeable or<br>number of U's"), '#weight' => $form_weight++);
    $form['general']['notification'] = array('#type' => 'textfield', '#size' => 80, '#maxlength' => 1024, '#title' => t('contact'), '#required' => FALSE, '#element_validate' => array('guifi_emails_validate'), '#default_value' => empty($dev->notification) ? $user->mail : $dev->notification, '#weight' => $form_weight++, '#description' => t('Mailid where changes on the device will be notified, if many, separated by \',\'<br />used for network administration.'));
    $form['continue'] = array('#type' => 'submit', '#weight' => 99, '#value' => t('Save & continue edit'));
    $form['submit'] = array('#type' => 'submit', '#weight' => 100, '#value' => t('Save'));
    if (isset($form['new'])) {
        return $form;
    }
    $form['ethernet'] = array('#type' => 'fieldset', '#title' => $dev->etherdev_max ? t('Ethernet') . ' (' . $dev->etherdev_max . ' ports)' : t('Ethernet'), '#attributes' => array('class' => "model-item"), '#collapsible' => TRUE, '#collapsed' => $dev->etherdev_max ? TRUE : FALSE, '#weight' => $form_weight++);
    $form['ethernet']['etherdev_max'] = array('#type' => 'textfield', '#title' => t('Ethernet Ports'), '#required' => TRUE, '#default_value' => $dev->etherdev_max ? $dev->etherdev_max : 0, '#size' => 2, '#maxlength' => 2, '#description' => t('# of ethernet ports<br>on this device.'), '#weight' => $form_weight++);
    $form['ethernet']['interfaces'] = array('#type' => 'textfield', '#title' => t('Interfaces'), '#required' => FALSE, '#default_value' => $dev->interfaces, '#size' => 80, '#maxlength' => 240, '#description' => t('Device interface names for this device model.<br>Use | to split de the names, ex: p1|p2|p3.... Default is port# (1|2|3...|max)'), '#weight' => $form_weight++);
    $form['fiber'] = array('#type' => 'fieldset', '#access' => in_array('fiber', $dev->arr_model_class), '#title' => $dev->optoports_max ? t('Fiber Optics') . ' (' . $dev->optoports_max . ' ports)' : t('Fiber Optics'), '#attributes' => array('class' => "model-item"), '#collapsible' => TRUE, '#collapsed' => $dev->optoports_max ? TRUE : FALSE, '#weight' => $form_weight++);
    $form['fiber']['optoports_max'] = array('#type' => 'textfield', '#access' => in_array('fiber', $dev->arr_model_class), '#title' => t('Optical ports'), '#required' => FALSE, '#default_value' => $dev->optoports_max, '#size' => 2, '#maxlength' => 2, '#description' => t('# of optical ports<br>on this device.'), '#weight' => $form_weight++);
    $form['fiber']['opto_interfaces'] = array('#type' => 'textfield', '#access' => in_array('fiber', $dev->arr_model_class), '#title' => t('Optical Interfaces'), '#required' => FALSE, '#default_value' => $dev->opto_interfaces, '#size' => 80, '#maxlength' => 240, '#description' => t('Port numbers with SFP slot<br>Use | to split de the numbers (i.e. 21|22|23|24)<br>Use same names as ethernet for shared ports'), '#weight' => $form_weight++);
    $form['wireless'] = array('#type' => 'fieldset', '#access' => in_array('wireless', $dev->arr_model_class), '#title' => $dev->radiodev_max ? t('Wireless') . ' (' . $dev->radiodev_max . ' ports)' : t('Wireless'), '#attributes' => array('class' => "model-item"), '#collapsible' => TRUE, '#collapsed' => $dev->radiodev_max ? TRUE : FALSE, '#weight' => $form_weight++);
    $form['wireless']['radiodev_max'] = array('#type' => 'textfield', '#access' => in_array('wireless', $dev->arr_model_class), '#title' => t('Max Radios'), '#required' => TRUE, '#default_value' => $dev->radiodev_max, '#size' => 2, '#maxlength' => 2, '#description' => t('Maximum number of radios<br>that can handle this device.'), '#weight' => $form_weight++);
    $form['wireless']['winterfaces'] = array('#type' => 'textfield', '#title' => t('Wireless Interfaces'), '#required' => FALSE, '#default_value' => $dev->winterfaces, '#size' => 80, '#maxlength' => 240, '#description' => t('Device Wireless interface names for this device model.<br>Use | to split de the names, ex: wlan1|wlan2|wlan3.... Default is port# (1|2|3...|max)'), '#weight' => $form_weight++);
    $form['wireless']['AP'] = array('#type' => 'select', '#access' => in_array('wireless', $dev->arr_model_class), '#title' => t('Acces Point'), '#required' => TRUE, '#default_value' => $dev->AP, '#options' => array('Yes' => t('Yes'), 'No' => t("No")), '#description' => t('Select yes if this device<br>can be an Access Point.'), '#weight' => $form_weight++);
    $form['wireless']['virtualAP'] = array('#type' => 'select', '#access' => in_array('wireless', $dev->arr_model_class), '#title' => t('HostPot / Vlan'), '#required' => TRUE, '#default_value' => $dev->virtualAP, '#options' => array('Yes' => t('Yes'), 'No' => t("No")), '#description' => t('Select yes if this device<br>can be a Hostpot or can create vlans.'), '#weight' => $form_weight++);
    $form['wireless']['client'] = array('#type' => 'select', '#access' => in_array('wireless', $dev->arr_model_class), '#title' => t('Statiton capable'), '#required' => TRUE, '#options' => array('Yes' => t('Yes'), 'No' => t("No")), '#default_value' => $dev->client, '#description' => t('Select yes if this device<br>can be a station.'), '#weight' => $form_weight++);
    $form['firmware'] = array('#type' => 'fieldset', '#access' => in_array('wireless', $dev->arr_model_class) || in_array('router', $dev->arr_model_class), '#title' => t('Firmware'), '#attributes' => array('class' => "model-item"), '#collapsible' => TRUE, '#collapsed' => FALSE, '#weight' => $form_weight++);
    $form['firmware']['supported'] = array('#type' => 'select', '#access' => in_array('wireless', $dev->arr_model_class) || in_array('router', $dev->arr_model_class), '#title' => t('Supported'), '#required' => TRUE, '#options' => array('Yes' => t('Yes'), 'Deprecated' => t("Deprecated")), '#default_value' => $dev->supported, '#description' => t('Deprecated devices does not have any support and no appear on the device list select form.'), '#prefix' => '<td>', '#suffix' => '</td></tr></table>', '#weight' => $form_weight++);
    $query = db_query("select\n                    usc.id, usc.mid, usc.fid, f.id as firmware_id, f.nom\n                    from\n                    guifi_firmware f\n                    left join\n                    guifi_configuracioUnSolclic usc ON usc.fid = f.id  and usc.mid = %d order by nom asc", $devid);
    while ($firmwares = db_fetch_array($query)) {
        //echo "<hr>firmwares[fid]=". $firmwares["fid"] ."firmwares[mid]=". $firmwares["mid"]. " firmwares[nom]=". $firmwares["nom"];
        //echo "<br>firmwares[fid]=". firmwares["fid"];
        if ($firmwares["mid"] == $devid) {
            $firms_compatibles[$firmwares["firmware_id"]] = $firmwares["nom"];
        } else {
            $firms_tots[$firmwares["firmware_id"]] = $firmwares["nom"];
        }
    }
    $form['firmware']['firmwaresCompatibles'] = array('#type' => 'select', '#access' => in_array('wireless', $dev->arr_model_class) || in_array('router', $dev->arr_model_class), '#title' => t('firmwares compatibles'), '#default_value' => 0, '#options' => $firms_compatibles, '#description' => t('firmwares compatibles amb aquest model.'), '#size' => 10, '#multiple' => true, '#required' => false, '#validated' => true, '#prefix' => '<tr><td class="mselects" align="left" colspan="2"><table style="width:575px"><tr><td style="width:250px">', '#suffix' => '</td><td  style="width:50px">', '#weight' => $form_weight++, '#attributes' => array('style' => 'width:250px;height:350px'));
    $disponiblesButtonOne = '<input type="button" value=">" id="associatsButtonOne" class="selectButtons" style="width:40px;margin:5px 0;">';
    $disponiblesButtonAll = '<input type="button" value=">>" id="associatsButtonAll" class="selectButtons" style="width:40px;margin:5px 0;">';
    $associatsButtonOne = '<input type="button" value="<" id="disponiblesButtonOne" class="selectButtons" style="width:40px;margin:5px 0;">';
    $associatsButtonAll = '<input type="button" value="<<" id="disponiblesButtonAll" class="selectButtons" style="width:40px;margin:5px 0;">';
    $botons = $disponiblesButtonOne . '<br>';
    $botons .= $disponiblesButtonAll . '<br>';
    $botons .= $associatsButtonOne . '<br>';
    $botons .= $associatsButtonAll . '<br>';
    $form['firmware']['firmwaresTots'] = array('#type' => 'select', '#access' => in_array('wireless', $dev->arr_model_class) || in_array('router', $dev->arr_model_class), '#title' => t('Tots els firmwares'), '#default_value' => 0, '#options' => $firms_tots, '#description' => t('Tots els firmwares.'), '#size' => 10, '#multiple' => true, '#required' => false, '#validated' => true, '#prefix' => $botons . '</td><td  style="width:250px">', '#suffix' => '</td></tr></table></td></tr>', '#weight' => $form_weight++, '#attributes' => array('style' => 'width:250px;height:350px'));
    return $form;
}
Пример #7
0
/**
 * 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;
}
Пример #8
0
/**
 *
 * @param GuifiAPI $gapi GuifiAPI object
 *
 * @param mixed[] $parameters
 *
 * @return
 */
function guifi_api_misc_channel($gapi, $parameters)
{
    if (!guifi_api_check_fields($gapi, array('protocol'), $parameters)) {
        return FALSE;
    }
    if (!guifi_validate_types('protocol', $parameters['protocol'])) {
        $gapi->addError(403, "protocol not found: {$parameters['protocol']}");
        return FALSE;
    }
    $types = guifi_types('channel', NULL, NULL, $parameters['protocol']);
    $channels = array();
    foreach ($types as $type_title => $type_description) {
        $channels[] = array('title' => $type_title, 'description' => $type_description);
    }
    $gapi->addResponseField('channels', $channels);
    return TRUE;
}
Пример #9
0
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;
}
Пример #10
0
function guifi_vinterface_form($iClass, $vinterface, $first_port = true, $eInterfaces)
{
    global $user;
    switch ($iClass) {
        case 'vlans':
            $iconNew = '/icons/vlans-new.png';
            $iType = 'vlan';
            break;
        case 'aggregations':
            $iconNew = '/icons/aggr-new.png';
            $iType = 'aggregation';
            break;
    }
    guifi_log(GUIFILOG_TRACE, 'function guifi_vinterface_form (iClass)', $iClass);
    if (empty($vinterface[interface_type])) {
        if (isset($vinterface[iname])) {
            $vinterface[interface_type] = $vinterface[iname];
        } else {
            $vinterface[interface_type] = substr($iType, 0, 4) . $vinterface[id];
        }
    }
    $prefix = '';
    $suffix = '';
    guifi_log(GUIFILOG_TRACE, 'function guifi_vinterface_form (vinterface)', $vinterface);
    /*  if ($vinterface['deleted']) {
        $form['deleted'] = array(
          '#type'         => 'hidden',
          '#value'        => $vinterface['deleted'],
          '#weight'       => $form_weight++,
        );
        $form['deletedMsg'] = array(
          '#type'         => 'item',
          '#value'        => $vinterface[interface_type]. ' '. t('Will be deleted when saving the device'),
        );
        return $form;
      } */
    $form = array('#type' => 'fieldset', '#parents' => array($iClass, $vinterface[id]), '#attributes' => array('class' => 'fieldset-interface-port'), '#prefix' => '<div id="fieldset-port-' . $vinterface[id] . '">', '#suffix' => '</div>', '#tree' => TRUE);
    if ($vinterface[interface_class] == 'wds/p2p') {
        $vlan_wds = TRUE;
    }
    $form['interface_class'] = array('#type' => 'select', '#title' => $first_port ? t('%iClass type', array('%iClass' => $iType)) : false, '#options' => guifi_types($iType), '#default_value' => $vinterface[interface_class], '#disabled' => $vlan_wds ? TRUE : FALSE or $vinterface['deleted'] ? TRUE : FALSE, '#attributes' => array('class' => 'interface-item'));
    $form['interface_type'] = array('#type' => 'textfield', '#title' => $first_port ? t('name') : false, '#default_value' => $vinterface[interface_type], '#size' => 20, '#maxlength' => 40, '#attributes' => array('class' => 'interface-item'));
    if ($form['interface_type']['#disabled']) {
        $form['interface_type']['#value'] = $vinterface[interface_type];
        $form['interface_type']['#attributes'] = array('class' => 'interface-item-disabled');
        if (empty($vinterface['deleted'])) {
            $form['iname'] = array('#type' => 'hidden', '#value' => $vinterface['interface_type']);
        }
    }
    guifi_log(GUIFILOG_TRACE, 'function guifi_vinterface_form(type)', $vinterface);
    // $eInterfaces = array_merge(array(''=>t('not defined')),$eInterfaces);
    $form['related_interfaces'] = array('#type' => 'select', '#title' => $first_port ? t('parent') : false, '#options' => array_diff($eInterfaces, array($vinterface[interface_type])), '#default_value' => $vinterface['related_interfaces'], '#disabled' => $vlan_wds ? TRUE : FALSE or $vinterface['deleted'] ? TRUE : FALSE, '#attributes' => array('class' => 'interface-item'));
    if ($iType == 'aggregation') {
        // if ($iClass == 'vlans') {
        $form['related_interfaces']['#size'] = 4;
        $form['related_interfaces']['#multiple'] = true;
        $form['related_interfaces']['#title'] = $first_port ? t('parents') : false;
    }
    if (!$vinterface[deleted]) {
        $form['vlan'] = array('#type' => 'textfield', '#type' => $iClass == 'vlans' ? 'textfield' : 'hidden', '#title' => $first_port ? t('vlan id') : false, '#size' => 6, '#maxlength' => 10, '#default_value' => $vinterface[vlan], '#disabled' => $vlan_wds ? TRUE : FALSE or $vinterface['deleted'] ? TRUE : FALSE, '#attributes' => array('class' => 'interface-item'));
    }
    $form['comments'] = array('#type' => 'textfield', '#title' => $first_port ? t('comments') : false, '#size' => 40, '#maxlength' => 60, '#disabled' => $vinterface['deleted'] ? TRUE : FALSE, '#default_value' => $vinterface[comments], '#attributes' => $vinterface['deleted'] ? array('class' => 'interface-item-disabled') : array('class' => 'interface-item'));
    if ($vinterface[deleted]) {
        $form['comments']['#value'] = t('will be deleted. press "reset" to cancel');
    }
    if (!$vinterface[deleted]) {
        //   if ($vinterface['mac'] === '00:00:00:00:00:00')
        //     $vinterface['mac'] = '';
        $form['mac'] = array('#type' => 'textfield', '#title' => $first_port ? t('mac') : false, '#size' => 20, '#maxlength' => 17, '#default_value' => $vinterface['mac'], '#element_validate' => array('guifi_mac_validate'));
    }
    if (!$vinterface[deleted]) {
        $form['delete'] = array('#type' => 'image_button', '#title' => $first_port ? t('delete') : false, '#src' => drupal_get_path('module', 'guifi') . '/icons/drop.png', '#attributes' => array('title' => t('Delete interface')), '#submit' => array('guifi_vinterfaces_delete_submit'), '#prefix' => $first_port ? '<div class="form-item"><label>&nbsp</label>' : false, '#suffix' => $first_port ? '</div>' : false);
    }
    // Hidden fields
    $form['id'] = array('#type' => 'hidden', '#value' => $vinterface['id']);
    $form['device_id'] = array('#type' => 'hidden', '#value' => $vinterface['device_id']);
    $form['connto_did'] = array('#type' => 'hidden', '#value' => $vinterface['connto_did']);
    $form['connto_iid'] = array('#type' => 'hidden', '#value' => $vinterface['connto_iid']);
    if ($vinterface['deleted']) {
        $form['deleted'] = array('#type' => 'hidden', '#value' => $vinterface['deleted']);
    }
    if ($vinterface['new']) {
        $form['new'] = array('#type' => 'hidden', '#value' => $vinterface['new']);
    }
    //      $form['interface_type']['#value'] = $vinterface['interface_type'];
    return $form;
}
Пример #11
0
 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;
 }
Пример #12
0
/**
 * Add ipv4s dialog
 * Used at device/radio edit form, at IPv4 Networking section for adding
 *  Public, Private subnetworks, or get an IP from an already defined subnetwork
 *  at another device 
 *
 * URL: http://guifi.net/guifi/js/add-ipv4s
 */
function guifi_ahah_add_ipv4s()
{
    $cid = 'form_' . $_POST['form_build_id'];
    $cache = cache_get($cid, 'cache_form');
    $iClass = arg(3);
    guifi_log(GUIFILOG_TRACE, 'guifi_ahah_add_ipv4s(' . $iClass . ')', $_POST[ipv4][ipv4sdialog][netmask]);
    //if (!$net) {
    //  drupal_set_message(t(
    //    'Unable to allocate new range, no networks available'),'warning');
    //  return FALSE;
    //}
    if ($cache) {
        $form = $cache->data;
        $form_dialog = $form['ipv4']['ipv4sdialog'];
        guifi_log(GUIFILOG_TRACE, 'guifi_ahah_add_ipv4s(dialog)', $form_dialog);
        // Dialog fields
        $form['ipv4']['ipv4sdialog']['#type'] = 'fieldset';
        $form['ipv4']['ipv4sdialog']['#collapsed'] = false;
        $form['ipv4']['ipv4sdialog']['#collapsible'] = true;
        switch ($iClass) {
            case 'private':
                $form['ipv4']['ipv4sdialog']['adddid']['#type'] = 'hidden';
                $form['ipv4']['ipv4sdialog']['adddid']['#value'] = false;
                $form['ipv4']['ipv4sdialog']['snet']['#type'] = 'hidden';
                $form['ipv4']['ipv4sdialog']['snet']['#value'] = false;
                $form['ipv4']['ipv4sdialog']['netmask']['#type'] = 'select';
                $form['ipv4']['ipv4sdialog']['netmask']['#value'] = '255.255.255.252';
                $form['ipv4']['ipv4sdialog']['ipv4_type']['#value'] = 2;
                $form['ipv4']['ipv4sdialog']['ipv4']['#type'] = 'textfield';
                $form['ipv4']['ipv4sdialog']['netmask']['#options'] = guifi_types('netmask', 30, 26);
                $form['ipv4']['ipv4sdialog']['netmask']['#description'] = t('%class subnetwork size (mask)', array('%class' => $iClass));
                $form['ipv4']['ipv4sdialog']['#description'] = t('Obtain a new %class subnetwork range and get an IPv4 address from it', array('%class' => $iClass));
                break;
            case 'public':
                $form['ipv4']['ipv4sdialog']['adddid']['#type'] = 'hidden';
                $form['ipv4']['ipv4sdialog']['adddid']['#value'] = false;
                $form['ipv4']['ipv4sdialog']['snet']['#type'] = 'hidden';
                $form['ipv4']['ipv4sdialog']['snet']['#value'] = false;
                $form['ipv4']['ipv4sdialog']['netmask']['#type'] = 'select';
                $form['ipv4']['ipv4sdialog']['netmask']['#value'] = '255.255.255.224';
                $form['ipv4']['ipv4sdialog']['ipv4_type']['#value'] = 1;
                $form['ipv4']['ipv4sdialog']['ipv4']['#type'] = 'textfield';
                $form['ipv4']['ipv4sdialog']['netmask']['#options'] = guifi_types('netmask', 30, 22);
                $form['ipv4']['ipv4sdialog']['netmask']['#description'] = t('%class subnetwork size (mask)', array('%class' => $iClass));
                $form['ipv4']['ipv4sdialog']['#description'] = t('Obtain a new %class subnetwork range and get an IPv4 address from it', array('%class' => $iClass));
                break;
            case 'netmask':
                $form['ipv4']['ipv4sdialog']['netmask']['#value'] = $_POST[ipv4][ipv4sdialog][netmask];
                break;
            case 'defined':
                $form['ipv4']['ipv4sdialog']['netmask']['#type'] = 'hidden';
                $form['ipv4']['ipv4sdialog']['adddid']['#type'] = 'textfield';
                $form['ipv4']['ipv4sdialog']['snet']['#type'] = 'select';
                $form['ipv4']['ipv4sdialog']['ipv4']['#type'] = 'hidden';
                $form['ipv4']['ipv4sdialog']['ipv4']['#value'] = 'false';
                $form['ipv4']['ipv4sdialog']['#description'] = t('Get a new ip from an already defined subnetwork range at any existing device');
        }
        // Obtaining ipv4
        if ($iClass != 'defined') {
            $ntype = $form['ipv4']['ipv4sdialog']['ipv4_type']['#value'];
            drupal_set_message(t('Obtaining a new %type range', array('%type' => $ntype == 1 ? t('public') : t('private'))), 'warning');
            $ips_allocated = guifi_ipcalc_get_ips('0.0.0.0', '0.0.0.0', $_POST, $ntype);
            $net = guifi_ipcalc_get_subnet_by_nid($_POST[nid], $form['ipv4']['ipv4sdialog']['netmask']['#value'], $ntype == 1 ? 'public' : 'backbone', $ips_allocated, 'Yes', TRUE);
            $form['ipv4']['ipv4sdialog']['ipv4']['#value'] = long2ip(ip2long($net) + 1);
        }
        unset($form['ipv4']['ipv4sdialog']['#prefix']);
        unset($form['ipv4']['ipv4sdialog']['#suffix']);
        guifi_log(GUIFILOG_TRACE, 'guifi_ahah_add_ipv4s(dialog)', $form['ipv4']['ipv4sdialog']);
        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'] = $_POST;
        $form = form_builder($form['form_id']['#value'], $form, $form_state);
        $output = theme('status_messages') . drupal_render($form['ipv4']['ipv4sdialog']);
        drupal_json(array('status' => TRUE, 'data' => $output));
    } else {
        drupal_json(array('status' => FALSE, 'data' => ''));
    }
    exit;
    // Build the new form.
    $form_state = array('submitted' => FALSE);
    $form_build_id = $_POST['form_build_id'];
    // Add the new element to the stored form. Without adding the element to the
    // form, Drupal is not aware of this new elements existence and will not
    // process it. We retreive the cached form, add the element, and resave.
    $form = form_get_cache($form_build_id, $form_state);
    $choice_form = $form[ipv4s][ipv4sdialog];
    $form[ipv4s][ipv4sdialog] = $form_dialog;
    form_set_cache($form_build_id, $form, $form_state);
    $form += array('#post' => $_POST, '#programmed' => FALSE);
    // Rebuild the old form.
    $form = form_builder('guifi_device_form', $form, $form_state);
    // Render the new output.
    $choice_form = $form[ipv4s][ipv4sdialog];
    unset($choice_form['#prefix'], $choice_form['#suffix']);
    // Prevent duplicate wrappers.
    unset($choice_form[$delta]);
    // build new form
    $fs = array();
    $form_element['#post'] = array();
    $form_element = form_builder($form_element['form_id']['#value'], $form_element, $fs);
    $newfield = drupal_render($form_element);
    //  guifi_log(GUIFILOG_BASIC,sprintf('choice_form %d',$delta),htmlspecialchars($newfield));
    $output = theme('status_messages') . drupal_render($choice_form) . $newfield;
    drupal_json(array('status' => TRUE, 'data' => $output));
    exit;
}
Пример #13
0
/**
 * Present the guifi zone editing form.
 */
function guifi_service_form($node, $param)
{
    global $user;
    guifi_log(GUIFILOG_TRACE, 'guifi_service_form()', $node);
    drupal_set_breadcrumb(guifi_zone_ariadna($node->zone_id, 'node/%d/view/services'));
    // $f = guifi_form_hidden_var($node,array('id'));
    if (empty($node->nid) and is_numeric($node->title)) {
        $zone = guifi_zone_load($node->title);
        $node->zone_id = $node->title;
        $node->contact = $user->mail;
        $default = t('<service>');
        $node->title = NULL;
        $node->nick = $zone->nick . $default;
        $node->status_flag = 'Planned';
    }
    if (isset($node->id)) {
        $f['id'] = array('#type' => 'hidden', '#value' => $node->id);
    }
    $type = db_fetch_object(db_query("SELECT description FROM {guifi_types} WHERE type='service' AND text='%s'", $node->service_type));
    if ($node->nid > 0) {
        $f['service_type'] = array('#type' => 'item', '#value' => t('Service type'), '#description' => t($type->description));
    }
    //$output = form_item(t('Service type'),$node->service_type,t($type->description));
    $type = node_get_types('type', $node);
    if ($type->has_title) {
        $f['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title);
    }
    $f['nick'] = array('#type' => 'textfield', '#title' => t('Nick'), '#required' => FALSE, '#size' => 20, '#maxlength' => 20, '#default_value' => $node->nick, '#element_validate' => array('guifi_service_nick_validate'), '#collapsible' => FALSE, '#tree' => TRUE, '#description' => t("Unique identifier for this service. Avoid generic names such 'Disk Server', use something that really describes what is doing and how can be distinguished from the other similar services.<br />Short name, single word with no spaces, 7-bit chars only."));
    //$output .= form_textfield(t("Nick"), "nick", $node->nick, 20, 20, t("Unique identifier for this service. Avoid generic names such 'Disk Server', use something that really describes what is doing and how can be distinguished from the other similar services.<br />Short name, single word with no spaces, 7-bit chars only.") . ($error['nick'] ? $error["nick"] : ''), NULL, TRUE);
    $f['notification'] = array('#type' => 'textfield', '#title' => t('Contact'), '#required' => FALSE, '#size' => 60, '#maxlength' => 128, '#default_value' => $node->notification, '#element_validate' => array('guifi_emails_validate'), '#description' => t("Who did possible this service or who to contact with regarding this service if it is distinct of the owner of this page."));
    //$output .= form_textfield(t("Contact"), "contact", $node->contact, 60, 128, t("Who did possible this service or who to contact with regarding this service if it is distinct of the owner of this page.") . ($error['contact'] ? $error["contact"] : ''));
    ////  $output .= form_select(t('Zone'), 'zone_id', $node->zone_id, guifi_zones_listbox(), t('The zone where this node where this node belongs to.'));
    $f['server'] = array('#type' => 'textfield', '#title' => t("Device"), '#size' => 60, '#maxlength' => 128, '#default_value' => guifi_server_descr($node->device_id), '#element_validate' => array('guifi_servername_validate'), '#autocomplete_path' => 'guifi/js/select-server', '#description' => t('Where it runs.'));
    //$params .= guifi_form_column(form_select(t('Device'), "device_id", $node->device_id, guifi_servers_select(),t('Where it runs.')));
    if (!$node->nid) {
        $f['service_type'] = array('#type' => 'select', '#title' => t("Service"), '#default_value' => $node->service_type, '#options' => guifi_types('service'), '#description' => t('Type of service'));
        //$types = guifi_types('service');
        //array_shift($types);
        //$params.= guifi_form_column(form_select(t('Service'), "service_type", $node->service_type, $types,t('Type of service')));
    } else {
        $f['protocol'] = array('#type' => 'hidden', '#title' => t("service_type"), '#value' => $node->service_type);
    }
    //$output .= form_hidden("service_type",$node->service_type);
    $f['status_flag'] = array('#type' => 'select', '#title' => t("Status"), '#default_value' => $node->status_flag, '#options' => guifi_types('status'), '#description' => t('Current status'));
    //$params .= guifi_form_column(form_select(t('Status'), 'status_flag', $node->status_flag, guifi_types('status'), t('Current status')));
    //$output .= guifi_form_column_group(t('General parameters'),$params, NULL);
    // $node->var = unserialize($node->extra);
    if ($node->nid > 0) {
        $f['var'] = array('#type' => 'fieldset', '#title' => $node->service_type . ' ' . t("settings"), '#tree' => TRUE, '#collapsible' => TRUE, '#collapsed' => FALSE);
    }
    if ($node->nid > 0) {
        switch ($node->service_type) {
            case 'mail':
                $f['var']['in'] = array('#type' => 'textfield', '#title' => t('Inbound mail server'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['in'], '#description' => t('Where email clients have to be configured for getting email messages'));
                $f['var']['out'] = array('#type' => 'textfield', '#title' => t('Outbound mail server'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['out'], '#description' => t('Where email clients have to be configured for sending email messages'));
                $f['var']['webmail'] = array('#type' => 'textfield', '#title' => t('Webmail url'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['webmail'], '#description' => t('URL for accessing to this mail server, if there is'));
                $f['var']['admin'] = array('#type' => 'textfield', '#title' => t('Admin web interface'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['admin'], '#description' => t('Where to create/edit/delete users, change passwords, etc...'));
                break;
            case 'asterisk':
                $f['var']['prefix'] = array('#type' => 'textfield', '#title' => t('Dial prefix'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['prefix'], '#description' => t('Dial prefix for calling this server extensions'));
                $f['var']['incoming'] = array('#type' => 'textfield', '#title' => t('Incoming calls'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['incoming'], '#description' => t('Server or IP address where the calls have to be sent'));
                $f['var']['protocols'] = array('#type' => 'checkboxes', '#title' => t('Protocols'), '#required' => TRUE, '#default_value' => $node->var['protocols'], '#options' => array('IAX' => 'IAX', 'SIP' => 'SIP'));
                break;
            case 'NTP':
                $f['var']['ntp'] = array('#type' => 'textfield', '#title' => t('IP address or hostname'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['ntp']);
                break;
            case 'ftp':
                $f['var']['ftphost'] = array('#type' => 'textfield', '#title' => t('IP address or hostname'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['ftphost']);
                $f['var']['protocols'] = array('#type' => 'checkboxes', '#title' => t('Protocols'), '#required' => TRUE, '#default_value' => $node->var['protocols'], '#options' => array('SMB' => 'SMB (Samba)', 'ftp' => 'FTP', 'nfs' => 'NFS'));
                break;
            case 'Proxy':
            case 'ADSL':
                $f['var']['down'] = array('#type' => 'select', '#title' => t('Download'), '#default_value' => $node->var['down'], '#options' => guifi_bandwidth_types(), '#description' => t('Download bandwidth'));
                $f['var']['up'] = array('#type' => 'select', '#title' => t('Upload'), '#options' => guifi_bandwidth_types(), '#default_value' => $node->var['up'], '#description' => t('Upload bandwidth'));
                if ($node->service_type == 'ADSL') {
                    break;
                }
                if (empty($node->var['fed'])) {
                    $node->var['fed'] = array('IN' => '0', 'OUT' => '0');
                }
                $f['var']['fed'] = array('#type' => 'checkboxes', '#title' => t('Proxy federation'), '#default_value' => $node->var['fed'], '#options' => array('IN' => t('Allow login of users from OUT federated proxys'), 'OUT' => t('Allow proxy users to use other IN federated proxys')));
                $f['var']['proxy'] = array('#type' => 'textfield', '#title' => t("Name"), '#default_value' => $node->var['proxy'], '#size' => 60, '#maxlength' => 60);
                $f['var']['port'] = array('#type' => 'textfield', '#title' => t("Port"), '#default_value' => $node->var['port'], '#size' => 60, '#maxlength' => 60);
                $f['var']['type'] = array('#type' => 'select', '#title' => t("Type"), '#default_value' => $node->var['type'], '#options' => array('HTTP' => 'HTTP', 'Socks4' => 'SOCKS4', 'Socks5' => 'SOCKS5', 'arp' => 'ARP', 'ftp' => 'FTP'));
                break;
            case 'SNPgraphs':
                $f['var']['version'] = array('#type' => 'select', '#title' => t('version'), '#default_value' => $node->var['version'], '#options' => drupal_map_assoc(array('1.0', '2.0')), '#description' => t('version of the CNML services'));
                $f['var']['url'] = array('#type' => 'textfield', '#title' => t('url'), '#size' => 60, '#maxlength' => 250, '#default_value' => $node->var['url'], '#description' => t('Base url to call CNML services'));
                break;
            default:
                $f['var']['url'] = array('#type' => 'textfield', '#title' => t('url'), '#size' => 60, '#maxlength' => 250, '#default_value' => $node->var['url']);
                break;
        }
    }
    // multiple fields
    $delta = 0;
    if ($node->nid > 0) {
        switch ($node->service_type) {
            case 'mail':
                $f['var']['domains'] = guifi_service_multiplefield($node->var['domains'], 'domains', t('Managed domains'));
                break;
            case 'web':
                $f['var']['homepages'] = guifi_service_multiplefield($node->var['homepages'], 'homepages', t('URL pointing to the website homepage'));
                break;
            case 'irc':
                $f['var']['irc'] = guifi_service_multiplefield($node->var['irc'], 'irc', t('IRC server hostname'));
                break;
        }
    }
    if ($type->has_body) {
        $f['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
    }
    return $f;
}
Пример #14
0
function guifi_ipv4_link_form(&$f, $ipv4, $interface, $tree, &$weight)
{
    global $definedBridgeIpv4;
    $ki = $tree[count($tree) - 3];
    $ka = $tree[count($tree) - 1];
    if (count($tree) > 4) {
        $rk = $tree[1];
    } else {
        $rk = NULL;
    }
    if ($interface['interface_type'] == 'wLan/Lan') {
        $bridge = TRUE;
    }
    if ($ipv4['netmask'] != '255.255.255.252' or count($ipv4['links']) == 0) {
        // multilink set
        $multilink = TRUE;
        $f['local'] = array('#type' => 'fieldset', '#parents' => $tree, '#title' => $ipv4['ipv4'] . ' / ' . $ipv4['netmask'] . ' - ' . count($ipv4['links']) . ' ' . t('link(s)'), '#weight' => $weight++, '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => $weight++);
        $prefix = '<table><tr><td>';
        $f['local']['id'] = array('#type' => 'hidden', '#parents' => array_merge($tree, array('id')), '#default_value' => $ipv4['id']);
        if (user_access('administer guifi networks')) {
            $f['local']['ipv4'] = array('#type' => 'textfield', '#parents' => array_merge($tree, array('ipv4')), '#size' => 16, '#maxlength' => 16, '#default_value' => $ipv4['ipv4'], '#title' => t('Local IPv4'), '#prefix' => $prefix, '#suffix' => '</td>', '#weight' => 0);
            $f['local']['netmask'] = array('#type' => 'select', '#parents' => array_merge($tree, array('netmask')), '#title' => t("Network mask"), '#default_value' => $ipv4['netmask'], '#options' => guifi_types('netmask', 30, 0), '#prefix' => '<td>', '#suffix' => '</td>', '#weight' => 1);
        } else {
            $f['local']['ipv4'] = array('#type' => 'item', '#parents' => array_merge($tree, array('ipv4')), '#title' => t('Local IPv4'), '#value' => $ipv4['ipv4'], '#description' => $ipv4['netmask'], '#prefix' => $prefix, '#suffix' => '</td>', '#weight' => 0);
        }
    } else {
        // singlelink set
        $multilink = FALSE;
        $prefix = '<td>';
    }
    // foreach link
    if (count($ipv4['links'])) {
        foreach ($ipv4['links'] as $kl => $link) {
            if ($link['deleted']) {
                continue;
            }
            // linked node-device
            guifi_link_form($f['links'][$kl], $link, $ipv4, $tree, $multilink);
        }
    }
    // foreach link
    // Deleting the IP address
    switch ($interface['interface_type']) {
        case 'wds/p2p':
            break;
        case 'wLan/Lan':
            if (!$definedBridgeIpv4) {
                $f['local']['delete_address'] = array('#type' => 'item', '#parents' => array_merge($tree, array('comment_address')), '#value' => t('Main public address'), '#description' => t('wLan/Lan public IP address is required. No delete allowed.'), '#prefix' => '<td>', '#suffix' => '</td></tr></table>', '#description' => t('Can\'t delete this address. The device should have at least one public IP address.'), '#weight' => 3);
                $definedBridgeIpv4 = TRUE;
                break;
            }
        default:
            $f['local']['delete_address'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/drop.png', '#parents' => array_merge($tree, array('delete_address')), '#attributes' => array('title' => t('Delete ipv4 address')), '#submit' => array('guifi_ipv4_delete_submit'), '#prefix' => '<td>', '#suffix' => '</td></tr></table>', '#weight' => 3);
    }
    // switch $it (interface_type)
    return count($ipv4['links']);
}
Пример #15
0
function guifi_traceroute_search_form($form_state, $from = NULL, $to = array())
{
    $ftitle = t('From:');
    if ($from) {
        $fname = guifi_get_devicename($from, 'large');
        $ftitle .= ' ' . $fname;
    }
    $search_help = t('To find the device, you can write some letters to find the available devices in the database.');
    $form['from'] = array('#type' => 'fieldset', '#title' => $ftitle, '#collapsible' => TRUE, '#collapsed' => $from);
    $form['from']['from_description'] = array('#type' => 'textfield', '#title' => t('Device'), '#required' => TRUE, '#default_value' => $fname, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => 'guifi/js/select-node-device', '#element_validate' => array('guifi_devicename_validate'), '#description' => t('Search for a device to trace the route from.') . '<br />' . $search_help);
    $dtitle = t('To:');
    if (count($to)) {
        if (is_numeric($to[0])) {
            $dname = guifi_get_devicename($to[0], 'large');
            $dservice = '';
            $dtitle .= ' ' . $dname;
        } else {
            $dservice = $to[0];
            $dname = '';
            $dtitle .= ' ' . t('Explore service !service', array('!service' => $to[0]));
        }
    }
    $form['to'] = array('#type' => 'fieldset', '#title' => $dtitle, '#collapsible' => TRUE, '#collapsed' => count($to), '#description' => t('Choose between tracing a route to a known device, or discover services by selecting a service type. Yo use only one option at a time, and then press the <em>"Get traceroute"</em> button to get the list of possible known routes ordered by best route first.'));
    $form['to']['to_description'] = array('#type' => 'textfield', '#title' => t('Device'), '#default_value' => $dname, '#size' => 60, '#maxlength' => 128, '#element_validate' => array('guifi_devicename_validate'), '#autocomplete_path' => 'guifi/js/select-node-device', '#description' => t('Target device to trace the route to.') . '<br />' . $search_help, '#prefix' => '<table><tr><td>', '#suffix' => '</td>');
    $types[] = t('<select one from this list>');
    $form['to']['discover_service'] = array('#type' => 'select', '#title' => t("Service"), '#default_value' => $dservice, '#options' => array_merge($types, guifi_types('service')), '#description' => t('Type of service to be discovered'), '#prefix' => '<td>', '#suffix' => '</td>');
    $form['submit'] = array('#type' => 'submit', '#value' => t('Get traceroute'), '#prefix' => '<td>', '#suffix' => '</td></tr></table>');
    return $form;
}
Пример #16
0
/** guifi_zone_form(): Present the guifi zone editing form.
 */
function guifi_zone_form(&$node, &$param)
{
    guifi_log(GUIFILOG_TRACE, 'function guifi_zone_form()', $node);
    drupal_set_breadcrumb(guifi_zone_ariadna($node->id));
    $form_weight = -20;
    $type = node_get_types('type', $node);
    if ($type->has_title) {
        $form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => $form_weight++);
    }
    $form['jspath'] = array('#type' => 'hidden', '#value' => base_path() . drupal_get_path('module', 'guifi') . '/js/');
    $form['master'] = guifi_zone_autocomplete_field($node->master, 'master');
    $form['master']['#weight'] = $form_weight++;
    if ($type->has_body) {
        $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
        $form['body_field']['#weight'] = $form_weight++;
    }
    // This is for non-admin users, they don't need to edit more information
    if (!user_access('administer guifi zones')) {
        return $form;
    }
    $form['nick'] = array('#type' => 'textfield', '#title' => t('Short abreviation'), '#required' => FALSE, '#default_value' => $node->nick, '#size' => 8, '#maxlength' => 10, '#element_validate' => array('guifi_zone_nick_validate'), '#description' => t('Single word, 7-bits characters. Used while default values as hostname, SSID, etc...'), '#weight' => $form_weight++);
    /*
     * maintainers fieldset
     */
    $form['maintainers'] = guifi_maintainers_form($node, $form_weight);
    $form['time_zone'] = array('#type' => 'select', '#title' => t('Time zone'), '#required' => FALSE, '#default_value' => $node->time_zone, '#options' => guifi_types('tz'), '#weight' => $form_weight++);
    $form['homepage'] = array('#type' => 'textfield', '#title' => t('Zone homepage'), '#required' => FALSE, '#default_value' => $node->homepage, '#size' => 60, '#maxlength' => 128, '#description' => t('URL of the local community homepage, if exists. Useful for those who want to use this site just for network administration, but have their own portal.'), '#weight' => $form_weight++);
    $form['notification'] = array('#type' => 'textfield', '#title' => t('email notification'), '#required' => TRUE, '#default_value' => $node->notification, '#size' => 60, '#maxlength' => 1024, '#element_validate' => array('guifi_emails_validate'), '#description' => t('Mails where changes at the zone will be notified. Useful for decentralized administration. If more than one, separated by \',\''), '#weight' => $form_weight++);
    // Service parameters
    $form['zone_services'] = array('#type' => 'fieldset', '#title' => t('Zone services'), '#weight' => $form_weight++, '#collapsible' => FALSE, '#collapsed' => TRUE, '#prefix' => '<div>');
    $proxystr = guifi_service_str($node->proxy_id);
    function _service_descr($type)
    {
        return t('Select the default %type to be used at this ' . 'zone.<br />' . 'You can find the %type by introducing part of the id number, ' . 'zone name or proxy name. A list with all matching values ' . 'with a maximum of 50 values will be created.<br />' . 'You can refine the text to find your choice.', array('%type' => $type));
    }
    $form['zone_services']['proxystr'] = array('#type' => 'textfield', '#title' => t('default proxy'), '#maxlength' => 80, '#default_value' => $proxystr, '#autocomplete_path' => 'guifi/js/select-service/proxy', '#element_validate' => array('guifi_service_name_validate', 'guifi_zone_service_validate'), '#description' => _service_descr('proxy'));
    $form['zone_services']['proxy_id'] = array('#type' => 'hidden', '#value' => $node->proxy_id);
    $graphstr = guifi_service_str($node->graph_server);
    $form['zone_services']['graph_serverstr'] = array('#type' => 'textfield', '#title' => t('default graphs server'), '#maxlength' => 80, '#required' => FALSE, '#default_value' => $graphstr, '#autocomplete_path' => 'guifi/js/select-service/SNPgraphs', '#element_validate' => array('guifi_service_name_validate', 'guifi_zone_service_validate'), '#description' => _service_descr('graph server'));
    $form['zone_services']['graph_server'] = array('#type' => 'hidden', '#value' => $node->graph_server, '#suffix' => '</div>');
    // Separació Paràmetre globals de xarxa
    $form['zone_network_settings'] = array('#type' => 'fieldset', '#title' => t('Zone global network parameters'), '#weight' => $form_weight++, '#collapsible' => TRUE, '#collapsed' => TRUE, '#preffix' => '<div>');
    $form['zone_network_settings']['sep-global-param'] = array('#value' => '<hr /><h2>' . t('zone global network parameters') . '</h2>', '#weight' => $form_weight++);
    $form['zone_network_settings']['dns_servers'] = array('#type' => 'textfield', '#title' => t('DNS Servers'), '#required' => FALSE, '#default_value' => $node->dns_servers, '#size' => 60, '#maxlength' => 128, '#description' => t('The Name Servers of this zone, will inherit parent DNS servers if blank. Separated by ",".'), '#weight' => $form_weight++);
    $form['zone_network_settings']['ntp_servers'] = array('#type' => 'textfield', '#title' => t('NTP Servers'), '#required' => FALSE, '#default_value' => $node->ntp_servers, '#size' => 60, '#maxlength' => 128, '#description' => t('The network time protocol (clock) servers of this zone, will inherit parent NTP servers if blank. Separated by ",".'), '#weight' => $form_weight++);
    $form['zone_network_settings']['ospf_zone'] = array('#type' => 'textfield', '#title' => t('OSPF zone id'), '#required' => FALSE, '#default_value' => $node->ospf_zone, '#size' => 60, '#maxlength' => 128, '#element_validate' => array('guifi_zone_ospf_validate'), '#description' => t('The id that will be used when creating configuration files for the OSPF routing protocol so all the routers within the zone will share a dynamic routing table.'), '#weight' => $form_weight++, '#suffix' => '</div>');
    // Separació Paràmetres dels mapes
    $form['zone_mapping'] = array('#type' => 'fieldset', '#title' => t('Zone mapping parameters'), '#weight' => $form_weight++, '#collapsible' => TRUE, '#collapsed' => FALSE);
    $form['zone_mapping']['sep-maps-param'] = array('#value' => '<hr /><h2>' . t('zone mapping parameters') . '</h2>', '#weight' => $form_weight++);
    // if gmap key defined, prepare scripts anf launch google maps integration
    if (guifi_gmap_key()) {
        drupal_add_js(drupal_get_path('module', 'guifi') . '/js/guifi_gmap_zonelimits.js', 'module');
        $form['zone_mapping']['GMAP'] = array('#type' => 'item', '#title' => t('Map'), '#description' => t('Drag the South-West/North-East corners over the map to change the zone boundaries.'), '#suffix' => '<div id="map" style="width: 100%; height: 437px; margin:5px;"></div>', '#weight' => $form_weight++);
        $form['guifi_wms'] = array('#type' => 'hidden', '#value' => variable_get('guifi_wms_service', ''));
    }
    $form['zone_mapping']['MIN_help'] = array('#type' => 'item', '#title' => t('Bottom-left (SW) corner'), '#description' => t('Coordinates (Lon/Lat) of the bottom-left (South-West) corner of the map.'), '#weight' => $form_weight++);
    $form['zone_mapping']['minx'] = array('#type' => 'textfield', '#default_value' => $node->minx, '#size' => 12, '#maxlength' => 24, '#prefix' => '<table style="width: 32em"><tr><td style="width: 12em">', '#suffix' => '</td>', '#element_validate' => array('guifi_lon_validate'), '#description' => t('Longitude'), '#weight' => $form_weight++);
    $form['zone_mapping']['miny'] = array('#type' => 'textfield', '#default_value' => $node->miny, '#size' => 12, '#prefix' => '<td style="width: 12em">', '#suffix' => '</td></tr></table>', '#element_validate' => array('guifi_lat_validate'), '#description' => t('Latitude'), '#maxlength' => 24, '#weight' => $form_weight++);
    $form['zone_mapping']['MAX_help'] = array('#type' => 'item', '#title' => t('Upper-right (NE) corner'), '#description' => t('Coordinates (Lon/Lat) of the upper-right (North-East) corner of the map.'), '#weight' => $form_weight++);
    $form['zone_mapping']['maxx'] = array('#type' => 'textfield', '#default_value' => $node->maxx, '#size' => 12, '#maxlength' => 24, '#prefix' => '<table style="width: 32em"><tr><td style="width: 12em">', '#suffix' => '</td>', '#element_validate' => array('guifi_lon_validate'), '#description' => t('Longitude'), '#weight' => $form_weight++);
    $form['zone_mapping']['maxy'] = array('#type' => 'textfield', '#default_value' => $node->maxy, '#size' => 12, '#maxlength' => 24, '#prefix' => '<td style="width: 12em">', '#suffix' => '</td></tr></table>', '#element_validate' => array('guifi_lat_validate'), '#description' => t('Latitude'), '#weight' => $form_weight++);
    $form['#attributes'] = array('class' => zone_form);
    return $form;
}