Location: PHPKode > scripts > AskPeople-Free PHP survey application > AskPeople_2_2_2/survey.php
<?php

$completedSurveyCookie = 'askpeople_survey_completed'; // hardwired into the script to cut down on survey settings, but feel free to modify if need be

ob_start();
require_once('includes/functions.inc.php');
session_start();

if ($_REQUEST['reset'] == "yes") {
	$a_stitle = $_SESSION['admin_stitle'];

	session_destroy();
	session_start();
	$_SESSION['admin_sid'] = $_REQUEST['sid'];
	$_SESSION['admin_stitle'] = $a_stitle;
	//@array_map("unset",$_SESSION['submitted']); - a buggy approach - better to destroy the session, even if it means logging back in
}

//print_r($_SESSION);
if ($_COOKIE['askpeople_portcullis']) {

	if ($_REQUEST['reset'] != "yes") {
		$consolebar = "<div id=\"consolebar\" class=\"clearbox\">
		<p>Go to: <a href=\"projmgr.php\">Project Manager</a> | 
		<a href=\"qeditor.php\">Edit questionnaire</a> | 
		<a href=\"http://www.askpeople.co.uk/help/\" target=\"_blank\">Help</a> | 
		<a href=\"login.inc.php?logout=true&referer={$globalsettings['logoutURL']}\">Logout</a> |
		<a onclick=\"toggleVisibility('consolebar');\" href=\"#\">Hide this bar</a>
		<br /><small>(these links are only shown while you are logged in, and not visible to respondents)</small></p>
		</div>
		";	
	} else {
		$consolebar = "<div id=\"consolebar\" class=\"clearbox\">
		<p>Go to: <a href=\"projmgr.php?sid={$_REQUEST['sid']}\">Project Manager</a> | 
		<a href=\"qeditor.php?action=EditQuestionnaire&sid={$_REQUEST['sid']}\">Edit questionnaire</a> | 
		<a href=\"http://www.askpeople.co.uk/help/\" target=\"_blank\">Help</a> | 
		<a href=\"login.inc.php?logout=true&referer={$globalsettings['logoutURL']}\">Logout</a> |
		<a onclick=\"toggleVisibility('consolebar');\" href=\"#\">Hide this bar</a>
		<br /><small>(these links are only shown while you are logged in, and not visible to respondents)</small></p>
		</div>
		";	
	}
}

if ($_REQUEST['embed'] != "true") { // hide the console bar for embedded (iframed) surveys - just for neatness
	$html .= $consolebar;
}

$qid = "surveys/quest_" . $_REQUEST['sid'] . ".xml";
$loaded = loadQuest2($qid); // load questionnaire

$configpath = "surveys/config_" . $_REQUEST['sid'] . ".php";	
include_once($configpath); // load survey settings

$templatepath = "templates/" . $loaded['meta']['template'];	
//include_once($templatepath); // load survey template (for header)

$template = @file_get_contents($templatepath);
if (strlen($template)<1) { // no content in the template, so just show the raw output
	$template = "<html>\n<!-- SURVEYFORM -->\n</html>";
}

if ($surveysettings['surveyStatus'] == "Closed") {
	$errormsg = ("{$surveysettings['surveyClosedMessage']}");
}

if ($surveysettings['blockResubmission'] == "TRUE" && ($_COOKIE["$completedSurveyCookie"] == $_REQUEST['sid'])) {	
	$errormsg = ("{$surveysettings['blockResubmissionMessage']}");
	$blockresubmissionflag = "TRUE";
}
   
// do stuff with the most recent batch of $_POSTed data - stick in a session, validate it, whatever
foreach((array)$_POST['answers'] as $k => $v) {
	$_SESSION['submitted'][$k] = $v;
}

// validate submission from previous page, if any
if (strlen($_POST['validated_required'])>0) {
	$validated['required'] = explode(",",$_POST['validated_required']);
	$missingflag = null;
	
	foreach((array)$validated['required'] as $v) {
		if (strlen(@implode("",$_SESSION['submitted'][$v]))<1) { // no answer supplied for this required q
			$missingflag = "TRUE";
		}
	}
	
	if ($missingflag == "TRUE") {
 		 $errormsg = ("{$surveysettings['missingRequiredMessage']}");
	}
	
}//print_r($_SESSION['submitted']);

