public function main()
    {
        ?>
		<div id="main">
		<div id="reports-new">
		<div class="ui error form segment square-corners no-shadow">
		<div class="three fields">
			<div class="field">
				<label>Год набора</label>
				<input id="year" name="year" placeholder="Год набора" type="text">
			</div>

			<div class="field">
				<label>Срок обучения (лет)</label>
				<input id="duration" name="duration" placeholder="4" type="text" onchange="calendar.update();">
			</div>

			<div class="field">
				<label>ФИО ректора</label>
				<?php 
        $settings = settings::get_rector_value(template_session::get_user_id());
        $rector = $settings->value;
        ?>
				<input id="rector" name="rector" value="<?php 
        if (!empty($rector)) {
            echo $rector;
        }
        ?>
" placeholder="М.П. Батура" type="text" >
			</div>
		</div>

		<div class="field">
			<label>Регистрационный номер учебного плана</label>
			<input id="registration_number" name="registration_number" placeholder="2014.09.20/000" type="text" >
		</div>

		<div class="field">
			<div class="ui fluid selection dropdown">
				<div class="default text">Форма обучения</div>
				<i class="dropdown icon"></i>
				<input type="hidden" id="training_form_id" name="training_form_id">
				<div class="menu">
					<?php 
        $training_forms = training_forms::get();
        if ($training_forms) {
            foreach ($training_forms as $training_form) {
                ?>
							<div class="item" data-value="<?php 
                echo $training_form->id;
                ?>
"><?php 
                echo html::escape($training_form->name);
                ?>
</div>
						<?php 
            }
        }
        ?>
				</div>
			</div>
		</div>

		<div class="field">
			<div class="ui fluid selection dropdown">
				<div class="default text">Квалификация специалиста</div>
				<i class="dropdown icon"></i>
				<input type="hidden" id="qualification_id" name="qualification_id" >
				<div class="menu">
					<?php 
        $qualifications = qualifications::get();
        if ($qualifications) {
            foreach ($qualifications as $qualification) {
                ?>
							<div class="item" data-value="<?php 
                echo $qualification->id;
                ?>
"><?php 
                echo html::escape($qualification->name);
                ?>
</div>
						<?php 
            }
        }
        ?>
				</div>
			</div>
		</div>

		<div class="field">
			<div class="ui fluid selection dropdown">
				<div class="default text">Специальность</div>
				<i class="dropdown icon"></i>
				<input type="hidden" id="specialty_id" name="specialty_id">
				<div class="menu">
					<?php 
        $specialties = specialties::get();
        if ($specialties) {
            foreach ($specialties as $specialty) {
                ?>
							<div class="item" data-value="<?php 
                echo $specialty->id;
                ?>
"><?php 
                echo html::escape($specialty->name);
                ?>
</div>
						<?php 
            }
        }
        ?>
				</div>
			</div>
		</div>

		<div class="field">
			<div class="ui fluid selection dropdown">
				<div class="default text">Специализация</div>
				<i class="dropdown icon"></i>
				<input type="hidden" id="specialization_id" name="specialization_id" >
				<div class="menu">
					<?php 
        $specializations = specializations::get();
        if ($specializations) {
            foreach ($specializations as $specialization) {
                ?>
							<div class="item" data-value="<?php 
                echo $specialization->id;
                ?>
"><?php 
                echo html::escape($specialization->name);
                ?>
</div>
						<?php 
            }
        }
        ?>
				</div>
			</div>
		</div>

		<?php 
        //						$calendar = new ajax_calendar();
        //						$calendar->html();
        ?>

		<div class="ui green submit button small" onclick="save(0); return false;">Сохранить</div>
		<a href="#" target="_blank" id="button-preview" class="ui blue submit button small" onclick="save(1); return false;">Предпросмотр</a>
		<a href="#" target="_blank" id="button-popup" class="ui blue submit button small" onclick="calendar.popup(); return false;">Календарь</a>

		<div class="ui dimmer page hidden">
		<div id="calendar" class="ui modal large transition hidden">
		<i class="close icon"></i>

		<div class="header">
			Календарь
		</div>

		<div class="content">
		<table class="ui basic table">
		<tr>
			<th rowspan="3">к<br/>у<br/>р<br/>с<br/>ы</th>
			<th colspan="4">Сентябрь</th>
			<th></th>
			<th colspan="3">Октябрь</th>
			<th></th>
			<th colspan="4">Ноябрь</th>
			<th colspan="4">Декабрь</th>
			<th></th>
			<th colspan="3">Январь</th>
			<th></th>
			<th colspan="3">Февраль</th>
			<th></th>
			<th colspan="4">Март</th>
			<th></th>
			<th colspan="3">Апрель</th>
			<th></th>
			<th colspan="4">Май</th>
			<th colspan="4">Июнь</th>
			<th></th>
			<th colspan="3">Июль</th>
			<th></th>
			<th colspan="4">Август</th>
		</tr>
		<tr>
			<td>1</td>
			<td>8</td>
			<td>15</td>
			<td>22</td>
			<td>
				<div class="underline">29</div>
				09
			</td>
			<td>6</td>
			<td>13</td>
			<td>20</td>
			<td>
				<div class="underline">27</div>
				10
			</td>
			<td>3</td>
			<td>10</td>
			<td>17</td>
			<td>24</td>
			<td>1</td>
			<td>8</td>
			<td>15</td>
			<td>22</td>
			<td>
				<div class="underline">29</div>
				12
			</td>
			<td>5</td>
			<td>12</td>
			<td>19</td>
			<td>
				<div class="underline">26</div>
				01
			</td>
			<td>2</td>
			<td>9</td>
			<td>16</td>
			<td>
				<div class="underline">23</div>
				02
			</td>
			<td>2</td>
			<td>9</td>
			<td>16</td>
			<td>23</td>
			<td>
				<div class="underline">30</div>
				03
			</td>
			<td>6</td>
			<td>13</td>
			<td>20</td>
			<td>
				<div class="underline">27</div>
				04
			</td>
			<td>4</td>
			<td>11</td>
			<td>18</td>
			<td>25</td>
			<td>1</td>
			<td>8</td>
			<td>15</td>
			<td>22</td>
			<td>
				<div class="underline">29</div>
				06
			</td>
			<td>6</td>
			<td>13</td>
			<td>20</td>
			<td>
				<div class="underline">27</div>
				07
			</td>
			<td>3</td>
			<td>10</td>
			<td>17</td>
			<td>24</td>
		</tr>
		<tr>
			<td>7</td>
			<td>14</td>
			<td>21</td>
			<td>28</td>
			<td>
				<div class="underline">05</div>
				10
			</td>
			<td>12</td>
			<td>19</td>
			<td>26</td>
			<td>
				<div class="underline">02</div>
				11
			</td>
			<td>7</td>
			<td>16</td>
			<td>23</td>
			<td>30</td>
			<td>7</td>
			<td>14</td>
			<td>21</td>
			<td>28</td>
			<td>
				<div class="underline">04</div>
				01
			</td>
			<td>11</td>
			<td>18</td>
			<td>25</td>
			<td>
				<div class="underline">01</div>
				02
			</td>
			<td>8</td>
			<td>15</td>
			<td>22</td>
			<td>
				<div class="underline">01</div>
				03
			</td>
			<td>8</td>
			<td>15</td>
			<td>22</td>
			<td>29</td>
			<td>
				<div class="underline">05</div>
				04
			</td>
			<td>12</td>
			<td>19</td>
			<td>26</td>
			<td>
				<div class="underline">03</div>
				05
			</td>
			<td>10</td>
			<td>17</td>
			<td>24</td>
			<td>31</td>
			<td>7</td>
			<td>14</td>
			<td>21</td>
			<td>28</td>
			<td>
				<div class="underline">05</div>
				07
			</td>
			<td>12</td>
			<td>19</td>
			<td>26</td>
			<td>
				<div class="underline">02</div>
				08
			</td>
			<td>9</td>
			<td>16</td>
			<td>23</td>
			<td>31</td>
		</tr>

		<?php 
        for ($i = 1; $i <= 0; $i++) {
            ?>
<tr id="generated-<?php 
            echo $i;
            ?>
" class="generated"><td><?php 
            echo int::to_roman($i);
            ?>
</td><?php 
            for ($j = 1; $j < 53; $j++) {
                $val = '';
                ?>
					<td>
						<div class="ui form">
							<div class="inline field">
								<input class="<?php 
                echo $j;
                ?>
" type="text" maxlength="2" value="<?php 
                echo $val;
                ?>
">
							</div>
						</div>
					</td>
				<?php 
            }
            ?>
</tr><?php 
        }
        ?>
		</table>

		<br />

		<div class="ui icon buttons constructor">
			<div class="ui button" onclick="calendar_char = ''"><i class="align icon eraser"></i></div>

			<?php 
        $legend = calendar_legend::get();
        if ($legend) {
            foreach ($legend as $item) {
                ?>
						<div class="ui button constructor" title="<?php 
                echo $item->description;
                ?>
" onclick="calendar_char = '<?php 
                echo $item->legend_letter;
                ?>
'"><?php 
                echo $item->legend_letter;
                ?>
</div>
						<?php 
            }
        }
        ?>
		</div>

		<script>
			rude.semantic.init.buttons();


			var calendar_char = '';


			$(function () {
				mouse_selection();
			});

			function mouse_selection()
			{
				var isMouseDown = false;

				$('#calendar .content table.ui.basic td')
					.mousedown(function () {
						isMouseDown = true;

						$(this).addClass('highlighted');
						$(this).find('input').val(calendar_char);

						return false; // prevent text selection
					})
					.mouseover(function () {
						if (isMouseDown) {
							$(this).addClass('highlighted');
							$(this).find('input').val(calendar_char);
						}
					});

				$(document)
					.mouseup(function () {
						isMouseDown = false;
					});
			}
		</script>


		<a href="#" target="_blank" id="button-save" class="ui blue submit button small" onclick="calendar.save(0); $('#calendar .icon.close').click(); return false;">Сохранить</a>
		</div>
		</div>
		</div>

		<div style="display: none">
			<table>
				<tr id="calendar-hidden">
					<?php 
        for ($i = 1; $i < 53; $i++) {
            ?>
							<td>
								<div class="ui form">
									<div class="inline field">
										<input class="<?php 
            echo $i;
            ?>
" type="text" maxlength="2">
									</div>
								</div>
							</td>
							<?php 
        }
        ?>
				</tr>
			</table>
		</div>


		<script>
			function save(is_tmp)
			{
				var report = new Report();
				$.ajax(
					{
						url: '/?page=reports-new&task=add&ajax=true&is_tmp=' + is_tmp,

						data:
						{
							is_tmp:              is_tmp,

							year:                report.year,
							duration:            report.duration,
							rector:              report.rector,
							registration_number: report.registration_number,
							training_form_id:    report.training_form_id,
							qualification_id:    report.qualification_id,
							specialty_id:        report.specialty_id,
							specialization_id:   report.specialization_id
						},

						success: function (report_id)
						{
							console.log(report_id);

							if (report_id)
							{
								if (is_tmp)
								{
									calendar.save(1, report_id, true);
								}
								else
								{
									calendar.save(0, report_id, false);
									rude.redirect('/?page=reports-edit&report_id=' + report_id);
								}
							}
						}
					});
			}



			function Report()
			{
				this.year                = $('#year').val();
				this.duration            = $('#duration').val();
				this.rector              = $('#rector').val();
				this.registration_number = $('#registration_number').val();
				this.training_form_id    = $('#training_form_id').val();
				this.qualification_id    = $('#qualification_id').val();
				this.specialty_id        = $('#specialty_id').val();
				this.specialization_id   = $('#specialization_id').val();
			}

			var calendar =
			{

				reset: function()
				{
					$('#calendar .generated').remove();
				},

				update: function()
				{
					var duration = $('#duration').val();

					if (calendar.duration === null || calendar.duration != duration)
					{
						calendar.reset();

						var row = $('#calendar-hidden').html();

						for (var i = 1; i <= duration; i++)
						{
							$('#calendar table').append('<tr id="generated-' + i + '" class="generated"><td>' + rude.romanize(i) + '</td>' + row + '</tr>');
						}
					}

					calendar.duration = duration;

					mouse_selection();
				},

				popup: function()
				{
					if (calendar.duration === null)
					{
						calendar.update();
					}

					$('#calendar').modal('show').modal('cache sizes');

					setTimeout(function() {
						$('#calendar').modal('refresh');
					}, 750);
				},

				get: function()
				{
					var result = [];

					for (var i = 1; i <= $('#duration').val(); i++)
					{
						var selector = '#generated-' + i;

						if ($(selector).length)
						{
							var cols = $(selector + ' td').length;

							for (var j = 1; j < cols; j++)
							{
								if ($(selector + ' .' + j).val() !== '')
								{
									result.push([i, j, $(selector + ' .' + j).val()]);
								}
							}
						}
					}

					return result;
				},

				save: function(is_tmp, report_id, prewiew)
				{
					var data = calendar.get();





					$.ajax(
						{
							url: '/?page=calendar&task=save&ajax=true',

							type: 'POST',

							data:
							{
								is_tmp: is_tmp,

								data: data,
								report_id: report_id
							},

							success: function (data)
							{
								console.log(data);


								if (prewiew)
								{
									rude.open('/?page=reports-preview&is_tmp=1&report_id=' + report_id, true);
								}
							}
						});
				}
			}
		</script>
		</div>
		</div>
		</div>
	<?php 
    }
    public function main()
    {
        ?>
		<div id="main">
			<div id="reports-new">
				<div class="ui error form segment square-corners no-shadow">
					<div class="three fields">
						<div class="field">
							<label>Год набора</label>
							<input id="year" name="year" placeholder="<?php 
        echo date::year();
        ?>
" type="text" value="<?php 
        echo $this->report->year;
        ?>
">
						</div>

						<div class="field">
							<label>Срок обучения (лет)</label>
							<input id="duration" name="duration" placeholder="4" type="text" value="<?php 
        echo $this->report->duration;
        ?>
" onchange="calendar.update();">
						</div>

						<div class="field">
							<label>ФИО ректора</label>
							<input id="rector" name="rector" placeholder="М.П. Батура" type="text" value="<?php 
        echo $this->report->rector;
        ?>
">
						</div>
					</div>

					<div class="field">
						<label>Регистрационный номер учебного плана</label>
						<input id="registration_number" name="registration_number" placeholder="2014.09.20/000" type="text" value="<?php 
        echo $this->report->registration_number;
        ?>
">
					</div>

					<div class="field">
						<div class="ui fluid selection dropdown">
							<div class="default text">Форма обучения</div>
							<i class="dropdown icon"></i>
							<input type="hidden" id="training_form_id" name="training_form_id" value="<?php 
        echo $this->report->training_form_id;
        ?>
">
							<div class="menu">
								<?php 
        $training_forms = training_forms::get();
        if ($training_forms) {
            foreach ($training_forms as $training_form) {
                ?>
											<div class="item" data-value="<?php 
                echo $training_form->id;
                ?>
"><?php 
                echo html::escape($training_form->name);
                ?>
</div>
											<?php 
            }
        }
        ?>
							</div>
						</div>
					</div>

					<div class="field">
						<div class="ui fluid selection dropdown">
							<div class="default text">Квалификация специалиста</div>
							<i class="dropdown icon"></i>
							<input type="hidden" id="qualification_id" name="qualification_id" value="<?php 
        echo $this->report->qualification_id;
        ?>
">
							<div class="menu">
								<?php 
        $qualifications = qualifications::get();
        if ($qualifications) {
            foreach ($qualifications as $qualification) {
                ?>
											<div class="item" data-value="<?php 
                echo $qualification->id;
                ?>
"><?php 
                echo html::escape($qualification->name);
                ?>
</div>
											<?php 
            }
        }
        ?>
							</div>
						</div>
					</div>

					<div class="field">
						<div class="ui fluid selection dropdown">
							<div class="default text">Специальность</div>
							<i class="dropdown icon"></i>
							<input type="hidden" id="specialty_id" name="specialty_id" value="<?php 
        echo $this->report->specialty_id;
        ?>
">
							<div class="menu">
								<?php 
        $specialties = specialties::get();
        if ($specialties) {
            foreach ($specialties as $specialty) {
                ?>
											<div class="item" data-value="<?php 
                echo $specialty->id;
                ?>
"><?php 
                echo html::escape($specialty->name);
                ?>
</div>
											<?php 
            }
        }
        ?>
							</div>
						</div>
					</div>

					<div class="field">
						<div class="ui fluid selection dropdown">
							<div class="default text">Специализация</div>
							<i class="dropdown icon"></i>
							<input type="hidden" id="specialization_id" name="specialization_id" value="<?php 
        echo $this->report->specialization_id;
        ?>
">
							<div class="menu">
								<?php 
        $specializations = specializations::get();
        if ($specializations) {
            foreach ($specializations as $specialization) {
                ?>
											<div class="item" data-value="<?php 
                echo $specialization->id;
                ?>
"><?php 
                echo html::escape($specialization->name);
                ?>
</div>
											<?php 
            }
        }
        ?>
							</div>
						</div>
					</div>

					<div class="field width50">
						<label>Учебная практика</label>
						<textarea id="study_practice" name="study_practice"><?php 
        echo $this->report->study_practice;
        ?>
</textarea>
					</div>

					<div class="field width50">
						<label>Производственная практика</label>
						<textarea id="manufact_practice" name="manufact_practice"><?php 
        echo $this->report->manufact_practice;
        ?>
</textarea>
					</div>

					<div class="field width50">
						<label>Дипломные проекты или дипломные работы</label>
						<input id="grad_work" name="grad_work" type="text" value="<?php 
        echo $this->report->grad_work;
        ?>
">
					</div>

					<div class="field width50">
						<label>Государственный экзамен</label>
						<input id="gos_exam" name="gos_exam" type="text" value="<?php 
        echo $this->report->gos_exam;
        ?>
">
					</div>

					<div id="education-list">
						<div class="ui form">

						</div>

						<ul id="education-ul">
							<?php 
        $educations = education::get_by_report(get('report_id'));
        ?>
							<?php 
        foreach ($educations as $education) {
            ?>
								<li class="disciplines" data-id="<?php 
            echo $education->id;
            ?>
">
									<div class="actions">
										<div class="ui button red tiny" onclick=" remove_education(this,<?php 
            echo $education->id;
            ?>
);buttons.update();">Удалить</div>
										<div class="ui button blue tiny" onclick="education.filler.popup(education.filler.get(this),education.filler.getdata(this),education.filler.getid(this),<?php 
            echo get('report_id');
            ?>
,<?php 
            echo $education->id;
            ?>
);">Заполнить</div>
									</div>
									<div class="base" onclick="$(this).parent('li').find('.tip').toggle('slow'); $(this).find('i.icon.triangle').toggleClass('down').toggleClass('right')">
										<i class="icon triangle down"></i>
										<span class="description"><?php 
            echo $education->name;
            ?>
