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

📄 webform.inc

📁 对于。Net最新的MVC开发方式提供自动对类的注入Webform
💻 INC
📖 第 1 页 / 共 3 页
字号:
        $shadow_rows[$skey]['word_count'] += str_word_count($field->data);        //$shadow_rows[$skey]['average'] = round($shadow_rows[$key]['word_count'] / $valid_records);      } else {        $shadow_rows[$skey]['blank']++;      }            //unset($skey);            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.                $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";                if(isset($rows[$rkey])){          // Check it is set because some may not exist by design, ie when the default is blank          switch($subkey){          case 'average':            $divisor = ($valid_records - $shadow_rows[$skey]['blank']);            if ($divisor !== 0) {            $av = round($shadow_rows[$skey]['word_count'] / ($valid_records - $shadow_rows[$skey]['blank']),1);	// 1 decimal place            }            else {              $av = 0;            }            $rows[$rkey][2] = _build_tally($views_switches,$view_settings,$av);            $rows[$rkey][3] = '';		// No percentages or bars on average wordcounts            break;          default:            $rows[$rkey][2] = _build_tally($views_switches,$view_settings,$shadow_rows[$skey][$subkey]);            $rows[$rkey][3] = _build_percentages($views_switches,$view_settings,$shadow_rows[$skey][$subkey],$valid_records);            break;          }        }      }      //unset($skey,$rkey,$subkey);    }        if($component_type == 'select'){            if($new_question){        $new_question = false;  // Only one pass here for each question                // select components need to have their options pulled out        // from the extra field                $extra_data = unserialize($field->extra);                if(is_array($extra_data)){                    if($extra_data['multiple'] == 'Y'){            $multiple_choice = true;		// ie Checkboxes          } else {            $multiple_choice = false;		// ie Radio Buttons          }          if($extra_data['aslist'] == 'Y'){            $aslist = true;   // ie List Box and thus implying lot's of choices          } else {            $aslist = false;          }                    $choices = explode("\n", _webform_filtervalues($extra_data['items']));                    if(is_array($choices)){            foreach ($choices as $choice) {                            $stripped_choice = trim($choice);     // Have to pull off the line-feeds etc..              $key = "$question_name"."$stripped_choice";	                            $row = array();              $shadow_row = array();	// This is the non-display shadow that persists data for calculations              $row[0] = $shadow_row[0] = _build_numbering($views_switches,$view_settings,$question_number);              //$default_label = ($stripped_choice == trim($field->value)) ? '<span style="color: = ' . $view_settings['options']['highlight_color'] . '"> ' . $view_settings['options']['default_identifier'] . '</span>':'';              $default_label = ($stripped_choice == trim($field->value)) ? '<span style="color: = red "> ' . $view_settings['options']['default_identifier'] . '</span>':'';              $row[1] = $shadow_row[1] = $stripped_choice . $default_label; 	// The option title              $row[2] = '';              $row[3] = '';                            $shadow_row['raw_tally'] = 0;	// Raw tallies are always kept              $rows[$key] = $row;              if($aslist) {                $shadow_row['do_not_display'] = true;              }              else {                $shadow_row['do_not_display'] = false;              }              $shadow_rows[$key] = $shadow_row;                            // Populate the Covariance Matrix index lookup array if required              if(in_array('c',$views_switches)) $cm_index[$key] = $row[0];                            unset($row,$key,$shadow_row);            }          }            }      }            // The choices are now stored in $question_rows and this may be a first or subsequent call      reset($rows);            if($multiple_choice){                // Handling multiple choice checkboxes        $multiple_data = unserialize($field->data);        if(is_array($multiple_data)){          if(count($multiple_data)){  // Stops a zero length array hitting the foreach            foreach($multiple_data as $check){              $key = "$question_name".trim($check);                            $shadow_rows[$key]['raw_tally']++;              $shadow_rows[$key]['do_not_display'] = false;               if(in_array('c',$views_switches)){                $covariance_records[$cm_index[$key]][] = $field->sid;                $covariance_records[$field->sid][$cm_index[$key]] = true;                //print "Count -> " . count($covariance_records[$cm_index[$key]]);              }                            $rows[$key][2] = _build_tally($views_switches,$view_settings,$shadow_rows[$key]['raw_tally']);              $rows[$key][3] = _build_percentages($views_switches,$view_settings,$shadow_rows[$key]['raw_tally'],$valid_records);            }          } else {            // If no checkboxes are selected, then you would expect a zero length array            // which would end up in here.  It does not because the data contains a simple 0 rather             // than a zero length array!          }        } else {          // No checkboxes selected results in a 0 rather than a zero length array.  The          // is_array() conditional therefore drops the condition here          //print ("It was not an array at all, it was $field->data and there were $field->tally of them");        }      } else {                // Handling normal radio buttons        $key = "$question_name".trim($field->data);        $shadow_rows[$key]['raw_tally']++;        $shadow_rows[$key]['do_not_display'] = false;         if(in_array('c',$views_switches)){          $covariance_records[$cm_index[$key]][] = $field->sid;          $covariance_records[$field->sid][$cm_index[$key]] = true;          //print("<br>--> $field->sid , $cm_index[$key]");        }                $rows[$key][2] = _build_tally($views_switches,$view_settings,$shadow_rows[$key]['raw_tally']);        $rows[$key][3] = _build_percentages($views_switches,$view_settings,$shadow_rows[$key]['raw_tally'],$valid_records);        //$pss = '<div class="bar"><div style="width: '. $ps .'%;" class="foreground"></div>'; // This is the "correct" way, but I couldn't get it to work easily.              }      end($rows);      unset($key);    }      } //end main loop  // Remove any rows that should not be display, ie have had $shadow_rows[$key]['do_not_display'] set to true  foreach($shadow_rows as $skey => $shadow_row){    if($shadow_row['do_not_display']){      // Extract element from rows[] here      unset($rows[$skey]);    }  }  // Display the Results Table  $box_content = "<br>";  $box_content .= theme('table', $header, $rows);    // Add legend elements below the table  $box_content .= "<p><br>";  $box_content .= $view_settings['options']['default_identifier'];  $box_content .= " = Default Value <br>";    $content .= theme_box("Results Table", $box_content);    // Construct the covariance matrix if requested    if(in_array('c',$views_switches)){        $box_content = "<br>";	// The covariance matrix is themed as a box        $cm_rows = array();    $cm_header = array();        $cm_row[] = '&nbsp;';			// The corner square!    $build_header = true;        foreach($shadow_rows as $sr){      if($sr[0]){        $cm_row = array();                if($build_header){          $cm_header[] = "&nbsp;";        }                $cm_row[0] = "<b>$sr[0]</b>";        $row_tally = $sr['raw_tally'];        $max_registered = 0;                foreach($shadow_rows as $sc){          if($sc[0]){            if($build_header){              $cm_header[] = $sc[0];            }            $positive_covariance = 0;            //$negative_covariance = 0;            foreach($covariance_records[$sc[0]] as $sid){              if($covariance_records[$sid][$sr[0]]){                $positive_covariance++;                if($positive_covariance > $max_registered){                  $max_registered = $positive_covariance;	 // Find maximum for normalization                }              }            }            $cm_row[$sc[0]] = $positive_covariance;          }        }                $build_header = false;                // Go back and set the normalized values        //$first = true;        foreach($shadow_rows as $sc){          if($sc[0]){            $pc = $cm_row[$sc[0]];            if ( $max_registered != 0 ) {              $av = round(255 * $pc / $max_registered,1);            }            else {              $av = 0;            }            if($max_registered){              $cm_row[$sc[0]] = '<span style="background-color:' . sprintf("#%'02x%'02x%'02x",$av,$av,$av) . '">' . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>';            }else{              $cm_row[$sc[0]] = 'N';            }          }        }        $cm_rows[] = $cm_row;        unset($cm_row);      }    }        $box_content .= theme('table', $cm_header, $cm_rows);    $content .= theme_box("Covariance Matrix", $box_content);      }    return $content;}/** _build_tally - Creates an HTML string sufficient to render the current tally as * appropriate to the current $views_switches[]. * @param &$views_switches A reference to an array of current views_switches which may toggle elements of the display. * @param &$view_settings  A reference to an array of current view_settings which may change the apprearance of elements. * @param $t An integer representing the current tally * @return an HTML string representing the tally. **/function _build_tally(&$views_switches,&$view_settings,$t){  // $view_settings[] is not currently used here.  It may later.  $output_string = in_array('t',$views_switches) ? "$t":"";  return $output_string;}/** _build_numbering - Creates an HTML string sufficient to render the question number as * appropriate to the current $views_switches[]. The function creates the number internally by incrementing * static variables. * @param &$views_switches A reference to an array of current views_switches which may toggle elements of the display. * @param &$view_settings  A reference to an array of current view_settings which may change the apprearance of elements. * @param $qn An integer representing the current question number * @return an HTML string representing the question number. **/function _build_numbering(&$views_switches,&$view_settings,$qn){    static $last_question = -1;  static $last_subnumber = -1;    if (!in_array('c',$views_switches)) return "";    if($qn != $last_question){    $last_subnumber = 1;    $last_question = $qn;  } else {    $last_subnumber++;  }    $number_string  = "$last_question.$last_subnumber";																// Simple #.# format  $output_string .= sprintf($view_settings['options']['subnumbering_format'],$number_string);    return $output_string;}/** _build_percentages - Creates an HTML string sufficient to render an analog bar and percentage label as * appropriate to the current $views_switches[]. * @param &$views_switches A reference to an array of current views_switches which may toggle elements of the display. * @param &$view_settings  A reference to an array of current view_settings which may change the apprearance of elements. * @param $fraction An integer representing an ordinal number of elements comprising all or part of the total.  0 <= $fraction <= $total * @param $total A integer representing the total number of elements in the population. * @return an HTML string representing the bar. **/function _build_percentages(&$views_switches,&$view_settings,$fraction,$total){    $output_string = "&nbsp;";  $calculated_percentage = false;	// The conditional is a tad quicker than doing the maths multiple times    // First some range checking for safety.  if($fraction < 0) $fraction = 0;  if($fraction > $total) $fraction = $total;    if(in_array('a',$views_switches)){    $ps = round($fraction * 100 / $total);	// 100 to make it a percentage    $calculated_percentage = true;    $output_string .= "&nbsp";							// We tend to pad with &nbsp; to stop it ever wrapping    $output_string .= _build_percentage_bar($view_settings,$ps);    $output_string . "&nbsp";								// We tend to pad with &nbsp; to stop it ever wrapping  }  if(in_array('p',$views_switches)){    if(!$calculated_percentage) $ps = round($fraction * 100 / $total);	// 100 to make it a percentage    $output_string .= "&nbsp;";							// We tend to pad with &nbsp; to stop it ever wrapping    $output_string .= sprintf("%d%%",$ps);  }    return $output_string;}/** _build_percentage_bar - Creates an analog bar of length k, k:0 <= k <= 100.  The bar is rendered in HTML using <span></span> tags * using attributes such as color and character type as provided in $view_settings[].  The output string is not padded and will * vary in length with the percentage rendered.  This is by design as it allows values to be attached flush to the end of the bar. * @param &$vs A reference to an array of current view_settings. * $param $ps The percentage that is to be rendered as a bar.  This number is assumed to be a percentage. * @return an HTML string representing the bar.  The string is not padded and will vary in length with the percentage rendered. **/function _build_percentage_bar(&$vs,$ps = 0){  // First some range checking for safety.  if($ps < 0) $ps = 0;  if($ps > 100) $ps = 100;    // Calculate the bar length in HTML characters as required to render it.  // The bar will appear shorter than this.  For example &nbsp; is 6 characters long but renders as 1 character.  $pad = round($ps / $vs['analog_bar']['resolution']) * strlen($vs['analog_bar']['bar_char']) ; // We multiply by strlen because we use str_pad() to build the bar and thus we need it to be a multiple of whatever character we use ie: &nbsp; = 6 chars  $bar_string = '<span style="background-color:' . $vs['analog_bar']['color'] . '">' . str_pad('',$pad,$vs['analog_bar']['bar_char']) . '</span>';  // Ugly non-robust way of drawing a bar.	return $pad;  return $bar_string;}?>

⌨️ 快捷键说明

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