if ($_POST['direction'] == "Next" || $_POST['direction'] == $surveysettings['submitButtonLabel']) {
	$startid = ($_POST['nextnode']) ? $_POST['nextnode'] : "0";
} elseif ($_POST['direction'] == "Previous") {
	$startid = ($_POST['prevnode']) ? $_POST['prevnode'] : "0";	
} else {
	$startid = "0";
	$_SESSION = null;
}

$startnode = findBreak($startid,'prev',$loaded[questions]);
$nextnode = findBreak($startid,'next',$loaded[questions]);

$html .= "<form action='survey.php' method='post'>
 <input type='hidden' name='sid' value=\"{$_REQUEST['sid']}\" />
 <input type='hidden' name='uid' value=\"".urldecode($_REQUEST['uid'])."\" />
 <input type='hidden' name='prevnode' value=\"{$startnode}\" />
 <input type='hidden' name='nextnode' value=\"{$nextnode}\" />

 <h1 class=\"clearbox\">{$loaded['meta']['title']}</h1>
";
	
if ($startid <= "1" && !$errormsg) { 
	$firstqflag = "TRUE"; 
	$html .= "<div id='introduction'><p>{$loaded[meta][introduction]}</p></div>"; // populate intro for the first q
}		
	
$html .= "<div class='page'>"; // start of the page
	
if ($firstqflag != "TRUE") {
	$prevbtn = "<input type='submit' name='direction' value='Previous' />";	
}

$disabled = ($missingflag == "TRUE" || $blockresubmissionflag == "TRUE") ? " disabled='disabled' ": null;

if ($nextnode > count($loaded[questions])) {
	$lastqflag = "TRUE"; 
	$nextbtn = "<input type='submit' name='direction' value='{$surveysettings['submitButtonLabel']}' {$disabled}/>";
} else {
	$nextbtn = "<input type='submit' name='direction' value='Next' {$disabled}/>";
}

if ($surveysettings['showReset'] == "TRUE") {
	$resetlink = "<a onclick=\"return confirmSubmit('".$surveysettings['resetWarning']."');\" href='survey.php?sid={$_REQUEST['sid']}&amp;reset=yes' id='resetlink'>{$surveysettings['resetLink']}</a>";
}

