<?   
include('auth.php');
include('common.php');
$update_success=false;
$insert_success=false;

$lid = $_GET['lid'];
$empstatuschecked = array();

$mode="";
$SQL="SELECT * FROM learneremploy WHERE learner_id=".$_GET['lid'];
$results = llnb_query($SQL);
$row = llnb_fetch_assoc($results);
if ($row)
	$mode="edit";
else
	$mode="new";



if (count($_POST) > 0) //form has been submitted by user
{
	//prep the data regardless
	$empstatus= secure_user_input($_POST['empstatus']);
	$empstatuschecked[$empstatus]="checked";
	
	$occupation= secure_user_input($_POST['occupation']);
	$compname= secure_user_input($_POST['compname']);
	$address= secure_user_input($_POST['address']);
	$unit= secure_user_input($_POST['unit']);
	$pobox= secure_user_input($_POST['pobox']);
	$city= secure_user_input($_POST['city']);
	$prov= secure_user_input($_POST['prov']);
	$postalcode= secure_user_input($_POST['postalcode']);
	
	$ei = secure_user_input($_POST['ei']);
	if ($ei)
		$eiyes = "selected";
	else
		$eino  = "selected";
		
	$lid = $_POST['lid'];
	
	if ($mode == 'new')
	{
		$SQL = "INSERT INTO learneremploy
		(`learner_id`, 
		`empstatus`,		
		`occupation` ,
		`compname` ,
		`address` ,		
		`unit` ,		
		`pobox` 	,	
		`city` ,		
		`prov` 	,	
		`postalcode`,
		`ei` 	
		)			
		 VALUES 
		('".$lid."',
		 '".$empstatus."',
		 '".$occupation."',
		'".$compname."',
		 '".$address."',
		 '".$unit."',
		 '".$pobox."',
		 '".$city."',
		 '".$prov."',
		 '".$postalcode."',
		 '".$ei."'
	)";						

		if (!llnb_query($SQL))
			echo "ERROR on INSERT SQL";
		//echo $SQL;
		
		$insert_success=true;
		header("Location: ./learner_overview.php?lid=".$lid);

	}
	else if ($mode="edit" )
	{
		$SQL = "UPDATE learneremploy SET
		`learner_id` ='".$lid."',
		`empstatus`=		'".$empstatus."',
		`occupation` = '".$occupation."',
		`compname` = '".$compname."',
			`address`=		    '".$address."',
			`unit`=			    '".$unit."',
			`pobox`=		    '".$pobox."',
			`city`=			    '".$city."',
			`prov`=		    '".$prov."',
			`postalcode`= 		    '".$postalcode."',
			`ei`= 		    '".$ei."'
			WHERE learner_id=".$_POST['lid'];

		//echo $SQL;
		$results = llnb_query($SQL);
		$update_success = true;
		header("Location: ./learner_overview.php?lid=".$lid);

	}
	


}
else if (isset($_GET['lid']) && $mode !="new")
{
	$SQL="SELECT * FROM learneremploy WHERE learner_id=".$_GET['lid'];
	$results = llnb_query($SQL);
	$row = llnb_fetch_assoc($results);
	
	$empstatus= $row['empstatus'];
	$empstatuschecked[$empstatus]="checked";
	if ($row['ei'] == 1)
		$eiyes="checked";
	else
		$eino="checked";
		
	//prep the data regardless
		$empstatus= secure_user_input($row['empstatus']);
		$empstatuschecked[$empstatus]="checked";
		
		$occupation= secure_user_input($row['occupation']);
		$compname= secure_user_input($row['compname']);
		$address= secure_user_input($row['address']);
		$unit= secure_user_input($row['unit']);
		$pobox= secure_user_input($row['pobox']);
		$city= secure_user_input($row['city']);
		$prov= secure_user_input($row['prov']);
	$postalcode= secure_user_input($row['postalcode']);
}
?>




