<?php

$form = $this->beginWidget('ext.PlGrid.PlActiveForm', array(
    'id' => 'create-fax-form',
    'gridId' => 'create-fax-grid',
    'displayProgressBar' => true,
    'action' => array('createFax'),
    'autoRefreshGrid' => false,
    'afterSaveScript' => 'window.location.reload()',
    ));

echo $form->textFieldRow($model, 'fax_number', array(
    'class' => 'span3',
    'data-translation-id' => 'UCITEM_MODEL_FAX_NUMBER',
));

echo $form->labelEx($model, 'fax_data', array('class' => 'control-label'));
echo '<div class="controls">';
echo CHtml::activeFileField($model, 'fax_data', array(
    'class' => 'span4',
    'data-translation-id' => 'UCITEM_MODEL_FAX_DATA',
    'accept' => 'application/pdf, image/tiff',
    'onchange' => 'getFileName(this)'
));
echo $form->error($model, 'fax_data');


echo "<div class='showError'>";
echo '</div>';
echo '</div>';

echo $form->hiddenField($model, 'fax_data', array('id' => 'hiddenData', 'name' => 'UCItem[fax_data]'));

if (count($model->renderFaxHeader()) != 0) {
    echo '<br>';

    $faxHeaders = $model->renderFaxHeader();
    $tooltip = '';
    $finalTooltip = array();

    foreach ($faxHeaders as $faxHeader) {
        foreach ($faxHeader as $key => $value) {

            $headerExplode = explode('_', $key);

            if ($headerExplode[0] == 'user') {
                $user = app()->user->realUserInstance;
                $tooltip = $user->name;
            } elseif ($headerExplode[0] == 'group') {

                $group = Groups::model()->findByPk($headerExplode[1]);
                $tooltip = $group->name;
            } elseif ($headerExplode[0] == 'system') {
                $tooltip = __('UCITEM_RENDER_SYSTEM_FAX_HEADER');
            }
            $finalTooltip[$key] = array('title' => $tooltip);
        }
    }

    echo $form->dropDownListRow(
        $model,
        'fax_header',
        $faxHeaders,
        array(
            'data-translation-target' => 'UCITEM_MODEL_FAX_HEADER_TRANSLATIONS',
            'options' => $finalTooltip
        )
    );
} else {
    echo '<br>';
    echo '<strong '
        . 'style="color:#ff0000;" '
        . 'data-translation-id = "UCITEM_CREATE_FAX_ANONYM_ERROR_MESSAGE" >'
        . __('UCITEM_CREATE_FAX_ANONYM_ERROR_MESSAGE')
        . '</strong>';
    echo '<br>';
    echo '<br>';
}

$this->endWidget();


if (Yii::app()->user->translateMode) {
    echo '<i '
        . 'data-translation-target="UCITEM_MODEL_FAX_HEADER_TRANSLATIONS" '
        . 'data-translation-id="UCITEM_MODEL_FAX_HEADER"'
        . '>'
        . '</i>';
    echo '<i '
        . 'data-translation-target="UCITEM_MODEL_FAX_HEADER_TRANSLATIONS" '
        . 'data-translation-id="UCITEM_RENDER_USER_FAX_HEADER"'
        . '>'
        . '</i>';
    echo '<i '
        . 'data-translation-target="UCITEM_MODEL_FAX_HEADER_TRANSLATIONS" '
        . 'data-translation-id="UCITEM_RENDER_GROUP_FAX_HEADER"'
        . '>'
        . '</i>';
    echo '<i '
        . 'data-translation-target="UCITEM_MODEL_FAX_HEADER_TRANSLATIONS" '
        . 'data-translation-id="UCITEM_RENDER_SYSTEM_FAX_HEADER"'
        . '>'
        . '</i>';
}
?>
<script>
    //$('#AudioFile_data_em_').show();
    function getFileName(el) {
        filePath = $(el).val().replace(/C:\\fakepath\\/i, '');
        $('#hiddenData').val(filePath);
    }
</script>

<?php
return;
