<?php
session_start();
require "settings.php";
include "header.inc.php";
?>

<tr>
<td width="800" bgcolor="#FFFFFF" style="width: 800px;"><p>&nbsp;</p>
  <p>
<?
if ($_GET['start'] == "1") {

	if ($_GET['code'] == "") {
		$err = "<br><font color=red>Sorry, the survey code is required to start the survey.</font><br>";
		include "error.php";
		include "footer.inc.php";
		die;
	}
	switch ($_GET['fleet']) {
		case "AF":
			$db = "reserve";
			$sql = "
			SELECT 
				`WWM_survey_codes`.*,
				`boats`.`name`,
				`resellers`.`company`

			FROM $db.`WWM_survey_codes`,$db.`boats`,$db.`reservations`,$db.`reseller_agents`,$db.`inventory`,$db.`resellers`

			WHERE 
				`WWM_survey_codes`.`inventoryID` = '$_GET[code]' 
				AND `WWM_survey_codes`.`submitted` IS NULL
				AND `WWM_survey_codes`.`boatID` = `boats`.`boatID`	
				and `reservations`.`reservationID`=`inventory`.`reservationID` and `inventory`.`inventoryID`='$_GET[code]' and `reservations`.`reseller_agentID`=`reseller_agents`.`reseller_agentID` and `reseller_agents`.`resellerID`=`resellers`.`resellerID`
			
			";
		//	die($sql);
		$result = mysql_query("$sql", $af);
         $sql2 = "SELECT * FROM $db.`WWM_survey_results` WHERE `inventoryID` = '$_GET[code]'";
         $result2 = mysql_query("$sql2", $af);
			break;
		default:
			$err = "<br><font color=red>Sorry, I was unable to determin what cruize line you traveled with. Please email <a href=\"mailto:robert@wayneworks.com\">robert@wayneworks.com</a></font><br>";
			include "error.php";
			include "footer.inc.php";
			die;
	}

	for ($x=0; $x <1; $x++) {
		$row = mysql_fetch_assoc($result);
		$found_record = "1";
		// Start Survey

		$w1 = " width=20% ";

		$line = "<tr><td colspan=1><hr></td></tr>";

		print "
		<form name=\"MyForm\" action=\"guest_survey.php\" method=\"post\">
		<input type=\"hidden\" name=\"fleet\" value=\"$_GET[fleet]\">
		<input type=\"hidden\" name=\"fleet2\" value=\"$_GET[fleet2]\">
		<input type=\"hidden\" name=\"code\" value=\"$_GET[code]\">
		<input type=\"hidden\" name=\"start\" value=\"2\">
		<input type=\"hidden\" name=\"company\" value=\"$row[company]\">
		<table border=0 width=80% cellpadding=5 cellspacing=5>
		<tr><td colspan=2>
		Your vacation is very important to us. To help us ensure that you received the high quality service that we expect, please tell us how we did by completing the following survey.
		</td></tr>
<!-- 1 -->
		<tr><td><b>How did you hear about us?</td><td><select name=\"q1\">
			<option>Repeat guest</option>
			<option>Friend</option>
			<option>Dive Show</option>
			<option>Internet</option>
			<option>Magazine</option>
			<option>Dive Store</option>
			<option>Tour Operator</option>
			<option>Travel Agent</option>
			</select></td></tr>
		$line

<!-- 2 -->
      <tr><td colspan=2><b>Why did you choose us?</b></td></tr>
      <tr><td colspan=2><textarea name=\"q2\" cols=75 rows=5></textarea></td></tr>
      $line

<!-- 3 -->

		";

		if ($_GET['fleet'] == "AF") {
			$c1 = "selected";
		} else {
			$c2 = "selected";
		}

		if ($_GET['fleet2'] == "AF") {
			$c1 = "selected";
			$c2 = "";
		}

		print "

      <tr><td><b>How were your reservations made?</b></td><td>
         <select name=\"q3\" id=\"q3\">
				<option value=\"\">--Please Select--</option>
            <option $c1>Aggressor</option>
            <option>Tour Operator</option>
            <option>Dive Store</option>
				<option>Travel Agent</option>
      </td></tr>
      $line


<!-- 4 -->
		<tr><td colspan=2><b>Please rate your reservation process on a scale of 5 (very satisfied) to 1 (unsatisfied)</b>&nbsp;
		<select name=\"q4\">
			<option selected>5</option>
			<option>4</option>
			<option>3</option>
			<option>2</option>
			<option>1</option>
		</select>
		</td></tr>
		$line

<!-- NEW -->
	<tr><td colspan=2><b>Did you receive a travel package from Aggressor Adventures prior to traveling?</b> <select name=\"q4b\"><option>Yes</option><option>No</option></select></td></tr>
	$line

<!-- 5 -->
		<tr><td colspan=2><b>How can we improve the reservation process?</b></td></tr>
		<tr><td colspan=2><textarea name=\"q5\" cols=75 rows=5></textarea></td></tr>
		$line

<!-- 6 -->
      <tr><td colspan=2><b>If your travel arrangements were made by our in house travel department, please tell us about your experience.</b></td></tr>
      <tr><td colspan=2><textarea name=\"q6\" cols=75 rows=5></textarea></td></tr>
      $line

<!-- 7 -->
      <tr><td colspan=2><b>How was your onboard experience?</b></td></tr>
      <tr><td colspan=2>
         <table border=0 width=99% cellspacing=5>
         <tr><td width=30%>&nbsp;</td><td width=11.6%><b>Excellent</b></td><td width=11.6%>&nbsp;</td><td width=11.6%><b>Fair</b></td><td width=11.6%>&nbsp;</td><td width=11.6%><b>Poor</b></td><td width=11.6%><b>N/A</b></td></tr>
         <tr><td>How were your accommodations?</td>
            <td><input type=\"radio\" name=\"q7a\" value=\"5\"></td>
            <td><input type=\"radio\" name=\"q7a\" value=\"4\"></td>
            <td><input type=\"radio\" name=\"q7a\" value=\"3\"></td>
            <td><input type=\"radio\" name=\"q7a\" value=\"2\"></td>
            <td><input type=\"radio\" name=\"q7a\" value=\"1\"></td>
            <td>&nbsp;</td>
         </tr>
         <tr><td>How was the service?</td>
            <td><input type=\"radio\" name=\"q7b\" value=\"5\"></td>
            <td><input type=\"radio\" name=\"q7b\" value=\"4\"></td>
            <td><input type=\"radio\" name=\"q7b\" value=\"3\"></td>
            <td><input type=\"radio\" name=\"q7b\" value=\"2\"></td>
            <td><input type=\"radio\" name=\"q7b\" value=\"1\"></td>
            <td>&nbsp;</td>
         </tr>
         <tr><td>How was the food?</td>
            <td><input type=\"radio\" name=\"q7c\" value=\"5\"></td>
            <td><input type=\"radio\" name=\"q7c\" value=\"4\"></td>
            <td><input type=\"radio\" name=\"q7c\" value=\"3\"></td>
            <td><input type=\"radio\" name=\"q7c\" value=\"2\"></td>
            <td><input type=\"radio\" name=\"q7c\" value=\"1\"></td>
            <td>&nbsp;</td>
         </tr>
         <tr><td>How was the diving?</td>
            <td><input type=\"radio\" name=\"q7d\" value=\"5\"></td>
            <td><input type=\"radio\" name=\"q7d\" value=\"4\"></td>
            <td><input type=\"radio\" name=\"q7d\" value=\"3\"></td>
            <td><input type=\"radio\" name=\"q7d\" value=\"2\"></td>
            <td><input type=\"radio\" name=\"q7d\" value=\"1\"></td>
            <td><input type=\"radio\" name=\"q7d\" value=\"0\"></td>
         </tr>
         </table>
      </td></tr>
      $line

<!-- 8 -->
      <tr><td colspan=2><b>Please tell us about your experience.</b></td></tr>
      <tr><td colspan=2><textarea name=\"q8\" cols=60 rows=4></textarea></td></tr>
      $line

<!-- 9 -->
		<tr><td colspan=2><b>How likely are you to continue to travel with us?</b></td></tr>
      <tr><td colspan=2>
         <table border=0 width=99% cellspacing=5>
         <tr><td $w1>&nbsp;</td><td $w1><b>Very Likely</b></td><td $w1><b>Likely</b></td><td $w1><b>Somewhat Likely</b></td><td $w1><b>Unlikely</b></td><td $w1><b>Very Unlikely</b></td></tr>
			<tr><td>&nbsp;</td>
				<td><input type=\"radio\" name=\"q9\" value=\"5\"></td>
            <td><input type=\"radio\" name=\"q9\" value=\"4\"></td>
            <td><input type=\"radio\" name=\"q9\" value=\"3\"></td>
            <td><input type=\"radio\" name=\"q9\" value=\"2\"></td>
            <td><input type=\"radio\" name=\"q9\" value=\"1\"></td>
			</tr>
			</table>
		</td></tr>
		$line

<!-- 22 -->
      <tr><td colspan=2><b>How would you rate the value provided by this vessel?</b></td></tr>
      <tr><td colspan=2>
         <table border=0 width=99% cellspacing=5>
         <tr><td $w1>&nbsp;</td><td $w1><b>Excellent</b></td><td $w1></td><td $w1><b>Fair</b></td><td $w1></td><td $w1><b>Poor</b></td></tr>
         <tr><td>&nbsp;</td>
            <td><input type=\"radio\" name=\"q22\" value=\"5\"></td>
            <td><input type=\"radio\" name=\"q22\" value=\"4\"></td>
            <td><input type=\"radio\" name=\"q22\" value=\"3\"></td>
            <td><input type=\"radio\" name=\"q22\" value=\"2\"></td>
            <td><input type=\"radio\" name=\"q22\" value=\"1\"></td>
         </tr>
         </table>
      </td></tr>
      $line


<!-- 10 -->
      <tr><td colspan=2><b>Do you plan to join us on another vacation?</b> &nbsp;&nbsp;&nbsp;&nbsp; <select name=\"q10a\"><option value=\"1\">Yes</option><option value=\"0\">No</option></select></td></tr>
      <tr><td colspan=2>If yes, which destination is of particular interest to you?<br>
      <textarea name=\"q10b\" cols=70 rows=2></textarea></td></tr>
      $line

<!-- 11 -->
		<tr><td colspan=2><b>List two new locations where you would like to see an Aggressor vessel?</b></td></tr>
		<tr><td colspan=2>1. <input type=\"text\" name=\"q11a\" size=20> 2. <input type=\"text\" name=\"q11b\" size=20></td></tr>
		$line

<!-- 12 -->
		<tr><td colspan=2><b>What dive publications do you read?</b></td></tr>
		<tr><td colspan=2>
			<table border=0 cellspacing=5>
			<tr>
				<td width=30%>&nbsp;</td>
				<td width=11.6%><b>Favorite</b></td>
				<td width=11.6%>&nbsp;</td>
				<td width=11.6%><b>Fair</b></td>
				<td width=11.6%>&nbsp;</td>
				<td width=11.6%><b>Least</b></td>
				<td width=11.6%><b>N/A</b></td>
			</tr>
			<tr>";

			$mag = array();
			$mag[0] = "Alert Diver Magazine";
			$mag[1] = "Dive Training Magazine";
			$mag[2] = "Scuba Diving Magazine USA";
		    $mag[3] = "Silent World (Germany)";
			$mag[4] = "DIVER UK";
			$mag[5] = "unterwasser (Germany)";
			$mag[6] = "EZ Dive Magazine";
			$mag[7] = "Scuba Diving Asia Pacific";
			$mag[8] = "Scuba Diver UK";
			$mag[9] = "Tauchen Magazine";
            $mag[11] = "Diver Canada";
			$mag[12] = "Plongee";
			$mag[13] = "SCUBA BSAC UK";
			$mag[14] = "Ultimate Depth (Russia)";
			$mag[15] = "Sport Diver Magazine UK";
			$mag[16] = "Sport DYKAREN";
			$mag[17] = "Scuba Diver (Australasia Ocean Planet/ Asian Diver)";
			$mag[18] = "Dive Center Business";
			$mag[19] = "DIVE UK"; // new
			$mag[20] = "Action Diver (Asia)"; // new

			asort($mag);

			foreach ($mag as $y=>$value) {
				print "
				<tr><td>$value</td>
					<td><input type=\"radio\" name=\"q12a_$y\" value=\"5\"></td>
               <td><input type=\"radio\" name=\"q12a_$y\" value=\"4\"></td>
               <td><input type=\"radio\" name=\"q12a_$y\" value=\"3\"></td>
               <td><input type=\"radio\" name=\"q12a_$y\" value=\"2\"></td>
               <td><input type=\"radio\" name=\"q12a_$y\" value=\"1\"></td>
               <td><input type=\"radio\" name=\"q12a_$y\" value=\"0\"></td>
				</td></tr>";
			}
			print "
			<tr><td>Other</td><td colspan=6><input type=\"text\" name=\"q12b\" size=40></td></tr>
			</table>
		</td></tr>
		$line

<!-- 13 -->
      <tr><td colspan=2><b>What websites do you visit to gain more information about traveling on your next liveaboard?</b></td></tr>
      <tr><td colspan=2>
         <table border=0 cellspacing=5>
         <tr>
            <td width=30%>&nbsp;</td>
            <td width=11.6%><b>Favorite</b></td>
            <td width=11.6%>&nbsp;</td>
            <td width=11.6%><b>Fair</b></td>
            <td width=11.6%>&nbsp;</td>
            <td width=11.6%><b>Least</b></td>
            <td width=11.6%><b>N/A</b></td>
         </tr>
         <tr>";

			$scu = array();
			$scu[0] = "ScubaBoard";
			$scu[1] = "Internet";
			$scu[2] = "Scuba Diving USA";
			$scu[3] = "DiveNewsWire";
			$scu[4] = "Buceadores (Spain)";
			$scu[5] = "X-Ray";
			$scu[6] = "AustralAsia";
			$scu[7] = "DIVE UK";
			$scu[8] = "Sport Diver (USA)";

			// new below
			$scu[9] = "PADI.com";
			$scu[10] = "SSI";
			$scu[11] = "Aggressor TV";
		//	$scu[12] = "Aqua Lung";
			$scu[13] = "DEMA";
		//	$scu[14] = "Jim Church Photo";
			$scu[15] = "AQa"; // new
		//	$scu[16] = "In Depth"; // new

			asort($scu);
         foreach ($scu as $y=>$value) {
            print "
            <tr><td>$value</td>
               <td><input type=\"radio\" name=\"q13a_$y\" value=\"5\"></td>
               <td><input type=\"radio\" name=\"q13a_$y\" value=\"4\"></td>
               <td><input type=\"radio\" name=\"q13a_$y\" value=\"3\"></td>
               <td><input type=\"radio\" name=\"q13a_$y\" value=\"2\"></td>
               <td><input type=\"radio\" name=\"q13a_$y\" value=\"1\"></td>
               <td><input type=\"radio\" name=\"q13a_$y\" value=\"0\"></td>
            </td></tr>";
            $y++;
         }
         print "
			<tr><td>Other</td><td colspan=6><input type=\"text\" name=\"q13b\" size=40></td></tr>
         </table>
      </td></tr>
      $line


<!-- 14 -->
		<tr><td colspan=2>
		<table border=0 width=100%>
			<tr>
				<td width=80%><b>On a scale of 10 (best) to 1 (least), how likely are you to recommend us to a friend or colleague?</b>
				</td>
				<td width=20%><select name=\"q14\">\n";
				for ($t=1; $t < 11; $t++) {
					$extra1 = "";
					if ($t == "10") {
						$extra1 = "selected";
					}
					print "<option $extra1 value=\"$t\">$t</option>";
				}
		print "
				</select></td>
			</tr>
		</table>
		</td></tr>
		$line

<!-- 15 -->
      <tr><td colspan=2>
      <table border=0 width=100%>
         <tr>
            <td width=80%><b>On a scale of 10 (best) to 1 (least), how likely are you to recommend $row[name] to a friend or colleague?</td>
            <td width=20%><select name=\"q15\">\n";
            for ($t=1; $t < 11; $t++) {
               $extra1 = "";
               if ($t == "10") {
                  $extra1 = "selected";
               }
               print "<option $extra1 value=\"$t\">$t</option>";
            }
      print "
            </select></td>
         </tr>
      </table>
      </td></tr>
      $line


<!-- 16 -->
      <tr><td colspan=2>
      <table border=0 width=100%>
         <tr>
				<td colspan=2><b>What was the primary factor you considered in determining your score?</b></td>
			</tr>
			<tr>
				<td colspan=2>
					<textarea name=\"q16\" cols=60 rows=4></textarea>
				</td>
			</tr>
		$line

<!-- 17 -->
      <tr><td colspan=2>
      <table border=0 width=100%>
         <tr>
            <td colspan=2><b>What is the one thing we can do to improve this score next time?</b></td>
			</tr>
         <tr>
            <td colspan=2>
               <textarea name=\"q17\" cols=60 rows=4></textarea>
            </td>
         </tr>
		$line
		<tr><td colspan=2><center><input type=\"submit\" value=\"Submit Survey\" class=\"btn btn-primary\"></center></td></tr>

		</table>
		\n";

	}
	// Error
	if ($found_record != "1") {
		$err = "<br><br><br><br><br><br><br><br><br><center><font color=red>Sorry, the reservation code entered was not valid or the survey has already been completed.</font></center><br>";
		include "error.php";
		include "footer.inc.php";
		die;
	}

}


