<?php
	Assets::add( 'select2' );
	Assets::add( 'users.min.js' );
	Assets::add( 'amib-datepicker' );
	Assets::add( 'momentjs' );
	Assets::add( 'users.css' );
	AMIB::add_js_translation( trans( 'user.js-msgs' ) );
?>
<?php $__env->startSection( 'head' ); ?>
	<script>
		var deleteUrl = "<?php echo route( 'delete-user-ajax' ); ?>";
		var getUserDataUrl = "<?php echo route( 'get-user-data-ajax' ); ?>";
		var citiesAjaxUrl = "<?php echo route( 'get-cities-ajax' ); ?>";
		var companiesAjaxUrl = "<?php echo route( 'get-companies-ajax' ); ?>";
		var examsAjaxUrl = "<?php echo route( 'get-exams-ajax' ); ?>";
		var searchedCompany = <?php echo AMIB::json_encode( $searched_company ); ?>;
	</script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection( 'content' ); ?>
	<div class="pure-g">
		<div class="pure-u-1 pure-u-lg-2-3">
			<?php echo Form::model( $old_search_data, array( 'method' => 'get', 'id' => 'search_form' ) ); ?>

				<div class="pure-g">
					<span class="search-field pure-u-1 pure-u-lg-1-2">
						<?php echo Form::label( 's_name', trans( 'user.fname' ) ); ?>

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

					</span>
					<span class="search-field pure-u-1 pure-u-lg-1-2">
						<?php echo Form::label( 's_national_code', trans( 'user.national_code' ) ); ?>

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

					</span>
					<span class="search-field pure-u-1 pure-u-lg-1-2">
						<?php echo Form::label( 's_company', trans( 'user.company_id' ) ); ?>

						<?php echo Form::select( 's_company', array(), null, array( 'class' => 'company-select' ) ); ?>

					</span>
					<span class="search-field pure-u-1 pure-u-lg-1-2">
						<?php echo Form::label( 's_province_id', trans( 'user.province_id' ) ); ?>

						<?php echo Form::select( 's_province_id', $provinces_select ); ?>

					</span>
				</div>
				<?php echo Form::hidden( 'sort' ); ?>

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

				<a href="<?php echo route( 'users' ); ?>" class="button"><?php echo trans( 'main.show-all' ); ?></a>
			<?php echo Form::close(); ?>

		</div>

		<div class="pure-u-1 pure-u-lg-1-3">
			<?php echo Form::model( $old_search_data, array( 'method' => 'get', 'id' => 'sort_form' ) ); ?>

				<?php echo Form::label( 'sort', trans( 'main.sort' ) ); ?>

				<?php echo Form::select( 'sort', $sorts_select ); ?>

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

		</div>
	</div>

	<?php if( count( $users ) ): ?>
		<table id="users-table" class="default">
			<thead>
				<tr>
					<th><?php echo trans( 'main.row' ); ?></th>
					<th><?php echo trans( 'user.fname' ); ?></th>
					<th><?php echo trans( 'user.lname' ); ?></th>
					<th><?php echo trans( 'user.national_code' ); ?></th>
					<th><?php echo trans( 'user.father_name' ); ?></th>
					<th><?php echo trans( 'user.company_name' ); ?></th>
					<!-- <th><?php echo trans( 'user.userable_type' ); ?></th> -->
					<th></th>
				</tr>
			</thead>
			<tbody>
				<?php $row = $users->getFrom(); ?>
				<?php foreach( $users as $user ): ?>
					<tr data-user-id="<?php echo $user->userable_id; ?>" class="active-<?php echo $user->active; ?> user-type-<?php echo $user->userable_type; ?>">
						<td><?php echo en2fa( $row++ ); ?></td>
						<td><?php echo $user->isAdmin() ? '<i class="fa fa-user"></i> ' : ''; ?><?php echo e($user->fname); ?></td>
						<td><?php echo e($user->lname); ?></td>
						<td><?php echo e($user->national_code); ?></td>
						<td><?php echo e($user->father_name); ?></td>
						<td><?php echo e($user->company_name); ?></td>
						<!-- <td><?php echo e($user->type_text); ?></td> -->
						<td>
							<?php echo HTML::link( '#', trans( 'main.edit' ), array( 'class' => 'button edit' ) ); ?>

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

							<?php echo HTML::link( route( 'user-exams', array( $user->userable_id ) ), trans( 'user.exams' ), array( 'class' => 'button exams' ) ); ?>

							<?php echo HTML::link( route( 'user-chart', array( $user->userable_id ) ), trans( 'user.chart' ), array( 'class' => 'button chart' ) ); ?>

							<?php echo HTML::link( '#', trans( 'main.delete' ), array( 'class' => 'button delete' ) ); ?>


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

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

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

	<hr>

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

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


	<span class="splitter"></span>

	<?php echo HTML::link( '#', trans( 'user.import' ), array( 'class' => 'button', 'id' => 'import' ) ); ?>

	<?php echo HTML::link( '#', trans( 'user.import-groups' ), array( 'class' => 'button', 'id' => 'import-groups' ) ); ?>

	<?php echo HTML::link( '#', trans( 'user.sell-pack' ), array( 'class' => 'button', 'id' => 'sell-pack' ) ); ?>


	<span class="splitter"></span>

	<?php echo HTML::linkRoute( 'users', trans( 'user.export' ), $old_search_data + [ 'output_type' => 'csv' ], array( 'class' => 'button', 'id' => 'export' ) ); ?>


	<div id="add-edit-popup" class="white-popup mfp-hide mfp-with-anim">
		<?php echo Form::open( array( 'route' => 'add-edit-user-ajax', 'files' => true, 'class' => 'single-line' ) ); ?>

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

			<?php echo Form::hidden( 'userable_type' ); ?>


			<div class="pure-g">
				<div class="pure-u-1 pure-u-md-1-2 l-box">
					<?php echo Form::label( 'fname', trans( 'user.fname' ) ); ?>

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


					<?php echo Form::label( 'lname', trans( 'user.lname' ) ); ?>

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


					<?php echo Form::label( 'gender', trans( 'user.gender' ) ); ?>

					<?php echo Form::select( 'gender', $genders_select ); ?>


					<?php echo Form::label( 'father_name', trans( 'user.father_name' ) ); ?>

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


					<?php echo Form::label( 'national_code', trans( 'user.national_code' ) ); ?>

					<?php echo Form::text( 'national_code', null, array( 'class' => 'ltr' ) ); ?>


					<?php echo Form::label( 'study_field', trans( 'user.study_field' ) ); ?>

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


					<?php echo Form::label( 'company_id', trans( 'user.company_id' ) ); ?>

					<?php echo Form::select( 'company_id', $companies_select ); ?>


					<?php echo Form::label( 'code', trans( 'user.code' ) ); ?>

					<?php echo Form::text( 'code', null, array( 'class' => 'ltr' ) ); ?>


					<?php echo Form::label( 'position', trans( 'user.position' ) ); ?>

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


					<?php echo Form::label( 'unit', trans( 'user.unit' ) ); ?>

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


					<?php echo Form::label( 'job', trans( 'user.job' ) ); ?>

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

				</div>

				<div class="pure-u-1 pure-u-md-1-2 l-box">
					<?php echo Form::label( 'province_id', trans( 'user.province_id' ), array( 'class' => 'required' ) ); ?>

					<?php echo Form::select( 'province_id', $provinces_select ); ?>


					<?php echo Form::label( 'city_id', trans( 'user.city_id' ), array( 'class' => 'required' ) ); ?>

					<?php echo Form::select( 'city_id', $cities_select ); ?>


					<?php echo Form::label( 'address', trans( 'user.address' ) ); ?>

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


					<?php echo Form::label( 'mobile', trans( 'user.mobile' ), array( 'class' => 'required' ) ); ?>

					<?php echo Form::text( 'mobile', null, array( 'class' => 'ltr' ) ); ?>


					<?php echo Form::label( 'email', trans( 'user.email' ), array( 'class' => 'required' ) ); ?>

					<?php echo Form::text( 'email', null, array( 'class' => 'ltr' ) ); ?>


					<?php echo Form::label( 'password', trans( 'user.password' ) ); ?>

					<?php echo Form::password( 'password' ); ?>


					<?php echo Form::label( 'password_confirmation', trans( 'user.password_confirmation' ) ); ?>

					<?php echo Form::password( 'password_confirmation' ); ?>


					<?php echo Form::label( 'bc_num', trans( 'user.bc_num' ) ); ?>

					<?php echo Form::text( 'bc_num', null, array( 'class' => 'ltr' ) ); ?>


					<?php echo Form::label( 'bc_location', trans( 'user.bc_location' ) ); ?>

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


					<?php echo Form::label( 'image', trans( 'user.image' ) ); ?>

					<?php echo Form::file( 'image' ); ?>


					<div>
						<?php echo Form::label( 'active', trans( 'user.active' ), array( 'class' => 'required' ) ); ?>

						<?php echo Form::checkbox( 'active' ); ?>

					</div>
				</div>

				<div class="pure-u-1 ff l-box">
					<h2><?php echo trans( 'user.attachments' ); ?></h2>
					<div id="attachments-container"><!-- fbjs --></div>

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

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

	</div>

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

			<table>
				<tr>
					<td><?php echo Form::label( 'file', trans( 'user.import-file' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::file( 'file', null ); ?></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>
	
	<div id="import-groups-popup" class="white-popup mfp-narrow mfp-hide mfp-with-anim">
		<a href="img/groups.xlsx" class="button" target="_BLANK"><?php echo trans( 'user.sample-import-file' ); ?></a>
		<hr>
		<?php echo Form::open( array( 'route' => 'import-user-groups', 'files' => true ) ); ?>

			<table>
				<tr>
					<td><?php echo Form::label( 'groups-file', trans( 'user.import-groups-file' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::file( 'groups-file', null ); ?></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>

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

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

			<table>
				<tr>
					<td><?php echo Form::label( 'exam_id', trans( 'exam.name' ), array( 'class' => 'required' ) ); ?></td>
					<td><?php echo Form::select( 'exam_id', array(), null, array( 'class' => 'exam-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' ); ?>

					</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( 'exam.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>

	<div id="access-popup" class="white-popup mfp-narrow mfp-hide mfp-with-anim">
		<?php echo Form::open( array( 'route' => 'update-user-access', 'files' => true ) ); ?>

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


			<h2>دسترسی مدیریت به دوره‌ها</h2>
			<div id="courses-access"><!-- fbjs --></div>

			<?php echo Form::select( 'access_course_id', $courses_select ); ?>

			<a href="#" class="button add" id="add-course-access"><?php echo trans( 'main.add' ); ?></a>

			<script type="amib/template" id="course-access-template">
				<div class="access">
					<input type="hidden" name="courses-access[]" value="%id%">
					<a href="#" class="button delete"><?php echo trans( 'main.delete' ); ?></a>
					<span class="name">%name%</span>
				</div>
			</script>

			<h2>دسترسی مدیریت به آزمون‌ها</h2>
			<div id="exams-access"><!-- fbjs --></div>

			<?php echo Form::select( 'access_exam_id', $exams_select ); ?>

			<a href="#" class="button add" id="add-exam-access"><?php echo trans( 'main.add' ); ?></a>

			<script type="amib/template" id="exams-access-template">
				<div class="access">
					<input type="hidden" name="exams-access[]" value="%id%">
					<a href="#" class="button delete"><?php echo trans( 'main.delete' ); ?></a>
					<span class="name">%name%</span>
				</div>
			</script>

			<hr>

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

				<div class="progress"><div></div></div>
			</div>
		<?php echo Form::close(); ?>

	</div>

	<div id="sell-pack-popup" class="white-popup mfp-mid-size mfp-hide mfp-with-anim">
		<?php echo Form::open( array( 'route' => 'sell-pack-ajax' ) ); ?>

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

				<tr>
					<td><?php echo Form::label( 'sp_course_id', trans( 'course.name' ) ); ?></td>
					<td><?php echo Form::select( 'sp_course_id', $courses_select ); ?></td>
				</tr>
				<tr>
					<td><?php echo Form::label( 'sp_course_price', trans( 'user.sell_pack_price' ) ); ?></td>
					<td><?php echo Form::text( 'sp_course_price' ); ?></td>
				</tr>

				<tr>
					<td><?php echo Form::label( 'sp_exam_id', trans( 'exam.name' ) ); ?></td>
					<td><?php echo Form::select( 'sp_exam_id', $exams_select ); ?></td>
				</tr>
				<tr>
					<td><?php echo Form::label( 'sp_exam_price', trans( 'user.sell_pack_price' ) ); ?></td>
					<td><?php echo Form::text( 'sp_exam_price' ); ?></td>
				</tr>

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

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


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

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

						<?php echo Form::hidden( 'sp_start_timestamp' ); ?>

					</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(); ?>