<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model backend\models\Dt134 */
/* @var $form yii\widgets\ActiveForm */

$this->registerJsFile('/js/touch_0.js'); 
$this->registerJsFile('/js/touch_1.js');
$this->registerJsFile('/js/drawing_0.js');
//$this->registerJsFile('/js/touch_3.js');
//$this->registerJsFile('/js/touch_4.js');
$this->registerJsFile('/js/updatesignatures.js'); //load canvas_3

$yesno = ['no' => 'NO', 'yes' => 'YES'];

	if ($model->tyredepthout1 > 2.0) {
		$out1 = 'Green';
	}elseif ($model->tyredepthout1 <= 2.0 && $model->tyredepthout1 > 1.6) {
		$out1 = 'Orange';
	} elseif ($model->tyredepthout1 < 1.6) {
		$out1 = 'Red';
	}
		
	$out2 = '';
	$out3 = '';
	$out4 = '';
$drivers = \modules\users\models\User::EmployeesU();
$vehicles = yii\helpers\ArrayHelper::map(\modules\cors\models\Vehiclebe::find()->orderby(['reg' => SORT_ASC])->all(), 'id', 'reg');

?>
<div class="d-none">
	<img src="/images/transitvan.png" id='drawing_0' />
</div>
<script>
$(function() {
//	init(); //Drawing
	init0(); //canvas_0
	init1(); //canvas_1
//	init2(); //canvas_2
	//init3(); //canvas_3
	//init4(); //canvas_3
//	init5(); //canvas_3
drawing_0();
	}) ;
