<?php $__env->startSection('page_title'); ?>
    OSAA - Forms
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_sub_title'); ?>    
	<?php echo $information['form_name']; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    @parent

    <style type="text/css">
    	tbody tr.odd {
    		background-color: #f2f2f2;
    	}

    	.success_bar {
    		position: fixed;
    		top: 600px;
    		left: 0;
    		width: 100%;
    		padding: 0.25em 0;
    		line-height: 1.5em;
    		background-color: rgba(176, 255, 190, 0.0);
    		border-bottom: 2px solid rgba(13, 88, 27, 0.50);
    		border-top: 2px solid rgba(13, 88, 27, 0.50);
    		z-index: 500;
    	}

    	.success_bar .message {
    		width: 1200px;
    		margin: 0 auto;
    		font-size: 14pt;
    		color: #151515;
    	}  

    </style>

	
<?php $__env->stopSection(); ?>

<?php $__env->startSection('jquery_init'); ?>
	$('.button').button();
	$('.button.notext').button({text:false});
	$('.button.close').button({ icons : { primary : 'ui-icon-circle-close'}});
	$('.button.delete').button({ icons : { primary : 'ui-icon-closethick'}});
	$('.button.add').button({ icons : { primary : 'ui-icon-plusthick'}});
	$('.tooltip').tooltip();	 

	/* Limit input to numbers and a decimal point for GPA entries */	
	$('.gpa input').bind('input', function()
	{
  	    $(this).val($(this).val().replace(/[^0-9\.]/gi, ''));
	}).bind('change blur', function ()
	{		
		var v = parseFloat($(this).val());
		
		if (v <= 0.0 || v > 4.0)
		{
			$(this).val('');
		}		

		updateTotals();
	});		

	function updateTotals()
	{		
		team = 0;
		total = 0;
		count = 0;
		
		$('.gpa input').each(function ()
		{	
			if ($(this).parents('tr').filter(':visible').size() > 0)
			{
				var v = parseFloat($(this).val());

				if (v != '' && v > 0.0 && v <= 4.0)
				{					
					count = count + 1;				
					total = total + v;
				}
			}
		});		

		/* Calculate the team GPA, if any */
		if (count > 0)
		{
			team = total / count;			
		}
		else
		{
			team = 0;
		}	
		
		/* Format the numbers for display */
		team = team.toFixed(2);		
		total = total.toFixed(2);

		/* Display the calculations */
		$('#gpa_count').html(count);
		$('#total_gpa').html(total);
		$('#team_gpa').html(team);

		if (count < 5)
		{
			$('#submit').button('disable')
					    .addClass('ui-state-error');
			$('#min_note').html('(A minimum of 5 GPAs is required.)');
			$('#min_note').fadeIn();
		}
		else
		{
			$('#submit').button('enable')
						.removeClass('ui-state-error');	
			

            var missing_gpa = 0;
            $('td.gpa input:visible').each(function ()
            {
            	if ($(this).val() == '') missing_gpa += 1;
        	})

        	if (missing_gpa == 0)
        	{
				$('#min_note').fadeOut();
        	}
        	
        	if (missing_gpa == 1)
        	{
				$('#min_note').html("(Missing " + missing_gpa + " student's GPA.)");
				$('#min_note').fadeIn();
			}
			
			if (missing_gpa > 1)
			{
				$('#min_note').html("(Missing " + missing_gpa + " students' GPA.)");
				$('#min_note').fadeIn();
			}
			
		}

	}

	/* Start the page with the calculations in the case of existing data */
	updateTotals();

	function colorRows ()
	{		
		$('table').each(function ()
		{
			var i = 0;

			$('tbody tr:visible', $(this)).each(function ()
			{
				if (i % 2 == 1)
				{
					$(this).addClass('odd');
				}
				else
				{
					$(this).removeClass('odd');
				}
				i = i + 1;
			});		


		});		
	}

	colorRows();

	/* Remove a row */
	$('tbody tr .button.delete').click(function ()
	{			
		var row = $(this).parents('tr');
		$(row).remove();
		colorRows();
		updateTotals();
	});

	/* Add a row */
	$('.button.add').click(function ()
	{
		var row = $('.form_entries tr:hidden').first();
		$(row).show();
		colorRows();
		updateTotals();
	});

	/* Display any success messages */
    $('.success_bar').animate({ 'top' : 32, 'background-color' : 'rgba(176, 255, 190, 1.0)'}, 1600, 'easeOutQuad', function ()
	{		
		$(this).delay(6000).fadeOut(4000);	

		$(this).hover(function ()
		{
			$(this).stop(true).css('opacity', '1.0');
		},
		function ()
		{
			$(this).fadeOut(4000);
		})
	});


    $('#confirm_dialog').dialog({
      autoOpen: false,
      resizable: false,
      height:368,
      width: 600,
      modal: true,
	  buttons : [ {
	  				  text : 'Yes, Submit Form',
	                  'class' : 'float_left',
	                  click : function () {
	                					      $('#all_state_form').submit();                    
									          $(this).dialog("close");          
									          return true;
									      }
				  },
				  {
				      text : 'No, Go Back',
				      'class' : 'float_right',
				      click : function () {
											  $(this).dialog( "close" );
          									  return false;
				    				      }
				  }
				],
	  open : function () {                                         
                             $('.ui-dialog-buttonpane').css('padding', '0').css('font-size', '10pt');
                             $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');                                      
                         }
    });  

	$('#submit').click(function (event)
	{	
		$('#confirm_dialog').dialog('open');
		
	});
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_functions'); ?> 	
	
	<a href="<?php echo $information['return_url']; ?>" class="button close tooltip" style="font-size:9pt;" title="Discard any unsaved changes and close this form.">Close</a>	
	
