Index: handlers.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/handlers.inc,v
retrieving revision 1.63
diff -u -r1.63 handlers.inc
--- handlers.inc	31 Mar 2008 19:49:56 -0000	1.63
+++ handlers.inc	2 Apr 2008 14:07:52 -0000
@@ -2201,7 +2201,7 @@
   function admin_summary() {
     $output = check_plain($this->operator) . ' ';
     if (in_array($this->operator, $this->operator_values(2))) {
-      $output .= t('@min and @max', array('@min' => $this->value['min'], '@max' => $this->value['max']));
+      $output .= t('@min <br />and @max', array('@min' => $this->value['min'], '@max' => $this->value['max']));
     }
     else {
       $output .= check_plain($this->value['value']);
@@ -2211,74 +2211,127 @@
 }
 
 class views_handler_filter_date extends views_handler_filter_numeric {
-  function options(&$options) {
-    parent::options($options);
-    $options['value']['type'] = 'date';
+  function date_parts($limit = array()) {
+    $parts =  array(
+      'year' => t('Year'), 'month' => t('Month'), 'day' => t('Day'),
+      'hour' => t('Hour'), 'minute' => t('Minute'), 'second' => t('Second'),
+      'offset' => t('Offset'),
+      );
+    if (!empty($limit)) {
+      foreach ($parts as $key => $part) {
+        if (!in_array($key, $limit)) {
+          unset($parts[$key]);
+        }
+      }
+    }
+    return $parts;
   }
 
-  /**
-   * Add a type selector to the value form
-   */
-  function value_form(&$form, &$form_state) {
-    $form['value']['type'] = array(
-      '#type' => 'radios',
-      '#title' => t('Value type'),
-      '#options' => array(
-        'date' => t('A date in any machine readable format. CCYY-MM-DD HH:MM:SS is preferred.'),
-        'offset' => t('An offset from the current time such as "+1 day" or "-2 hours and 30 minutes"'),
-      ),
-      '#default_value' => $this->value['type'],
-    );
-    parent::value_form($form, $form_state);
+  function date_factory($source, $which, $value, $operator_value) {
+    $parts = array('year', 'month', 'day', 'hour', 'minute', 'offset');
+    foreach ($this->date_parts($parts) as $key => $name) {
+      $form[$key] = array(
+        '#title' => $name,
+        '#type' => 'textfield',
+        '#size' => $key != 'offset' ? 6 : 20,
+        '#default_value' => isset($value[$key]) ? $value[$key] : '',
+        '#prefix' => '<div style="float:left;margin-right:-20px;padding:0">',
+        '#suffix' => '</div>',
+      );
+      if ($which == 'all') {
+        $dependency = array(
+          '#process' => array('views_process_dependency'),
+          '#dependency' => array($source => $this->operator_values($operator_value)),
+        );
+        $form[$key] += $dependency;
+      }
+    }
+    $form['#prefix'] = '<div class="views-left-75">';
+    $form['#suffix'] = '</div>';
+    return $form;
   }
 
-  function options_validate(&$form, &$form_state) {
-    parent::options_validate($form, $form_state);
-    $operators = $this->operators();
-    if ($operators[$form_state['values']['options']['operator']]['values'] == 1) {
-      $convert = strtotime($form_state['values']['options']['value']['value']);
-      if ($convert == -1 || $convert === FALSE) {
-        form_error($form['value']['value'], t('Invalid date format.'));
+  function admin_summary() {
+    $labels = $this->date_parts();
+    $output = check_plain($this->operator) . ' ';
+    if (in_array($this->operator, $this->operator_values(2))) {
+      $min = array();
+      $max = array();
+      foreach ($this->value['min'] as $key => $value) {
+        if (!empty($value)) {
+          $min[] = $labels[$key] .'='. $value;
+        }
       }
+      foreach ($this->value['max'] as $key => $value) {
+        if (!empty($value)) {
+          $max[] = $labels[$key] .'='. $value;
+        }
+      }
+      $min = implode(', ', $min);
+      $max = implode(', ', $max);
+      $output .= t('@min and @max', array('@min' => $min, '@max' => $max));
     }
     else {
-      $min = strtotime($form_state['values']['options']['value']['min']);
-      if ($min == -1 || $min === FALSE) {
-        form_error($form['value']['min'], t('Invalid date format.'));
-      }
-      $max = strtotime($form_state['values']['options']['value']['max']);
-      if ($max == -1 || $max === FALSE) {
-        form_error($form['value']['max'], t('Invalid date format.'));
+      $values = array();
+      foreach ($this->value['value'] as $key => $value) {
+        if (!empty($value)) {
+          $values[] = $labels[$key] .'='. $value;
+        }
       }
+      $values = implode(', ', $values);
+      $output .= check_plain($values);
     }
+    return $output;
   }
 
-  function op_between($field) {
-    if ($this->operator == 'between') {
-      $a = strtotime($this->value['min'], 0);
-      $b = strtotime($this->value['max'], 0);
+  /**
+   * Add a type selector to the value form
+   */
+  function value_form(&$form, &$form_state) {
+    parent::value_form($form, $form_state);
+
+    $form['value']['#tree'] = TRUE;
+
+    // We have to make some choices when creating this as an exposed
+    // filter form. For example, if the operator is locked and thus
+    // not rendered, we can't render dependencies; instead we only
+    // render the form items we need.
+    $which = 'all';
+    if (!empty($form['operator'])) {
+      $source = ($form['operator']['#type'] == 'radios') ? 'radio:options[operator]' : 'edit-options-operator';
     }
-    else {
-      $a = strtotime($this->value['max'], 0);
-      $b = strtotime($this->value['min'], 0);
+
+    if (!empty($form_state['exposed'])) {
+      if (empty($this->options['expose']['operator'])) {
+        // exposed and locked.
+        $which = in_array($this->operator, $this->operator_values(2)) ? 'minmax' : 'value';
+      }
+      else {
+        $source = 'edit-' . form_clean_id($this->options['expose']['operator']);
+      }
     }
+    if ($which == 'all' || in_array($which, array_keys($this->date_parts()))) {
+      $form['value']['value'] = $this->date_factory($source, $which, $this->value['value'], 1);
+    }
+    $form['value']['min'] = $this->date_factory($source, $which, $this->value['min'], 2);
+    $form['value']['max'] = $this->date_factory($source, $which, $this->value['max'], 2);
+    $form['value']['description'] = array(
+      '#prefix' => '<div class="views-left-75"><div class="form-item"><div class="description">',
+      '#suffix' => '</div></div></div>',
+      '#value' => t('Blank values do no filtering, \'now\' filters for the current value, \'Offset\' adds a adjustment like \'+1 day\' to the input value. For instance, setting the Year to 2008 and the month to 4 and leaving everything else blank will filter for all dates in April 2008; setting the month to \'now\' and leaving everything else blank will filter for the current month in all years.'));
+  }
 
-    if ($this->value['type'] == 'offset') {
-      $a = '***CURRENT_TIME***' . sprintf('%+d', $a); // keep sign
-      $b = '***CURRENT_TIME***' . sprintf('%+d', $b); // keep sign
-    }
-    // %s is safe here because strtotime scrubbed the input and we might
-    // have a string if using offset.
-    $this->query->add_where($this->options['group'], "$field >= %s", $a);
-    $this->query->add_where($this->options['group'], "$field <= %s", $b);
+  function options_validate(&$form, &$form_state) {
+    //parent::options_validate($form, $form_state);
+    // TODO
+  }
+
+  function op_between($field) {
+    // TODO
   }
 
   function op_simple($field) {
-    $value = strtotime($this->value['value'], 0);
-    if ($this->value['type'] == 'offset') {
-      $value = '***CURRENT_TIME***' . sprintf('%+d', $value); // keep sign
-    }
-    $this->query->add_where($this->options['group'], "$field $this->operator %s", $value);
+    // TODO
   }
 }
 