// submit survey

if ($_POST['start'] == "2") {
	foreach ($_POST as $k=>$value) {
		$_POST[$k] = @mysql_real_escape_string($value);
	}

	// Insert survey results
   switch ($_POST['fleet']) {
      case "AF":
         $db = "reserve";
         $sql = "
         SELECT
            `WWM_survey_codes`.*,
            `boats`.`name`

         FROM $db.`WWM_survey_codes`,$db.`boats`

         WHERE
            `WWM_survey_codes`.`inventoryID` = '$_POST[code]'
            AND `WWM_survey_codes`.`submitted` IS NULL
            AND `WWM_survey_codes`.`boatID` = `boats`.`boatID`
         ";
         $result = mysql_query("$sql", $af);
			for ($x=0; $x < mysql_num_rows($result); $x++) {
				$row = mysql_fetch_assoc($result);
				$contactID = $row['passengerID'];
			}

			// check for duplicate
			$sql2 = "SELECT `inventoryID`  FROM $db.`WWM_survey_results` WHERE `inventoryID` = '$_POST[code]'";
			$result2 = mysql_query($sql2,$af);
			for ($x2=0; $x2 < mysql_num_rows($result2); $x2++) {
				$row2 = mysql_fetch_assoc($result2);
				$found = "1";
			}


			if ($found == "1") {
				print "<br><br>You have already completed the survey.<br><br>";
				die;
			}

      // My Aggressor Points - 10/30/2016 - RBS
      $today = date("Ymd");
      $sql7 = "INSERT INTO `$db`.`points_earned_log` (`contactID`,`points_earned`,`date`,`event_details`) VALUES 
      ('$contactID','100','$today','Completed Survey')";
      $result7 = mysql_query("$sql7", $af);
                                        
      $sql8 = "SELECT `points` FROM `$db`.`contacts` WHERE `contactID` = '$contactID'";
      $result8 = mysql_query("$sql8",$af);
      for ($x8=0; $x8 < mysql_num_rows($result8); $x8++) {
         $row8 = mysql_fetch_assoc($result8);
         $points = $row8['points'] + 100;
         $sql9 = "UPDATE `$db`.`contacts` SET `points` = '$points' WHERE `contactID` = '$contactID'";
         $result9 = mysql_query("$sql9",$af);         
      }
     // end points

		print_r($row);
			// Insert
			$sql = "
			INSERT INTO $db.`WWM_survey_results` (

			`inventoryID`,`boatID`,`start_date`,`end_date`,
			`ans_1`,`ans_3`,`ans_4a`,`ans_4b`,`ans_5`,`ans_6`,`ans_7`,`ans_8`,`ans_9`,`ans_10`,`ans_11`,`ans_12`,`ans_gift`,`ans_15`,
			`ans_16`,`ans_17`,`ans_18`,`ans_19`,`ans_20`,`ans_21`,`ans_22`,`ans_23`,`ans_24`
			)

			VALUES (
			'$_POST[code]','$row[boatID]','$row[start_date]','$row[end_date]',
			'$_POST[q2]','$_POST[q9]','$_POST[q11a]','$_POST[q11b]','$_POST[q7a]','$_POST[q7b]','$_POST[q7c]','$_POST[q7d]','$_POST[q8]','$_POST[company]','$_POST[q4]','$_POST[q5]','$_POST[donate]','$_POST[q14]',
			'$_POST[q15]','$_POST[q10a]','$_POST[q10b]','$_POST[q6]','$_POST[q1]','$_POST[q4b]','$_POST[q22]','$_POST[q16]','$_POST[q17]'
			)
			";
		//	die($sql);
			$result2 = mysql_query("$sql", $af);
			if ($result2 == "TRUE") {

				for ($r=0; $r < 30; $r++) {
					$i = "q12a_";
					$i .= $r;
					$mag[$r] = $_POST[$i];
				}

            for ($r=0; $r < 30; $r++) {
               $i = "q13a_";
               $i .= $r;
               $site[$r] = $_POST[$i];
            }
			

				$sql3 = "
				INSERT INTO $db.`WWM_survey_publications` (

				`inventoryID`,`boatID`,`start_date`,`end_date`,
				`mag_1`,`mag_2`,`mag_3`,`mag_4`,`mag_5`,`mag_6`,`mag_8`,`mag_9`,`mag_10`,`mag_11`,`mag_13`,`mag_14`,`mag_15`,`mag_16`,`mag_17`,`mag_18`,`mag_19`,`mag_20`,`mag_21`,`mag_22`,`mag_23`,
				`mag_other`,
				`site_1`,`site_2`,`site_3`,`site_4`,`site_5`,`site_6`,`site_7`,`site_8`,`site_9`,`site_10`,`site_11`,`site_12`,`site_13`,`site_14`,`site_15`,`site_16`,`site_17`,
				`site_other`
				)

				VALUES (
				'$_POST[code]','$row[boatID]','$row[start_date]','$row[end_date]',
				'$mag[0]','$mag[1]','$mag[2]','$mag[3]','$mag[4]','$mag[5]','$mag[6]','$mag[7]','$mag[8]','$mag[9]','$mag[10]','$mag[11]','$mag[12]','$mag[13]','$mag[14]','$mag[15]','$mag[16]','$mag[17]','$mag[18]',
				'$mag[19]','$mag[20]',

				'$_POST[q12b]',

				'$site[0]','$site[1]','$site[2]','$site[3]','$site[4]','$site[5]','$site[6]','$site[7]','$site[8]','$site[9]','$site[10]','$site[11]','$site[12]','$site[13]','$site[14]','$site[15]','$site[16]',

				'$_POST[q13b]'
				)
				";
				$result3 = mysql_query("$sql3", $af);
				$submitted = date("Ymd");
				$result4 = mysql_query("UPDATE $db.`WWM_survey_codes` SET `submitted` = '$submitted' WHERE `inventoryID` = '$_POST[code]'", $af);

				print "<meta http-equiv=\"refresh\" content=\"0;url=http://www.aggressor.com/thankyou-survey.php\">";

				//include "thankyou.php";
			} else {
				$err = "<br><font color=red>There was an error saving your survey results. Please email <a href=\"mailto:info@aggressor.com\">info@aggressor.com</a>.</font><br>\n";
				include "error.php";
			}

			break;

      case "DF":
         $db = "peterhughes";
         $sql = "
         SELECT
            `survey_codes`.*,
            `vessels`.`vessel` AS 'name'

         FROM $db.`survey_codes`, $db.`vessels`

         WHERE
               `survey_codes`.`inventoryID` = '$_POST[code]'
               AND `survey_codes`.`submitted` IS NULL
               AND `survey_codes`.`boatID` = `vessels`.`vessel_id`
         ";
         $result = mysql_query("$sql", $df);
			for ($x=0; $x < mysql_num_rows($result); $x++) {
				$row = mysql_fetch_assoc($result);
			}

			$sql2 = "
			INSERT INTO $db.`survey_results` (
			`inventoryID`,`boatID`,`start_date`,`end_date`,
			`ans_1`,`ans_3`,`ans_4a`,`ans_4b`,`ans_5`,`ans_6`,`ans_7`,`ans_8`,`ans_9`,`ans_10`,`ans_11`,`ans_12`,`ans_gift`,`ans_15`,`ans_16`,`ans_17`,`ans_18`,`ans_19`,`ans_20`,`ans_21`)
			VALUES (
			'$_POST[code]','$row[boatID]','$row[start_date]','$row[end_date]',
			'$_POST[q2]','$_POST[q9]','$_POST[q11a]','$_POST[q11b]','$_POST[q7a]','$_POST[q7b]','$_POST[q7c]','$_POST[q7d]','$_POST[q8]','$row[company]','$_POST[q4]','$_POST[q5]','$_POST[donate]','$_POST[q14]',
			'$_POST[q15]','$_POST[q10a]','$_POST[q10b]','$_POST[q6]','$_POST[q1]','$_POST[q4b]'
			)
			";
			die($sql2);

         $result2 = mysql_query("$sql2", $df);
         if ($result2 == "TRUE") {

            for ($r=0; $r < 11; $r++) {
               $i = "q12a_";
               $i .= $r;
               $mag[$r] = $_POST[$i];
            }

            for ($r=0; $r < 7; $r++) {
               $i = "q13a_";
               $i .= $r;
               $site[$r] = $_POST[$i];
            }


            $sql3 = "
            INSERT INTO $db.`survey_publications` (

            `inventoryID`,`boatID`,`start_date`,`end_date`,
            `mag_1`,`mag_2`,`mag_3`,`mag_4`,`mag_5`,`mag_6`,`mag_8`,`mag_9`,`mag_10`,`mag_11`,`mag_12`,`mag_other`,
            `site_1`,`site_2`,`site_3`,`site_4`,`site_5`,`site_6`,`site_7`,`site_other`
            )

            VALUES (
            '$_POST[code]','$row[boatID]','$row[start_date]','$row[end_date]',
            '$mag[0]','$mag[1]','$mag[2]','$mag[3]','$mag[4]','$mag[5]','$mag[6]','$mag[7]','$mag[8]','$mag[9]','$mag[10]','$_POST[q12b]',
            '$site[0]','$site[1]','$site[2]','$site[3]','$site[4]','$site[5]','$site[6]','$_POST[q13b]'
            )
            ";
            $result3 = mysql_query("$sql3", $df);
            $submitted = date("Ymd");
            $result4 = mysql_query("UPDATE $db.`survey_codes` SET `submitted` = '$submitted' WHERE `inventoryID` = '$_POST[code]'", $df);

            include "thankyou.php";
         } else {
            $err = "<br><font color=red>There was an error saving your survey results. Please email <a href=\"mailto:robert@wayneworks.com\">robert@wayneworks.com</a>.</font><br>\n";
            include "error.php";
         }

         break;
      default:
         $err = "<br><font color=red>Sorry, I was unable to determin what cruize line you traveled with. Please email <a href=\"mailto:robert@wayneworks.com\">robert@wayneworks.com</a></font><br>";
         include "error.php";
         include "footer.inc.php";
         die;
   }
die;

}



include "footer.inc.php";
die;
?>



