<?php
	Assets::add( 'my-exams.css' );
?>
<?php $__env->startSection( 'content' ); ?>
	<div id="main-content" class="cc padding">
		<h1><?php echo trans( 'user.my-exams' ); ?></h1>

		<?php if( Session::get( 'message' ) ): ?>
			<?php success_html( Session::get( 'message' ) ); ?>
		<?php endif; ?>

		<?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( 'exam.course_id' ); ?></th>
						<th><?php echo trans( 'begin.allowed_timestamp' ); ?></th>
						<th><?php echo trans( 'exam.minutes' ); ?></th>
						<th><?php echo trans( 'begin.start_timestamp' ); ?></th>
						<th><?php echo trans( 'begin.finalized' ); ?></th>
						<th></th>
					</tr>
				</thead>
				<tbody>
					<?php $row = $exams->getFrom(); ?>
					<?php foreach( $exams as $exam ): ?>
						<tr data-exam-id="<?php echo $exam->id; ?>">
							<td><?php echo en2fa( $row++ ); ?></td>
							<td class="exam-name"><?php echo e($exam->name); ?></td>
							<td><?php echo e($exam->pivot->type == 'exam' ? $exam->course_name : $exam->poll_name); ?></td>
							<td>
								<?php echo unix_to_pdate_time( $exam->pivot->allowed_timestamp ); ?>


								<?php if( $exam->pivot->latest_allowed_timestamp ): ?>
									-
									<?php echo unix_to_pdate_time( $exam->pivot->latest_allowed_timestamp ); ?>

								<?php endif; ?>
							</td>
							<td><?php echo e(en2fa( $exam->pivot->type == 'exam' ? $exam->minutes : '--' )); ?></td>
							<td><?php echo unix_to_pdate_time( $exam->pivot->start_timestamp ); ?></td>
							<td>
								<?php if( $exam->pivot->finalized ): ?>
									<i class="fa fa-check"></i>
								<?php else: ?>
									<i class="fa fa-times"></i>
								<?php endif; ?>
							</td>
							<td>
								<?php if( $exam->pivot->allowed_timestamp > time() ): ?>
									زمان شروع نرسیده است
								<?php endif; ?>

								<?php if(
									$exam->pivot->latest_allowed_timestamp != null &&
									time() > $exam->pivot->latest_allowed_timestamp &&
									$exam->pivot->start_timestamp == null
								): ?>
									زمان مجاز سپری شده است
								<?php endif; ?>

								<?php if(
									$exam->pivot->finalized == 0 &&
									time() >= $exam->pivot->allowed_timestamp &&
									( $exam->pivot->latest_allowed_timestamp == null || time() <= $exam->pivot->latest_allowed_timestamp )
								): ?>
									<!-- begin exam -->
									<?php echo HTML::linkRoute( 'begin-exam', $exam->pivot->start_timestamp ? trans( 'user.continue-exam' ) : trans( 'user.begin-exam' ), array( $exam->pivot->id ), array( 'class' => 'button begin' ) ); ?>


								<?php elseif( $exam->pre_exam == 1 && is_null( $exam->pivot->pre_exam_data ) ): ?>
									<!-- continue pre exam( post exam ) -->
									<?php echo HTML::linkRoute( 'begin-exam', trans( 'user.do-pre-exam' ), array( $exam->pivot->id ), array( 'class' => 'button begin' ) ); ?>

								<?php endif; ?>

								<?php if( $exam->pre_exam == 0 || ! is_null( $exam->pivot->pre_exam_data ) ): ?>
									<!-- check user completed pre_exam -->

									<?php if( $exam->type != 'poll' && $exam->pivot->finalized && $exam->show_workbook ): ?>
										<!-- workbbok -->

										<?php if( raw_results_has_ex_workbook( $exam->pivot->raw_results ) ): ?>
											<?php echo HTML::linkRoute( 'exworkbook', trans( 'user.exworkbook' ), array( $exam->pivot->id ), array( 'class' => 'button workbook' ) ); ?>

										<?php else: ?>
											<?php echo HTML::linkRoute( 'workbook', trans( 'user.workbook' ), array( $exam->pivot->id ), array( 'class' => 'button workbook' ) ); ?>

										<?php endif; ?>

									<?php endif; ?>

									<?php if( $exam->type != 'poll' && $exam->type != 'pdf' && $exam->pivot->finalized && $exam->show_results ): ?>
										<?php echo HTML::linkRoute( 'answer_sheet', trans( 'user.answer-sheet' ), array( $exam->pivot->id ), array( 'class' => 'button answer-sheet' ) ); ?>

									<?php endif; ?>

									<?php if( $exam->show_certificate && $exam->pivot->finalized ): ?>
										<?php echo HTML::linkRoute( 'certificate', trans( 'user.certificate' ), array( $exam->pivot->id ), array( 'class' => 'button certificate' ) ); ?>

									<?php endif; ?>
								<?php endif; ?>
							</td>
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
		<?php else: ?>
			<div class="msg-info"><?php echo trans( 'exam.no-exams-for-you' ); ?></div>
		<?php endif; ?>

		<?php echo $exams->links(); ?>

		<!-- <?php echo HTML::linkRoute( 'buy-exam', trans( 'exam.buy' ), array(), array( 'class' => 'button' ) ); ?> -->
	</div>
<?php $__env->stopSection(); ?>