What is this code doing?

Hello,

I didn’t know whether to put this in the Development forum or here, as it is related to both.

This is some code from a game I had made for me. I’m trying to understand it better.

The first chunk of code, I’m assuming is for submitting a high score to a database via XML and PHP. What exactly is happening here? Is the SWF creating the XML or is the PHP doing it?

 
function getscore (pts, mail, nickname)
{
 this.messageVar = "Submitting scores...";
 scoreXML = new XML ();
 scoreXML.ignoreWhite = false;
 scoreXML.contentType = "text/xml";
 scoreElement = scoreXML.createElement ("SubmitScore");
 element1 = scoreXML.createElement ("PlayerName");
 element2 = scoreXML.createElement ("EmailId"); 
 element3 = scoreXML.createElement ("Score");
 subelement1 = scoreXML.createTextNode (nickname);
 subelement2 = scoreXML.createTextNode (mail); 
 subelement3 = scoreXML.createTextNode (pts);
 scoreElement.appendChild (element1);
 scoreElement.appendChild (element2);
 scoreElement.appendChild (element3);
 element1.appendChild (subelement1);
 element2.appendChild (subelement2);
 element3.appendChild (subelement3);
 scoreXML.appendChild (scoreElement);
 scoreReplyXML = new XML ();
 scoreReplyXML.onLoad = onscoreReply;
 scoreReplyXML.ignoreWhite = true;
 //scoreXML.send("[Server Address /score.php](http://www.arts-estrie.com/nascar/score.php)", "_blank");
 scoreXML.sendAndLoad ("[Server Address /score.php](http://www.arts-estrie.com/nascar/score.php)", scoreReplyXML, "POST");
}
function onscoreReply (ok1)
{
 if (ok1 == true)
 {
  getscoreReply (this.firstChild);  
  messageVar = scorestatus.toString ();
 }
}
function getscoreReply (rootscore)
{
 if (rootscore.nodeName.toUpperCase () == "SCOREREPLY")
 {
  fcscore = rootscore.firstChild;
  while (fcscore != null)
  {
   if (fcscore.nodeName.toUpperCase () == "STATUSDESC")
   {
    scorestatus = fcscore.firstChild.nodeValue;
   }
   fcscore = fcscore.nextSibling;
  }
 }
}
stop();

This second chunk is to retrieve the data from the database and a create a high score table with it.