</script>
<div class="dt134-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'actid')->hiddenInput()->label(false) ?>
    <?= $form->field($model, 'status')->hiddenInput()->label(false) ?>
    <?= $form->field($model, 'vehiclereg')->hiddenInput()->label(false) ?>
					
	<div class="row">
		<div class="col-sm-3">Driver</div>
		<div class="col-sm-3"><?= $form->field($model, 'driver')->dropdownlist($drivers, ['prompt' => 'Please Select'])->label(false) ?></div>
		<div class="col-sm-3">Vehicle Reg</div>
		<div class="col-sm-3"><?= $form->field($model, 'vehicleid')->dropdownlist($vehicles, ['prompt' => 'Please Select'])->label(false) ?></div>
	</div>
	<div class="row">
		<div class="col-sm-3">Start Mileage</div>
		<div class="col-sm-3"><?= $form->field($model, 'startmileage')->textInput()->label(false) ?></div>
		<div class="col-sm-3">Finish Mileage</div>
		<div class="col-sm-3"><?= $form->field($model, 'finishmileage')->textInput()->label(false) ?></div>

	</div>
	<div class="row">
		<div class="col-sm-2">
			<p><strong>Damage Key</strong></p>
			<p>D = Dent</p>
			<p>S = Scratch</p>
			<p>Sc = Scuff</p>
			<p>C = Chip</p>
			<p>R = Rust</p>
			<p><?= HTML::IMG('/images/fors.png') ?></p>
		</div>    
		<div class="col-sm-9">
			<canvas class="canvas" height="300px" width="700px" id="drawingcanvas_0"></canvas>
		</div>
		<div class="col-sm-1 text-right">
			<?= html::button('Reset', ['onclick' => 'clearCanvas()', 'class' => 'btn btn-danger']); ?>
		</div>
	</div>	
	<div class="row">
		<div class="col-sm-5">Good Visability through all cab windows & mirrors</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question1')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
		<div class="col-sm-5">Exhaust secure with no excess noise or smoke</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question9')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
	</div>
	<div class="row">
		<div class="col-sm-5">Driver controls, seat and safety belt adjusted correctly</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question2')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
		<div class="col-sm-5">Vehicle access , doors, steps and bodywork in good condition</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question10')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
	</div>
	<div class="row">
		<div class="col-sm-5">Windscreen washers, wipers, demister and horn operating correctly</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question3')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
		<div class="col-sm-5">Locking fuel cap in place and not leaking</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question11')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
	</div>
	<div class="row">
		<div class="col-sm-5">All instruments, gauges and other warning devices operating (includingABS/EBS in cab warning lights)</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question4')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
		<div class="col-sm-5">Engine oil, water, windscreen washer and fuel levels checked and no leaks</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question12')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
	</div>
	<div class="row">
		<div class="col-sm-5">Cab clean and tidy</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question5')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
		<div class="col-sm-5">Steering and brakes operating correctly</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question13')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
	</div>
	<div class="row">
		<div class="col-sm-5">Vehichle sitting square and not leaning</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question6')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
		<div class="col-sm-5">Load within limits and secured correctly</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question14')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
	</div>
	<div class="row">
		<div class="col-sm-5">Number plates clearly visable</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question7')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
		<div class="col-sm-5">ABS/EBS warning lights off</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question15')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
	</div>
	<div class="row">			

		<div class="col-sm-5">All lights and reflectors fitted and working</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question8')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
		<div class="col-sm-5">All tyres are checked and meet requirements</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question16')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
	</div>
	<div class="row">			
		<div class="col-sm-5">FORS Badge Clean and readable</div>		
		<div class="col-sm-1"><?= $form->field($model, 'question17')->dropdownlist($yesno, ['prompt' => 'Please Select...'])->label(false) ?></div>		
	</div>
	<div class="row">			
		<div class="col-sm-2">Tyre</div>		
		<div class="col-sm-2">Offside Front</div>		
		<div class="col-sm-2">Nearside Front</div>		
		<div class="col-sm-2">Offside Reat</div>		
		<div class="col-sm-2">Nearside Rear</div>		
		<div class="col-sm-2">Spare</div>		
	</div>
	<div class="row">			
		<div class="col-sm-2">Inside Depths</div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyredepthin1')->textInput(['id' => 'tdin1', 'onChange' => "check('tdin1')"])->label(false) ?></div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyredepthin2')->textInput(['id' => 'tdin2', 'onChange' => "check('tdin2')"])->label(false) ?></div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyredepthin3')->textInput(['id' => 'tdin3', 'onChange' => "check('tdin3')"])->label(false) ?></div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyredepthin4')->textInput(['id' => 'tdin4', 'onChange' => "check('tdin4')"])->label(false) ?></div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyredepthin5')->textInput(['id' => 'tdin5', 'onChange' => "check('tdin5')"])->label(false) ?></div>		
	</div>
	<div class="row">			
		<div class="col-sm-2">Outside Depths</div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyredepthout1')->textInput(['id' => 'tdout1', 'onChange' => "check('tdout1')", 'style' => "background-color: $out1"])->label(false) ?></div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyredepthout2')->textInput(['id' => 'tdout2', 'onChange' => "check('tdout2')"])->label(false) ?></div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyredepthout3')->textInput(['id' => 'tdout3', 'onChange' => "check('tdout3')"])->label(false) ?></div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyredepthout4')->textInput(['id' => 'tdout4', 'onChange' => "check('tdout4')"])->label(false) ?></div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyredepthout5')->textInput(['id' => 'tdout5', 'onChange' => "check('tdout5')"])->label(false) ?></div>		
	</div>	
	<div class="row hidden">			
		<div class="col-sm-2">Pressures</div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyrepressure1')->textInput(['id' => 'tp1'])->label(false) ?></div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyrepressure2')->textInput(['id' => 'tp2'])->label(false) ?></div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyrepressure3')->textInput(['id' => 'tp3'])->label(false) ?></div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyrepressure4')->textInput(['id' => 'tp4'])->label(false) ?></div>		
		<div class="col-sm-2"><?= $form->field($model, 'tyrepressure5')->textInput(['id' => 'tp5'])->label(false) ?></div>		
	</div>
	
	<div class="row">			
		<div class="col-sm-12">Comments</div>		
		<div class="col-sm-12"><?= $form->field($model, 'comments')->textArea()->label(false) ?></div>		
	</div>	
	<div class="row">			
		<div class="col-sm-12">Corrective Measures</div>		
		<div class="col-sm-12"><?= $form->field($model, 'correctivemeasures')->textArea()->label(false) ?></div>		
	</div>
	
	<div class="row">			
		<div class="col-sm-6">Driver 1</div>		
		<div class="col-sm-6">Driver 2</div>		
	</div>
	<div class="row">			
		<div class="col-sm-6"><canvas class="canvas" height="150px" width="300px" id="canvas_0"></canvas></div>		
		<div class="col-sm-6"><canvas class="canvas" height="150px" width="300px" id="canvas_1"></canvas></div>		
	</div>
	<div class="row">
		<div class="col-sm-2">Result</div>		
		<div class="col-sm-4"><?= $form->field($model, 'result')->textInput()->label(false) ?></div>		
		
	</div>
	
				
    <?= $form->field($model, 'image')->hiddenInput(['id' => 'drawingtext_0'])->label(false) ?>
    <?= $form->field($model, 'signature1')->hiddenInput(['id' => 'signature0'])->label(false) ?>
    <?= $form->field($model, 'signature2')->hiddenInput(['id' => 'signature1'])->label(false) ?>



    <div class="form-group">
        <?= Html::submitButton('Save', ['class' => 'btn btn-success', 'onClick' => 'saveImages();']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

<script>
	x= 0;
function saveImages() {
	while (x <= 1)		{
		id = "signature"+x;		cavid = "canvas_"+x;
	document.getElementById(id).value = document.getElementById(cavid).toDataURL();
		x++
	}
	$('#drawingtext_0').val(document.getElementById('drawingcanvas_0').toDataURL());
}
function check(field) {
		field = '#'+field;
		 if ($(field).val() <= 1.6) {
		 	$(field).css('background-color','red'); 
		 	$(field).css('color','white'); 
		 } else if ($(field).val() >= 1.6 && $(field).val() <= 2) {
		 	$(field).css('background-color','orange');
		 	$(field).css('color','white');
		 } else{
		 	$(field).css('background-color','green');
		 	$(field).css('color','white');
		 }
	}

</script>
