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' => ' ', '#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' => ' ', '#suffix' => ' ', '#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' => ' ', '#suffix' => ' ', '#weight' => $bw++); } $prefix = " "; } // 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' => ' ', '#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' => ' ', '#suffix' => ' ', '#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' => ' ', '#suffix' => ' ', '#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' => ' ', '#suffix' => ' ', '#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; }
/** * Select firmware by model * * URL: http://guifi.net/guifi/js/firmware_by_model */ function guifi_ahah_select_firmware_by_model() { $cid = 'form_' . $_POST['form_build_id']; // $bid = $_POST['book']['bid']; $cache = cache_get($cid, 'cache_form'); $mid = $_POST['variable']['model_id']; if ($cache) { $form = $cache->data; // Validate the firmware. if (isset($form['radio_settings']['variable']['model_id'])) { $form['radio_settings']['variable']['firmware_id'] = guifi_radio_firmware_field($_POST['variable']['firmware_id'], $mid); 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['radio_settings']['variable']['firmware_id']); drupal_json(array('status' => TRUE, 'data' => $output)); } else { drupal_json(array('status' => FALSE, 'data' => '')); } } else { drupal_json(array('status' => FALSE, 'data' => '')); } exit; }