<?   
include('auth.php');
include('common.php');

$update_success=false;
$insert_success=false;



if (count($_POST) > 0) //form has been submitted by user
{
	$FIELDS[0]="birth"; 
	$FIELDS[1]="startdate";	
	$FIELDS[2]="learnassessdate"; 
	$FIELDS[3]="learnconsentdate"; 
	$FIELDS[4]="confdate"; 
	
	//checkboxes
	$prog = $_POST['prog1']+$_POST['prog2'];

	if ($prog == 1 || $prog == 3)
		$literacychecked= "checked";
	if ($prog == 2  || $prog == 3)
		$eslchecked= "checked";
	
	//assemble all dates
	$startdate = $_POST['startyear']."-".$_POST['startmonth']."-".$_POST['startday'];
	$dob = $_POST['year']."-".$_POST['month']."-".$_POST['day'];
	$ladate = $_POST['layear']."-".$_POST['lamonth']."-".$_POST['laday'];
	$lcdate = $_POST['lcyear']."-".$_POST['lcmonth']."-".$_POST['lcday'];
	$cdate = $_POST['cyear']."-".$_POST['cmonth']."-".$_POST['cday'];

	//assemble phone numbers
	$homephone = $_POST['phone1'].$_POST['phone2'].$_POST['phone3'];
	$altphone = $_POST['cell1'].$_POST['cell2'].$_POST['cell3'];
	$workphone = $_POST['work1'].$_POST['work2'].$_POST['work3'];
	$refworkphone  = $_POST['refph1'].$_POST['refph2'].$_POST['refph3'];
	$clientofworkphone = $_POST['clientofph1'].$_POST['clientofph2'].$_POST['clientofph3'];
	
	//prep radio buttons
	$callhome= $_POST['callhome']; if ($callhome == 1) $callhomeyes = "checked"; if ($callhome == 0) $callhomeno = "checked"; 
	$callwork= $_POST['callwork']; if ($callwork == 1) $callworkyes = "checked"; if ($callwork == 0) $callworkno = "checked"; 
	$gender= $_POST['gender']; if ($gender == 1) $gendermale = "checked"; if ($gender == 0) $genderfemale = "checked"; 
	$mothertongue= $_POST['mothertongue'];  if ($mothertongue == 1) $langeng = "checked"; if ($mothertongue == 2) $langfr = "checked"; if ($mothertongue == 3) $langother = "checked"; 
	$crime= $_POST['crime']; if ($crime == 1) $crimeyes = "checked"; if ($crime == 0) $crimeno = "checked"; 
	$drinking= $_POST['drinking'];  if ($drinking == 1) $drinkingyes = "checked"; if ($drinking == 0) $drinkingno = "checked"; 
	$health= $_POST['health'];  if ($health == 1) $healthyes = "checked"; if ($health == 0) $healthno = "checked"; 
	$whyhelp= $_POST['whyhelp']; if ($whyhelp == 1) $whyhelp_pers = "checked"; if ($whyhelp == 2) $whyhelp_emp = "checked"; if ($whyhelp == 3) $whyhelp_ged = "checked"; if ($whyhelp == 4) $whyhelp_oth = "checked"; 
	$learnassess= $_POST['learnassess']; if ($learnassess == 1) $learnassess_yes = "checked"; if ($learnassess == 0) $learnassess_no = "checked"; 
	$learnconsent= $_POST['learnconsent']; if ($learnconsent == 1) $learnconsent_yes = "checked"; if ($learnconsent == 0) $learnconsent_no = "checked"; 
	$confform= $_POST['confform']; if ($confform == 1) $confform_yes = "checked"; if ($confform == 0) $confform_no = "checked"; 
	
	//prep the data regardless
	$firstname= secure_user_input($_POST['firstname']);
	$lastname= secure_user_input($_POST['lastname']);
	$address= secure_user_input($_POST['address']);
	$apt= secure_user_input($_POST['apt']);
	$pobox= secure_user_input($_POST['pobox']);
	$city= secure_user_input($_POST['city']);
	$prov= secure_user_input($_POST['prov']);
	$postalcode= secure_user_input($_POST['postalcode']);
	$email= secure_user_input($_POST['email']);
	$langother= secure_user_input($_POST['langother']);
	$crimeinfo= secure_user_input($_POST['crimeinfo']);
	$drinkinginfo= secure_user_input($_POST['drinkinginfo']);
	$healthinfo= secure_user_input($_POST['healthinfo']);
	$hobbies= secure_user_input($_POST['hobbies']);
	$whyhelpinfo= secure_user_input($_POST['whyhelpinfo']);
	$ref= secure_user_input($_POST['ref']);
	$refworker= secure_user_input($_POST['refworker']);
	$refemail= secure_user_input($_POST['refemail']);
	$clientof= secure_user_input($_POST['clientof']);
	$clientofworker= secure_user_input($_POST['clientofworker']);
	$clientofemail= secure_user_input($_POST['clientofemail']);
	$council= secure_user_input($_POST['council']);


	
	//Y-M-D in MYSQL
	//$time_date = date("Y-m-j G:i:s");

	if (!$firstname || !$lastname )
	{
		$mssg= "*** REQUIRED FIELDS MISSING ***";
		/*
		//need to grab start date, name and llnb id (readonly) fields
		$SQL="SELECT startdate, llnb_id, firstname, lastname FROM learner WHERE id=".$_POST['lid'];
		$results = llnb_query($SQL);
		$row = llnb_fetch_assoc($results);
		*/
	}
	else
	{
		if ($_GET['mode'] == 'new' && !$_POST['lid'])
		{
		

			$SQL = "INSERT INTO learner
			(`email`, 		
			`firstname`,		
			`lastname`, 		
			`startdate`,
			`active` ,
			`council_id` ,
			`address` ,		
			`apt` ,		
			`pobox` 	,	
			`city` ,		
			`prov` 	,	
			`postalcode`, 		
			`gender` 	,	
			`birth` 	,	
			`homephone` ,		
			`altphone`, 		
			`workphone` ,		
			`callathome`,		
			`callatwork`,		
			`lang` 	,	
			`langother` ,		
			`health` 	,	
			`healthinfo` ,		
			`hobbies` ,		
			`whyhelp` ,		
			`whyhelpinfo`, 	
			`prog`, 		
			`learnassess` ,	
			`learnassessdate`, 
			`learnconsent` ,	
			`learnconsentdate`,
			`confform` ,		
			`confdate`,		
			`ref` ,		
			`refworker` ,		
			`refphone` ,		
			`refemail` ,		
			`clientof` ,		
			`clientofworker`,	
			`clientofphone`,	
			`clientofemail`,	
			`crime` 		,
			`crimeinfo` ,		
			`drinking` ,		
			`drinkinginfo` )			
			 VALUES 
			('".$email."',
			 '".$firstname."',
			 '".$lastname."',
			'".$startdate."',
			 '1',
			 '".$council."',
			 '".$address."',
			 '".$apt."',
			 '".$pobox."',
			 '".$city."',
			 '".$prov."',
			 '".$postalcode."',
			 '".$gender."',
			 '".$dob."',
			 '".$homephone."',
			 '".$altphone."',
			 '".$workphone."',
			 '".$callhome."',
			 '".$callwork."',
			 '".$mothertongue."',
			 '".$langother."',
			 '".$health."',
			 '".$healthinfo."',
			 '".$hobbies."',
			 '".$whyhelp."',
			 '".$whyhelpinfo."',
			 '".$prog."',
			 '".$learnassess."',
			 '".$ladate."',
			 '".$learnconsent."',
			 '".$lcdate."',
			 '".$confform."',
			 '".$cdate."',
			 '".$ref."',
			 '".$refworker."',
			 '".$refworkphone."',
			 '".$refemail."',
			 '".$clientof."',
			 '".$clientofworker."',
			 '".$clientofworkphone."',
			 '".$clientofemail."',
			 '".$crime."',
			 '".$crimeinfo."',
			 '".$drinking."',
			 '".$drinkinginfo."')";						
		
			if (!llnb_query($SQL))
				echo "ERROR on INSERT SQL";
			
			$currentid = mysql_insert_id();
			$ccode = fetchCouncilCode($council);
			
			$llnbid = createLLNBID($ccode,$currentid);
			
			$SQL = "UPDATE learner SET 
				llnb_id = '".$llnbid."' WHERE id =".$currentid;
			$results = llnb_query($SQL);

			//deal with 0000-00-00 fields and make them null
			setDateNullFields($FIELDS, $currentid, "learner");	
			
			//add a status of active to status history
			//use start date if not empty
			if ($startdate == '--')
				$thedate = "CURDATE()";
			else
				$thedate = "'".$startdate."'";
						
			$SQL="INSERT INTO status
						(user_id, thestatus,usertype,thedate )
						VALUES 
			('".$currentid."', 1, '1', ".$thedate." )";
			$results = llnb_query($SQL);
		
		
			$insert_success=true;
			header("Location: ./learner_overview.php?lid=".$currentid);
		
		}
		else if ($_POST['lid'] && $_GET['mode'] == 'edit' )
		{
			$SQL = "UPDATE learner SET
				`email`= 		         '".$email."', 
				`firstname`=		    '".$firstname."',
				`lastname`= 		    '".$lastname."',
				`startdate`= 		    '".$startdate."',
				`active`=		    '1',
				`council_id`=		    '".$council."',
				`address`=		    '".$address."',
				`apt`=			    '".$apt."',
				`pobox`=		    '".$pobox."',
				`city`=			    '".$city."',
				`prov`=		    '".$prov."',
				`postalcode`= 		    '".$postalcode."',
				`gender`=		    '".$gender."',
				`birth`=		    '".$dob."',
				`homephone`=		    '".$homephone."',
				`altphone`= 		    '".$altphone."',
				`workphone`=		    '".$workphone."',
				`callathome`=		    '".$callhome."',
				`callatwork`=		    '".$callwork."',
				`lang`=		    '".$mothertongue."',
				`langother`=		    '".$langother."',
				`health`=		    '".$health."',
				`healthinfo`=		    '".$healthinfo."',
				`hobbies`=		    '".$hobbies."',
				`whyhelp`=		    '".$whyhelp."',
				`whyhelpinfo`= 	    '".$whyhelpinfo."',
				`prog`= 			    '".$prog."',
				`learnassess`=	    '".$learnassess."',
				`learnassessdate`= 	    '".$ladate."',
				`learnconsent`=	    '".$learnconsent."',
				`learnconsentdate`=	    '".$lcdate."',
				`confform`=		    '".$confform."',
				`confdate`=		    '".$cdate."',
				`ref`=			    '".$ref."',
				`refworker`=		    '".$refworker."',
				`refphone`=		    '".$refworkphone."',
				`refemail`=		    '".$refemail."',
				`clientof`=		    '".$clientof."',
				`clientofworker`=	    '".$clientofworker."',
				`clientofphone`=	    '".$clientofworkphone."',
				`clientofemail`=	    '".$clientofemail."',
				`crime`=	    '".$crime."',
				`crimeinfo`=		    '".$crimeinfo."',
				`drinking`=		    '".$drinking."',
				`drinkinginfo`=		    '".$drinkinginfo."'
				WHERE id=".$_POST['lid'];
			//echo $SQL;
			$results = llnb_query($SQL);
			
			//deal with 0000-00-00 fields and make them null
			setDateNullFields($FIELDS, $_POST['lid'], "learner");	
			
			$update_success = true;
			header("Location: ./learner_overview.php?lid=".$_POST['lid']);

		}
		
		
	}

}
else if (isset($_GET['lid']))
{
	$SQL="SELECT * FROM learner WHERE id=".$_GET['lid'];
	$results = llnb_query($SQL);
	$row = llnb_fetch_assoc($results);

	//create date pieces from DB
	$datepieces = explode("-", $row['birth']);
	$bmonth = $datepieces[1];
	$bday = $datepieces[2];
	$byear = $datepieces[0];

	$datepieces = explode("-", $row['learnassessdate']);
	$lamonth = $datepieces[1];
	$laday = $datepieces[2];
	$layear = $datepieces[0];
	
	$datepieces = explode("-", $row['learnconsentdate']);
	$lcmonth = $datepieces[1];
	$lcday = $datepieces[2];
	$lcyear = $datepieces[0];

	$datepieces = explode("-", $row['confdate']);
	$cmonth = $datepieces[1];
	$cday = $datepieces[2];
	$cyear = $datepieces[0];
	
	$datepieces = explode("-", $row['startdate']);
	$startmonth = $datepieces[1];
	$startday = $datepieces[2];
	$startyear = $datepieces[0];	

	//checkboxes
	$prog = $row['prog'];

	if ($prog == 1 || $prog == 3)
		$literacychecked= "checked";
	if ($prog == 2  || $prog == 3)
		$eslchecked= "checked";

	//assemble phone numbers
	$phnums = phonenumberToPieces($row['homephone']);
	$ph1 = $phnums[0]; $ph2 = $phnums[1]; $ph3 = $phnums[2]; 
	$phnums = phonenumberToPieces($row['altphone']);
	$c1 = $phnums[0]; $c2 = $phnums[1]; $c3 = $phnums[2]; 
	$phnums = phonenumberToPieces($row['workphone']);
	$w1 = $phnums[0]; $w2 = $phnums[1]; $w3 = $phnums[2]; 
	$phnums = phonenumberToPieces($row['clientofphone']);
	$clientofph1 = $phnums[0]; $clientofph2 = $phnums[1]; $clientofph3 = $phnums[2]; 
	$phnums = phonenumberToPieces($row['refphone']);
	$refph1 = $phnums[0]; $refph2 = $phnums[1]; $refph3 = $phnums[2]; 
	

	//prep radio buttons
	$callhome= $row['callathome']; if ($callhome == 1) $callhomeyes = "checked"; if ($callhome == 0) $callhomeno = "checked"; 
	$callwork= $row['callatwork']; if ($callwork == 1) $callworkyes = "checked"; if ($callwork == 0) $callworkno = "checked"; 
	$gender= $row['gender']; if ($gender == 1) $gendermale = "checked"; if ($gender == 0) $genderfemale = "checked"; 
	$mothertongue= $row['lang'];  if ($mothertongue == 1) $langeng = "checked"; if ($mothertongue == 2) $langfr = "checked"; if ($mothertongue == 3) $langother = "checked"; 
	$crime= $row['crime']; if ($crime == 1) $crimeyes = "checked"; if ($crime == 0) $crimeno = "checked"; 
	$drinking= $row['drinking'];  if ($drinking == 1) $drinkingyes = "checked"; if ($drinking == 0) $drinkingno = "checked"; 
	$health= $row['health'];  if ($health == 1) $healthyes = "checked"; if ($health == 0) $healthno = "checked"; 
	$whyhelp= $row['whyhelp']; if ($whyhelp == 1) $whyhelp_pers = "checked"; if ($whyhelp == 2) $whyhelp_emp = "checked"; if ($whyhelp == 3) $whyhelp_ged = "checked"; if ($whyhelp == 4) $whyhelp_oth = "checked"; 
	$learnassess= $row['learnassess']; if ($learnassess == 1) $learnassess_yes = "checked"; if ($learnassess == 0) $learnassess_no = "checked"; 
	$learnconsent= $row['learnconsent']; if ($learnconsent == 1) $learnconsent_yes = "checked"; if ($learnconsent == 0) $learnconsent_no = "checked"; 
	$confform= $row['confform']; if ($confform == 1) $confform_yes = "checked"; if ($confform == 0) $confform_no = "checked"; 
	
	//prep the data regardless
	$firstname= secure_user_input($row['firstname']);
	$lastname= secure_user_input($row['lastname']);
	$address= secure_user_input($row['address']);
	$apt= secure_user_input($row['apt']);
	$pobox= secure_user_input($row['pobox']);
	$city= secure_user_input($row['city']);
	$prov= secure_user_input($row['prov']);
	$postalcode= secure_user_input($row['postalcode']);
	$email= secure_user_input($row['email']);
	$langother= secure_user_input($row['langother']);
	$crimeinfo= secure_user_input($row['crimeinfo']);
	$drinkinginfo= secure_user_input($row['drinkinginfo']);
	$healthinfo= secure_user_input($row['healthinfo']);
	$hobbies= secure_user_input($row['hobbies']);
	$whyhelpinfo= secure_user_input($row['whyhelpinfo']);
	$ref= secure_user_input($row['ref']);
	$refworker= secure_user_input($row['refworker']);
	$refemail= secure_user_input($row['refemail']);
	$clientof= secure_user_input($row['clientof']);
	$clientofworker= secure_user_input($row['clientofworker']);
	$clientofemail= secure_user_input($row['clientofemail']);
	$council= secure_user_input($row['council_id']);
}
else //default values
{

	//assemble phone numbers
	$ph1 = "506";
	$c1 = "506";
	$w1 = "506";
	$clientofph1 = "506"; 
	$refph1 = "506";
}

