<?
$item = $this->item;
$title = $item['id'] ? 'Edit User' : 'Create User';
$title = $this->_($title);
$this->headTitle($title, 'SET');
$this->textDelay('breadcrumbText', $title);

if($this->form){
	$form = $this->form;
} else {
    $form = $item['id'] ? new User\Form\UserEditForm() : new User\Form\UserCreateForm();
    $form->useSubFormGroup();
}

$form->setMethod($item['id'] ? 'put' : 'post');
$form->setView($this)
     ->setAction($this->uri('/admin/user/'))
     ->bind($item)
     ->prepare();
$tags = isset($item['Tags']) ? $item['Tags'] : array();
?>

<div class="row">
    <form <?=$this->formAttr($form)?>>
        <?=$form->restful();?>
        <?=$form->helper('id');?>
        <?=$form->helper('avatar_id');?>
        <div class="span10">
            <?if($item):?>
            <div class="btn-group pull-right">
                <a href="<?=$this->uri('/admin/user/create')?>" class="btn"><?=$this->_('Clear Cache')?></a>
                <a href="<?=$this->uri('/admin/user/remove/' . $item['id'], 'c', array('c' => $this->uri('/admin/user/' . $item['id']))); ?>" class="btn"><?=$this->_('Delete')?></a>
            </div>
            <ul class="nav nav-tabs">
                <li class="active">
                <a href="<?=$this->uri('/admin/user/' . $item['id'])?>"><?=$title?></a>
                </li>
                <li><a href="<?=$this->uri('/admin/user/field/userfield/' . $item['id'])?>"><?=$this->_('User Fields')?></a></li>
                <li><a href="#"><?=$this->_('User Tags')?></a></li>
            </ul>
            <?else:?>
            <div class="slate">
                <div class="page-headr">
                    <h2><?=$title?></h2>
                </div>
            </div>
            <?endif?>
        </div><!--span10 end-->

        <div class="span5">
            <div class="slate">
                <div class="page-header">
                    <h3><?=$this->_('User Basic Info')?></h3>
                </div>

                <fieldset class="form-horizontal">
                    <div class="control-group <?=$form->isError('userName') ? 'error' : '';?>">
                        <?=$form->helper('userName', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper('userName', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper('userName', 'formElementErrors')?></div>
                        </div>
                    </div>

                    <div class="control-group <?=$form->isError('status') ? 'error' : '';?>">
                        <?=$form->helper('status', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper('status', 'formSelect', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper('status', 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError('screenName') ? 'error' : '';?>">
                        <?=$form->helper('screenName', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper('screenName', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper('screenName', 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError('firstName') ? 'error' : '';?>">
                        <?=$form->helper('firstName', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper('firstName', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper('firstName', 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError('lastName') ? 'error' : '';?>">
                        <?=$form->helper('lastName', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper('lastName', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper('lastName', 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError('gender') ? 'error' : '';?>">
                        <?=$form->helper('gender', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper('gender', 'formSelect', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper('gender', 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError('avatar') ? 'error' : '';?>">
                        <?=$form->helper('avatar', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper('avatar', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper('avatar', 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError('timezone') ? 'error' : '';?>">
                        <?=$form->helper('timezone', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper('timezone', 'formSelect', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper('timezone', 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError('language') ? 'error' : '';?>">
                        <?=$form->helper('language', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper('language', 'formSelect', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper('language', 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError('flag') ? 'error' : '';?>">
                        <?=$form->helper('flag', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper('flag', array('class' => 'span1'))?>        
                            <div class="help-block"><?=$form->helper('flag', 'formElementErrors')?></div>
                        </div>
                    </div>
                </fieldset>
            </div>
        </div><!--span5 end-->

        <div class="span5">
            <div class="slate">
                <div class="page-header">
                    <h3><?=$this->_('Security Setting')?></h3>
                </div>
                <fieldset class="form-horizontal">
                   <div class="control-group <?=$form->isError('email') ? 'error' : '';?>">
                        <?=$form->helper('email', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper('email', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper('email', 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError('inputPassword') ? 'error' : '';?> hide">
                        <?=$form->helper('inputPassword', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper('inputPassword', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper('inputPassword', 'formElementErrors')?></div>
                        </div>
                    </div>
                </fieldset>
            </div>
        </div><!--span5 end-->


        <div class="span5">
            <div class="slate">
                <div class="page-header">
                    <h3><?=$this->_('Credits Setting')?></h3>
                </div>
                <fieldset class="form-horizontal">
                    <div class="control-group <?=$form->isError(array('Account', 'credits')) ? 'error' : '';?>">
                        <?=$form->helper(array('Account', 'credits'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Account', 'credits'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Account', 'credits'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Account', 'points')) ? 'error' : '';?>">
                        <?=$form->helper(array('Account', 'points'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Account', 'points'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Account', 'points'), 'formElementErrors')?></div>
                        </div>
                    </div>

                </fieldset>
            </div>
        </div><!--span5 end-->

        <div class="span5">
            <div class="slate">
                <div class="page-header">
                    <h3><?=$this->_('Tags')?></h3>
                </div>
                <fieldset class="form-horizontal">
                    <div class="control-group">
                        <label class="control-label">Tags</label>
                        <div class="controls">
                            <?$tagForm = $form->get('Tags')->get('0');?>
                            <?=$tagForm->helper('tagName', array('id' => 'tagging', 'class' => 'input-block-level', 'value' => $this->tagging($tags)->toNameString()))?> 
                        </div>
                    </div>
                </fieldset>
            </div>
        </div><!--span5 end-->


        <div class="span10">
            <div class="slate">
                <div class="page-header">
                    <h3><?=$this->_('Roles & Permissions')?></h3>
                </div>
                <?foreach($form->get('RoleUser') as $subForm):?>
                <?$role = $subForm->getRole();?>
                <fieldset class="form-horizontal">
                    <div class="control-group <?=$subForm->isError('role_id') ? 'error' : '';?> span3">
                        <?=$subForm->helper('role_id', 'label', array(
                            'class' => 'control-label',
                            'label' => $role['roleName'],
                        ))?>
                        <div class="controls">
                            <?=$subForm->helper('role_id', 'formCheckbox', array(
                                'class' => '',
                                'checkedValue' => $role['id'],
                                'checked' => $subForm->get('user_id')->getValue() ? true : false
                            ))?>
                            <div class="help-block"><?=$subForm->helper('role_id', 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$subForm->isError('status') ? 'error' : '';?> span3">
                        <?=$subForm->helper('status', 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$subForm->helper('status', 'formSelect', array('class' => ''))?>        
                            <div class="help-block"><?=$subForm->helper('status', 'formElementErrors')?></div>
                        </div>
                    </div>
                </fieldset>
                <?endforeach?>
            </div>
        </div><!--span5 end-->

        <div class="span10">
            <div class="slate">
                <div class="page-header">
                    <h2><?=$this->_('User Profile')?></h2>
                </div>
                <fieldset class="form-horizontal">
                    <div class="control-group <?=$form->isError(array('Profile', 'site')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'site'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'site'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'site'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'fullName')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'fullName'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'fullName'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'fullName'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'birthday')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'birthday'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'birthday'), array('class' => 'datepicker', 'data-date-format' => 'yyyy-mm-dd'))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'birthday'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'height')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'height'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'height'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'height'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'weight')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'weight'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'weight'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'weight'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'country')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'country'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'country'), 'formSelect', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'country'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'address')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'address'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'address'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'address'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'addressMore')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'addressMore'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'addressMore'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'addressMore'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'city')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'city'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'city'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'city'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'province')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'province'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'province'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'province'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'state')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'state'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'state'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'state'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'zipcode')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'zipcode'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'zipcode'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'zipcode'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'phoneBusiness')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'phoneBusiness'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'phoneBusiness'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'phoneBusiness'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'phoneMobile')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'phoneMobile'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'phoneMobile'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'phoneMobile'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'phoneHome')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'phoneHome'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'phoneHome'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'phoneHome'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'fax')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'fax'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'fax'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'fax'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'signature')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'signature'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'signature'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'signature'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'location')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'location'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'location'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'location'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'bio')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'bio'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'bio'), 'formTextarea', array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'bio'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'localIm')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'localIm'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'localIm'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'localIm'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'internalIm')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'internalIm'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'internalIm'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'internalIm'), 'formElementErrors')?></div>
                        </div>
                    </div>
                    <div class="control-group <?=$form->isError(array('Profile', 'otherIm')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'otherIm'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'otherIm'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'otherIm'), 'formElementErrors')?></div>
                        </div>
                    </div>
    
                    <div class="control-group <?=$form->isError(array('Profile', 'interest')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'interest'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'interest'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'interest'), 'formElementErrors')?></div>
                        </div>
                    </div>

                    <div class="control-group <?=$form->isError(array('Profile', 'industry')) ? 'error' : '';?>">
                        <?=$form->helper(array('Profile', 'industry'), 'label', array('class' => 'control-label'))?>
                        <div class="controls">
                            <?=$form->helper(array('Profile', 'industry'), array('class' => ''))?>        
                            <div class="help-block"><?=$form->helper(array('Profile', 'industry'), 'formElementErrors')?></div>
                        </div>
                    </div>
                </fieldset>
            </div>
        </div><!--span10 end-->


        <div class="span10 listing-buttons">
            <button id="save-publish" class="btn btn-success btn-large"><?=$this->_('Save')?></button>
        </div>
    </form>
</div>


<script>
eva.ready(function(){
	eva.loadcss(eva.s('/lib/js/jquery/jquery.select2/select2.css'));
	eva.loader(eva.s('/lib/js/jquery/jquery.select2/select2.js'), function(){
            $('#tagging').select2({
                    tags : <?=$this->json($this->tagging($tags)->toNameArray())?>
            });
	});
});
</script>
