<?php

use app\base\Common;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use kartik\widgets\DepDrop;
use yii\helpers\Url;


/* @var $this yii\web\View */
/* @var $model app\models\preartbeliefs */
/* @var $form yii\widgets\ActiveForm */

$Surveys = Common::getSurvey();
$PIDs = Common::getHealthSeekingPIDs("");

if(Yii::$app->params['SURVEY'] != '') {
	$Locations = Common::getSurlocations(Yii::$app->params['SURVEY']);
}
if(Yii::$app->params['SURVEY'] != '' && Yii::$app->params['LOCATION'] != '') {
	$Locations = Common::getSurlocations(Yii::$app->params['SURVEY']);
	$PIDs = Common::getHealthSeekingPIDs("artb",Yii::$app->params['SURVEY'], Yii::$app->params['LOCATION']);
}

$JS="

$('#healthseeking-health_seeking_part_id').on('select2:select', function (evt) {
		if($(this)[0].value != '') {
			var ctrlval = $(this)[0].value;
			$.ajax({
				async: false,
				url: '".Url::to(["stime"])."',
	            type: 'post',
	            data: 'id='+ctrlval,			
				
				success: function (response) {
					// do something with response
					//var idusite=response;			
				    
					$('#healthseeking-health_seeking_starttime').val(response);
					                  					
				}
				
			});
		}
	});
	

$('#healthseeking-health_seeking_part_id').on('select2:select', function (evt) {
		if($(this)[0].value != '') {
			var ctrlval = $(this)[0].value;
			$.ajax({
				async: false,
				url: '".Url::to(["appset"])."',
	            type: 'post',
	            data: 'id='+ctrlval,			
				
				success: function (response) {
					// do something with response
					var idusite=response.app_idu;					
				    
	                
					//$('#healthseeking-health_seeking_starttime').val(Stime);
					
					if(idusite==1)	{		 
					 $('#healthseeking-health_seeking_group').val('IDU');
					}					 
                    else {
                      $('#healthseeking-health_seeking_group').val('MSM');	
					}
                    					
				}
				
			});
		}
	});
	
	$('#healthseeking-health_seeking_part_id').on('select2:select', function (evt) {
		if($(this)[0].value != '') {
			var ctrlval = $(this)[0].value;
			$.ajax({
				async: false,
				url: '".Url::to(["reg"])."',
	            type: 'post',
	            data: 'id='+ctrlval,
				
				success: function (response) {
					// do something with response
					var age=response.corfrm_q4;                
					$('#healthseeking-health_seeking_age').val(age);
								  
				}
				
			});
		}
	});
	
	$('#healthseeking-health_seeking_part_id').on('select2:select', function (evt) {
		if($(this)[0].value != '') {
			var ctrlval = $(this)[0].value;
			$.ajax({
				async: false,
				url: '".Url::to(["demog"])."',
	            type: 'post',
	            data: 'id='+ctrlval,
				
				success: function (response) {
					// do something with response
					var gender=response.demographics_q1;  				
					var sexori=response.demographics_q10; 
					
					//console.log()
					$('#healthseeking-health_seeking_gender').val(gender);
					$('#healthseeking-health_seeking_sexual_orientation').val(sexori);
					
								  
				}
				
			});
		}
	});
	
	$('#healthseeking-health_seeking_part_id').on('select2:select', function (evt) {
		if($(this)[0].value != '') {
			var ctrlval = $(this)[0].value;
			$.ajax({
				async: false,
				url: '".Url::to(["demogmaristatus"])."',
	            type: 'post',
	            data: 'id='+ctrlval,
				
				success: function (response) {
					// do something with response					
					var msta=response.demographics_q2;					
					$('#healthseeking-health_seeking_marital_status').val(msta);
								  
				}
				
			});
		}
	});
		
	
	$('#healthseeking-health_seeking_part_id').on('select2:unselect', function (evt) {
		$('#healthseeking-health_seeking_starttime').val('');
		$('#healthseeking-health_seeking_group').val('');
		$('#healthseeking-health_seeking_age').val('');
		$('#healthseeking-health_seeking_gender').val('');
		$('#healthseeking-health_seeking_sexual_orientation').val('');		
		$('#healthseeking-health_seeking_marital_status').val('');
	});


";
$this->registerJs($JS);


?>

