<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\date\DatePicker;
/* @var $this yii\web\View */
/* @var $model modules\forms\models\Dttmz */
/* @var $form yii\widgets\ActiveForm */

if (!$model->actid) {$model->actid = Yii::$app->getRequest()->getQueryParam('actid');}
$model->weldersname = Yii::$app->user->identity->username;
$model->weldersstamp = Yii::$app->user->identity->stampno;
$this->registerJsFile('/js/updatesignatures.js'); //load canvas drawing 
$this->registerJsFile('/js/touch_0.js');//load canvas_0
//$this->registerJsFile('/js/touch_1.js');//load canvas_1 
//$this->registerJsFile('/js/touch_2.js'); //load canvas_2 
//$this->registerJsFile('/js/touch_3.js'); //load canvas_3 ?>
<script>
window.onload = function() {
//	init(); //Drawing
	init0(); //canvas_0
//	init1(); //canvas_1
//	init2(); //canvas_2
//	init3(); //canvas_3
	} 
</script>

<div class="dttmz-form">

    <?php $form = ActiveForm::begin(); ?>
    
    <table class="Table">
    	<tr>
    		<th class="DarkerBlue">Date</th>
    		<td><?= $form->field($model, 'date')->widget(DatePicker::class, ['size' => 'sm', 'pluginOptions' => ['showMeridian' =>false, 'format' => 'dd/mm/yyyy']])->label(false) ?></td>
    		<th class="DarkerBlue">Delivery Unit</th>
    		<td><?= $form->field($model, 'deliveryunit')->textInput()->label(false) ?></td>
    	</tr>
    	<tr>
    		<th class="DarkerBlue">Site Location	</th>
    		<td>	<?= $form->field($model, 'sitelocation')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">Route</th>
    		<td><?= $form->field($model, 'route')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue"><?= $model->getAttributelabel('defectno') ?></th>
    		<td><?= $form->field($model, 'defectno')->textInput()->label(false) ?></td>
    		<td></td>
    	</tr>
    	<tr>
    		<th class="DarkerBlue">Line</th>
    		<td><?= $form->field($model, 'line')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">Miles/Yards</th>
    		<td>
    			<?= $form->field($model, 'miles')->textInput()->label(false) ?>
    			<?= $form->field($model, 'yards')->textInput()->label(false) ?>
    		</td>
    		<th class="DarkerBlue">Points No</th>
    		<td><?= $form->field($model, 'pointno')->textInput()->label(false) ?></td>
    	</tr>
    	<tr>
    		<th class="DarkerBlue">Crossing Manufacturer</th>
    		<td><?= $form->field($model, 'crossingmanufacturer')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">Crossing No</th>
    		<td><?= $form->field($model, 'crossingno')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">Leg End</th>
    		<td><?= $form->field($model, 'legendfr')->textInput()->label(false) ?></td>
    	</tr>
    	<tr>
    		<th class="DarkerBlue">Type, Common/Obtuse</th>
    		<td><?= $form->field($model, 'type')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">Angle</th>
    		<td><?= $form->field($model, 'angle')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">Rh/Lh</th>
    		<td><?= $form->field($model, 'legendlhrh')->textInput()->label(false) ?></td>
    	</tr>
    	<tr>
    		<td colspan="6">&nbsp;</td>
    	</tr>
    	<tr>
    		<th colspan="6" class="DarkerBlue">Area that the repair has took place</th>
    	</tr>
    	<tr>
    		<td colspan="6">Manganese only</td>
    	</tr>
    	<tr>
    		<th class="DarkerBlue">Length</th>
    		<td><?= $form->field($model, 'mlength')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">Depth</th>
    		<td><?= $form->field($model, 'mdepth')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">Width</th>
    		<td><?= $form->field($model, 'mwidth')->textInput()->label(false) ?></td>
    	</tr>
    		<tr>
    		<td colspan="6">Manganese + Tri-metal Weld</td>
    	</tr>
    	<tr>
    		<th class="DarkerBlue">Length</th>
    		<td><?= $form->field($model, 'mtlength')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">Depth</th>
    		<td><?= $form->field($model, 'mtdepth')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">Width</th>
    		<td><?= $form->field($model, 'mtwidth')->textInput()->label(false) ?></td>
    	</tr>
    	<tr>
    		<th class="DarkerBlue" colspan="5">Did the repair encroach within 5mm of the Normal Grade rail?</th>
    		<td><?= $form->field($model, 'encrouch5mm')->textInput()->label(false) ?>
    </td>
    		
    	</tr>



		<tr>
			<th class="DarkerBlue" colspan="2">Distance from TMW Normal grade</th>
			<td> <?= $form->field($model, 'distancefromtmwnorm')->textInput()->label(false) ?></td>
			<th class="DarkerBlue" colspan="2">Distance from TMW Manganese</th>
			<td><?= $form->field($model, 'distancefromtmwmang')->textInput()->label(false) ?></td>
		</tr>
		<tr>
			<th class="DarkerBlue" colspan="2">Overall length of repair</th>
			<td><?= $form->field($model, 'overall')->textInput()->label(false) ?></td>
			<th class="DarkerBlue" colspan="2">Depth</th>
			<td><?= $form->field($model, 'depth')->textInput()->label(false) ?></td>
		</tr>
	    	<tr>
    		<td colspan="6">Normal Grade + Tri-metal weld</td>
    	</tr>
    	<tr>
    		<th class="DarkerBlue">Length</th>
    		<td><?= $form->field($model, 'nglength')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">Depth</th>
    		<td><?= $form->field($model, 'ngdepth')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">Width</th>
    		<td><?= $form->field($model, 'ngwidth')->textInput()->label(false) ?></td>
    	</tr>
    	
    	<tr>
    		<th class="DarkerBlue" rowspan="2">Electrode/wire used</th>
    		<td rowspan="2"><?= $form->field($model, 'electrodeused')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue" rowspan="2">Process Used</th>
    		<th class="DarkerBlue">MMA</th>
    		<th class="DarkerBlue">Semi-Auto</th>
    		<th class="DarkerBlue">Fully Auto</th>
    		
    	
    	</tr>
    	<tr>
    		<td><?= $form->field($model, 'processmma')->textInput()->label(false) ?></td>
    		<td><?= $form->field($model, 'processsemiauto')->textInput()->label(false) ?></td>
    		<td><?= $form->field($model, 'processfullyauto')->textInput()->label(false) ?></td>
    	</tr>
    	<tr>
    		<td colspan="6">
    		<div id="drawing"><img height="500px" width="auto" src="/images/dt192.jpg"></img></div>
    			
    		</td>
    	</tr>
    	<tr>
    		<th class="DarkerBlue">Welders Name</th>
    		<td colspan="2" ><?= $form->field($model, 'weldersname')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue" rowspan="2">Supervisors name</th>
    		<td colspan="2"><?= $form->field($model, 'supervisorname')->textInput()->label(false) ?></td>
    	</tr>
    	<tr>
    		<th class="DarkerBlue">Stamp No</th>
    		
    		<td colspan="2"><?= $form->field($model, 'weldersstamp')->textInput()->label(false) ?></td>
    	</tr>
    	<tr><th>Welders Signature</th><td><canvas id="canvas_0" class="canvas1">Drawing</canvas>
    	
	    	<?= Html::button('Reset', [ 'class' => 'btn btn-primary', 'onclick' => 'ClearCanvasX(0);' ]); ?></td></tr>
    </table>
 

    

    

    <?= $form->field($model, 'signature')->hiddenInput(['id' => 'signature0'])->label(false) ?>
    <?= $form->field($model, 'actid')->hiddenInput([])->label(false) ?>

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

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

</div>
<script>
	x= 0;
function saveImages() {
	while (x <= 0)		{
		id = "signature"+x;		cavid = "canvas_"+x;
	document.getElementById(id).value = document.getElementById(cavid).toDataURL();
		x++
	}
}
</script>