@extends('layouts.default')

@section('title')
	@parent
	Редактирование информации о пользователе
@stop

@section('js')
	<script src="{{ asset('js/jquery.maskedinput.min.js') }}"></script>
	<script language="javascript" type="text/javascript">
	$(document).ready(function() {
		$("#edit_phone").mask("+7 (999) 999-99-99")
	});
	</script>
@stop

@section('content')
	<h4>Редакитрование
		@if ($user->email == Sentry::getUser()->email)
		вашей
		@else
		{{ $user->email }}
		@endif

		информации</h4>
	<div class="well">
		{{ Form::open(array(
					'action' => array('UserController@update', $user->id),
					'method' => 'put',
					'class' => 'form-horizontal',
					'role' => 'form'
					)) }}

		<div class="form-group {{ ($errors->has('firstName')) ? 'has-error' : '' }}" for="firstName">
			{{ Form::label('edit_firstName', 'Имя', array('class' => 'col-sm-2 control-label')) }}
			<div class="col-sm-10">
				{{ Form::text('firstName', $user->first_name, array('class' => 'form-control', 'placeholder' => 'Имя', 'id' => 'edit_firstName'))}}
				{{ ($errors->has('firstName') ? '<p class="help-block">'.$errors->first('firstName').'</p>' : '') }}
			</div>
		</div>

		<div class="form-group {{ ($errors->has('lastName')) ? 'has-error' : '' }}" for="lastName">
			{{ Form::label('edit_lastName', 'Фамилия', array('class' => 'col-sm-2 control-label')) }}
			<div class="col-sm-10">
				{{ Form::text('lastName', $user->last_name, array('class' => 'form-control', 'placeholder' => 'Фамилия', 'id' => 'edit_lastName'))}}
				{{ ($errors->has('lastName') ? '<p class="help-block">'.$errors->first('lastName').'</p>' : '') }}
			</div>
		</div>

		<div class="form-group {{ ($errors->has('phone')) ? 'has-error' : '' }}" for="phone">
			{{ Form::label('edit_phone', 'Телефон', array('class' => 'col-sm-2 control-label')) }}
			<div class="col-sm-10">
				{{ Form::text('phone', $user->phone, array('class' => 'form-control', 'placeholder' => 'Телефон', 'id' => 'edit_phone'))}}
				{{ ($errors->has('phone') ? '<p class="help-block">'.$errors->first('phone').'</p>' : '') }}
			</div>
		</div>

		@if (Sentry::getUser()->hasAccess('admin') || User::find(Sentry::getUser()->id)->hasRole(Role::ROLE_USERS_EDITOR))
		<div class="form-group">
			{{ Form::label('edit_memberships', 'Группы', array('class' => 'col-sm-2 control-label'))}}
			<div class="col-sm-10">
				@foreach ($allGroups as $group)
				<label class="checkbox-inline">
					<input type="checkbox" name="groups[{{ $group->id }}]" value='1'
								 {{ (in_array($group->name, $userGroups) ? 'checked="checked"' : '') }} > {{ $group->getName() }}
				</label>
				@endforeach
			</div>
		</div>
		@endif
		@if (Sentry::getUser()->hasAccess('admin') || User::find(Sentry::getUser()->id)->hasRole(Role::ROLE_USERS_EDITOR))
		<div class="form-group">
			{{ Form::label('edit_rolesmemberships', 'Роли', array('class' => 'col-sm-2 control-label'))}}
			<div class="col-sm-10">
				@foreach ($allRoles as $role)
				<label class="checkbox-inline">
					<input type="checkbox" name="roles[{{ $role->id }}]" value='1'
								 {{ (in_array($role->id, $userRoles) ? 'checked="checked"' : '') }} > {{ $role->name }}
				</label><br/>
				@endforeach
				<br/>
			</div>
		</div>
		<div class="form-group">
			{{ Form::label('edit_projectsmemberships', 'Проекты', array('class' => 'col-sm-2 control-label'))}}
			<div class="col-sm-10">
				@if ($allProjects->isEmpty())
				<p class="form-control-static">Нет ни одного проекта <a class="btn btn-xs btn-success" href="{{ URL::to('projects/create') }}"><span class="glyphicon glyphicon-plus"></span> Добавить проект</a></p>
				@else
					@foreach ($allProjects as $project)
					<label class="checkbox-inline">
						<input type="checkbox" name="projects[{{ $project->id }}]" value='1'
									 {{ (in_array($project->id, $userProjects) ? 'checked="checked"' : '') }} > {{ $project->name }}
					</label><br/>
					@endforeach
					<br/>
				@endif
			</div>
		</div>
		@endif

		<div class="form-group {{ ($errors->has('city')) ? 'has-error' : '' }}" for="city">
			{{ Form::label('city', 'Город', array('class' => 'col-sm-2 control-label')) }}
			<div class="col-sm-10">
				{{ Form::text('city', $user->city, array('class' => 'form-control', 'id' => 'city'))}}
				{{ ($errors->has('city') ? '<p class="help-block">'.$errors->first('city').'</p>' : '') }}
			</div>
		</div>
		<div class="form-group {{ ($errors->has('address')) ? 'has-error' : '' }}" for="address">
			{{ Form::label('address', 'Адрес', array('class' => 'col-sm-2 control-label')) }}
			<div class="col-sm-10">
				{{ Form::text('address', $user->address, array('class' => 'form-control', 'id' => 'address'))}}
				{{ ($errors->has('address') ? '<p class="help-block">'.$errors->first('address').'</p>' : '') }}
			</div>
		</div>
		<div class="form-group {{ ($errors->has('delivery_company')) ? 'has-error' : '' }}" for="delivery_company">
			{{ Form::label('address', 'Транспортная компания', array('class' => 'col-sm-2 control-label')) }}
			<div class="col-sm-10">
				{{ Form::text('delivery_company', $user->delivery_company, array('class' => 'form-control', 'id' => 'delivery_company'))}}
				{{ ($errors->has('delivery_company') ? '<p class="help-block">'.$errors->first('delivery_company').'</p>' : '') }}
			</div>
		</div>
		<div class="form-group">
			{{ Form::label( null, 'Доставка до:', array('class' => 'col-sm-2 control-label')) }}
			<div class="col-sm-10">
				<div class="radio">
					<label>
						{{ Form::radio( 'delivery_to', 0, (!$user->delivery_to)?true:false) }}
						адреса
					</label>
				</div>
				<div class="radio">
					<label>
						{{ Form::radio( 'delivery_to', 1, ($user->delivery_to == 1)?true:false) }}
						транспортной компании
					</label>
				</div>
			</div>
		</div>
		<div class="form-group {{ ($errors->has('address')) ? 'has-error' : '' }}" for="delivery_price">
			{{ Form::label('delivery_price', 'Стоимость доствки', array('class' => 'col-sm-2 control-label')) }}
			<div class="col-sm-10">
				{{ Form::text('delivery_price', $user->delivery_price, array('class' => 'form-control', 'id' => 'delivery_price'))}}
				{{ ($errors->has('delivery_price') ? '<p class="help-block">'.$errors->first('delivery_price').'</p>' : '') }}
			</div>
		</div>

		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
				{{ Form::hidden('id', $user->id) }}
				{{ Form::submit('Сохранить', array('class' => 'btn btn-primary'))}}
			</div>
		</div>
		{{ Form::close()}}
	</div>

	<h4>Сменить пароль</h4>
	<div class="well">
		{{ Form::open(array(
					'action' => array('UserController@change', $user->id),
					'class' => 'form-inline',
					'role' => 'form'
					)) }}

		<div class="form-group {{ $errors->has('oldPassword') ? 'has-error' : '' }}">
			{{ Form::label('oldPassword', 'Old Password', array('class' => 'sr-only')) }}
			{{ Form::password('oldPassword', array('class' => 'form-control', 'placeholder' => 'Старый пароль')) }}
		</div>

		<div class="form-group {{ $errors->has('newPassword') ? 'has-error' : '' }}">
			{{ Form::label('newPassword', 'New Password', array('class' => 'sr-only')) }}
			{{ Form::password('newPassword', array('class' => 'form-control', 'placeholder' => 'Новый пароль')) }}
		</div>

		<div class="form-group {{ $errors->has('newPassword_confirmation') ? 'has-error' : '' }}">
			{{ Form::label('newPassword_confirmation', 'Confirm New Password', array('class' => 'sr-only')) }}
			{{ Form::password('newPassword_confirmation', array('class' => 'form-control', 'placeholder' => 'Подтверждение пароля')) }}
		</div>

		{{ Form::submit('Изменить пароль', array('class' => 'btn btn-primary'))}}

		{{ ($errors->has('oldPassword') ? '<br />' . $errors->first('oldPassword') : '') }}
		{{ ($errors->has('newPassword') ?  '<br />' . $errors->first('newPassword') : '') }}
		{{ ($errors->has('newPassword_confirmation') ? '<br />' . $errors->first('newPassword_confirmation') : '') }}

		{{ Form::close() }}
	</div>
@stop