<style>
	.accordion {
		background-color: #eee;
		color: #444;
		cursor: pointer;
		/*padding: 18px;*/
		width: 100%;
		border: none;
		/*text-align: left;*/
		outline: none;
		/*font-size: 15px;*/
		transition: 0.4s;
	}

	.active1, .accordion:hover {
		background-color: #ccc;
	}

	.accordion:after {
		content: '\002B';
		color: #007bff;
		font-weight: bold;
		float: right;
		font-size: 150%;
		margin-left: 5px;
	}

	.active1:after {
		content: "\2212";
	}

	.panel {
		padding: 0 18px;
		background-color: white;
		max-height: 0;
		overflow: hidden;
		transition: max-height 0.2s ease-out;
	}
</style>

<section class="container" style="padding-bottom: 2rem;">
	<div class="row">
		<div class="col-sm-12">
			<div class="tab-content" id="tabContent">
				<div class="tab-pane fade show active" id="profile" role="tabpanel" aria-labelledby="profile-tab">
					<div class="card bg-light-transparent">
						<div class="card-header bg-light">
							<h4 class="card-title float-left"><?php echo (empty($ID))?'New ':'Edit '; ?>Training Evaluation Form</h4>
							<h6 class="card-title float-left">1 = Strongly Disagree, 2 = Disagree, 3 = Indifferent, 4 = Agree, 5 = Strongly Agree. Using the scale above, circle the number that best corresponds to your rating for each question.</h6>
						</div>
						<div class="card-body">
							<div class="card no-shadow">
								<div class="card-body">
									<form id="evaluationForm" class="form" action="<?php echo base_url('hr/Serviceform/evaluation_form_save') ?>" method="POST" onsubmit="return confirm('Do you really want to submit the form?')">
										<div class="form-row">
											<div class="col-12 col-sm-4">
												<div class="form-group">
													<label>Name</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($evaluation_detail[0]['user_id'])): ?>
															<input type="text" class="form-control" name="name" id="name" value="<?php echo $evaluation_detail[0]['userName']; ?>" readonly>
															<input type="text" class="form-control" name="user_id" id="user_id" value="<?php echo $evaluation_detail[0]['user_id']; ?>" hidden>
														<?php endif; ?>
													<?php } else { ?>
														<input type="text" class="form-control" name="name" id="name" value="<?php echo $_SESSION['user']['name']; ?>" readonly>
														<input type="text" class="form-control" name="user_id" id="user_id" value="<?php echo $_SESSION['user']['id']; ?>" hidden>
													<?php } ?>
												</div>
											</div>

											<div class="col-12 col-sm-4">
												<div class="form-group">
													<label for="department">Department</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($evaluation_detail[0]['department_id'])): ?>
															<input type="text" class="form-control" name="department" id="department" value="<?php echo $evaluation_detail[0]['dept_name']; ?>" readonly>
															<input type="text" class="form-control" name="department_id" id="department_id" value="<?php echo $evaluation_detail[0]['department_id']; ?>" hidden>
														<?php endif; ?>
													<?php } else { ?>
														<input type="text" class="form-control" name="department" id="department" value="<?php echo $_SESSION['user']['department_name']; ?>" readonly>
														<input type="text" class="form-control" name="department_id" id="department_id" value="<?php echo $_SESSION['user']['department_id']; ?>" hidden>
													<?php } ?>
												</div>
											</div>

											<div class="col-12 col-sm-4">
												<div class="form-group">
													<label for="department">Date submitted</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($evaluation_detail[0]['createdTS'])): ?>
															<input type="" class="form-control" name="reqDate" id="reqDate" value="<?php echo (!empty($ID))?date('d-m-Y',strtotime($evaluation_detail[0]['createdTS'])):''; ?>" readonly/>
														<?php endif; ?>
													<?php } else { ?>
														<input type="" class="form-control" name="date" id="date" value="<?php echo date("d-m-Y"); ?>" readonly/>
													<?php } ?>
												</div>
											</div>
										</div>

										<div class="form-row">
											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label for="title">Training Title</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($evaluation_detail[0]['training_title'])): ?>
															<input type="text" class="form-control" name="title" id="title" value="<?php echo (!empty($ID))?$evaluation_detail[0]['training_title']:''; ?>" readonly>
														<?php endif; ?>
													<?php } else{ ?>
														<input type="text" class="form-control" name="title" id="title" value="" required>
													<?php } ?>
												</div>
											</div>

											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label for="date">Date of training </label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($evaluation_detail[0]['training_date'])): ?>
															<input type="text" class="form-control" name="date_training" id="date_training" value="<?php echo (!empty($ID))?$evaluation_detail[0]['training_date']:''; ?>" readonly>
														<?php endif; ?>
													<?php } else{ ?>
														<input type="text" class="form-control datepicker" name="date_training" id="date_training" value="" required>
													<?php } ?>
												</div>
											</div>
										</div>

										<div class="form-row">
											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label for="time">Time</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($evaluation_detail[0]['time'])): ?>
															<input type="time" class="form-control" name="time" id="time" value="<?php echo (!empty($ID))?$evaluation_detail[0]['time']:''; ?>" readonly>
														<?php endif; ?>
													<?php } else{ ?>
														<input type="time" class="form-control" name="time" id="time" value="" required>
													<?php } ?>
												</div>
											</div>

											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label for="package">Packages:</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($evaluation_detail[0]['packages'])): ?>
															<input type="text" class="form-control" name="packages" id="packages" value="<?php echo (!empty($ID))?$evaluation_detail[0]['packages']:''; ?>" readonly>
														<?php endif; ?>
													<?php } else{ ?>
														<select class="form-control" name="packages" required>
															<option value="" disabled selected>--Please Select--</option>
															<option name="package" value="External">External</option>
															<option name="package" value="Internal">Internal</option>
															<option name="package" value="In-house">In-house</option>
														</select>
													<?php } ?>
												</div>
											</div>
										</div>

										<div class="form-row">
											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label for="venue">Venue</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($evaluation_detail[0]['venue'])): ?>
															<input type="text" class="form-control" name="venue" id="venue" value="<?php echo (!empty($ID))?$evaluation_detail[0]['venue']:''; ?>" readonly>
														<?php endif; ?>
													<?php } else{ ?>
														<input type="text" class="form-control" name="venue" id="venue" value="" required>
													<?php } ?>
												</div>
											</div>

											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label for="branch">Respective Department / Branch</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($evaluation_detail[0]['department_id'])): ?>
															<input type="text" class="form-control" name="respective_dept" id="respective_dept" value="<?php echo (!empty($ID))?$evaluation_detail[0]['dept_name']. ' / ' . $evaluation_detail[0]['branchName']:''; ?>" readonly>
														<?php endif; ?>
													<?php } else { ?>
														<select class="form-control" name="respective_dept" id="respective_dept" required>
															<option value="" disabled selected>--Please Select--</option>
															<?php if(!empty($rsDepartments)) foreach($rsDepartments as $row) { ?>
																<option value="<?php echo $row['id']; ?>"><?php echo $row['department']; ?></option>
															<?php } ?>
														</select>
													<?php } ?>
												</div>
											</div>
										</div>

										<div class="form-row">
											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label for="hour">CPD / CPE hours</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($evaluation_detail[0]['cpd_hours'])): ?>
															<input type="text" class="form-control" name="hour" id="hour" value="<?php echo (!empty($ID))?$evaluation_detail[0]['cpd_hours']:''; ?>" readonly>
														<?php endif; ?>
													<?php } else{ ?>
														<input type="number" class="form-control" name="hour" id="hour" value="" required>
													<?php } ?>
												</div>
											</div>

											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label for="name">Name of Trainer / Speaker</label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($evaluation_detail[0]['trainer_name'])): ?>
															<input type="text" class="form-control" name="trainer_name" id="trainer_name" value="<?php echo (!empty($ID))?$evaluation_detail[0]['trainer_name']:''; ?>" readonly>
														<?php endif; ?>
													<?php } else{ ?>
														<input type="text" class="form-control" name="trainer_name" id="trainer_name" value="" required>
													<?php } ?>
												</div>
											</div>
										</div>

										<!-- new evaluation -->

										<?php if(!empty($ID)){ ?>
											<?php if(!empty($evaluation_detail)){ foreach($evaluation_detail as $key => $detail){ ?>
												<?php if($detail['question_type']==0){ ?>
													<?php if($detail['question_category_id'] == $detail['category_id']){ ?>
														<div class="form-row">
															<div class="col-12">
																<a class="accordion p-2 bg-light float-right">
																	<?php echo $detail['category_question']; ?>
																</a>
																<div id="speakerDetails" class="col-12 panel">
																	<br>
																	<div class="table-responsive">
																		<table id="qwerty" class="table table-hover table-striped " width="980">
																			<thead align="center"> 
																				<tr>
																					<td></td>
																					<td>1</td>
																					<td>2</td>
																					<td>3</td>
																					<td>4</td>
																					<td>5</td>
																				</tr>
																			</thead>
																			<tbody>
																				<?php for($i=0; $i<sizeof($detail['qtn']); $i++){ ?>
																					<tr align="center">
																						<td class="text-left">
																							<?php echo $detail['qtn'][$i];?>
																						</td>
																						<td>
																							<input type="radio" name="answerRadio[<?php echo $detail['qtn_id'][$i]; ?>]" id="answerRadio[]" value="1" <?php echo ($detail['radio'][$i]==1)?'checked':''; ?>><br>
																						</td>
																						<td>
																							<input type="radio" name="answerRadio[<?php echo $detail['qtn_id'][$i]; ?>]" id="answerRadio[]" value="2" <?php echo ($detail['radio'][$i]==2)?'checked':''; ?>><br>
																						</td>
																						<td>
																							<input type="radio" name="answerRadio[<?php echo $detail['qtn_id'][$i]; ?>]" id="answerRadio[]" value="3" <?php echo ($detail['radio'][$i]==3)?'checked':''; ?>><br>
																						</td>
																						<td>
																							<input type="radio" name="answerRadio[<?php echo $detail['qtn_id'][$i]; ?>]" id="answerRadio[]" value="4" <?php echo ($detail['radio'][$i]==4)?'checked':''; ?>><br>
																						</td>
																						<td>
																							<input type="radio" name="answerRadio[<?php echo $detail['qtn_id'][$i]; ?>]" id="answerRadio[]" value="5" <?php echo ($detail['radio'][$i]==5)?'checked':''; ?>><br>
																						</td>
																					</tr>
																				<?php } ?>
																			</tbody>
																		</table>
																	</div>
																</div>
															</div>
														</div><br>
													<?php } ?>
												<?php } else { ?>
													<div class="form-row">
														<div class="col-12">
															<div class="form-group">
																<?php if($detail['question_category_id'] == $detail['category_id']){ ?>
																	<?php for($i=0; $i<sizeof($detail['qtn']); $i++){ ?>
																		<label for="attend"><?php echo $detail['qtn'][$i]; ?></label>
																		<textarea rows="3" cols="50" class="form-control" name="answerText[<?php echo $detail['qtn_id'][$i]; ?>]" id="answerText[]" value="" readonly><?php echo (!empty($detail['txt']))?$detail['txt'][$i]:''; ?></textarea>
																	<?php } ?>
																<?php } ?>
															</div>
														</div>
													</div>
												<?php } ?>
											<?php } } ?>
										<?php } else { ?>
											<?php if($rsEvaluationQuestion) { foreach($rsEvaluationQuestion as $row) { ?>
												<?php if($row['ID'] <= '4'){ ?>
													<div class="form-row">
														<div class="col-12">
															<a class="accordion p-2 bg-light float-right">
																<?php echo $row['category_question']; ?>
															</a>
															<div id="speakerDetails" class="col-12 panel">
																<br>
																<div class="table-responsive">
																	<table id="qwerty" class="table table-hover table-striped " width="980">
																		<thead align="center"> 
																			<tr>
																				<td></td>
																				<td>1</td>
																				<td>2</td>
																				<td>3</td>
																				<td>4</td>
																				<td>5</td>
																			</tr>
																		</thead>
																		<tbody align="center" >
																			<?php if($row['item']) foreach($row['item'] as $rowItem) {  ?>
																				<?php if(($rowItem['category_id'] == $row['ID'])) { ?>
																					<input type="text" class="form-control" name="question_id[]" id="question_id" value="<?php echo $rowItem['questionID']; ?>" hidden>
																					<input type="text" class="form-control" name="question_type[<?php echo $rowItem['questionID']; ?>]" id="question_type[]" value="<?php echo $rowItem['question_type']; ?>" hidden>

																					<tr>
																						<?php if($rowItem['question_type'] == 0){ ?>
																							<td class="text-left">
																								<?php echo $rowItem['question']; ?>
																							</td>

																							<td >
																								<input type="radio" name="answerRadio[<?php echo $rowItem['questionID']; ?>]" id="answerRadio[]" value="1" ><br>
																							</td>
																							<td>
																								<input type="radio" name="answerRadio[<?php echo $rowItem['questionID']; ?>]" id="answerRadio[]" value="2"><br>
																							</td>
																							<td>
																								<input type="radio" name="answerRadio[<?php echo $rowItem['questionID']; ?>]" id="answerRadio[]" value="3"><br>
																							</td>
																							<td>
																								<input type="radio" name="answerRadio[<?php echo $rowItem['questionID']; ?>]" id="answerRadio[]" value="4"><br>
																							</td>
																							<td>
																								<input type="radio" name="answerRadio[<?php echo $rowItem['questionID']; ?>]" id="answerRadio[]" value="5"><br>
																							</td>
																						<?php } ?>
																					</tr>
																				<?php } ?>
																			<?php } ?>
																		</tbody>
																	</table>
																</div>
															</div>
														</div>
													</div><br>
												<?php } else { ?>
													<?php if($row['item']) foreach($row['item'] as $rowItem) {  ?>
														<?php if(($rowItem['category_id'] == $row['ID'])) { ?>
															<input type="text" class="form-control" name="question_id[]" id="question_id" value="<?php echo $rowItem['questionID']; ?>" hidden>
															<input type="text" class="form-control" name="question_type[<?php echo $rowItem['questionID']; ?>]" id="question_type[]" value="<?php echo $rowItem['question_type']; ?>" hidden>
															<?php if($rowItem['question_type'] == 1){ ?>
																<div class="form-row">
																	<div class="col-12">
																		<div class="form-group">
																			<label for="attend"><?php echo $rowItem['question']; ?></label>
																			<?php if(!empty($ID)){ ?>
																				<?php if(!empty($rsEvaluationAnswer)): foreach($rsEvaluationAnswer as $row): ?>
																					<?php if($row['sv_evaluation_question_id'] == $rowItem['ID']) { ?>
																						<textarea rows="3" cols="50" class="form-control" name="answerText[<?php echo $rowItem['questionID']; ?>]" id="answerText[]" value="" readonly><?php echo (!empty($ID))?$row['answer_text']:''; ?></textarea>
																					<?php } ?>
																				<?php endforeach;endif; ?>
																			<?php } else{ ?>
																				<textarea rows="3" cols="50" class="form-control" name="answerText[<?php echo $rowItem['questionID']; ?>]" id="answerText[]" value=""></textarea>
																			<?php } ?>
																		</div>
																	</div>
																</div>
															<?php } ?>
														<?php } ?>
													<?php } ?>
												<?php } ?>
											<?php } } ?>
										<?php } ?>

										<!-- new evaluation -->

										<div class=" form-row float-right">
											<?php if(!empty($ID)){ ?>
												<a class="btn btn-light" href="<?php echo base_url('hr/serviceform/evaluation_list'); ?>">Close</a>
											<?php } else{ ?>
												<button type="Submit" class="btn btn-primary text-right">Submit</button>
											<?php } ?>

										</div> 
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>

<script>
	var acc = document.getElementsByClassName("accordion");
	var i;

	for (i = 0; i < acc.length; i++) {
		acc[i].addEventListener("click", function() {
			this.classList.toggle("active1");
			var panel = this.nextElementSibling;
			if (panel.style.maxHeight) {
				panel.style.maxHeight = null;
			} else {
				panel.style.maxHeight = panel.scrollHeight + "px";
			} 
		});
	}

	$(function() {
		$('.datepick').datepicker();

		$('.timepicker').timepicker();
	});
</script>