<?php $__env->stopSection(); ?>


<?php $__env->startSection('main_content'); ?>    
	
	<?php if (Session::has('success')): ?>

		<div class="success_bar">
			<div class="message">				
				<?php echo Session::get('success'); ?>
			</div>			
		</div>

	<?php endif; ?>  

    <br />

    <img src="<?php echo asset('images/icons/all_state_64px.png'); ?>" alt="" title="" style="float: left; width: 64px; height: 64px; position: relative; top: -1em; margin-right: 0.5em;" />

	<h1><?php echo Helpers::getActivityName($information['activity_form']->activity); ?> Academic All State Nomination Form</h1>

	<br />

	<?php if ($information['is_past_due']): ?>
		<div class="online_form_late ui-state-error ui-corner-all">
			<span class="ui-icon ui-icon-alert" style="display:inline-block; position:relative; top:2px;"></span>
			This form was due by <?php echo date('g:i A l, F j, Y', strtotime($information['activity_form']->due_at)); ?> and is now past the deadline.  Please submit your entries now before the form closes and becomes unavailable.
		</div>
	<?php endif; ?>

	<div class="online_form_instructions ui-corner-all">
		<span class="ui-icon ui-icon-info" style="display:inline-block; position:relative; top:2px;"></span>
		<b>Instructions</b> <br />
		<ol>
			<li>All entries must be submitted by <?php echo date('g:i A l, F j, Y', strtotime($information['activity_form']->due_at)); ?> using this online form.</li>
			<li>List the entire varsity team only.  Do not include sub-varsity participants.</li>
			<li>Do not combine boys and girl teams.  Each activity has a separate form.</li>
			<li>Type in the name of the student, select his/her grade in school, and <b>type a GPA for every student listed</b>.</li>			
			<li>Use the most recent <b>unweighted</b> semester/trimester grades included on each student's transcript.  Do not use cumulative GPA.</li>
			<li>Be sure to include all co-op students and their GPA from his/her cooperating school.</li>
			<li>If a student's grades were not earned at your high school or cooperating high school during the previous semester/trimester, please list his/her name and leave the GPA field blank. (For example: first term freshman, home school students, new exchange students, new transfer students.)</li>
			<li>There must be a minimum of 5 students with a GPA to submit this form.  After the 5th GPA is entered and confirmed (which may require clicking or tabbing outside of that GPA's text-box,) the <b>Submit</b> button will be enabled (it will turn from red to blue.)</li>
		</ol>
		<br />

		For questions, contact Kelly Foster at (503) 682-6722 x233 or by e-mail to <?php echo Helpers::obfuscateEmailLink ("kellyf@osaa.org"); ?>.  For technical assistance, you can email <?php echo Helpers::obfuscateEmailLink ("support@osaa.org"); ?>.
	</div>	

	<?php if (Session::has('errors')): ?>                
        <br />
        <div class="error ui-state-error"><span class="ui-icon ui-icon-alert box_icon"></span><?php foreach ($errors->all() as $error): ?><?php echo $error; ?> <?php endforeach; ?></div>
    <?php endif; ?>

	<?php
		$entries = array();

		// No data was submitted 
		if (is_null($information['submission']))
		{
			// Pull over the Varsity team roster
			$team = team::where('activity_program', '=', $information['activity_program']->id)
						->where('level', '=', 'V')
						->first();

			// Was the team found?
			if (!is_null($team))
			{
				// Get the team's roster
				$roster_data = json_decode($team->roster_data);

				// Was a roster submitted?
				if(!is_null($roster_data) and is_array($roster_data) and count($roster_data) > 0)
				{
					// Add each player's information as an entry item
					foreach ($roster_data as $player)
					{
						$entry = new stdClass();
						$entry->name = $player->name;
						$entry->grade = $player->grade;
						$entry->gpa = null;
						$entry->notes = 'Automatically added from team roster';

						$entries[] = $entry;
					}
				}
			}
		}
		
		// The form has submitted data
		else
		{
			// Decode the data from JSON
			$data = json_decode($information['submission']->data);

			// Make sure the data is not empty and properly formatted
			if (!is_null($data) and !is_null($data->students))
			{			
				// Go through each data item and extract the entry items
				foreach ($data->students as $person)
				{
					$entry = new stdClass();
					$entry->name = $person->name;
					$entry->grade = $person->grade;
					$entry->gpa = $person->gpa;
					$entry->notes = $person->notes;

					$entries[] = $entry;						
				}
			}
		}
	?>

	<br />

	<h2><?php echo $information['activity_program']->name; ?> <?php echo Helpers::getActivityName($information['activity_program']->activity); ?></h2>

	<?php echo Form::open(array('url' => url('/forms/submit'), 'id' => 'all_state_form')); ?>

		<?php echo Form::hidden('form', 'ALL-STATE'); ?>
		<?php echo Form::hidden('activity_program', $information['activity_program']->id); ?>

		<?php if (Input::has('override') and Input::get('override') == 'LATE'): ?>
			<?php echo Form::hidden('accept-override', 'true'); ?>
		<?php endif; ?>

		<div class="columns">

			<div style="width:73%; min-height: 300px; float:left; padding:0 2% 0 0;">

				<table class="form_entries all_state">
					<thead>
						<tr>
							<th class="name">Student Name</th>
							<th class="grade">Grade</th>
							<th class="gpa">GPA</th>
							<th class="notes">Notes</th>
							<th></th>
						</tr>
					</thead>

					<tbody>
						<?php $i = 0; ?>

						<?php if (count($entries) > 0): ?>							

							<?php foreach ($entries as $entry): ?>

								<tr data-number="<?php echo $i; ?>" <?php if ($i++ % 2 == 1): ?> class="odd" <?php endif; ?>>
									
									<td class="name">
										<?php echo Form::text(sprintf('name_%s', $i - 1),
													  $entry->name,
													  array('id'    => sprintf('name_%s', $i - 1),
													  		'style' => 'width: 95%;')); ?>
									</td>
									
									<td class="grade">
										<?php echo Form::select(sprintf('grade_%s', $i - 1),
														array(9 => 9, 10 => 10, 11 => 11, 12 => 12),
													    $entry->grade,
													    array('id'    => sprintf('grade_%s', $i - 1),
													    	  'style' => 'width: 95%;')); ?>
									</td>
									
									<td class="gpa">										
										<?php echo Form::text(sprintf('gpa_%s', $i - 1),
													  is_null($entry->gpa) ? '' : number_format($entry->gpa, 2, '.', ''),
													  array('id'    => sprintf('gpa_%s', $i - 1),
													    	'style' => 'width: 65px;')); ?>
									</td>
									
									<td class="notes">
										<?php echo Form::text(sprintf('notes_%s', $i - 1),
													  $entry->notes,
													  array('id'    => sprintf('notes_%s', $i - 1),
													  	    'style' => 'width: 95%;')); ?>
									</td>
									
									<td class="text_center"><div class="button delete notext tooltip" style="width:16px; height:16px; position:relative; top:-1px;" title="Delete this entry line item."></div></td>
								</tr>

							<?php endforeach; ?>
							
						<?php endif; ?>

						<?php while ($i < 140): ?>

							<tr data-number="<?php echo $i; ?>" <?php if ($i++ % 2 == 1): ?> class="odd" <?php endif; ?> style="display: none;">
								
								<td class="name">
									<?php echo Form::text(sprintf('name_%s', $i - 1),
												  null,
												  array('id'    => sprintf('name_%s', $i - 1),
												  		'style' => 'width: 95%;')); ?>
								</td>
								
								<td class="grade">
									<?php echo Form::select(sprintf('grade_%s', $i - 1),
													array(9 => 9, 10 => 10, 11 => 11, 12 => 12),
												    null,
												    array('id'    => sprintf('grade_%s', $i - 1),
												    	  'style' => 'width: 95%;')); ?>
								</td>
								
								<td class="gpa">										
									<?php echo Form::text(sprintf('gpa_%s', $i - 1),
												  null,
												  array('id'    => sprintf('gpa_%s', $i - 1),
												    	'style' => 'width: 65px;')); ?>
								</td>
								
								<td class="notes">
									<?php echo Form::text(sprintf('notes_%s', $i - 1),
												  null,
												  array('id'    => sprintf('notes_%s', $i - 1),
												  	    'style' => 'width: 95%;')); ?>
								</td>
								
								<td class="text_center"><div class="button delete notext tooltip" style="width:16px; height:16px; position:relative; top:-1px;" title="Delete this entry line item."></div></td>
							</tr>

						<?php endwhile; ?>
					</tbody>


				</table>
			</div>



			<div style="width:25%; float:left;">
				<div class="button add" style="font-size: 9pt;">Add a New Row</div>
			

				<br /><br /><br />

				<b>Last Submitted</b><br />
				<?php if (!is_null($information['submission'])): ?>
					<?php echo date('m/d/Y g:i a', strtotime($information['submission']->updated_at)); ?> by <?php echo $information['submission']->user_first_name; ?> <?php echo $information['submission']->user_last_name; ?>
				<?php else: ?>
					Never
				<?php endif; ?>

				<br /><br />

				<table>
					<tr>
						<td style="width: 160px;"><b>Team GPA</b></td>
						<td id="team_gpa"></td>
					</tr>

					<tr>
						<td><b>Total GPA</b></td>
						<td id="total_gpa"></td>
					</tr>

					<tr>
						<td><b>Number of GPAs</b></td>
						<td id="gpa_count"></td>
					</tr>
				</table>

				<br />			
				<br />

				<div id="submit" class="button float_right" style="font-size: 11pt;">Submit</div>

				
				<br /><br />
				<div id="min_note" class="small gray note float_right">
					(A minimum of 5 GPAs is required.)
				</div>

				<br /><br />

				<div class="ui-corner-all ui-state-highlight" style="padding: 0.75em 0.5em; font-size: 10pt; line-height: 1.25em;">
					<b>REMINDER</b><br /><br />
					Only list <b>varsity</b> team participants, do not include sub-varsity.<br /><br />
					Be sure to provide a GPA for all students listed, even if a student's GPA is lower than 3.0; <b>every student must have a GPA provided.</b>  If a GPA is not specified for a varsity level participant, that student must be a:
					<ul>
						<li><u>First term</u> freshman</li>
						<li>Home school student</li>
						<li>New exchange student</li>
						<li>Newly transfered student</li>
					</ul>

				</div>

			</div>

		</div>

	<?php echo Form::close(); ?>

	<br class="clear" />
	<br />

	<div id="confirm_dialog" title="Please Confirm Your Entries">
		<h3>Did you follow the instructions?</h3>
		<br />
		<img src="<?php echo asset('images/icons/all_state_128px.png'); ?>" alt="" title="" class="float_right" style="width: 128px; margin: 0 0 0 0.5em;" />
		<ul style="font-size: 10pt; margin-left: 2em;">
			<li>Did you only list students on the <b>varsity</b> team?</li>
			<li>Did you provide a GPA for <b>every student</b>?  Even if the GPA was less than 3.0?</li>
			<li>If you did not enter in a student's GPA, was it because the student is a first term freshman, home school student, new exchange student, or newly transfered student?</li>
			<li>Did you include all co-op students and their GPA from his/her cooperating school?</li>
			<li>Did you use <b>the most recent unweighted semester/trimester grades</b> and not the students' cumulative GPA?</li>	
		</ul>
	</div>

<?php $__env->stopSection(); ?>
