<?php $__env->startSection('page_title'); ?>
    OSAA - Upload Stats File
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_sub_title'); ?>    
   Upload Stats File to Bracket
<?php $__env->stopSection(); ?>

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

    <style type="text/css">
    	h3 {
    		color: #1C43A6 !important;
    	}    	

    	.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();

	// Success bar
	$('.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);
		})
	});

	var divisions = <?php echo json_encode($info['activity_divisions']); ?>;

	$('#activity').change(function()
	{
		// Get the selected activity
		var select = $(this);
		var activity = $('option:selected', select).val();
		
		// Get this newly selected activity's divisions
		var options = divisions[activity];

		// Get the division select
		var div_select = $('select[name="division"]');

		// Clear out all options
		$('option', div_select).remove();

		// Add options from the new list of divisions
		$.each(options, function(value, text)
		{
			$('<option></option>')
				.attr('value', value)
				.html(text)
				.appendTo(div_select);
		});

		div_select.focus();

        updateMatchups();	        
	});

    $('#division').change(function ()
    {
        updateMatchups();
    });

    function updateMatchups()
    {
        var list = $('#matchup');

        var activity = $('#activity option:selected').val();
        var division = $('#division option:selected').val();

        var frame = $('#bracket');

        frame.attr('src', 'http://www.osaa.org/activities/' + activity.toLowerCase() + '/brackets?div=' + division);

        frame.load(function ()
        {
            frame.contents().find('#navigation, #masthead, #live_alert_2, .ad, #next_to_leaderboard, #osaa_websites, #footer, #championships, .header, .sub_menu_header, .division_select, .bracket_actions').remove();

            frame.contents().find('#full_page_content').css('width', '');
            frame.contents().find('.holder').css('width', 'auto');
            frame.contents().find('.main_content').css('width', '');
            frame.contents().find('.bracket').css({'width':'', 'padding':'0'});
        });

        // Get a list of JSON matchups
        var data = {activity : activity,
                    division : division};

        var matchup_objects;

        var jqxhr = $.ajax(
        {
            type : 'GET',
            url : '<?php echo url('stats/matchups'); ?>',
            data : data,
            dataType : 'html'
        })
        .done(function (returned_data)
        {               
            matchup_objects = $.parseJSON(returned_data);
        })
        .fail(function (jqXHR, status, error)
        {                                                   
            var response = jqXHR.responseText;
            var errorData = $.parseJSON(response);
            
            alert ("There was an error.\n\n" + errorData.error.message + "\n\nPlease try again.");            
        })
        .complete(function ()
        {
            // Only show results if there is at least one matchup
            if (matchup_objects[0] >= 1)
            {
                // Get the list
                var list = $('#matchup');

                // Remove all options
                $('option', list).remove();

                // Add an option for each matchup object
                $.each(matchup_objects, function(index, object)
                {
                    // Skip the first element because it's the number of matchups returned
                    if (index == 0)
                    {
                        return;
                    }

                    var home = object.contest.home_team_name;
                    if (!home)
                    {
                        home = 'TBD';
                    }
                    var away = object.contest.away_team_name;
                    if (!away)
                    {
                        away = 'TBD';
                    }

                    var time = object.show_time;

                    var text = away + ' vs. ' + home + ', ' + time;

                    list.append($('<option>', { value : object.matchup.id}).text(text));                    
                });

                if ($('#matchup option').size() == 1)
                {
                    $('#matchup option').first().attr('selected', 'selected');
                    $('#matchup').focus();
                }
            }
        });
    }

    updateMatchups();

    $('#debug').change(function()
    {
        var input = $(this);
        var form = $('#upload_form');

        if (input.is(':checked'))
        {
            form.attr('target', '_blank');
        }
        else
        {
            form.removeAttr('target');
        }
    });


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

<?php $__env->startSection('page_functions'); ?>
    
<?php $__env->stopSection(); ?>


