need help with code calculating conference fees

I am using code used by the previous webmaster and passed on to me. when a member selects the ALL Inclusive package (allpack), the base rate is $225 (allbase) and the a la carte items should not be added to their total. Guests (guestpack) has a base rate of 0 (gbase) and should be charged for each a la carte item.

The Guest packs are calculating correctly, but the all inclusive packages are adding the costs of the a la carte items to the all inclusive base. I can’t find why that is happening. The form can be found and tested at http://www.zonta-district11.org/confsample/conferenceregistrationform.php I am the only one receiving the results.

I think this is the section of code where the calculations are being done.

[php] $allpacks = array($package);
if($numguest > 0) {
for($v=0;$v<$numguest;$v++) {
$guestpack = $_REQUEST[“guestpackage$v”];
array_push($allpacks, $guestpack);
}
js_addit($numguest, $allpacks, $posheld); // Javascript for adding up the total
}
else {
js_addit($numguest, $allpacks, $posheld); // Javascript for adding up the total
}

echo "<body bgcolor=\"$bgcolor\"><script type=\"text/javascript\">window.onload=function() { addit(); } </script><center>";    
title();
echo "<font size=+1>Item Selection</font><br>";
echo "<font size=+1><u>Must</u> make a selection on each line</font><br><br>";

echo "<form name=theform method=\"post\" action=\"?loc=" . $_REQUEST["loc"] . "\">";
echo "<input type=\"hidden\" name=\"stage\" value=\"4\">";
if($numguest > 0) {
  for($x=0;$x<$numguest;$x++) {
    $guestname = cleaningdata($_REQUEST["guestname$x"]);
    $guestneeds = cleaningdata($_REQUEST["needs$x"]);
$guestpack = $_REQUEST["guestpackage$x"];
    echo "<input type=\"hidden\" name=\"guestname$x\" value=\"$guestname\"><p>";
    echo "<input type=\"hidden\" name=\"needs$x\" value=\"$guestneeds\"><p>";
    echo "<input type=\"hidden\" name=\"guestpackage$x\" value=\"$guestpack\"><p>";
  }
}
echo "<input type=\"hidden\" name=\"areacode\" value=\"$areacode\"><p>";
echo "<input type=\"hidden\" name=\"prenum\" value=\"$prenum\"><p>";
echo "<input type=\"hidden\" name=\"postnum\" value=\"$postnum\"><p>";
echo "<input type=\"hidden\" name=\"club\" value=\"$club\"><p>";
echo "<input type=\"hidden\" name=\"fuser\" value=\"$fuser\"><p>";
echo "<input type=\"hidden\" name=\"muser\" value=\"$muser\"><p>";
echo "<input type=\"hidden\" name=\"luser\" value=\"$luser\"><p>";
echo "<input type=\"hidden\" name=\"role\" value=\"$role\"><p>";
echo "<input type=\"hidden\" name=\"email\" value=\"$email\"><p>";
echo "<input type=\"hidden\" name=\"state\" value=\"$state\"><p>";
echo "<input type=\"hidden\" name=\"oldnumguest\" value=\"$numguest\"><p>";
echo "<input type=\"hidden\" name=\"numguest\" value=\"$numguest\"><p>";
echo "<input type=\"hidden\" name=\"arrive\" value=\"$arrive\"><p>";
echo "<input type=\"hidden\" name=\"depart\" value=\"$depart\"><p>";
echo "<input type=\"hidden\" name=\"pastgovern\" value=\"$pastgovern\"><p>";
echo "<input type=\"hidden\" name=\"posheld\" value=\"" . implode(",", $posheld) . "\"><p>";
echo "<input type=\"hidden\" name=\"package\" value=\"$package\"><p>";
echo "<input type=\"hidden\" name=\"needs\" value=\"$needs\"><p>";

// Opens the File and pulls data in order to grab the variables
$handler = fopen($config, "r");
$counter = filesize($config);
$contents = fread($handler, filesize($config));

