コード例 #1
0
function guifi_domain_create_form($form_state, $node)
{
    $ip = guifi_main_ip($node->device_id);
    if (guifi_domain_access('create', $node->sid)) {
        $form['text_add'] = array('#type' => 'item', '#value' => t('You are not allowed to create a domain on this service.'), '#weight' => 0);
        return $form;
    }
    if (empty($ip['ipv4'])) {
        $device = db_fetch_object(db_query('SELECT nick FROM {guifi_devices} WHERE id = %d', $node->device_id));
        $url = url('guifi/device/' . $node->device_id);
        $form['text'] = array('#type' => 'item', '#value' => t('The server <a href=' . $url . '>' . $device->nick . '</a> does not have an IPv4 address, can not create a domain.'));
        return $form;
    }
    $form['domain_type'] = array('#type' => 'select', '#title' => t('Select new domain type'), '#default_value' => 'none', '#options' => array('NULL' => 'none', 'master' => 'Master, ex: newdomain.net', 'delegation' => 'Delegation, ex: newdomain.guifi.net'), '#ahah' => array('path' => 'guifi/js/add-domain', 'wrapper' => 'select_type', 'effect' => 'fade'));
    $form['domain_type_form'] = array('#prefix' => '<div id="select_type">', '#suffix' => '</div>', '#type' => 'fieldset');
    if ($form_state['values']['domain_type'] == 'master') {
        $form['domain_type_form']['sid'] = array('#type' => 'hidden', '#value' => $node->id);
        $form['domain_type_form']['name'] = array('#type' => 'textfield', '#size' => 64, '#maxlength' => 32, '#title' => t('Add a new domain'), '#description' => t('Insert domain name'), '#prefix' => '<table style="width: 0px"><tr><td>', '#suffix' => '</td>');
        $form['domain_type_form']['type'] = array('#type' => 'hidden', '#value' => 'master');
        $form['domain_type_form']['ipv4'] = array('#type' => 'hidden', '#value' => $ip[ipv4]);
        $form['domain_type_form']['scope'] = array('#type' => 'select', '#title' => t('Scope'), '#options' => array('internal' => 'internal', 'external' => 'external'), '#prefix' => '<td>', '#suffix' => '</td>');
        $form['domain_type_form']['management'] = array('#type' => 'select', '#title' => t('Management'), '#options' => array('automatic' => 'automatic', 'manual' => 'manual'), '#prefix' => '<td>', '#suffix' => '</td>');
        $form['domain_type_form']['mname'] = array('#type' => 'hidden', '#value' => '0');
        $form['domain_type_form']['submit'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/add.png', '#attributes' => array('title' => t('add')), '#executes_submit_callback' => TRUE, '#submit' => array(guifi_domain_create_form_submit), '#prefix' => '<td>', '#suffix' => '</td></tr></table>');
    }
    if ($form_state['values']['domain_type'] == 'delegation') {
        $ip = guifi_main_ip($node->device_id);
        $form['domain_type_form']['sid'] = array('#type' => 'hidden', '#value' => $node->id);
        $form['domain_type_form']['name'] = array('#type' => 'textfield', '#title' => t('Add a new delegated Domain Name'), '#description' => t('Just the hostname (HOSTNAME.domain.com) will be added before master domain.'), '#prefix' => '<table style="width: 0px"><tr><td>', '#suffix' => '</td>');
        $domqry = db_query("\n      SELECT *\n      FROM {guifi_dns_domains}\n      WHERE type = 'master'\n      AND public = 'yes'\n      ORDER BY name");
        $values = array();
        while ($type = db_fetch_object($domqry)) {
            $values[$type->name] = $type->name;
        }
        $form['domain_type_form']['mname'] = array('#type' => 'select', '#options' => $values, '#prefix' => '<td>', '#suffix' => '</td>');
        $form['domain_type_form']['scope'] = array('#type' => 'select', '#title' => t('Scope'), '#options' => array('internal' => 'internal', 'external' => 'external'), '#prefix' => '<td>', '#suffix' => '</td>');
        $form['domain_type_form']['management'] = array('#type' => 'select', '#title' => t('Management'), '#options' => array('automatic' => 'automatic', 'manual' => 'manual'), '#prefix' => '<td>', '#suffix' => '</td>');
        $form['domain_type_form']['type'] = array('#type' => 'hidden', '#value' => 'delegation');
        $form['domain_type_form']['ipv4'] = array('#type' => 'hidden', '#value' => $ip[ipv4]);
        $form['domain_type_form']['submit'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/add.png', '#attributes' => array('title' => t('add')), '#executes_submit_callback' => TRUE, '#submit' => array(guifi_domain_create_form_submit), '#prefix' => '<td>', '#suffix' => '</td></tr></table>');
    }
    return $form;
}
コード例 #2
0
/**
 * outputs the node information
**/
function guifi_service_view($node, $teaser = FALSE, $page = FALSE, $block = FALSE)
{
    node_prepare($node);
    if ($teaser) {
        return $node;
    }
    if ($block) {
        return $node;
    }
    if ($page) {
        drupal_set_breadcrumb(guifi_zone_ariadna($node->zone_id, 'node/%d/view/services'));
        $node->content['body']['#value'] = theme('box', t('Description'), $node->content['body']['#value']);
        $node->content['body']['#weight'] = 1;
        $service_data = array('#value' => theme('box', t('service information'), theme_guifi_service_data($node, FALSE)), '#weight' => -0);
        if ($node->service_type == 'DNS') {
            $form = drupal_get_form('guifi_domain_create_form', $node);
            $id = $node->id;
            $rows = array();
            $header = array('<h2>' . t('Domain') . '</h2>', array('data' => t('type'), 'style' => 'text-align: left;'), array('data' => t('Scope')));
            $query = db_query("SELECT d.id FROM {guifi_dns_domains} d WHERE sid=%d", $id);
            while ($d = db_fetch_object($query)) {
                $domain = guifi_domain_load($d->id);
                if (guifi_domain_access('update', $domain['id'])) {
                    $edit_domain = l(guifi_img_icon('edit.png'), 'guifi/domain/' . $domain['id'] . '/edit', array('html' => TRUE, 'title' => t('edit domain'), 'attributes' => array('target' => '_blank'))) . '</td><td>' . l(guifi_img_icon('drop.png'), 'guifi/domain/' . $domain['id'] . '/delete', array('html' => TRUE, 'title' => t('delete domain'), 'attributes' => array('target' => '_blank')));
                }
                $rows[] = array('<a href="' . url('guifi/domain/' . $domain[id]) . '">' . $domain['name'] . '</a>', array('data' => $domain['type'], 'style' => 'text-align: left;'), array('data' => $domain['scope']), $edit_domain);
            }
            if (count($rows)) {
                $node->content['data'] = array($service_data, array('#value' => theme('table', $header, $rows) . $form, '#weight' => 1));
            } else {
                $node->content['data'] = array(array('#value' => theme('box', t('service information'), theme_guifi_service_data($node, FALSE)) . $form, '#weight' => -0));
            }
        } else {
            $node->content['data'] = array(array('#value' => theme('box', t('service information'), theme_guifi_service_data($node, FALSE)) . $form, '#weight' => -0));
        }
    }
    return $node;
}