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

<?php $__env->startSection('page_sub_title'); ?>    
   <?php echo $info['activity']->name; ?> League and Special District Results
<?php $__env->stopSection(); ?>

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

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

    	h4 {
    		color: #005fa9;
    		display: inline-block;
    	}

    	table {
    		border-collapse: collapse;
    		font-size: 10pt;
    		width: 100%;
    	}

    	table thead th {
    		text-align: left;
    		border-bottom: 1px solid #aaaaaa;
    	}

    	.preview_unpublished {
    		background-color: #d0d0d0;
    		position: relative;
    		overflow: hidden;
    	}

    	.preview_watermark {
    		position: absolute;
    		opacity: 0.25;
		    font-size: 3em;
		    line-height: 115%;
		    width: 100%;
		    text-align: center;
		    z-index: 1000;
		    top: 15%;
    	}

    	.preview_watermark_note {
    		font-size: 14pt;
    	}

    	@media print {
    		#full_page_content {
    			float: none !important;    			
    		}

    		.print_break {
    			page-break-before: always !important;
    		}

    		* {
    			font-size: 105%;
    			line-height: 105%;
    		}

    	}
    </style>

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

<?php $__env->startSection('jquery_init'); ?>
	$('.button')
		.button()
		.css({'font-size' : '9pt'});

	$('.button.back')
		.button({ icons : { primary : 'ui-icon-arrowthick-1-w'}});

	$('.button.switch')
		.button({ icons : { primary : 'ui-icon-transferthick-e-w'}});

	$('.button.edit')
		.button({ icons : { primary : 'ui-icon-pencil'}});

	$('.button.form')
		.button({ icons : { primary : 'ui-icon-clipboard'}});
    
    $('.page_functions')
    	.css({'width' : 'auto'});

    // Download drop-down menu
    $('#grabber_list')
        .menu()
        .css({'display' : 'none',
              'z-index' : '200',
              'position' : 'absolute',
              'right' : '0',
              'top' : '23px',
              'margin' : '0',
              'padding' : '0',
              'font-size' : '10pt',
              'width' : '150px'});

    $('#grabber_list img')
        .css({'position' : 'relative',
              'top' : '2px',
              'margin-right' : '6px'});

    $('.grabber_button')
        .button({ icons : { secondary : 'ui-icon-triangle-1-s'}})
        .css({'float':'right',
              'font-size':'9pt'})
        .click(function (event)
        {
            if ($('#grabber_list').is(':visible'))
            {
                $('#grabber_list').slideUp(400);
                $(this).button({icons : { secondary : 'ui-icon-triangle-1-s'}});
            }
            else
            {
                $('#grabber_list').slideDown(400);
                $(this).button({icons : { secondary : 'ui-icon-triangle-1-n'}});
            }   
        });

    $('#populate')
        .click(function ()
        {
            $('<div></div>')
                .appendTo('body')
                .html('<br /><img src="<?php echo asset('images/icons/help_24px.png'); ?>" class="float_left" style="margin: 0.25em 1em 0.5em 0;" alt="" title="" />Are you sure you want to reset all <?php echo (Session::get('year') + 1); ?> tennis brackets and re-populate the database?<div style="font-size: 9pt; margin-top: 2.25em;">This will clear the database of all existing tennis participants for the current school year, erasing any existing bracket placements.<br /><br /><div class="ui-state-error" style="padding: 0.5em 0.25em;"><b>Note:</b> This cannot be undone.  Choose wisely.</div><br />This procedure should only be executed once, after all entries have been submitted and before placing any participants onto a tennis bracket.</div>')
                .dialog(
                {
                    autoOpen: true,
                    draggable: false,
                    resizable: false,
                    height: 'auto',
                    width: 450,
                    title: 'WARNING - Please Confirm',
                    modal: true,
                    buttons: [
                    {
                        text : "Yes",
                        'class' : "float_left",
                        icons : { primary : 'ui-icon-check'},
                        click : function()
                        {   
                            $('<div><div>').addClass('ui-widget-overlay ui-front')
                            			   .attr('id', 'shadow')
                                           .appendTo('body');
                            
                            $('<div><div>').appendTo('body')                            			   
                            		       .attr('id', 'waiting')
                                           .css('width', '225px')
                                           .css('height', '170px')
                                           .css('text-align', 'center')
                                           .css('padding', '0.5em')
                                           .position({my : "center center", at : "center center", of : window})
                                           .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-dialog-buttons')
                                           .html('<br />Working...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Please wait, this may take a while to process and update the database.</div>');

                            var jqxhr = $.ajax(
                            {
                                type : 'GET',
                                url : '/brackets/populate-tennis-participants',                                
                                dataType : 'html',                            
                                error : function ()
	                            {
	                                alert('There was an error populating the database.  The procedure was unexpectedly interrupted.');
	                            },
	                            success : function (data)
	                            {                           
	                                alert('Database was successfully populated with ' + data + ' participants.');
	                            },
	                            complete : function ()
	                            {	                                
	                                $('#waiting').remove();
	                                $('#shadow').remove();
	                            }
                            });

                            $(this).dialog("close");
                            $(this).remove();                                                                      
                        }
                    },
                    {
                        text : "No",
                        'class' : "float_right",
                        'autofocus' : true,
                        icons : { primary : 'ui-icon-cancel'},
                        click : function()
                        {
                            $(this).dialog("close");
                            $(this).remove();
                        }
                    }],
                    open : function ()
                    {                   
                        $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '10pt');
                        $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');
                        $('.ui-dialog-titlebar').addClass('ui-state-highlight');
                    }
                });  
        });

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