<div class="health_seeking-form">
	<div class="panel panel-default">
		<div class="panel-heading">
			
		</div>
		<div class="panel-body">
			<div class="row">
				<div class="col-lg-12">
					<?php
						$form = ActiveForm::begin(['options' => ['class' => 'form-horizontal']]);
						$template = [
							'labelOptions' => ['class' => 'form-label'],
							'template' => '<div class="col-sm-5">{label}{hint}</div><div class="col-sm-4">{input}{error}</div>',
						];
						$chklist_template = [
							'labelOptions' => ['class' => 'form-label'],
							'template' => '<div class="col-sm-5">{label}{hint}</div><div class="col-sm-7 checkbox-list">{input}{error}</div>',
						];
						$htemplate = [
							'options' => ['tag' => false],
							'template' => '{input}'
						];
					?>
					
					<?= Common::generateControl($form, $model, $template, 'health_seeking_survey', $Surveys, 'survey', 'getHealthSeekingPIDs','artb') ?>
					<?= Common::generateControl($form, $model, $template, 'health_seeking_loc', $Locations, 'location', '', [Html::getInputId($model, 'health_seeking_survey')]) ?>
					<?= Common::generateControl($form, $model, $template, 'health_seeking_part_id', $PIDs, 'pid', '', [Html::getInputId($model, 'health_seeking_survey'), Html::getInputId($model, 'health_seeking_loc')]) ?>
					<?= $form->field($model, 'health_seeking_group', $htemplate)->hiddenInput()->label() ?>
					<?= $form->field($model, 'health_seeking_starttime', $htemplate)->hiddenInput()->label() ?>
					 
					<?php if($model->isNewRecord) : ?>	
					 <?= $form->field($model, 'health_seeking_age', $template)->textInput() ?>
					 <?= $form->field($model, 'health_seeking_gender', $template)->dropDownList($model->gender,['prompt'=>'Select']) ?>
					 <?= $form->field($model, 'health_seeking_sexual_orientation', $template)->dropDownList($model->sexori,['prompt'=>'Select']) ?>
					 <?= $form->field($model, 'health_seeking_marital_status', $template)->dropDownList($model->marstatus,['prompt'=>'Select']) ?>
					<?php else: ?>
					 <?= $form->field($model, 'health_seeking_age', $template)->textInput(['disabled' => true]) ?>
					 <?= $form->field($model, 'health_seeking_gender', $template)->dropDownList($model->gender,['prompt'=>'Select','disabled' => true]) ?>
					 <?= $form->field($model, 'health_seeking_sexual_orientation', $template)->dropDownList($model->sexori,['prompt'=>'Select','disabled' => true]) ?>
					 <?= $form->field($model, 'health_seeking_marital_status', $template)->dropDownList($model->marstatus,['prompt'=>'Select','disabled' => true]) ?>
					 
					 <?= $form->field($model, 'health_seeking_age', $htemplate)->hiddenInput(['value' => $model->health_seeking_age])->label("") ?>
					 <?= $form->field($model, 'health_seeking_gender', $htemplate)->hiddenInput(['value' => $model->health_seeking_gender])->label("") ?>
					 <?= $form->field($model, 'health_seeking_sexual_orientation', $htemplate)->hiddenInput(['value' => $model->health_seeking_sexual_orientation])->label("") ?>
					 <?= $form->field($model, 'health_seeking_marital_status', $htemplate)->hiddenInput(['value' => $model->health_seeking_marital_status])->label("") ?>
					<?php endif; ?>
					
										
					<?= $form->field($model, 'health_seeking_q1', $chklist_template)->radioList($model->agree)?>
					<?= $form->field($model, 'health_seeking_q2', $chklist_template)->radioList($model->agree)?>			
					<?= $form->field($model, 'health_seeking_q3', $chklist_template)->radioList($model->agree)?>
					<?= $form->field($model, 'health_seeking_q4', $chklist_template)->radioList($model->agree)?>	
					<?= $form->field($model, 'health_seeking_q5', $chklist_template)->radioList($model->agree)?>
					<?= $form->field($model, 'health_seeking_q6', $chklist_template)->radioList($model->agree)?>	
					<?= $form->field($model, 'health_seeking_q7', $chklist_template)->radioList($model->agree)?>	
					<?= $form->field($model, 'health_seeking_q8', $chklist_template)->radioList($model->agree)?>	
					<?= $form->field($model, 'health_seeking_q9', $chklist_template)->radioList($model->agree)?>
					<?= $form->field($model, 'health_seeking_q10', $chklist_template)->radioList($model->agree)?>
					<?= $form->field($model, 'health_seeking_q11', $chklist_template)->radioList($model->agree)?>
					<?= $form->field($model, 'health_seeking_q12', $chklist_template)->radioList($model->agree)?>			
					<?= $form->field($model, 'health_seeking_q13', $chklist_template)->radioList($model->agree)?>
					<?= $form->field($model, 'health_seeking_q14', $chklist_template)->radioList($model->agree)?>	
					<?= $form->field($model, 'health_seeking_q15', $chklist_template)->radioList($model->agree)?>
					<?= $form->field($model, 'health_seeking_q16', $chklist_template)->radioList($model->agree)?>	
					<?= $form->field($model, 'health_seeking_q17', $chklist_template)->radioList($model->agree)?>	
					<?= $form->field($model, 'health_seeking_q18', $chklist_template)->radioList($model->agree)?>	
					<?= $form->field($model, 'health_seeking_q19', $chklist_template)->radioList($model->agree)?>				
					<?= $form->field($model, 'health_seeking_q20', $chklist_template)->radioList($model->agree)?>
					<?= $form->field($model, 'health_seeking_q21', $chklist_template)->radioList($model->agree)?>
					<?= $form->field($model, 'health_seeking_q22', $chklist_template)->radioList($model->agree)?>		 	
					<?= $form->field($model, 'health_seeking_q23', $chklist_template)->radioList($model->agree)?>
					<?= $form->field($model, 'health_seeking_q24', $chklist_template)->radioList($model->agree)?>	
									    							
					<?= $form->field($model, 'status', $htemplate)->hiddenInput(['value' => 1])->label() ?>
					<?= $form->field($model, $model->isNewRecord ? 'create_user' : 'update_user', $htemplate)->hiddenInput(['value' => yii::$app->user->identity->id])->label("") ?>
					<div class="form-group">
						<div class="col-sm-offset-5 col-sm-7">
							<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
							<?= Html::a('Cancel', ['/'.Yii::$app->controller->id], ['class' => 'btn btn-default']) ?>
						</div>
					</div>
					<?php ActiveForm::end(); ?>
				</div>
				<!-- /.col-lg-6 (nested) -->
			</div>
			<!-- /.row (nested) -->
		</div>
		<!-- /.panel-body -->
	</div>
	<!-- /.panel -->
</div>