function guifi_radio_form($edit, &$form_weight)
{
    global $hotspot;
    global $bridge;
    global $user;
    guifi_log(GUIFILOG_TRACE, 'function guifi_radio_form()', $edit);
    $querymid = db_query("\n    SELECT mid, model, f.name manufacturer\n    FROM guifi_model_specs m, guifi_manufacturer f\n    WHERE f.fid = m.fid\n    AND supported='Yes'\n    ORDER BY manufacturer, model ASC");
    while ($model = db_fetch_array($querymid)) {
        $models_array[$model["mid"]] = $model["manufacturer"] . ", " . $model["model"];
    }
    // codi pfc '#title' => t('Device model, firmware & MAC address').' ('.$models_array[$edit['mid']].')',
    $form['radio_settings'] = array('#type' => 'fieldset', '#title' => t('Device model, firmware & MAC address') . ' (' . $edit['variable']['firmware'] . ')', '#weight' => $form_weight++, '#collapsible' => TRUE, '#tree' => FALSE, '#collapsed' => !is_null($edit['id']));
    $form['radio_settings']['variable'] = array('#tree' => TRUE);
    // codi del PFC $form['radio_settings']['variable']['mid'] = array(
    // '#default_value' => $edit['mid'],
    $form['radio_settings']['variable']['model_id'] = array('#type' => 'select', '#title' => t("Radio Model"), '#required' => TRUE, '#default_value' => $edit['variable']['model_id'], '#options' => $models_array, '#description' => t('Select the radio model that do you have.'), '#prefix' => '<table><tr><td>', '#suffix' => '</td>', '#ahah' => array('path' => 'guifi/js/firmware_by_model', 'wrapper' => 'select-firmware', 'method' => 'replace', 'effect' => 'fade'), '#weight' => 0);
    $form['radio_settings']['variable']['firmware_id'] = guifi_radio_firmware_field($edit['variable']['firmware_id'], $edit['variable']['model_id']);
    $form['radio_settings']['variable']['firmware'] = array('#type' => 'hidden', '#default_value' => $edit['variable']['firmware']);
    $form['radio_settings']['mac'] = array('#type' => 'textfield', '#title' => t('Device MAC Address'), '#required' => TRUE, '#size' => 20, '#maxlength' => 20, '#default_value' => $edit['mac'], '#element_validate' => array('guifi_mac_validate'), '#description' => t("Base/Main MAC Address.<br />Some configurations won't work if is blank"), '#prefix' => '<td>', '#suffix' => '</td></tr></table>', '#weight' => 4);
    $collapse = TRUE;
    $msg = count($edit['radios']) ? format_plural(count($edit['radios']), '1 radio', '@count radios') : t('No radios');
    if (count($edit['radios'])) {
        foreach ($edit['radios'] as $value) {
            if ($value['unfold']) {
                $collapse = FALSE;
            }
        }
    }
    $form['r'] = array('#type' => 'fieldset', '#title' => $msg, '#collapsible' => TRUE, '#collapsed' => $collapse, '#tree' => FALSE, '#prefix' => '<img src="/' . drupal_get_path('module', 'guifi') . '/icons/wifi.png"> ' . t('Wireless networking section'), '#weight' => $form_weight++);
    $form['r']['radios'] = array('#tree' => TRUE);
    $rc = 0;
    $bridge = FALSE;
    $cinterfaces = 0;
    $cipv4 = 0;
    $clinks = 0;
    if (!empty($edit['radios'])) {
        foreach ($edit['radios'] as $key => $radio) {
            $hotspot = FALSE;
            //    if ($radio['deleted']) continue;
            $form['r']['radios'][$key] = guifi_radio_radio_form($radio, $key, $form_weight);
            $bw = $form_weight - 1000;
            // Going to paint the buttons
            // For AP Mode, clients_accepted
            if (!isset($radio['deleted'])) {
                $prefix = "<table><tr><td>";
                if ($radio['mode'] == 'ap') {
                    // If no wLan interface, allow to create one
                    if (count($radio['interfaces']) < 2 or user_access('administer guifi networks')) {
                        $form['r']['radios'][$key]['AddwLan'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/insertwlan.png', '#parents' => array('radios', $key, 'AddwLan'), '#submit' => array('guifi_radio_add_wlan_submit'), '#attributes' => array('title' => t('Add a public network range to the wLan for clients')), '#prefix' => $prefix, '#suffix' => '&nbsp;', '#weight' => $bw++);
                    }
                    $form['r']['radios'][$key]['AddWDSiface'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/wdsiface.png', '#parents' => array('radios', $key, 'AddWDSiface'), '#submit' => array('guifi_radio_add_wdsiface_submit'), '#attributes' => array('title' => t('Add wds interface')), '#prefix' => '&nbsp;', '#suffix' => '&nbsp;', '#weight' => $bw++);
                    if (!$hotspot) {
                        $form['r']['radios'][$key]['AddHotspot'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/inserthotspot.png', '#attributes' => array('title' => t('Add a Hotspot for guests')), '#submit' => array('guifi_radio_add_hotspot_submit'), '#prefix' => '&nbsp;', '#suffix' => '&nbsp;', '#weight' => $bw++);
                    }
                    $prefix = "&nbsp;";
                }
                // Only allow delete and move functions if the radio has been saved
                if ($radio['new'] == FALSE) {
                    $form['r']['radios'][$key]['delete'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/drop.png', '#parents' => array('radios', $key, 'delete'), '#attributes' => array('title' => t('Delete radio')), '#submit' => array('guifi_radio_delete_submit'), '#prefix' => $prefix, '#suffix' => '&nbsp;', '#weight' => $bw++);
                    // TODO: Fix ticket about moving radios
                    $form['r']['radios'][$key]['change'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/move.png', '#parents' => array('radios', $key, 'move'), '#attributes' => array('title' => t('Move radio to another device')), '#ahah' => array('path' => 'guifi/js/move-device/' . $key, 'wrapper' => 'move-device-' . $key, 'method' => 'replace', 'effect' => 'fade'), '#prefix' => '&nbsp;', '#suffix' => '&nbsp;', '#weight' => $bw++);
                }
                // if not first, allow to move up
                if ($rc) {
                    $form['r']['radios'][$key]['up'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/up.png', '#attributes' => array('title' => t('Move radio up')), '#submit' => array('guifi_radio_swap_submit'), '#parents' => array('radios', $key, 'up'), '#prefix' => '&nbsp;', '#suffix' => '&nbsp;', '#weight' => $bw++);
                }
                // if not last, allow to move down
                if ($rc + 1 < count($edit['radios'])) {
                    $form['r']['radios'][$key]['down'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/down.png', '#attributes' => array('title' => t('Move radio down')), '#submit' => array('guifi_radio_swap_submit'), '#parents' => array('radios', $key, 'down'), '#prefix' => '&nbsp;', '#suffix' => '&nbsp;', '#weight' => $bw++);
                }
                $form['r']['radios'][$key]['to_did'] = array('#type' => 'hidden', '#value' => $radio['id'], '#prefix' => '<div id="move-device-' . $key . '"', '#suffix' => '</div></td></tr></table>', '#weight' => $bw++);
                $rc++;
            }
            // radio not deleted
        }
    }
    // foreach radio
    // Add radio?
    if ($rc) {
        $dradios = db_fetch_object(db_query('SELECT radiodev_max max ' . 'FROM {guifi_model_specs} ' . 'WHERE mid=%s', $edit['variable']['model_id']));
        if ($rc < $dradios->max) {
            $form['r']['addRadio'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/addwifi.png', '#parents' => array('addRadio'), '#attributes' => array('title' => t('Add wireless radio to this device')), '#ahah' => array('path' => 'guifi/js/add-radio', 'wrapper' => 'add-radio', 'method' => 'replace', 'effect' => 'fade'), '#prefix' => '<div id="add-radio">', '#suffix' => '</div>');
        }
    } else {
        $form['r']['newRadio'] = guifi_radio_add_radio_form($edit);
    }
    return $form;
}
Example #2
0
/**
 * Add wireless radio
 *
 * URL: http://guifi.net/guifi/js/add-radio
 */
function guifi_ahah_add_radio()
{
    $cid = 'form_' . $_POST['form_build_id'];
    $cache = cache_get($cid, 'cache_form');
    if ($cache) {
        $form = $cache->data;
        $form['r']['newRadio'] = guifi_radio_add_radio_form($_POST);
        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']['newRadio']);
        drupal_json(array('status' => TRUE, 'data' => $output));
    } else {
        drupal_json(array('status' => FALSE, 'data' => ''));
    }
    exit;
}