{box title="Information about the subscriber"}
<style>
	#updatepinbtn,
	#updatedatabtn {
		margin-left: 10px;
	}
</style>
{if $fields_changed}
	<div class="alert alert-info">{trans("WARNING! Some fields have been changed and changes must become accepted by admin")}.</div>
{/if}
<div class="card">
	<div class="card-header">
		{if $userinfo.type == 0}
			<strong>{trans("Personal data")}</strong>
		{else}
			<strong>{trans("Company data")}</strong>
		{/if}
		{if $rights.info.edit_addr || $rights.info.edit_addr_ack || $rights.info.edit_contact || $rights.info.edit_contact_ack}
			{if $rights.info.edit_addr || $rights.info.edit_addr_ack || $rights.info.edit_contact || $rights.info.edit_contact_ack}
				{button id="updatedatabtn" class="btn btn-primary btn-sm" data_toggle="modal" data_target="#updateuserinfobox" accesskey="A" icon="reload" label="Update"}
			{/if}
		{/if}
	</div>
	<ul class="list-group list-group-flush">
		<li class="list-group-item">
			<strong>{if $userinfo.type == 0}{trans("Last and first name")}{else}{trans("Company name")}{/if}:</strong><br>
			{if isset($fields_changed.lastname) || isset($fields_changed.name)}
			    <del>{$userinfo.customername}</del>&rarr;
			    {if isset($fields_changed.lastname) && $fields_changed.lastname.fieldvalue != $userinfo.lastname}<mark>{$fields_changed.lastname.fieldvalue}</mark>{else}{$userinfo.lastname}{/if}
			    {if isset($fields_changed.name) && $fields_changed.name.fieldvalue != $userinfo.name}<mark>{$fields_changed.name.fieldvalue}</mark>{else}{$userinfo.name}{/if}
			{else}
			    {$userinfo.customername}
			{/if}
		</li>
		{if $userinfo.emails}
			<li class="list-group-item">
				<strong>{trans("E-mail:")}</strong><br>
				{foreach $userinfo.emails as $email}
				    {$emailid='email'|cat:$email.id}
				    {if isset($fields_changed[$emailid])}
					<del>{$email.email}</del> &rarr; <mark>{$fields_changed[$emailid].fieldvalue}</mark>
				    {else}
					{$email.email}
				    {/if}
				    {if !$email@last}<br>{/if}
				{/foreach}
		</li>
		{/if}
		<li class="list-group-item">
			<strong>{trans("Address:")}</strong><br>
			{if isset($fields_changed.street) || isset($fields_changed.building) || isset($fields_changed.apartment)}
			    <del>{$userinfo.address}</del>&rarr;
			    {if isset($fields_changed.street) && $fields_changed.street.fieldvalue != $userinfo.street}<mark>{$fields_changed.street.fieldvalue}</mark>{else}{$userinfo.street}{/if}
			    {if isset($fields_changed.building) && $fields_changed.building.fieldvalue != $userinfo.building}<mark>{$fields_changed.building.fieldvalue}</mark>{else}{$userinfo.building}{/if}
			    {if isset($fields_changed.apartment) && $fields_changed.apartment.fieldvalue != $userinfo.apartment}/<mark>{$fields_changed.apartment.fieldvalue}</mark>{else}{$userinfo.apartment}{/if}
			{else}
			    {$userinfo.address}
			{/if}
			{if isset($fields_changed.zip) || isset($fields_changed.city)}
			    <del>, {$userinfo.zip} {$userinfo.city}</del>&rarr;
			    {if isset($fields_changed.zip) && $fields_changed.zip.fieldvalue != $userinfo.zip}, <mark>{$fields_changed.zip.fieldvalue}</mark>{else}, {$userinfo.zip}{/if}
			    {if isset($fields_changed.city) && $fields_changed.city.fieldvalue != $userinfo.city}&nbsp;<mark>{$fields_changed.city.fieldvalue}</mark>{else}&nbsp;{$userinfo.city}{/if}
			{else}
			    , {$userinfo.zip} {$userinfo.city}
			{/if}
		</li>
		{if $userinfo.serviceaddr}
			<li class="list-group-item">
				<strong>{trans("Postal address:")}</strong><br>
				{$userinfo.serviceaddr}
			</li>
		{/if}
		{if $userinfo.contacts}
			<li class="list-group-item">
				<strong>{trans("Phones:")}</strong><br>
				{foreach $userinfo.contacts as $item}
				    {$phoneid='phone'|cat:$item.id}
				    {if isset($fields_changed[$phoneid])}
					<del>{$item.phone}</del> &rarr; <mark>{$fields_changed[$phoneid].fieldvalue}</mark>
				    {else}
					{$item.phone}
				    {/if}
				    {if !$item@last}<br>{/if}
				{/foreach}
			</li>
		{/if}

		{foreach $userinfo.ims as $item}
			<li class="list-group-item">
				<strong>
					{if $item.type & $smarty.const.CONTACT_IM_GG}
						{trans("Gadu-Gadu")}
					{elseif $item.type & $smarty.const.CONTACT_IM_YAHOO}
						{trans("Yahoo")}
					{elseif $item.type & $smarty.const.CONTACT_IM_SKYPE}
						{trans("Skype")}
					{elseif $item.type & $smarty.const.CONTACT_IM_FACEBOOK}
						{trans("Facebook")}
					{/if}
				</strong><br>
				{$item.uid}
				{$imid='im'|cat:$item.id}
				{if isset($fields_changed[$imid])}
				    <del>{$item.uid}</del> &rarr; <mark>{$fields_changed[$imid].fieldvalue}</mark>
				{/if}
			</li>
		{/foreach}

		{if $userinfo.ten neq ""}
			<li class="list-group-item">
				<strong>{trans("TEN")}:</strong>
				{if isset($fields_changed.ten) && $fields_changed.ten.fieldvalue != $userinfo.ten}
				    <del>{$userinfo.ten}</del> &rarr; <mark>{$fields_changed.ten.fieldvalue}</mark>
				{else}
				    {$userinfo.ten}
				{/if}
			</li>
		{/if}

		{if $userinfo.ssn neq "" && (isset($fields_changed.ssn) && $fields_changed.ssn.fieldvalue != $userinfo.ssn || ConfigHelper::checkConfig('userpanel.show_customer_sensitive_data'))}
			<li class="list-group-item">
				<strong>{trans("SSN")}:</strong>
				{if isset($fields_changed.ssn) && $fields_changed.ssn.fieldvalue != $userinfo.ssn}
					{if ConfigHelper::checkConfig('userpanel.show_customer_sensitive_data')}
						<del>{$userinfo.ssn}</del>
					{/if}
					&rarr; <mark>{$fields_changed.ssn.fieldvalue}</mark>
				{else}
					{$userinfo.ssn}
				{/if}
			</li>
		{/if}

		<li class="list-group-item">
			<strong>{trans("Balance:")}
		{if $userinfo.balance < 0}<span class="text-danger">{$userinfo.balance|money_format}{else}<span class="text-success">{$userinfo.balance|money_format}{/if}</span>
			</strong>
	</li>
	{if $userinfo.bankaccount || $userinfo.accounts}
		<li class="list-group-item">
			<strong>{trans("Bank accounts:")}</strong><br>
			{if $userinfo.bankaccount}
				{format_bankaccount($userinfo.bankaccount)|replace:" ":"&nbsp;"}
			{/if}
			{if $userinfo.accounts}<br>{/if}
			{foreach $userinfo.accounts as $account}
				{format_bankaccount($account.account)|replace:" ":"&nbsp;"}{if !$account@last}<br>{/if}
			{/foreach}

		</li>
	{/if}
