<?php
$page_name = "Cult Calculator - Beta";
$menu_type = "bad math";
$menu_name = "Cult Calculator";
$blog_num = 37;
$page_rate = 10;
$page_tags = array();
$page_date = "October 10, 2011";
include_once("./files/head.php");

echo "<p>Are you part of a cult? Let's find out.  It's long (started with well over 200 questions, so don't complain), there are non-sequesters, tangents, and other *strange* questions just to blur things.</p>\n";
echo "<p>It's all weighted into catagories, so answer everything.  After your done, you can check out how I came up with this page. <a href=\"./cult_calculator_2.php" . $admin_link . "\">(HERE)</a></p>\n";


$part = $_POST['part'];

$score_total = 0;
foreach($questions as $num => $answer) {
  $checked[] = $_POST['' . $num . ''];
  if ($checked[$num] == "yes") {
    $score[] = $answer[1] * $answer[2];
  } else {
    $score[] = ($answer[1] == 1) ? 0 : $answer[2];
  }
  $score_total += $score[$num];
}

//print_r($score);

/*
religious, commercial, political
*/

echo "<form enctype=\"multipart/form-data\" id=\"cult_calc\" action=\"./cult_calculator.php" . $admin_link . "#results\" method=\"POST\">\n";
echo "<input type=\"hidden\" name=\"part\" id=\"part\" value=\"1\" />";
echo "<h3>Cult Calculator</h3>\n";
echo "<table>\n";
  echo "<tr>\n";
    echo "<th>Question</th>\n";
    echo "<th>Yes</th>\n";
    echo "<th>No</th>\n";
  echo "</tr>\n";

foreach($questions as $num => $quest) {
  echo "<tr>\n";
    echo "<td>" . ($num+1) . ": " . $quest[0] . "</td>\n";
    echo "<td><input type=\"radio\" name=\"" . $num . "\" id=\"" . $num . "\" value=\"yes\" ";
	echo ($checked[$num] == "yes") ? "checked" : null;
	echo "/></td>\n";
    echo "<td><input type=\"radio\" name=\"" . $num . "\" id=\"" . $num . "\" value=\"no\" ";
	echo ($checked[$num] == "yes") ? null : "checked";

    echo "/></td>\n";
  echo "</tr>\n";
  if (($num+1) % 10 == 0) {
    echo "<tr>\n";
      echo "<td colspan=3>&nbsp;</td>\n";
    echo "</tr>\n";
  }
}
echo "</table>\n";
echo "<br />\n";
echo "<input type=\"submit\" value=\"Submit\" />\n";
echo "</form>\n";





if ($part == 1) {
echo "<style type=\"text/css\">\n";
  echo "#cult_level_1 {\n  background-color: #00FF00;\n color: #000000;\n}\n";
  echo "#cult_level_2 {\n  background-color: #66FF99;\n color: #000000;\n}\n";
  echo "#cult_level_3 {\n  background-color: #00CCCC;\n color: #000000;\n}\n";
  echo "#cult_level_4 {\n  background-color: #3399FF;\n color: #000000;\n}\n";
  echo "#cult_level_5 {\n  background-color: #FFFF00;\n color: #000000;\n}\n";
  echo "#cult_level_6 {\n  background-color: #FF9933;\n color: #000000;\n}\n";
  echo "#cult_level_7 {\n  background-color: #FF6600;\n color: #000000;\n}\n";
  echo "#cult_level_8 {\n  background-color: #FF0000;\n color: #FFFFFF;\n}\n";
  echo "#cult_level_9 {\n  background-color: #CC0000;\n color: #FFFFFF;\n}\n";
  echo "#cult_level_10 {\n  background-color: #660000;\n color: #FFFFFF;\n}\n";
echo "</style>\n";

foreach($questions as $value) {
  $areas["leadership"] += $value[3] * $value[2];
  $areas["methods"] += $value[4] * $value[2];
  $areas["tolerance"] += $value[5] * $value[2];
  $areas["belief"] += $value[6] * $value[2];
  $areas["control"] += $value[7] * $value[2];
  $score_max += $value[2];
}

$score_level = ceil($score_total / $score_max * $levels_size);
$score_max_weight = array_sum($areas_weight) * $levels_size;

$i = 3;
foreach ($areas as $name => $max) {
  $temp_score = $name . "_score";
  $$temp_score = 0;
  foreach($questions as $num => $value) { $$temp_score += $score[$num] * $value[$i]; }
  $temp_level = $name . "_level";
  $$temp_level = ceil($$temp_score / $max * $levels_size);
  $temp_weight = $name . "_weight";
  $$temp_weight = $areas_weight[$name] * $$temp_level;
  $i++;
  $score_weight += $$temp_weight;
}
$score_weight_level = ceil($score_weight / $score_max_weight * $levels_size);

echo "<h3 id=\"results\">Results</h3>\n";
echo "<p>" . $results[$score_weight_level] . "\n";
echo "<br /><br />On a scale of 1 to " . $levels_size . " your group scored a " . $score_weight_level . ".</p>\n";
echo "<table id=\"cult\">\n";
  echo "<tr>\n";
  for ($i=1; $i<=10; $i++) {
    echo "<td id=\"cult_level_" . $i . "\">&nbsp;&nbsp;";
	echo ($score_weight_level == $i) ? "\/" : "&nbsp;";
	echo "&nbsp;&nbsp;<br />&nbsp;&nbsp;" . $i . "&nbsp;&nbsp;</td>";
  }
  echo "</tr>\n";
echo "</table>\n";
echo "<p>1 is not a cult at all, " . $levels_size . " means run as fast and far as you can from this group, it screams cult!</p>\n";

echo "<table id=\"cult\">\n";
  echo "<tr>\n";
    echo "<th>Group Quality</th>\n";
    echo "<th>Score</th>\n";
    echo "<th>Explaination</th>\n";
  echo "</tr>\n";
foreach ($areas as $name => $max) {
  $temp_score = $name . "_score";
  $temp_level = $name . "_level";
  echo "<tr>\n";
    echo "<td>" . ucfirst($name) . "</td><td id=\"cult_level_" . $$temp_level . "\">" . $levels[$$temp_level - 1] . "</td>\n";
	echo "<td>" . $definitions[$name] . "</td>\n";
  echo "</tr>\n";
}
echo "</table>\n";

echo "<p>See how it was made: <a href=\"./cult_calculator_2.php\">cult_calculator_2.php</a></p>\n";
}
echo "<center><img src=\"./images/bad_math/cults_05.jpg\" width=351 height=400 class=\"no_print\"></center>\n";

unset($levels, $areas, $areas_weight, $results, $definitions, $questions);

include_once("./files/close.php");
?>