<?
$days 		= array_keys($arResult["EVENTS"]);
$firstterm	= key($arResult["TERMS"]);
$M_FULL = Array('01' => 'Январь', '02' => 'Февраль', '03' => 'Март', '04' => 'Апрель', '05' => 'Май', '06' => 'Июнь', '07' => 'Июль', '08' => 'Август', '09' => 'Сентябрь', '10' => 'Октябрь', '11' => 'Ноябрь', '12' => 'Декабрь');
asort($arResult["SUBJECTS_F"], SORT_STRING);
?>
                                <div class="month_2">
									<?
									foreach($arResult["NAVIGATION"]["MONTHS"] as $timestamp) { ?>
									<a href="/final_marks/<?=date("Y-m", $timestamp)?>"<?=(date("m-Y",$arResult["ACTIVE"]) == date("m-Y", $timestamp)) ? ' class="curent"' : '' ;?>><?=$M_FULL[date("m", $timestamp)]?></a>
									<? }	?>
										<span class="separator"></span>
										<? if(!empty($arResult["NAVIGATION"]["PREV_SCHOOLYEAR"])) { ?>
										<a  id="year-right" title="<?=$arResult["NAVIGATION"]["PREV_SCHOOLYEAR"]["NAME"]?>" href="/final_marks/<?=date("Y-m",$arResult["NAVIGATION"]["PREV_SCHOOLYEAR"]["DATE"])?>"><img src="/sites/all/themes/e_diary/skin/arrow-left.png" alt="&lt;"/></a>
										<? } ?>
										<span class="curent_year"><?=$arResult["NAVIGATION"]["SCHOOLYEAR"]?></span>
										<? if(!empty($arResult["NAVIGATION"]["NEXT_SCHOOLYEAR"])) { ?>
										<a id="year-right" title="<?=$arResult["NAVIGATION"]["NEXT_SCHOOLYEAR"]["NAME"]?>" href="/final_marks/<?=date("Y-m",$arResult["NAVIGATION"]["NEXT_SCHOOLYEAR"]["DATE"])?>"><img src="/sites/all/themes/e_diary/skin/arrow-right.png" alt="&lt;"/></a>
										<? } ?>
                                </div>
                            
	<table class = "table_finall">
		<thead>
			<tr class="row_1">
				<td rowspan="2">Предмет</td>
				<?foreach($days as $day):?>
					<td rowspan="2" class="<? //echo ($day==date("j")) ? " hover_color" : ""; ?>"><?=$day;?></td>
				<?endforeach;?>
				<td rowspan="2" class="left_border test_3"><span title="Всего пропусков">Пр.</span></td>
				
                <?foreach($arResult["TERMS_NAME"] as $id=>$name):?>
                    <td colspan="<?=count($arResult["TERMS"][$id]);?>"   class="left_border part "><?=$name?></td>
                <?endforeach?>
				
                <td rowspan="2"  class="left_border">Год</td>
				<td rowspan="2"  class="left_border">Экз</td>
				<td rowspan="2"  class="left_border">Итог</td>
				<?if(!empty($arResult["SRED"])) {?>
				<td rowspan="2"  class="left_border"><span title="Средний балл за текущий период обучения">Средний балл<br/>за текущий<br/>период</span></td>
				<?}?>
			</tr>
			<tr class="sem row_2">
				<?/* foreach($arResult["TERMS"] as $k => $term) { ?>
					<td<? echo ($k==$firstterm) ? ' class="left_border"' : ''; ?>><?=$term?></td>
				<? } */?>
                <? foreach($arResult["TERMS"] as $id => $type) { ?>
                    <? foreach($type as $k => $term) { ?>
                        <td<? echo ($k==$firstterm) ? ' class="left_border"' : ''; ?>><?=$term?></td>
                    <? } ?>
                <? } ?>
			</tr>
		</thead>
		<tbody>
			<? $i = 1; ?>
			<? foreach($arResult["SUBJECTS_F"] as $sid => $name) { ?>
				<tr class="<? echo ($i % 2 == 1) ? "odd" : "even"; ?>">
					<td><span><?=$i ?>.</span> <?=$name?></td>
					<? foreach($days as $day) {
						if($arResult["EVENTS"][$day][$sid]["MISS"]) { ?>
							<td class="out">Н</td>
						<? } else { ?>
							<td>
							<? if(!empty($arResult["EVENTS"][$day][$sid]["MARKS"])) {
								$marks = '';
								foreach($arResult["EVENTS"][$day][$sid]["MARKS"] as $mark) {
									if(is_string($mark) && mb_strlen($mark) > 3) {
										$marks .= ' ' . htmlspecialchars(mb_substr($mark, 0, 3));
									} else {
										$marks .= ' ' . htmlspecialchars($mark);
									}
								}
								$marks_t = htmlspecialchars(implode(", ", $arResult["EVENTS"][$day][$sid]["MARKS"]));
								$count = count($arResult["EVENTS"][$day][$sid]["MARKS"]);
								?>
								<div class="mark_big c_<?=$count ?>" title="<?=$marks_t?>">
									<?=$marks ?>
								</div>
							<? } ?>
							</td>
						<? }
					} ?>
							<td class="left_border"><?=$arResult["TOTALMISS_F"][$sid] ?></td>
							<? /*foreach($arResult["TERMS"] as $k => $term) { ?>
								<td<? echo ($k==$firstterm) ? ' class="left_border"' : ''; ?>><?=$arResult["FINAL_MARKS"][$sid]["TERMS"][$k]?></td>
							<? }*/ ?>
                            
                            <? foreach($arResult["TERMS"] as $id => $type) { ?>
                                <? foreach($type as $k => $term) { ?>

									<?
									$class = '';
									if( !in_array($k, $arResult["SUBJECT_TERMS"][$sid]) && count($arResult["SUBJECT_TERMS"]) > 0 )
									{
										$class = 'noactive';
									}

									if( $k==$firstterm )
									{
										if( $class != '' ) $class .= ' ';
										$class .= 'left_border';
									}
									?>

									<td class="<?=$class?>"><?=$arResult["FINAL_MARKS"][$sid]["TERMS"][$k]?></td>
                                <? } ?>
                            <? } ?>
                            
                            <td class="left_border "><?=$arResult["FINAL_MARKS"][$sid]["YEAR"] ?></td>
                            <td class="left_border"><?=$arResult["FINAL_MARKS"][$sid]["EXAM"] ?></td>
                            <td class="left_border"><?=$arResult["FINAL_MARKS"][$sid]["FINAL"] ?></td>
							<?if(!empty($arResult["SRED"])) {?>
							<td class="left_border rating"><?=$arResult["SRED"][$sid] ?></td>
							<? } ?>
				</tr>
			<? 
				$i++;
			} ?>
		</tbody>
	</table>