<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;;
use kartik\datetime\DateTimePicker;
use kartik\date\DatePicker;
use common\widgets\TinyMce;
/* @var $this yii\web\View */
/* @var $model modules\forms\models\Dt188 */
/* @var $form yii\widgets\ActiveForm */
if (!$model->actid) {$model->actid = Yii::$app->getRequest()->getQueryParam('actid');}
$model->name = Yii::$app->user->identity->username;


$model->datetime = empty($model->datetime) == false ? Date('d/m/Y H:i', strtotime($model->datetime)) : $model->datetime;
echo $model->date;
$model->date = empty($model->date) == false && $model->date !== '1970-01-01' ? Date('d/m/Y H:i', strtotime($model->date)) : ($model->date !== '1970-01-01' ? $model->date : null);

$this->registerJsFile('/js/touch_0.js');//load canvas_0
$this->registerJsFile('/js/updateignatures.js'); //load canvas drawing 
//$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>
$(function() {
    //init(); //Drawing
    init0(); //canvas_0
    //init1(); //canvas_1
    //init2(); //canvas_2
    //init3(); //canvas_3
})
</script>


<div class="dt188-form">
    <?php $form = ActiveForm::begin(); ?>
    <div class="row">
        <div class="col-md-3"><img src="/images/logo.jpg" alt="logo"></img></div>
        <div class="col-md-7">Non- Compliance Report Form DT188</div>
        <div class="col-md-2">Rev1/April2016/GJS</div>
    </div>
    <div class="row">
        <div class="col-md-offset-8">NCR REF No</div>
        <div class="col-md-4"></div>
    </div>
    <div class="row">
        <div class="col-md-3 DarkerBlue">
            Subject
        </div>
        <div class="col-md-9">
            <?= $form->field($model, 'subject')->textInput()->label(false) ?>
        </div>
        </div>
    <div class="row">
        <div class="col-md-3 DarkerBlue">
            Name (person identifying non compliance):
        </div>
        <div class="col-md-3">
            <?= $form->field($model, 'name')->textInput()->label(false) ?>
        </div>
        <div class="col-md-3 DarkerBlue">
            Date & Time (if applicable):
        </div>
        <div class="col-md-3">
            <?= $form->field($model, 'datetime')->widget(DateTimePicker::class, ['size' => 'sm', 'name'=>'datetime', 'pluginOptions' => [
				'showMeridian' =>false, 
				'format' => 'dd/mm/yyyy hh:ii'
				]
])->label(false) ?>
        </div>
    </div>
    <div class="row">
        <div class="col-md-4 DarkerBlue">Contract</div>
        <div class="col-md-4 DarkerBlue">Site Location</div>
        <div class="col-md-4 DarkerBlue">Project (if this has come from a note please type NOTE in the field below)
        </div>
    </div>
    <div class="row">
        <div class="col-md-4"><?= $form->field($model, 'contract')->textInput()->label(false) ?> </div>
        <div class="col-md-4"><?= $form->field($model, 'location')->textInput()->label(false) ?> </div>
        <div class="col-md-4"><?= $form->field($model, 'project')->textInput()->label(false) ?> </div>
    </div>
    <div class="row">
        <div class="col-12 DarkerBlue">
            Detail of Non-Compliance (e.g. materials/equipment/authority to work/competence/etc.)
        </div>
    </div>
    <div class="row">
        <div class="col-12">
            <?= $form->field($model, 'details')->widget(TinyMce::class, [])->label(false); ?>
        </div>
    </div>
    <div class="row DarkerBlue">
        <div class="col-12">
            Actions: (Determine reasons for escalation, if applicable)
        </div>
    </div>
    <div class="row">
        <div class="col-12">
            <?= $form->field($model, 'actions')->widget(TinyMce::class, [])->label(false); ?>
        </div>
    </div>
    <div class="row DarkerBlue">
        <div class="col-12">
            Escalated to:
        </div>

    </div>
    <div class="row">
        <div class="col-12">
            <?= $form->field($model, 'escalatedto')->dropdownlist(['HSEQ Director'=>'HSEQ Director', 'Project Manager' => 'Project Manager', 'Quality Manager' => 'Quality Manager','Safety Manager' => 'Safety Manager' ])->label(false) ?>
        </div>
    </div>
    <div class="row DarkerBlue">
        <div class="col-12">
            Signature
        </div>
    </div>
    <div class="row">
        <div class="col-12">
            <canvas class="canvas" width="300" height="150" id="canvas_0"></canvas>
            <?= $form->field($model, 'signature')->hiddenInput(['id' => 'signature0'])->label(false) ?>

            <?= Html::button('Reset', [ 'class' => 'btn btn-primary', 'onclick' => 'ClearCanvasX(0);' ]); ?>
        </div>
    </div>
    <div class="row ">
        <div class="col-sm-4 DarkerBlueC data-label">Date</div>
        <div class="col-sm-4 DarkerBlueC data-label">Type</div>
        <div class="col-sm-4 DarkerBlueC data-label">Status</div>
    </div>
    <div class="row">
        <div class="col-sm-4">
            <?= $form->field($model, 'date')->widget(DatePicker::class, ['size' => 'sm', 'name'=>'date', 'pluginOptions' => ['showMeridian' =>false, 'convertFormat' => true, 'format' => 'dd/mm/yyyy', 'useCurrent' => true]])->label(false) ?>
        </div>
        <div class="col-sm-4">
            <?= $form->field($model, 'noncontype')->dropdownlist(['General' => 'General', 'Fleet' => 'Fleet'], ['prompt' => 'Please Select...'])->label(false) ?>
        </div>
        <div class="col-sm-4">
            <?= $form->field($model, 'status')->dropdownlist(['Active' => 'Active', 'Complete' => 'Complete'], ['prompt' => 'Please Select...'])->label(false) ?>
        </div>
    </div>



    <div class="row">
        <div class="col-sm-12">
            This document is the property of Inline Track Welding Limited.<br>
            It shall not be reproduced in whole or in part, nor disclosed to a third party, without the written
            permission of the Inline Track Welding Limited HSEQ Manager.<br>
            &copy; Copyright Inline Track Welding Limited
        </div>
    </div>


    <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++
    }
}
<?php if (Yii::$app->controller->action->id == 'update') { ?>
    var canvas0 = document.getElementById('canvas_0');
    if (canvas0) {
    var context0 = canvas0.getContext('2d');    
    var imagesrc0 = document.getElementById('signature0').value;
    var image0 = new Image();
        image0.src = imagesrc0
        context0.drawImage(image0, 0, 0);
        //console.log('canvas0 loaded');	
    }
<?php  } ?>
</script>