<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\date\DatePicker;
/* @var $this yii\web\View */
/* @var $model modules\forms\models\Dt203 */
/* @var $form yii\widgets\ActiveForm */
$types = ['Facing' => 'Facing','Trailing' => 'Trailing','Single' => 'Single'];
$construction = ['Cast Monobloc' => 'Cast Monobloc', 'Cast Centre Block' => 'Cast Centre Block', 'Cast Vee' => 'Cast Vee', 'Machined nose block' => 'Machined nose block', 'Electro-slag welded Vee' => 'Electro-slag welded Vee', 'Fabricated' => 'Fabricated'];
$design = ['Common' => 'Common', 'Obtuse' => 'Obtuse', 'Swing nose' => 'Swing nose'];
$installationtype = ['Plated' => 'Plated', 'Welded' => 'Welded', 'Part Welded' => 'Part Welded'];
$steeltype = ['AMS' => 'AMS', 'Bainitic' => 'Bainitic', 'Normal' => 'Normal', 'Grade' => 'Grade', 'Low alloy(i.e. machined nose block)' => 'Low alloy(i.e. machined nose block)'];

is_integer($model->date) ? $model->date = date('d/m/Y', $model->date)  : '';
is_integer($model->datemanufactured) ? $model->datemanufactured = date('d/m/Y', $model->datemanufactured) : '';
is_integer($model->dateinstalled) ? $model->dateinstalled = date('d/m/Y', $model->dateinstalled) : '';
is_integer($model->inspectedbydate) ? $model->inspectedbydate = date('d/m/Y', $model->inspectedbydate) : '';
is_integer($model->smtdate) ? $model->smtdate = date('d/m/Y', $model->smtdate)  : '';
is_integer($model->inputerdate) ? $model->inputerdate = date('d/m/Y', $model->inputerdate) : '';
is_integer($model->sectionplannerdate) ? $model->sectionplannerdate = date('d/m/Y', $model->sectionplannerdate) : '';
is_integer($model->sectionmandate) ? $model->sectionmandate = date('d/m/Y', $model->sectionmandate) : '';
is_integer($model->trackmandate) ? $model->trackmandate = date('d/m/Y', $model->trackmandate) : ''; 
?>
<?php $this->registerJsFile('/js/touch_0.js');//load canvas_1?>
<?php $this->registerJsFile('/js/touch_1.js');//load canvas_1?>
<?php $this->registerJsFile('/js/touch_2.js'); //load canvas_2 ?>
<?php $this->registerJsFile('/js/touch_3.js'); //load canvas_2 ?>
<?php $this->registerJsFile('/js/touch_4.js'); //load canvas_2 ?>
<?php $this->registerJsFile('/js/touch_5.js'); //load canvas_2 ?>
<?php $this->registerJsFile('/js/touch_6.js'); //load canvas_2 ?>
<?php $this->registerJsFile('/js/touch_7.js'); //load canvas_2 ?>
<?php $this->registerJsFile('/js/updatesignatures.js'); //load canvas_2 ?>
<div class="d-none">
    <?= HTML::IMG('/images/3031-l.png', ['id' => 'image1']) ?>
    <?= HTML::IMG('/images/3031-r.png', ['id' => 'image2']) ?>
