Index: webform_report.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform_report/Attic/webform_report.inc,v
retrieving revision 1.1.2.27.2.10
diff -u -r1.1.2.27.2.10 webform_report.inc
--- webform_report.inc	9 Nov 2010 21:10:01 -0000	1.1.2.27.2.10
+++ webform_report.inc	12 Nov 2010 19:56:49 -0000
@@ -114,7 +114,41 @@
       }
     }
   }
-  
+
+  // check for search values - add filters for search
+  $search =  $_SESSION['search_form'][$node->nid];
+  if (is_array($search)) {
+    $col = $search['column'];
+    $val = $search['value'];
+    if ($val != '') {
+      $columns = _webform_report_get_columns($node, $components);
+      // if all columns, add search filter for each column
+      if ($col == -1) {
+        foreach($columns as $index => $column) {
+          // exclude special links (view, edit, etc)
+          if ($column['cid'] > -5) {
+            $filters[] = array(
+              'type' => $column['type'],
+              'ftype' => -1,
+              'value' => $val,
+              'cid' => $column['cid']
+            );
+          }
+        }
+      }
+      // add search filter for specified column
+      else {
+        if (array_key_exists($col, $columns)) {
+          $filters[] = array(
+            'type' => $columns[$col]['type'],
+            'ftype' => -1,
+            'value' => $val,
+            'cid' => $columns[$col]['cid']
+          );
+        }
+      }
+    }
+  }
   return $filters;
 }
 
@@ -187,7 +221,7 @@
  * @return 
  *   a string of text or a themed table
  */
