<!--// $Id$ //-->
{$unsecure_pin_validity = intval(ConfigHelper::getConfig('customers.unsecure_pin_validity', ConfigHelper::getConfig('phpui.unsecure_pin_validity', 0, true), true))}
{$gps_location_url = ConfigHelper::getConfig('phpui.gps_location_url', 'https://www.google.com/maps/place/%location')}
{$show_numeric_identifiers = ConfigHelper::checkConfig('teryt.show_numeric_identifiers')}
{$restrictive_sensitive_data_access = ConfigHelper::checkConfig('customers.restrictive_sensitive_data_access')}

<style>

	.rbe-details td {
		padding-left: 0 !important;
	}

	.rbe-name {
		display: flex;
		align-items: center;
	}

	.rbe-name > *:not(:first-child) {
		margin-left: 0.3em;
	}

	.customer-header {
		width: 100%;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: stretch;
		flex-wrap: wrap;
	}

	.customer-header > div {
	}

	.customer-contact {
		display: flex;
		max-width: 98%;
	}

	.limit-width {
		max-width: 35vw;
	}

	.customer-options td:last-child {
		padding-left: 0;
	}

	#add-instantpayment {
		margin-left: 1em;
	}

	#instant-payment-options {
		display: inline-flex;
		align-items: center;
		flex-wrap: wrap;
	}

	#payment-options td {
		padding-right: 1em;
	}

	.lms-ui-button-clipboard[data-type] {
		display: none;
	}

	.lms-ui-button-clipboard[data-type] + #check-ssn-button {
		display: none;
	}

	[data-type="ssn"].lms-ui-error {
		color: red;
	}

	.customerinfo-button-panel {
		display: flex;
		flex-direction: column;
	}

	.customerinfo-buttons {
		display: flex;
		flex-wrap: wrap;
	}

	.customerinfo-buttons > *:not(:first-child) {
		margin-left: 0.3em;
	}

	.consent-group {
		display: flex;
		padding-inline-end: 0.5em;
	}

	.lms-ui-separated-rows .lms-ui-separated-rows {
		width: 100%;
	}

	.consent-group-row {
		border-top: none !important;
	}

	.consent-group-row + tr {
		border-top: none !important;
	}

	#consent-caption td {
		display: flex;
		align-items: flex-start;
	}

	#consent-caption td > * {
		margin-left: 0.5em;
		largin-right: 0.5em;
	}

</style>