?>


<!doctype html>
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->

<head>
<meta charset="utf-8">

<!-- Use the .htaccess and remove these lines to avoid edge case issues.
       More info: h5bp.com/i/378 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>LLNB System</title>
<meta name="description" content="">

<!-- Mobile viewport optimized: h5bp.com/viewport -->
<meta name="viewport" content="width=device-width, maximum-scale=1.0">

<!-- Place favicon.ico and apple-touch-icon.png in the root directory: mathiasbynens.be/notes/touch-icons -->
  <LINK REL="SHORTCUT ICON" HREF="favicon.ico">

<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/llnb-style.css">

<!-- More ideas for your <head> here: h5bp.com/d/head-Tips -->

<script src="js/libs/modernizr-2.5.3.min.js"></script>
<script>
	function hideSubmitButton()
	{
		
		self.document.getElementById("learnersubmitbutton").disabled=true;
		return true;
		
	}
</script>


</head>
<body onLoad="document.forms.learnerpersonalinfo.firstname.focus()">


<div id="wrap"> 
  <!-- Prompt IE 6 users to install Chrome Frame. Remove this if you support IE 6.
       chromium.org/developers/how-tos/chrome-frame-getting-started --> 
  <!--[if lt IE 7]><p class=chromeframe>Your browser is <em>ancient!</em> <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.</p><![endif]-->
  <header><a href="index.php" class="btn lfr" style="position:relative; top: 15px; right: 0;">Logout</a>
	<h1>Laubach Literacy - <?=uType();?></h1> 
	<h3><?=fetchCouncilName($_SESSION['council_id']);?></h3>
	
	<nav id="menu" class="clearfix navmenu">
    <a href="home.php" class="btn lfl">Home</a>
    <?
    		if ($_SESSION['ulevel'] == $_COORD || $_SESSION['ulevel'] == $_TUTOR)
		{
			$force_council= "?council=".$_SESSION['council_id'];
		}
		
   		if ($_SESSION['ulevel'] == $_TUTOR)
		{
		 	$hidefromtutor = "style=\"display: none\"";
		}
		
		
    ?>
    <a href="learner_list.php<?=$force_council;?>" class="btn lfl">Learner List</a>
    
    
    
    
    <?
    if ($_GET['mode'] != "new")
    {
    	 echo "<a href=\"learner_overview.php?lid=".$_GET['lid']."\" class=\"btn lfl\">Learner Overview</a></nav>";
    }
    ?>
  </header>
  <div role="main" id="main" class="clearfix">
    <?
    
    if ($_GET['mode'] != "new")
    {
		echo "
		    <div id=\"location\">
			 <H2><span>Learner:</span> ".$row['firstname']." ".$row['lastname']."</H2>
		    </div>";
    }
    ?>
    <!-- end of location -->
    <div>
    <H2>Personal Information</H2>
    <div style="color: red;"><?=$mssg;?></div>
    
    
    <form class="midform" name="learnerpersonalinfo" action="learner_personalinfo.php?mode=<?=$_GET['mode']; ?>&lid=<?= $_GET['lid'];?>" method="POST"  onSubmit="return hideSubmitButton();">

          <div class="input">
            <label style="display:block;">Start Date:</label>
            <select name="startmonth" title="month">
			<?
			$mymon = ($_POST['startmonth']) ? stripslashes($_POST['startmonth']) : $startmonth;
			echo buildMonthDropdown($mymon, $_MONTHS_abbr); 
			?>

            </select>
            <select name="startday" title="date">
				<?
				$myday = ($_POST['startday']) ? stripslashes($_POST['startday']) : $startday;
				echo buildDayDropdown($myday); 
				?>

            </select>
            <select name="startyear" title="Year">
				<?
				$myyear = ($_POST['startyear']) ? stripslashes($_POST['startyear']) : $startyear;
				echo buildYearDropdown($myyear, "2012"); 
				?>

            </select>
          </div>

    
    <div class="input plusleft">
    <label style="margin-right: 25px;">Council this learner is in:</label>
	  <?
		if ($_SESSION['ulevel'] == $_COORD || $_SESSION['ulevel'] == $_TUTOR)
		{
			$council = $_SESSION['council_id'];
			
			echo 
				"<strong>".fetchCouncilName($council)."</strong>
				<input type=\"hidden\" name=\"council\" readonly value=\"".$council."\">";
		}
		else
		{
			echo "<select name=\"council\">".buildCouncilDropdown($council)."</select>";
		}
	  ?>

	  
     </div>
     
     
     <div style="clear:both;"></div>

    <?
    if ($_GET['mode'] != "new")
    {
			echo "
			<div class=\"input\" ".$hidefromtutor.">
			   <label>ID:</label>
			   <input name=\"id\" type=\"text\" value=\"".$row['llnb_id']."\" class=\"midminp\" readonly>
			</div>

			<div class=\"input\" ".$hidefromtutor.">
			<label>Start Date</label>
			<input name=\"startdate\" type=\"text\" value=\"".$row['startdate']."\" readonly=\"readonly\" class=\"smminp\">
			</div>";

    }
    
    ?>
    <div style="clear:both;"></div>
      <div class="input" >
        <label class="mandatory">First Name:</label>
        <input name="firstname" type="text"   value="<?= ($_POST['firstname']) ? stripslashes($_POST['firstname']) : $row['firstname'];?>">
      </div>
      <div class="input">
        <label class="mandatory">Last Name:</label>
        <input name="lastname" type="text"   value="<?= ($_POST['lastname']) ? stripslashes($_POST['lastname']) : $row['lastname'];?>">
      </div>
      <div style="clear:both;"></div>