// check for password
if (strlen($surveysettings['surveyPassword'])>0 && ($_COOKIE['askpeople_password_'.$_REQUEST['sid']] != md5($surveysettings['surveyPassword']) ) ) { // password is set

	if ($_POST['passwordsubmit'] == "true") { // if submitted password, check it
		if ($_POST['surveypassword'] == $surveysettings['surveyPassword']) { // password OK
			setcookie("askpeople_password_".$_REQUEST['sid'],md5($surveysettings['surveyPassword'])); // session cookie
			header('Location: survey.php?sid='.$_REQUEST['sid']."&uid=".$_REQUEST['uid']);
		} else { // no match
			$html .= "
			  </form> <!-- close main survey form which otherwise is left open -->
			  
			  <form action='survey.php' method='post' id='surveypasswordform'>
			  <label>{$surveysettings['surveyPasswordError']}<br />
			  <br /><input type='password' size='10' name='surveypassword' /></label> <input type='submit' value='Go' />
			 
			  <input type='hidden' name='passwordsubmit' value='true' />
			  <input type='hidden' name='sid' value='{$_REQUEST['sid']}' />
			  <input type='hidden' name='uid' value='{$_REQUEST['uid']}' />
			  </form>
			";	
		}
	} else { // show password form
		$html .= "
		  </form> <!-- close main survey form which otherwise is left open -->
		
		  <form action='survey.php' method='post' id='surveypasswordform'>
		  <label>{$surveysettings['surveyPasswordInstruction']}<br />
		  <br /><input type='password' size='10' name='surveypassword' /></label> <input type='submit' value='Go' />
		  
		  <input type='hidden' name='passwordsubmit' value='true' />
		  <input type='hidden' name='sid' value='{$_REQUEST['sid']}' />
		  <input type='hidden' name='uid' value='{$_REQUEST['uid']}' />
		  </form>
		";	
	}
	
  $html = str_replace("<!-- SURVEYFORM -->",$html,$template);
  echo ($html);
	
} else {

  if ($startid <= count($loaded[questions])) {

	//$progresspoint = round(($startid/count($loaded[questions]))*100); // this seems ot undercount where you really are in the survey by the time you scroll to the foot of the page

	for($q=$startid;$q<=count($loaded[questions]);$q++) {
	
	   $qv = $loaded[questions][$q];
	   $validatedflag = null;
	   
	   // get stuff from the $_SESSION['submitted'] array if there is a value for element[$q]
	   
	   if ($breakflag != "TRUE" && !$errormsg && !$missingflag) { // no flags, so add another question to this chunk
	  
   	    if ($qv['type']) {
   	       $html .= "\n<div id=\"q{$q}\" class='question {$qv[type]}'>\n"; // start of the question node
		}
		
		if ($qv['validation'] == "required") { // some validation required (future versions could use and OR clause for other types of validation here
			$validatedqs['required'][] = $q;
			$validatedflag = " <span class='required'>(REQUIRED)</span>";
		}
		
		if ($qv['questiontext']) {
		   $question = "\t<p class='questiontext'>".nl2br($qv[questiontext])."{$validatedflag}</p>\n";
		} else {
		   $question = NULL;	
		}

		switch($qv['type']) {
		  
			case "single" :		  
			  
			  if ($surveysettings['randomiseOrder'] == "TRUE" && (!eregi("other_specify:",@implode("",$qv['options'])))) { // a template setting to reorder answer options to avoid question-order effects for questions without other_specify vales
				  shuffle($qv[options]);			  
			  }
			  
			  if (count($qv[scale])>0) { // there are scale options, so make this a grid
				$question .= "<table class='grid'>\n<thead class='gridheader'><tr><th><!--empty option row header--></th>\n";
				foreach((array)$qv['scale'] as $s) { // make a header row
					$question .= "<th class='gridheadercol'>{$s}</th>\n"; // header in the column for each scale point
				}
				$question .= "</tr></thead>\n\n<tbody>\n";
				foreach((array)$qv['options'] as $o) { 
					$opt = idWord($o);
					$question .= "<tr class='gridrow'><td class='optionlabel'>{$o}</td>\n";// foreach option, make a row
					foreach((array)$qv[scale] as $qk => $s) {
						$scpt = idWord($s);
						$s = addslashes($s);
				        $active = NULL;
			      		if ($_SESSION['submitted'][$q]['code'][$opt] == $s) { $active = " checked='checked'"; }
						$question .= "<td><input type='radio' name='answers[$q][code][{$opt}]' value=\"{$s}\"{$active} /></td>\n"; // then make a column for each scale point
					}
					$question .= "</tr>\n";// end of option row
				}
				$question .= "</tbody></table>\n";
			  } else {
				foreach((array)$qv[options] as $o) { 
				  if (eregi("other_specify:.*",$o) && $otherflag != "TRUE") {
					  $otherflag = TRUE;
					  $otherlabel = str_replace("other_specify:","",$o);
					  $otherlabel = (strlen($otherlabel)>0) ? $otherlabel : "Other (please specify)";
					  $opt = idWord($otherlabel);
					  $o_val = addslashes($o);
					  $active = NULL;
					  if ($_SESSION['submitted'][$q][code] == $o_val) { $active = " checked='checked'"; }
					  $question .= "\t<p class='singleoption'><label><input type='radio' name='answers[$q][code]' value=\"{$o_val}\"{$active} /> {$otherlabel}</label> <input type='text' name='answers[$q][other]' class='othervalue' value=\"".htmlspecialchars(stripslashes($_SESSION['submitted'][$q][other]))."\" /></p>\n";
				  } else {
					  $otherflag = FALSE;
	  			      $opt = idWord($o);
			      	  $o_val = addslashes($o);
					  $active = NULL;
					  if ($_SESSION['submitted'][$q][code] == $o_val) { $active = " checked='checked'"; }
					  $question .= "\t<p class='singleoption'><label><input type='radio' name='answers[$q][code]' value=\"{$o_val}\"{$active} /> {$o}</label></p>\n";
				  }
				}
			  }
			break;
			
			case "dropdown" :
			
			  if ($surveysettings['randomiseOrder'] == "TRUE" && (!eregi("other_specify:",@implode("",$qv['options'])))) { // a template setting to reorder answer options to avoid question-order effects for questions without other_specify vales
				  shuffle($qv[options]);			  
			  }

			  $question .= "<select name='answers[$q][code]' class='dropdownoption'>";
			  $question .= "\t<option value=\"\">{$surveysettings['dropdownDefaultText']}</option>\n";
			  
			  foreach((array)$qv[options] as $o) { 
				  $otherflag = FALSE;
				  $opt = idWord($o);
				  $o_val = addslashes($o);
				  $active = NULL;
				  if ($_SESSION['submitted'][$q][code] == $o_val) { $active = " selected='selected'"; }
				  $question .= "\t<option value=\"{$o_val}\"{$active}>{$o}</option>\n";
			  }
			  
			  $question .= "</select>\n";
			  
			break;
			
			case "multi":

			  if ($surveysettings['randomiseOrder'] == "TRUE" && (!eregi("other_specify:",@implode("",$qv['options'])))) { // a template setting to reorder answer options to avoid question-order effects for questions without other_specify vales
				  shuffle($qv[options]);			  
			  }
			  
			  if (count($qv[scale])>0) { // there are scale options, so make this a grid
				$question .= "<table class='grid'>\n<thead class='gridheader'><tr><th><!--empty option row header--></th>\n";
				foreach((array)$qv[scale] as $s) { // make a header row
					$question .= "<th class='gridheadercol'>{$s}</th>\n"; // header in the column for each scale point
				}
				foreach((array)$qv[options] as $o) { 
					$opt = idWord($o);
					$question .= "</tr></thead><tbody><tr class='gridrow'><td class='optionlabel'>{$o}</td>\n";// foreach option, make a row
					foreach((array)$qv[scale] as $qk => $s) {
						$scpt = idWord($s);
				        $active = NULL;
			      		if ($_SESSION['submitted'][$q][code][$opt][$scpt] == "TRUE") { $active = " checked='checked'"; }
						$question .= "<td><input type='checkbox' name='answers[$q][code][{$opt}][{$scpt}]' value='TRUE'{$active} /></td>\n"; // then make a column for each scale point
					}
					$question .= "</tr>\n";// end of option row
				}
				$question .= "</tbody></table>\n";
			  } else {
				foreach((array)$qv[options] as $qk => $o) { 
				  if (eregi("other_specify:.*",$o) && $otherflag != "TRUE") {
					  $otherflag = TRUE;
					  $otherlabel = str_replace("other_specify:","",$o);
					  $otherlabel = (strlen($otherlabel)>0) ? $otherlabel : "Other (please specify)";
					  //$opt = idWord($otherlabel);
					  $opt = idWord($o);
					  $active = NULL;
					  if ($_SESSION['submitted'][$q][code][$opt] == "TRUE") { $active = " checked='checked'"; }
					  $question .= "\t<p class='multioption'><label><input type='checkbox' name='answers[$q][code][{$opt}]' value='TRUE'{$active} /> {$otherlabel}</label> <input type='text'  class='othervalue' name='answers[$q][_other]' value=\"".htmlspecialchars(stripslashes($_SESSION['submitted'][$q][_other]))."\" /></p>\n";
				 } else {
					  $otherflag = FALSE;
					  $opt = idWord($o);
					  $active = NULL;
					  if ($_SESSION['submitted'][$q][code][$opt] == "TRUE") { $active = " checked='checked'"; }
					  $question .= "\t<p class='multioption'><label><input type='checkbox' name='answers[$q][code][{$opt}]' value='TRUE'{$active} /> {$o}</label></p>\n";
				  
				  }
				}
			  }
			  
			break;
			
			case "smallbox" :
			
			    $active = (strlen($_SESSION['submitted'][$q][other])>0) ? htmlspecialchars(stripslashes($_SESSION['submitted'][$q][other])) : stripslashes(@implode("",$qv[options]));
				$question .= "\t<p class=\"smallboxoption\"><input type=\"text\" name=\"answers[$q][other]\" id=\"answers_{$q}_other\" size=\"{$surveysettings['smallBoxWidth']}\" value=\"{$active}\" /></p>\n";
				
			break;
			
			case "bigbox" :
			
			    $active = (strlen($_SESSION['submitted'][$q][other])>0) ? stripslashes($_SESSION['submitted'][$q][other]) : stripslashes(@implode("",$qv[options]));
				$question .= "\t<p class=\"bigboxoption\"><textarea name=\"answers[$q][other]\" id=\"answers_{$q}_other\" cols=\"{$surveysettings['bigBoxWidth']}\" rows=\"{$surveysettings['bigBoxHeight']}\">{$active}</textarea></p>\n";

			break;
			
			case "info" :
			
				 // this type just has content in the question wording, and no options
				$question .= "\t<input type='hidden' name='answers[$q]' value='[info]' />\n";
				 
			break;

			case "pagebreak" :
			
				$breakflag = "TRUE";
			
			break;
			
			default :
			
			break;
		  
		}
		
		if ($missingflag != "TRUE") {
			$html .= $question;
		}
		
		if ($qv[type]) { $html .= "\n\t<div class='breaker'></div>\n</div>\n\n"; } // end of the question node
	  }
		
	}
			
	// show error if there is one
	$html .= ($errormsg) ? "\n<div class='errormsg'>\n{$errormsg}\n</div>" : null;
	
	$html .= "\n</div>\n"; // end of the page of questions
		
	if ($surveysettings['showProgress']  == "TRUE") {
		$progresshere = ($nextnode>count($loaded[questions])) ? count($loaded[questions])-1 : $nextnode-1;
		$progresspoint = round(($progresshere/count($loaded[questions]))*100);
		$firstpoint = ($progresspoint > 0) ? "continuationscreen" : "firstscreen"; // set a class so we can tweak the CSS display of the progress bar for the first screen (where 0% looks funny otherwise)	
		$progresschunk = "<p id='progressindicator'><span id='progressbar' class=\"{$firstpoint}\" style=\"width:{$progresspoint}%;\">$progresspoint%</span>&nbsp;{$surveysettings['progressComplete']}</p>";
	}
	
	//question validation - record which questions on this page need validation, and pass to the next page
	if (count($validatedqs)>0) { // some of the qs on this page need to be validated when the user moves to the next node
		$validated_required = '<input type="hidden" name="validated_required" value="'hide@address.com(",",$validatedqs['required']).'" />';
	} else {
		$validated_required = null;
	}
	
	$html .= "
	<div id='surveycontrol'>
	  <div id='progress'>{$progresschunk}</div>
	  <div id='buttons'>{$prevbtn}&nbsp;{$nextbtn} &nbsp; {$resetlink}</div>
      <div class='breaker'></div>
   </div>
	";

	$html .= "
	 {$validated_required}\r
	 <input type=\"hidden\" name=\"embed\" value=\"".$_REQUEST['embed']."\" />\r
	 </form>	 
	";

	$html = str_replace("<!-- SURVEYFORM -->",$html,$template);
	//$html = str_replace("<!-- BODYID -->","fromQ".$startid,$html); // make it easy to build CSS hooks into this page
	echo ($html);
	
 } else { // startid is beyond the end of the questionnaire, so have reached the end

	// check validation of stuff from the previous screen
	
	if ($errormsg || $missingflag) {
		
		$html .= ($errormsg) ? "<div class='errormsg'>\n{$errormsg}\n</div>" : null;
		$html .= "<div id='progressbuttons'><p>{$prevbtn}&nbsp;{$nextbtn} &nbsp; {$resetlink}</p></div></form>\n";
		$html = str_replace("<!-- SURVEYFORM -->",$html,$template);
		echo ($html);
	} else {
		$dodgy = array("\r","\n","\t");
	
		for ($c=1;$c<=count($loaded['questions']);$c++) {
			if (is_array($_SESSION['submitted'][$c])) { // there is data for this question
				
				$outputcell = NULL;
				switch ($loaded['questions'][$c]['type']) {
				
					case "single" :		                                                                                                                                                                                                                                                              
					  if (is_array($loaded['questions'][$c]['scale'])) { // grid
						  foreach((array)$_SESSION['submitted'][$c]['code'] as $k => $v) { // go down each questionoption...
							$answers_array[data][$c][$k] = $v; // store the questionoption and its corresponding scale value
						  }
					  } else { // flat single
						  
						  if (eregi("other_specify",@implode("",$loaded['questions'][$c]['options']))) { // there is an other option for this question
							$answers_array[data][$c][code] = $_SESSION['submitted'][$c]['code'];				  
							$answers_array[data][$c][other] = str_replace($dodgy," ",$_SESSION['submitted'][$c]['other']);				  
						  } else {
							$answers_array[data][$c] = $_SESSION['submitted'][$c]['code'];			  	  
						  }
					  }
					break;
	
					case "dropdown" :
					
						$answers_array[data][$c] = $_SESSION['submitted'][$c]['code'];			  	  

					break;
					
					case "multi" :		
					  if (is_array($loaded['questions'][$c]['scale'])) { // grid
						  foreach((array)$_SESSION['submitted'][$c]['code'] as $k => $v) { // go down each questionoption...
							foreach((array)$v as $scalepoint => $value) { // then look across at each scale point...
								$answers_array[data][$c][$k][$scalepoint] = $value; // store the scalepoint within its questionoption, and whether checked or not
							}
						  }				  				  				  
					  } else { // flat multi - but still need to store each questionoption individually
	
						  if (eregi("other_specify",@implode("",$loaded['questions'][$c]['options']))) { // there is an other option for this question
							  foreach((array)$_SESSION['submitted'][$c]['code'] as $k => $v) { // go down each questionoption...
								$answers_array[data][$c][$k] = $v; // store the questionoption, and whether checked or not
							  }	
							  $answers_array[data][$c][_other] = str_replace($dodgy," ",$_SESSION['submitted'][$c][_other]);
						  } else {
							  foreach((array)$_SESSION['submitted'][$c]['code'] as $k => $v) { // go down each questionoption...
								$answers_array[data][$c][$k] = $v; // store the questionoption, and whether checked or not
							  }				  				  				  					  
						  }					  
					  }
					break;
	
					default : // bigbox/smallbox
						$answers_array[data][$c] = str_replace($dodgy," ",$_SESSION['submitted'][$c]['other']);
					break;
				}
			} else { // no data
				$answers_array[data][$c] = null;
			}
		}
			
		$answers_array['uid'] = (strlen($_POST['uid'])>0) ? urldecode($_POST['uid']) : "Anonymous"; // append user id to answers, or say survey was filled in anonymously
	
		// save responses
		$savestring = saveResponse2($_REQUEST['sid'],$answers_array);
	
		if ($surveysettings['blockResubmission'] == "TRUE") { // set 30 day cookie to block resubmission
			setcookie("$completedSurveyCookie","$_REQUEST[sid]",time()+30*60*60*24);
		}
		
		if (@eregi("@",$surveysettings['emailResults'])) { // send the submission to administrator email address as an HTML attachment
		
			// construct HTML
			$data_array = @explode("\t",$savestring);
			$emailhtml = "<html>
			<head>
			<title>New response submitted</title>
			<style type='text/css'>
				span.questionnumber {
				  display: none;
				}
				body {
				  font-family: arial, helvetica, verdana, sans-serif;
				}
				.simpletable {
					border-collapse: collapse;
					border-spacing: 0;
					border: 1px solid #888;
					border-width: 1px 0 0 1px;
					margin: 1em 0;
					width: 100%;
				}
				.simpletable th, .simpletable td {
					border: 1px solid #888;
					border-width: 0 1px 1px 0;
					padding: 3px;
				}
			</style>
			</head>
			<body><h1>New response submitted: {$loaded['meta']['title']}</h1>";
			$emailhtml .= makeRespondentResultsTable($data_array,$_REQUEST['sid']);
			$emailhtml .= "</body></html>";
			
			$dodgy = array(" ","'",",",".");
			
			$now = date("d-M");
			$nicefilename = substr(strtolower(str_replace($dodgy,"_",$loaded['meta']['title'])),0,8) . "_" . $answers_array['uid'] . "_data.html";
	
 			$protocol = ($_SERVER['HTTPS'] == "on") ? "https://" : "http://"; // if installed on https server
			$directory = (substr(dirname($_SERVER['PHP_SELF']),-1) == "/") ? dirname($_SERVER['PHP_SELF']) : dirname($_SERVER['PHP_SELF']) . "/";
			$reportlink = $protocol . $_SERVER['HTTP_HOST'] . $directory . "respondentreport.php?sid=".$_SESSION['admin_sid'];

			$headers = "From: hide@address.com\r\n";
			$headers .= "MIME-Version: 1.0\r\n";
			//$headers .= "Content-Type: multipart/mixed; boundary=pentri12345\r\n";
			$headers .= "Content-Type: multipart/alternative; boundary=pentri12345\r\n";
			
			$message .= "--pentri12345\r\n";
			
			$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
			$message .= "Content-Transfer-Encoding: 7bit\r\n";
			$message .= "Dear AskPeople user,\r\n\r\nA new response to your survey \"{$loaded['meta']['title']}\" has been received.\r\n\r\nThe response is embedded in this HTML email, or can be viewed online at:\r\n<{$reportlink}>\r\n\r\nThanks again for using AskPeople.\r\n\r\nBest regards,\r\nThe AskPeople.co.uk Team\r\n";
			$message .= "--pentri12345\r\n";
			$message .= "Content-Type: text/html;\r\n";
			//$message .= "Content-Disposition: attachment; filename=\"$nicefilename\"\r\n";
			$message .= "Content-Transfer-Encoding: 7-bit\r\n";
			$message .= "<p>Dear AskPeople user,</p><p>A new response to your survey \"{$loaded['meta']['title']}\" is enclosed.</p><p>Thanks again for using AskPeople.</p><p>Best regards,<br />The AskPeople.co.uk Team</p>\r\n";			
			$message .= "\r\n" . $emailhtml . "\r\n";
			$message .= "--pentri12345--";
	
			$MailTo = $surveysettings['emailResults'];
			$MailSubject = "New response submitted: {$loaded['meta']['title']}";
	
			if (mail($MailTo,$MailSubject,$message,$headers)) {
				$emailed = "TRUE";
			}
		}
		
		if ($surveysettings['makeRSS'] == "TRUE") {
			$_REQUEST['file'] = "TRUE";
			include_once("rssreport.php");
		}

		if ($surveysettings['finalURL']) {
			header("Location:".$surveysettings['finalURL']);
		} else {
			$html .= "
			<div class='question'>
			  {$surveysettings['confirmationMessage']}
			</div>
			</form>	 
			</div>
			";
			if ($emailed == "TRUE") { $html .= "<!-- response sent by email -->"; }
			$html = str_replace("<!-- SURVEYFORM -->",$html,$template);
			echo ($html);		
		}
	}
  }
}


/*
	echo ("<!-- \n\n");
	//print_r($_REQUEST);	

	echo ("loaded:\n");
	//print_r($loaded);
	echo ("\nanswers_array:\n");
	//print_r($answers_array);	
	echo ("\nSESSION[submitted]:\n");
	//print_r($_SESSION['submitted']);
	echo ("\n\n -->");
*/

ob_end_flush();

?>
Return current item: AskPeople-Free PHP survey application