<?php
//ob_start();

$linknull	= "http://www.kis.ac.th/img/untick.gif";
$linkyes	= "http://www.kis.ac.th/img/tick.jpg";
///////////////////////////// Contact Person Information : //////////////////////////////////////////////
$FName	= trim(addslashes($_POST['FName']));
$LName	= trim(addslashes($_POST['LName']));
$Address= trim(addslashes($_POST['Address']));
$Email	= trim(addslashes($_POST['Email']));

$cpi_button_relation	= $_POST['cpi_button_relation'];
$cpi_others				= stripslashes($_POST['cpi_others']);
$cpi_details			= $_POST['cpi_details'];
$cpi_button_english		= $_POST['cpi_button_english'];

$cpi_button_relation1	= "<img src='$linknull' width='13' height='13' />";
$cpi_button_relation2	= "<img src='$linknull' width='13' height='13' />";
$cpi_button_relation3   = "<img src='$linknull' width='13' height='13' />";

if($cpi_button_relation == "parent")
{
	$cpi_button_relation1 = "<img src='$linkyes' width='13' height='13' />";
}
elseif($cpi_button_relation == "guardian")
{
	$cpi_button_relation2 = "<img src='$linkyes' width='13' height='13' />";
}
elseif($cpi_button_relation == "others")
{
	$cpi_button_relation3 = "<img src='$linkyes' width='13' height='13' />";
}

$a	= "0";

$cpi_button_english1	= "<img src='$linknull' width='13' height='13' />";
$cpi_button_english2    = "<img src='$linknull' width='13' height='13' />";
$cpi_button_english3    = "<img src='$linknull' width='13' height='13' />";
$cpi_button_english4    = "<img src='$linknull' width='13' height='13' />";

if($cpi_button_english == "excellent")
{
	$cpi_button_english1 = "<img src='$linkyes' width='13' height='13' />";
}
elseif($cpi_button_english == "good")
{
	$cpi_button_english2 = "<img src='$linkyes' width='13' height='13' />";
}
elseif($cpi_button_english == "fair")
{
	$cpi_button_english3 = "<img src='$linkyes' width='13' height='13' />";
}
elseif($cpi_button_english == "none")
{
	$cpi_button_english4 = "<img src='$linkyes' width='13' height='13' />";
}
////////////////////////////// Top Three (3) Factors in Your Decision : ////////////////////////////////////////////////
$top3_box	= $_POST['top3_box'];

for($b=0;$b<11;$b++)
{
	if($top3_box[$b] == "")
	{
		$top3_box[$b]	= "<img src='$linknull' width='13' height='13' />";
	}
	else
	{
		$top3_box[$b]	= "<img src='$linkyes' width='13' height='13' />";
	}
}

$text_other	= $_POST['text_other'];

//////////////////////////////// Student Information : ///////////////////////////////////////////////
$si_name	= $_POST['si_name'];

$si_question1	= $_POST['si_question1'];
$si_question2	= $_POST['si_question2'];
$si_question3	= $_POST['si_question3'];
$si_question4a	= $_POST['si_question4a'];
$si_question4b	= $_POST['si_question4b'];
$si_question4c	= $_POST['si_question4c'];
$si_question5	= $_POST['si_question5'];
$si_question6	= $_POST['si_question6'];

$si_button_willgo	= $_POST['si_button_willgo'];

$si_button_willgo1    = "<img src='$linknull' width='13' height='13' />";
$si_button_willgo2    = "<img src='$linknull' width='13' height='13' />";

if($si_button_willgo == "local")
{
	$si_button_willgo1 = "<img src='$linkyes' width='13' height='13' />";
}
elseif($si_button_willgo == "abroad")
{
	$si_button_willgo2 = "<img src='$linkyes' width='13' height='13' />";
}

//////////////////////////////// Interested in School Bus Service? //////////////////////////////////////////////////
$school_bus	= $_POST['school_bus'];

$school_bus1	= "<img src='$linknull' width='13' height='13' />";
$school_bus2    = "<img src='$linknull' width='13' height='13' />";

if($school_bus == "yes")
{
	$school_bus1 = "<img src='$linkyes' width='13' height='13' />";
}
elseif($school_bus == "no")
{
	$school_bus2 = "<img src='$linkyes' width='13' height='13' />";
}

$bus_root	= $_POST['bus_root'];

