<?php
/* @var $this ClusterController */
/* @var $data Cluster */
?>

<div class="row blok-sub">
	<div class="col-md-12">

		<H3><i class="mdi mdi-badge-check"></i> <?php echo CHtml::encode($data->name); ?></H3>

		<div class="blok-pertanyaan">

			<div class="panel-group" id="accordion">
				<?php foreach (Question::getQuestions($data->id_sub) as $question) { ?>
					<?php
					$jawaban=Answer::model()->findByAttributes(
						array(
							'question_id'=>$question['id_question'],
							'created_id'=>$user_id,
							'session_id'=>$sessionid,
						)
					);

					if($jawaban===NULL){

						// Apabila Jawaban Kosong

					}else{

						?>

						<div class="panel panel-default">
							<div>
								<div class="panel-body">

									<p>
										<h4>
											<?php echo CHtml::encode($question['question_sort']); ?>. <?php echo $question['question']; ?>
											<?php echo $question['attachment']==1 ? "<span class='text-info'><b>( Lampirkan dokumen Pendukung )</b></span>" : ""; ?>
										</h4>
									</p>

									<?php if($jawaban->answer_status==1 || $jawaban->answer_status==2){; ?>

										<table class="table table-condensed">

											<?php if($question['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($question['question_extend']!=""){ ?>
													<TR>
														<TD class="question"></TD>
														<TD class="answer">
															<?php echo $question['question_extend']; ?>
														</TD>
													</TR>
												<?php } ?>
												<TR>
													<TD class="question">Jawaban</TD>
													<TD class="answer">
														<?php if($question['type']==1){ ?>

															<?php echo $jawaban->answer_id==NULL ? "-" : $jawaban->QuestionAnswer->name; ?>

														<?php }elseif($question['type']==2){ ?>

															<?php $jawaban->answer_multiple==NULL ? "-" : Answer::model()->multipleKu($jawaban->answer_multiple); ?>

														<?php }elseif($question['type']==3){ ?>

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

														<?php }else{ ?>

															<?php echo $jawaban->answer_id==NULL ? "-" : $jawaban->QuestionAnswer->name; ?>

														<?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($question['attachment']==1 && AnswerAttachment::model()->countAttachment($jawaban->question_id)!=0){ ?>
												<TR>
													<TD class="question">Lampiran</TD>
													<TD class="answer">
														<?php echo Answer::model()->Attachment($jawaban->attachment); ?>
													</TD>
												</TR>
											<?php } ?>
											<?php if($question['total_children']==1){ ?>
												<TR>
													<TD class="question">Kondisi Sebelum</TD>
													<TD class="answer">
														<?php echo $jawaban->male; ?>
													</TD>
												</TR>
												<TR>
													<TD class="question">Kondisi Sesudah</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($question['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 && AnswerAttachment::model()->countAttachment($jawaban->question_id)!=0):
											$dataAnswerAttachment=new CActiveDataProvider('AnswerAttachment',array('criteria'=>array('condition'=>'question_id='.$question['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;
										?>

									<?php }else{ ?>

										(Belum di Jawab)

									<?php } ?>

								</div>
							</div>
						</div>
						<?php

																	} //End of Answer
																}  //End of Question

																?>

															</div>



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

