You are here

function _webform_render_date in Webform 5

Same name and namespace in other branches
  1. 5.2 components/date.inc \_webform_render_date()
  2. 6.3 components/date.inc \_webform_render_date()
  3. 6.2 components/date.inc \_webform_render_date()
  4. 7.4 components/date.inc \_webform_render_date()
  5. 7.3 components/date.inc \_webform_render_date()

Build a form item array containing all the properties of this component.

Parameters

$component: An array of information describing the component, directly correlating to the webform_component database schema.

Return value

An array of a form item to be displayed on the client-side webform.

1 call to _webform_render_date()
_webform_submission_display_date in components/date.inc
Display the result of a textfield submission. The output of this function will be displayed under the "results" tab then "submissions".

File

components/date.inc, line 50

Code

function _webform_render_date($component) {
  if (strlen($component['value']) > 0) {

    // Calculate the timestamp in GMT.
    $timestamp = strtotime(_webform_filtervalues($component['value']));
    if ($component['extra']['timezone'] == "user") {

      // Use the users timezone.
      global $user;
      $timestamp += (int) $user->timezone;
    }
    elseif ($component['extra']['timezone'] == "gmt") {

      // Use GMT.
      $timestamp += 0;
    }
    else {

      // Use the Drupal site time.
      $timestamp += variable_get('date_default_timezone', 0);
    }

    // Check for daylight savings time.
    if ($component['extra']['check_daylight_savings'] && date("I")) {
      $timestamp += 3600;
    }
    $year = gmdate('Y', $timestamp);
    $month = gmdate('n', $timestamp);
    $day = gmdate('j', $timestamp);
  }
  $months = array(
    "" => t("month"),
    1 => t('January'),
    t('February'),
    t('March'),
    t('April'),
    t('May'),
    t('June'),
    t('July'),
    t('August'),
    t('September'),
    t('October'),
    t('November'),
    t('December'),
  );
  $days = array(
    "" => t("day"),
  );
  for ($i = 1; $i <= 31; $i++) {
    $days[$i] = $i;
  }
  $form_item = array(
    '#title' => $component['name'],
    '#weight' => $component['weight'],
    '#theme' => 'webform_date',
    '#description' => _webform_filtervalues($component['extra']['description']),
    '#prefix' => '<div class="webform-component-' . $component['type'] . '" id="webform-component-' . $component['form_key'] . '">',
    '#suffix' => '</div>',
    '#required' => $component['mandatory'],
  );
  $form_item['month'] = array(
    '#type' => 'select',
    '#default_value' => $month,
    '#options' => $months,
    '#validate' => array(
      'webform_validate_date' => array(
        'month',
        $component['name'],
        $component['form_key'],
        $component['cid'],
        $component['mandatory'],
      ),
    ),
  );
  $form_item['day'] = array(
    '#type' => 'select',
    '#default_value' => $day,
    '#options' => $days,
    '#validate' => array(
      'webform_validate_date' => array(
        'day',
        $component['name'],
        $component['form_key'],
        $component['cid'],
        $component['mandatory'],
      ),
    ),
  );
  $form_item['year'] = array(
    '#type' => 'textfield',
    '#default_value' => $year,
    '#maxlength' => 4,
    '#size' => 4,
    '#validate' => array(
      'webform_validate_date' => array(
        'year',
        $component['name'],
        $component['form_key'],
        $component['cid'],
        $component['mandatory'],
      ),
    ),
  );
  return $form_item;
}