<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use kartik\date\DatePicker;
use kartik\time\TimePicker;
use frontend\models\Users;
use kartik\select2\Select2;


if (!$model->actid) {
	$model->actid = Yii::$app->getRequest()->getQueryParam('actid');
	}
$users = \frontend\models\User::EmployeesU();
/* @var $this yii\web\View */
/* @var $model modules\forms\models\Dt133 */
/* @var $form yii\widgets\ActiveForm */

//$this->registerJsFile('/js/touch.js'); //load canvas drawing 
$this->registerJsFile('/js/touch_0.js');//load canvas_1 
$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 
$this->registerJsFile('/js/updatesignatures.js'); //load canvas_3 ?>
<script>
window.onload = function() {
	//init(); //Drawing
	init0(); //canvas_1
	init1(); //canvas_1
	init2(); //canvas_2
	init3(); //canvas_3
	} 
</script>
<style>
.DarkerBlue{
	border-top: none !important;
}
</style>
<div class="dt131-form">
<h1>Incident Report Form DT133:</h1>

    <?php $form = ActiveForm::begin(); ?>
    
    <table class="table table-resonsive" style=";">
    	<tbody>
    		<tr>
    			<th class="DarkerBlue">Contract / Project:</th>
    			<td colspan="3"><?= $form->field($model, 'contract')->textInput()->label(false) ?></td>
    			<th class="DarkerBlue">IN Ref Number: </th>
    			<td colspan="3"><?= $form->field($model, 'refno')->textInput()->label(false) ?></td>
    		</tr>
    		<tr>
    			<th width="50%" colspan="4" class="DarkerBlue">Details of person who had accident:</th>
    			<th width="50%" colspan="4" class="DarkerBlue">Equipment involved in the event (please specify): </th>
    		</tr>
    		<tr>
    			<th class="DarkerBlue">Name:</th>
    			<td colspan="3"><?= $form->field($model, 'detailsname')->widget(Select2::class,
					['data' => $users,
					 'id' => 'weldersname',
					 'options' => [
					 	'placeholder' => 'Select Operatives...', 
					 	],
					 'pluginOptions' => [
						'tags' => true,
					 	'multiple' => true, 
					  	'tokenSeparators' => ['; ', ''],
					 	],])    ->label(false)?></td>
    			<th colspan="4" class="DarkerBlue">(Train / OTP / Road Vehicle / Tools / Infrastructure etc)</th>	
    		</tr>
    		<tr>
    			<th class="DarkerBlue">Job Title:</th>
    			<td colspan="3"><?= $form->field($model, 'detailstitle')->textInput()->label(false) ?></td>
    			<td colspan="4"><?= $form->field($model, 'equipment')->textInput(['max' => 100])->label(false) ?></td>
    			
    		</tr>
    		<tr>
    			<th class="DarkerBlue">Mobile Number:</th>
    			<td colspan="3"><?= $form->field($model, 'detailsmobile')->textInput()->label(false) ?></td>
    			<th colspan="4" class="DarkerBlue">Witnesses</th>
    		</tr>
    		<tr>
    			<th class="DarkerBlue">Business Address:</th>
    			<td colspan="3"><?= $form->field($model, 'detailsaddress1')->textInput(['placeholder' => 'Address Line 1'])->label(false) ?></td>
    			<td colspan="4"><?= $form->field($model, 'witnesses')->textArea([])->label(false) ?></td>
    		</tr>
    		<tr>
    			<td colspan="2"><?= $form->field($model, 'detailsaddress2')->textInput(['placeholder' => 'Address Line 2'])->label(false) ?></td>
    			<td colspan="2"><?= $form->field($model, 'detailstown')->textInput(['placeholder' => 'Town'])->label(false) ?></td>
    		</tr>
    		    		<tr>
    			<th class="DarkerBlue">County:</th>
    			<td colspan="3"><?= $form->field($model, 'detailscounty')->textInput()->label(false) ?></td>
    			
    		</tr>
    		<tr>
    			<th class="DarkerBlue">Post Code:</th>
    			<td><?= $form->field($model, 'detailspostcode')->textInput()->label(false) ?></td>
    			<th class="DarkerBlue">Tel No:</th>
    			<td><?= $form->field($model, 'detailstelno')->textInput()->label(false) ?></td>
    			<th colspan="4" class="DarkerBlue">Immediate action taken to prevent reoccurrence? </th>
    		
    		</tr>
    		<tr>
    			<th class="DarkerBlue">Employer:</th>
    			<td colspan="3"><?= $form->field($model, 'detailsemployer')->textInput()->label(false) ?></td>
    			<td colspan="4"><?= $form->field($model, 'immediateaction')->textInput(['max' => 100])->label(false) ?></td>
    		
    		</tr>
    		<tr>
    			<th class="DarkerBlue">Signature:</th>
    			<td><canvas id="canvas_0" class="canvas1"></canvas>
	<?= Html::button('Reset', [ 'class' => 'btn btn-primary', 'onclick' => 'ClearCanvasX(0);' ]); ?>
    	<?= $form->field($model, 'detailssign')->hiddenInput(['id' => 'signature0'])->label(false) ?></td>
    			<th class="DarkerBlue">Date:</th>
    			<td><?= $form->field($model, 'detailssigndate')->widget(DatePicker::class, ['size' => 'sm', 'name'=>'detailssigndate', 'pluginOptions' => ['showMeridian' =>false, 'format' => 'yyyy-mm-dd']])->label(false) ?></td>
    				<th class="DarkerBlue">Confirmed by Director/HSEQ Manager:</th>
    			<td colspan="3"><?= $form->field($model, 'hseqconfirmed')->checkbox(['label' => false ])->label(false) ?></td>
    			
    		
    		</tr>
    		<tr>
    			<th colspan="4" class="DarkerBlueC">Details of Incident:</th>
    			
    			<th class="DarkerBlue">Name:</th>
    			<td colspan="3"><?= $form->field($model, 'confirmedname')->textInput()->label(false) ?></td>
    		</tr>
    		<tr>
    			<th class="DarkerBlue">Date of Event:</th>
		    	<td><?= $form->field($model, 'eventdate')->widget(DatePicker::class, ['size' => 'sm', 'pluginOptions' => ['showMeridian' =>false, 'format' => 'yyyy-mm-dd']])->label(false) ?></td>
		    	<th class="DarkerBlue">Time of Event:</th>
		    	<td><?= $form->field($model, 'eventtime')->widget(TimePicker::class, ['size' => 'sm', 'pluginOptions' => ['showMeridian' =>false]])->label(false) ?></td>
				<th colspan="" class="DarkerBlue">Job Title</th>
    			<td colspan="3"><?= $form->field($model, 'confirmedtitle')->textInput()->label(false) ?></td>
			</tr>
    		<tr>
    			 	<th class="DarkerBlue" >Location of Event:</th>
    	<td colspan="3"><?= $form->field($model, 'eventlocation')->textInput()->label(false) ?></td>
   	<th colspan="" class="DarkerBlue">Signature</th>
    			<td colspan="">
    				<canvas id="canvas_1" class="canvas1"></canvas>
			
			<?= Html::button('Reset', [ 'class' => 'btn btn-primary', 'onclick' => 'ClearCanvasX(1);' ]); ?>
				<?= $form->field($model, 'confirmedsign')->hiddenInput(['id'=>'signature1'])->label(false) ?>
			
    			</td>
    			<th colspan="" class="DarkerBlue">Date</th>
    			<td colspan=""><?= $form->field($model, 'lmdate')->widget(DatePicker::class, ['size' => 'sm','pluginOptions' => ['showMeridian' =>false, 'convertFormat'=>true, 'format' => 'yyyy-mm-dd']])->label(false) ?></td>
    		
    			
    		</tr>
    		<tr>
				<th colspan="3" class="DarkerBlue">Did the accident occur on Network Rail  Controlled Infrastructure</th>
	    		<td ><?= $form->field($model, 'nrcontrolled')->dropdownlist(['Yes', 'No'], ['placeholder' => 'Please Select'])->label(false) ?></td>
   	<th colspan="4" class="DarkerBlue">Incidents Reportable under RIDDOR 95:</th>
    		
    		</tr>
    		<tr>
    			<th class="DarkerBlue">ELR</th>
    			<td><?= $form->field($model, 'elr')->textInput()->label(false) ?></td>
    			<th class="DarkerBlue">Mileage</th>
    			<td><?= $form->field($model, 'mileage')->textInput()->label(false) ?></td>
    		<th class="DarkerBlue">If a major Incident has the MIA been completed?</th>
			<td><?= $form->field($model, 'riddor95')->dropdownlist([1 => 'Yes', 0 => 'No'])->label(false) ?></td>
			<th class="DarkerBlue">Has a F2508 been sent to the HMRI?   Y/N</th>
			<td><?= $form->field($model, 'f2508')->dropdownlist([1 => 'Yes', 0 => 'No'])->label(false) ?></td>
			
    		</tr>
    		<tr>
    			<th colspan="4" class="DarkerBlue">About the Accident (what happened?):</th>
    		</tr>
    		<tr>
    			<td colspan="4"><?= $form->field($model, 'about')->textArea()->label(false) ?></td>
    		</tr>
    	
    	
    		</tbody>
    		</table>
    <table class="table table-responsive">
    	<tbody>
    		<tr>
    			<th class="DarkerBlueC">Investigators / HSEQ Manager Findings (attach Sketches, Photographs, Witness Statements as required).	</th>
    		</tr>
    		<tr>
    			<td><?= $form->field($model, 'findings')->textArea()->label(false) ?></td>
    		</tr>
    		<tr>
    			<th class="DarkerBlueC">Conclusions</th>
    		</tr>
    		<tr>
    			<td><?= $form->field($model, 'conclusions')->textArea()->label(false) ?> </td>
    		</tr>
    		<tr>
    			<th class="DarkerBlueC">Immediate Causes</th>
    		</tr>
    		<tr>
    			<td><?= $form->field($model, 'immediatecause')->textArea()->label(false) ?></td>
    		</tr><tr>
    			<th class="DarkerBlueC">Underlying Causes	</th>
    		</tr>
    		<tr>
    			<td><?= $form->field($model, 'underlyingcause')->textArea()->label(false) ?></td>
    		</tr><tr>
    			<th class="DarkerBlueC">Remedial Actions</th>
    		</tr>
    		<tr>
    			<td><?= $form->field($model, 'remedialactions')->textArea()->label(false) ?> </td>
    		</tr>
    		<tr>
    			<th class="DarkerBlueC">Recommendations	</th>
    		</tr>
    		<tr>
    			<td><?= $form->field($model, 'recommedations')->textArea()->label(false) ?>	</td>
    		</tr>
    	</tbody>
    </table>
    <table class="Table" cellpadding="none">
		<tr>
			<th class="DarkerBlue">Signed:</th>
			<td>
			<canvas id="canvas_2" class="canvas1"></canvas>
			<?= Html::button('Reset', ['class' => 'btn btn-primary', 'onclick' => 'ClearCanvasX(2);' ]); ?>
			<?= $form->field($model, 'lmsigned')->hiddenInput(['id' => 'signature2'])->label(false) ?>
			</td>
			
			<th class="DarkerBlue">Signed:</th>
			<td>
			<canvas id="canvas_3" class="canvas1"></canvas>
			<?= Html::button('Reset', ['class' => 'btn btn-primary', 'onclick' => 'ClearCanvasX(3);' ]); ?>
			<?= $form->field($model, 'hseqsign')->hiddenInput(['id' => 'signature3'])->label(false) ?>
			</td>
		</tr>
		<tr>
			
			<th class="DarkerBlue">Print Name:<br />  <i>(Line Manager/Supervisor)</i></th>
			<td><?= $form->field($model, 'lmname')->textInput()->label(false) ?></td>
			<th class="DarkerBlue">Print Name:<br />  <i>HSEQ Manager</i></th>
			<td><?= $form->field($model, 'hseqprint')->textInput()->label(false) ?></td>
		</tr>	
		<tr>
			<th class="DarkerBlue">Date:</th>
			<td><?= $form->field($model, 'lmsigndate2')->widget(DatePicker::class, ['size' => 'sm', 'pluginOptions' => ['showMeridian' =>true, 'format' => 'yyyy-mm-dd']])->label(false) ?></td>
			<th class="DarkerBlue">Date:</th>
			<td><?= $form->field($model, 'hseqdate')->widget(DatePicker::class, ['size' => 'sm', 'pluginOptions' => ['showMeridian' =>true, 'format' => 'yyyy-mm-dd']])->label(false) ?></td>
		</tr>	
	</table>



   

	

		<?= $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 <= 3)		{
		id = "signature"+x;		cavid = "canvas_"+x;
	document.getElementById(id).value = document.getElementById(cavid).toDataURL();
		x++
	}
}
</script>