Пример #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
/**
 * Select channel by protocol
 *
 * URL: http://guifi.net/guifi/js/channel/%
 *
 * @param $rid
 */
function guifi_ahah_select_channel($rid)
{
    $rid = arg(3);
    $cid = 'form_' . $_POST['form_build_id'];
    $cache = cache_get($cid, 'cache_form');
    $protocol = $_POST['radios'][$rid]['protocol'];
    $curr_channel = $_POST['radios'][$rid]['channel'];
    if ($cache) {
        $form = $cache->data;
        $form['r']['radios'][$rid]['s']['channel'] = guifi_radio_channel_field($rid, $curr_channel, $protocol);
        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['r']['radios'][$rid]['s']['channel']);
        drupal_json(array('status' => TRUE, 'data' => $output));
    } else {
        drupal_json(array('status' => FALSE, 'data' => ''));
    }
    exit;
}