<?php $__env->startSection('main_content'); ?>    
    
	<?php /*  Success Bar  */ ?>
 	<?php if (Session::has('success')): ?>
		<div class="success_bar">
			<div class="message">				
				<?php echo Session::get('success'); ?>
			</div>			
		</div>
	<?php endif; ?> 

	<br />

	<div class="float_right small">
		Your IP address is <?php echo Request::server('REMOTE_ADDR'); ?><br />
		<?php if (!Auth::check() or !Auth::user()->isOSaaUser()): ?>
			You are not logged in as an OSAA staff user.
		<?php endif; ?>
	</div>

	<h1>Upload a Stats File</h1>

	<br />

	<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>Use this form to upload a stats summary file (.htm) to the OSAA server after your OSAA Championships contest is over.</li>
			<li>You must be logged in as an OSAA staff member or you must provide the stats password in order to submit this form.</li>	
			<li>Select the <b>Sport</b> and <b>Division</b>.  This will update the list of contest matchups and show a corresponding bracket.</li>
			<li>Choose from the list of <b>Contest Matchups</b> which contest you are uploading stats to.</li>
            <li>Enabling "Over-write any existing file" will upload a new file and replace any existing file uploaded for that matchup.</li>
            <li>"Test mode, don't upload" will not upload any file and will show a debug screen with information if there are no errors.</li>
            <li>Pick which file is to be uploaded then click the <b>Upload</b> button.</li>            			
		</ol>		
		
		<br />
		For questions, contact Gibby Reynolds at (503) 682-6722 x228 or by e-mail to <?php echo Helpers::obfuscateEmailLink('gibbyr@osaa.org'); ?>.
	</div>

	<br />

	<?php /*  Errors  */ ?>
    <?php if (Session::has('errors')): ?>                
        <div class="error ui-state-error" style="font-weight: bold; padding: 1em;">
            <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 echo Form::open(array('url'   => 'stats/upload',
						'files' => true,
                        'id'    => 'upload_form')); ?>		

        <div class="columns">
            <div class="fourth">
                
                <h2>Authenticate</h2>
        		<?php if (Auth::check() and Auth::user()->isOSaaUser()): ?>
        			
        			<img src="<?php echo asset('images/icons/check_16px.png'); ?>"	alt="" title="" style="vertical-align: middle;" /> <?php echo Auth::user()->getDisplayFullName(); ?>, OSAA

        		<?php else: ?>

        			<?php echo Form::label('code', 'Stats Password', array('style' => 'font-weight: bold;')); ?>
        			<?php echo Form::password('code', array()); ?>

        		<?php endif; ?>

            </div>

            <div class="fourth">		
			    
                <h2>Sport</h2>

			    <?php echo Form::label('activity', 'Select', array('style' => 'font-weight: bold;')); ?>
			    <?php echo Form::select('activity', $info['activity_options'], null, array()); ?>

			</div>

            <div class="fourth">

    			<h2>Division</h2>
    			
    			<?php echo Form::label('division', 'Select', array('style' => 'font-weight: bold;')); ?>
    			<?php echo Form::select('division', reset($info['activity_divisions']), null, array()); ?>

            </div>

            <div class="fourth">                
                
                <h2>Options</h2>

                <label style="font-weight: bold;">
                    <?php echo Form::checkbox('replace', true, false, array('id' => 'replace', 'style' => 'vertical-align: middle;')); ?> Over-write any existing file
                </label>

                <br />

                <label style="font-weight: bold;">
                    <?php echo Form::checkbox('debug', true, false, array('id' => 'debug', 'style' => 'vertical-align: middle;')); ?> Test mode, don't upload
                </label>
                
                
                

            </div>



		</div>

        <br class="clear" />

        <div class="columns">
            <div class="half">

                <h2>Contest</h2>                
                <?php echo Form::label('matchup', 'Matchup', array('style' => 'font-weight: bold; vertical-align: top;')); ?>                
                <?php echo Form::select('matchup', array(), null, array('size' => '4', 'style' => 'width: 400px; font-size: 8pt;')); ?>

                <div class="small gray note" style="margin-left: 75px;">(Pick one contest matchup from the list above)</div>

            </div>

            <div class="half">
                
                <h2>Stats File</h2>
                
                <?php echo Form::label('file', 'Pick File', array('style' => 'font-weight: bold;')); ?>
                <?php echo Form::file('file'); ?>            

                <?php echo Form::submit('Upload', array('class' => 'button', 'style' => 'font-size: 9pt; margin-left: 50px;')); ?>

            </div>

            

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

		<br class="clear" />

		<div style="border-top: 1px solid #bcbcbc; margin: 1em 0 2em 0;"></div>

        <iframe id="bracket" src="" style="width: 100%; height: 600px;"></iframe>


		

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

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