<?php
/* @var $this QuestionController */
/* @var $data Question */
$jawaban=Answer::model()->findByAttributes(
	array(
		'question_id'=>$data->id_question,
		'created_id'=>$u,
		'session_id'=>$sessionid,
		)
	);


if($jawaban===NULL){

						// Apabila Jawaban Kosong

}else{

	?>


	<div class="panel panel-default">
		<div class="panel-heading" data-toggle="collapse" data-parent="#accordion1" href="#collapse-<?php echo $data->id_question; ?>" aria-expanded="false" class="collapsed">
			<h4 class="panel-title">

				<a data-toggle="collapse" data-parent="#accordion1" href="#collapse-<?php echo $data->id_question; ?>" aria-expanded="false" class="collapsed"><i class="icon mdi mdi-chevron-down"></i> <?php echo CHtml::encode("Pertanyaan Ke-". $data->question_sort); ?>

					<?php 
					if($jawaban->answer_status==0){
						// echo "<i class='text-danger mdi mdi-close'></i>";
					}else{
						echo "<i class='text-success mdi mdi-check'></i>";
					}
					?>
					

					<span class="pull-right">

						<span class="label label-success">Nilai <b><?php echo $jawaban->point; //echo Question::model()->sumQustionPointMY($data->id_question,$jawaban->created_id); ?></b></span>

						<span class="label label-danger">Max <b><?php echo $data->point; ?></b></span>

					</span>

				</a>


			</h4>
		</div>
		<div id="collapse-<?php echo $data->id_question; ?>" class="panel-collapse collapse" aria-expanded="false" style="">
			<div class="panel-body">

				<p><h4><?php echo $data->question; ?>
					<?php
					if($data->attachment==1){
						echo "<span class='text-info'><b>( Lampirkan dokumen Pendukung )</b></span></h4>";
					}else{
						echo "</h4>";
					}

					if($jawaban===null){
						throw new CHttpException(404,'Sesi Kuesioner Anda belum di Aktifkan.');
					}else{

						?>
					</p>



					<table class="table table-condensed">
						<?php if($jawaban->question_extend!=""){ ?>
							<TR>
								<TD class="question">Jawaban</TD>
								<TD class="answer">
									<?php echo Answer::model()->AnswerStatus($jawaban->answer_status); ?>
								</TD>
							</TR>
							<?php } ?>
							
							<?php if($jawaban->answer_status==1){ ?>

								<?php if($jawaban->question_extend!=""){ ?>
									<TR>
										<TD class="question"></TD>
										<TD class="answer">
											<?php echo $data->question_extend; ?> 
										</TD>
									</TR>
									<?php } ?>

									<TR>
										<TD class="question"></TD>
										<TD class="answer">
											<?php if($data->type==1){ ?>

												<?php echo $jawaban->QuestionAnswer->name; ?> 

												<?php }elseif($data->type==2){ ?>

													<?php echo Answer::model()->multipleKu($jawaban->answer_multiple);; ?> 

													<?php }else{ ?>

														<?php echo $jawaban->male + $jawaban->female; ?> 

														<?php } ?>
													</TD>
												</TR>
												<?php }else{ ?>
													<TR>
														<TD class="question"></TD>
														<TD class="answer">
															<?php echo $jawaban->answer_status == 0 ? "-" : "Jika Tidak, Alasannya"; ?> 
														</TD>
													</TR>
													<TR>
														<TD class="question"></TD>
														<TD class="answer">
															<?php echo $jawaban->reason == NULL ? "-" : $jawaban->reason; ?> 
														</TD>
													</TR>
													<?php } ?>
													<TR>
														<TD class="question">Catatan</TD>
														<TD class="answer">
															<?php echo $jawaban->answer == NULL ? "-" : $jawaban->answer; ?> 
														</TD>
													</TR>
													<?php if($data->attachment==1){ ?>
														<TR>
															<TD class="question">Lampiran</TD>
															<TD class="answer">
																<?php echo Answer::model()->Attachment($jawaban->attachment); ?>
															</TD>
														</TR>
														<?php } ?>
														<?php if($data->total_children==1){ ?>
															<TR>
																<TD class="question">Jumlah Anak Laki-laki</TD>
																<TD class="answer">
																	<?php echo $jawaban->male; ?>
																</TD>
															</TR>
															<TR>
																<TD class="question">Jumlah Anak Perempuan</TD>
																<TD class="answer">
																	<?php echo $jawaban->female; ?>
																</TD>
															</TR>
															<?php } ?>
															<TR>
																<TD class="question">Nilai</TD>
																<TD class="answer">
																	<?php //echo Question::model()->sumQustionPointMY($data->id_question,$jawaban->created_id); ?>
																	<?php echo $jawaban->point; ?>
																</TD>
															</TR>
															<?php if($jawaban->verified_id==NULL): ?>
															<TR>
																<TD class="question">Status Jawaban</TD>
																<TD class="answer">
																	<?php echo Answer::model()->AnswerVerified($jawaban->verified_answer); ?>
																</TD>
															</TR>						
														<?php endif; ?>

													</table>

													<?php 
													if($jawaban->attachment==1):
														$dataAnswerAttachment=new CActiveDataProvider('AnswerAttachment',array('criteria'=>array('condition'=>'question_id='.$data->id_question.' AND session_id='.$jawaban->session_id)));
													$this->widget('zii.widgets.grid.CGridView', array(
														'id'=>'answer-attachment-grid',
														'summaryText'=>'',
														'dataProvider'=>$dataAnswerAttachment,
														'itemsCssClass' => 'table-responsive table table-striped table-hover table-vcenter',
														'columns'=>array(

															array(   
																'header'=>'Lampiran',
																'type'=>'raw',
																'value'=>'CHtml::link($data->lampiran, array("main/answer/download/id/$data->id_attachment"))',
																),

															),
														)); 
													endif;
													?>

													<style>
														.question{width: 10px;color:#000;}
														.answer{font-weight: 700;font-size: 14px;color:#31708f;}
													</style>

													<?php } ?>

													<?php
													if(YII::app()->user->record->level==1):  
											// echo CHtml::link('Ubah Pertanyaan',
											// 	array('master/question/update', 'id'=>$data->id_question),
											// 	array('class' => 'btn btn-primary btn-warning pull-left btn-flat','title'=>'Ubah Jawaban'));


														echo CHtml::link('<i class="mdi mdi-check"></i> Benar',
															array('main/answer/true', 'id'=>$jawaban->id_answer,'subid'=>$data->sub_id,'userid'=>$u,'token'=>$token,'sessionid'=>$sessionid),
															array('class' => 'btn btn-success btn-info pull-right btn-flat','title'=>'Ubah Jawaban'));

													echo CHtml::link('<i class="mdi mdi-close"></i> Tidak Sesuai',
														array('main/answer/false', 'id'=>$jawaban->id_answer,'subid'=>$data->sub_id,'userid'=>$u,'token'=>$token,'sessionid'=>$sessionid),
														array('class' => 'btn btn-danger btn-info pull-right btn-flat','title'=>'Ubah Jawaban'));

													endif;
													?>



													<?php
													if(YII::app()->user->record->level==1){ 

														if($jawaban->answer_status==0):
															echo "<div class='pull-right label label-danger'>( Belum di Jawab )</div>";
														endif;

													}else{ 

														if($jawaban->answer_status==0){

															echo CHtml::link('Beri Jawaban',
																array('master/question/answer', 'id'=>$jawaban->id_answer,'u'=>$u,'token'=>$token,'sessionid'=>$sessionid),
																array('class' => 'btn btn-primary btn-info pull-right btn-flat','title'=>'Beri Jawaban'));

														}else{

															if($jawaban->verified_id==0){

																echo CHtml::link('Ubah Jawaban',
																	array('master/question/answer', 'id'=>$jawaban->id_answer,'u'=>$u,'token'=>$token,'sessionid'=>$sessionid),
																	array('class' => 'btn btn-primary btn-success pull-right btn-flat','title'=>'Ubah Jawaban'));

															}
														}

													}

													?>





												</div>
											</div>
										</div>



										<?php } ?>
