<?php

echo $form->textFieldRow($model, 'name', array(
    'class' => 'span3',
    'data-translation-target' => 'USERS_FORM_NAME',
    'autocomplete' => 'off',
    'rel' => 'tooltip',
    'data-original-title' => __("USER_MODEL_CANNOT_CHANGE_SYSTEM_ADMIN_NAME"),
    'data-placement' => 'right',
    'readonly' => $model->isSystemAdmin,
));


echo $form->dropDownListRow($model, 'group', $availableGroups, array(
    'class' => 'span3',
    'data-translation-id' => 'USERGROUPS_MODEL_GROUP',
));

if (cfg('DP_BRANCH_PREFIX')) {
    echo $form->textFieldRow($model, 'extension', array(
        'prepend' => cfg('DP_BRANCH_PREFIX'),
        'class' => 'span3',
        'style' => 'width: 179px;',
        'data-translation-target' => 'USERS_FORM_EXTENSION',
        'autocomplete' => 'off',
    ));
} else {
    echo $form->textFieldRow($model, 'extension', array(
        'class' => 'span3',
        'data-translation-target' => 'USERS_FORM_EXTENSION',
        'autocomplete' => 'off',
    ));
}

if ($model->isNewRecord) {
    echo $form->textFieldRow($model, 'password', array(
        'class' => 'span3',
        'data-translation-id' => 'USERS_MODEL_PASSWORD',
        'autocomplete' => 'off',
    ));
} else {
    $userModel = app()->user->realUserInstance;
    if ($userModel->isSystemAdmin) {
        echo $form->passwordFieldRow($model, 'password', array(
            'class' => 'span3',
            'data-translation-id' => 'USERS_MODEL_PASSWORD',
            'autocomplete' => 'off',
            'placeholder' => '********************',
        ));
    }
}

echo $form->textFieldRow($model, 'pin', array(
    'class' => 'span3',
    'data-translation-id' => 'USERS_MODEL_PIN',
    'autocomplete' => 'off',
));

if (Yii::app()->user->translateMode) {
    echo '<i data-translation-id = "USERS_MODEL_NAME" data-translation-target = "USERS_FORM_NAME"></i>';
    echo '<i data-translation-id = "USER_MODEL_IS_UNIQUE_ERROR_MESSAGE" data-translation-target = "USERS_FORM_NAME"></i>';
    echo '<i data-translation-id = "USER_MODEL_SHOULD_NOT_START_WITH_ZERO_OR_PUNCTUATION_CHARACTERS_ERROR_MESSAGE" data-translation-target = "USERS_FORM_NAME"></i>';
    echo '<i data-translation-id = "USER_MODEL_SHOULD_ONLY_CONTAIN_UNDERLINE_AND_DOT_PUNCTUATION_CHARACTERS_ERROR_MESSAGE" data-translation-target = "USERS_FORM_NAME"></i>';
    echo '<i data-translation-id = "USERS_MODEL_EXTENSION" data-translation-target = "USERS_FORM_EXTENSION"></i>';
    echo '<i data-translation-id = "USER_MODEL_IS_UNIQUE_ERROR_MESSAGE" data-translation-target = "USERS_FORM_EXTENSION"></i>';
    echo '<i data-translation-id = "USER_MODEL_SHOULD_NOT_START_WITH_ZERO_ERROR_MESSAGE" data-translation-target = "USERS_FORM_EXTENSION"></i>';
    echo '<i data-translation-id="DEFAULT_TIMEZONE" data-translation-target="USERS_MODAL_TIMEZONE"></i>';
    echo '<i data-translation-id="USERS_MODEL_USER_TIMEZONE" data-translation-target="USERS_MODAL_TIMEZONE"></i>';
    echo '<i data-translation-id="DEFAULT_LANGUAGE" data-translation-target="USERS_MODAL_LANGUAGE"></i>';
    echo '<i data-translation-id="USERS_MODEL_USER_LANGUAGE" data-translation-target="USERS_MODAL_LANGUAGE"></i>';
    echo '<i data-translation-id="DEFAULT_TIME_FORMAT" data-translation-target="USERS_MODAL_TIME_FORMAT"></i>';
    echo '<i data-translation-id="USERS_MODEL_USER_TIME_FORMAT" data-translation-target="USERS_MODAL_TIME_FORMAT"></i>';
    echo '<i data-translation-id="DEFAULT_DATE_FORMAT" data-translation-target="USERS_MODAL_DATE_FORMAT"></i>';
    echo '<i data-translation-id="USERS_MODEL_USER_DATE_FORMAT" data-translation-target="USERS_MODAL_DATE_FORMAT"></i>';
    echo '<i data-translation-id = "USER_MODEL_CANNOT_CHANGE_SYSTEM_ADMIN_NAME" data-translation-target = "USER_MODEL_CANNOT_CHANGE_SYSTEM_ADMIN_NAME"></i>';
}

echo $form->textFieldRow($model, 'firstname', array(
    'class' => 'span3',
    'data-translation-id' => 'USERS_MODEL_FIRSTNAME',
    'autocomplete' => 'off',
));
echo $form->textFieldRow($model, 'lastname', array(
    'class' => 'span3',
    'data-translation-id' => 'USERS_MODEL_LASTNAME',
    'autocomplete' => 'off',
));
echo $form->textFieldRow($model, 'email', array(
    'class' => 'span3',
    'data-translation-id' => 'USERS_MODEL_EMAIL',
    'autocomplete' => 'off',
));
?>

<script>
$(function() {
	function initAdminUserNameTooltip() {
		var isSystemAdmin = '<?php echo $model->isSystemAdmin; ?>';
		if (isSystemAdmin === "1") { 
			$('#User_name').tooltip();
		}
	};
	initAdminUserNameTooltip();
});
</script>