onClipEvent (load) {
 this.proceedVar = 1;
 for (var i = 0; i <= 100; i++)
 {
  removeMovieClip (this["scoreClip" + i]);
 }
 loadcliper._visible = true;
 highScoreNameArray = new Array ();
 highScoreArray = new Array ();
 highScoreEmailArray = new Array ();
 function getleaderboard ()
 {
  leaderboardXML = new XML ();
  leaderboardXML.ignoreWhite = false;
  leaderboardXML.contentType = "text/xml";
  scoreElement = leaderboardXML.createElement ("LeaderBoard");
  element1 = leaderboardXML.createElement ("Request");
  subelement1 = leaderboardXML.createTextNode ("test");
  scoreElement.appendChild (element1);
  element1.appendChild (subelement1);
  leaderboardReplyXML = new XML ();
  leaderboardReplyXML.onLoad = onleaderboardReply;
  leaderboardReplyXML.ignoreWhite = true;
  leaderboardReplyXML.contentType = "text/xml";
  //leaderboardXML.send ("[Server Address /leaderboard.php","_blank](http://www.arts-estrie.com/nascar/leaderboard.php%22,%22_blank)");
  //leaderboardXML.sendAndLoad ("leaderboard.php", leaderboardReplyXML, "POST");
  leaderboardXML.sendAndLoad ("[Server Address /leaderboard.php?nocache="+random(23](http://www.arts-estrie.com/nascar/leaderboard.php?nocache="+random(23)), leaderboardReplyXML, "POST");
 }
 // End of the function
 function onleaderboardReply (ok1)
 {
  if (ok1 == true)
  {
   getleaderboardReply (this.firstChild);
   gotoAndStop ("displayBoard");
  }
 }
 function getleaderboardReply (rootleaderboard)
 {
  _parent.traceVar = "JESUS  " + rootleaderboard;
  if (rootleaderboard.nodeName.toUpperCase ().toString () == "LEADERBOARD")
  {
   fcleaderboard = rootleaderboard.firstChild;
   while (fcleaderboard != null)
   {
    if (fcleaderboard.nodeName.toUpperCase ().toString () == "HIGHSCORE")
    {
     scleaderboard = fcleaderboard.firstChild;
     while (scleaderboard != null)
     {
      if (scleaderboard.nodeName.toUpperCase ().toString () == "PLAYERNAME")
      {
       highScoreNameArray.push (scleaderboard.firstChild.nodeValue);
      }
      if (scleaderboard.nodeName.toUpperCase ().toString () == "PLAYEREMAILID")
      {
       highScoreEmailArray.push (scleaderboard.firstChild.nodeValue);
      }
      if (scleaderboard.nodeName.toUpperCase ().toString () == "SCORE")
      {
       highScoreArray.push (scleaderboard.firstChild.nodeValue);
      }
      scleaderboard = scleaderboard.nextSibling;
     }
    }
    fcleaderboard = fcleaderboard.nextSibling;
   }
  }
 }
}
onClipEvent (enterFrame) {
 this.proceedVar += 1;
 if (this.proceedVar == 2)
 {
  //_parent.traceVar = "Jesus Loves You"
  this.getleaderboard ();
  //delete this.onEnterFrame;
 }
}

I do have the PHP files which go with this aswell if needed. There is also some more actionscript obviously, like the code which builds the table itself, I can post these up later.

This first script is from the Score.php file.

 
<?php
include "includes/connection.php";
include "includes/function.php";
$raw_xml = file_get_contents("php://input");
$TheArrNickName = GetTagValue("PlayerName",$raw_xml);
$str_nickname = $TheArrNickName[0];
$TheArrEmailId = GetTagValue("EmailId",$raw_xml);
$str_emailid = $TheArrEmailId[0];
$TheArrScore = GetTagValue("Score",$raw_xml);
$str_score = $TheArrScore[0];
 $date = getDate();
 $strdate = $date['year']."/".$date['mon']."/".$date['mday']." ".$date['hours'].":".$date['minutes'].":".$date['seconds'];
 $sqlInsert1 = "Insert into cargame (playerName,playerEmail,score,entryDate) values ('$str_nickname','$str_emailid',$str_score,'$strdate') ";
 ExecuteSql($sqlInsert1);
 $sqlInsert2 = "Insert into game_period (playerName,playerEmail,score,entryDate) values ('$str_nickname','$str_emailid',$str_score,'$strdate') ";
 ExecuteSql($sqlInsert2);
 
echo ('<?xml version="1.0" encoding="ISO-8859-1" ?>');
echo("<ScoreReply>");
 echo("<StatusDesc>Score has been updated Successfully</StatusDesc>");
echo("</ScoreReply>");
?>

The second script is from the leaderboard.php file.

 
<?php
include "includes/connection.php";
include "includes/function.php";
$raw_xml = file_get_contents("php://input");
$TheArrRequest = GetTagValue("Request",$raw_xml);
$str_Request = $TheArrRequest[0];
$date = getDate();
$Seldate = $date['year']."/".$date['mon']."/01";
$sqlselect = "SELECT playername,playerEmail,score FROM cargame order by score desc ";
ExecuteSql($sqlselect,"objrs");
if (mysql_num_rows($objrs)<=100)
 $rowcount = mysql_num_rows($objrs);
else
 $rowcount =100;
echo ('<?xml version="1.0" encoding="ISO-8859-1" ?>');
echo("<LeaderBoard>");
for($i=0;$i<$rowcount;$i++)
{
 $row = mysql_fetch_row($objrs); 
 $strPlayerName = $row[0];
 $strPlayerEmailId = $row[1];
 $strScore = $row[2]; 
 echo("<HighScore>"); 
  echo("<PlayerName>" . $strPlayerName ."</PlayerName>");
  echo("<PlayerEmailId>" . $strPlayerEmailId ."</PlayerEmailId>");
  echo("<Score>". $strScore ."</Score>"); 
 echo("</HighScore>");
 } 
echo("</LeaderBoard>");
?>

Can a kind person tell me in basic terms (I have nearly no PHP experience) what the 2 scripts are doing? and how is the XML used exactly?

I would really appreciate a basic explanation as to what is happening for each section of code so that I can get my head around it!

Regards,
adsmithy