<?php
// enneagram_type_game.php
// July, 2023
// RJM Programming
// Using experimental_drag_and_drop.htm for Enneagram Celebrities


 $scorebit='';
 if (isset($_GET['score']) && isset($_GET['secs'])) {
   $scorebit="Score " . $_GET['score'] . '/' . $_GET['secs'];
 }
 
 // Thanks to https://www.enneagraminstitute.com/type-descriptions and https://www.psychologyjunkie.com/enneagram-famous-people/
 $typedescstuff="1 THE REFORMER
The Rational, Idealistic Type: Principled, Purposeful, Self-Controlled, and Perfectionistic
Katharine Hepburn#//upload.wikimedia.org/wikipedia/commons/thumb/0/08/Katharine_Hepburn_promo_pic.jpg/220px-Katharine_Hepburn_promo_pic.jpg,Jane Fonda#//upload.wikimedia.org/wikipedia/commons/thumb/4/46/Jane_Fonda_Cannes_2015.jpg/220px-Jane_Fonda_Cannes_2015.jpg,Vanessa Redgrave#//upload.wikimedia.org/wikipedia/commons/thumb/2/26/Vanessa_Redgrave_Cannes_2016.jpg/220px-Vanessa_Redgrave_Cannes_2016.jpg,Julie Andrews#//upload.wikimedia.org/wikipedia/commons/thumb/8/89/Julie_Andrews_Park_Hyatt%2C_Sydney%2C_Australia_2013.jpg/220px-Julie_Andrews_Park_Hyatt%2C_Sydney%2C_Australia_2013.jpg,Emma Watson#//upload.wikimedia.org/wikipedia/commons/thumb/7/7f/Emma_Watson_2013.jpg/220px-Emma_Watson_2013.jpg,Natalie Portman#//upload.wikimedia.org/wikipedia/commons/thumb/d/d3/Natalie_Portman_%2848470988352%29_%28cropped%29.jpg/220px-Natalie_Portman_%2848470988352%29_%28cropped%29.jpg

2 THE HELPER
The Caring, Interpersonal Type: Demonstrative, Generous, People-Pleasing, and Possessive
Debbie Reynolds#//upload.wikimedia.org/wikipedia/commons/thumb/0/0f/Debbie_Reynolds_6_Allan_Warren.jpg/220px-Debbie_Reynolds_6_Allan_Warren.jpg,Doris Day#//upload.wikimedia.org/wikipedia/commons/thumb/3/30/Doris_Day_-_1957.JPG/220px-Doris_Day_-_1957.JPG,Dolly Parton#//upload.wikimedia.org/wikipedia/commons/thumb/d/d8/Dolly_Parton_accepting_Liseberg_Applause_Award_2010_portrait.jpg/220px-Dolly_Parton_accepting_Liseberg_Applause_Award_2010_portrait.jpg,Jennifer Garner#//upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Jennifer_Garner_at_the_Fast_Company_Innovation_Festival_-_44972951114_%28cropped%29.jpg/220px-Jennifer_Garner_at_the_Fast_Company_Innovation_Festival_-_44972951114_%28cropped%29.jpg

3 THE ACHIEVER
The Success-Oriented, Pragmatic Type: Adaptive, Excelling, Driven, and Image-Conscious
Tom Cruise#//upload.wikimedia.org/wikipedia/commons/thumb/3/33/Tom_Cruise_by_Gage_Skidmore_2.jpg/220px-Tom_Cruise_by_Gage_Skidmore_2.jpg,Sharon Stone#//upload.wikimedia.org/wikipedia/commons/thumb/3/3c/Sharon_Stone_%2833374127422%29_%28cropped%29.jpg/220px-Sharon_Stone_%2833374127422%29_%28cropped%29.jpg,Oprah Winfrey#//upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Oprah_in_2014.jpg/220px-Oprah_in_2014.jpg,Will Smith#//upload.wikimedia.org/wikipedia/commons/thumb/3/3f/TechCrunch_Disrupt_2019_%2848834434641%29_%28cropped%29.jpg/220px-TechCrunch_Disrupt_2019_%2848834434641%29_%28cropped%29.jpg