</span>
									</div>
									<div class="tip">
										<ul>
											<?php 
            $educations_items = education_items::get_by_order($education->id);
            ?>
											<?php 
            foreach ($educations_items as $item) {
                $values = education_items_values::get_by_education_item_id($item->id);
                ?>
													<li data-order="<?php 
                echo $item->order_num;
                ?>
" data-type="undefined" data-name="<?php 
                echo $item->name;
                ?>
" data-id="<?php 
                echo $item->id;
                ?>
"
														data-values="<?php 
                for ($i = 1; $i < 40; $i++) {
                    foreach ($values as $value) {
                        if ($value->col_num == $i) {
                            echo $value->value;
                        }
                    }
                    echo ',';
                }
                ?>
"
														draggable="true"><?php 
                mb_strlen($item->name) > 96 ? $tmp = mb_substr($item->name, 0, 96, 'utf-8') . '...' : ($tmp = $item->name);
                echo $tmp;
                ?>
														<i class="icon remove circle" style="float: right" onclick="delete_item_discipline(this,<?php 
                echo $item->id;
                ?>
)" title="Удалить"></i>
														<i class="icon angle up" onclick="education.tip.move.up(this);"></i>
														<i class="icon angle down" onclick="education.tip.move.down(this);"></i>
														<div class="ui checkbox" style="float: right" data-content="Дисциплина по выбору">
															<input type="checkbox" class="popup" <?php 
                if ($item->is_optional == '1') {
                    echo "checked='checked'";
                }
                ?>