//////////////////////////// When are you looking to enroll? /////////////////////////////////////////
$enroll_button	= $_POST['enroll_button'];

$enroll_button1	   = "<img src='$linknull' width='13' height='13' />";
$enroll_button2    = "<img src='$linknull' width='13' height='13' />";
$enroll_button3    = "<img src='$linknull' width='13' height='13' />";
$enroll_button4    = "<img src='$linknull' width='13' height='13' />";

if($enroll_button == "current")
{
	$enroll_button1 = "<img src='$linkyes' width='13' height='13' />";
}
elseif($enroll_button == "next")
{
	$enroll_button2 = "<img src='$linkyes' width='13' height='13' />";
}
elseif($enroll_button == "nextyear")
{
	$enroll_button3 = "<img src='$linkyes' width='13' height='13' />";
}
elseif($enroll_button == "undecided")
{
	$enroll_button4 = "<img src='$linkyes' width='13' height='13' />";
}

///////////////////////////  How much do you know about IB? /////////////////////////////////////////////////////////
$how_much	= $_POST['how_much'];

$how_much1	  = "<img src='$linknull' width='13' height='13' />";
$how_much2    = "<img src='$linknull' width='13' height='13' />";
$how_much3    = "<img src='$linknull' width='13' height='13' />";

if($how_much == "nothing")
{
	$how_much1 = "<img src='$linkyes' width='13' height='13' />";
}
elseif($how_much == "familiar")
{
	$how_much2 = "<img src='$linkyes' width='13' height='13' />";
}
elseif($how_much == "alot")
{
	$how_much3 = "<img src='$linkyes' width='13' height='13' />";
}

/////////////////////////////// How did you hear about KIS? ///////////////////////////////////////////////////
$how_hear	= $_POST['how_hear'];

for($d=0;$d<11;$d++)
{
	if($how_hear[$d] == "")
	{
		$how_hear[$d]	= "<img src='$linknull' width='13' height='13' />";
	}
	else
	{
		$how_hear[$d]	= "<img src='$linkyes' width='13' height='13' />";
	}
}


/////////////////////////// visited_1 ////////////////////////////////////////////////////////////////////
$visited_1	= $_POST['visited_1'];
$visited_2	= $_POST['visited_2'];
$visited_3	= $_POST['visited_3'];


$from = $Email;
$Subject = "KIS Inquiry Form";

$headers = "MIME-Version: 1.0\r\n".
   "Content-type: text/html; charset=iso-8859-1\r\n".
   "From: <".$from.">\r\n";

$TO = "pitchayat@anet.net.th, psanti@anet.net.th,testmail@sakura.co.th";

$message = '
<div style="font-family:Arial, Helvetica, sans-serif;font-size:12px;">