// Splits the contents based on newlines
$contentarray = preg_split("/\n/", $contents);
$contentcounter = count($contentarray);

for($x=0;$x<$contentcounter;$x++) {
  if(($realcontent == 0) && (preg_match("/credit/", $contentarray[$x]))) {
$creditarray = preg_split("/,/", $contentarray[$x]);
if($creditarray[1] == "yes") {
  $maxcredit = $creditarray[2];
      $usecredit = 1;
}
  }

  if($realcontent == 1) {
    $perdata = preg_split("/\|/", $contentarray[$x]);
    $itemdate = $perdata[0];
    $itemname = $perdata[1];
    $itemdesc = $perdata[2];
    $itemtype = $perdata[3];
    $itemprice = $perdata[4];
    $itemdisp = $perdata[5];
    $itemselection = preg_split("/`/", $perdata[6]);
    echo "<font size=+1><b>$itemname</b></font><br>";
    echo "<table border=1 width=500 cellpadding=1><tr><td width=230 valign=top>";
    $itemdatearray = preg_split("/-/", $itemdate);
    echo "<b>Date:</b> $itemdate (" . date("l", mktime(0, 0, 0, $itemdatearray[0], $itemdatearray[1], $itemdatearray[2])) . ")<br>";
//if($package != "all")
      echo "<b>Ala carte Price:</b> \$$itemprice<br>";
    echo "</td><td width=275 valign=top>";
    echo "<u><center><b>Description</b></center></u><br>";
    echo "$itemdesc";
    echo "</td></tr></table><br>";
    echo "<table border=0 cellpadding=5><tr><td>";

$guestcounter = 0;
    for($y=0;$y<($numguest+1);$y++) {
  echo "</td><td valign=top>";
  if($y != 0) {
    $tempy = $y - 1;
    echo $_REQUEST["guestname$tempy"] . "<br>";
    $thename = $_REQUEST["guestname$tempy"] . "guest";
    $theguestpack = $_REQUEST["guestpackage$tempy"];
    $userpackage = "";
      }
      else {
    echo "$fuser $muser $luser<br>";
    $thename = "$fuser$muser$luser";
    $theguestpack = "";
	    $userpackage = $_REQUEST["package"];
  }	  

  $insidecounter = 0;
      foreach($itemselection as $theselection) {
        switch($itemdisp) {
          case "input": 
        echo "$theselection<br> <input type=text id=\"$guestcounter$itemname\" name=\"$thename$itemdate$itemname\" onclick=\"addit()\">";
        break;
          case "area": 
        echo "$theselection<br> <textarea id=\"$guestcounter$itemname\" name=\"$thename$itemdate$itemname\" rows=4 cols=16 onclick=\"addit()\"></td>";
        break;
          case "radio":
        if(($insidecounter == 0) && ($itemprice != 0) && (($userpackage == "all") || ($theguestpack == "all"))) {
	  $insidecounter++;
          echo "<input type=radio name=\"$thename$itemdate$itemname\" value=\"Not Attending\" disabled> Not Attending<br>";
        }
        elseif(($insidecounter == 0)) {
	  $insidecounter++;
          echo "<input type=radio name=\"$thename$itemdate$itemname\" id=\"$guestcounter$itemname\" value=\"Not Attending\" onclick=\"addit()\"> Not Attending<br>";
        }
	
        if($y != 0)
          echo "<input type=radio name=\"$thename$itemdate$itemname\" id=\"$guestcounter$itemname\" value=\"$theselection\" onclick=\"addit()\"> $theselection<br>";
        else
          echo "<input type=radio name=\"$thename$itemdate$itemname\" id=\"$guestcounter$itemname\" value=\"$theselection\" onclick=\"addit()\"> $theselection<br>";
        break;
          case "checkbox": 
        if(($insidecounter == 0) && ($itemprice != 0) && (($userpackage == "all") || ($theguestpack == "all"))) {
	  $insidecounter++;
          echo "<input type=checkbox name=\"$thename" . $itemdate . $itemname . "[]\" value=\"Not Attending\" disabled> Not Attending<br>";
        }
        elseif(($insidecounter == 0)) {
	  $insidecounter++;
          echo "<input type=checkbox name=\"$thename" . $itemdate . $itemname . "[]\" id=\"$guestcounter$itemname\" value=\"Not Attending\" onclick=\"addit()\"> Not Attending<br>";
        }

	
        if($y != 0)
          echo "<input type=checkbox name=\"$thename" . $itemdate . $itemname . "[]\" id=\"$guestcounter$itemname\" value=$theselection onclick=\"addit()\"> $theselection<br>";
        else
          echo "<input type=checkbox name=\"$thename" . $itemdate . $itemname . "[]\" id=\"$guestcounter$itemname\" value=\"$theselection\" onclick=\"addit()\"> $theselection<br>";
        break;
        }      
      }
      $guestcounter++;
	  if($guestcounter > $numguest)
    $guestcounter = 0;
    }
    echo "</td></tr></table><p>";
  }

  if($contentarray[$x] == "-thisisabreak")
$realcontent = 1;
}

