[php mode=”old” debug=”0″]

// Config:
$cat = array(1 => ‘Bacon’, 2 => ‘Greek Yogurt’, 3 => ‘Tortilla Chips’);
$preference = array(1 => ‘Agree completely’, 2 => ‘Agree strongly’, 3 => ‘Agree somewhat’, 4 => ‘Disagree somewhat’, 5 => ‘Disagree strongly’, 6 => ‘Disagree completely’);

function doLogic($cat) {
$prefs = 0;
$vol = 0;
if (@$_POST[‘preference1’] < 3) $prefs++; if (@$_POST['preference2'] < 3) $prefs++; if (@$_POST['preference3'] < 3) $prefs++; switch(@$_POST['category']) { case '1' : // bacon if (floor(@$_POST['volume_hal']) > 3)
$vol = 1;
break;
case ‘2’ : // greek yogurt
if (floor(@$_POST[‘volume_hal’]) > 1)
$vol = 1;
break;
case ‘3’ : // tortilla chips
if (@$_POST[‘volume_hal’] >= 2.5)
$vol = 1;
break;
default :
break;
//return $prefs + $vol;
}
$sc = ‘n’;
if ($prefs > 1 && $vol > 0)
$sc = ‘y’;
// $redirect = ‘hello’;
$redir = “n”;
echo $redir;
}

$startOver = null;
$leader = null;

if (@$_POST[‘category’])
$leader = ‘[h3 class=”section-title section-lined”]Category: [span style=”color:grey;font-size:smaller”]’ . $cat[$_POST[‘category’]] . ‘[/span][br]’;
if (@$_POST[‘volume_hal’])
$leader .= ‘Amount per month: [span style=”color:grey;font-size:smaller”]$’ . round($_POST[‘volume_hal’], 2) . ‘[/span]’;
if (@$_POST[‘category’] || @$_POST[‘volume_hal’])
$leader .= ‘[/h3]’;

// Build survey:

if ($_SERVER[‘REQUEST_METHOD’] == ‘GET’ || @$_POST[‘category’] == 0) {
$mainCat = ‘[h3 class=”section-title section-lined”]Are you a Super Consumer? Let’s find out! Please select the category of interest from the drop-down menu below.[/h3]’;
$mainCat .= ‘

‘;
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’ && @$_POST[‘category’] == 0)
$mainCat .= ‘

Please make a valid choice.

‘;
$mainCat .= ‘

‘;
echo $mainCat;
}
else { // Past first screen
$startOver = ‘

‘;
if ((! @$_POST[‘second_screen’] || ! @$_POST[‘volume_hal’] || floor($_POST[‘volume_hal’]) < 1) && ! @$_POST['third']) { // Second screen $secondScreen = '

‘;
if (@$_POST[‘second_screen’] && (! @$_POST[‘volume_hal’] || floor($_POST[‘volume_hal’]) < 1 || is_nan(@$_POST['volume_hal']))) $secondScreen .= '[p class="errorText"]Please enter a numerical amount more than zero.[/p]'; $secondScreen .= '‘;
$secondScreen .= ‘‘;
$secondScreen .= ‘[h3 class=”section-title section-lined”]Amount spent per month on ‘ . strtolower($cat[$_POST[‘category’]]) . ‘: $ [/h3]

‘;
echo $leader . $secondScreen . $startOver;
}

else { // Third screen:

if (@$_POST[‘third’] && @$_POST[‘preference1’]) {
doLogic($cat[$_POST[‘category’]]);
}

else {
$thirdScreen = ‘[h3 class=”section-title section-lined”]Next we’d like to know your responses to three key questions. Please select the option that best applies to how much you agree or disagree with each statement.[/h3]’;
$thirdScreen .= ‘

‘;
$thirdScreen .= ‘‘;
$thirdScreen .= ‘‘;
$thirdScreen .= ‘‘;

if (@$_POST[‘third’] && ! @$_POST[‘preference1’])
$thirdScreen .= ‘[p class=”errorText”]Please choose an answer to this question.[/p]’;
$thirdScreen .= ‘[p][b]I love ‘ . strtolower($cat[$_POST[‘category’]]) . ‘.[/b][/p]’;
foreach ($preference as $prefVal => $prefName)
$thirdScreen .= ‘‘ . $prefName . ‘[br]’;

if (@$_POST[‘third’] && ! @$_POST[‘preference2’])
$thirdScreen .= ‘[p class=”errorText”]Please choose an answer to this question.[/p]’;
$thirdScreen .= ‘[p][b]I’m always looking for new products in ‘ . strtolower($cat[$_POST[‘category’]]) . ‘.[/b][/p]’;
foreach ($preference as $prefVal => $prefName)
$thirdScreen .= ‘‘ . $prefName . ‘[br]’;

if (@$_POST[‘third’] && ! @$_POST[‘preference3’])
$thirdScreen .= ‘[p class=”errorText”]Please choose an answer to this question.[/p]’;
$thirdScreen .= ‘[p][b]I talk a lot about ‘ . strtolower($cat[$_POST[‘category’]]) . ‘ with my friends on social media.[/b][/p]’;
foreach ($preference as $prefVal => $prefName)
$thirdScreen .= ‘‘ . $prefName . ‘[br]’;

$thirdScreen .= ‘

‘;
echo $leader . $thirdScreen . $startOver;
}
}
}

[/php]