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

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

$mode="";
$SQL="SELECT * FROM volunteeremploy WHERE volunteer_id=".$_GET['vid'];
$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']);
	$compnameprev= secure_user_input($_POST['compnameprev']);
	$addressprev= secure_user_input($_POST['addressprev']);
	$unitprev= secure_user_input($_POST['unitprev']);
	$poboxprev= secure_user_input($_POST['poboxprev']);
	$cityprev= secure_user_input($_POST['cityprev']);
	$provprev= secure_user_input($_POST['provprev']);
	$postalcodeprev= secure_user_input($_POST['postalcodeprev']);	
	$workexpinfo= secure_user_input($_POST['workexpinfo']);	
	$contactempinfo= secure_user_input($_POST['contactempinfo']);	
	$contactemp = secure_user_input($_POST['contactemp']);

	if ($contactemp)
		$contactempyes = "checked";
	else
		$contactempno  = "checked";

	$workexp = secure_user_input($_POST['workexp']);
	if ($workexp)
		$workexpyes = "checked";
	else
		$workexpno  = "checked";	


	$vid = $_POST['vid'];
	
	if (!$compname)
		$mssg= "*** REQUIRED FIELDS MISSING ***";
	else
	{
		if ($mode == 'new')
		{
			$SQL = "INSERT INTO volunteeremploy
			(`volunteer_id`, 
			`empstatus`,		
			`occupation` ,
			`compname` ,
			`address` ,		
			`unit` ,		
			`pobox` 	,	
			`city` ,		
			`prov` 	,	
			`postalcode`,
			`compnameprev`,
			`addressprev`,		
			`unitprev`,		
			`poboxprev`,	
			`cityprev`,		
			`provprev`,	
			`postalcodeprev`,
			`contactemp`,
			`contactempinfo`,
			`workexp`,
			`workexpinfo`		)			
			 VALUES 
			('".$vid."',
			 '".$empstatus."',
			 '".$occupation."',
			'".$compname."',
			 '".$address."',
			 '".$unit."',
			 '".$pobox."',
			 '".$city."',
			 '".$prov."',
			 '".$postalcode."',
			 '".$compnameprev."',
			  '".$addressprev."',
			 '". $unitprev."',
			 '". $poboxprev."',
			 '". $cityprev."',
			 '". $provprev."',
			 '". $postalcodeprev."',
			 '". $contactemp."',
			 '". $contactempinfo."',
			 '". $workexp."',
			 '". $workexpinfo."'	)";						

			if (!llnb_query($SQL))
				echo "ERROR on INSERT SQL";
			//echo $SQL;

			$insert_success=true;
			header("Location: ./volunteer_overview.php?vid=".$vid);

		}
		else if ($mode="edit" )
		{
			$SQL = "UPDATE volunteeremploy SET
			`volunteer_id` ='".$vid."',
			`empstatus`=		'".$empstatus."',
			`occupation` = '".$occupation."',
			`compname` = '".$compname."',
				`address`=		    '".$address."',
				`unit`=			    '".$unit."',
				`pobox`=		    '".$pobox."',
				`city`=			    '".$city."',
				`prov`=		    '".$prov."',
				`postalcode`= 		    '".$postalcode."',
				 `compnameprev`=		'".$compnameprev."',
				  `addressprev`=		'".$addressprev."',
				 `unitprev`=			'". $unitprev."',
				 `poboxprev`=			'". $poboxprev."',
				 `cityprev`=			'". $cityprev."',
				 `provprev`=			'". $provprev."',
				 `postalcodeprev`=		'". $postalcodeprev."',
				 `contactemp`=		'". $contactemp."',
				 `contactempinfo`=		'". $contactempinfo."',			
				 `workexp`=			'". $workexp."',			
				`workexpinfo`=					'". $workexpinfo."'				
				WHERE volunteer_id=".$_POST['vid'];

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

		}
	}	
}
else if (isset($_GET['vid']) && $mode !="new")
{
	$SQL="SELECT * FROM volunteeremploy WHERE volunteer_id=".$_GET['vid'];
	$results = llnb_query($SQL);
	$row = llnb_fetch_assoc($results);
	
	$empstatus= $row['empstatus'];
	
	$empstatuschecked[$empstatus]="checked";
	if ($row['ei'] == 1)
		$eiyes="checked";
	else
		$eino="checked";
		
	$workexp = secure_user_input($row['workexp']);
	if ($workexp)
		$workexpyes = "checked";
	else
		$workexpno  = "checked";	

	$contactemp = secure_user_input($row['contactemp']);
	if ($contactemp)
		$contactempyes = "checked";
	else
		$contactempno  = "checked";		
		
		
		$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']);
		
		$compnameprev= secure_user_input($row['compnameprev']);
		$addressprev= secure_user_input($row['addressprev']);
		$unitprev= secure_user_input($row['unitprev']);
		$poboxprev= secure_user_input($row['poboxprev']);
		$cityprev= secure_user_input($row['cityprev']);
		$provprev= secure_user_input($row['provprev']);
		$postalcodeprev= secure_user_input($row['postalcodeprev']);	
		$workexpinfo= secure_user_input($row['workexpinfo']);	
		$contactempinfo= secure_user_input($row['contactempinfo']);	

}
?>