4 THE INDIVIDUALIST
The Sensitive, Withdrawn Type: Expressive, Dramatic, Self-Absorbed, and Temperamental
Johnny Depp#//upload.wikimedia.org/wikipedia/commons/thumb/2/21/Johnny_Depp_2020.jpg/220px-Johnny_Depp_2020.jpg,Jeremy Irons#//upload.wikimedia.org/wikipedia/commons/thumb/f/f1/Jeremy_Irons.jpg/220px-Jeremy_Irons.jpg,Judy Garland#//upload.wikimedia.org/wikipedia/commons/thumb/5/5f/JUDYGarland.jpg/220px-JUDYGarland.jpg,Kate Winslet#//upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Labor_Day_03_%289766118365%29.jpg/170px-Labor_Day_03_%289766118365%29.jpg

5 THE INVESTIGATOR
The Intense, Cerebral Type: Perceptive, Innovative, Secretive, and Isolated
Daniel Day-Lewis#//upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Daniel_Day-Lewis%2C_Jaguar%2C_Mille_Miglia_2013_cropped.jpg/220px-Daniel_Day-Lewis%2C_Jaguar%2C_Mille_Miglia_2013_cropped.jpg,Ralph Fiennes#//upload.wikimedia.org/wikipedia/commons/thumb/e/e1/Ralph_Fiennes_from_%22The_White_Crow%22_at_Opening_Ceremony_of_the_Tokyo_International_Film_Festival_2018_%2831747095048%29.jpg/220px-Ralph_Fiennes_from_%22The_White_Crow%22_at_Opening_Ceremony_of_the_Tokyo_International_Film_Festival_2018_%2831747095048%29.jpg,Greta Garbo#//upload.wikimedia.org/wikipedia/commons/thumb/5/57/Garbo_in_Inspiration.jpg/220px-Garbo_in_Inspiration.jpg

6 THE LOYALIST
The Committed, Security-Oriented Type: Engaging, Responsible, Anxious, and Suspicious
Tom Hanks#//upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Tom_Hanks_TIFF_2019.jpg/220px-Tom_Hanks_TIFF_2019.jpg,Jesse Eisenberg#//upload.wikimedia.org/wikipedia/commons/thumb/9/94/Jesse_Eisenberg-62192_%28cropped%29.jpg/220px-Jesse_Eisenberg-62192_%28cropped%29.jpg,Robert Pattinson#//upload.wikimedia.org/wikipedia/commons/thumb/d/df/MJK_08789_Robert_Pattinson_%28Damsel%2C_Berlinale_2018%29_%28cropped%29.jpg/220px-MJK_08789_Robert_Pattinson_%28Damsel%2C_Berlinale_2018%29_%28cropped%29.jpg,Daniel Craig#//upload.wikimedia.org/wikipedia/commons/thumb/8/87/Daniel_Craig_in_2021.jpg/220px-Daniel_Craig_in_2021.jpg

7 THE ENTHUSIAST
The Busy, Fun-Loving Type: Spontaneous, Versatile, Distractible, and Scattered
Elizabeth Taylor#//upload.wikimedia.org/wikipedia/commons/thumb/f/f4/Elizabeth_Taylor%2C_late_1950s.jpg/220px-Elizabeth_Taylor%2C_late_1950s.jpg,Robin Williams#//upload.wikimedia.org/wikipedia/commons/thumb/5/59/Robin_Williams_Happy_Feet_premiere.jpg/220px-Robin_Williams_Happy_Feet_premiere.jpg,Andy Samberg#//upload.wikimedia.org/wikipedia/commons/thumb/f/fb/Andy_Samberg.png/220px-Andy_Samberg.png,Dick van Dyke#//upload.wikimedia.org/wikipedia/commons/thumb/b/be/Dick_Van_Dyke_2021.jpg/220px-Dick_Van_Dyke_2021.jpg