</ul>
</div>
{/box}

<!-- Modal -->
<div class="modal fade" id="updateuserinfobox" tabindex="-1" role="dialog" aria-labelledby="updateuserinfobox" aria-hidden="true">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title">{trans("Information about the subscriber")}</h4>
				{button class="close" data_dismiss="modal" icon="cancel"}
			</div>
			<div class="modal-body">
				{if $error.ssn}
					<div class="alert alert-danger">{trans("Incorrect Social Security Number!")}</div>
				{/if}
				{if $error.ten}
					<div class="alert alert-danger">{trans("Incorrect Tax Exempt Number!")}</div>
				{/if}
				<form name="useredit" method="post" action="?m=info&f=updateusersave">
					{if $rights.info.edit_addr || $rights.info.edit_addr_ack}
						<div class="form-group">
							<label class="font-weight-bold" for="lastname">{if $userinfo.type == $smarty.const.CTYPES_PRIVATE}{trans("Last name:")}{else}{trans("Company name:")}{/if}</label>
							<input id="lastname" class="form-control" type="text" name="userdata[lastname]" value="{$userinfo.lastname|escape}" placeholder="{trans("Enter lastname")}">
						</div>
						{if $userinfo.type == $smarty.const.CTYPES_PRIVATE}
							<div class="form-group">
								<label class="font-weight-bold" for="firstname">{trans("First name:")}</label>
								<input id="firstname" class="form-control" type="text" name="userdata[name]" value="{$userinfo.name|escape}" placeholder="{trans("Enter first name")}">
							</div>
						{/if}
					{else}
						<strong>{trans("Name:")}</strong><br>{$userinfo.customername} ({$userinfo.id|string_format:"%04d"})
					{/if}

					{if $rights.info.edit_addr || $rights.info.edit_addr_ack}
						<div class="form-group">
							<label for="inputEmail3" class="col-form-label">{trans("Street:")}</label>
							<INPUT class="form-control" TYPE="TEXT" NAME="userdata[street]" VALUE="{$userinfo.street}" placeholder="{trans("Enter street name")}">
						</div>
						<div class="form-group row">
							<label for="building" class="col-form-label">{trans("Building:")}</label>
							<INPUT class="col form-control col-sm-2" id="building" TYPE="TEXT" NAME="userdata[building]" VALUE="{$userinfo.building}" placeholder="{trans("Enter building number")}">

							<label for="apartment" class="col-form-label">{trans("Apartment:")}</label>
							<INPUT class="col form-control col-sm-2" id="apartment" TYPE="TEXT" NAME="userdata[apartment]" VALUE="{$userinfo.apartment}" placeholder="{trans("Enter apartment number")}">
						</div>

						<div class="form-group row">
							<label for="zip" class="col-form-label">{trans("Zip:")}</label>
							<INPUT class="col-2 form-control" id="zip" TYPE="TEXT" NAME="userdata[zip]" VALUE="{$userinfo.zip}" placeholder="{trans("Enter zip code")}">

							<label for="city" class="col-form-label">{trans("City:")}</label>
							<INPUT class="col-5 form-control" id="city" TYPE="TEXT" NAME="userdata[city]" VALUE="{$userinfo.city}" placeholder="{trans("Enter city name")}">
						</div>
					{else}
						{$userinfo.address},<br> {$userinfo.zip} {$userinfo.city}
					{/if}
					<br><br>
					{if $rights.info.edit_contact || $rights.info.edit_contact_ack}

						{foreach $userinfo.emails as $email}
							<div class="form-group">
								<label for="email{$email.id}" class="font-weight-bold">{trans("E-mail:")}</label>
								<input id="email{$email.id}" class="form-control" type="email" name="userdata[email][{$email.id}]" value="{$email.email}" placeholder="{trans("Enter e-mail address")}">
							</div>
						{foreachelse}
							<div class="form-group">
								<label for="email" class="font-weight-bold">{trans("E-mail:")}</label>
								<INPUT id="email" class="form-control" type="email" name="userdata[email][0]" value="{$userinfo.email}" placeholder="{trans("Enter e-mail address")}">
							</div>
						{/foreach}
					{else}
						<strong>{trans("E-mail:")}</strong>
						{foreach $userinfo.emails as $email}
							{$email.email}{if !$email@last}<br>{/if}
						{/foreach}
					{/if}

					{if $rights.info.edit_contact || $rights.info.edit_contact_ack}
						{foreach $userinfo.contacts as $item}
							<div class="form-group">
								<strong>{trans("Phone:")}</strong>
								<INPUT class="form-control" TYPE="tel" NAME="userdata[phone][{$item.id}]" VALUE="{$item.phone}" placeholder="{trans("Enter phone number")}">
							</div>
						{foreachelse}
							<div class="form-group">
								<strong>{trans("Phone:")}</strong>
								<INPUT class="form-control" TYPE="tel" NAME="userdata[phone][0]" VALUE="{$userinfo.phone}" placeholder="{trans("Enter phone number")}">
							</div>
						{/foreach}
					{else}
						{foreach $userinfo.contacts as $item}
							{if $item.phone}{$item.phone}<br>{/if}
						{/foreach}
					{/if}

					{foreach $userinfo.ims as $item}
						<div class="font-weight-bold form-group">
							{if $item.type & $smarty.const.CONTACT_IM_GG}
								{trans("Gadu-Gadu")}
							{elseif $item.type & $smarty.const.CONTACT_IM_YAHOO}
								{trans("Yahoo")}
							{elseif $item.type & $smarty.const.CONTACT_IM_SKYPE}
								{trans("Skype")}
							{elseif $item.type & $smarty.const.CONTACT_IM_FACEBOOK}
								{trans("Facebook")}
							{/if}

							{if $rights.info.edit_contact || $rights.info.edit_contact_ack}
								<INPUT class="form-control" TYPE="TEXT" NAME="userdata[im][{$item.id}]" VALUE="{$item.uid}" placeholder="{trans("Enter IM number")}">
							{else}
								{$item.uid}
							{/if}
						</div>
					{/foreach}

					{if $userinfo.type == 0}
						{if $rights.info.edit_addr || $rights.info.edit_addr_ack}
							<div class="form-group">
								<strong>{trans("SSN")}:</strong>
								<INPUT class="form-control" type="text" NAME="userdata[ssn]" VALUE="{if ConfigHelper::checkConfig('userpanel.show_customer_sensitive_data')}{$userinfo.ssn}{else}***{/if}" placeholder="{trans("Enter social security number")}">
							</div>
						{else}
							{if ConfigHelper::checkConfig('userpanel.show_customer_sensitive_data')}
								<strong>{trans("SSN")}:</strong> {$userinfo.ssn}
							{/if}
						{/if}
					{else}
						{if $rights.info.edit_addr || $rights.info.edit_addr_ack}
							<div class="form-group">
								<strong>{trans("TEN")}: </strong>
								<INPUT class="form-control" TYPE="TEXT" NAME="userdata[ten]" VALUE="{$userinfo.ten}" placeholder="{trans("Enter tax exempt number")}">
							</div>
						{else}
							<strong>{trans("TEN")}:</strong> {$userinfo.ten}
						{/if}
					{/if}
				</form>
			</div>
			<div class="modal-footer">
				{if $rights.info.edit_addr || $rights.info.edit_addr_ack || $rights.info.edit_contact || $rights.info.edit_contact_ack}
					{button class="btn btn-danger" id="updateuserbtn" accesskey="A" icon="save" label="Save"}
				{/if}
					{button class="btn btn-secondary" data_dismiss="modal" icon="close" label="Close"}
			</div>
		</div>
	</div>
</div>
<script>

	$(function() {
		$('#updateuserbtn').click(function () {
			$('#updateuserinfobox').find('.alert').remove();

			var emails = $('input[type="email"]');
			var invalid = emails.length;
			emails.each(function () {
				if (this.checkValidity()) {
					invalid--;
				}
			});
			if (invalid) {
				return false;
			} else {
				document.useredit.submit();
			}
		});

		{if !empty($error)}
			$('#updateuserinfobox').modal('show');
		{/if}
	});

</script>
