<?php
function sortTraits(&$score, &$desc) {
    $x = 0;
    while ($x < 10) {
        $y = $x + 1;
        while ($y < 16) {
            if ($score[$x] < $score[$y]) {
                $t1 = $score[$x];
                $t2 = $desc[$x];
                $score[$x] = $score[$y];
                $desc[$x] = $desc[$y];
                $score[$y] = $t1;
                $desc[$y] = $t2;
            }
            $y++;
        }
        $x++;
    }
}

function getMDesc($name, $osex) {
    $name = substr(strtolower($name), 0, 3);
    $ret  = '';
    switch ($name) {
    case 'wea':
        $ret = 'You know what your goals are and you pursue them vigourously.  Achieving success is important to you.';
        break;
    case 'rel':
        $ret = 'Faith matters to you.  It is the foundation that you build your life upon.  You trust that God has a plan for you.';
        break;
    case 'ath':
        $ret = 'Physical fitness is one of your priorities.  You find the time to work athletic pursuits into your schedule.  You enjoy being active.';
        break;
    case 'big':
        $ret = 'You are a kind and caring person.  Your warmth is inviting, and your heart is a wellspring of love.';
        break;
    case 'int':
        $ret = 'You consider your mind amongst your assets.  Learning is not a chore but a constant search after wisdom and knowledge.  You value education and rationality.';
        break;
    case 'fun':
        $ret = 'You laugh often.  People never accuse you of lacking a sense of humor.  You don\'t take yourself too seriously.';
        break;
    case 'out':
        $ret = 'You can liven up any party.  You\'ve got a way with people and have little difficulty charming your dates.';
        break;
    case 'adv':
        $ret = 'Just sitting around the house is not something that appeals to you.  You love to be out trying new things and really experiencing life.';
        break;
    case 'sty':
        $ret = 'You do not lack for fashion sense.  Style matters.  You wouldn\'t want to be seen with someone who doesn\'t care about ' . ($osex == 'm' ? 'his' : 'her') . ' appearance.';
        break;
    case 'shy':
        $ret = 'You are often timid around others, though you will open up when the right person comes along.';
        break;
    case 'tra':
        $ret = 'Modern culture does not move you. You hold traditional values dear to your heart.';
        break;
    case 'sen':
        $ret = 'You are not particularly shy when it comes to your sexuality.  You know what you like and do not feel inhibited.';
        break;
    case 'pra':
        $ret = 'You are a down-to-earth individual who is not impressed with material excess.  You care about the stuff of like that really matters.';
        break;
    case 'lib':
        $ret = 'Politics matters to you, and you aren\'t afraid to share your left-leaning views.  You would never be caught voting for a conservative candidate.';
        break;
    case 'con':
        $ret = 'You take a conservative stance on most issues and aren\'t shy about saying so.  Your political views are an important component of who you are.';
        break;
    case 'rom':
        $ret = 'You know exactly how to melt your date\'s heart.  Romance comes naturally to you and is an important component of any relationship you have.';
        break;
    }
    return $ret;
}

function getODesc($name, $osex) {
    $name = substr(strtolower($name), 0, 3);
    $ret  = '';
    switch ($name) {
    case 'wea':
        $ret = 'You seek someone with goals, someone to whom success is important.  You would like for this person to open up new experiences and opportunities for you.';
        break;
    case 'rel':
        $ret = 'You seek someone who is grounded in faith and who possesses religious values.  You believe that a religious person can enhance your life.';
        break;
    case 'ath':
        $ret = 'You aren\'t looking for a couch potato.  You seek someone who is active and who keeps ' . ($osex == 'm' ? 'his' : 'her') . ' body in top shape.';
        break;
    case 'big':
        $ret = 'You want someone compassionate, someone gentle and kind.  A loving, nurturing person will fill that hole in your life.';
        break;
    case 'int':
        $ret = 'You seek out intelligence.  Idle chit-chat is not what you are after.  You prefer your date who can stimulate your mind.';
        break;
    case 'fun':
        $ret = 'You consider a good sense of humor a major necessity in a date.  If ' . ($osex == 'm' ? 'his' : 'her') . ' jokes make you laugh, ' . ($osex == 'm' ? 'he' : 'she') . ' has won your heart.';
        break;
    case 'out':
        $ret = 'Shy and timid people are not who you are after.  You need someone with a vibrant personality to breathe life into a relationship.';
        break;
    case 'adv':
        $ret = 'You are looking for someone who is willing to try new things and experience life to its fullest.  You need a companion who encourages you to take risks and do exciting things.';
        break;
    case 'sty':
        $ret = 'You cannot put up with someone who is lacking in style.  You want an original, someone with flare, someone with good taste.';
        break;
    case 'shy':
        $ret = 'You are put off by people who are open books.  You are drawn to someone who is a bit more mysterious.  You want to draw ' . ($osex == 'm' ? 'him' : 'her') . ' out of ' . ($osex == 'm' ? 'his' : 'her') . ' shell and get to know what ' . ($osex == 'm' ? 'he' : 'she') . ' is all about.';
        break;
    case 'tra':
        $ret = 'You need someone who is a bit old-fashioned.  A person with traditional values and beliefs will perfectly compliment your lifestyle.';
        break;
    case 'sen':
        $ret = 'You aren\'t looking for someone who is sexually repressed.  You want someone who is adventurous under the covers.';
        break;
    case 'pra':
        $ret = 'You are drawn to people who are sensible and smart.  Flashy, materialistic people turn you off.  You appreciate the simpler side of living.';
        break;
    case 'lib':
        $ret = 'You need a person who has liberal opinions and beliefs.  You are engaged by political discussions and would find a liberal viewpoint refreshing in a date.';
        break;
    case 'con':
        $ret = 'Forget liberals, you need a conservative match.  Political discussions interest you, and a conservative will offer the viewpoint you need.';
        break;
    case 'rom':
        $ret = 'You need someone with a traditional understanding of romance.  A true romantic is a must-have in any potential date.';
        break;
    }
    return $ret;
}

require('../setClassPath.php');
require_once('ui/Component.php');
require_once('util/InputHelper.php');

$helper = InputHelper::getInstance();
$msex = $helper->fullySanitize($_POST['msex']);
$osex = $helper->fullySanitize($_POST['osex']);
$mage = $helper->fullySanitize($_POST['mage']);
if (($mage == '') OR (!is_numeric($mage))) $mage = 20;

