<?php
	Assets::add( 'select2' );
	Assets::add( 'amib-datepicker' );
	Assets::add( 'momentjs' );
	Assets::add( 'exams.min.js' );
	// Assets::add( 'exams.css' );
	AMIB::add_js_translation( trans( 'exam.js-msgs' ) );
?>
<?php $__env->startSection( 'head' ); ?>
	<script>
		var deleteUrl = "<?php echo route( 'delete-exam-ajax' ); ?>";
		var getExamDataUrl = "<?php echo route( 'get-exam-data-ajax' ); ?>";
		var coursesAjaxUrl = "<?php echo route( 'get-courses-ajax' ); ?>";
		var getCourseLessonsUrl = "<?php echo route( 'get-course-lessons-ajax' ); ?>";
	</script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection( 'content' ); ?>
	<?php echo Form::model( $old_search_data, array( 'method' => 'get', 'id' => 'search_form' ) ); ?>

		<?php echo Form::text( 's_name' ); ?>

		<?php echo Form::submit( trans( 'main.search' ) ); ?>

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


	<?php if( count( $exams ) ): ?>
		<table id="exams-table" class="default">
			<thead>
				<tr>
					<th><?php echo trans( 'main.row' ); ?></th>
					<th><?php echo trans( 'exam.name' ); ?></th>
					<th><?php echo trans( 'course.active' ); ?></th>
					<th><?php echo trans( 'exam.course_id' ); ?></th>
					<th><?php echo trans( 'exam.start_timestamp' ); ?></th>
					<th><?php echo trans( 'exam.minutes' ); ?></th>
					<th></th>
				</tr>
			</thead>
			<tbody>
				<?php $row = $exams->getFrom(); ?>
				<?php foreach( $exams as $exam ): ?>
					<tr data-id="<?php echo $exam->id; ?>" data-price="<?php echo $exam->price; ?>">
						<td><?php echo en2fa( $row++ ); ?></td>
						<td><?php echo e($exam->name); ?></td>
						<td>
							<?php if( $exam->active == 1 ): ?>
								<i class="fa fa-check"></i>
							<?php else: ?>
								<i class="fa fa-times"></i>
							<?php endif; ?>
						</td>
						<td><?php echo e($exam->course_name); ?></td>
						<td><?php echo e($exam->start_date_persian); ?></td>
						<td><?php echo e(en2fa( $exam->minutes )); ?></td>
						<td>
							<?php if( Auth::user()->isAdmin() ): ?>
								<?php echo HTML::link( '#', trans( 'main.edit' ), array( 'class' => 'button edit' ) ); ?>

								<?php echo HTML::link( '#', trans( 'exam.participate-users' ), array( 'class' => 'button participate' ) ); ?>

							<?php endif; ?>

							<?php echo HTML::linkRoute( 'exam-users', 'شرکت‌کنندگان', array( $exam->id, 'exam' ), array( 'class' => 'button' ) ); ?>


							<?php if( Auth::user()->isAdmin() ): ?>
								<?php if( $exam->poll_id ): ?>
									<?php echo HTML::linkRoute( 'exam-users', 'نظرسنجی‌ها', array( $exam->id, 'poll' ), array( 'class' => 'button' ) ); ?>

								<?php endif; ?>
								<!-- <?php echo HTML::linkRoute( 'export-pre-exam', trans( 'exam.export-pre-exam' ), array( $exam->id ), array( 'class' => 'button excel' ) ); ?> -->
								<?php echo HTML::link( '#', trans( 'main.delete' ), array( 'class' => 'button delete' ) ); ?>

							<?php endif; ?>

							<?php if( $exam->type == 'pdf' || ( $exam->type == 'generic' && $exam->random_questions == 0 ) ): ?>
								<?php echo HTML::linkRoute( 'exam-get-key', 'دریافت کلید', array( $exam->id ), array( 'class' => 'button' ) ); ?>

								<?php echo HTML::linkRoute( 'exam-calc-raw', 'محاسبه ترازها', array( $exam->id ), array( 'class' => 'button' ) ); ?>

							<?php endif; ?>
						</td>
					</tr>
				<?php endforeach; ?>
			</tbody>
		</table>
		<div>
			<?php echo $exams->appends( $old_search_data )->links(); ?>

		</div>
	<?php else: ?>
		<div class="info-message"><?php echo trans( 'main.empty' ); ?></div>
	<?php endif; ?>

	<hr>

	<?php if( Auth::user()->isAdmin() ): ?>
		<?php echo HTML::link( '#', trans( 'exam.new' ), array( 'class' => 'button add-new' ) ); ?>

	<?php endif; ?>

	<div id="add-edit-popup" class="amib-lity lity-hide">
		<?php echo Form::open( array( 'route' => 'add-edit-exam-ajax', 'files' => true ) ); ?>

			<?php echo Form::hidden( 'old_id', null, array( 'id' => 'old_id' ) ); ?>

			<table>
				<tr>
					<td><?php echo Form::label( 'name', trans( 'exam.name' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::text( 'name' ); ?></td>
				</tr>

				<tr class="readonly-if-assigned">
					<td><?php echo Form::label( 'type', trans( 'exam.type' ) ); ?></td>
					<td>
						<?php echo Form::select( 'type', trans( 'exam.types' ) ); ?>

						<?php echo Form::label( 'category_id', trans( 'exam.category_id' ) ); ?>

						<?php echo Form::select( 'category_id', $categories_select ); ?>

					</td>
				</tr>
				
				<tr class="show-if-type-pdf">
					<td><?php echo Form::label( 'pdf_file', trans( 'exam.pdf_file' ), array( 'class' => 'required' ) ); ?></td>
					<td>
						<?php echo Form::file( 'pdf_file' ); ?>

						<div id="old-pdf-file"><a href="#" target="_BLANK">فایل آپلود شده</a></div>
					</td>
				</tr>
				
				<tr class="show-if-type-pdf">
					<td><?php echo Form::label( 'pdf_answer_file', trans( 'exam.pdf_answer_file' ), array( 'class' => 'required' ) ); ?></td>
					<td>
						<?php echo Form::file( 'pdf_answer_file' ); ?>

						<div id="old-pdf-answer-file"><a href="#" target="_BLANK"></a></div>
					</td>
				</tr>
				
				<tr class="show-if-type-pdf">
					<td><?php echo Form::label( 'pdf_key', trans( 'exam.pdf_key' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::textarea( 'pdf_key', null, array( 'class' => 'ltr' ) ); ?></td>
				</tr>

				<tr class="hide-if-type-pdf readonly-if-assigned">
					<td><?php echo Form::label( 'course_id', trans( 'exam.course_id' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::select( 'course_id', array(), null, array( 'class' => 'course-select' ) ); ?></td>
				</tr>

				<tr class="hide-if-type-pdf readonly-if-assigned">
					<td><?php echo Form::label( 'poll_id', trans( 'exam.poll_id' ) ); ?></td>
					<td><?php echo Form::select( 'poll_id', array(), null, array( 'class' => 'poll-select' ) ); ?></td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'start_date', trans( 'exam.start_date' ), array( 'class' => 'required' ) ); ?></td>
					<td>
						<?php echo Form::text( 'start_date' ); ?>

						<?php echo Form::hidden( 'start_date_gregorian', null, array( 'id' => 'start_date_gregorian' ) ); ?>


						<?php echo Form::label( 'start_time', trans( 'exam.start_time' ) ); ?>

						<?php echo Form::text( 'start_time' ); ?>

						<?php echo Form::hidden( 'start_timestamp', null, array( 'id' => 'start_timestamp' ) ); ?>

						<div class="help"><?php echo trans( 'exam.start-help' ); ?></div>
					</td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'minutes', trans( 'exam.minutes' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::text( 'minutes' ); ?></td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'total_mark', trans( 'exam.total_mark' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::text( 'total_mark' ); ?></td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'pass_mark', trans( 'exam.pass_mark' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::text( 'pass_mark' ); ?></td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'negative', trans( 'exam.negative' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::select( 'negative', trans( 'exam.nagative_marks' ) ); ?></td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'price', trans( 'exam.price' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::text( 'price' ); ?> <?php echo trans( 'main.currency' ); ?></td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'show_workbook', trans( 'exam.show_workbook' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::checkbox( 'show_workbook' ); ?></td>
				</tr>

				<!-- <tr>
					<td><?php echo Form::label( 'pre_exam', trans( 'exam.pre_exam' ) ); ?></td>
					<td><?php echo Form::checkbox( 'pre_exam' ); ?></td>
				</tr> -->

				<tr>
					<td><?php echo Form::label( 'show_results', trans( 'exam.show_results' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::checkbox( 'show_results' ); ?></td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'show_certificate', trans( 'exam.show_certificate' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::checkbox( 'show_certificate' ); ?></td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'active', trans( 'exam.active' ) ); ?></td>
					<td><?php echo Form::checkbox( 'active' ); ?></td>
				</tr>

				<tr class="hide-if-type-pdf readonly-if-assigned">
					<td><?php echo Form::label( 'random_questions', trans( 'exam.random_questions' ) ); ?></td>
					<td><?php echo Form::checkbox( 'random_questions' ); ?></td>
				</tr>

				<!-- certificate fields -->
				<tr>
					<td><?php echo Form::label( 'certificate_number', 'شماره مجوز' ); ?></td>
					<td><?php echo Form::text( 'certificate_number' ); ?></td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'certificate_company', 'شاغل در' ); ?></td>
					<td>
						<?php echo Form::text( 'certificate_company' ); ?>

						<?php echo Form::label( 'certificate_course', 'دوره آموزشی' ); ?>

						<?php echo Form::text( 'certificate_course' ); ?>

					</td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'certificate_license','مجوز' ); ?></td>
					<td>
						<?php echo Form::text( 'certificate_license' ); ?>

						<?php echo Form::label( 'certificate_date', 'مورخ مجوز' ); ?>

						<?php echo Form::text( 'certificate_date' ); ?>

					</td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'certificate_from_date', 'از تاریخ' ); ?></td>
					<td>
						<?php echo Form::text( 'certificate_from_date' ); ?>

						<?php echo Form::label( 'certificate_to_date', 'تا تاریخ' ); ?>

						<?php echo Form::text( 'certificate_to_date' ); ?>

					</td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'certificate_hours', 'به مدت ساعت' ); ?></td>
					<td><?php echo Form::text( 'certificate_hours' ); ?></td>
				</tr>
				<!-- end certificate fields -->

				<tr>
					<td colspan="2">
						<h2><?php echo trans( 'exam.lessons' ); ?></h2>
						<div id="lessons" class="box"></div>
						<div id="pdf-lessons" class="box"></div>
						<a href="#" id="add-pdf-lesson" class="button add">اضافه کردن درس</a>
					</td>
					
					<script id="lesson-template" type="amib/template">
						<div class="lesson-row ff">
							<input name="lesson_names[]" type="text" readonly tabindex="-1">
							<input name="lesson_ids[]" type="hidden" value="0">
							<label for="lesson-%id%"><?php echo trans( 'exam.lesson-count' ); ?></label>
							<input id="lesson-%id%" name="lesson_counts[]" type="text" class="ltr">
						</div>
					</script>
					
					<script id="pdf-lesson-template" type="amib/template">
						<div class="lesson-row ff">
							<input name="pdf_lesson_names[]" type="text">
							<label for="pdf-qnums-%id%"><?php echo trans( 'exam.pdf-lesson-questions' ); ?></label>
							<input id="pdf-qnums-%id%" name="pdf_lesson_questions[]" type="text" class="ltr" placeholder="1,2,3,...">
							<a href="#" class="button delete">حذف</a>
						</div>
					</script>
				</tr>

				<tr>
					<td colspan="2">
						<div class="progress"><div></div></div>
						<div class="error-container"></div>
						<?php echo Form::submit( trans( 'main.save' ) ); ?>

					</td>
				</tr>
			</table>
		<?php echo Form::close(); ?>

	</div></div>

	<div id="participate-popup" class="white-popup mfp-mid-size mfp-hide mfp-with-anim">
		<?php echo Form::open( array( 'route' => 'participate-exam-users', 'files' => true ) ); ?>

			<?php echo Form::hidden( 'exam_id', 0, array( 'id' => 'participate_exam_id' ) ); ?>

			<table>
				<tr>
					<td><?php echo Form::label( 'participate_national_codes', trans( 'exam.participate_national_codes' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::textarea( 'participate_national_codes', null, array( 'class' => 'ltr' ) ); ?></td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'p_start_date', trans( 'exam.start_date' ), array( 'class' => 'required' ) ); ?></td>
					<td>
						<?php echo Form::text( 'start_date', null, array( 'id' => 'p_start_date' ) ); ?>

						<?php echo Form::hidden( 'start_date_gregorian', null, array( 'id' => 'p_start_date_gregorian' ) ); ?>


						<?php echo Form::label( 'p_start_time', trans( 'exam.start_time' ) ); ?>

						<?php echo Form::text( 'start_time', null, array( 'id' => 'p_start_time' ) ); ?>

						<?php echo Form::hidden( 'start_timestamp', null, array( 'id' => 'p_start_timestamp' ) ); ?>

					</td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'p_latest_allowed_date', trans( 'exam.latest_allowed_date' ) ); ?></td>
					<td>
						<?php echo Form::text( 'latest_allowed_date', null, array( 'id' => 'p_latest_allowed_date' ) ); ?>

						<?php echo Form::hidden( 'latest_allowed_date_gregorian', null, array( 'id' => 'p_latest_allowed_date_gregorian' ) ); ?>


						<?php echo Form::label( 'p_latest_allowed_time', trans( 'exam.latest_allowed_time' ) ); ?>

						<?php echo Form::text( 'latest_allowed_time', null, array( 'id' => 'p_latest_allowed_time' ) ); ?>

						<?php echo Form::hidden( 'latest_allowed_timestamp', null, array( 'id' => 'p_latest_allowed_timestamp' ) ); ?>

					</td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'participation_method', trans( 'course.participation_method' ) ); ?></td>
					<td><?php echo Form::select( 'participation_method', $participation_methods ); ?></td>
				</tr>

				<tr id="price-row">
					<td><?php echo Form::label( 'buy_price', trans( 'course.price' ) ); ?></td>
					<td><?php echo Form::text( 'buy_price' ); ?></td>
				</tr>

				<tr>
					<td colspan="2">
						<div class="progress"><div></div></div>
						<div class="error-container"></div>
						<?php echo Form::submit( trans( 'main.save' ) ); ?>

					</td>
				</tr>
			</table>
		<?php echo Form::close(); ?>

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