Пример #1
0
function guifi_node_form(&$node, $form_state)
{
    global $user;
    $form_weight = 0;
    $type = node_get_types('type', $node);
    if (!empty($node->zone_id)) {
        drupal_set_breadcrumb(guifi_node_ariadna($node));
    } else {
        drupal_set_breadcrumb(NULL);
    }
    // ----
    // El títol el primer de tot
    // ------------------------------------------------
    if ($type->has_title) {
        $form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title);
    }
    $form_weight = 2;
    /*
     * maintainers fieldset
     */
    $form_weight = -3;
    $form['maintainers'] = guifi_maintainers_form($node, $form_weight);
    /*
     * funders fieldset
     */
    $form_weight = -4;
    $form['funders'] = guifi_funders_form($node, $form_weight);
    $form_weight = 0;
    $form['nick'] = array('#type' => 'textfield', '#title' => t('Nick'), '#required' => FALSE, '#size' => 20, '#maxlength' => 20, '#element_validate' => array('guifi_node_nick_validate'), '#default_value' => $node->nick, '#description' => t("Unique identifier for this node. Avoid generic names such 'MyNode', use something that really identifies your node.<br />Short name, single word with no spaces, 7-bit chars only, will be used for  hostname, reports, etc."), '#weight' => $form_weight++);
    $form['notification'] = array('#type' => 'textfield', '#title' => t('Contact'), '#required' => FALSE, '#size' => 60, '#maxlength' => 1024, '#element_validate' => array('guifi_emails_validate'), '#default_value' => $node->notification, '#description' => t("Who did possible this node or who to contact with regarding this node if it is distinct of the owner of this page. Use valid emails, if you like to have more than one, separated by commas.'"), '#weight' => $form_weight++);
    $form['settings'] = array('#type' => 'fieldset', '#title' => t('Node settings'), '#weight' => $form_weight++, '#collapsible' => TRUE, '#collapsed' => TRUE);
    // Si ets administrador pots definir el servidor de dades
    if (user_access('administer guifi zones')) {
        $graphstr = guifi_service_str($node->graph_server);
        $form['settings']['graph_serverstr'] = array('#type' => 'textfield', '#title' => t('default graphs server'), '#maxlength' => 60, '#required' => FALSE, '#default_value' => $graphstr, '#autocomplete_path' => 'guifi/js/select-service/SNPgraphs', '#element_validate' => array('guifi_service_name_validate', 'guifi_zone_service_validate'), '#description' => t('Select the <em>graph server</em> to be used at this node.<br />You can find the <em>graph server</em> by introducing part of the id number, zone name or graph server 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.'));
        $form['settings']['graph_server'] = array('#type' => 'hidden', '#value' => $node->graph_server);
    }
    $form['settings']['stable'] = array('#type' => 'select', '#title' => t("It's supposed to be a stable online node?"), '#required' => FALSE, '#default_value' => $node->stable ? $node->stable : 'Yes', '#options' => array('Yes' => t('Yes, is intended to be kept always on,  avalable for extending the mesh'), 'No' => t("I'm sorry. Will be connected just when I'm online")), '#description' => t("That helps while planning a mesh network. We should know which locations are likely available to provide stable links."), '#weight' => 1);
    // Ask for a license agreement if is a new node
    if (empty($node->nid)) {
        $form['license'] = array('#type' => 'item', '#title' => t('License and usage agreement'), '#value' => t(variable_get('guifi_license', NULL)), '#description' => t('You must accept this agreement to be authorized to create new nodes.'), '#weight' => 1);
        if (empty($node->agreement)) {
            $agreement = 'No';
        } else {
            $agreement = $node->agreement;
        }
        $form['agreement'] = array('#type' => 'radios', '#default_value' => $agreement, '#options' => array('Yes' => t('Yes, I have read this and accepted')), '#element_validate' => array('guifi_node_agreement_validate'), '#weight' => 2);
    } else {
        $form['agreement'] = array('#type' => 'hidden', '#default_value' => 'Yes');
    }
    if (empty($node->nid)) {
        if (empty($node->ndfzone)) {
            if (empty($node->zone_id)) {
                if (!empty($user->guifi_default_zone)) {
                    $zone_id = $user->guifi_default_zone;
                }
            } else {
                $zone_id = $node->zone_id;
            }
        } else {
            $zone_id = $node->ndfzone;
        }
    } else {
        $zone_id = $node->zone_id;
    }
    $form['zone_id'] = guifi_zone_autocomplete_field($zone_id, 'zone_id');
    //  $form['zone_id'] = guifi_zone_select_field($zone_id,'zone_id');
    $form['zone_id']['#weight'] = 3;
    // ----
    // position
    // ------------------------------------------------
    $form['position'] = array('#type' => 'fieldset', '#title' => t('Node position settings'), '#weight' => 4, '#collapsible' => FALSE);
    if (guifi_gmap_key()) {
        drupal_add_js(drupal_get_path('module', 'guifi') . '/js/guifi_gmap_node.js', 'module');
        $form['position']['GMAP'] = array('#type' => 'item', '#title' => t('Map'), '#description' => t('Select the point where the node has to be placed.'), '#suffix' => '<input style="width: 240px;" id="mapSearch" type="text" /><div id="map" style="width: 100%; height: 437px; margin:5px;"></div>', '#weight' => 0);
        $form['guifi_wms'] = array('#type' => 'hidden', '#value' => variable_get('guifi_wms_service', ''));
        $form['lat'] = array('#type' => 'hidden', '#value' => $node->lat);
        $form['lon'] = array('#type' => 'hidden', '#value' => $node->lon);
    }
    $form['position']['longitude'] = array('#type' => 'item', '#title' => t('Longitude'), '#prefix' => '<table><tr><th>&nbsp;</th><th>' . t('degrees (decimal values allowed)') . '</th><th>' . t('minutes') . '</th><th>' . t('seconds') . '</th></tr><tr><td>', '#suffix' => '</td>', '#weight' => 1);
    $form['position']['londeg'] = array('#type' => 'textfield', '#default_value' => $node->londeg, '#size' => 12, '#maxlength' => 24, '#element_validate' => array('guifi_lon_validate'), '#prefix' => '<td>', '#suffix' => '</td>', '#weight' => 2);
    $form['position']['lonmin'] = array('#type' => 'textfield', '#default_value' => $node->lonmin, '#size' => 12, '#maxlength' => 24, '#prefix' => '<td>', '#suffix' => '</td>', '#weight' => 3);
    $form['position']['lonseg'] = array('#type' => 'textfield', '#default_value' => $node->lonseg, '#size' => 12, '#maxlength' => 24, '#prefix' => '<td>', '#suffix' => '</td></tr>', '#weight' => 4);
    $form['position']['latitude'] = array('#type' => 'item', '#title' => t('Latitude'), '#prefix' => '<tr><td>', '#suffix' => '</td>', '#weight' => 5);
    $form['position']['latdeg'] = array('#type' => 'textfield', '#default_value' => $node->latdeg, '#size' => 12, '#maxlength' => 24, '#element_validate' => array('guifi_lat_validate'), '#prefix' => '<td>', '#suffix' => '</td>', '#weight' => 6);
    $form['position']['latmin'] = array('#type' => 'textfield', '#default_value' => $node->latmin, '#size' => 12, '#maxlength' => 24, '#prefix' => '<td>', '#suffix' => '</td>', '#weight' => 7);
    $form['position']['latseg'] = array('#type' => 'textfield', '#default_value' => $node->latseg, '#size' => 12, '#maxlength' => 24, '#prefix' => '<td>', '#suffix' => '</td></tr></table>', '#weight' => 8);
    $form['position']['zone_description'] = array('#type' => 'textfield', '#title' => t('Zone description'), '#required' => FALSE, '#size' => 60, '#maxlength' => 128, '#default_value' => $node->zone_description, '#description' => t("Zone, address, neighborhood. Something that describes your area within your location.<br />If you don't know your lat/lon, please provide street and number or crossing street."), '#weight' => 9);
    $form['position']['elevation'] = array('#type' => 'textfield', '#title' => t('Antenna elevation'), '#required' => FALSE, '#size' => 5, '#length' => 20, '#maxlength' => 20, '#default_value' => $node->elevation, '#element_validate' => array('guifi_elevation_validate'), '#description' => t("Antenna height over the floor level."), '#weight' => 10);
    if ($type->has_body) {
        $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
    }
    $radios = array();
    $query = db_query("SELECT * FROM {guifi_radios} WHERE nid=%d", $node->id);
    while ($radio = db_fetch_array($query)) {
        $radios[] = $radio;
    }
    if (count($radios) < 1) {
        $form['status_flag'] = array('#type' => 'select', '#title' => t("Node status"), '#default_value' => $node->status_flag ? $node->status_flag : 'Planned', '#required' => FALSE, '#options' => array('Reserved' => t('Reserved'), 'Inactive' => t('Inactive'), 'Planned' => t('Planned')));
    } else {
        $form['status_flag'] = array('#type' => 'hidden', '#default_value' => $node->status_flag);
    }
    return $form;
}
Пример #2
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;
}