if (($msex == '') OR ($osex == '')) {
    header("HTTP/1.1 302 Found");
    header("Location: /qquiz/quiz1.html");
    exit();
}
else {
    $mreligious     = 0;
    $mathletic      = 0;
    $mheart         = 0;
    $mmoney         = 0;
    $mintellect     = 0;
    $mfunny         = 0;
    $moutgoing      = 0;
    $madventure     = 0;
    $mstylish       = 0;
    $mshy           = 0;
    $mtradition     = 0;
    $msensual       = 0;
    $mpractical     = 0;
    $mliberal       = 0;
    $mconserve      = 0;
    $mromantic      = 0;
    $mpolitics      = 0;
    $oreligious     = 0;
    $oathletic      = 0;
    $oheart         = 0;
    $omoney         = 0;
    $ointellect     = 0;
    $ofunny         = 0;
    $ooutgoing      = 0;
    $oadventure     = 0;
    $ostylish       = 0;
    $oshy           = 0;
    $otradition     = 0;
    $osensual       = 0;
    $opractical     = 0;
    $oliberal       = 0;
    $oconserve      = 0;
    $oromantic      = 0;

    if ($msex == 'f') {
        $oheart++;
        $oromantic++;
    }
    else
        $osensual++;

    if ($mage > 29) {
        $ointellect++;
        if ($osex == 'm')
            $omoney++;
    }

    switch ($_POST['q1']) {
    case 'comedy':
        $mfunny++;
        $ofunny++;
        break;
    case 'drama':
        $mheart++;
        $oheart++;
        break;
    case 'action':
        $madventure++;
        break;
    case 'documentary':
        $mintellect++;
        $ointellect++;
    }

    switch ($_POST['q2']) {
    case 'yes':
        $mathletic = $mathletic + 2;
        $oathletic++;
        break;
    case 'nobut':
        $oathletic = $oathletic + 2;
        break;
    case 'no':
        $mathletic--;
        $oathletic = $oathletic - 2;
    }

    switch ($_POST['q3']) {
    case 'party':
        $moutgoing = $moutgoing + 2;
        $ooutgoing = $ooutgoing + 2;
        $oshy--;
        break;
    case 'work':
        $mmoney++;
        $omoney++;
        break;
    case 'book':
        $mintellect = $mintellect + 2;
        $ointellect++;
        break;
    case 'sweep':
        $mromantic = $mromantic + 2;
        $mtradition++;
        $mshy++;
        $omoney++;
        $oromantic++;
    }

    switch ($_POST['q4']) {
    case 'wantto':
        $omoney++;
        break;
    case 'spouse':
        $omoney = $omoney + 3;
        $opractical = $opractical - 2;
        break;
    case 'yes':
        $mmoney = $mmoney + 2;
        break;
    case 'dontneed':
        $mpractical = $mpractical + 2;
        $omoney--;
    }

    switch ($_POST['q5']) {
    case 'call':
        $mheart++;
        $oheart++;
        break;
    case 'nurse':
        $mheart = $mheart + 2;
        $oheart = $oheart + 2;
        break;
    case 'inside':
        $mheart = $mheart - 2;
        $oheart--;
    }

    switch ($_POST['q6']) {
    case 'yes':
        $mtradition = $mtradition + 2;
        $mconserve++;
        $oconserve++;
        $otradition = $otradition + 2;
        break;
    case 'no':
        $mtradition--;
        $otradition--;
    }

    switch ($_POST['q7']) {
    case 'yes':
        $mstylish = $mstylish + 2;
        $mpractical = $mpractical - 2;
        $ostylish++;
        $omoney++;
        break;
    case 'no':
        $mstylish = $mstylish - 2;
        $mpractical++;
        $ostylish = $ostylish - 2;
    }

    switch ($_POST['q8']) {
    case 'depends':
        $osensual++;
        break;
    case 'yes':
        $madventure++;
        $msensual = $msensual + 2;
        $osensual = $osensual + 2;
        break;
    case 'dependsshy':
        $msensual++;
        $osensual = $osensual + 2;
        break;
    case 'no':
        $mtradition++;
        $otradition = $otradition + 2;
        $madventure--;
        $msensual = $msensual - 2;
        $osensual--;
    }

    switch ($_POST['q9']) {
    case 'yes':
        $mreligious = $mreligious + 2;
        $oreligious++;
        break;
    case 'notas':
        $mreligious++;
        $oreligious = $oreligious + 2;
        break;
    case 'no':
        $mreligious = $mreligious - 2;
        $oreligious = $oreligious - 2;
    }

    switch ($_POST['q11']) {
    case 'show':
        $madventure++;
        $mpractical--;
        $mmoney--;
        $mromantic++;
        $oadventure = $oadventure + 2;
        $omoney++;
        $opractical = $opractical - 2;
        $ooutgoing++;
        break;
    case 'share':
        $madventure = $madventure + 2;
        $mpractical--;
        $mromantic++;
        $mmoney++;
        $oadventure = $oadventure + 2;
        $opractical--;
        break;
    case 'away':
        $madventure++;
        $omoney++;
        $oadventure++;
        break;
    case 'stay':
        $madventure = $madventure - 2;
        $mshy++;
        $oshy++;
        $oadventure--;
    }

    switch ($_POST['q12']) {
    case 'just':
        $mpractical++;
        $mmoney--;
        $opractical++;
        break;
    case 'latest':
        $mpractical--;
        $mmoney++;
        $opractical--;
        break;
    case 'afford':
        $mmoney = $mmoney - 2;
        $omoney = $omoney + 2;
    }

    switch ($_POST['q13']) {
    case 'relax':
        $mathletic = $mathletic - 2;
        $oathletic = $oathletic - 2;
        break;
    case 'both':
        $mathletic++;
        break;
    case 'active':
        $mathletic = $mathletic + 2;
        $madventure++;
        $oathletic = $oathletic + 2;
    }

    switch ($_POST['q14']) {
    case 'over':
        $mshy--;
        break;
    case 'terror':
        $mshy = $mshy + 2;
        break;
    case 'peers':
        $mmoney++;
        $mshy = $mshy - 2;
    }

    switch ($_POST['q15']) {
    case 'boring':
        $mintellect--;
        $ointellect--;
        break;
    case 'learn':
        $mintellect++;
        $ointellect = $ointellect + 2;
        break;
    case 'know':
        $mintellect = $mintellect + 2;
        $ointellect++;
    }

    switch ($_POST['q16']) {
    case 'attend':
        $mreligious = $mreligious + 2;
        $mtradition++;
        $oreligious = $oreligious + 2;
        $otradition++;
        break;
    case 'nonreligious':
        $mreligious = $mreligious - 2;
        $oreligious--;
        break;
    case 'nothing':
        $mtradition--;
        $mreligious--;
        $moutgoing--;
    }

    switch ($_POST['q17']) {
    case 'alone':
        $moutgoing--;
        $mshy++;
        $oheart++;
        break;
    case 'cost':
        $mromantic--;
        $mmoney--;
        $oromantic--;
        $omoney++;
        break;
    case 'love':
        $mromantic = $mromantic + 2;
        $oromantic = $oromantic + 2;
        $omoney++;
        break;
    case 'care':
        $mromantic = $mromantic - 2;
        $oromantic--;
        $opractical++;
        $ointellect++;
    }
    
    switch ($_POST['q18']) {
    case 'fire':
        $mromantic = $mromantic + 2;
        $mheart++;
        $oromantic = $oromantic + 2;
        break;
    case 'fly':
        $madventure++;
        $omoney++;
        $oadventure++;
        break;
    case 'ski':
        $mathletic = $mathletic + 2;
        $mmoney++;
        $mromantic--;
        $oathletic = $oathletic + 2;
    }

    switch ($_POST['q19']) {
    case 'not':
        $mtradition++;
        $mliberal--;
        $oliberal--;
        break;
    case 'beautiful':
        $mheart++;
        $mliberal++;
        break;
    case 'kids':
        $mpractical++;
    }

    switch ($_POST['q20']) {
    case 'unreal':
        $mconserve++;
        $mliberal--;
        $mheart--;
        $oconserve++;
        $oliberal--;
        break;
    case 'achievable':
        $mconserve--;
        $mliberal++;
        $oconserve--;
        $oliberal++;
        break;
    case 'history':
        $mpractical++;
        $mintellect++;
        $oliberal--;
    }

    switch ($_POST['q21']) {
    case 'man':
        $mconserve++;
        $mtradition = $mtradition + 2;
        if ($osex == 'm')
            $otradition = $otradition + 2;
        else
            $otradition++;
        $oromantic++;
        break;
    case 'split':
        $mtradition--;
        break;
    case 'woman':
        $mtradition = $mtradition - 2;
        $mliberal++;
        $otradition--;
    }

    switch ($_POST['q22']) {
    case 'love':
        $mromantic = $mromantic + 2;
        $mtradition++;
        $moutgoing--;
        $oromantic++;
        break;
    case 'settle':
        $mtradition--;
        $moutgoing++;
        $mconserve--;
        $otradition--;
        break;
    case 'comfort':
        $mpractical = $mpractical + 2;
        $mromantic--;
    }

    switch ($_POST['q23']) {
    case 'me':
        $moutgoing = $moutgoing + 2;
        if ($msex == 'm')
            $mshy--;
        else {
            $mshy = $mshy - 2;
            $mtradition--;
            $msensual++;
        }
        break;
    case 'you':
        $ooutgoing++;
        if ($msex == 'm') {
            $moutgoing--;
            $mshy = $mshy + 2;
        }
        else {
            $mshy++;
            $mtradition++;
        }
    }

    switch ($_POST['q24']) {
    case 'bores':
        $mpolitics = $mpolitics - 2;
        $mintellect--;
        $ointellect--;
        break;
    case 'passion':
        $mpolitics = $mpolitics + 2;
        $mintellect++;
        $ointellect++;
        break;
    case 'few':
        $mpolitics++;
    }

    switch ($_POST['q25']) {
    case 'dontfeel':
        $oreligious--;
        break;
    case 'oughtto':
        $oreligious++;
        break;
    case 'central':
        $mreligious = $mreligious + 2;
        $mconserve++;
        $oreligious = $oreligious + 2;
        break;
    case 'waste':
        $mreligious = $mreligious - 3;
        $mliberal++;
        $oreligious = $oreligious - 2;
    }

    switch ($_POST['q26']) {
    case 'comfort':
        $mpractical++;
        $mromantic--;
        $opractical++;
        break;
    case 'nothing':
        $mromantic++;
        $mstylish--;
        $omoney--;
        break;
    case 'pamper':
        $mpractical = $mpractical - 2;
        $mstylish++;
        $mmoney--;
        $omoney = $omoney + 2;
        $ostylish++;
        $opractical = $opractical - 2;
    }

    switch ($_POST['q27']) {
    case 'reward':
        $mpractical++;
        $mtradition = $mtradition + 2;
        $mheart++;
        $madventure--;
        $oadventure = $oadventure - 2;
        $otradition = $otradition + 2;
        break;
    case 'drag':
        $madventure++;
        $mreligious--;
        $oadventure++;
        $otradition--;
        $oconserve--;
        break;
    case 'challenge':
        $mtradition++;
    }

    switch ($_POST['q28']) {
    case 'laugh':
        $mfunny++;
        $mstylish--;
        $ostylish--;
        $ofunny = $ofunny + 2;
        break;
    case 'interests':
        $mstylish--;
        $ostylish--;
        break;
    case 'important':
        $mstylish++;
        $ointellect--;
        $oathletic++;
        $ostylish++;
        break;
    case 'dress':
        $mstylish = $mstylish + 2;
        $ostylish = $ostylish + 2;
    }

    switch ($_POST['q29']) {
    case 'interested':
        $madventure++;
        $oadventure = $oadventure + 2;
        $omoney++;
        break;
    case 'try':
        $madventure = $madventure + 2;
        $moutgoing++;
        $mtradition--;
        $oadventure++;
        break;
    case 'stick':
        $mtradition++;
        $madventure--;
        $oadventure--;
    }

    switch ($_POST['q30']) {
    case 'afford':
        $mmoney = $mmoney - 2;
        $madventure++;
        $omoney++;
        $oadventure++;
        break;
    case 'romantic':
        $mromantic = $mromantic + 2;
        $msensual++;
        $oromantic = $oromantic + 2;
        break;
    case 'fun':
        $madventure++;
        $oadventure++;
        $opractical--;
        break;
    case 'notravel':
        $mpractical++;
        $madventure = $madventure - 2;
        $oadventure--;
        break;
    case 'museums':
        $mintellect = $mintellect + 2;
        $ointellect++;
    }

    switch ($_POST['q31']) {
    case 'oppose':
        $mpolitics++;
        $mliberal++;
        break;
    case 'support':
        $mpolitics++;
        $mliberal--;
        break;
    case 'no':
        $mpolitics--;
        $mintellect--;
        $ointellect--;
    }

    switch ($_POST['q32']) {
    case 'help':
        $oheart++;
        break;
    case 'given':
        $mpolitics++;
        $mheart++;
        $oheart++;
        break;
    case 'own':
        $mheart--;
        $omoney++;
    }

    switch ($_POST['q33']) {
    case 'hate':
        $mconserve++;
        $mliberal--;
        $oliberal--;
        break;
    case 'vile':
        $mconserve--;
        $mliberal++;
        $oliberal++;
        break;
    case 'forces':
        $mintellect++;
        break;
    case 'god':
        $mreligious++;
    }

    switch ($_POST['q34']) {
    case 'funny':
        $mfunny++;
        $ofunny++;
        $mconserve--;
        break;
    case 'kids':
        $mconserve++;
        $mtradition++;
        $otradition++;
        break;
    case 'never':
        $mfunny--;
        $mintellect++;
        $ointellect++;
    }

    switch ($_POST['q35']) {
    case 'guidance':
        $mpractical++;
        $mtradition--;
        $mconserve--;
        break;
    case 'abstinence':
        $mtradition++;
        $mreligious++;
        $mconserve++;
        $msensual--;
        $otradition++;
        break;
    case 'explore':
        $mconserve--;
        $mtradition--;
        $msensual++;
        $otradition--;
        $oconserve--;
        break;
    case 'resist':
        $mtradition = $mtradition + 2;
        $mliberal--;
        $otradition++;
        $osensual++;
    }

    switch ($_POST['q36']) {
    case 'love':
        $mheart = $mheart + 2;
        $mromantic++;
        $mliberal++;
        break;
    case 'conform':
        $mliberal++;
        $madventure++;
        $mstylish++;
        $mtradition--;
        break;
    case 'values':
        $mreligious++;
        $mtradition++;
        $mconserve++;
        $msensual--;
        break;
    case 'means':
        $mpractical = $mpractical + 2;
        $mconserve++;
        break;
    case 'lazy':
        $mmoney++;
        $mconserve++;
        $mheart--;
    }

    switch ($_POST['q37']) {
    case 'success':
        $mmoney++;
        $omoney++;
        break;
    case 'love':
        $mromantic++;
        $mheart++;
        break;
    case 'vices':
        $mtradition++;
        $mreligious++;
        $otradition++;
        $osensual--;
    case 'change':
        $mpractical--;
        $mheart++;
        $mliberal++;
        $oliberal++;
        $oheart++;
        $omoney--;
    }

    switch ($_POST['q38']) {
    case 'manwoman':
        $mpolitics++;
        $mtradition = $mtradition + 2;
        $mconserve++;
        $oliberal--;
        break;
    case 'immoral':
        $mpolitics++;
        $mreligious = $mreligious + 2;
        $mconserve++;
        $oliberal--;
        $oreligious++;
        break;
    case 'love':
        $mliberal++;
        $mheart++;
        $mromantic++;
        $otradition--;
        break;
    case 'rights':
        $mpolitics++;
        $mliberal++;
        $oliberal++;
        $oconserve--;
    }

    switch ($_POST['q39']) {
    case 'laugh':
        $mfunny++;
        $otradition--;
        $ofunny = $ofunny + 2;
        break;
    case 'feelings':
        $mheart++;
        $oheart++;
        break;
    case 'finances':
        $omoney++;
        break;
    case 'roles':
        $mtradition = $mtradition + 2;
        $otradition = $otradition + 2;
        $oliberal--;
    }

    switch ($_POST['q40']) {
    case 'laughter':
        $mfunny++;
        $ofunny = $ofunny + 2;
        $ointellect--;
        break;
    case 'honesty':
        $mshy++;
        $oreligious++;
        $oheart++;
        break;
    case 'cuddle':
        $mromantic++;
        $oromantic = $oromantic + 2;
        $oheart++;
        break;
    case 'intellect':
        $mintellect++;
        $ointellect = $ointellect + 2;
        $oromantic--;
        $oheart--;
        break;
    case 'foreplay':
        $msensual++;
        $osensual = $osensual + 2;
        $otradition--;
        $oadventure++;
        break;
    case 'fashion':
        $mstylish++;
        $ostylish = $ostylish + 2;
        $omoney++;
        $opractical--;
    }

    switch ($_POST['q41']) {
    case 'assert':
        $omoney++;
        $ooutgoing = $ooutgoing + 2;
        $oshy = $oshy - 2;
        $oadventure++;
        $osensual++;
        break;
    case 'fit':
        $mathletic++;
        $oathletic = $oathletic + 2;
        break;
    case 'wealthy':
        $mstylish++;
        $omoney = $omoney + 2;
        $ostylish = $ostylish + 2;
        $opractical--;
        break;
    case 'modest':
        $opractical++;
        $omoney--;
        $ostylish--;
        break;
    case 'quiet':
        $oshy = $oshy + 2;
        $ooutgoing--;
    }

    switch ($_POST['q42']) {
    case 'appear':
        $ostylish++;
        break;
    case 'ambition':
        $omoney++;
        break;
    case 'meek':
        $oshy = $oshy - 2;
        $ooutgoing = $ooutgoing + 2;
        break;
    case 'intellect':
        $mintellect++;
        $ointellect = $ointellect + 2;
        break;
    case 'energy':
        $mathletic++;
        $madventure++;
        $oathletic++;
        $oadventure++;
    }

    switch ($_POST['q43']) {
    case 'humor':
        $oshy = $oshy + 2;
        $ofunny++;
        $ooutgoing--;
        break;
    case 'engaging':
        $oshy = $oshy - 2;
        $ointellect++;
        $ooutgoing = $ooutgoing + 2;
        break;
    case 'outgoing':
        $oshy--;
        $ofunny++;
        $ooutgoing++;
        break;
    case 'quiet':
        $oshy = $oshy + 2;
        $ointellect++;
        $ooutgoing--;
    }

    switch ($_POST['q44']) {
    case 'grounded':
        $opractical = $opractical + 2;
        $omoney--;
        $ostylish--;
        break;
    case 'wants':
        $omoney = $omoney + 2;
        break;
    case 'god':
        $oreligious = $oreligious + 2;
        $oconserve = $oconserve + 1;
        break;
    case 'experience':
        $ointellect = $ointellect + 2;
        break;
    case 'generous':
        $oheart = $oheart + 2;
        $opractical++;
    }

    switch ($_POST['q45']) {
    case 'bedroom':
        $oshy--;
        $osensual = $osensual + 2;
        $ooutgoing++;
        break;
    case 'causes':
        $mpolitics++;
        $ointellect++;
        break;
    case 'culture':
        $otradition++;
        $osensual--;
        break;
    case 'career':
        $omoney = $omoney + 2;
    }


    // <## Correction factors ##>
    
    if ($mtradition > 14)
        $oshy++;
    if ($mathletic > 2)
        $oathletic++;
    if ($mromantic > 8)
        $oromantic++;
    
    
    // <## GO BACK AND DO Q10 AT THE END! ALSO CHECK Q28, answer 2! ##>
    
    
    if ($_POST['q28'] == 'interests') {
        if ($mreligious > 7) $oreligious++;
        if ($mathletic > 3) $oathletic++;
        if ($mmoney > 6) $omoney++;
        if ($mintellect > 7) $ointellect = $ointellect + 2;
        if ($mfunny > 3) $ofunny++;
        if ($madventure > 7) $oadventure++;
        if ($mstylish > 4) $ostylish++;
        if ($mliberal > 3) $oliberal++;
        if ($mconserve > 3) $mconserve++;
    }
    
    if ($_POST['q10'] == 'yes') {
        if ($mmoney > 5) $omoney = $omoney - 2;
        if ($mreligious < 0) $oreligious = $oreligious + 2;
        if ($mathletic < 0) $oathletic++;
        if ($mintellect > 6) $ointellect = $ointellect - 2;
        if ($mintellect < 1) $ointellect = $ointellect + 2;
        if ($moutgoing > 4) {
            $oshy++;
            $ooutgoing--;
        }
        if ($mstylish > 4) $ostylish--;
        if ($mshy > 3) {
            $oshy--;
            $ooutgoing++;
        }
        if ($mtradition > 10) $otradition--;
        if ($mpractical > 6) $opractical = $opractical - 2;
        if ($mpractical < 0) $opractical = $opractical + 2;
        if ($mliberal > 3) {
            $oconserve = $oconserve + 2;
            $oliberal = $oliberal - 2;
        }
        if ($mconserve > 3) {
            $oconserve = $oconserve - 2;
            $oliberal = $oliberal + 2;
        }
    }
    else if ($_POST['q10'] == 'sometimes') {
        if ($mmoney > 5) $omoney--;
        if ($mreligious < 0) $oreligious++;
        if ($mathletic < 0) $oathletic++;
        if ($mintellect > 6) $ointellect--;
        if ($mintellect < 1) $ointellect++;
        if ($moutgoing > 4) $oshy++;
        if ($mstylish > 5) $ostylish--;
        if ($mshy > 3) $ooutgoing++;
        if ($mpractical > 6) $opractical--;
        if ($mpractical < 0) $opractical++;
        if ($mliberal > 3) {
            $oconserve++;
            $oliberal--;
        }
        if ($mconserve > 3) {
            $oconserve--;
            $oliberal++;
        }
    }

    if (($mpolitics > 2) AND (($_POST['q10'] == 'no') OR (($_POST['q10'] == 'sometimes') AND ($_POST['q28'] == 'interests')))) {
        if ($mliberal > 2) {
            $oconserve = $oconserve - 3;
            $oliberal++;
        }
        if ($mconserve > 2) {
            $oconserve++;
            $oliberal = $oliberal - 3;
        }
    }
    else if ($mpolitics < 0) {
        $oliberal--;
        $oconserve--;
    }
    

    $mpolitics = ($mpolitics + 3) * 100 / 9;
    $mreligious = ($mreligious + 8) * 100 / 20;
    $mathletic = ($mathletic + 3) * 100 / 11;
    $mheart = ($mheart + 5) * 100 / 17;
    $mmoney = ($mmoney + 9) * 100 / 19; // <## / +1 correction ##>
    $mintellect = ($mintellect + 4) * 100 / 16; // <## +1 correction ##>
    $mfunny = ($mfunny + 1) * 100 / 6;
    $moutgoing = ($moutgoing + 4) * 100 / 10;
    $madventure = ($madventure + 7) * 100 / 19;
    $mstylish = ($mstylish + 4) * 100 / 11;
    $mshy = ($mshy + 4) * 100 / 13;
    $mtradition = ($mtradition + 10) * 100 / 31; // <## +1 correction ##>
    $msensual = ($msensual + 4) * 100 / 10;
    $mpractical = ($mpractical + 7) * 100 / 21;
    $mliberal = ($mliberal + 5) * 100 / 13;
    $mconserve = ($mconserve + 5) * 100 / 14;
    $mromantic = ($mromantic + 6) * 100 / 21;

    $oreligious = ($oreligious + 5) * 100 / 15;
    $oathletic = ($oathletic + 4) * 100 / 14;
    $oheart = ($oheart + 2) * 100 / 13;
    $omoney = ($omoney + 7) * 100 / 29; // <## +2 correction ##>
    $ointellect = ($ointellect + 6) * 100 / 21; // <## +1 correction ##>
    $ofunny = ($ofunny + 1) * 100 / 9; // <## +1 correction ##>
    $ooutgoing = ($ooutgoing + 2) * 100 / 13;
    $oadventure = ($oadventure + 5) * 100 / 15;
    $ostylish = ($ostylish + 5) * 100 / 14;
    $oshy = ($oshy + 6) * 100 / 12; // <## / +1 correction ##>
    $otradition = ($otradition + 9) * 100 / 23;
    $osensual = ($osensual + 2) * 100 / 13; // <## / +1 correction ##>
    $opractical = ($opractical + 8) * 100 / 16; // <## -2 correction ##>
    $oliberal = ($oliberal + 5) * 100 / 9;
    $oconserve = ($oconserve + 4) * 100 / 8; // <## / +1 correction ##>
    $oromantic = ($oromantic + 2) * 100 / 14;

// <## ensure conservative and liberal don't end up in the same results ##>
    if ($mconserve > $mliberal)
        $mliberal = $mliberal - 150;
    else
        $mconserve = $mconserve - 150;
    if ($oconserve > oliberal)
        $oliberal = $oliberal - 150;
    else
        $oconserve = $oconserve - 150;

// <## ensure outgoing and shy don't end up in the same results ##>
    if ($moutgoing > $mshy)
        $mshy = $mshy - 150;
    else
        $moutgoing = $moutgoing - 150;
    if ($ooutgoing > $oshy)
        $oshy = $oshy - 150;
    else
        $ooutgoing = $ooutgoing - 150;

// <## do them all ##>

$md[] = 'Religious';
$m[] = $mreligious;
//echo 'Religious ' . $mreligious . '<br>';
$md[] = 'Athletic';
$m[] = $mathletic;
//echo 'Athletic ' . $mathletic . '<br>';
$md[] = 'Big-Hearted';
$m[] = $mheart;
//echo 'Big-Hearted ' . $mheart . '<br>';
$md[] = 'Wealthy/Ambitious';
$m[] = $mmoney;
//echo 'Wealthy/Ambitious ' . $mmoney . '<br>';
$md[] = 'Intellectual';
$m[] = $mintellect;
//echo 'Iintellectual ' . $mintellect . '<br>';
$md[] = 'Funny';
$m[] = $mfunny;
//echo 'Funny ' . $mfunny . '<br>';
$md[] = 'Outgoing';
$m[] = $moutgoing;
//echo 'Outoging ' . $moutgoing . '<br>';
$md[] = 'Adventurous';
$m[] = $madventure;
//echo 'Aventurous ' . $madventure . '<br>';
$md[] = 'Stylish';
$m[] = $mstylish;
//echo 'Sylihs ' . $mstylish . '<br>';
$md[] = 'Shy';
$m[] = $mshy;
//echo 'Shy ' . $mshy . '<br>';
$md[] = 'Traditional';
$m[] = $mtradition;
//echo 'Traditional ' . $mtradition . '<br>';
$md[] = 'Sensual';
$m[] = $msensual;
//echo 'Sensual ' . $msensual . '<br>';
$md[] = 'Practical';
$m[] = $mpractical;
//echo 'practical ' . $mpractical . '<br>';
$md[] = 'Liberal';
$m[] = $mliberal;
//echo 'Liberal ' . $mliberal . '<br>';
$md[] = 'Conservative';
$m[] = $mconserve;
//echo 'Conservtative ' . $mconserve . '<br>';
$md[] = 'Romantic';
$m[] = $mromantic;
//echo 'Romantic ' . $mromantic . '<br><br>';
$od[] = 'Religious';
$o[] = $oreligious;
//echo 'Religious ' . $oreligious . '<br>';
$od[] = 'Athletic';
$o[] = $oathletic;
//echo 'Athletic ' . $oathletic . '<br>';
$od[] = 'Big-Hearted';
$o[] = $oheart;
//echo 'Big-Hearted ' . $oheart . '<br>';
$od[] = 'Wealthy/Ambitious';
$o[] = $omoney;
//echo 'Wealthy/Ambitious ' . $omoney . '<br>';
$od[] = 'Intellectual';
$o[] = $ointellect;
//echo 'Intellecutal ' . $ointellect . '<br>';
$od[] = 'Funny';
$o[] = $ofunny;
//echo 'Funny ' . $ofunny . '<br>';
$od[] = 'Outgoing';
$o[] = $ooutgoing;
//echo 'Outoging ' . $ooutgoing . '<br>';
$od[] = 'Adventurous';
$o[] = $oadventure;
//echo 'Adventurous ' . $oadventure . '<br>';
$od[] = 'Stylish';
$o[] = $ostylish;
//echo 'Stylish ' . $ostylish . '<br>';
$od[] = 'Shy';
$o[] = $oshy;
//echo 'Shy ' . $oshy . '<br>';
$od[] = 'Traditional';
$o[] = $otradition;
//echo 'Traditional ' . $otradition . '<br>';
$od[] = 'Sensual';
$o[] = $osensual;
//echo 'Sensual ' . $osensual . '<br>';
$od[] = 'Practical';
$o[] = $opractical;
//echo 'Practical ' . $opractical . '<br>';
$od[] = 'Liberal';
$o[] = $oliberal;
//echo 'Liberal ' . $oliberal . '<br>';
$od[] = 'Conservative';
$o[] = $oconserve;
//echo 'Conservtaive ' . $oconserve . '<br>';
$od[] = 'Romantic';
$o[] = $oromantic;
//echo 'Romantic ' . $oromantic . '<br>';

// check to see if we need to update the cookie!
/*commented on WIDY
if (($msex != $osex) AND ($mreligious > 65)) {
    $cookieval = $_COOKIE['mystic'];
    if (strlen($cookieval) == 6)
        setcookie("mystic", $cookieval . '-r', time() + 94608000);
    else if (strlen($cookieval) == 8)
        setcookie("mystic", substr($cookieval, 0, 6) . '-r', time() + 94608000);
}
*/

/*
<MvCOMMENT>
mreligious:  &[mreligious];<br>
mathletic: &[mathletic];<br>  
mheart: &[mheart];<br>     
mmoney: &[mmoney];<br>     
mintellect: &[mintellect];<br> 
mfunny: &[mfunny];<br>
moutgoing: &[moutgoing];<br>  
madventure: &[madventure];<br> 
mstylish: &[mstylish];<br>   
mshy: &[mshy];<br>       
mtradition: &[mtradition];<br> 
msensual: &[msensual];<br>   
mpractical: &[mpractical];<br> 
mliberal: &[mliberal];<br>   
mconserve: &[mconserve];<br>  
mromantic: &[mromantic];<br>  
mpolitics: &[mpolitics];<br>  
oreligious: &[oreligious];<br> 
oathletic: &[oathletic];<br>  
oheart: &[oheart];<br>     
omoney: &[omoney];<br>
ointellect: &[ointellect];<br> 
ofunny: &[ofunny];<br>     
ooutgoing: &[ooutgoing];<br>  
oadventure: &[oadventure];<br> 
ostylish: &[ostylish];<br>   
oshy: &[oshy];<br>       
otradition: &[otradition];<br> 
osensual: &[osensual];<br>   
opractical: &[opractical];<br> 
oliberal: &[oliberal];<br>   
oconserve: &[oconserve];<br>  
oromantic: &[oromantic];<br>  
</MvCOMMENT>
*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Dating Profile Quiz, Your Results</title>
<link type="text/css" rel="stylesheet" href="/css/main.css">
<link type="text/css" rel="stylesheet" href="/css/quiz.css">
<style type="text/css">
td { padding: 5px; vertical-align: top; }
#profa { background: #e3f0d4 url(../i/bg1_530w_t.gif) no-repeat 0 0; padding: 7px 0 0 0; width: 530px; }
#profb { background: #e3f0d4 url(../i/bg1_530w_b.gif) no-repeat bottom left; padding: 0 7px 7px 7px; font-size: 0.8em; line-height: 1.3em; }
#matcha { background: #bcd8ee url(../i/bg2_530w_t.gif) no-repeat 0 0; padding: 7px 0 0 0; width: 530px; }
#matchb { background: #bcd8ee url(../i/bg2_530w_b.gif) no-repeat bottom left; padding: 0 7px 7px 7px; font-size: 0.8em; line-height: 1.3em; }
#top10a { background: #e3f0d4 url(../i/bg1_190w_t.gif) no-repeat 0 0; padding: 7px 0 0 0; width: 190px; }
#top10b { background: #e3f0d4 url(../i/bg1_190w_b.gif) no-repeat bottom left; padding: 0 7px 7px 7px; font-size: 0.8em; line-height: 1.3em; }
#match10a { background: #bcd8ee url(../i/bg2_190w_t.gif) no-repeat 0 0; padding: 7px 0 0 0; width: 190px; }
#match10b { background: #bcd8ee url(../i/bg2_190w_b.gif) no-repeat bottom left; padding: 0 7px 7px 7px; font-size: 0.8em; line-height: 1.3em; }
.memdisp { width: 120px; padding: 5px; font-size: 12px; text-align: center; vertical-align: top; }
.memdisp img { border: 1px solid #000; }
#datead { text-align: center; font-size: 12px; margin: 0 0 12px 0; color: #666; }
</style>
</head>
<body>
<div id="body">
<div id="widetop">
<h1>Dating Profile Quiz, Your Results</h1>

<p class="lg"><b>Below are your results for this quiz.</b> On top in green are <i>your</i> top dating personality traits. 
Below in blue are the top dating personality traits for a potential date to match best with you.</p>
</div>

<div id="datead">- Scroll to bottom for info on our free dating site! -</div>

<?php
     sortTraits($m, $md);
     sortTraits($o, $od);
     $mtraits = '<b>' . $md[0] . '</b> - ' . getMDesc($md[0], $osex) . '<br><b>' . $md[1] . '</b> - ' . getMDesc($md[1], $osex) . '<br><b>' . $md[2] . '</b> - ' . getMDesc($md[2], $osex);
     $otraits = '<b>' . $od[0] . '</b> - ' . getODesc($od[0], $osex) . '<br><b>' . $od[1] . '</b> - ' . getODesc($od[1], $osex) . '<br><b>' . $od[2] . '</b> - ' . getODesc($od[2], $osex);

     $mten = '';
     $c = 1;
     while ($c < 11) {
         if ($c < 4)
             $mten .= '<b>' . $c . '. ' . $md[$c-1] . '</b><br>';
         else
             $mten .= $c . '. ' . $md[$c-1] . '<br>';
         $c++;
     }

     $oten = '';
     $c = 1;
     while ($c < 11) {
         if ($c < 4)
             $oten .= '<b>' . $c . '. ' . $od[$c-1] . '</b><br>';
         else
             $oten .= $c . '. ' . $od[$c-1] . '<br>';
         $c++;
     }

     $match = '';
     if ($mage > 29) {
         if ($osex == 'f')
             $match = 'Woman';
         else
             $match = 'Man';
     }
     else {
         if ($osex == 'f')
             $match = 'Girl';
         else
             $match = 'Guy';
     }
?>

<table cellspacing="0" style="margin-left: 10px;">
<tr><td width="520">
<h2>Your dating personality profile:</h2>
<div id="profa"><div id="profb">
<b>You matched the following traits:</b><br><br>
<?= $mtraits ?>
</div></div>
</td><td>
<div class="box1" style="width: 260px;">
<h2>Your Top Ten Traits:</h2>
<div id="top10a">
<div id="top10b">
<?= $mten ?>
</div></div></div>
</td></tr>

<tr><td width="520">
<h2>Your date match profile:</h2>
<div id="matcha"><div id="matchb">
<b>You match with <?= ($osex == 'm' ? 'men' : 'women') ?> who have following traits:</b><br><br>
<?= $otraits ?>
</div></div>
</td><td>
<div class="box2" style="width: 260px;">
<h2>Your Top Ten Match Traits:</h2>
<div id="match10a">
<div id="match10b">
<?= $oten ?>
</div></div></div>
</td></tr>
</table>

<br>

<h2>Copy and Paste the HTML Code Below to your Blog, Online Journal, or Message Board:</h2>
<table style="margin: 0 0 15px 40px;">
  <tr>
    <td style="width: 300px; padding: 5px 20px 10px 5px;">
      <h3>Code for full results:</h3>
<textarea style="width: 300px; height: 100px;" onclick="this.focus();this.select();">
<table cellspacing="1" style="background-color: #444;"><tr valign="top"><td style="width: 400px; background-color: #e3f0d4; padding: 5px;"><b><u>Your dating personality profile:</u></b><br><br><?= $mtraits ?></td><td style="width: 190px; background-color: #e3f0d4; padding: 5px;"><b><u>Your Top Ten Traits</u></b><br><br><?= $mten ?></td></tr><tr valign="top"><td style="width: 400px; background-color: #bcd8ee; padding: 5px;"><b><u>Your date match profile:</u></b><br><br><?= $otraits ?></td><td style="width: 190px; background-color: #bcd8ee; padding: 5px;"><b><u>Your Top Ten Match Traits</u></b><br><br><?= $oten ?></td></tr></table><br>Take the <a href="http://www.wouldidateyou.com/pquiz/quiz1.html">Dating Profile Quiz</a> at <a href="http://www.wouldidateyou.com/">Would I Date You</a>
</textarea>
    <br>
    <img src="/i/fbshare.gif" alt="facebook" style="vertical-align: middle;"> <a href="http://www.facebook.com/sharer.php" onclick="window.open('http://www.facebook.com/sharer.php?u=http://www.wouldidateyou.com/pquiz/quiz1.html&t=Take+the+Dating+Profile+Quiz', 'facebook','toolbar=no,width=700,height=400'); return false;">Share This Quiz On Facebook</a>
    </td>
    <td style="width: 300px; padding: 5px; 5px 10px 20px;">
      <h3>Code for just the top 10s:</h3>
<?php
$restext = '<div style="border: 1px solid #444; width: 200px; padding: 5px; background-color: #e3f0d4;"><b><u>Your Top Ten Traits</u></b><br><br>'. $mten .'</div><div style="border: 1px solid #444; width: 200px; padding: 5px; background-color: #bcd8ee;"><b><u>Your Top Ten Match Traits</u></b><br><br>'. $oten .'</div><br>Take the <a href="http://www.wouldidateyou.com/pquiz/quiz1.html">Dating Profile Quiz</a> at <a href="http://www.wouldidateyou.com/">Would I Date You</a>';
?>
<textarea style="width: 300px; height: 100px;" onclick="this.focus();this.select();">
<?= $restext ?>
</textarea>
    <br>
    <form id="myspacepostto" method="post" action="http://www.myspace.com/index.cfm?fuseaction=postto" target="_blank" style="margin: 0; padding: 0;">
        <input type="hidden" name="t" value="Dating Profile Quiz" />
        <input type="hidden" name="c" value="<?= str_replace('"', '&quot;', $restext) ?>" />
        <input type="hidden" name="u" value="http://www.wouldidateyou.com/pquiz/quiz1.html" />
        <input type="hidden" name="l" value="3" />
        <img src="/i/myspace_16.gif" alt="myspace" style="vertical-align: middle;"> 
        <a href="#" onclick="document.getElementById('myspacepostto').submit();return false;">Post to MySpace</a>
      </form>
    </td>
  </tr>
</table>


<?php
    if ($mage > 17 && !isset($_SESSION['user'])) {
?>
<h2><a href="/account/join1.html">Join Our Free Dating Site</a></h2>
<h3>Meet some of our new members:</h3>
<table>
  <tr>
<?php
       if ($osex == 'f') {
?>
    <td class="memdisp">Tiffany0564<br><img src="/pic/080414/206/dba.jpg" alt="Member Tiffany0564"><br>18f, Middlesboro, KY</td>
    <td class="memdisp">Sunshine<br><img src="/pic/080405/90/84b.jpg" alt="Member Sunshine"><br>28f, Franklinton, NC</td>
    <td class="memdisp">Ashy Poo<br><img src="/pic/080402/64/e31.jpg" alt="Member Ashy Poo"><br>18f, Hawthorne, FL</td>
    <td class="memdisp">Jean<br><img src="/pic/080402/63/e5d.jpg" alt="Member Jean"><br>23f, Phoenix, AZ</td>
    <td class="memdisp">coco jnell<br><img src="/pic/080331/39/d4f.jpg" alt="Member coco jnell"><br>35f, Torrance, CA</td>
    <td class="memdisp">Sexymama<br><img src="/pic/080331/37/3f6.jpg" alt="Member Sexymama"><br>20f, Raleigh, NC</td>
<?php
       }
       else {
?>
    <td class="memdisp">19NyFL82<br><img src="/pic/080414/203/c88.jpg" alt="Member 19NyFL82"><br>25m, Spring Hill, FL</td>
    <td class="memdisp">stevieandstevie<br><img src="/pic/080408/120/cc5.jpg" alt="Member stevieandstevie"><br>20m, San Antonio, TX</td>
    <td class="memdisp">Snipehunter<br><img src="/pic/080403/67/23f.jpg" alt="Member Snipehunter"><br>22m, Portland, OR</td>
    <td class="memdisp">usaf86<br><img src="/pic/080329/16/708.jpg" alt="Member usaf86"><br>22m, Killeen, TX</td>
    <td class="memdisp">FrogJon<br><img src="/pic/080415/208/309.jpg" alt="Member FrogJon"><br>18m, Rockford, IL</td>
    <td class="memdisp">Gabo<br><img src="/pic/080413/187/cf2.jpg" alt="Member Reading, PR"><br>22m, Reading, PR</td>
<?php
       }
?>
  </tr>
</table>
<p><b><a href="/">Would I Date You</a> is a free dating site</b> where you can create your own compatability quiz and meet other singles from your area.  <a href="/account/join1.html">Create an account now</a> and get started!</p>
<?
    }

    require_once('db/TransManager.php');
    require_once('db/QuizDB.php');
    require_once('object/User.php');
    require_once('object/Picture.php');

    try {
        $trans = TransManager::getInstance();
        $quizdb = new QuizDB();
        $trans->beginTrans();

        $usersWithQuiz = $quizdb->getUsersWithQuizzes(6, $trans->getPDO(), TRUE, ($osex == 'f' ? 'F' : 'M'));

        $trans->commit();
        $trans->disconnect();
    }
    catch (Exception $e) {
        echo "\n<!-- $e -->\n";
        if ($trans)
            $trans->handleException();
    }

    if ($usersWithQuiz) {
        echo '<h3>These Members Have Recently Created Quizzes:</h3><table><tr>';
        for ($i = 0, $n = count($usersWithQuiz); $i < $n; ++$i) {
            $usr = $usersWithQuiz[$i];
            $pic = $usr->getPicture();
            echo '<td class="memdisp"><img src="/pic/'. $pic->getDirName() . $pic->getThumbName() .'" alt="Member '. $usr->getName() .'"><br><a href="/quiz/'. $usr->getQuizKey() .'.html">'. $usr->getName() .'\'s Quiz</a></td>';
        }
        echo '</tr></table><p>Feel free to take their quizzes. You don\'t have to be a member here to do so!</p>';
    }
?>
<b>Did you remember to post your dating quiz results to your blog or web site? :)</b><br>

<?php
$ui = Component::getInstance();
$ui->drawHeader($_SESSION['user']);
$ui->drawFooter();
?>
</div>
</body></html>
<?php
}
?>