>
															<label></label>
														</div>
														</li>
												<?php 
            }
            ?>
										</ul>
										<div class="ui search selection dropdown" onclick="">
											<input type="hidden" name="selected">
											<div class="default text" onclick="$(this).html('')" onkeyup="education.hint.init(this)" contenteditable="true">Выберите наименование</div>
											<i class="dropdown icon"></i>
											<div class="menu">
												<?php 
            $disciplines = disciplines::get();
            foreach ($disciplines as $discipline) {
                ?>
													<div class="item" data-type="discipline" data-name="<?php 
                echo $discipline->name;
                ?>
"
														 data-id="<?php 
                echo $discipline->id;
                ?>
"><?php 
                echo $discipline->name;
                ?>
													</div>
												<?php 
            }
            ?>

												<?php 
            $directions = directions::get();
            foreach ($directions as $direction) {
                ?>
													<div class="item" data-type="direction" data-name="<?php 
                echo $direction->name;
                ?>
"
														 data-id="<?php 
                echo $direction->id;
                ?>
"><?php 
                echo $direction->name;
                ?>
													</div>
												<?php 
            }
            ?>

											</div>
										</div>

										<div class="item ui button green" onclick="add_education_item(<?php 
            echo $education->id;
            ?>
,this)">добавить</div>
									</div>
								</li>
							<?php 
        }
        ?>
						</ul>
					</div>

					<script>
						$('.ui.checkbox').popup({ on: 'hover' });


						function add_education_item(education_id,selector){

							if ($(selector).parent('div').find('.text').hasClass('default'))
							{
								alert('Выберите название предмета из выпадающего списка.');

								return;
							}


							var order = $(".tip li").length+1;
							var name = $(selector).closest('.tip').find('.item.active').attr('data-name');
							var report_id = <?php 
        echo get('report_id');
        ?>
;
							$.post('/?page=reports-edit&task=add_education_item&report_id='+report_id+'&name='+name+'&education_id='+education_id+'&order='+order+'&ajax=true')
								.done(function(id) { education.tip.add(selector,id)});
						}
						function delete_item_discipline(selector,id){
							var report_id = <?php 
        echo get('report_id');
        ?>
;
							$.post('/?page=reports-edit&task=delete_item_discipline&report_id='+report_id+'&id='+id+'&ajax=true')
								.done(function() { $(selector).parent().remove();});
						}
						function remove_education(selector,id){
							var report_id = <?php 
        echo get('report_id');
        ?>
;
							$.post('/?page=reports-edit&task=remove_education&report_id='+report_id+'&id='+id+'&ajax=true')
								.done(function() { $(selector).closest('li').fadeToggle('slow', function() { $(selector).closest('li').remove();  } )});
						}
						<?php 
        $disciplines = disciplines::get();
        $directions = directions::get();
        $database = null;
        if ($disciplines) {
            foreach ($disciplines as $discipline) {
                $database .= '["discipline", "' . html::escape($discipline->name) . '", ' . $discipline->id . '],';
            }
            $database = char::remove_last($database);
        }
        if ($directions) {
            if ($database) {
                $database .= ',';
            }
            foreach ($directions as $direction) {
                $database .= '["direction", "' . $direction->name . '", ' . $direction->id . '],';
            }
            $database = char::remove_last($database);
        }
        ?>

						var database = [<?php 
        echo $database;
        ?>
];

						$(function() {
							education.disciplines.set(database);
						});
					</script>


					<?php 
        //						$calendar = new ajax_calendar();
        //						$calendar->html();
        ?>

					<div class="ui green submit button small" onclick="update();">Сохранить</div>
					<a href="#" target="_blank" id="button-preview" class="ui blue submit button small" onclick="save(1); return false;">Предпросмотр</a>
					<a href="#" target="_blank" id="button-popup" class="ui blue submit button small" onclick="calendar.popup(); return false;">Календарь</a>
					<a href="#" target="_blank" id="button-education" class="ui blue submit button small" onclick="$('#education').modal('show'); return false;">Добавить цикл</a>

					<div id="education" class="ui modal large">
						<div class="ui form segment">
							<div class="field">
								<label>Наименование цикла</label>
								<input class="education-new" type="text" placeholder="Цикл социально-гуманитарных дисциплин">
							</div>

							<a href="#" class="ui blue submit button small" onclick="
							var name = $('.education-new').val();
							$('.education-new').val('');
							var report_id = <?php 
        echo get('report_id');
        ?>
