<?php

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

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

$Surveys = Common::getSurvey();
$Locations = Common::getLocations();
$PIDs = Common::getIpcPIDs();
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::getIpcPIDs(Yii::$app->params['SURVEY'], Yii::$app->params['LOCATION']);
}

$JS = "

	$('.datepicker').datepicker({autoclose: true, startDate: '0', endDate: '0', format: '".strtolower(Yii::$app->formatter->dateFormat)."'});
		
	
	
	$('#ipc-ipc_q1').change(function(){	
	    var today='".date('d-m-Y')."';
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		 if($(this).val() != '1') {
			 $('div.form-group.field-ipc-ipc_q2').removeClass('required').hide();
			 $('#ipc-ipc_q2').val('');                     
			 
		} else {		  
			 $('div.form-group.field-ipc-ipc_q2').addClass('required').show();	
			 $('#ipc-ipc_q2').val(today); 
		}
		
	});	
	
		
	$('#ipc-ipc_q1').trigger('change');
	
	";

$this->registerJs($JS);

?>

<div class="artbook-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(['enableAjaxValidation' => false, 'options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data']]);
						$template = [
							'labelOptions' => ['class' => 'form-label'],
							'template' => '<div class="col-sm-5">{label}{hint}</div><div class="col-sm-4">{input}{error}</div>',
						];						
						$htemplate = [
							'options' => ['tag' => false],
							'template' => '{input}'
						];						
					?>
					<?php // $form->errorSummary($model); ?>
					<?= Common::generateControl($form, $model, $template, 'ipc_sid', $Surveys, 'survey', 'getIpcPIDs') ?>
					<?= Common::generateControl($form, $model, $template, 'ipc_loc', $Locations, 'location', '', [Html::getInputId($model, 'ipc_sid')]) ?>
					<?= Common::generateControl($form, $model, $template, 'ipc_pid', $PIDs, 'pid', '', [Html::getInputId($model, 'ipc_sid'), Html::getInputId($model, 'ipc_loc')]) ?>
					<?= $form->field($model, 'ipc_q1', $template)->dropDownList($model->yes_no,['prompt'=>'Select']) ?>		
                    <?= $form->field($model, 'ipc_q2', $template)->textInput(['class' => 'form-control datepicker']) ?>					
					<?= $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>