{ $mandatory=implode("|", remove_nulls_from_array($mandatorys)); echo "<input type='hidden' name='mandatory' value='$mandatory' id='mandatory' />\n"; } if (remove_nulls_from_array($conmandatorys)) { $conmandatory=implode("|", remove_nulls_from_array($conmandatorys)); echo "<input type='hidden' name='conmandatory' value='$conmandatory' id='conmandatory' />\n"; } if (remove_nulls_from_array($mandatoryfns)) { $mandatoryfn=implode("|", remove_nulls_from_array($mandatoryfns)); echo "<input type='hidden' name='mandatoryfn' value='$mandatoryfn' id='mandatoryfn' />\n"; } if (remove_nulls_from_array($conmandatoryfns)) { $conmandatoryfn=implode("|", remove_nulls_from_array($conmandatoryfns)); echo "<input type='hidden' name='conmandatoryfn' value='$conmandatoryfn' id='conmandatoryfn' />\n"; } echo "<input type='hidden' name='thisstep' value='{$_SESSION['step']}' id='thisstep' />\n" ."<input type='hidden' name='sid' value='$surveyid' id='sid' />\n" ."<input type='hidden' name='start_time' value='".time()."' id='start_time' />\n" ."<input type='hidden' name='token' value='$token' id='token' />\n" ."</form>\n"; echo templatereplace(file_get_contents("$thistpl/endpage.pstpl")); echo "\n"; doFooter(); ?>
/** * function select_random() * This function is given a string of <li>'s it is then converted into PHP code so that a random option can be selected * @param string $random_options - a string of <li>this</li><li>that</li> options to be made into an array and PHP code * @return array $array - the clean array **/ function select_random($random_options) { //echo "HERE WITH ".htmlentities($random_options); //initialise php code string $str = ""; //check if there is another random in here $find = "#<random>(.*)</random>#is"; if (preg_match($find, $random_options, $matches)) { //found a match and recall this function $replace = select_random($matches[1]); $find = "#<random>(.*)</random>#is"; $random_options = preg_replace($find, $replace, $random_options); } runDebug(__FILE__, __FUNCTION__, __LINE__, "Building an array to select random option from", 4); $arrayname = "\$" . get_random_str(); //split up the <li>'s $random_options = preg_split('#<li>|</li>#', $random_options); //remove any blanks from array $random_options = remove_nulls_from_array($random_options); //count the total options $mx = count($random_options) - 1; //add to php code string $str .= "'; \r\n\r\n{$arrayname} = rand(0,{$mx});\r\n\r\n"; //build big if else so that we can select a random options later foreach ($random_options as $index => $value) { if ($index == 0) { $str .= "if(" . $arrayname . "=='" . $index . "'){\r\n\t\$tmp_botsay.= '" . $value . "'; }\r\n"; } elseif (count($random_options) - 1 == $index) { $str .= "else{\r\n\t\$tmp_botsay.= '" . $value . "'; }\r\n\r\n"; $str .= "\$tmp_botsay .= '"; } else { $str .= "elseif(" . $arrayname . "=='" . $index . "'){\r\n\t\$tmp_botsay.= '" . $value . "'; }\r\n"; } } //return the php code string runDebug(__FILE__, __FUNCTION__, __LINE__, "Built PHP code string so that we can select option later: {$str}", 4); return $str; }