<?php
/* @var $this RegistroController */
/* @var $model FormularioRegistroUsuario */
/* @var $perfil Perfil */
/* @var $form CActiveForm  */

$this->layout = '//layouts/login';
$this->pageTitle = Yii::app()->name . ' - ' . Yii::t('factuges', 'Crear una cuenta');
if (isset($this->title))
    $this->title = Yii::t('factuges', 'Crear una cuenta');
$this->breadcrumbs = array(Yii::t('factuges', 'Crear una cuenta'));
?>


<?php if (Yii::app()->user->hasFlash('registration')): ?>
    <div class="success">
        <?php echo Yii::app()->user->getFlash('registration'); ?>
    </div>
<?php else: ?>

    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'formulario-registro-usuario',
        'enableAjaxValidation' => true,
        //'disableAjaxValidationAttributes' => array('RegistrationForm_verifyCode'),
        'htmlOptions' => array('enctype' => 'multipart/form-data'),
    ));
    ?>

    <h3 class="form-title"><?php echo Yii::t('factuges', 'Crear una cuenta'); ?></h3>
    <p><?php echo Yii::t('factuges', 'Indica los datos de la cuenta:'); ?></p>


    <?php if ($model->hasErrors() || $perfil->hasErrors()) { ?>
        <div class="alert alert-error">
            <button class="close" data-dismiss="alert"></button>
            <span><?php echo CHtml::errorSummary(array($model, $perfil), '', '', array('firstError' => true)); ?></span>
        </div>
    <?php } ?>

    <div class="control-group">
        <label class="control-label visible-ie8 visible-ie9"><?php echo $form->labelEx($model, 'username'); ?></label>
        <div class="controls">
            <div class="input-icon left">
                <i class="icon-user"></i>
                <?php
                echo $form->textField($model, 'username', array(
                    'class' => 'm-wrap placeholder-no-fix',
                    'placeholder' => $model->getAttributeLabel('username'),
                ));
                ?>
            </div>
        </div>
    </div>        
    <div class="control-group">
        <label class="control-label visible-ie8 visible-ie9"><?php echo $form->labelEx($model, 'password'); ?></label>
        <div class="controls">
            <div class="input-icon left">
                <i class="icon-lock"></i>
                <?php
                echo $form->passwordField($model, 'password', array(
                    'class' => 'm-wrap placeholder-no-fix',
                    'placeholder' => $model->getAttributeLabel('password'),
                ));
                ?>
            </div>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label visible-ie8 visible-ie9"><?php echo $form->labelEx($model, 'confirmacion_password'); ?></label>
        <div class="controls">
            <div class="input-icon left">
                <i class="icon-ok"></i>
                <?php
                echo $form->passwordField($model, 'confirmacion_password', array(
                    'class' => 'm-wrap placeholder-no-fix',
                    'placeholder' => $model->getAttributeLabel('confirmacion_password'),
                ));
                ?>
            </div>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label visible-ie8 visible-ie9"><?php echo $form->labelEx($model, 'email'); ?></label>
        <div class="controls">
            <div class="input-icon left">
                <i class="icon-envelope"></i>
                <?php
                echo $form->textField($model, 'email', array(
                    'class' => 'm-wrap placeholder-no-fix',
                    'placeholder' => $model->getAttributeLabel('email'),
                ));
                ?>
            </div>
        </div>
    </div>

    <?php
    $campos = $perfil->getFields();
    if ($campos) {
        foreach ($campos as $campo) {
            ?>
            <div class="control-group">
                <label class="control-label visible-ie8 visible-ie9">
                    <?php echo $form->labelEx($perfil, $campo->varname); ?>
                </label>
                <div class="controls">
                    <div class="input-icon">
                        <?php
                        if ($campo->widgetEdit($perfil)) {
                            echo $campo->widgetEdit($perfil, array(
                                'class' => 'm-wrap placeholder-no-fix',
                                'placeholder' => $campo->title,
                            ));
                        } elseif ($campo->range) {
                            echo $form->dropDownList($perfil, $campo->varname, Perfil::range($campo->range), array(
                                'class' => 'm-wrap placeholder-no-fix',
                                'placeholder' => $campo->title,
                            ));
                        } elseif ($campo->field_type == "TEXT") {
                            echo $form->textArea($perfil, $campo->varname, array(
                                'rows' => 6,
                                'cols' => 50,
                                'class' => 'm-wrap placeholder-no-fix',
                                'placeholder' => $campo->title,
                            ));
                        } else {
                            echo $form->textField($perfil, $campo->varname, array(
                                'maxlength' => (($campo->field_size) ? $campo->field_size : 255),
                                'class' => 'm-wrap placeholder-no-fix',
                                'placeholder' => $campo->title,
                            ));
                        }
                        ?>
                    </div>
                </div>
            </div>	
            <?php
        }
    }
    ?>
    <?php if (UsuarioModule::doCaptcha('registration')): ?>
        <div class="control-group">
            <label class="control-label visible-ie8 visible-ie9"><?php echo $form->labelEx($model, 'codigo_verificacion'); ?></label>
            <div class="controls">
                <?php $this->widget('CCaptcha'); ?>
                <div class="input-icon">
                    <?php
                    echo $form->textField($model, 'codigo_verificacion', array(
                        'class' => 'm-wrap placeholder-no-fix',
                        'placeholder' => $model->getAttributeLabel('codigo_verificacion'),
                    ));
                    ?>
                </div>    
                <span class="help-block">
                    <?php echo UsuarioModule::t("Please enter the letters as they are shown in the image above."); ?>
                    <br/>
                    <?php echo UsuarioModule::t("Letters are not case-sensitive."); ?>
                </span>
            </div>
        </div>
    <?php endif; ?>

    <div class="control-group">
        <div class="controls">
            <label class="checkbox">
                <input type="checkbox" name="tnc"/> I agree to the <a href="#">Terms of Service</a> and <a href="#">Privacy Policy</a>
            </label>  
            <div id="register_tnc_error"></div>
        </div>
    </div>


    <div class="form-actions">
        <?php
        $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType' => 'link',
            'url' => Yii::app()->user->returnUrl,
            'type' => 'primary',
            'icon' => 'm-icon-swapleft',
            'label' => Yii::t('factuges', 'Volver'),
            'htmlOptions' => array('class' => 'btn'),
        ));
        ?>

        <?php
        $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType' => 'submit',
            'type' => 'primary',
            'encodeLabel' => false,
            'label' => Yii::t('factuges', 'Registrar') . ' ' . CHtml::tag('i', array('class' => 'm-icon-swapright m-icon-white'), ''),
            'htmlOptions' => array('class' => 'btn green pull-right'),
        ));
        ?>
    </div>
    <?php $this->endWidget(); ?>
<?php endif; ?>