-function _webform_report_get_body_content($node, $formatcsv = FALSE) {
+function _webform_report_get_body_content($node, $teaser=FALSE, $page=FALSE, $formatcsv = FALSE) {
 
   $output = '';
   
@@ -196,7 +230,12 @@
 
   // if any submissions
   if (!empty($rs)) {
-  
+
+    // display search form if desired
+    if ($node->options['search_form'] && $page) {
+      $output .= drupal_get_form('webform_report_search_form', $node);
+    }
+    
     // get report criteria
     $components = _webform_report_get_components($node->wnid);
     $columns = _webform_report_get_columns($node, $components);
@@ -260,7 +299,7 @@
           if ($csid != 0) {
           
             // test submission against filters
-            if (_webform_report_test_filters($data, $filters)) {
+            if (_webform_report_test_filters($data, $filters, $columns)) {
               // output row if filters pass
               $rows[] = _webform_report_output($data, $columns);
             }
@@ -328,7 +367,7 @@
       }
       // no submissions met criteria
       else {
-        $output = t('There are no submissions that match the criteria for the selected webform.');
+        $output .= t('There are no submissions that match the criteria for the selected webform.');
       }
       
     }   // end - if (count($columns) > 0)...
@@ -362,7 +401,7 @@
  * @return 
  *   TRUE if filters passed, otherwise FALSE
  */
-function _webform_report_test_filters($data, $filters) {
+function _webform_report_test_filters($data, $filters, $columns) {
 
   // filter result, return true if no filters
   $ok = TRUE;
@@ -370,20 +409,28 @@
   // if any filters
   if (count($filters) > 0) {
   
+    // search flag
+    $hit = FALSE;
+    
     // loop through all filters  
     foreach($filters as $index => $filter) {
 
+      // reset result for each filter  
+      $ok = FALSE;
+        
       // check that cid is in data
       if (array_key_exists($filter['cid'], $data)) {
     
-        // reset result for each filter  
-        $ok = FALSE;
-        
         // get raw data
         $raw = $data[$filter['cid']];
         
         // format value
-        $value = _webform_report_format_data($raw, $filter['cid'], $filter['type']);
+        foreach ($columns as $col) {
+          if ($col['cid'] == $filter['cid']) {
+            break;
+          }
+        }
+        $value = _webform_report_format_data($raw, $col);
         
         // prepare filter values
         $filter_data = strip_tags(strtolower(trim($value['data'])));
@@ -422,9 +469,45 @@
           $filter_value = strtotime($filter_value);
         }
         
+        // extract filename for file types
+        if ($filter['type'] == 'file') {
+          $filter_data = '';
+          // new file handling in webforms 6.x-3.x - data is an id
+          if (is_numeric($raw[0])) {
+            // must load the webform file component handler
+            module_load_include('inc', 'webform', 'components/file');
+            $file = webform_get_file($raw[0]);
+            if (!empty($file->fid)) {
+              $filter_data = webform_file_name($file->filepath);
+            }
+          }
+          // file handling for prior versions of webforms - data is serialized fileinfo
+          else {
+            $tmp = unserialize($raw[0]);
+            if (!empty($tmp['filename'])) {
+              $filter_data = $tmp['filename'];
+            }
+          }
+        }
+        
         // apply filter
         switch($filter['ftype']) {
     
+          // search for x
+          case -1:
+            // convert submission date and time to strings
+            if ($filter['cid'] == -2) {
+              $filter_data = date('m/d/Y', $raw[0]);
+            }
+            if ($filter['cid'] == -3) {
+              $filter_data = date('H:m', $raw[0]);
+            }
+            if ($filter_data != '' && strpos($filter_data, $filter_value) !== FALSE) {
+              $hit = TRUE;
+              $ok = TRUE;
+            }
+            break;
+            
           // none
           case 0:
             $ok = TRUE;
@@ -516,6 +599,17 @@
           
         }   // end - if (array_key_exists($filter['cid'], $data)...
         
+        // if hit on search, quit - search filters are last,
+        // so any report filters have already been applied
+        if ($hit) {
+          break;
+        }
+        
+        // if last filter was search, keep going
+        if ($filter['ftype'] == -1) {
+          continue;
+        }
+        
         // if filter did not pass, don't check any further
         if (!$ok) {
           break;
@@ -971,7 +1065,7 @@
  */
 function webform_report_csv($node) {
 
-  $output = _webform_report_get_body_content($node, TRUE);
+  $output = _webform_report_get_body_content($node, FALSE, FALSE, TRUE);
       
   $fname = 'wfr_export.csv';
   header('Content-Type: text/plain');
@@ -1045,3 +1139,4 @@
   }
   return $value;
 }
+
Index: webform_report.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform_report/webform_report.module,v
retrieving revision 1.2.2.55.2.43.2.3
diff -u -r1.2.2.55.2.43.2.3 webform_report.module
--- webform_report.module	9 Nov 2010 21:06:58 -0000	1.2.2.55.2.43.2.3
+++ webform_report.module	12 Nov 2010 19:51:14 -0000
@@ -218,8 +218,10 @@
     drupal_goto('node/' . $node->nid . '/add/webform_report/criteria');
   }
   module_load_include('inc', 'webform_report', 'webform_report');
-
-  $output = _webform_report_get_body_content($node);
+  // include search form
+  module_load_include('inc', 'webform_report', 'webform_report_criteria');
+  
+  $output = _webform_report_get_body_content($node, $teaser, $page);
   
   $node->content['body'] = array('#value' => check_markup($node->body, $node->format, FALSE));
   $node->content['webform_report'] = array('#value' => $output, '#weight' => 10);
Index: webform_report_criteria.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform_report/Attic/webform_report_criteria.inc,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 webform_report_criteria.inc
--- webform_report_criteria.inc	9 Nov 2010 21:06:58 -0000	1.1.2.3
+++ webform_report_criteria.inc	12 Nov 2010 19:56:11 -0000
@@ -307,6 +307,16 @@
       '#default_value' => $default,
     );
     
+    $default = FALSE;  
+    if (array_key_exists('search_form', $node->options)) {
+      $default = $node->options['search_form'];
+    }
+    $form['options']['search_form'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Display Search Form'),
+      '#default_value' => $default,
+    );
+    
     $form['update'] = array(
       '#type' => 'submit',
       '#value' => t('Update'),
@@ -760,9 +770,132 @@
   // update options
   $node->options['results_per_page'] = $form_state['values']['results_per_page'];
   $node->options['hide_csv'] = $form_state['values']['hide_csv'];
+  $node->options['search_form'] = $form_state['values']['search_form'];
 
   // update the node  
   node_save($node);
 
   drupal_set_message(t('Webform Report has been updated.'));
-}
\ No newline at end of file
+}
+
+/**
+ * Generate a form for searching report data
+ *
+ * @param form_state
+ *   drupal form state
+ * *param node
+ *   current node object
+ * @return 
+ *   an array of form elements
+ */
+ function webform_report_search_form($form_state, $node) {
+  
+  $form = array();
+  
+  if (isset($node->wnid)) {  
+  
+    $webform_components = _webform_report_get_components($node->wnid);
+
+    $columns = _webform_report_get_columns($node, $webform_components);
+
+    $comp_options = array();
+    $comp_options[-1] = t('Search All Columns');
+    foreach($columns as $index => $comp) {
+      // don't include links in options
+      if ($index > -5) {
+        $comp_options[$index] = $comp['name'];
+      }
+    }
+  
+    // filters fieldset  
+    $form['search'] = array(
+      '#type' => 'fieldset', 
+      '#title' => t('Search Report'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#tree' => TRUE
+    );
+    
+    $form['search']['nid'] = array(
+      '#type' => 'hidden',
+      '#value' => $node->nid
+    );
+  
+    // get current session search values
+    $search = $_SESSION['search_form'][$node->nid];
+    
+    $default = '';
+    if (is_array($search)) {
+      if (array_key_exists('column', $search)) {
+        $default = $search['column'];
+      }
+    }
+    $form['search']['column'] = array(
+      '#type' => 'select',
+      '#title' => t('Column to search'),
+      '#options' => $comp_options,
+      '#default_value' => $default,
+      '#required' => FALSE
+    );
+  
+    $default = '';
+    if (is_array($search)) {
+      if (array_key_exists('value', $search)) {
+        $default = $search['value'];
+      }
+    }
+    $form['search']['value'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Value to search for'),
+      '#default_value' => $default,
+      '#required' => FALSE
+    );
+
+    $form['search']['search'] = array(
+      '#type' => 'submit',
+      '#value' => t('Search'),
+      '#weight' => 1
+    );
+  
+    $form['search']['reset'] = array(
+      '#type' => 'submit',
+      '#value' => t('Reset'),
+      '#weight' => 2
+    );
+    
+  }   // end -   if (isset($node->wnid))...
+  
+  return $form;
+}
+
+/**
+ * Implementation of hook_submit for the report search form
+ *
+ * @param form_id
+ *   drupal form id
+ * @param form_state
+ *   drupal form state and values
+ */
+function webform_report_search_form_submit($form_id, $form_state) {
+
+  // get current node id
+  $nid = $form_state['values']['search']['nid'];
+  
+  // refresh
+  if ($form_state['values']['op'] == 'Search') {
+  
+    // save search values in session variable
+    // include node id so values will not be 
+    // used in other nodes
+    $_SESSION['search_form'][$nid] = array(
+      'column' => $form_state['values']['search']['column'],
+      'value' => $form_state['values']['search']['value']
+    );
+  }
+  
+  // reset
+  else {
+    unset($_SESSION['search_form'][$nid]);
+  }
+  
+}

