<?php

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

use modules\users\models\User;
use kartik\select2\Select2;
use kartik\date\DatePicker;
use common\widgets\TinyMce;

/* @var $this yii\web\View */
/* @var $model modules\forms\models\Dt131 */
/* @var $form yii\widgets\ActiveForm */
//print_r($act);
?>

<?php
//$this->registerJsFile('/js/touch.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 
$this->registerJsFile('/js/updatesignatures.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="dt131-form">

    <div class="row">
        <div class="col-sm-12 col-md-12 text-center">
            <h1><?= $formModel->formname ?></h1>
        </div>
        <?php $form = ActiveForm::begin(); ?>

        <table class="table table-borderless">
            <tbody>
                <tr>
                    <th colspan="1" class="DarkerBlue">Contract / Project:</th>
                    <td colspan="3"><?= $form->field($model, 'contract')->textInput()->label(false) ?></td>
                    <th colspan="1" class="DarkerBlue">IN Ref Number:</th>
                    <td colspan="3"><?= $form->field($model, 'ref')->textInput()->label(false) ?></td>

                </tr>
                <tr>
                    <th colspan="4" class="DarkerBlue">Details of person who had accident:</th>
                </tr>
                <tr>
                    <th colspan="1" class="DarkerBlue">Name:</th>
                    <td colspan="3"><?= $form->field($model, 'name')->textInput()->label(false) ?></td>
                    <th colspan="1" class="DarkerBlue">PPE being worn (if YES please specify):</th>
                    <td colspan="3">
                        <?= $form->field($model, 'ppeworn')->dropdownlist([1 =>'Yes', 0 => 'No'], ['prompt' => 'Please Select'])->label(false) ?>
                    </td>

                </tr>
                <tr>
                    <th colspan="" class="DarkerBlue">Date of Birth:</th>
                    <td colspan="3">
                        <?= $form->field($model, 'dob')->widget(DatePicker::class, ['size' => 'sm', 'name'=>'dateofbirth', 'pluginOptions' => ['showMeridian' =>false, 'format' => 'yyyy-mm-dd']])->label(false) ?>
                    </td>
                    <td colspan="4" rowspan="4">
                        <?= $form->field($model, 'ppedetails')->widget(TinyMce::class, [])->label(false); ?>
                    </td>
                </tr>
                <tr>
                    <th colspan="1" class="DarkerBlue">Job Title:</th>
                    <td colspan="3"><?= $form->field($model, 'jobtitle')->textInput()->label(false) ?></td>
                </tr>
                <tr>
                    <th colspan="1" class="DarkerBlue">National Insurance Number:</th>
                    <td colspan="3"><?= $form->field($model, 'ninumber')->textInput()->label(false) ?></td>
                </tr>
                <tr>
                    <th colspan="1" class="DarkerBlue">Home Address:</th>
                    <td colspan="3">
                        <?= $form->field($model, 'homeaddress1')->textInput(['placeholder' => 'Address Line 1'])->label(false) ?>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <?= $form->field($model, 'homeaddress2')->textInput(['placeholder' => 'Address Line 2'])->label(false) ?>
                    </td>
                    <td colspan="2">
                        <?= $form->field($model, 'hometown')->textInput(['placeholder' => 'Town'])->label(false) ?></td>
                </tr>
                <tr>
                    <th colspan="1" class="DarkerBlue">County:</th>
                    <td colspan="3"><?= $form->field($model, 'homecounty')->textInput()->label(false) ?></td>
                    <th colspan="4" class="DarkerBlue">First Aid treatment given (name of First Aider) </th>
                </tr>
                <tr>
                    <th colspan="1" class="DarkerBlue">Post Code:</th>
                    <td colspan="1"><?= $form->field($model, 'homepostcode')->textInput()->label(false) ?></td>
                    <th colspan="1" class="DarkerBlue">Tel No:</th>
                    <td colspan="1"><?= $form->field($model, 'hometel')->textInput()->label(false) ?></td>
                    <td colspan="4">
                        <?= $form->field($model, 'firstaidername')->textInput(['placeholder' => 'Name'])->label(false) ?>
                    </td>
                </tr>
                <tr>
                    <th colspan="4" class="DarkerBlue">Details of person completing report:</th>
                    <td colspan="4" rowspan="4">

                        <?= $form->field($model, 'firstaidgiven')->widget(TinyMce::class, [])->label(false); ?>

                    </td>

                </tr>

                <tr>
                    <th class="DarkerBlue">Name:</th>
                    <td colspan="3"><?= $form->field($model, 'employer')->textInput()->label(false) ?></td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Job Title:</th>
                    <td colspan="3"><?= $form->field($model, 'employeraddress1')->textInput()->label(false) ?></td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Business Address:</th>
                    <td colspan="3">&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="2">
                        <?= $form->field($model, 'employeraddress2')->textInput(['placeholder' => 'Employer Address Line 2'])->label(false) ?>
                    </td>
                    <td colspan="2">
                        <?= $form->field($model, 'employertown')->textInput(['placeholder' => 'Employer Town'])->label(false) ?>
                    </td>
                    <th colspan="2" class="DarkerBlue">Attended Hospital (if YES give name):</th>
                    <td colspan="2">
                        <?= $form->field($model, 'attendedhospital')->dropdownlist([0 => 'No', 1 => 'Yes'], ['prompt' => 'Please Select'])->label(false) ?>
                    </td>
                </tr>
                <tr>
                    <th class="DarkerBlue">County:</th>
                    <td colspan="3"><?= $form->field($model, 'employercounty')->textInput()->label(false) ?></td>
                    <td colspan="4" rowspan="4">

                        <?= $form->field($model, 'hospitalname')->widget(TinyMce::class, [])->label(false); ?>

                    </td>

                </tr>
                <tr>
                    <th class="DarkerBlue">Post Code:</th>
                    <td colspan=""><?= $form->field($model, 'employerpostcode')->textInput()->label(false) ?></td>
                    <th class="DarkerBlue">Tel No:</th>
                    <td colspan=""><?= $form->field($model, 'employerphoneno')->textInput()->label(false) ?></td>
                </tr>
                <tr>
                    <th class="DarkerBlue">Signature:</th>
                    <td><canvas id="canvas_1" class="canvas1"></canvas>
                        <?= Html::button('Reset', ['class' => 'btn btn-primary', 'onclick' => 'ClearCanvasX(1);' ]); ?>
                        <?= $form->field($model, 'employersign')->hiddenInput(['id'=> 'signature1'])->label(false) ?>
                    </td>
                    <th class="DarkerBlue">Date:</th>
                    <td><?= $form->field($model, 'employersigndate')->widget(DatePicker::class, ['size' => 'sm', 'pluginOptions' => ['showMeridian' =>false, 'format' => 'yyyy-mm-dd']])->label(false) ?>
                    </td>
                </tr>
                <tr>
                    <th colspan="4" class="DarkerBlueC">Details of Accident:</th>

                </tr>
                <tr>
                    <th class="DarkerBlue">Date of Accident:</th>
                    <td><?= $form->field($model, 'detailsdate')->widget(DatePicker::class, ['size' => 'sm', 'pluginOptions' => ['showMeridian' =>false, 'format' => 'yyyy-mm-dd']])->label(false) ?>
                    </td>
                    <th class="DarkerBlue">Time of Accident:</th>
                    <td><?= $form->field($model, 'detailstime')->textInput()->label(false) ?></td>
                    <th colspan="4" class="DarkerBlue">What is the total number of man-days lost?</th>
                </tr>
                <tr>
                    <th class="DarkerBlue">Location:</th>
                    <td colspan="3"><?= $form->field($model, 'detailslocation')->textInput()->label(false) ?></td>
                    <td colspan="4"><?= $form->field($model, 'lostmandays')->textInput()->label(false) ?></td>
                </tr>
                <tr>
                    <th colspan="2" class="DarkerBlue">Did the accident occur on Network Rail Controlled Infrastructure
                    </th>
                    <td colspan="2">
                        <?= $form->field($model, 'detailsnwraili')->dropdownlist(['Yes', 'No'], ['placeholder' => 'Please Select'])->label(false) ?>
                    </td>
                    <th colspan="4" class="DarkerBlue">Details of any witnesses</th>
                </tr>
                <tr>
                    <th class="DarkerBlue">ELR</th>
                    <td><?= $form->field($model, 'detailselr')->textInput()->label(false) ?></td>
                    <th class="DarkerBlue">Mileage</th>
                    <td><?= $form->field($model, 'detailsmileage')->textInput()->label(false) ?></td>
                    <td colspan="4">
                        <?= $form->field($model, 'witnesses')->widget(TinyMce::class, [])->label(false); ?>
                    </td>

                </tr>
                <tr>
                    <th colspan="4" class="DarkerBlueC">About the Accident (what happened?):</th>
                    <th colspan="4" class="DarkerBlueC">Immediate action taken to prevent </th>

                </tr>
                <tr>
                    <td colspan="4">
                        <?= $form->field($model, 'about')->widget(TinyMce::class, [])->label(false); ?>
                    </td>
                    <td colspan="4">
                        <?= $form->field($model, 'actiontaken')->widget(TinyMce::class, [])->label(false); ?>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">&nbsp;</td>
                    <th colspan="2" class="DarkerBlue">Confirmed by Line Manager:</th>
                    <td colspan="2">
                        <?= $form->field($model, 'confirmedlineman')->dropdownlist(['Yes', 'No'])->label(false) ?></td>
                </tr>
                <tr>
                    <td colspan="4">&nbsp;</td>
                    <th class="DarkerBlue">Name </th>
                    <td colspan="3"><?= $form->field($model, 'linemanname')->textInput()->label(false) ?></td>
                </tr>
                <tr>
                    <td colspan="4">&nbsp;</td>
                    <th class="DarkerBlue">Job Title </th>
                    <td colspan="3"><?= $form->field($model, 'linemantitle')->textInput()->label(false) ?></td>
                </tr>
                <tr>
                    <td colspan="4">&nbsp;</td>
                    <th class="DarkerBlue">Signature </th>
                    <td>
                        <canvas id="canvas_2" class="canvas1"></canvas>
                        <?= Html::button('Reset', ['class' => 'btn btn-primary', 'onclick' => 'ClearCanvasX(2);' ]); ?>
                        <?= $form->field($model, 'linemansign')->hiddenInput(['id' => 'signature2'])->label(false) ?>
                    </td>
                    <th class="DarkerBlue">Date</th>
                    <td><?= $form->field($model, 'linemansigndate')->widget(DatePicker::class, ['size' => 'sm', 'pluginOptions' => ['showMeridian' =>false, 'format' => 'yyyy-mm-dd']])->label(false) ?>
                    </td>

                </tr>
                <tr>
                    <td colspan="4">&nbsp;</td>
                    <th colspan="4" class="DarkerBlue">Accidents Reportable under RIDDOR 95:</th>
                </tr>
                <tr>
                    <td colspan="4">&nbsp;</td>
                    <th class="DarkerBlue">Has a F2508 been sent to the HMRI?</th>
                    <td><?= $form->field($model, 'riddor95')->dropdownlist([0 => 'No', 1 =>'Yes'])->label(false) ?></td>
                    <th class="DarkerBlue">Initials</th>
                    <td><?= $form->field($model, 'riddor95initial')->textInput()->label(false) ?></td>
                </tr>
            </tbody>
        </table>
        <table class="table table-borderless">

            <tr>
                <th class="DarkerBlueC">Investigators / HSEQ Manager Findings (attach Sketches, Photographs, Witness
                    Statements as required).</th>
            </tr>
            <tr>
                <td>
                    <?= $form->field($model, 'findings')->widget(TinyMce::class, [])->label(false); ?>

                </td>
            </tr>
            <tr>
                <th class="DarkerBlueC">Conclusions</th>
            </tr>
            <tr>
                <td>
                    <?= $form->field($model, 'conclusions')->widget(TinyMce::class, [])->label(false); ?>
                </td>
            </tr>

            <tr>
                <th class="DarkerBlueC">Immediate Causes</th>
            </tr>
            <tr>

                <td>
                    <?= $form->field($model, 'inmmediatecauses')->widget(TinyMce::class, [])->label(false); ?>
                </td>
            </tr>

            <tr>
                <th class="DarkerBlueC">Underlying Causes</th>
            </tr>
            <tr>
                <td>
                    <?= $form->field($model, 'underlyingcauses')->widget(TinyMce::class, [])->label(false); ?>
                </td>
            </tr>

            <tr>
                <th class="DarkerBlueC">Remedial Actions </th>
            </tr>
            <tr>
                <td>
				<?= $form->field($model, 'remedialaction')->widget(TinyMce::class, [])->label(false); ?>
                </td>
            </tr>

            <tr>
                <th class="DarkerBlueC">Recommendations</th>
            </tr>
            <tr>
                <td>
				<?= $form->field($model, 'recommendations')->widget(TinyMce::class, [])->label(false); ?>

                </td>
            </tr>

        </table>
        <table class="table table-borderless" cellpadding="none">

            <tr>
                <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, 'supervisorsigned')->hiddenInput(['id' => 'signature3'])->label(false) ?>
                </td>

                <th class="DarkerBlue">Signed:</th>
                <td>
                    <canvas id="canvas_0" class="canvas1"></canvas>
                    <?= Html::button('Reset', ['class' => 'btn btn-primary', 'onclick' => 'ClearCanvasX(0);' ]); ?>
                    <?= $form->field($model, 'hseqmansign')->hiddenInput(['id' => 'signature0'])->label(false) ?>
                </td>



            </tr>
            <tr>

                <th class="DarkerBlue">Print Name:<br /> <i>(Line Manager/Supervisor)</i></th>
                <td><?= $form->field($model, 'superprint')->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, 'linemandate')->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(['id' => 'actid'])->label(false) ?>
        <div class="form-group">
            <?= Html::submitButton('Save', ['class' => 'btn btn-primary', 'onclick' => 'saveImages()']) ?>
        </div>

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

</div>
<script>
x = 0;

function saveImages() {
    while (x <= 3) {
        id = "#signature" + x;
        cavid = "canvas_" + x;
        $(id).val(document.getElementById(cavid).toDataURL());
        x++
    }
}
</script>