<div <?=$hidefromtutor;?>>
      <div class="input" >
        <label>Street Address:</label>
        <input name="address" type="text" value="<?= ($_POST['address']) ? stripslashes($_POST['address']) : $row['address'];?>" class="midinp">
      </div>
      <div class="input">
        <label>Apt.#:</label>
        <input name="apt" type="text"   value="<?= ($_POST['apt']) ? stripslashes($_POST['apt']) : $row['apt'];?>" class="ssminp">
      </div>
      <div class="input">
        <label>PO Box:</label>
        <input name="pobox" type="text"   value="<?= ($_POST['pobox']) ? stripslashes($_POST['pobox']) : $row['pobox'];?>" class="sminp">
      </div>
      <div style="clear:both;"></div>

      <div class="input">
        <label>City/Town:</label>
        <input name="city" type="text" value="<?= ($_POST['city']) ? stripslashes($_POST['city']) : $row['city'];?>" >
      </div>
      <div class="input">
        <label>Province:</label>
          <select name="prov" class="typevolunteer" title="prov">

			<?
			echo  buildProvDropdown($prov);
			?>
          </select>
        
      </div>
      <div class="input">
        <label>Postal Code:</label>
        <input name="postalcode" type="text" value="<?= ($_POST['postalcode']) ? stripslashes($_POST['postalcode']) : $row['postalcode'];?>" class="sminp">
      </div>