<!doctype html>
<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>
</head>
<body onLoad="document.forms.learneremploymentinfo.occupation.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>
    <a href="learner_list.php" class="btn lfl">Learner List</a>
    <a href="learner_overview.php?lid=<?=$lid?>" class="btn lfl">Learner Overview</a></nav>
  </header>
  <div role="main" id="main" class="clearfix">
    <div id="location">
      <H2><span>Learner:</span> <?= fetchLearnerName($lid); ?> </H2>
    </div>
    <!-- end of location -->
    <div>
    <H2>Employment Information</H2>
    
	 <form class="midform" name="learneremploymentinfo" action="learner_employmentinfo.php?lid=<?= $_GET['lid'];?>" method="POST">

        <label>What is your employment status?</label>
            
            <div  class="input moveright" >
            <ul>
            	<li><label class="radio"><input name="empstatus" type="radio" <?=$empstatuschecked[1];?> value="1">Full Time</label></li>
			<li><label class="radio"><input name="empstatus" type="radio" <?=$empstatuschecked[4];?> value="4">Self Employed</label></li>
            	<li><label class="radio"><input name="empstatus" type="radio" <?=$empstatuschecked[7];?> value="7">Retired</label></li>
            	<li><label class="radio"><input name="empstatus" type="radio" <?=$empstatuschecked[9];?> value="9">Other</label></li>
			</ul>	
    		</div>
            <div class="input moveright">
            <ul>
				<li><label class="radio"><input name="empstatus" type="radio" <?=$empstatuschecked[2];?> value="2">Part Time</label></li>
				<li><label class="radio"><input name="empstatus" type="radio" <?=$empstatuschecked[5];?> value="5">Unemployed</label></li>
				<li><label class="radio"><input name="empstatus" type="radio" <?=$empstatuschecked[8];?> value="8">Long Term Disability</label></li>
            </ul>
    		</div>
            <div  class="input moveright">
            <ul>
				<li><label class="radio"><input name="empstatus" type="radio" <?=$empstatuschecked[3];?> value="3">Seasonal</label></li>
				<li><label class="radio"><input name="empstatus" type="radio" <?=$empstatuschecked[6];?> value="6">Out of the Labour Market<br>
(ie. home wiht kids)</label></li>                
             </ul>
        </div>
        <!--</div>-->
    
      <div style="clear:both;"></div>
      <label>If employed, please answer question 2 &amp; 3. If not, please proceed to question 4</label>
      <div class="input">
        <label>Occupation Tile:</label>
        <input name="occupation" type="text"   value="<?= ($_POST['occupation']) ? stripslashes($_POST['occupation']) : $row['occupation'];?>" >
      </div>
      <div style="clear:both;"></div>
      <label>Current Employment Information</label>
      <div class="input">
        <label>Company Name:</label>
        <input name="compname" type="text"   value="<?= ($_POST['compname']) ? stripslashes($_POST['compname']) : $row['compname'];?>" class="midinp">
      </div>
      <div style="clear:both;"></div>
      <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>Unit.#:</label>
        <input name="unit" type="text"   value="<?= ($_POST['unit']) ? stripslashes($_POST['unit']) : $row['unit'];?>"  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 style="clear:both;"></div>
      
	<div class="input">
	    <label>Are you E.I. Eligible?</label>
		<label class="radio"><input name="ei" type="radio" value="1" <?=$eiyes;?> >Yes</label> 
		<label class="radio"><input name="ei" type="radio" value="0" <?=$eino;?> >No</label></div>
    <div style="clear:both;"></div>
            
      <p class="clearfix"><input type="submit" class="btn lfr" value="Save &amp; Close"> 
      <a href="learner_overview.php?lid=<?=$lid?>" class="btn lfr">Cancel</a></p>
   
   <input type="hidden" name="lid" value="<?=$lid;?>">
   </form>
  </div>
</div>
<!-- end of main -->
<aside>
</aside>
<div style="clear:both;"></div>
<footer>
  <?php include('footer.php'); ?>
</footer>
</div>
<!-- end of wrap --> 

<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline --> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script> 

<!-- scripts concatenated and minified via build script --> 
<script src="js/plugins.js"></script> 
<script src="js/script.js"></script> 
<!-- end scripts -->

</body>
</html>