<!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.volunteeremploymentinfo.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="volunteer_list.php" class="btn lfl">Volunteer List</a>
    <a href="volunteer_overview.php?vid=<?=$vid?>" class="btn lfl">Volunteer Overview</a></nav>
  </header>
  <div role="main" id="main" class="clearfix">
    <div id="location">
      <H2><span>Volunteer:</span> <?= fetchVolName($vid); ?> </H2>
    </div>
    <!-- end of location -->
    <div>
    <H2>Employment Information</H2>
       <div style="color: red;"><?=$mssg;?></div>

    
	 <form class="midform" name="volunteeremploymentinfo" action="volunteer_employmentinfo.php?vid=<?= $_GET['vid'];?>" 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 with kids)</label></li>                
             </ul>
        </div>
        <!--</div>-->
    
      <div style="clear:both;"></div>
      <label>If employed, please answer question 2 - 5. If not, please proceed to question 6.</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 class="mandatory">Company Name:</label>
        <input name="compname" type="text" class="mandatory"  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>
   
      <label>If employed less than one year, or if retired please give previous employer details.</label>
      <div class="input">
        <label>Company Name:</label>
        <input name="compnameprev" type="text"   value="<?= ($_POST['compnameprev']) ? stripslashes($_POST['compnameprev']) : $row['compnameprev'];?>" class="midinp">
      </div>
      <div style="clear:both;"></div>
      <div class="input">
        <label>Street Address:</label>
        <input name="addressprev" type="text"   value="<?= ($_POST['addressprev']) ? stripslashes($_POST['addressprev']) : $row['addressprev'];?>" class="midinp">
      </div>
      <div class="input">
        <label>Unit.#:</label>
        <input name="unitprev" type="text"   value="<?= ($_POST['unitprev']) ? stripslashes($_POST['unitprev']) : $row['unitprev'];?>" class="ssminp">
      </div>
      <div class="input">
        <label>PO Box:</label>
        <input name="poboxprev" type="text"   value="<?= ($_POST['poboxprev']) ? stripslashes($_POST['poboxprev']) : $row['poboxprev'];?>" class="sminp">
      </div>
      <div style="clear:both;"></div>
      <div class="input">
        <label>City/Town:</label>
        <input name="cityprev" type="text" value="<?= ($_POST['cityprev']) ? stripslashes($_POST['cityprev']) : $row['cityprev'];?>" >
      </div>
      <div class="input">
        <label>Province:</label>
             <select name="provprev" class="typevolunteer" >
			<?
			echo  buildProvDropdown($provprev);
			?>
          </select>
      </div>
      <div class="input">
        <label>Postal Code:</label>
        <input name="postalcodeprev" MAXLENGTH="7"  type="text"  value="<?= ($_POST['postalcodeprev']) ? stripslashes($_POST['postalcodeprev']) : $row['postalcodeprev'];?>" class="sminp">
      </div>
      <div style="clear:both;"></div>
      
        <div class="input">
          <label>Do you object to us contacting your employer (current or previous)? </label>
          <label class="radio">
            <input name="contactemp" type="radio" value="1" <?=$contactempyes;?> >
            Yes</label>
          <label class="radio">
            <input name="contactemp" type="radio" value="0" <?=$contactempno;?>>
            No</label>
          <label class="radio">If Yes, Please explain.</label>
        </div>
        <div class="input">
          <input name="contactempinfo" value="<?= ($_POST['contactempinfo']) ? stripslashes($_POST['contactempinfo']) : $row['contactempinfo'];?>" type="text"  class="lrginp">
        </div>
        <div style="clear:both;"></div>

        <div class="input">
          <label>Any additional work experience you feel may be relevant?</label>
         
         
         <label class="radio">
            <input name="workexp" type="radio" value="1" <?=$workexpyes;?>>Yes</label>
          <label class="radio">
            <input name="workexp" type="radio" value="0" <?=$workexpno;?>>No</label>
        
        
        <label class="radio">If yes, then please provide details: </label>
        </div>
        <div class="input">
          <input name="workexpinfo" value="<?= ($_POST['workexpinfo']) ? stripslashes($_POST['workexpinfo']) : $row['workexpinfo'];?>" type="text"  class="lrginp">
        </div>
        <div style="clear:both;"></div>     




    <div style="clear:both;"></div>
            
      <p class="clearfix"><input type="submit" class="btn lfr" value="Save &amp; Close"> 
      <a href="volunteer_overview.php?vid=<?=$vid?>" class="btn lfr">Cancel</a></p>
   
   <input type="hidden" name="vid" value="<?=$vid;?>">
   </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>