</div> <!-- END OF HIDE FROM TUTOR DIV-->
      <div style="clear:both;"></div>

      <div class="input">
        <label>Home Phone:</label>
        <input name="phone1" MAXLENGTH="3" type="text" value="<?= ($_POST['phone1']) ? stripslashes($_POST['phone1']) : $ph1;?>" class="ssminp">
        <input name="phone2" MAXLENGTH="3" type="text" value="<?= ($_POST['phone2']) ? stripslashes($_POST['phone2']) : $ph2;?>"  class="ssminp">
        <input name="phone3" MAXLENGTH="4" type="text" value="<?= ($_POST['phone3']) ? stripslashes($_POST['phone3']) : $ph3;?>" class="smminp">
      </div>
       
        <div class="input" style="margin-left:30px">
	        <label>May we call you at home?</label><label class="radio" style="margin-right:15px;">
	        <input name="callhome" type="radio" value="1" <?= $callhomeyes;?> >Yes</label><label class="radio">
	        <input name="callhome" type="radio" value="0" <?= $callhomeno; ?> >No</label>
        </div>
      
      <div style="clear:both;"></div>

      <div class="input">
        <label>Alternate Phone:</label>
        <input name="cell1" MAXLENGTH="3" type="text" value="<?= ($_POST['cell1']) ? stripslashes($_POST['cell1']) : $c1;?>" class="ssminp">
        <input name="cell2" MAXLENGTH="3" type="text" value="<?= ($_POST['cell2']) ? stripslashes($_POST['cell2']) : $c2;?>"  class="ssminp">
        <input name="cell3" MAXLENGTH="4" type="text" value="<?= ($_POST['cell3']) ? stripslashes($_POST['cell3']) : $c3;?>"  class="smminp">
      </div>
      <div style="clear:both;"></div>

      <div class="input">
        <label>Work Phone:</label>
        <input name="work1" MAXLENGTH="3" type="text" value="<?= ($_POST['work1']) ? stripslashes($_POST['work1']) : $w1;?>" class="ssminp">
        <input name="work2" MAXLENGTH="3" type="text" value="<?= ($_POST['work2']) ? stripslashes($_POST['work2']) : $w2;?>" class="ssminp">
        <input name="work3" MAXLENGTH="4" type="text" value="<?= ($_POST['work3']) ? stripslashes($_POST['work3']) : $w3;?>"  class="smminp">
      </div>
      <div class="input" style="margin-left:30px">
	        <label>May we call you at work?</label><label class="radio" style="margin-right:15px;">
	        <input name="callwork" type="radio" value="1" <?= $callworkyes;?>>Yes</label><label class="radio">
	        <input name="callwork" type="radio" value="0"  <?= $callworkno;?>>No</label>
        </div>

      <div style="clear:both;"></div>

      <div>
        <label>Email Address: *</label>
        <input name="email" type="text" value="<?= ($_POST['email']) ? stripslashes($_POST['email']) : $row['email'];?>" class="lrginp">
      </div>
      <div style="clear:both;"></div>
      
       	<div class="input">
	    <label>Gender</label>
		<label class="radio" style="margin-right:15px;">
		<input name="gender" type="radio" value="0" <?= $genderfemale;?> >Female</label>
		<label class="radio">
		<input name="gender" type="radio" value="1"  <?= $gendermale;?>>Male</label>
        </div>

      <div class="input plusleft" <?=$hidefromtutor;?>>
        <label style="display:block;">Date of Birth:</label>
        <select name="month" title="Month">
       	<?
       	$mymon = ($_POST['month']) ? stripslashes($_POST['month']) : $bmonth;
       	echo buildMonthDropdown($mymon, $_MONTHS_abbr); 
       	?>
        </select>
        <select name="day" title="Day">
       	<?
       	$myday = ($_POST['day']) ? stripslashes($_POST['day']) : $bday;
       	echo buildDayDropdown($myday); 
       	?>

        </select>
        <select name="year" title="Year">
       	<?
       	$myyear = ($_POST['year']) ? stripslashes($_POST['year']) : $byear;
       	$yrdefault = date('Y')-25;
       	echo buildYearDropdown($myyear, $yrdefault); 
       	?>
       </select>
       
      </div>
      
        
     <div style="clear:both;"></div>

     <div class="input" style="margin-right: 10px;">
	        <label>Mother Tongue:</label>
	<label class="radio"><input name="mothertongue" type="radio" value="1" <?= $langeng;?>>English</label>
	<label class="radio"><input name="mothertongue" type="radio" value="2" <?= $langfr;?>>French</label>
	<label class="radio"><input name="mothertongue" type="radio" value="3" <?= $langother;?>>Other</label>
	</div>

      <div class="input">
        <label>Other:</label>
        <input name="langother" type="text"  value="<?= ($_POST['langother']) ? stripslashes($_POST['langother']) : $row['langother'];?>" class="midinp">
      </div>
      
     <div style="clear:both;"></div>
