<?xml version="1.0" encoding="UTF-8"?>
<Report>
	<Title><var var="i18n::translate('Fact Sources')" /></Title>
	<Description>Prints a list of individuals and families with a specific source for facts or records</Description>

	<Input name="sid" lookup="SOUR" default="" type="text"><var var="i18n::translate('Find Source ID')" /></Input>
	<Input name="stype" type="select" default="facts" options="facts=>i18n::translate('facts')|records=>i18n::translate('records')"><var var="i18n::translate('Source type')" /></Input>
	<Input name="sortby" type="select" default="BIRT:DATE" options="NAME=>i18n::translate('Name')|BIRT:DATE=>i18n::translate('Date of birth')"><var var="i18n::translate('Sort by')" /></Input>
	<Input name="pageSize" type="select" default="A4" options="letter=>i18n::translate_c('paper size','Letter')|A3=>i18n::translate_c('paper size', 'A3')|A4=>i18n::translate_c('paper size','A4')|legal=>i18n::translate_c('paper size','Legal')"><var var="i18n::translate('Page size')" /></Input>
	<Input name="fonts" type="select" default="dejavusans" options="arialunicid0=>i18n::translate_c('font name', 'Arial')|dejavusans=>i18n::translate_c('font name', 'DejaVu')|helvetica=>i18n::translate_c('font name', 'Helvetica')"><var var="i18n::translate('Font')"/></Input>

	<!-- Header -->
	<Style name="header" font="$fonts" size="18" style="b" />
	<!-- Source Title -->
	<Style name="header2" font="$fonts" size="14" style="b" />
	<!-- Name of the List Type. INDI or FAM -->
	<Style name="listtype" font="$fonts" size="12" style="b" />
	<!-- Page numbers text -->
	<Style name="pagenum" font="$fonts" size="8" />
	<!-- Generated by style - required style name by the generator -->
	<Style name="genby" font="$fonts" size="8" />
	<!-- Date Text - CSS Style name -->
	<Style name="date" font="$fonts" size="8"/>
	<!-- Column list labels - CSS Style name -->
	<Style name="list_label" font="$fonts" size="9" style="b"/>
	<!-- List values - CSS Style name -->
	<Style name="list_value" font="$fonts" size="8"/>

	<SetVar name="nameindi" value="200" />
	<SetVar name="namefam" value="270" />
	<SetVar name="datebirth" value="120" />
	<SetVar name="fact" value="100" />
	<SetVar name="dateevent" value="110" />
	<SetVar name="vspace" value="5" />
	<SetVar name="printedsource" value="0" />
	<SetVar name="moresourcespaceindi" value="$nameindi + $datebirth" />
	<SetVar name="ignore" value="CHAN,CHIL,FAMC,FAMS,HUSB,NAME,NOTE,OBJE,SEX,SOUR,TITL,WIFE,_UID,_WT_OBJE_SORT"/>

	<Doc pageSize="$pageSize" orientation="landscape">
		<Header>
			<Cell align="center" newline="1" style="header"><var var="i18n::translate('Sources')" /></Cell>
			<Cell align="rightrtl" newline="1" style="pagenum"><var var="i18n::translate('Page')" /> <PageNum /> <var var="i18n::translate('of')" /> <TotalPages /></Cell>
			<!-- Source Title -->
			<Gedcom id="$sid">
				<Cell align="center" newline="1" style="header2"><GedcomValue tag="TITL" /></Cell>
			</Gedcom>
		</Header>

		<Body>
		<if condition="$stype=='facts'">
			<!-- List type -->
			<Cell align="center" newline="1" style="listtype"><var var="i18n::translate('Individuals')" /></Cell>
			<TextBox height="$vspace" newline="1" padding="0"/>

			<!-- Individual Name -->
			<SetVar name="fill" value="" />
			<if condition="$sortby=='NAME'">
				<SetVar name="fill" value="#AAAAAA" />
			</if>
			<Cell bgcolor="$fill" border="1" style="list_label" width="$nameindi"><var var="i18n::translate('Name')" /></Cell>
			<!-- Birth date -->
			<SetVar name="fill" value="" />
			<if condition="$sortby=='BIRT:DATE'">
				<SetVar name="fill" value="#AAAAAA" />
			</if>
			<Cell bgcolor="$fill" border="1" style="list_label" width="$datebirth"><var var="translate_fact('BIRT:DATE')" /></Cell>
			<!-- Name of the fact that contains the source -->
			<Cell border="1" style="list_label" width="$fact"><var var="i18n::translate('Event')" /></Cell>
			<!-- Date of the fact -->
			<Cell border="1" style="list_label" width="$dateevent"><var var="translate_fact('DATE')" /></Cell>
			<!-- Detailed source text -->
			<Cell border="1" newline="1" style="list_label"><var var="translate_fact('SOUR:PAGE')" /></Cell>
			<TextBox height="$vspace" newline="1" padding="0"/>

			<!-- Individual List -->
			<List list="individual" filter1=":SOUR CONTAINS @$sid@" sortby="$sortby">
				<SetVar name="moresource" value="0" />
				<SetVar name="printsource" value="0" />
				<!-- Printed List counter -->
				<SetVar name="printedsource" value="$printedsource + 1" />

				<!-- Individual Name -->
				<Cell style="list_value" width="$nameindi"><GetPersonName id="" /></Cell>
				<!-- Birth date -->
				<Cell style="list_value" width="$datebirth"><GedcomValue tag="BIRT:DATE" /></Cell>
				<Facts ignore="$ignore">
					<SetVar name="printfact" value="0" />
					<RepeatTag tag="@fact:SOUR">
						<Gedcom id="@SOUR">
							<if condition="@ID==$sid">
								<SetVar name="printfact" value="1" />
							</if>
						</Gedcom>
					</RepeatTag>

					<if condition="$printfact==1">
						<SetVar name="printsource" value="0" />
						<!-- Intend the fact line if more then one fact has source -->
						<if condition="$moresource==1">
							<Cell style="list_value" width="$moresourcespaceindi"> </Cell>
						</if>

						<!-- Name of the fact that contains the source -->
						<Cell style="list_value" width="$fact"><var var="@fact" /></Cell>
						<!-- Date of the fact -->
						<Cell style="list_value" width="$dateevent"><GedcomValue tag="@fact:DATE"/></Cell>
						<!-- Detailed source text -->
						<Cell style="list_value" newline="1">
							<RepeatTag tag="@fact:SOUR">
								<Gedcom id="@SOUR">
									<if condition="@ID==$sid">
										<SetVar name="printsource" value="1" />
									</if>
								</Gedcom>
								<if condition="$printsource==1">
									<GedcomValue tag="SOUR:PAGE"/>
									<if condition="@SOUR:DATA:TEXT!=''">
										<br /><GedcomValue tag="SOUR:DATA:TEXT"/>
									</if>
									<SetVar name="printsource" value="0" />
								</if>
							</RepeatTag>
						</Cell>
						<SetVar name="moresource" value="1" />
					</if>
					<SetVar name="printfact" value="0" />
				</Facts>
			</List>

			<!-- Print the list counter -->
			<if condition="$printedsource==0">
				<Cell align="rightrtl" newline="1" style="list_label"><var var="i18n::translate('Total individuals')"/>: 0</Cell>
			</if>
			<if condition="$printedsource > 0">
				<TextBox height="$vspace" newline="1" padding="0"/>
				<Cell align="rightrtl" newline="1" style="list_label"><var var="i18n::translate('Total individuals')"/>: <var var="printedsource" /></Cell>
			</if>

			<NewPage />
			<!-- Family List -->
			<TextBox height="$vspace" newline="1" padding="0"/>
			<Cell align="center" newline="1" style="listtype"><var var="i18n::translate('Families')" /></Cell>
			<TextBox height="$vspace" newline="1" padding="0"/>
			<!-- Family Name -->
			<Cell border="1" style="list_label" width="$namefam"><var var="i18n::translate('Name')" /></Cell>
			<!-- Name of the fact that contains the source -->
			<Cell border="1" style="list_label" width="$fact"><var var="i18n::translate('Event')" /></Cell>
			<!-- Date of the fact -->
			<Cell bgcolor="#AAAAAA" border="1" style="list_label" width="$dateevent"><var var="translate_fact('DATE')" /></Cell>
			<!-- Detailed source text -->
			<Cell border="1" newline="1" style="list_label"><var var="translate_fact('SOUR:PAGE')" /></Cell>

			<!-- Family List -->
			<TextBox height="$vspace" newline="1" padding="0"/>
			<SetVar name="printedsource" value="0" />
			<List list="family" filter1=":SOUR CONTAINS @$sid@" sortby="MARR:DATE">
				<SetVar name="moresource" value="0" />
				<SetVar name="printsource" value="0" />
				<!-- Printed List counter -->
				<SetVar name="printedsource" value="$printedsource + 1" />

				<!-- Family Name -->
				<Cell style="list_value" width="$namefam"><GetPersonName id="" /></Cell>
				<Facts ignore="$ignore">
					<SetVar name="printfact" value="0" />
					<RepeatTag tag="@fact:SOUR">
						<Gedcom id="@SOUR">
							<if condition="@ID==$sid">
								<SetVar name="printfact" value="1" />
							</if>
						</Gedcom>
					</RepeatTag>

					<if condition="$printfact==1">
						<SetVar name="printsource" value="0" />
						<!-- Intend the fact line if more then one fact has source -->
						<if condition="$moresource==1">
							<Cell style="list_value" width="$namefam"> </Cell>
						</if>

						<!-- Name of the fact that contains the source -->
						<Cell style="list_value" width="$fact">
							<if condition="@fact=='MARR'">
								<!-- Print different type of marriages -->
								<if condition="@MARR:TYPE==''">
									<var var="@fact" />
								</if>
								<if condition="@MARR:TYPE=='Religious'">
									<var var="i18n::translate('Religious marriage')" />
								</if>
								<if condition="@MARR:TYPE=='Civil'">
									<var var="i18n::translate('Civil marriage')" />
								</if>
								<if condition="@MARR:TYPE=='Partners'">
									<var var="i18n::translate('Registered partnership')" />
								</if>
							</if>
							<if condition="@fact!='MARR'">
								<var var="@fact" />
							</if>
						</Cell>

						<!-- Date of the fact -->
						<Cell style="list_value" width="$dateevent"><GedcomValue tag="@fact:DATE"/></Cell>
						<!-- Detailed source text -->
						<Cell style="list_value" newline="1">
							<RepeatTag tag="@fact:SOUR">
								<Gedcom id="@SOUR">
									<if condition="@ID==$sid">
										<SetVar name="printsource" value="1" />
									</if>
								</Gedcom>
								<if condition="$printsource==1">
									<GedcomValue tag="SOUR:PAGE"/>
									<if condition="@SOUR:DATA:TEXT!=''">
										<br /><GedcomValue tag="SOUR:DATA:TEXT"/>
									</if>
									<SetVar name="printsource" value="0" />
								</if>
							</RepeatTag>
						</Cell>
						<SetVar name="moresource" value="1" />
					</if>
					<SetVar name="printfact" value="0" />
				</Facts>
			</List>

			<!-- Print the list counter -->
			<if condition="$printedsource==0">
				<Cell align="rightrtl" newline="1" style="list_label"><var var="i18n::translate('Total families')"/>: 0</Cell>
			</if>
			<if condition="$printedsource > 0">
				<TextBox height="$vspace" newline="1" padding="0"/>
				<Cell align="rightrtl" newline="1" style="list_label"><var var="i18n::translate('Total families')"/>: <var var="printedsource" /></Cell>
			</if>
			<TextBox height="$vspace" newline="1" padding="0"/>
		</if>
		<if condition="$stype=='records'">
			<!-- List type -->
			<Cell align="center" newline="1" style="listtype"><var var="i18n::translate('Individuals')" /></Cell>
			<TextBox height="$vspace" newline="1" padding="0"/>

			<!-- Individual Name -->
			<SetVar name="fill" value="" />
			<if condition="$sortby=='NAME'">
				<SetVar name="fill" value="#AAAAAA" />
			</if>
			<Cell bgcolor="$fill" border="1" style="list_label" width="$nameindi"><var var="i18n::translate('Name')" /></Cell>
			<!-- Birth date -->
			<SetVar name="fill" value="" />
			<if condition="$sortby=='BIRT:DATE'">
				<SetVar name="fill" value="#AAAAAA" />
			</if>
			<Cell bgcolor="$fill" border="1" style="list_label" width="$fact"><var var="translate_fact('BIRT:DATE')" /></Cell>
			<Cell border="1" style="list_label" width="$dateevent"><var var="translate_fact('BIRT:PLAC')" /></Cell>
			<Cell border="1" style="list_label" width="$fact"><var var="translate_fact('DEAT:DATE')" /></Cell>
			<Cell border="1" style="list_label" width="$dateevent"><var var="translate_fact('DEAT:PLAC')" /></Cell>
			<!-- Detailed source text -->
			<Cell border="1" newline="1" style="list_label"><var var="translate_fact('SOUR:PAGE')" /></Cell>
			<TextBox height="$vspace" newline="1" padding="0"/>

			<!-- Individual List -->
			<List list="individual" filter1="SOUR CONTAINS @$sid@" sortby="$sortby">
				<!-- Printed List counter -->
				<SetVar name="printedsource" value="$printedsource + 1" />
				<!-- Individual Name -->
				<Cell style="list_value" width="$nameindi"><GetPersonName id="" /></Cell>
				<!-- Birth date -->
				<Cell style="list_value" width="$dateevent"><GedcomValue tag="BIRT:DATE" /></Cell>
				<!-- Birth place -->
				<Cell style="list_value" width="$fact"><GedcomValue tag="BIRT:PLAC" /></Cell>
				<!-- Death date -->
				<Cell style="list_value" width="$dateevent"><GedcomValue tag="DEAT:DATE" /></Cell>
				<!-- Death place -->
				<Cell style="list_value" width="$fact"><GedcomValue tag="DEAT:PLAC" /></Cell>
				<!-- Detailed source text -->
				<Cell style="list_value" newline="1">
					<GedcomValue tag="SOUR:PAGE"/>
					<if condition="@SOUR:DATA:TEXT!=''">
						<br /><GedcomValue tag="SOUR:DATA:TEXT"/>
					</if>
				</Cell>	
			</List>

			<!-- Print the list counter -->
			<if condition="$printedsource==0">
				<Cell align="rightrtl" newline="1" style="list_label"><var var="i18n::translate('Total individuals')"/>: 0</Cell>
			</if>
			<if condition="$printedsource > 0">
				<TextBox height="$vspace" newline="1" padding="0"/>
				<Cell align="rightrtl" newline="1" style="list_label"><var var="i18n::translate('Total individuals')"/>: <var var="printedsource" /></Cell>
			</if>
			<NewPage />
			<!-- Family List -->
			<TextBox height="$vspace" newline="1" padding="0"/>
			<Cell align="center" newline="1" style="listtype"><var var="i18n::translate('Families')" /></Cell>
			<TextBox height="$vspace" newline="1" padding="0"/>
			<!-- Family Name -->
			<Cell border="1" style="list_label" width="$namefam"><var var="i18n::translate('Name')" /></Cell>
			<!-- Name of the fact that contains the source -->
			<Cell bgcolor="#AAAAAA" border="1" style="list_label" width="$dateevent"><var var="translate_fact('MARR:DATE')" /></Cell>
			<!-- Date of the fact -->
			<Cell border="1" style="list_label" width="$fact"><var var="translate_fact('MARR:PLAC')" /></Cell>
			<!-- Detailed source text -->
			<Cell border="1" newline="1" style="list_label"><var var="translate_fact('SOUR:PAGE')" /></Cell>

			<!-- Family List -->
			<TextBox height="$vspace" newline="1" padding="0"/>
			<SetVar name="printedsource" value="0" />
			<List list="family" filter1="SOUR CONTAINS @$sid@" sortby="MARR:DATE">
				<SetVar name="printsource" value="0" />
				<!-- Printed List counter -->
				<SetVar name="printedsource" value="$printedsource + 1" />

				<!-- Family Name -->
				<Cell style="list_value" width="$namefam"><GetPersonName id="" /></Cell>
				<!-- Date of the fact -->
				<Cell style="list_value" width="$dateevent"><GedcomValue tag="MARR:DATE"/></Cell>
				<!-- Place of the fact -->
				<Cell style="list_value" width="$fact"><GedcomValue tag="MARR:PLAC"/></Cell>
				<!-- Detailed source text -->
				<Cell style="list_value" newline="1">
					<GedcomValue tag="SOUR:PAGE"/>
					<if condition="@SOUR:DATA:TEXT!=''">
						<br /><GedcomValue tag="SOUR:DATA:TEXT"/>
					</if>
				</Cell>
			</List>

			<!-- Print the list counter -->
			<if condition="$printedsource==0">
				<Cell align="rightrtl" newline="1" style="list_label"><var var="i18n::translate('Total families')"/>: 0</Cell>
			</if>
			<if condition="$printedsource > 0">
				<TextBox height="$vspace" newline="1" padding="0"/>
				<Cell align="rightrtl" newline="1" style="list_label"><var var="i18n::translate('Total families')"/>: <var var="printedsource" /></Cell>
			</if>
			<TextBox height="$vspace" newline="1" padding="0"/>
		</if>
		</Body>

		<Footer>
			<Cell align="rightrtl" newline="1" style="date"><Now/></Cell>
		</Footer>

	</Doc>
</Report>
