<?php
//VARIABLES////////////////////////////////////////////////////////////////////
$signature_templates = '';
$worksteep_task = '';
$end_point = $dominio . '/api/avanws.php';
//FIRMAS///////////////////////////////////////////////////////////////////////
foreach ($datos_firma->firmantes as &$valor) {
    //TEMPLATES
    $signature_templates .= '
    <sig id="FIRMA'.$valor->orden.'">
        <positionPage>'.$valor->pag_firma.'</positionPage>
        <DocRefNumber>1</DocRefNumber>
        <positionX>'.$valor->coord_x.'</positionX>
        <positionY>'.$valor->coord_y.'</positionY>
        <width>200</width>
        <height>50</height>
        <param name="enabled">1</param>
        <param name="completed">0</param>
        <param name="bio">0</param>
        <param name="req">1</param>
        <param name="reason">'.$valor->nombre.'</param>
        <param name="location">Madrid</param>
        <param name="positioning">onPage</param>
		<param name="allowedCapturingMethods">Draw2Sign</param>
		<param name="sigType">Picture</param>
		<param name="text0">'.$valor->nombre.'</param>
		<param name="allowedCapturingMethods">TransactionCode</param>
		<!-- SMS -->
		<AllowedSignatureTypes>
			<sigType id="cd944482-8785-4fc4-b866-64b7540acc1b" type="TransactionCode" preferred="false">
				<trModType>TransactionCodeSenderPlugin</trModType>
				<trValidityInSeconds>60</trValidityInSeconds>
				<ly>simpleTransactionCode</ly>
				<positioning>onPage</positioning>
				<phonenumber>'.$valor->telefono.'</phonenumber>
				<trConfId>Trans1</trConfId>
				<uid/>
				<iid/>
				<trModTypeId/>
			</sigType>
		</AllowedSignatureTypes>
	</sig>
    ';
    //TASK
    $worksteep_task .= '
        <Task enabled="1" completed="0" required="1" id="FIRMA'.$valor->orden.'" displayName="'.$valor->nombre.' '.PREF_LIT_FIRMANTE.'" DocRefNumber="1" type="SignField" internalAllConcernedDocRefNumbersList="1" allRequiredFieldsFilledOnWorkstepCreation="0" />
    ';
}
//CONFIG WORKSTEEP/////////////////////////////////////////////////////////////
$xml_config_workstep = '
<workstepConfiguration skipThirdPartyChecks="0">
	<WorkstepLabel />
	<SmallTextZoomFactorPercent>100</SmallTextZoomFactorPercent>
	<WorkstepTimeToLiveInMinutes>1000</WorkstepTimeToLiveInMinutes>
	<FinishAction>
    <ServerAction callSynchronous="0">www.google.es</ServerAction>
    <ClientAction clientName="SIGNificant WSI" closeApp="1" RemoveDocumentFromRecentDocumentList="0" CallClientActionOnlyAfterSuccessfulSync="1">www.google.es</ClientAction>
  </FinishAction>
	<signatureTemplate>
		<version>1.2.0.2</version>
		<positionUnits>PdfUnits</positionUnits>
		<positionReferenceCorner>Lower_Right</positionReferenceCorner>
		'.$signature_templates.'
	</signatureTemplate>
	<!--Agreement about doing electronic business-->
	<Agreements></Agreements>
	<Policy version="1.1.0.0">
		<GeneralPolicies>
			<AllowSaveDocument>1</AllowSaveDocument>
			<AllowSaveAuditTrail>1</AllowSaveAuditTrail>
			<AllowRotatingPages>0</AllowRotatingPages>
			<AllowAppendFileToWorkstep>0</AllowAppendFileToWorkstep>
			<AllowAppendTasksToWorkstep>0</AllowAppendTasksToWorkstep>
			<AllowEmailDocument>0</AllowEmailDocument>
			<AllowPrintDocument>0</AllowPrintDocument>
			<AllowFinishWorkstep>1</AllowFinishWorkstep>
			<AllowRejectWorkstep>1</AllowRejectWorkstep>
			<AllowRejectWorkstepDelegation>1</AllowRejectWorkstepDelegation>
			<AllowUndoLastAction>0</AllowUndoLastAction>
			<AllowColorizePdfForms>0</AllowColorizePdfForms>
			<AllowReloadOfFinishedWorkstep>1</AllowReloadOfFinishedWorkstep>
			<AllowAdhocPdfAttachments>0</AllowAdhocPdfAttachments>
			<AllowAdhocSignatures>0</AllowAdhocSignatures>
			<AllowAdhocStampings>0</AllowAdhocStampings>
			<AllowAdhocFreeHandAnnotations>0</AllowAdhocFreeHandAnnotations>
			<AllowAdhocTypewriterAnnotations>0</AllowAdhocTypewriterAnnotations>
			<AllowAdhocPictureAnnotations>0</AllowAdhocPictureAnnotations>
			<AllowAdhocPdfPageAppending>0</AllowAdhocPdfPageAppending>
		</GeneralPolicies>
		<WorkstepTasks SequenceMode="NoSequenceEnforced">
			'.$worksteep_task.'
		</WorkstepTasks>
		<AdhocPolicies>
			<AllowModificationsAfterSignature>0</AllowModificationsAfterSignature>
		</AdhocPolicies>
	</Policy>
	<signaturePluginConfiguration>
		<PdfSignatureProperties_V1>
			<PdfAConformant>1</PdfAConformant>
			<PAdESPart4Compliant>1</PAdESPart4Compliant>
			<IncludeSigningCertificateChain>1</IncludeSigningCertificateChain>
      <SigningCertificateRevocationInformationIncludeMode>DoNotInclude</SigningCertificateRevocationInformationIncludeMode>
			<SignatureTimestampData>
				<Password />
				<SignatureHashAlgorithm></SignatureHashAlgorithm>
				<Uri></Uri>
				<UserName />
			</SignatureTimestampData>
		</PdfSignatureProperties_V1>
		<PdfSignatureCryptographicData_V1>
			<SignatureHashAlgorithm>Sha256</SignatureHashAlgorithm>
			<SigningCertificateDescriptor>
				<Identifier>14527a6bcfa8b4d7d0183fca6b735b1c246d14ae</Identifier>
				<Type>Sha1Thumbprint</Type>
				<Csp>Default</Csp>
			</SigningCertificateDescriptor>
		</PdfSignatureCryptographicData_V1>
	</signaturePluginConfiguration>
	<AuditingToolsConfiguration WriteAuditTrail="1">
		<NotificationConfiguration>
			  <NotificationEventsToSend>
					<NotificationEvent>WorkstepCreated</NotificationEvent>
					<NotificationEvent>WorkstepFinished</NotificationEvent>
					<NotificationEvent>WorkstepRejected</NotificationEvent>
					<NotificationEvent>SignWorkstepDocument</NotificationEvent>
			 </NotificationEventsToSend>
			<NotificationUrl>http://localhost:81/Notification/api/v1/Notification?WorkstepId=##WorkstepId##&amp;EventType=##EventType##&amp;Source=##Source##&amp;Time=##Time##&amp;Description=##Description##&amp;EndPoint='.$end_point.'</NotificationUrl>
		</NotificationConfiguration>
	</AuditingToolsConfiguration>
	<!-- SMS -->
	<TransactionCodeConfigurations>
		<TransactionCodeConfiguration trConfId="">
			<Message>Please sign the document with the transactionId {tId} with the code: {Token}</Message>
			<hashAlgorithmIdentifier>Sha256</hashAlgorithmIdentifier>
		</TransactionCodeConfiguration>
		<TransactionCodeConfiguration trConfId="Trans1">
			<Message>Please accept the transactionId {tId} with the code: {Token}</Message>
			<hashAlgorithmIdentifier>Sha256</hashAlgorithmIdentifier>
		</TransactionCodeConfiguration>
		<TransactionCodeConfiguration trConfId="IdentityServerMail">
			<Subject>Mensaje para el Código de Transacción</Subject>
			<FromAddress>signanywhere@dealerbest.com</FromAddress>
			<TextBody> Bienvid@ a Papel Cero! Para aceptar el trámite relacionado con tu vehículo, acepta el id de transacción {tId} con el código: {Token}</TextBody>
			<HtmlBody>
        &lt;head&gt;
          &lt;title&gt;Tu Código de verificación&lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;
          &lt;h1&gt;Tu Código de verificación&lt;/h1&gt;&lt;br/&gt;
          &lt;h2&gt;Transacción: {tId}&lt;/h2&gt;Código PIN: {Token}
        &lt;/body&gt;
			</HtmlBody>
			<hashAlgorithmIdentifier>Sha256</hashAlgorithmIdentifier>
		</TransactionCodeConfiguration>
	</TransactionCodeConfigurations>
</workstepConfiguration>
';
?>