<div  <?=$hidefromtutor;?>>
    <div class="input" style="margin-right: 10px;">
	        <label>Have you been convicted of a criminal offense for which you have not received a pardon?</label>
	<label class="radio">
	<input name="crime" type="radio" value="1" <?= $crimeyes;?> >Yes</label>
	<label class="radio">
	<input name="crime" type="radio" value="0" <?= $crimeno;?> >No</label> 
	<label class="radio">If Yes, Please specify (failing a Breathalyzer is a criminal offense)</label></div>
      <div class="input">
        <input name="crimeinfo" type="text" value="<?= ($_POST['crimeinfo']) ? stripslashes($_POST['crimeinfo']) : $row['crimeinfo'];?>" class="lrginp">
      </div>
 
     <div style="clear:both;"></div>

       <div class="input" style="margin-right: 10px;">
	        <label>Do you, at the present time, have a drinking or drug problem?</label>
	<label class="radio">
	<input name="drinking" type="radio" value="1"  <?= $drinkingyes;?> >Yes</label>
	<label class="radio">
	<input name="drinking" type="radio" value="0" <?= $drinkingno;?> >No</label> 
	<label class="radio">If Yes, Please explain.</label></div>
      <div class="input">
        <input name="drinkinginfo" type="text" value="<?= ($_POST['drinkinginfo']) ? stripslashes($_POST['drinkinginfo']) : $row['drinkinginfo'];?>" class="lrginp">
      </div>
      
     <div style="clear:both;"></div>

       <div class="input" style="margin-right: 10px;">
	        <label>Do you have any physical or mental health conditions you think we should be aware of?</label>
		<label class="radio">
		<input name="health" type="radio" value="1" <?= $healthyes;?> >Yes</label>
		<label class="radio">
		<input name="health" type="radio" value="0" <?= $healthno;?>>No</label>
		<label class="radio">If yes, then please provide details:</label></div>
      <div class="input">
        <input name="healthinfo" type="text" value="<?= ($_POST['healthinfo']) ? stripslashes($_POST['healthinfo']) : $row['healthinfo'];?>" class="lrginp">
      </div>