<table class="lmsbox{if $customerpanel} lms-ui-tab-container lms-ui-sortable{/if}" id="customerinfobox"{if $customerpanel} data-label="{trans("Customer Info")}"{/if}>
	<colgroup>
		<col style="width: 99%;">
		<col style="width: 1%;">
	</colgroup>
	<thead>
		<tr{if $customerpanel} class="hand lmsbox-titlebar" data-lmsbox-content="customerpanel"{/if}>
			<td colspan="2">
				<div class="customer-header">
					<div class="bold">
						{icon name="customer" class="{if $customerpanel} lms-ui-sortable-handle{/if}"}
						{if $customerpanel}{trans("Owner:")}{/if}
						{$customerinfo.customername|escape}
						{if $customerinfo.altname}[{$customerinfo.altname|escape}]{/if}
						(#{$customerinfo.id}{if $customerinfo.extid} / {$customerinfo.extid|escape}{/if})
						{if $customerinfo.deleted} <span class="lms-ui-alert">({trans("deleted customer")})</span>{/if}
					</div>
					<div>
						{karma title="Karma" value=$customerinfo.karma handler="?m=customeredit&id={$customerinfo.id}&op=changekarma"}
						{if $customerpanel}{strip}
							<a href="?m=customerinfo&id={$customerinfo.id}">
								{trans('Navigate to the customer')}
								{icon name="next" class="fa-fw"}
							</a>
						{/strip}{/if}
					</div>
				</div>
			</td>
		</tr>
	</thead>
	<tbody {if $customerpanel} id="customerpanel" style="display:none;"{/if}>
		<tr>
			<td colspan="2" class="container">
				<table width="100%" cellpadding="0">
					<tr>
						<td class="lmsbox-panels">
							<div class="lmsbox-panel">
								<table>
									<colgroup>
										<col style="width: 1%;">
										<col style="width: 99%;">
									</colgroup>
									{block name="customerinfobox-leftcolumn"}
									<tr>
										<td>
											{icon name="customer-status-{$_CSTATUSES[$customerinfo.status].alias}"}
										</td>
										<td class="lms-ui-customer-status-{$_CSTATUSES[$customerinfo.status].alias}">
											<strong>{$_CSTATUSES[$customerinfo.status].singularlabel}</strong>
										</td>
									</tr>
									{if !empty($customerinfo.origin)}
										<tr>
											<td>
												{icon name="origin" class="fa-fw"}
											</td>
											<td>
												{trans($_ORIGINS[$customerinfo.origin])}
											</td>
										</tr>
									{/if}
									{if !empty($customerinfo.flags)}
									<tr>
										<td>
											{icon name="legal-personality"}
										</td>
										<td>
											{$first = true}
											{foreach $_CUSTOMERFLAGS as $cflag => $flag}{if isset($customerinfo.flags[$cflag])}{if !$first}, {/if}<span title="{$flag.tip}">{trans($flag.label)}</span>{$first = false}{/if}{/foreach}
										</td>
									</tr>
									{/if}
									{if $customerinfo.division}
										<tr>
											<td>
												{icon name="division"}
											</td>
											<td>
												{if $customerinfo.division_label}{$customerinfo.division_label|escape}{else}{$customerinfo.division|escape}{/if}
											</td>
										</tr>
									{/if}
									<tr>
										<td>
											{icon name="legal-personality"}
										</td>
										<td>
											{if $customerinfo.type == $smarty.const.CTYPES_COMPANY}
												{assign var='type' value=$smarty.const.CTYPES_COMPANY}
												{$_CTYPES.$type}
											{elseif $customerinfo.type == $smarty.const.CTYPES_PRIVATE}
												{assign var='type' value=$smarty.const.CTYPES_PRIVATE}
												{$_CTYPES.$type}
											{/if}
										</td>
									</tr>
									{if !ConfigHelper::checkPrivilege('hide_customer_sensitive_data', !$restrictive_sensitive_data_access)}
										{if $customerinfo.icn != ""}
											<tr>
												<td class="valign-top">
													{icon name="user-id-number"}
												</td>
												<td>
													{trans("Identity document")}
													<br>
													{if isset($_IDENTITY_TYPES[$customerinfo.ict])}
														{trans($_IDENTITY_TYPES[$customerinfo.ict])}
													{/if}
													{if ConfigHelper::checkPrivilege('customer_sensitive_data_view', !$restrictive_sensitive_data_access)}
														{$icn = $customerinfo.icn|escape}
													{else}
														{$icn = preg_replace('/[^\s]/', '*', $customerinfo.icn)}
													{/if}
													<span class="customer-sensitive-data" data-type="icn">
														{$icn}
													</span>
													{if ConfigHelper::checkPrivilege('customer_sensitive_data_view', !$restrictive_sensitive_data_access)}
														{icon name="copy" class="lms-ui-button-clipboard" data_clipboard_text=$icn}
													{else}
														{icon name="copy" class="lms-ui-button-clipboard" data_clipboard_handler=true
															data_type="icn"}
													{/if}
													{if $customerinfo.icexpires !== ''}
														{if $customerinfo.icexpires > 0}
															{textformat assign="icexpires"}
																{strip}
																	<span{if $customerinfo.icexpires - time() < 31 * 86400} class="lms-ui-alert bold"{/if}>
																		{$customerinfo.icexpires|date_format:"Y-m-d"}
																	<span>
																{/strip}
															{/textformat}
															({t a=$icexpires}expires $a{/t})
														{elseif $customerinfo.icexpires === '0'}
															({trans("never expires")})
														{/if}
													{/if}
												</td>
											</tr>
										{/if}
										{if $customerinfo.ssn != ""}
											<tr>
												<td>
													{icon name="user-id-number"}
												</td>
												<td>
													{trans("SSN")}
													{if ConfigHelper::checkPrivilege('customer_sensitive_data_view', !$restrictive_sensitive_data_access)}
														<span data-type="ssn">
															{$customerinfo.ssn|escape}
														</span>
														{icon name="copy" class="lms-ui-button-clipboard" data_clipboard_text=$customerinfo.ssn}
													{else}
														<span class="customer-sensitive-data" data-type="ssn">
															{preg_replace('/[^\s]/', '*', $customerinfo.ssn)}
														</span>
														{icon name="copy" class="lms-ui-button-clipboard" data_clipboard_handler=true
															data_type="ssn"}
													{/if}
													{if ConfigHelper::getConfig('pesel.api_key', '', true)}
														{button type="link" icon="check" id="check-ssn-button" tip="Check in PESEL Reservation Registry"}
													{/if}
												</td>
											</tr>
										{/if}
									{/if}
									{if $customerinfo.ten != ""}
									<tr>
										<td>
											{icon name="user-id-number" class="lms-ui-button-clipboard" data_clipboard_text=$customerinfo.ten}
										</td>
										<td>
											{trans("TEN")}
											{$customerinfo.ten}
										</td>
									</tr>
									{/if}
									{if $customerinfo.regon != ""}
									<tr>
										<td>
											{icon name="user-id-number" class="lms-ui-button-clipboard" data_clipboard_text=$customerinfo.regon}
										</td>
										<td>
											{trans("REGON")}
											{$customerinfo.regon}
										</td>
									</tr>
									{/if}

									{foreach $customerinfo.addresses as $v}
										{if $v.location_address_type == $smarty.const.BILLING_ADDRESS}
											<tr>
												<td>
													{icon name="home" tip="billing address"}
												</td>
												<td>
													<span title="{trans('billing address')}">
														{if $v.location_name}{$v.location_name|escape}, {/if}
														{if $v.teryt}
															{if $show_numeric_identifiers}
																{capture assign="teryt_comment"}{strip}
																	{if empty($v.location_street)}
																		{t a=$v.terc b=$v.simc}TERC: $a, SIMC: $b{/t}
																	{else}
																		{t a=$v.terc b=$v.simc c=$v.ulic}TERC: $a, SIMC: $b, ULIC: $c{/t}
																	{/if}
																{/strip}{/capture}
																{t a=$v.location|default:""|escape b=$teryt_comment}$a ($b){/t}
															{else}
																{t a=$v.location|default:""|escape}$a (TERYT){/t}
															{/if}
														{else}
															{$v.location|default:""|escape}
														{/if}
													</span>
													{$gps_location_url_replaced = str_replace(
														array(
															'%location',
															'%state',
															'%city',
															'%zip',
															'%street',
															'%full_street',
															'%full_reversed_street',
															'%short_street',
															'%house'
														),
														array(
															$v.location,
															$v.location_state_name,
															$v.location_city_name,
															$v.location_zip,
															$v.location_street_name,
															$v.location_full_street_name,
															$v.location_full_reversed_street_name,
															$v.location_short_street_name,
															$v.location_house
														),
														$gps_location_url
													)}
													{button
														type="link"
														tip="Show on map"
														icon="location"
														href=$gps_location_url_replaced|escape
													}
													{show_on_map_button
														type="default"
														cityid=$v.location_city
														streetid=$v.location_street
														building_num=$v.location_house
													}
													{show_on_map_button
														type="netstork"
														cityid=$v.location_city
														streetid=$v.location_street
														building_num=$v.location_house
													}
													{show_on_map_button
														type="geoportal"
														cityid=$v.location_city
														streetid=$v.location_street
														building_num=$v.location_house
													}
													{show_on_map_button
														type='sidusis'
														cityid=$v.location_city
														streetid=$v.location_street
														building_num=$v.location_house
													}
												</td>
											</tr>
											{break}
										{/if}
									{/foreach}

									{foreach $customerinfo.addresses as $v}
										{if $v.location_address_type == $smarty.const.POSTAL_ADDRESS}
											<tr>
												<td>
													{icon name="message" tip="postal address"}
												</td>
												<td>
													<span title="{trans('postal address')}">
														{if $v.location_name}{$v.location_name|escape}, {/if}
														{if !empty($v.location_ten)}{trans("TEN")} {$v.location_ten|escape}, {/if}
														{if $v.teryt}
															{if $show_numeric_identifiers}
																{capture assign="teryt_comment"}{strip}
																	{if empty($v.location_street)}
																		{t a=$v.terc b=$v.simc}<span class="nobr">TERC: $a,</span> <span class="nobr">SIMC: $b</span>{/t}
																	{else}
																		{t a=$v.terc b=$v.simc c=$v.ulic}<span class="nobr">TERC: $a,</span> <span class="nobr">SIMC: $b,</span> <span class="nobr">ULIC: $c</span>{/t}
																	{/if}
																{/strip}{/capture}
																{t a=$v.location|default:""|escape b=$teryt_comment}$a ($b){/t}
															{else}
																{t a=$v.location|default:""|escape}$a (TERYT){/t}
															{/if}
														{else}
															{$v.location|escape}
														{/if}
													</span>
													{$gps_location_url_replaced = str_replace(
														array(
															'%location',
															'%state',
															'%city',
															'%zip',
															'%street',
															'%full_street',
															'%full_reversed_street',
															'%short_street',
															'%house'
														),
														array(
															$v.location,
															$v.location_state_name,
															$v.location_city_name,
															$v.location_zip,
															$v.location_street_name,
															$v.location_full_street_name,
															$v.location_full_reversed_street_name,
															$v.location_short_street_name,
															$v.location_house
														),
														$gps_location_url
													)}
													{button
														type="link"
														tip="Show on map"
														icon="location"
														href=$gps_location_url_replaced|escape
													}
													{show_on_map_button
														type="default"
														cityid=$v.location_city
														streetid=$v.location_street
														building_num=$v.location_house
													}
													{show_on_map_button
														type="netstork"
														cityid=$v.location_city
														streetid=$v.location_street
														building_num=$v.location_house
													}
													{show_on_map_button
														type="geoportal"
														cityid=$v.location_city
														streetid=$v.location_street
														building_num=$v.location_house
													}
                                                                                                        {show_on_map_button
                                                                                                                type='sidusis'
                                                                                                                cityid=$v.location_city
                                                                                                                streetid=$v.location_street
                                                                                                                building_num=$v.location_house
                                                                                                        }
												</td>
											</tr>
											{break}
										{/if}
									{/foreach}

									{foreach $customerinfo.addresses as $v}
										{if $v.location_address_type != $smarty.const.BILLING_ADDRESS && $v.location_address_type != $smarty.const.POSTAL_ADDRESS}
											<tr>
												{if $v.location_address_type == $smarty.const.DEFAULT_LOCATION_ADDRESS}
													{$icon  = 'lms-ui-icon-default-customer-location fa-fw'}
													{$title = trans('default location address')}
												{else}
													{$icon  = 'lms-ui-icon-customer-location fa-fw'}
													{$title = trans('location/recipient address')}
												{/if}

												<td>
													{icon class=$icon tip=$title}
												</td>
												<td>
													<span title="{$title}">
														{if $v.location_name}{$v.location_name|escape}, {/if}
														{if !empty($v.location_ten)}{trans("TEN")} {$v.location_ten|escape}, {/if}
														{if $v.teryt}
															{if $show_numeric_identifiers}
																{capture assign="teryt_comment"}{strip}
																	{if empty($v.location_street)}
																		{t a=$v.terc b=$v.simc}TERC: $a, SIMC: $b{/t}
																	{else}
																		{t a=$v.terc b=$v.simc c=$v.ulic}TERC: $a, SIMC: $b, ULIC: $c{/t}
																	{/if}
																{/strip}{/capture}
																{t a=$v.location|default:""|escape b=$teryt_comment}$a ($b){/t}
															{else}
																{t a=$v.location|default:""|escape}$a (TERYT){/t}
															{/if}
														{else}
															{$v.location|default:""|escape}
														{/if}
													</span>
													{$gps_location_url_replaced = str_replace(
														array(
															'%location',
															'%state',
															'%city',
															'%zip',
															'%street',
															'%full_street',
															'%full_reversed_street',
															'%short_street',
															'%house'
														),
														array(
															$v.location,
															$v.location_state_name,
															$v.location_city_name,
															$v.location_zip,
															$v.location_street_name,
															$v.location_full_street_name,
															$v.location_full_reversed_street_name,
															$v.location_short_street_name,
															$v.location_house
														),
														$gps_location_url
													)}
													{button
														type="link"
														tip="Show on map"
														icon="location"
														href=$gps_location_url_replaced|escape
													}
													{show_on_map_button
														type="default"
														cityid=$v.location_city
														streetid=$v.location_street
														building_num=$v.location_house
													}
													{show_on_map_button
														type="netstork"
														cityid=$v.location_city
														streetid=$v.location_street
														building_num=$v.location_house
													}
													{show_on_map_button
														type="geoportal"
														cityid=$v.location_city
														streetid=$v.location_street
														building_num=$v.location_house
													}
                                                                                                        {show_on_map_button
                                                                                                                type='sidusis'
                                                                                                                cityid=$v.location_city
                                                                                                                streetid=$v.location_street
                                                                                                                building_num=$v.location_house
                                                                                                        }
												</td>
											</tr>
										{/if}
									{/foreach}

									{foreach $_CUSTOMERCONTACTTYPES as $type => $properties}
										{if isset($customerinfo[$type|cat:"s"])}
											<tr>
												<td></td>
												<td class="customer-contact">
													<fieldset style="width: auto;">
														<legend class="bold nobr">
															{icon class=$properties.ui.legend.icon}
															{$properties.ui.legend.text}
														</legend>
														<table>
															{foreach $customerinfo[$type|cat:"s"] as $contact}
															<tr{if ($contact.type & $smarty.const.CONTACT_DISABLED) == $smarty.const.CONTACT_DISABLED} class="blend"{/if}>
																<td class="customer-contact">
																	<div>
																		{if isset($properties.formatter)}
																			{$text = call_user_func($properties.formatter, $contact)}
																		{else}
																			{$text = $contact.contact|escape}
																		{/if}
																		{contact type=$contact.type content=$text text=$contact.contact clipboard_button=true qrcode_button=true}
																		{if $contact.typestr}[{$contact.typestr}]{/if}
																		{if $contact.name} ({$contact.name|trunescape:40}){/if}
																	</div>
																</td>
															</tr>
															{if $type == 'email' && !empty($contact.properties)}
																<tr>
																	<td class="customer-contact">
																		<div style="padding-left: 0.5em;">
																			{foreach $contact.properties as $property}
																				<span {tip text="Property name"}><strong>{$property.name}:</strong></span>
																				<span {tip text="Property value"}>{$property.value}</span><br>
																			{/foreach}
																		</div>
																	</td>
																</tr>
															{/if}
															{/foreach}
														</table>
													</fieldset>
												</td>
											</tr>
										{/if}
									{/foreach}
									{if $customerinfo.pin}
										<tr>
											<td>
												{if $customerinfo.secure_pin || $unsecure_pin_validity && $smarty.now - $customerinfo.pinlastchange > $unsecure_pin_validity}
													{icon name="customer-pin-code" tip="PIN"}
												{else}
													{icon name="customer-pin-code" class="lms-ui-button-clipboard" data_clipboard_text=$customerinfo.pin}
												{/if}
											</td>
											<td>
												{if $customerinfo.secure_pin}
													{trans("<!pin>(hashed)")}
												{else}
													{if $unsecure_pin_validity && $smarty.now - $customerinfo.pinlastchange > $unsecure_pin_validity}
														<span class="lms-ui-alert">
															<strong>{trans("<!pin>(expired)")}</strong>
														</span>
													{else}
														{if ConfigHelper::checkConfig('phpui.protect_passwords')}
															{button icon="clipboard" class="lms-ui-button-clipboard" label="Copy" data_clipboard_text=$customerinfo.pin}
														{else}
															{$customerinfo.pin}
														{/if}
													{/if}
												{/if}
											</td>
										</tr>
									{/if}

									{if $customerinfo.rbename != "" || $customerinfo.rbe}
										<tr>
											<td class="valign-top">
												{icon name="user-id-number"}
											</td>
											<td>
												<fieldset>
													<legend class="bold">
														{trans("Business register")}
													</legend>
													<table class="rbe-details">
														<tr>
															<td>
																{trans("Name")}
															</td>
															<td class="rbe-name">
																{if $customerinfo.rbename != ""}
																	<div class="lms-ui-multiline-box">
																		{$customerinfo.rbename|escape|replace:"\n":"<BR>"}
																	</div>
																	{icon name="copy" class="lms-ui-button-clipboard" data_clipboard_text=$customerinfo.rbename}
																{else}
																	—
																{/if}
															</td>
														</tr>
														<tr>
															<td>
																{trans("Number")}
															</td>
															<td>
																{if $customerinfo.rbe != ""}
																	{$customerinfo.rbe|escape}
																	{icon name="copy" class="lms-ui-button-clipboard" data_clipboard_text=$customerinfo.rbe}
																{else}
																	—
																{/if}
															</td>
														</tr>
													</table>
												</fieldset>
											</td>
										</tr>
									{/if}

									{if $customerinfo.bankaccount}
										<tr>
											<td>
												{icon name="account-number" class="lms-ui-button-clipboard" data_clipboard_text=$customerinfo.bankaccount}
											</td>
											<td class="nobr">
												{format_bankaccount($customerinfo.bankaccount)}
											</td>
										</tr>
									{/if}
									<tr class="customer-options">
										<td class="valign-top">
											{icon name="paytype"}
										</td>
										<td>
											<table id="payment-options">
												<tr>
													<td>
														{trans("Deadline")}
													</td>
													<td>
														{if $customerinfo.paytime == -1}
															{trans("default")}
														{else}
															{$customerinfo.paytime}&nbsp;{trans("days")}
														{/if}
													</td>
												</tr>
												<tr>
													<td>
														{trans("Payment type")}
													</td>
													<td>
														{assign var=paytype value=$customerinfo.paytype}
														{if isset($_PAYTYPES[$paytype])}
															{trans($_PAYTYPES[$paytype].label)}
														{else}
															{trans("default")}
														{/if}
													</td>
												</tr>
												{if $customerinfo.cutoffstop > $smarty.now}
													<tr>
														<td colspan="2">
															<span class="lms-ui-alert">
																{if $customerinfo.cutoffstop == intval(pow(2, 31) - 1)}
																	{trans("Cutoff suspended indefinitely")}
																{else}
																	{t a=$customerinfo.cutoffstop|date_format:"Y-m-d"}Cutoff suspended to $a{/t}
																{/if}
															</span>
														</td>
													</tr>
												{/if}
											</table>
										</td>
									</tr>
									<tr class="customer-options">
										<td class="valign-top">
											{icon name="consent"}
										</td>
										<td>
											<table cellpadding="2" class="lms-ui-separated-rows">
												<tr id="consent-caption">
													<td colspan="2">
														<strong>{trans("Consents")}</strong>
														{button type="link" icon="less" icon_class="consent-view-toggle-icon" id="consent-view-toggle-button"}
													</td>
												</tr>
												{block name="customerinfobox-options"}
													{$current_customer_consent_group_id = 0}
													{foreach $_CCONSENTS as $type => $consent}
														{if !is_array($consent)}
															{continue}
														{/if}
														{$customer_consent_group_id = Utils::findCustomerConsentGroupByCustomerConsent($type, $_CCONSENT_GROUPS)}
														{if $current_customer_consent_group_id && $current_customer_consent_group_id != $customer_consent_group_id || $current_customer_consent_group_id && $consent@last}
																		</table>
																	</fieldset>
																</td>
															</tr>
														{/if}
														{if $customer_consent_group_id && $customer_consent_group_id != $current_customer_consent_group_id}
															<tr class="consent-group-row consent-row">
																<td colspan="2">
																	<fieldset class="consent-group">
																		<legend>
																			<strong>{$_CCONSENT_GROUPS[$customer_consent_group_id].label}</strong>
																		</legend>
																		<table class="lms-ui-separated-rows">
														{/if}
														<tr class="consent-row">
															<td>
																{if $consent.type == 'selection' && isset($customerinfo.consents[$type]) && isset($consent.values[$customerinfo.consents[$type]].name)}
																	{t a=$consent.label b=$consent.values[$customerinfo.consents[$type]].label}<!billing-type>$a ($b){/t}
																{else}
																	{$consent.label}
																{/if}
															</td>
															<td class="text-right">
																{if isset($customerinfo.consents[$type])}
																	{if $consent.type == 'date'}
																		{$customerinfo.consents[$type]['cdate']|date_format:"Y-m-d"}
																	{else}
																		{if $consent.type != 'selection' || isset($consent.values[$customerinfo.consents[$type]].name)}
																			{icon name="checked"}
																		{else}
																			{icon name="empty"}
																		{/if}
																	{/if}
																{else}
																	{icon name="empty"}
																{/if}
															</td>
														</tr>
														{$current_customer_consent_group_id = $customer_consent_group_id}
													{/foreach}
												{/block}
											</table>
										</td>
									</tr>

									{/block}
								</table>
							</div>
							<div class="lmsbox-panel">
								<table>
									<colgroup>
										<col style="width: 1%;">
										<col style="width: 1%;">
										<col style="width: 98%;">
									</colgroup>
									{block name="customerinfobox-rightcolumn"}
									{if $customerinfo.info}
										<tr>
											<td>
												{icon name="optional-info"}
											</td>
											<td colspan="2">
												<table width="100%" cellpadding="5">
													<tr>
														<td class="limit-width">
															<div class="lms-ui-multiline-box lms-ui-autolinker">
																{$customerinfo.info|replace:"\n":"<br>"}
															</div>
														</td>
													</tr>
												</table>
											</td>
										</tr>
									{/if}
									{if $customerinfo.message}
										<tr>
											<td>
												{icon name="warning"}
											</td>
											<td colspan="2">
												<table width="100%" cellpadding="5">
													<tr>
														<td class="limit-width">
															<div class="lms-ui-multiline-box lms-ui-autolinker">
																{$customerinfo.message|replace:"\n":"<br>"}
															</div>
														</td>
													</tr>
												</table>
											</td>
										</tr>
									{/if}
									{if $customerinfo.notes}
										<tr>
											<td>
												{icon name="notes"}
											</td>
											<td colspan="2">
												<table width="100%" cellpadding="5">
													<tr>
														<td class="limit-width">
															<div class="lms-ui-multiline-box lms-ui-autolinker">
																{$customerinfo.notes|replace:"\n":"<br>"}
															</div>
														</td>
													</tr>
												</table>
											</td>
										</tr>
									{/if}
									{if $customerinfo.documentmemo}
										<tr>
											<td>
												{icon name="memo"}
											</td>
											<td colspan="2">
												<table width="100%" cellpadding="5">
													<tr>
														<td class="limit-width">
															<div class="lms-ui-multiline-box lms-ui-autolinker">
																{$customerinfo.documentmemo|replace:"\n":"<br>"}
															</div>
														</td>
													</tr>
												</table>
											</td>
										</tr>
									{/if}
									{if ConfigHelper::checkConfig('privileges.superuser') || !ConfigHelper::checkConfig('privileges.hide_finances')}
										<tr>
											<td>
												{icon name="money"}
											</td>
											<td>
												<strong>{trans("Balance")}</strong>
											</td>
											<td>
												{if $customerinfo.balance < 0}
													<div id="instant-payment-options">
														<span class="lms-ui-alert">
															{moneyf($customerinfo.balance)}
														</span>
														{if $instantpayment}
															<form name="instantpayment" id="instantpayment" method="POST" action="?m=balanceadd&id={$customerinfo.id}&receipt=1">
																<input type="hidden" name="instantpayment[customerid]" value="{$customerinfo.id}">
																<input type="hidden" name="instantpayment[value]" value="{$customerinfo.balance*-1}">
																<input type="hidden" name="instantpayment[type]" value="1">
																<input type="hidden" name="instantpayment[sourceid]" value="0">
																<input type="hidden" name="instantpayment[comment]" value="{trans("instant payment")}">
																{button icon="print" id="add-instantpayment" data_name="{$customerinfo.customername|escape:"javascript"|escape:"html"}"
																	label="instant payment"}
																<label>
																	<input type="checkbox" name="instantpayment[print]" value="1"
																		{if ConfigHelper::checkConfig('receipts.instant_payment_print')} checked{/if}>
																	{trans("print")}
																</label>
															</form>
														{/if}
													</div>
												{else}
													{$customerinfo.balance|default:"0"|money_format}
												{/if}
											</td>
										</tr>
										{if ConfigHelper::checkConfig('customers.show_due_balance', ConfigHelper::checkConfig('phpui.show_customer_due_balance', ConfigHelper::checkConfig('customers.show_expired_balance', ConfigHelper::checkConfig('phpui.show_customer_expired_balance'))))}
											<tr>
												<td>
													{icon name="money"}
												</td>
												<td>
													<strong>{trans("Balance excluding current receivables")}</strong>
												</td>
												<td>
													{if $customerinfo.expiredbalance < 0}
														<span class="lms-ui-alert">
															{$customerinfo.expiredbalance|default:"0"|money_format}
														</span>
													{else}
														{$customerinfo.expiredbalance|default:"0"|money_format}
													{/if}
												</td>
											</tr>
										{/if}
									{/if}
									<tr>
										<td>
											{icon name="lastloggedin"}
										</td>
										<td class="nobr">
											<strong>{trans("Last login")}<br>
												{trans("Last failed login")}</strong>
										</td>
										<td>
											{if isset($customerinfo.up_logins.lastlogindate) && $customerinfo.up_logins.lastlogindate}
												{$customerinfo.up_logins.lastlogindate|date_format:"Y-m-d H:i"}
												({$customerinfo.up_logins.lastloginip})
											{else}
												-
											{/if}
											<br>
											{if isset($customerinfo.up_logins.failedlogindate) && $customerinfo.up_logins.failedlogindate}
												{$customerinfo.up_logins.failedlogindate|date_format:"Y-m-d H:i"}
												({$customerinfo.up_logins.failedloginip})
											{else}
												-
											{/if}
										</td>
									</tr>
									<tr>
										<td>
											{icon name="modified-date"}
										</td>
										<td>
											<strong>{trans("Created")}<br>
												{trans("Modified")}</strong>
										</td>
										<td>
											{$customerinfo.createdby|escape}, {$customerinfo.creationdateh}
											<br>
											{if $customerinfo.moddate}
												{$customerinfo.modifiedby|escape}, {$customerinfo.moddateh}
											{else}
												-
											{/if}
										</td>
									</tr>
									{/block}
								</table>
							</div>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td colspan="2" class="lms-ui-box-buttons">
				<div class="customerinfo-button-panel">
					<div class="customerinfo-buttons">
						{block name="customerinfobox-buttons"}
							{if $customerinfo.deleted}
								{if ConfigHelper::checkPrivilege('customer_management')}
									{if ConfigHelper::checkPrivilege('permanent_customer_removal')}
										{button id="remove-button" icon="remove" label="Remove permanently"
											data_href="?m=customerdel&id={$customerinfo.id}&type=permanent"}
									{/if}
									{button id="restore-button" icon="restore" label="Restore"
										href="?m=customeredit&id={$customerinfo.id}&action=recover"}
								{/if}
							{else}
								{button type="link-button" id="rtsearch-button"
									class="{if $customerstats['tickets']['notresolved']}bold{/if}"
									icon="timetable"
									label="{trans("Tickets")}{if $customerstats['tickets']} ({$customerstats['tickets']['all']}{if $customerstats['tickets']['notresolved']} / {$customerstats['tickets']['notresolved']}{/if}){/if}"
									href="?m=rtsearch&id={$customerinfo.id}"}
								{button type="link-button" id="accounts-button" icon="customer"
									label="{trans("Accounts")} ({$customerstats['accounts']})"
									href="?m=accountlist&u={$customerinfo.id}"}
								{button type="link-button" id="domains-button" icon="network"
									label="{trans("Domains")} ({$customerstats['domains']})"
									href="?m=domainlist&c={$customerinfo.id}"}
								{button type="link-button" id="stats-button" icon="stats" label="Stats"
									href="?m=trafficprint&type=customertraffic&customer={$customerinfo.id}"}
								{if ConfigHelper::checkPrivilege('customer_management')}
									{button type="link-button" id="edit-button" icon="edit" label="Edit"
										href="?m=customeredit&id={$customerinfo.id}"}
									{if ConfigHelper::checkPrivilege('customer_removal')}
										{button id="delete-button" icon="delete" label="Delete"
											data_href="?m=customerdel&id={$customerinfo.id}"}
									{/if}
								{/if}
							{/if}
							{if $info_link}
								{button type="link-button" id="info-button" icon="info" label="Info"
									href="?m=customerinfo&id={$customerinfo.id}"}
							{/if}
						{/block}
					</div>
					{if !ConfigHelper::checkPrivilege('customer_sensitive_data_view', !$restrictive_sensitive_data_access) && !ConfigHelper::checkPrivilege('hide_customer_sensitive_data', !$restrictive_sensitive_data_access)}
						<div class="customerinfo-buttons">
							{button icon="sensitive-data" label="Show sensitive data" id="customer-sensitive-data-button"}
						</div>
					{/if}
				</div>
			</td>
		</tr>
	</tbody>
</table>
<script>

	{if $customerpanel}
		if (getCookie('customerpanel') == '1') {
			$('#customerpanel').show();
		}
	{/if}

	function consentViewToggle() {
		var iconElem = $('.consent-view-toggle-icon');
		iconElem.toggleClass('lms-ui-icon-less lms-ui-icon-more');
		var consentViewVisible = !iconElem.is('.lms-ui-icon-more');
		setStorageItem('consent-view-visible', consentViewVisible ? 1 : 0, 'local');
		iconElem.closest('.customer-options').find('.consent-row').toggle(consentViewVisible);
	}

	$(function() {
		{if ConfigHelper::checkPrivilege('customer_management')}
			$('#delete-button').click(function() {
				confirmDialog($t("Are you sure, you want to remove customer '$a' from database?\n\nIf that customer have some nodes, they will be also removed and data definitely lost!", "{$customerinfo.customername|escape}"), this).done(function() {
					location.href = $(this).attr('data-href');
				});
			});

			$('#remove-button').click(function() {
				confirmDialog($t("Do you want to permanently remove $a customer?", "{$customerinfo.customername|escape}"), this).done(function() {
					location.href = $(this).attr('data-href');
				});
			});
		{/if}

		$('#add-instantpayment').click(function() {
			var name = $(this).attr('data-name');
			confirmDialog($t("Are you sure, you want to make instant payment for customer '$a'?", name), this).done(function () {
				$('#instantpayment').submit();
			});
		});

		$('#customer-sensitive-data-button').click(function() {
			var btn = $(this);

			$.ajax({
				url: "?m={$layout.module}&api=1&id={$customerinfo.id}&action=get_sensitive_data",
				dataType: "json",
				success: function(data) {
					$('.customer-sensitive-data[data-type]').each(function() {
						var type = $(this).attr('data-type');
						if (data.hasOwnProperty(type)) {
							$(this).html(data[type]);
						}
					});
					$('.lms-ui-button-clipboard[data-type],#check-ssn-button').show();
					btn.prop('disabled', true);
				}
			});
		});

		$('.lms-ui-button-clipboard[data-type]').on('lms:clipboard:click', function() {
			return $('.customer-sensitive-data[data-type="' + $(this).attr('data-type') + '"]').text().trim();
		});

		$('#check-ssn-button').click(function() {
			var btn = $(this);
			var ssnElem = $(':not(.lms-ui-button-clipboard)[data-type="ssn"]');

			ssnElem.attr({
				"data-tooltip": null,
				title: null
			}).css({
				color: ''
			}).removeClass('lms-ui-error');

			btn.prop('disabled', true);

			$.ajax({
				url: '?m=customerssncheck&api=1&id={$customerinfo.id}&ssn=' + ssnElem.text().trim(),
				//url: '?m=customerssncheck&api=1&ssn=80103193344', // not reserved
				//url: '?m=customerssncheck&api=1&ssn=70030158839', // reserved
				dataType: "json",
				success: function(data) {
					if (data.hasOwnProperty('error')) {
						ssnElem.addClass('lms-ui-error').attr({
							title: data.error,
							"data-tooltip": null
						});
					} else if (data.errors.length) {
						ssnElem.addClass('lms-ui-error').attr({
							title: data.errors.join('<br>'),
							"data-tooltip": null
						});
					} else {
						if (data.reserved) {
							ssnElem.css('color', 'Sienna');
						} else {
							ssnElem.css('color', 'green');
						}
					}

					btn.prop('disabled', false);
				}

			});
		});

		$('#consent-view-toggle-button').click(consentViewToggle);
	});

	var consentViewVisible = getStorageItem('consent-view-visible', 'local');
	if (consentViewVisible) {
		consentViewVisible = parseInt(consentViewVisible);
		if (!consentViewVisible) {
			consentViewToggle();
		}
	}

</script>
