<?
$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"]["TERMS"] as $tid=>$termType) { ?>
									    <?=$arResult["NAVIGATION"]["TERMS_NAME"][$tid]?>
                                        <?foreach($termType as $id=>$term) { ?>
                                            <a href="/final_terms/<?=$arResult["SCHOOLYEAR"]?>/<?=$id?>"<?=$arResult["ACTIVE_ID"] == $id ? ' class="curent"' : '' ;?>><?=$term?></a>
									    <? } ?>
                                    <? } ?>
                                    
										<span class="separator"></span>
										<? if(!empty($arResult["NAVIGATION"]["PREV_SCHOOLYEAR"])) { ?>
										<a  id="year-right" title="<?=$arResult["NAVIGATION"]["PREV_SCHOOLYEAR"]["NAME"]?>" href="/final_terms/<?=$arResult["NAVIGATION"]["PREV_SCHOOLYEAR"]["ID"]?>/<?=$arResult["NAVIGATION"]["PREV_SCHOOLYEAR"]["TERM"]?>"><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_terms/<?=$arResult["NAVIGATION"]["NEXT_SCHOOLYEAR"]["ID"]?>/<?=$arResult["NAVIGATION"]["NEXT_SCHOOLYEAR"]["TERM"]?>"><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($arResult["MONTHS"] as $m => $nd) {?>
					<td colspan="<?=$nd?>"><?=$M_FULL[$m]?></td>
				<?}?>
				<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($days as $day):?>
					<td class="<? //echo ($day==date("j")) ? " hover_color" : ""; ?>"><?=date("j",$day);?></td>
				<?endforeach;?>
				
                <? 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>&nbsp;<?=$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 $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>