</div>
<div class="dt203-form">
    <h2><?= $model->formname; ?></h2>
    <?php $form = ActiveForm::begin(); ?>
    <table class="table table-borderless">
        <tr>
            <th class="DarkerBlue">Location</th>
            <td colspan="4"><?= $form->field($model, 'location')->textInput()->label(false) ?></td>
            <th class="DarkerBlue">Date Inspected</th>

            <td>
                <?= $form->field($model, 'date')->widget(DatePicker::class, ['type' => 1, 'options' => ['placeholder' => 'Enter Date ...'], 'pluginOptions' => ['autoclose' => true,
        'convertFormat' => true,
        'format' => 'dd/mm/yyyy']])->label(false) ; ?>
            </td>
        </tr>
        <tr>
            <th class="DarkerBlue">ELR</th>
            <td><?= $form->field($model, 'elr')->textInput()->label(false) ?></td>
            <th class="DarkerBlue">Track ID</th>
            <td colspan="2"><?= $form->field($model, 'trackid')->textInput()->label(false) ?></td>
            <th class="DarkerBlue">Mileage</th>
            <td>
                <div class="input-group">
                    <?= $form->field($model, 'mileagem')->textInput(['class' => 'form-control'])->label(false) ?>
                    <div class="input-group-append">
                        <span class="input-group-text">m</span>
                        <?= $form->field($model, 'mileagey')->textInput()->label(false) ?>
                        <span class="input-group-text">yrds</span>
                    </div>
                </div>
            </td>

        </tr>
        <tr>
            <th class="DarkerBlue">Point Number</th>
            <td><?= $form->field($model, 'pointsno')->textInput()->label(false) ?></td>
            <th class="DarkerBlue">Type</th>
            <td colspan="2"><?= $form->field($model, 'type')->checkboxlist($types, [])->label(false) ?></td>
            <th class="DarkerBlue">Crossing Angle</th>
            <td><?= $form->field($model, 'crossingangle')->textInput()->label(false) ?></td>
        </tr>
        <tr>
            <th class="DarkerBlue">Construction</th>
            <td colspan="6"><?= $form->field($model, 'construction')->checkboxlist($construction, [])->label(false) ?>
            </td>
        </tr>
        <tr>
            <th class="DarkerBlue">Design</th>
            <td colspan="4"><?= $form->field($model, 'design')->checkboxlist($design)->label(false) ?></td>
            <th class="DarkerBlue">Installation Type</th>
            <td><?= $form->field($model, 'installationtype')->checkboxlist($installationtype)->label(false) ?></td>
        </tr>
        <tr>
            <th class="DarkerBlue">Steel Type</th>
            <td colspan="2"><?= $form->field($model, 'steeltype')->checkboxlist($steeltype)->label(false) ?></td>
            <th class="DarkerBlue">Date Manufactured</th>
            <td>
                <?= $form->field($model, 'datemanufactured')->widget(DatePicker::class, ['type' => 1, 'options' => ['placeholder' => 'Enter Date ...'], 'pluginOptions' => ['autoclose' => true,
				'convertFormat' => true,
				'format' => 'dd/mm/yyyy']])->label(false) ; ?>
            </td>
            <th class="DarkerBlue">Date Installed</th>
            <td><?= $form->field($model, 'dateinstalled')->widget(DatePicker::class, ['type' => 1, 'options' => ['placeholder' => 'Enter Date ...'], 'pluginOptions' => ['autoclose' => true,
        'convertFormat' => true,
        'format' => 'dd/mm/yyyy']])->label(false) ; ?></td>
        </tr>
        <tr>
            <th class="DarkerBlue">Manufacturer</th>
            <td colspan="2"><?= $form->field($model, 'manufacturer')->textInput()->label(false) ?></td>
            <th class="DarkerBlue">Cast No</th>
            <td colspan="3"><?= $form->field($model, 'castno')->textInput()->label(false) ?></td>
        </tr>


    </table>

    <table class="table table-borderless">
        <thead>
            <tr>
                <th class="DarkerBlue" rowspan="2">Defect Description</th>
                <th class="DarkerBlue">Defect Present</th>
                <th class="DarkerBlue">if yes, UIC</th>
                <th class="DarkerBlue">Comments; include length, depth &amp; width as appropiate</th>
            </tr>
        </thead>
        <tbody>
            <?php $x = 1; ?>
            <?php while($x <= 47 ){ ?>
            <?= $x == 1 ? '<tr class="DarkerBlue"><td colspan="4">Cast Monobloc, Cast Centre or Cast Vee Within fishplate limits</td></tr>' : null ?>
            <?php if($model->getAttributelabel("response$x".'a') !== "response$x".'a'){ ?>
            <tr>
                <th>
                    <?= $model->getAttributelabel("response$x".'a') ?>
                </th>
                <th>
                    <?= $form->field($model, "response$x".'a')->dropdownlist(['NO' => 'NO', 'YES' => 'YES'], ['prompt' => 'Please Select'])->label(false)  ?>
                </th>
                <td>
                    <?= $form->field($model, "response$x".'b')->textInput([])->label(false)  ?>
                </td>
                <td>
                    <?= $form->field($model, "response$x".'c')->textArea([])->label(false)  ?>
                </td>
            </tr>
            <?php } ?>
            <?= $x == 9 ? '<tr class="DarkerBlue"><td colspan="4">Leg ends</td></tr>' : null ?>
            <?= $x == 14 ? '<tr class="DarkerBlue"><td colspan="4">Anywhere within casting</td></tr>' : null ?>
            <?= $x == 24 ? '<tr class="DarkerBlue"><td colspan="4">Change of section</td></tr>' : null ?>
            <?= $x == 29 ? '<tr class="DarkerBlue"><td colspan="4">Monobloc</td></tr>' : null ?>
            <?= $x == 40 ? '<tr class="DarkerBlue"><td colspan="4">Rolled Steel Crossing Components Wheel transfer area</td></tr>' : null ?>
            <?php  $x++ ?>
            <?php  } ?>
        </tbody>
    </table>


    <table class="Table">
        <tr>
            <td rowspan="2" valign="top">
                <canvas id="canvas_0" height="175px" width="350px"></canvas>
                <?= HTML::Button('Reset', ['Onclick' => "ClearCanvasI(0, 'image1')", 'Class' => 'btn btn-danger']); ?>
            </td>
            <td colspan="2">
                <canvas id="canvas_1" height="175px" width="400px"></canvas>
                <?= HTML::Button('Reset', ['Onclick' => "ClearCanvasI(1, 'image2')", 'Class' => 'btn btn-danger']); ?>

            </td>

            <?= $form->field($model, 'image0')->hiddeninput(['id' => 'signature0'])->label(false) ?>
            <?= $form->field($model, 'image1')->hiddeninput(['id' => 'signature1'])->label(false) ?>

        </tr>
        <tr>
            <td>Indicate Areas requiring repair (diagram my not accurately refect the crossing construction)</td>
        </tr>
        <tr>
            <th class="DarkerBlue">Rail Defects</th>
            <th class="DarkerBlue">Actions in Accordance with NR/L2/TRK/1054</th>
            <th class="DarkerBlue">RDMS No</th>
        </tr>
        <tr>
            <td><?= $form->field($model, 'railfefect1')->textArea()->label(false) ?></td>
            <td><?= $form->field($model, 'actions1')->textArea()->label(false) ?></td>
            <td><?= $form->field($model, 'rdmsno1')->textArea()->label(false) ?></td>
        </tr>
        <tr>
            <td><?= $form->field($model, 'railfefect2')->textArea()->label(false) ?></td>
            <td><?= $form->field($model, 'actions2')->textArea()->label(false) ?></td>
            <td><?= $form->field($model, 'rdmsno2')->textArea()->label(false) ?></td>
        </tr>
        <tr>
            <td><?= $form->field($model, 'railfefect3')->textArea()->label(false) ?></td>
            <td><?= $form->field($model, 'actions3')->textArea()->label(false) ?></td>
            <td><?= $form->field($model, 'rdmsno3')->textArea()->label(false) ?></td>
        </tr>

        <tr>
            <th class="DarkerBlue">Track Condition</th>
            <th class="DarkerBlue">Actions in Accordance with NR/L2/TRK/001 &amp; <br /> NR/L2/TRK/1054</th>
            <th class="DarkerBlue">ELLIPSE</th>
        </tr>

        <tr>
            <td><?= $form->field($model, 'trackconditions1')->textArea()->label(false) ?></td>
            <td><?= $form->field($model, 'actions4')->textArea()->label(false) ?></td>
            <td></td>
        </tr>
        <tr>
            <td><?= $form->field($model, 'trackconditions2')->textArea()->label(false) ?></td>
            <td><?= $form->field($model, 'actions5')->textArea()->label(false) ?></td>
            <td></td>
        </tr>
        <tr>
            <td><?= $form->field($model, 'trackconditions3')->textArea()->label(false) ?></td>
            <td><?= $form->field($model, 'actions6')->textArea()->label(false) ?></td>
            <td></td>
        </tr>

    </table>

    <table class="Table">
        <tr>
            <th class="DarkerBlue">Inspected by Name</th>

            <td><?= $form->field($model, 'inspectedbyname')->textInput()->label(false) ?></td>
            <th class="DarkerBlue">Signature</th>
            <td>
                <canvas id="canvas_6" class="canvas"></canvas>
                <?= $form->field($model, 'inspectedbysignature')->hiddenInput(['id' => 'signature6'])->label(false) ?>
                <?= HTML::Button('Reset', ['Onclick' => 'ClearCanvasX(6)', 'Class' => 'btn btn-danger']); ?>
            </td>
            <th class="DarkerBlue">Date</th>
            <td><?= $form->field($model, 'inspectedbydate')->widget(DatePicker::class, ['type' => 1, 'options' => ['placeholder' => 'Enter Date ...'], 'pluginOptions' => ['autoclose' => true,
        'convertFormat' => true,
        'format' => 'dd/mm/yyyy']])->label(false) ; ?></td>
        </tr>
        <tr>
            <th class="DarkerBlue">SM[T] Name</th>
            <td><?= $form->field($model, 'smtname')->textInput()->label(false) ?></td>
            <th class="DarkerBlue">Signature</th>
            <td>
                <canvas id="canvas_7" class="canvas"></canvas>
                <?= $form->field($model, 'smtsignature')->hiddenInput(['id' => 'signature7'])->label(false) ?>
                <?= HTML::Button('Reset', ['Onclick' => 'ClearCanvasX(7)', 'Class' => 'btn btn-danger']); ?>

            </td>
            <th class="DarkerBlue">Date</th>
            <td><?= $form->field($model, 'smtdate')->widget(DatePicker::class, ['type' => 1, 'options' => ['placeholder' => 'Enter Date ...'], 'pluginOptions' => ['autoclose' => true,
        'convertFormat' => true,
        'format' => 'dd/mm/yyyy']])->label(false) ; ?></td>
        </tr>
        <tr>
            <th class="DarkerBlue">Imputer Name</th>
            <td><?= $form->field($model, 'inputername')->textInput()->label(false) ?></td>
            <th class="DarkerBlue">Signature</th>
            <td>
                <canvas id="canvas_2" class="canvas"></canvas>
                <?= $form->field($model, 'inputersignature')->hiddenInput(['id' => 'signature2'])->label(false) ?>
                <?= HTML::Button('Reset', ['Onclick' => 'ClearCanvasX(2)', 'Class' => 'btn btn-danger']); ?>

            </td>
            <th class="DarkerBlue">Date Entered RDMS</th>
            <td><?= $form->field($model, 'inputerdate')->widget(DatePicker::class, ['type' => 1, 'options' => ['placeholder' => 'Enter Date ...'], 'pluginOptions' => ['autoclose' => true,
        'convertFormat' => true,
        'format' => 'dd/mm/yyyy']])->label(false) ; ?></td>
        </tr>
        <tr>
            <th class="DarkerBlue">Section Planner Name</th>
            <td><?= $form->field($model, 'sectionplannername')->textInput()->label(false) ?></td>
            <th class="DarkerBlue">Signature</th>
            <td>
                <canvas id="canvas_3" class="canvas"></canvas>
                <?= $form->field($model, 'sectionplannersignature')->hiddenInput(['id' => 'signature3'])->label(false) ?>
                <?= HTML::Button('Reset', ['Onclick' => 'ClearCanvasX(3)', 'Class' => 'btn btn-danger']); ?>

            </td>
            <th class="DarkerBlue">Date Entered ELLIPSE</th>
            <td><?= $form->field($model, 'sectionplannerdate')->widget(DatePicker::class, ['type' => 1, 'options' => ['placeholder' => 'Enter Date ...'], 'pluginOptions' => ['autoclose' => true,
        'convertFormat' => true,
        'format' => 'dd/mm/yyyy']])->label(false) ; ?></td>
        </tr>
    </table>
    <br />
    <table class="Table">
        <tr>
            <th colspan="4" class="DarkerBlue"> </th>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <th class="DarkerBlue">Please "x" recommended action</th>
            <th class="DarkerBlue">Estimate of time required for repair</th>
            <th class="DarkerBlue">can repair be staged over successive possessions?</th>
        </tr>
        <tr>
            <th class="DarkerBlue">Temporary Weld Repair - <br /> Pending Replacement</th>
            <td><?= $form->field($model, 'twrrecommendation')->textInput()->label(false) ?></td>
            <td><?= $form->field($model, 'twrrepairtime')->textInput()->label(false) ?></td>
            <td><?= $form->field($model, 'twrstaged')->textInput()->label(false) ?></td>
        </tr>
        <tr>
            <th class="DarkerBlue">Permanent Repair</th>
            <td><?= $form->field($model, 'prrecommendation')->textInput()->label(false) ?></td>
            <td><?= $form->field($model, 'prrepairtime')->textInput()->label(false) ?></td>
            <td><?= $form->field($model, 'prstaged')->textInput()->label(false) ?></td>
        </tr>
        <tr>
            <th class="DarkerBlue">Replace</th>
            <td><?= $form->field($model, 'rrecommendation')->textInput()->label(false) ?></td>
            <td><?= $form->field($model, 'rrepairtime')->textInput()->label(false) ?></td>
            <td><?= $form->field($model, 'rstaged')->textInput()->label(false) ?></td>
        </tr>
        <tr>
            <td colspan="4">
                Ultrasonics Findings(if Applicable)<br />
                <?= $form->field($model, 'ultrasonics')->textArea()->label(false) ?>

            </td>
        </tr>
        <tr>
            <td colspan="4">
                Additional Comments (This may include addinitional required work prior to welding e.g fetting)
                <?= $form->field($model, 'addcomments')->textInput()->label(false) ?>
            </td>
        </tr>
        <tr>
            <th class="DarkerBlue"></th>
            <td><?= $form->field($model, 'sitevisitperformed')->textInput()->label(false) ?></td>
        </tr>
    </table>


    <table class="Table">
        <tr>
            <th class="DarkerBlue">Section Manager (W&amp;G)</th>
            <th class="DarkerBlue">Name</th>
            <td><?= $form->field($model, 'sectionmanname')->textInput()->label(false) ?></td>
            <th class="DarkerBlue">Signature</th>
            <td>
                <canvas id="canvas_4" class="canvas"></canvas>
                <?= $form->field($model, 'sectionmansignature')->hiddenInput(['id' => 'signature4'])->label(false) ?>
                <?= HTML::Button('Reset', ['Onclick' => 'ClearCanvasX(4)', 'Class' => 'btn btn-danger']); ?>
            </td>
            <th class="DarkerBlue">Date</th>
            <td><?= $form->field($model, 'sectionmandate')->widget(DatePicker::class, ['type' => 1, 'options' => ['placeholder' => 'Enter Date ...'], 'pluginOptions' => ['autoclose' => true,
        'convertFormat' => true,
        'format' => 'dd/mm/yyyy']])->label(false) ; ?></td>
        </tr>
        <tr>
            <th class="DarkerBlue">Track Maintenance Engineer</th>
            <th class="DarkerBlue">Name</th>
            <td><?= $form->field($model, 'trackmanname')->textInput()->label(false) ?></td>
            <th class="DarkerBlue">Signature</th>
            <td>
                <canvas id="canvas_5" class="canvas"></canvas>
                <?= $form->field($model, 'trackmansignature')->hiddenInput(['id' => 'signature5'])->label(false) ?>
                <?= HTML::Button('Reset', ['Onclick' => 'ClearCanvasX(5)', 'Class' => 'btn btn-danger']); ?>
            </td>
            <th class="DarkerBlue">Date</th>
            <td><?= $form->field($model, 'trackmandate')->widget(DatePicker::class, ['type' => 1, 'options' => ['placeholder' => 'Enter Date ...'], 'pluginOptions' => ['autoclose' => true,
        'convertFormat' => true,
        'format' => 'dd/mm/yyyy']])->label(false) ; ?></td>
        </tr>

    </table>




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

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

</div>

<script type="text/javascript">
function saveImages() {
    $("#signature0").val(document.getElementById("canvas_0").toDataURL());
    $("#signature1").val(document.getElementById("canvas_1").toDataURL());
    $("#signature2").val(document.getElementById("canvas_2").toDataURL());
    $("#signature3").val(document.getElementById("canvas_3").toDataURL());
    $("#signature4").val(document.getElementById("canvas_4").toDataURL());
    $("#signature5").val(document.getElementById("canvas_5").toDataURL());
    $("#signature6").val(document.getElementById("canvas_6").toDataURL());
    $("#signature7").val(document.getElementById("canvas_7").toDataURL());
    //$("#signature8").val(document.getElementById("canvas_8").toDataURL());
}

window.onload = function() {
    init0();
    init1();
    init2();
    init3();
    init4();
    init5();
    init6();
    init7()
} //Drawing, canvas_1, canvas_2
</script>