;
							$.post('/?page=reports-edit&task=add_education&report_id='+report_id+'&name='+name+'&ajax=true')
								.done(function(data) { $('#education').modal('hide');
								education.add(name,data,report_id);
								/*rude.redirect('/?page=reports-edit&report_id='+report_id);*/ }); return false;
							">Добавить</a>
						</div>
					</div>

					<?php 
        static::filler();
        ?>

					<?php 
        static::calendar();
        ?>

				</div>
			</div>
		</div>
		<?php 
    }
    public function main()
    {
        ?>
		<div id="main">
			<?php 
        $specialties = specialties::get();
        ?>
			<table class="ui table segment square-corners celled">
				<thead>
					<tr class="header">
						<th class="numeric">#</th>
						<th>Наименование</th>
						<th class="middle">Факультет</th>
						<th>Квалификация</th>
						<th colspan="2" class="right icon-add"><i class="icon add sign pointer" title="Добавить" onclick="$('#add_modal').modal('show');"></i></th>
					</tr>
				</thead>
				<tbody>
				<?php 
        foreach ($specialties as $specialty) {
            ?>
						<tr id="specialty-<?php 
            echo $specialty->id;
            ?>
">
							<td class="small numeric"><?php 
            echo $specialty->id;
            ?>
</td>
							<td><?php 
            echo $specialty->name;
            ?>
</td>
							<td class="middle"><?php 
            echo $specialty->faculty_shortname;
            ?>
</td>
							<td><?php 
            echo $specialty->qualification_name;
            ?>
</td>
							<?php 
            $faculty_id = faculties::get_by_shortname($specialty->faculty_shortname);
            $qualificatio_id = qualifications::get_by_name($specialty->qualification_name);
            ?>
							<td class="icon first no-border">
								<a href="#" onclick="$('#edit_modal').modal('show'); $('.id').val('<?php 
            echo $specialty->id;
            ?>
');
									$('.editname').val('<?php 
            echo $specialty->name;
            ?>
');
									$('#editfaculty_shortname').val(<?php 
            echo $faculty_id->id;
            ?>
);
									$('#faculty_dd').dropdown('set selected',<?php 
            echo $faculty_id->id;
            ?>
);
									$('#editqualificatio_name').val('<?php 
            echo $qualificatio_id->id;
            ?>
');
									$('#qualificatio_dd').dropdown('set selected',<?php 
            echo $qualificatio_id->id;
            ?>
);">
									<i class="icon edit" title="Редактировать"></i>
								</a>
							</td>
							<td class="icon last no-border">
								<a href="#" onclick="$.post('<?php 
            echo template_url::ajax('specialties', 'remove', $specialty->id);
            ?>
').done(function(answer) { answer_removed(answer, <?php 
            echo $specialty->id;
            ?>
); }); return false;">
									<i class="icon remove circle" title="Удалить"></i>
								</a>
							</td>
						</tr>
						<?php 
        }
        ?>
				</tbody>
			</table>
		</div>

		<script>
			function answer_removed(answer, specialty_id)
			{
				console.log(answer);


				switch(answer)
				{
					case '<?php 
        echo RUDE_AJAX_ERROR;
        ?>
':

						break;

					case '<?php 
        echo RUDE_AJAX_OK;
        ?>
':
						console.log(this);

						$('#specialty-' + specialty_id).fadeOut('slow');
						break;

					case '<?php 
        echo RUDE_AJAX_ACCESS_VIOLATION;
        ?>
':
						$('#access-violation').modal('show');
						break;

					default:
						break;
				}

				return false;
			}
		</script>

		<div id="add_modal" class="ui modal">
			<i class="close icon"></i>
			<div class="header">
				Добавить специальность
			</div>
			<div class="content">
				<div class="ui form segment">
					<div class="field">
						<label for="name">Наименование специальности</label>
						<div class="ui left labeled input">
							<input class="name" name="name" type="text" placeholder="Наименование специальности">
							<div class="ui corner label">
								<i class="icon asterisk"></i>
							</div>
						</div>
					</div>
					<div class="field">
						<label>Факультет</label>
						<div class="ui fluid selection dropdown">
							<div class="default text" >Выберите факультет</div>

							<input type="hidden" id="faculties_name">
							<div style="max-height: 150px;" class="menu">
								<?php 
        $faculty_list = faculties::get();
        foreach ($faculty_list as $faculty) {
            ?>
									<div class="item" data-value="<?php 
            echo $faculty->id;
            ?>
"><?php 
            echo $faculty->shortname;
            ?>
</div>
								<?php 
        }
        ?>
							</div>
						</div>
					</div>
					<div class="field">
						<label>Квалификация</label>
						<div maxlength="50" style="max-height: 16px;" class="ui fluid selection dropdown">
							<div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;width: 413px;" class="default text">Выберите квалификацию</div>

							<input type="hidden" id="qualificatio_name">
							<div style="max-height: 150px; max-width:418px;" class="menu">
								<?php 
        $qualification_list = qualifications::get();
        foreach ($qualification_list as $qualification) {
            ?>
									<div class="item" data-value="<?php 
            echo $qualification->id;
            ?>
"><?php 
            echo $qualification->name;
            ?>
</div>
								<?php 
        }
        ?>
							</div>
						</div>
					</div>
					<div class="ui error message">
						<div class="header">Найдены ошибки при заполнении формы</div>
					</div>
					<div class="ui blue submit button" value="add">Добавить</div>
				</div>
			</div>
		</div>

		<script>

			$('#add_modal .ui.form')
				.form({
					name: {
						identifier : 'name',
						rules: [
							{
								type   : 'empty',
								prompt : 'Пожалуйста, укажите наименование кафедры.'
							}
						]
					},
					qualificatio_name:{
						identifier : 'qualificatio_name',
						rules: [
							{
								type   : 'empty',
								prompt : 'Пожалуйста, укажите квалификацию.'
							}
						]
					},
					faculties_name: {
						identifier : 'faculties_name',
						rules: [
							{
								type   : 'empty',
								prompt : 'Пожалуйста, укажите факультет.'
							}
						]
					}

				},
				{
					onSuccess: function()
					{
						var name = $('.name').val();
						var faculti_id = $('#faculties_name').val();
						var qualif_id = $('#qualificatio_name').val();
						$.post('/?page=specialties&task=add&name='+name+'&faculti_id='+faculti_id+'&qualif_id='+qualif_id+'&ajax=true')
							.done(function() { $('#add_modal').modal('hide');  rude.redirect('/?page=specialties');}); return false;
					}
				})
			;
		</script>


		<div id="edit_modal" class="ui modal">
			<i class="close icon"></i>
			<div class="header">
				Редактировать специальность
			</div>
			<div class="content">
				<div class="ui form segment">
					<div class="field">
						<label for="editname">Наименование специальности</label>
						<div class="ui left labeled input">
							<input class="editname" name="editname" type="text" placeholder="Наименование специальности">
							<div class="ui corner label">
								<i class="icon asterisk"></i>
							</div>
						</div>
					</div>
					<div class="field" hidden>
						<label for="id">id</label>
						<div class="ui left labeled icon input">
							<input class="id" name="id" type="text" placeholder="id">
							<div class="ui corner label">
								<i class="icon asterisk"></i>
							</div>
						</div>
					</div>
					<div class="field">
						<label>Факультет</label>
						<div class="ui fluid selection dropdown" id="faculty_dd">
							<div class="text" id="facul_text">Выберите факультет</div>

							<input type="hidden" id="editfaculty_shortname">
							<div style="max-height: 150px;" class="menu">
								<?php 
        $faculty_list = faculties::get();
        foreach ($faculty_list as $faculty) {
            ?>
									<div class="item" data-value="<?php 
            echo $faculty->id;
            ?>
"><?php 
            echo $faculty->shortname;
            ?>
</div>
								<?php 
        }
        ?>
							</div>
						</div>
					</div>
					<div class="field">
						<label>Квалификация</label>
						<div maxlength="50" style="max-height: 16px;" class="ui fluid selection dropdown" id="qualificatio_dd">
							<div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;width: 413px;" class="text">Выберите квалификацию</div>

							<input type="hidden" id="editqualificatio_name">
							<div style="max-height: 150px; max-width:418px;" class="menu">
								<?php 
        $qualification_list = qualifications::get();
        foreach ($qualification_list as $qualification) {
            ?>
									<div class="item" data-value="<?php 
            echo $qualification->id;
            ?>
"><?php 
            echo $qualification->name;
            ?>
</div>
								<?php 
        }
        ?>
							</div>
						</div>
					</div>
					<div class="ui error message">
						<div class="header">Найдены ошибки при заполнении формы</div>
					</div>
					<div class="ui blue submit button" value="edit">Изменить</div>
				</div>
			</div>
		</div>

		<script>

			$('#edit_modal .ui.form')
				.form({
					editname: {
						identifier : 'editname',
						rules: [
							{
								type   : 'empty',
								prompt : 'Пожалуйста, укажите наименование кафедры.'
							}
						]
					},
					editqualificatio_name:{
						identifier : 'editqualificatio_name',
						rules: [
							{
								type   : 'empty',
								prompt : 'Пожалуйста, укажите квалификацию.'
							}
						]
					},
					editfaculty_shortname: {
						identifier : 'editfaculty_shortname',
						rules: [
							{
								type   : 'empty',
								prompt : 'Пожалуйста, укажите факультет.'
							}
						]
					}

				},
				{
					onSuccess: function()
					{
						var name = $('.editname').val();
						var id = $('.id').val();
						var faculti_id = $('#editfaculty_shortname').val();
						var qualif_id = $('#editqualificatio_name').val();
						$.post('/?page=specialties&task=edit&id='+id+'&name='+name+'&faculti_id='+faculti_id+'&qualif_id='+qualif_id+'&ajax=true')
							.done(function() { $('#edit_modal').modal('hide');  rude.redirect('/?page=specialties');}); return false;
					}
				})
			;
		</script>
		<?php 
    }