<?php $__env->startSection('page_functions'); ?>	
	
	<a href="<?php echo url('/forms/registration/' . strtolower($info['activity']->slug)); ?>" class="button form">Form</a>	

	<?php if(Helpers::strEqual($info['activity']->slug, 'BTN')): ?>
		<a href="<?php echo url('/activities/gtn/league-results'); ?>" class="button switch">Switch to Girls Results</a>
		<a href="<?php echo url('/activities/btn'); ?>" class="button back">Boys Tennis</a>
	<?php else: ?>
		<a href="<?php echo url('/activities/btn/league-results'); ?>" class="button switch">Switch to Boys Results</a>
		<a href="<?php echo url('/activities/gtn'); ?>" class="button back">Girls Tennis</a>
	<?php endif; ?>

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


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

	<?php if (Auth::check() and Auth::user()->isOsaaUser()): ?>

		<div style="position: absolute; right: 0;">
			
			<div class="grabber_button">Download/Export</div>
			
			<ul id="grabber_list">
				<li><a href="<?php echo url('/reports/tn-entries/csv'); ?>" target="_blank">Download Entries</a></li>
				<li><a href="<?php echo url('/reports/tn-entries/sheets'); ?>" target="_blank">Print Data Sheets</a></li>
				<li><a href="<?php echo url('/reports/tn-entries/sheets?results-only=1'); ?>" target="_blank">Print District Results</a></li>
				<li><a href="#" id="populate">Load Database</a></li>
			</ul>
		</div>

	<?php endif; ?>

	<?php foreach ($info['leagues'] as $item): ?>

		<div class="print_break">

		<h2>
			<?php echo preg_replace('/ \(.*\)/', '', $item->league->slug); ?> <?php echo $item->league->name; ?>
			<?php if (Auth::check() and Auth::user()->isOsaaUser()): ?>
				<a href="<?php echo url('/forms/registration/' . strtolower($info['activity']->slug) . '?league=' . $item->league->slug); ?>" class="button edit" style="font-size: 7pt !important; margin-left: 25px;">Edit</a>
			<?php endif; ?>
		</h2>

		<?php if (is_null($item->form)): ?>
			
			The meet director has not yet submitted <?php echo strtolower($info['activity']->name); ?> results for <?php echo preg_replace('/ \(.*\)/', '', $item->league->slug); ?> <?php echo $item->league->name; ?>.  Please check back again soon.<br />

		<?php else: ?>
			
			<h3>District Meet</h3>
			<b>Date: </b><?php echo date('l n/j/Y', strtotime($item->data->meet->event->date)); ?><br />
			<b>Location: </b><?php echo $item->data->meet->event->location; ?><br />
			<b>Director: </b><?php echo $item->data->meet->director->name; ?><br />

			<br />

			<?php if ($item->data->complete or (Auth::check() and Auth::user()->isOsaaUser())): ?>

				<?php if (!$item->data->complete): ?>
					<div class="preview_unpublished">
					<div class="preview_watermark">Unpublished<br />Preview<div class="preview_watermark_note">Form has not been submitted</div></div>
				<?php endif; ?>

				<div class="columns">

					<div class="half">
						<b>Doubles Qualifiers</b><br />						
						
						<table style="margin-left: 5%; width:95%;">
							<thead>
								<tr>
									<th>#</th>
									<th>Names</th>									
									<th>Seed</th>									
									<th>Team</th>
								</tr>
							</thead>

							<tbody>								

								<?php foreach ($item->data->meet->qualifiers->doubles as $count => $participant): ?>

									<?php										
										$ap = activityprogram::find($participant->ap_id);
									?>

									<tr>
										<td><?php echo ($count + 1); ?></td>
										<td>
										    <?php echo $participant->name_1; ?>, <?php echo $participant->grade_1; ?><br />
										    <?php echo $participant->name_2; ?>, <?php echo $participant->grade_2; ?>
										</td>										
										<td>
											<?php if (Helpers::strIsEmpty($participant->seed)): ?>
												NS											
											<?php elseif (is_numeric($participant->seed)): ?>
												<?php echo $participant->seed; ?>
											<?php else: ?>
												<?php echo strtoupper($participant->seed); ?>
											<?php endif; ?>
										</td>
										<td>
											<?php if (!is_null($ap)): ?>
												<?php echo $ap->name; ?>
											<?php else: ?>
												No Team Listed
											<?php endif; ?>
										</td>
									</tr>										
									<tr>
										<td colspan="4">&nbsp;</td>
									</tr>
								<?php endforeach; ?>

							</tbody>

						</table>
							
						<br />

					</div>

					<div class="half">
						<b>Singles Qualifiers</b><br />						
						
						<table style="margin-left: 5%; width:95%;">
							<thead>
								<tr>
									<th>#</th>
									<th>Name</th>									
									<th>Seed</th>									
									<th>Team</th>
								</tr>
							</thead>

							<tbody>								

								<?php foreach ($item->data->meet->qualifiers->singles as $count => $participant): ?>

									<?php										
										$ap = activityprogram::find($participant->ap_id);
									?>

									<tr>
										<td><?php echo ($count + 1); ?></td>
										<td>
										    <?php echo $participant->name; ?>, <?php echo $participant->grade; ?>										    
										</td>										
										<td>
											<?php if (Helpers::strIsEmpty($participant->seed)): ?>
												NS												
											<?php elseif (is_numeric($participant->seed)): ?>
												<?php echo $participant->seed; ?>
											<?php else: ?>
												<?php echo strtoupper($participant->seed); ?>
											<?php endif; ?>
										</td>
										<td>
											<?php if (!is_null($ap)): ?>
												<?php echo $ap->name; ?>
											<?php else: ?>
												No Team Listed
											<?php endif; ?>
										</td>
									</tr>
									<tr>
										<td colspan="4">&nbsp;</td>
									</tr>										
								<?php endforeach; ?>

							</tbody>

						</table>
							
						<br />

					</div>

				</div>				

				<br class="clear" />

				<?php if (!$item->data->complete): ?>
					</div>
				<?php endif; ?>

			<?php else: ?>
				
				These results have not been published, yet.  Please check back again soon.<br />

			<?php endif; ?>


		<?php endif; ?>

		<br />


		</div>

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