{% extends "admin/base_site.html" %}

{% block title %}Send emails to communication recipients | By ReportLab for Air Seychelles{% endblock %}

{% block breadcrumbs %}
<div class="breadcrumbs"><a href="/admin/">Home</a>
&rsaquo; <a href="/admin/crm/">Crm</a>
&rsaquo; <a href="/admin/crm/communication/">Communication</a>
&rsaquo; Send emails</div>
{% endblock %}

{% block content %}
<h1>Send emails to communication recipients</h1>

{% ifequal step 1 %}
    <p>
    Here are the details of the email you are about to send. Once you have checked the all the content is correct, click 'Next'. If you need to make changes to the email, use the 'Edit' button and come back here afterwards.
    </p>

    <form action="." method="get">
        <table>
            <tr><th>Subject:</th><td>{{communication.subject}}</td></tr>
            <tr><th>Message HTML:</th><td>
{{communication.message_html|truncatewords:20}}
<br/>
<a href="#" onclick="javascript:window.open('/admin/crm/preview_communication/{{communication.id}}/','communication_preview','menubar=no,width=600,height=600,toolbar=no,scrollbars=yes');">Preview</a>
            </td></tr>
            <tr><th>Message Plain:</th><td>{{communication.message_plain|truncatewords:20}}</td></tr>
            <tr><th>Select tag:</th><td><select name="tag_id">
            {% for tag in tags %}
                <option value="{{tag.id}}">{{tag.id}}</option>
            {% endfor %}
            </select>
            <p class="help">You must have assigned a tag to all the leads you wish to include in an email.</p>
            </td></tr>
            <tr><th>Only send to leads that have never been emailed by this system before:</th><td><input type="checkbox" name="ignore_previously_emailed"/></td></tr>
            <tr><th>Only send to leads that have not received an email with this subject before:</th><td><input type="checkbox" name="ignore_previously_emailed_with_same_subject" checked/></td></tr>
        </table>

        <input type="hidden" name="id" value="{{id}}"/>

        <div class="submit-row">
            <input type="submit" name="confirm" value="Next" class="default"/>
        </div>
    </form>
{% endifequal %}

{% ifequal step 2 %}
    {% if communication_warnings %}
        <div style="border: 1px solid #f00; padding: 0 10px; color: #f00; margin-bottom: 20px">
            <p><strong>You have the following errors with your email content:</strong></p>
            <ul>
            {% for warning in communication_warnings %}
                <li>{{warning}}</li>
            {% endfor %}
            </ul>
        </div>
    {% endif %}

    {% if lead_count %}
    <p>
    You are about to add approximately {{lead_count}} lead{{lead_count|pluralize}} to the email queue. If you chose to only send to leads you havn't emailed before, there will actually be less than this number of emails sent. If you are sure you want to procede and send these emails, <strong>please carefully press the 'Send' button once</strong>.
    </p>

    <form action="." method="get">
        <input type="hidden" name="id" value="{{id}}"/>
        <input type="hidden" name="tag_id" value="{{tag_id}}"/>
        <input type="hidden" name="ignore_previously_emailed" value="{{ignore_previously_emailed}}"/>
        <input type="hidden" name="ignore_previously_emailed_with_same_subject" value="{{ignore_previously_emailed_with_same_subject}}"/>
        <div class="submit-row">
            <input type="submit" name="send" value="Send" class="default"/>
        </div>
    </form>
    {% else %}
    <p>Error: No leads!</p>
    {% endif %}
{% endifequal %}

{% endblock %}
