function guifi_interfaces_add_cable_public_link_submit(&$form, &$form_state) { $values = $form_state['clicked_button']['#parents']; $iid = $values[1]; $ipv4_id = $values[3]; $to_did = $form_state['values']['interfaces'][$iid]['ipv4'][$ipv4_id]['to_did']; $rdevice = guifi_device_load($to_did); guifi_log(GUIFILOG_TRACE, sprintf('function guifi_interfaces_add_cable_public_link_submit(%d)', $iid), $form_state['clicked_button']['#parents']); $ips_allocated = guifi_ipcalc_get_ips('0.0.0.0', '0.0.0.0', $form_state['values'], 1); // get next available ip address $base_ip = $form_state['values']['interfaces'][$iid]['ipv4'][$ipv4_id]; $item = _ipcalc($base_ip['ipv4'], $base_ip['netmask']); $ip = guifi_ipcalc_find_ip($item['netid'], $base_ip['netmask'], $ips_allocated); // no IP was given, so raise a message and don't create the link' if (empty($ip)) { drupal_set_message(t('Unable to assign a free ip, link not created, ' . 'contact the administrator.')); return; } $newlk['new'] = TRUE; $newlk['interface'] = array(); $newlk['link_type'] = 'cable'; $newlk['flag'] = 'Planned'; $newlk['nid'] = $form_state['values']['nid']; $newlk['device_id'] = $to_did; if ($rdevice['type'] == 'radio') { $newlk['routing'] = 'BGP'; } else { $newlk['routing'] = 'Gateway'; } $newlk['interface']['new'] = TRUE; $newlk['interface']['device_id'] = $to_did; $free = guifi_get_free_interfaces($to_did, $rdevice); $newlk['interface']['interface_type'] = array_shift($free); $newlk['interface']['ipv4']['new'] = TRUE; $newlk['interface']['ipv4']['ipv4_type'] = 1; $newlk['interface']['ipv4']['ipv4'] = $ip; $newlk['interface']['ipv4']['netmask'] = $base_ip['netmask']; $form_state['values']['interfaces'][$iid]['ipv4'][$ipv4_id]['links'][] = $newlk; $form_state['values']['interfaces'][$iid]['unfold'] = TRUE; // print_r($form_state['values']); $form_state['rebuild'] = TRUE; return TRUE; }
/** * Add interface * * URL: http://guifi.net/guifi/js/add-interface */ function guifi_ahah_add_interface() { $interfaces = $_POST['interfaces']; // Build our new form element. $free = guifi_get_free_interfaces($_POST['id'], $_POST); $newI['interface_type'] = array_shift($free); $newI['new'] = TRUE; $newI['unfold'] = TRUE; $interfaces[] = $newI; end($interfaces); $delta = key($interfaces); $newI['interface_id'] = $delta; // guifi_log(GUIFILOG_TRACE,sprintf('add_interface %d',$delta),$newI); $form_element = guifi_interfaces_form($newI, array('interfaces', $delta)); // drupal_alter('form', $form_element, array(), 'guifi_ahah_add_interface'); // 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['if']['interfaces']['ifs']; $form['if']['interfaces']['ifs'][$newI['interface_type']][$delta] = $form_element; 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['if']['interfaces']['ifs']; unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers. unset($choice_form[$newI['interface_type']][$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; }