8 THE CHALLENGER
The Powerful, Dominating Type: Self-Confident, Decisive, Willful, and Confrontational
Marlon Brando#//upload.wikimedia.org/wikipedia/commons/thumb/5/53/Marlon_Brando_publicity_for_One-Eyed_Jacks.png/220px-Marlon_Brando_publicity_for_One-Eyed_Jacks.png,John Wayne#//upload.wikimedia.org/wikipedia/commons/thumb/7/7b/John_Wayne_-_still_portrait.jpg/220px-John_Wayne_-_still_portrait.jpg,Frank Sinatra#//upload.wikimedia.org/wikipedia/commons/thumb/e/e3/Frank_Sinatra_%281957_studio_portrait_close-up%29.jpg/220px-Frank_Sinatra_%281957_studio_portrait_close-up%29.jpg,Kathleen Turner#//upload.wikimedia.org/wikipedia/commons/thumb/a/a2/Kathleen_Turner_%288689689518%29_cropped.jpg/220px-Kathleen_Turner_%288689689518%29_cropped.jpg

9 THE PEACEMAKER
The Easygoing, Self-Effacing Type: Receptive, Reassuring, Agreeable, and Complacent
Keanu Reeves#//upload.wikimedia.org/wikipedia/commons/thumb/3/33/Reuni%C3%A3o_com_o_ator_norte-americano_Keanu_Reeves_%2846806576944%29_%28cropped%29.jpg/220px-Reuni%C3%A3o_com_o_ator_norte-americano_Keanu_Reeves_%2846806576944%29_%28cropped%29.jpg,Audrey Hepburn#//upload.wikimedia.org/wikipedia/commons/thumb/5/5e/Audrey_Hepburn_1956.jpg/220px-Audrey_Hepburn_1956.jpg,Morgan Freeman#//upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Morgan_Freeman_Deauville_2018.jpg/220px-Morgan_Freeman_Deauville_2018.jpg,Jeff Bridges#//upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Jeff_bridges_0001_%28cropped%29.jpg/170px-Jeff_bridges_0001_%28cropped%29.jpg";

  $thisis=file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'enneagram_type_game.php');
  $lastotherde='';
  $categorizations=[];
  $wikistuffs=explode("\n", $typedescstuff);
  $wikidesignations=[];
  $wikidescriptions=[];
  $crandlist='';
  $randlist=[];
  $thisde='';
  $otherde='';
  for ($i=0; $i<sizeof($wikistuffs); $i++) {
    if (trim($wikistuffs[$i]) != '') {
    if (trim($wikistuffs[$i]) != '' && trim($wikistuffs[$i]) == strtoupper(trim($wikistuffs[$i]))) {
    $thisde=substr($wikistuffs[$i],2);
    } else if ($thisde != '') {
    $otherde=$thisde . ' ... ' . $wikistuffs[$i];
    array_push($categorizations, $otherde);
    $thisde='';
    } else {    
    if (trim($otherde) != '') {
    $cwikistuffs=explode(',', trim($wikistuffs[$i]));
    for ($ii=0; $ii<sizeof($cwikistuffs); $ii++) {
    if (strpos($cwikistuffs[$ii], '#') === false) {
       $bio=file_get_contents('http://en.wikipedia.org/wiki/' . str_replace(' ','_',$cwikistuffs[$ii]));
       $biois=explode('<img src="', $bio);
       if (sizeof($biois) > 1) {
         $thisis=str_replace($cwikistuffs[$ii], $cwikistuffs[$ii] . '#' . explode('"', $biois[1])[0], $thisis);
         file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'enneagram_type_game.php', $thisis); 
         $cwikistuffs[$ii].='#' . explode('"', $biois[1])[0];
       }
    }
    array_push($wikidesignations, $cwikistuffs[$ii]);
    array_push($wikidescriptions, $otherde);
    }
    $otherde='';
    }
    }
    }
  }
  
  $sofar=';';
  for ($i=0; $i<9; $i++) {
    $j=rand(0, (-1 + sizeof($wikidesignations)));
    if ($crandlist == '') {
      $crandlist='' . $j;
      $sofar.=$wikidescriptions[$j] . ';';
    } else if (strpos((',' . $crandlist . ','), (',' . $j . ',')) !== false || strpos($sofar, ';' . $wikidescriptions[$j] . ';') !== false) {
      while (strpos((',' . $crandlist . ','), (',' . $j . ',')) !== false || strpos($sofar, ';' . $wikidescriptions[$j] . ';') !== false) {
        $j=rand(0, (-1 + sizeof($wikidesignations)));
      }
      $crandlist.=',' . $j;
      $sofar.=$wikidescriptions[$j] . ';';
    } else {
      $crandlist.=',' . $j;
      $sofar.=$wikidescriptions[$j] . ';';
    }
  }
  
  $sofar=';';
  $ccrandlist='';
  for ($i=1; $i<=9; $i++) {
    $j=rand(1, 9);
    if ($ccrandlist == '') {
      $ccrandlist='' . $j;
      $sofar.='' . $j . ';';
    } else if (strpos((',' . $ccrandlist . ','), (',' . $j . ',')) !== false) {
      while (strpos((',' . $ccrandlist . ','), (',' . $j . ',')) !== false) {
        $j=rand(1, 9);
      }
      $ccrandlist.=',' . $j;
      $sofar.='' . $j . ';';
    } else {
      $ccrandlist.=',' . $j;
      $sofar.='' . $j . ';';
    }
  }
  
  $randlist=explode(',', "1,2,3,4,5,6,7,8,9"); //$crandlist);
  $randlist=explode(',', $crandlist);
  $rrandlist=explode(',', $ccrandlist);
  $randmode=rand(0,1);
  $correctans=rand(0,8);
  
  $callbackurl='./enneagram_type_game.php';
  $templategame=file_get_contents('./experimental_drag_and_drop.htm');

  for ($i=1; $i<=9; $i++) {
    $templategame=str_replace('>' . $i . '<', '>##' . $rrandlist[-1 + $i] . '<', $templategame);
  }
  $templategame=str_replace('>##', '>', $templategame);
  $templategame=str_replace('<table ', '<table cellspacing=8 cellpadding=8 ', $templategame);

  $templategame=str_replace('</h4>', '<input type=hidden id="callback" value="' . $callbackurl . '"></input></h4>', $templategame);
  $templategame=str_replace('>Game<', '>Enneagram Type Game <font size=1>... drag to matching correct answer to score</font><', $templategame);
  $templategame=str_replace('></h3>', '>' . $scorebit . '</h3>', $templategame);
  $thepsource=explode('f0;">', explode("</p>", $templategame)[0])[-1 + sizeof(explode('f0;">', explode("</p>", $templategame)[0]))];

  $templategame=str_replace(', 2023<', ', 2023 ... thanks to <a target=_blank href=https://www.enneagraminstitute.com/type-descriptions>The Nine Enneagram Type Descriptions</a> &amp; <a target=_blank href=https://www.psychologyjunkie.com/enneagram-famous-people/>The Enneagram Types of Your Favorite Movie Stars</a> &amp; <a target=_blank href=https://wikipedia.org>Wikipedia</a><', $templategame);
  $templategame=str_replace('>Reset example<', ' style="display:none;">Reset example<', $templategame);
  
  //echo $crandlist . "\n" . $thepsource . "\n" . $correctans . "\n";
  //exit;
  //echo $crandlist . "\n";
  //echo "" . $randlist[$correctans] . "\n" . $wikidescriptions[$randlist[$correctans]] . "\n" . $wikidesignations[$randlist[$correctans]];
  //exit;
  
  //file_put_contents('x.x', '' . $randmode . "\n" . $crandlist . "\n" . $thepsource . "\n" . $correctans . "\n" . $crandlist . "\n" . $randlist[$correctans] . "\n" . $wikidescriptions[$randlist[$correctans]] . "\n" . $wikidesignations[$randlist[$correctans]]);
  
  if ($randmode == 0) {  // designation up top and descriptions in drop zone
    $templategame=str_replace('>' . (1 + $correctans) . '<', ' data-answer="' . explode(' ... ', $wikidescriptions[$randlist[$correctans]])[0] . '">' . $categorizations[$correctans] . '<', $templategame);
    if (strpos($wikidesignations[$randlist[$correctans]], '#') !== false) {
    $templategame=str_replace(' style="background-color:#f0f0f0;"', ' ', $templategame);
    $templategame=str_replace('>' . $thepsource . '<', ' data-answer="' . explode(' ... ', $wikidescriptions[$randlist[$correctans]])[0] . '" style="background-color:#f0f0f0;background:URL(' . str_replace('http:','',explode('#', $wikidesignations[$randlist[$correctans]])[1]) . '); background-repeat: no-repeat; background-size: contain;background-position: center right;border:5px dashed pink;" alt="f0;">&nbsp;<br>' . explode('#', $wikidesignations[$randlist[$correctans]])[0] . '<br>&nbsp;<', $templategame);
    } else {
    $templategame=str_replace('>' . $thepsource . '<', ' data-answer="' . explode(' ... ', $wikidescriptions[$randlist[$correctans]])[0] . '">' . explode('#', $wikidesignations[$randlist[$correctans]])[0] . '<', $templategame);
    }
    for ($i=1; $i<=9; $i++) {
       if ((-1 + $i) != $correctans) {
    $templategame=str_replace('>' . $i . '</td', ' data-answer="' . explode(' ... ', $categorizations[-1 + $i])[0] . '">' . $categorizations[-1 + $i] . '</td', $templategame);
       }
    }
    $templategame=str_replace(' contenteditable=', ' data-contenteditable=', $templategame);
    echo $templategame;
  } else { // description up top and designations in drop zone
    if (strpos($wikidesignations[$randlist[$correctans]], '#') !== false) {
    $templategame=str_replace(' style="background-color:#f0f0f0;"', ' ', $templategame);
    $templategame=str_replace('>' . (1 + $correctans) . '<', ' data-answer="' . explode('#', $wikidesignations[$randlist[$correctans]])[0] . '" style="background-color:#f0f0f0;background:URL(' . str_replace('http:','',explode('#', $wikidesignations[$randlist[$correctans]])[1]) . '); background-repeat: no-repeat; background-size: contain;background-position: center right;" alt="f0;">' . explode('#', $wikidesignations[$randlist[$correctans]])[0] . '<', $templategame);
    } else {
    $templategame=str_replace('>' . (1 + $correctans) . '<', ' data-answer="' . explode('#', $wikidesignations[$randlist[$correctans]])[0] . '">' . explode('#', $wikidesignations[$randlist[$correctans]])[0] . '<', $templategame);
    }
    if (strpos($wikidesignations[$randlist[$correctans]], '#') !== false && 1 == 7) {
    $templategame=str_replace('>' . $thepsource . '<', ' data-answer="' . explode('#',$wikidesignations[$randlist[$correctans]])[0] . '" style="background:URL(' . str_replace('http:','',explode('#', $wikidesignations[$randlist[$correctans]])[1]) . '); background-repeat: no-repeat; background-size: contain;background-position: center right;border:5px dashed pink;" alt="f0;">&nbsp;<br>' . $wikidescriptions[$randlist[$correctans]] . '<br>&nbsp;<', $templategame);
    } else {
    $templategame=str_replace(' style="border:5px dashed pink;background-color:#f0f0f0;"', ' ', $templategame);
    $templategame=str_replace('>' . $thepsource . '<', ' style="border:5px dashed pink;background-color:#f0f0f0;" data-answer="' . explode('#', $wikidesignations[$randlist[$correctans]])[0] . '">' . $wikidescriptions[$randlist[$correctans]] . '<', $templategame);
    }
    for ($i=1; $i<=9; $i++) {
       if ((-1 + $i) != $correctans) {
    if (strpos($wikidesignations[$randlist[-1 + $i]], '#') !== false) {
    $templategame=str_replace('>' . $i . '</td', ' data-answer="" style="background:URL(' . str_replace('http:','',explode('#', $wikidesignations[$randlist[-1 + $i]])[1]) . '); background-repeat: no-repeat; background-size: contain;background-position: center right;" alt="f0;">' . explode('#', $wikidesignations[$randlist[-1 + $i]])[0] . '</td', $templategame);
    } else {
    $templategame=str_replace('>' . $i . '</td', ' data-answer="">' . explode('#', $wikidesignations[$randlist[-1 + $i]])[0] . '</td', $templategame);
    }
       }
    }
    $templategame=str_replace(' contenteditable=', ' data-contenteditable=', $templategame);
    echo $templategame;
  }
  

?>