</div>


      <div style="clear:both;"></div>

      
      <div class="input">
        <label>What are your hobbies?</label>
        <input name="hobbies" type="text" value="<?= ($_POST['hobbies']) ? stripslashes($_POST['hobbies']) : $row['hobbies'];?>" value="Your Hobbies" class="lrginp">
      </div>
      <div style="clear:both;"></div>

<div  <?=$hidefromtutor;?>>
       <div class="input" style="margin-right: 10px; display: none;">
	<label class="radio">
	<input name="whyhelp" type="radio" value="1"  <?= $whyhelp_pers;?> >Personal</label>
	<label class="radio">
	<input name="whyhelp" type="radio" value="2" <?= $whyhelp_emp;?>>Employability</label> 
	<label class="radio">
	<input name="whyhelp" type="radio" value="3" <?= $whyhelp_ged;?>>GED</label>
	<label class="radio">
	<input name="whyhelp" type="radio" value="4" <?= $whyhelp_oth;?>>Other, please specify:</label>
	</div>
	
      <div class="input">
      	  <label>Why are you seeking help at this time?</label>

        <input name="whyhelpinfo" value="<?= ($_POST['whyhelpinfo']) ? stripslashes($_POST['whyhelpinfo']) : $row['whyhelpinfo'];?>" type="text"   class="lrginp">
      </div>
      <div style="clear:both;"></div>

      
       <div class="input" style="margin-right: 10px;">
	        <label>Which program does the learner fall under (click all that apply)?</label>
		<label class="radio">
		<input name="prog1" type="checkbox" value="1" <?= $literacychecked;?>>Literacy</label>
		<label class="radio">
		<input name="prog2" type="checkbox" value="2" <?= $eslchecked;?>>ESL</label> </div>
      <div style="clear:both;"></div>

      <div class="input" style="margin-right: 15px;">
	        <label>Learner Assessment completed.</label>
	<label class="radio">
	<input name="learnassess" type="radio" value="1"  <?= $learnassess_yes;?>>Yes</label>
	<label class="radio">
	<input name="learnassess" type="radio" value="0" <?= $learnassess_no;?>>No</label> </div>      <div class="input">
        <label style="display:block;">Date on form:</label>
        <select name="lamonth" title="Month">
       	<?
       	$lamymon = ($_POST['lamonth']) ? stripslashes($_POST['lamonth']) : $lamonth;
       	echo buildMonthDropdown($lamymon, $_MONTHS_abbr); 
       	?>

        </select>
        <select name="laday" title="Day">
       	<?
       	$lamyday = ($_POST['laday']) ? stripslashes($_POST['laday']) : $laday;
       	echo buildDayDropdown($lamyday); 
       	?>

        </select>
        <select name="layear" title="Year">
       	<?
       	$lamyyear = ($_POST['layear']) ? stripslashes($_POST['layear']) : $layear;
       	echo buildYearDropdown($lamyyear, date("Y")); 
       	?>

        </select>
      </div>
      <div style="clear:both;"></div>


     <div class="input" style="margin-right: 15px;">
	        <label>Confirmation signed and dated<br />in Learner intake application.</label><label class="mandatory">Please verify permission<br />limitation on Learner Consent<br />to Release of Information form.</label>
	<label class="radio">
	<input name="confform" type="radio" value="1" <?= $confform_yes;?>>Yes</label>
	<label class="radio">
	<input name="confform" type="radio" value="0" <?= $confform_no;?>>No</label> </div>
	<div class="input">
        <label style="display:block;">Date on form:</label>
        <select name="cmonth" title="month">
       	<?
       	$cmymon = ($_POST['cmonth']) ? stripslashes($_POST['cmonth']) : $cmonth;
       	echo buildMonthDropdown($cmymon, $_MONTHS_abbr); 
       	?>
        </select>
        <select name="cday" title="date">
       	<?
       	$cmyday = ($_POST['cday']) ? stripslashes($_POST['cday']) : $cday;
       	echo buildDayDropdown($cmyday); 
       	?>
        </select>
        <select name="cyear" title="Year">
       	<?
       	$cmyyear = ($_POST['cyear']) ? stripslashes($_POST['cyear']) : $cyear;
       	echo buildYearDropdown($cmyyear, date("Y")); 
       	?>
        </select>
      </div>
      <div style="clear:both;"></div>
      <div class="input" style="margin-right: 15px;">
	        <label>Learner Consent to Release of Information<br />signed and dated. (PETL Release Consent Form)</label>
	<label class="radio">
	<input name="learnconsent" type="radio" value="1"  <?= $learnconsent_yes;?>>Yes</label>
	<label class="radio">
	<input name="learnconsent" type="radio" value="0" <?= $learnconsent_no;?>>No</label> </div>
	<div class="input">
        <label style="display:block;">Date on form:</label>
        <select name="lcmonth" title="Month">
       	<?
       	$lcmymon = ($_POST['lcmonth']) ? stripslashes($_POST['lcmonth']) : $lcmonth;
       	echo buildMonthDropdown($lcmymon, $_MONTHS_abbr); 
       	?>
        </select>
        <select name="lcday" title="Day">
       	<?
       	$lcmyday = ($_POST['lcday']) ? stripslashes($_POST['lcday']) : $lcday;
       	echo buildDayDropdown($lcmyday); 
       	?>
	    </select>
        <select name="lcyear" title="Year">
       	<?
       	$lcmyyear = ($_POST['lcyear']) ? stripslashes($_POST['lcyear']) : $lcyear;
       	echo buildYearDropdown($lcmyyear, date("Y")); 
       	?>
        </select>
      </div>
      <div style="clear:both;"></div>


      
    <label style="display:block;">Referral Source:</label>
      <select name="ref" class="" title="referral source">
	<? echo buildRefSourceDropdown($ref);?>

    </select>
    <div style="clear:both;"></div>

      <div class="input">
        <label>More Infomation:</label>
        <input name="refmoreinfo" type="text" value="<?= ($_POST['refmoreinfo']) ? stripslashes($_POST['refmoreinfo']) : $row['refmoreinfo'];?>"  class="lrginp">
      </div>
    <div style="clear:both;"></div>

    
      <div class="input">
        <label>Case Worker:</label>
        <input name="refworker"  value="<?= ($_POST['refworker']) ? stripslashes($_POST['refworker']) : $row['refworker'];?>"  type="text"   class="lrginp">
      </div>
    <div style="clear:both;"></div>

      <div class="input">
        <label>Work Phone:</label>
        <input name="refph1" MAXLENGTH="3" value="<?= ($_POST['refph1']) ? stripslashes($_POST['refph1']) : $refph1;?>" type="text" class="ssminp">
        <input name="refph2" MAXLENGTH="3" value="<?= ($_POST['refph2']) ? stripslashes($_POST['refph2']) : $refph2;?>"  type="text"  class="ssminp">
        <input name="refph3" MAXLENGTH="4"  value="<?= ($_POST['refph3']) ? stripslashes($_POST['refph3']) : $refph3;?>"  type="text" class="smminp">
      </div>
            <div class="input">
        <label>Email Address: </label>
        <input name="refemail" value="<?= ($_POST['refemail']) ? stripslashes($_POST['refemail']) : $row['refemail'];?>"  type="text"   value="Email Address">
      </div>
    <div style="clear:both;"></div>


    <label style="display:block;">Client of:</label>
        <select name="clientof" class="" title="Client of">
	<? echo buildClientOfDropdown($clientof);?>

    </select>
    <div style="clear:both;"></div>
    
      <div class="input">
        <label>More Infomation:</label>
        <input name="clientofmoreinfo" type="text" value="<?= ($_POST['clientofmoreinfo']) ? stripslashes($_POST['clientofmoreinfo']) : $row['clientofinfo'];?>"  class="lrginp">
      </div>
    <div style="clear:both;"></div>

    
      <div class="input">
        <label>Case Worker:</label>
        <input name="clientofworker" type="text"    value="<?= ($_POST['clientofworker']) ? stripslashes($_POST['clientofworker']) : $row['clientofworker'];?>"  class="lrginp">
      </div>
    <div style="clear:both;"></div>

      <div class="input">
        <label>Work Phone:</label>
        <input name="clientofph1" MAXLENGTH="3" type="text" value="<?= ($_POST['clientofph1']) ? stripslashes($_POST['clientofph1']) : $clientofph1;?>"  class="ssminp">
        <input name="clientofph2" MAXLENGTH="3" type="text" value="<?= ($_POST['clientofph2']) ? stripslashes($_POST['clientofph2']) : $clientofph2;?>" class="ssminp">
        <input name="clientofph3" MAXLENGTH="4" type="text" value="<?= ($_POST['clientofph3']) ? stripslashes($_POST['clientofph3']) : $clientofph3;?>"  class="smminp">
      </div>
            <div class="input">
        <label>Email Address: </label>
        <input name="clientofemail" type="text"   value="<?= ($_POST['clientofemail']) ? stripslashes($_POST['clientofemail']) : $row['clientofemail'];?>" >
      </div>
</div>
    <div style="clear:both;"></div>
            
      <p><input type="submit" id="learnersubmitbutton"  class="btn lfr" value="Save &amp; Close">
      
     <?
	     if ($_GET['mode'] != "new")
	         	 $cancel= "<a href=\"learner_overview.php?lid=".$_GET['lid']."\" class=\"btn lfr\">Cancel</a>";
	     else
	        	 $cancel= "<a href=\"learner_list.php\" class=\"btn lfr\">Cancel</a>";
     ?>
      <?=$cancel;?></p>
      
      <input type="hidden" name="lid" value="<?=$_GET['lid']; ?>">
 
 </form>
  </div>
</div>
<!-- end of main -->
    <div style="clear:both;"></div>
<footer>
  <?php include('footer.php'); ?>
</footer>
</div>


</body>
</html>