<div ><img src="http://www.kis.ac.th/img/app_header.gif" width="848" height="122" /></div>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td valign="top">

	    <table width="100%" border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td align="center" class="style5">Family Inquiry Form</td>
          </tr>
          <tr>
            <td align="center" class="style7">Thank you for your interest in KIS. The following information will help us in the inquiry process.</td>
          </tr>
          <tr>
            <td bgcolor="#9ACCFF" class="style11"  style="border:1px solid  #666666"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="57%"><span class="style3">Contact Person Information :</span></td>
                  <td width="43%"><span class="style1">Top Three (3) Factors in Your Decision :</span></td>
                </tr>
            </table></td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="57%"><table width="100%" border="0" cellspacing="2" cellpadding="0">
                  <tr>
                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>'.$cpi_button_relation1.' Parent</td>
                        <td>'.$cpi_button_relation2.' Guardian</td>
                        <td>'.$cpi_button_relation3.' Others : '.$cpi_others.'</td>
                      </tr>
                    </table></td>
                  </tr>
                  <tr>
                    <td><table width="100%" border="0" cellspacing="2" cellpadding="2">
                      <tr>
                        <td width="49%"><strong>First Name :</strong>'.$FName.'</td>
                        <td width="51%"><strong>Last Name :</strong>'.$LName.'</td>
                      </tr>
                      <tr>
                        <td colspan="2"><strong>Address :</strong></td>
                        </tr>
						<tr>
                        <td colspan="2">'.$Address.'</td>
                        </tr>
                      <tr>
                        <td><strong>Home Phone :</strong>'.$cpi_details[$a].'';
						$a++;
						
						$message .= '</td>
                        <td><strong>Work Phone :</strong> '.$cpi_details[$a].'';
						 $a++;
						 
						 
						 $message .= '</td>
                      </tr>
                      <tr>
                        <td><strong>Mobile :</strong>'.$cpi_details[$a].'';
						 $a++;
						 
						 $message .= '</td>
                        <td><strong>Fax :</strong> '.$cpi_details[$a].'';
						 $a++;
						 
						 $message .= '</td>
                      </tr>
                    </table></td>
                  </tr>
                  <tr>
                    <td><strong>Email : </strong>'.$Email.'</td>
                  </tr>
                  <tr>
                    <td><strong>Level of English:</strong> &nbsp;&nbsp;
                      '.$cpi_button_english1.' Excellent &nbsp;
                      '.$cpi_button_english2.' Good &nbsp;
                      '.$cpi_button_english3.' Fair &nbsp;
                      '.$cpi_button_english4.' None &nbsp;</td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                  </tr>
                </table></td>
                <td width="43%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
                  <tr>
                    <td width="40%">'.$top3_box[0].' Accessibility</td>
                    <td width="60%">'.$top3_box[1].' fee </td>
                  </tr>
                  <tr>
                    <td>'.$top3_box[2].' Class Size</td>
                    <td>'.$top3_box[3].' Student: Teacher ratio</td>
                  </tr>
                  <tr>
                    <td>'.$top3_box[4].' Curriculum</td>
                    <td>'.$top3_box[5].' School Atmosphere</td>
                  </tr>
                  <tr>
                    <td>'.$top3_box[6].' Facilities</td>
                    <td>'.$top3_box[7].' Reputation</td>
                  </tr>
                  <tr>
                    <td>'.$top3_box[8].'
                      Student Diversity</td>
                    <td>
                      '.$top3_box[9].' <strong>Other</strong>&nbsp;&nbsp;'.$text_other.'</td>
                  </tr>
                  <tr>
                    <td colspan="2">'.$top3_box[10].' Foreign language acquisition</td>
                    </tr>
                </table></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td bgcolor="#9ACCFF" style="border:1px solid #666666" gcolor="#9ACCFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><strong>Student Information : </strong></td>
                </tr>
            </table></td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><table width="100%" border="0" cellspacing="0" cellpadding="2">
                    <tr>
                      <td><table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#9ACCFF" >
                          <tr>
                            <td width="22%" align="center" ><strong>Child\'s Name (Nickname) </strong></td>
                            <td width="14%" align="center" ><strong>Date of Birth </strong></td>
                            <td width="14%" align="center" ><strong>Nationality</strong></td>
                            <td width="24%" align="center" ><strong>Current School &amp; Country </strong></td>
                            <td width="12%" align="center" ><strong>Grade Level </strong></td>
                            <td width="14%" align="center" ><strong>Level of English </strong></td>
                          </tr>';
				
					  $k = 0;
					  for($i=1;$i<4;$i++)
					  {
                            $message .=  '<tr>
                                <td width="22%" height="25" align="left">'.stripslashes($si_name[$k]).'';
								$k++;
								$message .= '</td>
                                <td width="14%" height="25" align="left">'.stripslashes($si_name[$k]).'';
								 $k++;
								 
								 $message .='</td>
                                <td width="14%" height="25" align="left">'.stripslashes($si_name[$k]).'';
								 $k++;
								 
								 $message .='</td>
                                <td width="24%" height="25" align="left">'.stripslashes($si_name[$k]).'';
								 $k++;
								 $message .='</td>
                                <td width="12%" height="25" align="left">'.stripslashes($si_name[$k]).'';
								 $k++;
								 
								 $message .='</td>
                                <td width="14%" height="25" align="left">'.stripslashes($si_name[$k]).'';
								 $k++;
								 
								 $message .='</td>
                              </tr>';
                      }
					  
                      $message .= '</table></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>

                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td><strong>1. What other languages does your child (ren) currently speak? </strong></td>
                      </tr>
					<tr>
                      <td>&nbsp;&nbsp;&nbsp;'.$si_question1.'</td>
                      </tr>
                    <tr>
                      <td><strong>2. Are you changing schools and if yes, what is the reason?</strong></td>
                      </tr>
					<tr>
                      <td>&nbsp;&nbsp;&nbsp;'.$si_question2.'</td>
                      </tr>
                    <tr>
                      <td><strong>3. How does your child (ren) feel about changing the school?</strong> </td>
                      </tr>
					<tr>
                      <td>&nbsp;&nbsp;&nbsp;'.$si_question3.'</td>
                      </tr>
                    <tr>
                      <td><strong>4. Who is responsible for making the decision? </strong>&nbsp;</td>
                    </tr>
                    <tr>
                      <td>&nbsp;&nbsp;&nbsp; Parents : '.$si_question4a.'
% &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Child : '.$si_question4b.'
% &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Others : '.$si_question4c.'
%</td>
                    </tr>
                    <tr>
                      <td><strong>5. How long will your child attend KIS?</strong></td>
                      </tr>
					<tr>
                      <td>&nbsp;&nbsp;&nbsp; '.$si_question5.'</td>
                      </tr>
                    <tr>
                      <td><strong>6. Where will your child go after secondary school? </strong>&nbsp;</td>
                    </tr>
                    <tr>
                      <td>&nbsp;&nbsp;&nbsp; '.$si_button_willgo1.'&nbsp;
Local University &nbsp;
'.$si_button_willgo2.'
&nbsp;<strong>Abroad (country) :</strong> &nbsp;
'.$si_question6.'</td>
                    </tr>
                </table></td>
                </tr>
            </table></td>
          </tr>
          <tr>
            <td  bgcolor="#9ACCFF" style="border:1px solid #666666" gcolor="#9ACCFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="33%"><strong>Interested in School Bus Service?</strong></td>
                      <td width="32%"><strong>When are you looking to enroll?</strong></td>
                      <td width="35%"><strong>How much do you know about IB?</strong></td>
                    </tr>
                </table></td>
              </tr></table></td></tr>
			  <tr>
			  	<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><table width="100%" border="0" cellspacing="1" cellpadding="2">
                    <tr>
                      <td width="33%">'.$school_bus1.'
                        Yes</td>
                      <td width="32%">'.$enroll_button1.' Current Term </td>
                      <td width="35%">'.$how_much1.' Nothing</td>
                    </tr>
                    <tr>
                      <td>'.$school_bus2.' 
                        No</td>
                      <td>'.$enroll_button2.' Next Term </td>
                      <td>'.$how_much2.' Familiar</td>
                    </tr>
                    <tr>
                      <td><strong>If yes, please list location</strong> </td>
                      <td>'.$enroll_button3.' Next Academic Year </td>
                      <td>'.$how_much3.' A lot, it is the reason </td>
                    </tr>
                    <tr>
                      <td>'.$bus_root.'</td>
                      <td>'.$enroll_button4.' Undecided</td>
                      <td>we are interest in KIS </td>
                    </tr>
                </table></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>

            </table></td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="2">
              <tr bgcolor="#9ACCFF" style="border:1px solid #666666" gcolor="#9ACCFF">
                <td bgcolor="#9ACCFF" style="border:1px solid #666666" gcolor="#9ACCFF"><table width="100%" border="0" cellspacing="0" cellpadding="2">
                    <tr>
                      <td width="65%"><strong>How did you hear about KIS?</strong></td>
                      <td width="35%"><strong>Other schools you will visit / have visited</strong></td>
                    </tr>
                </table></td>
              </tr>
              <tr>
                <td><table width="100%" border="0" cellspacing="0" cellpadding="2">
                    <tr>
                      <td width="65%"><table width="100%" cellspacing="1" cellpadding="2">
                        <tr>
                          <td width="34%">'.$how_hear[0].' Embassy</td>
                          <td width="32%">'.$how_hear[1].' Word of Mouth</td>
                          <td width="34%">'.$how_hear[2].' Advertisement</td>
                        </tr>
                        <tr>
                          <td>'.$how_hear[3].' Location</td>
                          <td>'.$how_hear[4].' KIS Sibling</td>
                          <td>'.$how_hear[5].' Exhibition</td>
                        </tr>
                        <tr>
                          <td>'.$how_hear[6].' ISAT</td>
                          <td>'.$how_hear[7].' Relocation Agent</td>
                          <td>'.$how_hear[8].' Others</td>
                        </tr>
                        <tr>
                          <td>'.$how_hear[9].' Internet / KIS Website</td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                        </tr>
                      </table></td>
                      <td width="35%"><table width="100%" cellspacing="0" cellpadding="2">
                        <tr>
                          <td>1. '.$visited_1.'</td>
                        </tr>
                        <tr>
                          <td>2. '.$visited_2.'</td>
                        </tr>
                        <tr>
                          <td>3. '.$visited_3.'</td>
                        </tr>
                        <tr>
                          <td>&nbsp;</td>
                        </tr>
                      </table></td>
                    </tr>
                    
                </table></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><strong>For Office Use Only</strong></td>
                      </tr>
                </table></td>
              </tr>
              <tr>
                <td bgcolor="#9ACCFF" style="border:1px solid #666666" gcolor="#9ACCFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><table width="100%" cellpadding="2" cellspacing="1" bgcolor="#9ACCFF">

                          <tr>
                            <td>Date : </td>
                            <td><input type="checkbox" name="checkbox1925" id="checkbox1925" />
                              Telephone</td>
                            <td>Grade Level(s) </td>
                            <td colspan="2"><input type="checkbox" name="checkbox19214" id="checkbox19214" />
                              Waiting List </td>
                            <td><input type="checkbox" name="checkbox19215" id="checkbox19215" />
                              Follow up </td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td><input type="checkbox" name="checkbox1926" id="checkbox1926" />
                              Walk-in</td>
                            <td><input type="checkbox" name="checkbox19210" id="checkbox19210" />
                              EY 1A, 1B, EY2 </td>
                            <td colspan="2">Term 1 2 3 </td>
                            <td><input type="checkbox" name="checkbox19216" id="checkbox19216" />
                              Will call us </td>
                          </tr>
                          <tr>
                            <td>Assisted by : </td>
                            <td><input type="checkbox" name="checkbox1927" id="checkbox1927" />
                              E-mail</td>
                            <td><input type="checkbox" name="checkbox19211" id="checkbox19211" />
                              Kindergarten</td>
                            <td>Year  </td>
                            <td>08-09 09-10</td>
                            <td><input type="checkbox" name="checkbox19217" id="checkbox19217" />
                              Assessment Test </td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td><input type="checkbox" name="checkbox1928" id="checkbox1928" />
                              Appointment</td>
                            <td><input type="checkbox" name="checkbox19212" id="checkbox19212" />
                              Grade 1 2 3 4 5 </td>
                            <td>&nbsp;</td>
                            <td>10-11 11-12 </td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td><input type="checkbox" name="checkbox1929" id="checkbox1929" />
                              KIS Event </td>
                            <td><input type="checkbox" name="checkbox19213" id="checkbox19213" />
                              Grade 6 7 8 9 10 11 12 </td>
                            <td colspan="2">&nbsp;</td>
                            <td>&nbsp;</td>
                          </tr>
                      </table></td>
                      </tr>
                </table></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
        </table>
 </td>
</tr></table>
</div>';

$ok = @mail($TO, $Subject, $message,$headers);

/*$fp = fopen("new.html","w+");
$cont = ob_get_contents(); 
$newh = fwrite($fp,$cont);
$files = array("new.html");////////////The attachement of two files//Remove one if needed
/////////////////////////////////////////////////////// email fields: to, from, subject, and so on
$from = "prasanth@e2mars.net";
$subject ="Family Inquiry Form";
$message = "There is one new 'Family Inquiry Form'.";
$headers = "From: $from";
/////////////////////////////////////////////////////// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
/////////////////////////////////////////////////////// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
/////////////////////////////////////////////////////// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
/////////////////////////////////////////////////////// preparing attachments
for($x=0;$x<count($files);$x++)
{
    $file = fopen($files[$x],"rb");
    $data = fread($file,filesize($files[$x]));
	fclose($file);
    $data = chunk_split(base64_encode($data));
    $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
    "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
    "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
    $message .= "--{$mime_boundary}\n";
}
$to	= "masood@e2mars.net";*/
/////////////////////////////////////////////////////// send
/*$ok = @mail($to, $subject, $message, $headers);*/
if ($ok) 
{
    $msg	= "The Application has been send Successfully.";
	header("Location:application_form.php?msg=$msg");
} 
else 
{
    $msg	= "There was an error while sendng the application.";
	header("Location:application_form.php?msg=$msg");
}


//echo $message;
header("Location:application_confirm.html");
?>