if($usecredit == 1) {
  echo "Credit: $<input type=text id=\"usercredit\" name=\"credit\" value=\"0\"><br>"; 
  echo "<font size=+1 color=\"red\"><b>* The Rosa E. Fiol credit will be applied after completing the form. *</b></font><br>";
  echo "<font size=+1 color=\"red\"><b>* Maximum amount of the credit is \$$maxcredit. *</b></font><p>";
}
else
  echo "<input type=hidden id=\"usercredit\" name=\"credit\" value=\"0\"><p>";
  echo "<input type=hidden id=\"usercredit\" name=\"maxcredit\" value=\"0\"><p>";

echo "Total: $<div id=thetotalamount></div><p>";    
echo "<input type=\"button\" value=\"Continue\" onclick=\"validcheck()\"><p>";
footer();
echo "</center>";

} // END stage3

// Validator
function stage4() {
// variables
global $bgcolor;
global $file;
global $curfilename;
global $config;
$addinfo = “”;
$breakfound = 0;
$thecounter = 0;
$usercredit = 0;
$club = $_REQUEST[“club”];
$fuser = cleaningdata($_REQUEST[“fuser”]);
$muser = cleaningdata($_REQUEST[“muser”]);
$luser = cleaningdata($_REQUEST[“luser”]);
$role = $_REQUEST[“role”];
$email = cleaningdata($_REQUEST[“email”]);
$areacode = $_REQUEST[“areacode”];
$prenum = $_REQUEST[“prenum”];
$postnum = $_REQUEST[“postnum”];
$state = $_REQUEST[“state”];
$oldnumguest = $_REQUEST[“oldnumguest”];
$numguest = $_REQUEST[“numguest”];
$arrive = $_REQUEST[“arrive”];
$depart = $_REQUEST[“depart”];
$pastgovern = $_REQUEST[‘pastgovern’];
$posheld = explode(",", $_REQUEST[“posheld”]);
$package = $_REQUEST[“package”];
$needs = cleaningdata($_REQUEST[“needs”]);
$credit = $_REQUEST[“credit”];
$maxcredit = $_REQUEST[“maxcredit”];
$totalamount = $_REQUEST[“totalamount”];

// Opens the File and pulls data in order to grab the variables
$handler = fopen($file, "r");
$counter = filesize($file);
$contents = fread($handler, filesize($file));

// Splits the contents based on newlines
$contentarray = preg_split("/\n/", $contents);
$contentcounter = count($contentarray);

$allpacks = array($package);
if($numguest > 0) {
  for($v=0;$v<$numguest;$v++) {
    $guestpack = $_REQUEST["guestpackage$v"];
    array_push($allpacks, $guestpack);
  }
  js_addit($numguest, $allpacks, $posheld); // Javascript for adding up the total
}
else {
  js_addit($numguest, $allpacks, $posheld); // Javascript for adding up the total
}

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service