⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webform.inc

📁 对于。Net最新的MVC开发方式提供自动对类的注入Webform
💻 INC
📖 第 1 页 / 共 3 页
字号:
    case '__userid':    case '__remotehost':    case '__useragent':      $record_array[1][$record->name] = $record->data;      break;    default:      switch($record_array[0]['components'][$index]['type']){      case 'select':        if($record_array[0]['components'][$index]['options']['multiple'] == 'Y'){          $record_array[1]['components'][$index]['data'] = unserialize($record->data);        } else {          $record_array[1]['components'][$index]['data'][0] = $record->data;        }        break;      case 'textarea':      case 'hidden':      case 'textfield':      case 'email':        //print "<br>Setting $record->data on $record->name at CIX:$index";        $record_array[1]['components'][$index]['data'][0] = $record->data;        break;      default:              }      //print "<p>Setting $index components $record->name :" . $record->data;    }  }  // Get the last one  if($current_sid > 0){    if($serial != 0){      $record_count++;      switch($mode){      case 'record':        break;      case 'submission_list':        $print_sid = "sid=".$record_array[1]['sid'];        $print_view_ref = l(t('View'),"node/$nid",NULL,$print_sid,NULL,FALSE);        $print_delete_ref = l(t('Delete'),"node/$nid/results/delete/" . $record_array[1]['sid'],NULL,NULL,NULL,FALSE);        $submission_list_array[] = array($record_count,$record_array[1]['sid'],$record_array[1]['__timestamp'],$record_array[1]['__userid'],$record_array[1]['__remotehost'],$print_view_ref,$print_delete_ref);        break;      case 'print':        print _webform_make_record_csv_string($record_array,$new_line);        break;      case 'string':        $records .= _webform_make_record_csv_string($record_array,$new_line);        break;      case 'file':      default:        $file_record = _webform_make_record_csv_string($record_array,$new_line);        @fwrite($handle,$file_record);      }    } // end if ($serial != 0)  }    //print "Main result = " . count($record_array) . " records.";  switch($mode){  case 'submission_list':    $content = theme('table', $submission_list_header, $submission_list_array);    return $content;  case 'print':    return true;  case 'string':    return $records;  case 'file':  default:    @fclose($handle);    return $file_name;  }}/** _webform_make_record_csv_string - Decomposes a single session ID to a flat structure. * @param &$record_array - A reference to the filled record array element. * @param $new_line - A string to be used to render a new line. * @return a string representing the file in csv format. **/function _webform_make_record_csv_string(&$ra,$new_line){    $output =  $ra[1]['serial'] . ",";  $output .= $ra[1]['__timestamp'] . ",";  $output .= $ra[1]['sid'] . ",";  $output .= $ra[1]['__userid'] . ",";  $output .= $ra[1]['__remotehost'];    foreach($ra[0]['index'] as $name => $index){        switch($name){    case '__remotehost':    case '__userid':    case '__timestamp':    case '__useragent':      // Ignore the common elements      break;    default:      if($ra[0]['components'][$index]['type'] == 'select'){        foreach($ra[0]['components'][$index]['options']['items'] as $choice){          if(is_array($ra[1]['components'][$index]['data'])){  // When all null, then not array?            if(in_array($choice,$ra[1]['components'][$index]['data'])){ // This was throwing a warning! [Wrong datatype for second argument]              $output .= ',YES';            } else {              $output .= ',no';            }          } else {            $output .= ',no';          }        }      } else {        $d = $ra[1]['components'][$index]['data'][0];        $output .= ",\"$d\""; // The internal slashed quotes allow the field to include commas      }    }  }    $output .= $new_line;  return $output;}/** * Pulls the information block for a given node * @param $nid - The node requested * @return - A structure containing the node info. * TODO: Remove this function in favour of the core drupal alternative **/function _webform_get_node_info($nid){  $node_search_result = db_query("SELECT nid, title FROM {node} WHERE type='webform' AND nid=%d",$nid);  $node_info = db_fetch_object($node_search_result);  return $node_info;}/** _webform_results_analysis - Provides simple analysis of a series of webform submission. * @return to stdio a themeatic HTML rendering of the page. **/function _webform_results_analysis($nid) {     // The current defaults  // TODO: Move some of these variables to the settings page.    $view_settings['analog_bar']['color'] = '#0000AA';		// The color of the analog bar.  $view_settings['analog_bar']['resolution'] = 2;				// The bar resolution in %. A bar bit will occur at every x% where x is this value.  $view_settings['analog_bar']['bar_char'] = '&nbsp;';	// The HTML character used to form the bar.  $view_settings['options']['default_identifier'] = '&nbsp;<font color=#FF0000>*</font>'; // The HTML stream used to flag a default value  $view_settings['options']['highlight_color'] = '#AA0000';  $view_settings['options']['heading_format'] = "<b>%s</b>";  $view_settings['options']['subnumbering_format'] = "&nbsp;<i><small>%s</small></i>";  $view_settings['options']['nonuser_option_format'] = "<i>%s</i>";    // Set the filters and views switches    $filters_array = array('u'=>t('Unique Users Only'),'i'=>t('Unique IPs Only'));  $views_array = array('a'=>t('Analog Bar'),'p'=>t('Percentage'),'t'=>t('Tallies'),'c'=>t('Covariance Matrix'));    //$elements = str_split($filters_and_views_switches);  Remember, Drupal does not work with php5    if($_POST['op'] == 'Set Filters & View Elements'){    $array_test = $_POST['edit'];    if(is_array($array_test)){      if(is_array($array_test['submission_view_elements'])){        $views_switches = $array_test['submission_view_elements'];      }else{        $views_switches = array();	// User has deselected everything including defaults      }      if(is_array($array_test['submission_filters'])){        $filters_switches = $array_test['submission_filters'];      }else{        $filters_switches = array();	// User has deselected everything including defaults      }    } else {      // Invalid posted element. Not an array    }  } else {    //This has not come from the "Set Filters & View Elements" button.  Set the default values    $filters_switches = array();	// No filters currently set as default.    $views_switches = array('t'); // Tallies.  }    $post_content  = form_checkboxes("Filters","submission_filters",$filters_switches,$filters_array,"Select the filters to apply to the set of submissions");  $post_content .= form_checkboxes("View Elements","submission_view_elements",$views_switches,$views_array,"Select the view elements to best highlight the results");  $post_content .= form_submit('Set Filters & View Elements');    // $content .= form($post_content, 'post');   // This statement which pastes of the HTML to $content now occurs later to allow the   // record numbers to be counted and displayed ahead of it.    // The filter mechanism uses a single pass through the database to create an indexed array of  // valid Session Ids.  This is subsequently compared against the results returned for the main query. This is an inefficient mechanism but has been chosen to allow backward capacity with  // MYSQL Versions < 4.1  // A better mechanism would use sub-SELECTs (MySQL v > 4.1) or CREATE VIEW (MySQL v > 5.0)    // Load up the valid nodes array    if(count($filters_switches)){        // The filters are going to be OR'd so we must make them return empty sets when they are off    $uniqueid_query = (in_array('u',$filters_switches)) ? "__userid" : "@@@Turn off this filter@@@"; 			// The '@@@' is to make it extrememly unlikey that this would ever be user data    $uniqueip_query = (in_array('i',$filters_switches)) ? "__remotehost" : "@@@Turn off this filter@@@";	// The '@@@' is to make it extrememly unlikey that this would ever be user data  } else {    // If there are no filters then they should return "everything".    $uniqueid_query = "%";    $uniqueip_query = "%";  }    // Perform the search to identify valid records.    // Boolean logic does not follow the associative law, hence the brackets: x AND (y OR z)  $filtered_nodes_search_result = db_query('SELECT DISTINCT max(sd.sid) AS latest_sid '.                                           'FROM {webform_submitted_data} sd '.                                           "WHERE sd.nid = %d AND (sd.name LIKE '%s' OR sd.name LIKE '%s') ".                                           'GROUP By sd.data '.                                           'ORDER BY sd.sid DESC',                                           $nid, $uniqueid_query, $uniqueip_query);    // Set them up in a keyed array so we can find them quickly.    $valid_nodes = array();  while ($field = db_fetch_object($filtered_nodes_search_result)) {    $valid_nodes[$field->latest_sid] = $field->latest_sid;   }    $valid_records = count($valid_nodes);  if(!$valid_records) $valid_records = 1; // Should never happen, however kill any divide by zeros just in case.    // Show the number of records in a friendly sentence at the top of the screen.  $content .= "<p>There are $valid_records records selected with the current filter.<p>";    $content .= form($post_content, 'post');  $content .= "<br>"; // Some themes jam the form button too close to the next element and it looks ugly.    unset($uniqueid_query,$uniqueip_query);	    // Pull the title of the form from node and make a nice heading for the page  //$node_info = _webform_get_node_info($nid);  //$title = $node_info->title";    // Do the main query  $query = 'SELECT sd.name as name, sd.sid as sid, c.cid as cid, c.type as type, sd.data as data, c.extra as extra, c.value as value '.    'FROM {webform_submitted_data} sd, {webform_component} c '.    'WHERE sd.nid = c.nid '.    '  AND sd.name = c.name '.    '  AND sd.nid = %d '.    'ORDER BY c.cid, sd.data';  $res = db_query($query, $nid);    // View the submitted entries as a list with tallies.  $question_number = 0;  $question_name = '';  $new_question = true;    $rows = array();  $shadow_rows = array();	// Everything in rows[] will be displayed, so shadow_rows[] keeps things  // that we do not want to display such as raw tallies.    $header = array(t('Q'),t('choice'),array('data' => t('responses'),'colspan' => '2'));    // Setup for the covariance matrix, but only if we need to  if(in_array('c',$views_switches)){    $covariance_records = array();	// An array of arrays of SIDs    $cm_index = array();						// A lookup array to get index into $covariance_records  }    // This is the main loop that steps through all of the records returned by the  // SQL query.  This is a superset of the required nodes given in $valid_nodes[]    while ($field = db_fetch_object($res)) {        if(!isset($valid_nodes[$field->sid])){      // Use the array lookup on the $valid_nodes[] to be a filter.  Loop back if it fails.      continue;    }        // It must be a valid record to get this far.        if($field->name != $question_name){      //We must have hit a new question (component)      $question_name = $field->name;      $question_number++;      $new_question = true;      $component_type = $field->type;            // Perform common and psuedo-common actions for components            switch($component_type){      case 'textarea':      case 'textfield':      case 'select':        //$row = array();        $row[0] = $shadow_row[0] = $question_number;        $row[1] = $shadow_row[1] = sprintf($view_settings['options']['heading_format'],$field->name);        $row[2] = $shadow_row[2] = ''; 			// The question heading have nothing in the columns to their right where the        $row[3] = "";												// data appears in other rows.  So we fill up the view switches cells with ''                $rows[] = $row;        break;      }    }        // Perform specific actions for components.    // This should be a switch statement but it looks too ugly.        if($component_type == 'textarea' || $component_type == 'textfield'){            if($new_question){                $new_question = false;  // Only one pass here for each question                     // A textarea object does not have subquestions like checkboxes or radio buttons, rather it has nominated analysis characteristics        // as given in the $choices[].                $choices = array('blank' => t('Left Blank'),'default' => t('Default'), 'value' => t('User entered value'),'average' => t('Average submission length in words (ex blanks)'));                foreach ($choices as $subkey => $choice) {          $stripped_choice = trim($choice);     // Have to pull off the line-feeds etc.. Should not be any as we created the array just above by hand.                    if($subkey == 'default'){            if(!trim($field->value)){              // If there is no user default value set, then we don't need a row for it because it will be the same as blank.              continue;            }          }                    $skey = "$question_name"."$question_number";	// The question number is included in case there are ever more than one textarea with the same name          $rkey = "$skey"."$subkey";                    $row = array();          $shadow_row = array();																	// This is the non-display shadow that persists data for calculations          $row[0] = $shadow_row[0] = '';													// No numbering on options of textareas          $row[1] = $shadow_row[1] = sprintf($view_settings['options']['nonuser_option_format'],$stripped_choice); 	// The results title, highlighted to differentiate it from the user entered questions of other component types.          $row[2] = $shadow_row[2] = '';													// The tallies will go here          $row[3] = '';																						// Any analog bar or percentages will go here		          $shadow_row[$subkey] = 0;                    $rows[$rkey] = $row;          $shadow_rows[$skey] = $shadow_row;		          unset($row,$rkey,$shadow_row);        }      }            // The possible choices for a textarea/textfield are now stored and this may be a first or subsequent call      reset($rows);            if(!isset($shadow_rows[$skey]['word_count'])) $shadow_rows['word_count'] = 0;      if(!isset($shadow_rows[$skey]['average'])) $shadow_rows['average'] = 0;            if(trim($field->data)){        if(trim($field->data != $field->value)){          // Then it is not empty or the same as the default          $shadow_rows[$skey]['value']++;        } else {          $shadow_rows[$skey]['default']++;        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -