# DOCUMENTATION
# Note: Use the Code option in the editor to easily copy and paste with formatting.
<p>
    Renders every Form or Form Builder step in a workflow as a two-column summary table. For each form, it shows Person Entry information (and spouse information, if enabled) limited to the fields configured as Optional or Required, followed by every other visible field grouped under its Action Form Section. Any Optional field left blank shows "No Answer" instead of an empty cell. A `format` parameter switches between an email-safe layout and a print-friendly PDF layout.
</p>
<p><strong>Examples:</strong></p>
<p>Get the workflow guid: <code>{% assign workflowGuid = Workflow.Guid %}</code></p>
<p>Inside Lava: <code>{[ webworkflowformsummary workflowguid:workflowGuid ]}</code></p>
<p>Lava-To-PDF Action: <code>{[ webworkflowformsummary workflowguid:workflowGuid format:'pdf' labelwidth:'40%' ]}</code></p>
<p>Color Changes: <code>{[ webworkflowformsummary workflowguid:workflowGuid labelbgcolor:'#eef2f7' linkcolor:'#1a5276' ]}</code></p>
<p><strong>Parameters:</strong></p>
<ul>
    <li>workflowguid (string, required) - The Workflow Guid to render. Pass `Workflow.Guid` from inside a workflow action, or the workflow's guid from any other Lava context.</li>
    <li>format (string, email) - 'email' or 'pdf'. Switches font size, padding, border weight, page-break behavior, and the profile-link default. |</li>
    <li>labelwidth (string, 35%) - Width of the left/label column.</li>
    <li>labelbgcolor (string, #f7f7f7) - Background color for label cells and section headings.</li>
    <li>linkcolor (string, #006dcc) - Link color for profile links (email mode only by default).</li>
    <li>addresstype (string, Home) - Address type shown for the Person Entry address row.</li>
    <li>noanswertext (string, No Answer) - Placeholder shown for a blank Optional field.</li>
    <li>showprofilelinks (string, auto) -'true', 'false', or 'auto'. 'auto' links names in email mode and shows plain text in PDF mode.</li>
    <li>showformheadings (string, true) - Whether each form's Activity Name / Action Name renders as a heading above its table. Turn off for a workflow with a single form.</li>
    <li>showformhtml (string, false) - Show each form's Header, Footer, and PreHtml/PostHtml.</li>
    <li>pdfmargin (string, 0.5in) - Padding on all sides of the output, pdf mode only.</li>
    <li>showpdftitle (string, true) - Show the workflow Name centered at the top, pdf mode only.</li>
</ul>
<p><strong>Notes:</strong>&nbsp;</p>
<ul>
    <li>A workflow will need a Persist Action prior to creating the PDF or email. Use the Immediately Persist option within the action.</li>
    <li>Enabled Lava Commands required on the shortcode: RockEntity</li>
    <li>Profile links use the `InternalApplicationRoot` global attribute and are staff-facing.</li>
    <li>If a workflow type has more than one Form / Form Builder action, all of them render, in the order they appear in the workflow (activity order, then action order).</li>
    <li>Header, Footer, and every PreHtml/PostHtml value pass through Rock's `RunLava` filter, so an admin who put merge fields or attribute lookups into one of those fields gets the resolved value, not the raw Lava text. If that content ever needs a Lava command beyond `RockEntity` (for example `Sql`), enable that command on the shortcode too.</li>
</ul>



# SHORTCODE MARKUP
# Copy into the Shortcode Markup Field
{% assign internalRoot = 'Global' | Attribute:'InternalApplicationRoot' %}
{% assign personFieldClass = 'Rock.Field.Types.PersonFieldType' %}

//- Resolve profile-link default from 'auto'
{% assign profileLinksOn = false %}
{% if showprofilelinks == 'true' %}
    {% assign profileLinksOn = true %}
{% elsif showprofilelinks == 'auto' and format != 'pdf' %}
    {% assign profileLinksOn = true %}
{% endif %}

//- Style profile: email vs pdf
{% if format == 'pdf' %}
    {% assign baseFontSize = '11pt' %}
    {% assign headingFontSize = '13pt' %}
    {% assign baseLineHeight = '1.5' %}
    {% assign cellPadding = '6pt 8pt' %}
    {% assign borderRule = '0.5pt solid #cccccc' %}
    {% assign rowBreak = 'page-break-inside:avoid;' %}
{% else %}
    {% assign baseFontSize = '14px' %}
    {% assign headingFontSize = '16px' %}
    {% assign baseLineHeight = '1.4' %}
    {% assign cellPadding = '8px 12px' %}
    {% assign borderRule = '1px solid #e0e0e0' %}
    {% assign rowBreak = '' %}
{% endif %}

{% assign labelStyle = 'width:' | Append:labelwidth | Append:'; padding:' | Append:cellPadding | Append:'; border:' | Append:borderRule | Append:'; background-color:' | Append:labelbgcolor | Append:'; font-weight:bold; vertical-align:top; font-family:Arial,Helvetica,sans-serif; font-size:' | Append:baseFontSize | Append:'; ' | Append:rowBreak %}
{% assign valueStyle = 'padding:' | Append:cellPadding | Append:'; border:' | Append:borderRule | Append:'; vertical-align:top; font-family:Arial,Helvetica,sans-serif; font-size:' | Append:baseFontSize | Append:'; line-height:' | Append:baseLineHeight | Append:'; ' | Append:rowBreak %}
{% assign sectionStyle = 'padding:10px 12px; font-weight:bold; font-family:Arial,Helvetica,sans-serif; font-size:' | Append:baseFontSize | Append:'; background-color:' | Append:labelbgcolor | Append:'; border-bottom:2px solid #cccccc; ' | Append:rowBreak %}
{% assign formHeadingStyle = 'font-family:Arial,Helvetica,sans-serif; font-size:' | Append:headingFontSize | Append:'; margin:0 0 8px 0; color:#111111;' %}
{% assign formHtmlStyle = 'font-family:Arial,Helvetica,sans-serif; font-size:' | Append:baseFontSize | Append:'; line-height:' | Append:baseLineHeight | Append:'; margin:0 0 10px 0;' %}
{% assign pdfTitleStyle = 'text-align:center; font-family:Arial,Helvetica,sans-serif; font-size:18pt; font-weight:bold; margin:0 0 20px 0; color:#111111;' %}

//- Resolve the workflow
{% assign wf = null %}
{% workflow where:'Guid == "{{ workflowguid }}"' securityenabled:'false' %}
  {% assign wf = workflowItems | First %}
{% endworkflow %}

{% if wf == null %}
  <!-- webworkflowformsummary: no workflow found for guid {{ workflowguid }} -->
{% else %}
    {% assign wfTypeId = wf.WorkflowTypeId %}
    {% assign formsFound = 0 %}
    
    <div style="{% if format == 'pdf' %}padding:{{ pdfmargin }};{% endif %}">
        {% if format == 'pdf' and showpdftitle == 'true' %}
            <h1 style="{{ pdfTitleStyle }}">{{ wf.WorkflowType.Name }}</h1>
        {% endif %}
    
        {% workflowtype where:'Id == {{ wfTypeId }}' securityenabled:'false' %}
            {% assign wt = workflowtypeItems | First %}
            {% if wt %}
                {% assign activityTypes = wt.ActivityTypes | Sort:'Order' %}
                {% for act in activityTypes %}
                    {% assign actionTypes = act.ActionTypes | Sort:'Order' %}
                    {% for at in actionTypes %}
                        {% if at.WorkflowFormId and at.WorkflowFormId > 0 %}
                            {% assign formsFound = formsFound | Plus:1 %}
        
                            //- Load this form's Person Entry configuration
                            {% assign form = null %}
                            {% workflowactionform where:'Id == {{ at.WorkflowFormId }}' securityenabled:'false' %}
                                {% assign form = workflowactionformItems | First %}
                            {% endworkflowactionform %}
        
                            {% if form %}
                                <div style="margin-bottom:28px;">
                                    {% if showformheadings == 'true' %}
                                        <h2 style="{{ formHeadingStyle }}">{{ at.Name }}</h2>
                                    {% endif %}
                                    
                                    {% if showformhtml == 'true' and form.Header and form.Header != '' %}
                                        <div style="{{ formHtmlStyle }}">{{ form.Header | RunLava }}</div>
                                    {% endif %}
  
                                    <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="width:100%; border-collapse:collapse;">
                                        <tbody>
                                            //- Person Entry section
                                            {% if form.AllowPersonEntry %}
                                                {% assign personKey = '' %}
                                                {% assign spouseKey = '' %}
                                                {% if form.PersonEntryPersonAttributeGuid and form.PersonEntryPersonAttributeGuid != '' %}
                                                    {% attribute where:'Guid == "{{ form.PersonEntryPersonAttributeGuid }}"' securityenabled:'false' %}
                                                      {% assign paItem = attributeItems | First %}
                                                      {% if paItem %}{% assign personKey = paItem.Key %}{% endif %}
                                                    {% endattribute %}
                                                {% endif %}
                                                {% if form.PersonEntrySpouseAttributeGuid and form.PersonEntrySpouseAttributeGuid != '' %}
                                                    {% attribute where:'Guid == "{{ form.PersonEntrySpouseAttributeGuid }}"' securityenabled:'false' %}
                                                        {% assign spItem = attributeItems | First %}
                                                        {% if spItem %}{% assign spouseKey = spItem.Key %}{% endif %}
                                                    {% endattribute %}
                                                {% endif %}
                                                {% if personKey != '' %}
                                                    {% assign peRaw = wf | Attribute:personKey,'RawValue' %}
                                                    {% assign pePerson = peRaw | PersonByAliasGuid %}
                                                    {% if pePerson != null and pePerson.Id != '' %}
                                            
                                                        {% if showformhtml == 'true' and form.PersonEntryPreHtml and form.PersonEntryPreHtml != '' %}
                                                            <tr><td colspan="2" style="padding:4px 0;">{{ form.PersonEntryPreHtml | RunLava }}</td></tr>
                                                        {% endif %}
                                            
                                                        //- Name is always captured by Person Entry
                                                        <tr>
                                                            <td valign="top" style="{{ labelStyle }}">Name</td>
                                                            <td valign="top" style="{{ valueStyle }}">
                                                                {% if profileLinksOn %}
                                                                    <a href="{{ internalRoot }}Person/{{ pePerson.Id }}" style="color:{{ linkcolor }}; text-decoration:none;">{{ pePerson.FullName }}</a>
                                                                {% else %}
                                                                    {{ pePerson.FullName }}
                                                                {% endif %}
                                                            </td>
                                                        </tr>
                                                        
                                                        /-
                                                            Entry options are an enum: Hidden(0) / Optional(1) / Required(2). Depending on
                                                            the engine it can render as a name or an int, so we test "not hidden" three ways.
                                                        -/
                                                        {% assign o = form.PersonEntryEmailEntryOption %}
                                                        {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                            <tr><td valign="top" style="{{ labelStyle }}">Email</td><td valign="top" style="{{ valueStyle }}">{{ pePerson.Email | Default:noanswertext }}</td></tr>
                                                        {% endif %}
                                                        {% assign o = form.PersonEntryMobilePhoneEntryOption %}
                                                        {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                            <tr><td valign="top" style="{{ labelStyle }}">Mobile Phone</td><td valign="top" style="{{ valueStyle }}">{{ pePerson | PhoneNumber:'Mobile' | Default:noanswertext }}</td></tr>
                                                        {% endif %}
                                                        {% assign o = form.PersonEntryBirthdateEntryOption %}
                                                        {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                            <tr><td valign="top" style="{{ labelStyle }}">Birth Date</td><td valign="top" style="{{ valueStyle }}">{{ pePerson.BirthDate | Date:'M/d/yyyy' | Default:noanswertext }}</td></tr>
                                                        {% endif %}
                                                        {% assign o = form.PersonEntryGenderEntryOption %}
                                                        {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                            <tr><td valign="top" style="{{ labelStyle }}">Gender</td><td valign="top" style="{{ valueStyle }}">{{ pePerson.Gender | Default:noanswertext }}</td></tr>
                                                        {% endif %}
                                                        {% assign o = form.PersonEntryMaritalStatusEntryOption %}
                                                        {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                            <tr><td valign="top" style="{{ labelStyle }}">Marital Status</td><td valign="top" style="{{ valueStyle }}">{{ pePerson.MaritalStatusValue.Value | Default:noanswertext }}</td></tr>
                                                        {% endif %}
                                                        {% assign o = form.PersonEntryRaceEntryOption %}
                                                        {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                            <tr><td valign="top" style="{{ labelStyle }}">Race</td><td valign="top" style="{{ valueStyle }}">{{ pePerson.RaceValue.Value | Default:noanswertext }}</td></tr>
                                                        {% endif %}
                                                        {% assign o = form.PersonEntryEthnicityEntryOption %}
                                                        {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                            <tr><td valign="top" style="{{ labelStyle }}">Ethnicity</td><td valign="top" style="{{ valueStyle }}">{{ pePerson.EthnicityValue.Value | Default:noanswertext }}</td></tr>
                                                        {% endif %}
                                                        {% assign o = form.PersonEntryAddressEntryOption %}
                                                        {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                            <tr><td valign="top" style="{{ labelStyle }}">Address</td><td valign="top" style="{{ valueStyle }}">{{ pePerson | Address:addresstype | Default:noanswertext }}</td></tr>
                                                        {% endif %}
                                                        {% if form.PersonEntryCampusIsVisible %}
                                                            {%- assign peCampus = pePerson | Campus -%}
                                                            <tr><td valign="top" style="{{ labelStyle }}">Campus</td><td valign="top" style="{{ valueStyle }}">{{ peCampus.Name | Default:noanswertext }}</td></tr>
                                                        {% endif %}
                                                        
                                                        /-
                                                            Spouse (if enabled): same Optional/Required fields, resolved for the
                                                            spouse person. 
                                                        -/
                                                        {% assign o = form.PersonEntrySpouseEntryOption %}
                                                        {% if spouseKey != '' and o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                            {% assign spRaw = wf | Attribute:spouseKey,'RawValue' %}
                                                            {% assign spPerson = spRaw | PersonByAliasGuid %}
                                                            {% assign spouseLabel = form.PersonEntrySpouseLabel | Default:'Spouse' %}
                                                            <tr>
                                                                <td valign="top" style="{{ labelStyle }}">{{ spouseLabel }} Name</td>
                                                                <td valign="top" style="{{ valueStyle }}">
                                                                    {% if spPerson != null and spPerson.Id != '' %}
                                                                        {% if profileLinksOn %}
                                                                            <a href="{{ internalRoot }}Person/{{ spPerson.Id }}" style="color:{{ linkcolor }}; text-decoration:none;">{{ spPerson.FullName }}</a>
                                                                        {% else %}
                                                                            {{ spPerson.FullName }}
                                                                        {% endif %}
                                                                    {% else %}
                                                                        {{ noanswertext }}
                                                                    {% endif %}
                                                                </td>
                                                            </tr>
                                                            {% if spPerson != null and spPerson.Id != '' %}
                                                                {% assign o = form.PersonEntryEmailEntryOption %}
                                                                {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                                    <tr><td valign="top" style="{{ labelStyle }}">{{ spouseLabel }} Email</td><td valign="top" style="{{ valueStyle }}">{{ spPerson.Email | Default:noanswertext }}</td></tr>
                                                                {% endif %}
                                                                {% assign o = form.PersonEntryMobilePhoneEntryOption %}
                                                                {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                                    <tr><td valign="top" style="{{ labelStyle }}">{{ spouseLabel }} Mobile Phone</td><td valign="top" style="{{ valueStyle }}">{{ spPerson | PhoneNumber:'Mobile' | Default:noanswertext }}</td></tr>
                                                                {% endif %}
                                                                {% assign o = form.PersonEntryBirthdateEntryOption %}
                                                                {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                                    <tr><td valign="top" style="{{ labelStyle }}">{{ spouseLabel }} Birth Date</td><td valign="top" style="{{ valueStyle }}">{{ spPerson.BirthDate | Date:'M/d/yyyy' | Default:noanswertext }}</td></tr>
                                                                {% endif %}
                                                                {% assign o = form.PersonEntryGenderEntryOption %}
                                                                {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                                    <tr><td valign="top" style="{{ labelStyle }}">{{ spouseLabel }} Gender</td><td valign="top" style="{{ valueStyle }}">{{ spPerson.Gender | Default:noanswertext }}</td></tr>
                                                                {% endif %}
                                                                {% assign o = form.PersonEntryMaritalStatusEntryOption %}
                                                                {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                                    <tr><td valign="top" style="{{ labelStyle }}">{{ spouseLabel }} Marital Status</td><td valign="top" style="{{ valueStyle }}">{{ spPerson.MaritalStatusValue.Value | Default:noanswertext }}</td></tr>
                                                                {% endif %}
                                                                {% assign o = form.PersonEntryRaceEntryOption %}
                                                                {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                                    <tr><td valign="top" style="{{ labelStyle }}">{{ spouseLabel }} Race</td><td valign="top" style="{{ valueStyle }}">{{ spPerson.RaceValue.Value | Default:noanswertext }}</td></tr>
                                                                {% endif %}
                                                                {% assign o = form.PersonEntryEthnicityEntryOption %}
                                                                {% if o != 'Hide' and o != 'Hidden' and o != 0 %}
                                                                    <tr><td valign="top" style="{{ labelStyle }}">{{ spouseLabel }} Ethnicity</td><td valign="top" style="{{ valueStyle }}">{{ spPerson.EthnicityValue.Value | Default:noanswertext }}</td></tr>
                                                                {% endif %}
                                                            {% endif %}
                                                        {% endif %}
                                                        
                                                        {% if showformhtml == 'true' and form.PersonEntryPostHtml and form.PersonEntryPostHtml != '' %}
                                                            <tr><td colspan="2" style="padding:4px 0;">{{ form.PersonEntryPostHtml | RunLava }}</td></tr>
                                                        {% endif %}
                                                    {% endif %}
                                                {% endif %}
                                            {% endif %}
                                            
                                            //- Load Action Form Sections for this form (for grouping headings)
                                            {% assign sections = '' %}
                                            {% workflowactionformsection where:'WorkflowActionFormId == {{ at.WorkflowFormId }}' sort:'Order' securityenabled:'false' %}
                                                {% assign sections = workflowactionformsectionItems %}
                                            {% endworkflowactionformsection %}
                                            
                                            //- Additional form fields: visible, ordered, grouped by section
                                            {% assign lastSectionId = -1 %}
                                            
                                            {% workflowactionformattribute where:'WorkflowActionFormId == {{ at.WorkflowFormId }} && IsVisible == true' sort:'Order' securityenabled:'false' %}
                                                {%- for wafa in workflowactionformattributeItems -%}
        
                                                    {% assign thisSectionId = -1 %}
                                                    {% if wafa.ActionFormSectionId and wafa.ActionFormSectionId != '' %}
                                                        {% assign thisSectionId = wafa.ActionFormSectionId %}
                                                    {% endif %}
                                            
                                                    {% if thisSectionId != lastSectionId %}
                                                        {% assign lastSectionId = thisSectionId %}
                                                        {% if thisSectionId != -1 %}
                                                            {% assign sec = sections | Where:'Id',thisSectionId | First %}
                                                            {% if sec %}
                                                                <tr><td colspan="2" style="{{ sectionStyle }}">
                                                                    {{ sec.Title }}{% if sec.Description and sec.Description != '' %}<div style="font-weight:normal; font-size:0.85em; margin-top:2px;">{{ sec.Description }}</div>{% endif %}
                                                                </td></tr>
                                                            {% endif %}
                                                        {% endif %}
                                                    {% endif %}
                                            
                                                    {% if showformhtml == 'true' and wafa.PreHtml and wafa.PreHtml != '' %}
                                                        <tr><td colspan="2" style="padding:4px 0;">{{ wafa.PreHtml | RunLava }}</td></tr>
                                                    {% endif %}
                                            
                                                    {% assign aKey = wafa.Attribute.Key %}
                                                    <tr>
                                                        <td valign="top" style="{{ labelStyle }}">{{ wafa.Attribute.Name }}</td>
                                                        <td valign="top" style="{{ valueStyle }}">
                                                            {% if wafa.Attribute.FieldType.Class == personFieldClass %}
                                                                {% assign raw = wf | Attribute:aKey,'RawValue' %}
                                                                {% assign fieldPerson = raw | PersonByAliasGuid %}
                                                                {% if fieldPerson != null and fieldPerson.Id != '' %}
                                                                    {% if profileLinksOn %}
                                                                      <a href="{{ internalRoot }}Person/{{ fieldPerson.Id }}" style="color:{{ linkcolor }}; text-decoration:none;">{{ fieldPerson.FullName }}</a>
                                                                    {% else %}
                                                                      {{ fieldPerson.FullName }}
                                                                    {% endif %}
                                                                {% else %}
                                                                    {{ noanswertext }}
                                                                {% endif %}
                                                            {% else %}
                                                                {% assign fieldVal = wf | Attribute:aKey %}
                                                                {% if wafa.IsRequired %}
                                                                    {{ fieldVal }}
                                                                {% else %}
                                                                    {{ fieldVal | Default:noanswertext }}
                                                                {% endif %}
                                                            {% endif %}
                                                        </td>
                                                    </tr>
                                            
                                                    {% if showformhtml == 'true' and wafa.PostHtml and wafa.PostHtml != '' %}
                                                      <tr><td colspan="2" style="padding:4px 0;">{{ wafa.PostHtml | RunLava }}</td></tr>
                                                    {% endif %}
                                            
                                                {% endfor %}
                                            {% endworkflowactionformattribute %}
                                        </tbody>
                                    </table>
                                    
                                    {% if showformhtml == 'true' and form.Footer and form.Footer != '' %}
                                        <div style="{{ formHtmlStyle }} margin-top:10px;">{{ form.Footer | RunLava }}</div>
                                    {% endif %}
                                </div>
                            {% endif %}
                        {% endif %}
                    {% endfor %}
                {% endfor %}
            {% endif %}
        {% endworkflowtype %}
    </div>
    
    {% if formsFound == 0 %}
        <!-- webworkflowformsummary: workflow type {{ wfTypeId }} has no Form or Form Builder actions -->
    {% endif %}

{% endif %}