{% extends 'admin.twig' %}

{% set title %}{{ 'PrivacyManager_TeaserHeadline'|translate }}{% endset %}

{% block content %}
{% import 'macros.twig' as piwik %}
{% if isSuperUser %}
    <h2 piwik-enriched-headline
        help-url="http://piwik.org/docs/privacy/">{{ title }}</h2>
    <p>{{ 'PrivacyManager_Teaser'|translate('<a href="#anonymizeIPAnchor">',"</a>",'<a href="#deleteLogsAnchor">',"</a>",'<a href="#optOutAnchor">',"</a>")|raw }}
        {{'PrivacyManager_SeeAlsoOurOfficialGuidePrivacy'|translate('<a href="http://piwik.org/privacy/" rel="noreferrer"  target="_blank">','</a>')|raw }}</p>

    <h2 id="anonymizeIPAnchor">{{ 'PrivacyManager_UseAnonymizeIp'|translate }}</h2>
    <form method="post" action="{{ {'action':'saveSettings', 'form':'formMaskLength', 'token_auth':token_auth} | urlRewriteWithParameters }}" id="formMaskLength">
        <div id="anonymizeIpSettings" class="form-group">
            <label>
                {{ 'PrivacyManager_UseAnonymizeIp'|translate }}
            </label>
            <div class="form-help">
                {{ 'PrivacyManager_AnonymizeIpInlineHelp'|translate }}
                {{ 'PrivacyManager_AnonymizeIpDescription'|translate }}
            </div>
            <label class="radio">
                <input id="anonymizeIPEnable-1" type="radio" name="anonymizeIPEnable" value="1" {% if anonymizeIP.enabled == '1' %}checked {% endif %}/>
                {{ 'General_Yes'|translate }}
            </label>
            <label class="radio">
                <input class="indented-radio-button" id="anonymizeIPEnable-0" type="radio" name="anonymizeIPEnable" value="0" {% if anonymizeIP.enabled == '0' %} checked {% endif %}/>
                {{ 'General_No'|translate }}
            </label>
            <input type="hidden" name="token_auth" value="{{ token_auth }}"/>
        </div>
        <div id="anonymizeIPenabled">
            <div class="form-group">
                <label>
                    {{ 'PrivacyManager_AnonymizeIpMaskLengtDescription'|translate }}<br/>
                </label>
                <div class="form-help">
                    {{ 'PrivacyManager_GeolocationAnonymizeIpNote'|translate }}
                </div>
                <label class="radio">
                    <input id="maskLength-1" type="radio" name="maskLength" value="1" {% if anonymizeIP.maskLength == '1' %} checked {% endif %}/>
                    {{ 'PrivacyManager_AnonymizeIpMaskLength'|translate("1","192.168.100.xxx") }}
                </label>
                <label class="radio">
                    <input id="maskLength-2" type="radio" name="maskLength" value="2" {% if anonymizeIP.maskLength == '2' %} checked {% endif %}/>
                    {{ 'PrivacyManager_AnonymizeIpMaskLength'|translate("2","192.168.xxx.xxx") }}
                    <span class="form-description">{{ 'General_Recommended'|translate }}</span>
                </label>
                <label class="radio">
                    <input id="maskLength-3" type="radio" name="maskLength" value="3" {% if anonymizeIP.maskLength == '3' %} checked {% endif %}/>
                    {{ 'PrivacyManager_AnonymizeIpMaskLength'|translate("3","192.xxx.xxx.xxx") }}
                </label>
            </div>
            <div class="form-group">
                <label>
                    {{ 'PrivacyManager_UseAnonymizedIpForVisitEnrichment'|translate }}<br/>
                </label>
                <div class="form-help">
                    {{ 'PrivacyManager_UseAnonymizedIpForVisitEnrichmentNote'|translate }}
                </div>
                <label class="radio">
                    <input id="useAnonymizedIpForVisitEnrichment-1" type="radio" name="useAnonymizedIpForVisitEnrichment" value="1" {% if anonymizeIP.useAnonymizedIpForVisitEnrichment == '1' %}checked {% endif %}/>
                    {{ 'General_Yes'|translate }}
                    <span class="form-description">{{ 'PrivacyManager_RecommendedForPrivacy'|translate }}</span>
                </label>
                <label class="radio">
                    <input id="useAnonymizedIpForVisitEnrichment-2" type="radio" name="useAnonymizedIpForVisitEnrichment" value="0" {% if anonymizeIP.useAnonymizedIpForVisitEnrichment == '0' %} checked {% endif %}/>
                    {{ 'General_No'|translate }}
                </label>
            </div>
        </div>

        <input type="hidden" name="nonce" value="{% if anonymizeIP.enabled %}{{ deactivateNonce }}{% else %}{{ activateNonce }}{% endif %}">
        <input type="submit" value="{{ 'General_Save'|translate }}" id="privacySettingsSubmit"/>
    </form>

    {% if isDataPurgeSettingsEnabled %}

        <div class="ui-confirm" id="confirmDeleteSettings">
            <h2 id="deleteLogsConfirm">{{ 'PrivacyManager_DeleteLogsConfirm'|translate }}</h2>

            <h2 id="deleteReportsConfirm">{{ 'PrivacyManager_DeleteReportsConfirm'|translate }}</h2>

            <h2 id="deleteBothConfirm">{{ 'PrivacyManager_DeleteBothConfirm'|translate }}</h2>
            <input role="yes" type="button" value="{{ 'General_Yes'|translate }}"/>
            <input role="no" type="button" value="{{ 'General_No'|translate }}"/>
        </div>
        <div class="ui-confirm" id="saveSettingsBeforePurge">
            <h2>{{ 'PrivacyManager_SaveSettingsBeforePurge'|translate }}</h2>
            <input role="yes" type="button" value="{{ 'General_Ok'|translate }}"/>
        </div>
        <div class="ui-confirm" id="confirmPurgeNow">
            <h2>{{ 'PrivacyManager_PurgeNowConfirm'|translate }}</h2>
            <input role="yes" type="button" value="{{ 'General_Yes'|translate }}"/>
            <input role="no" type="button" value="{{ 'General_No'|translate }}"/>
        </div>
        <h2 id="deleteLogsAnchor">{{ 'PrivacyManager_DeleteOldVisitorLogs'|translate }}</h2>
        <p>{{ 'PrivacyManager_DeleteDataDescription'|translate }} {{ 'PrivacyManager_DeleteDataDescription2'|translate }}</p>
        <form method="post" action="{{ {'action':'saveSettings','form':'formDeleteSettings','token_auth':token_auth} | urlRewriteWithParameters }}" id="formDeleteSettings">
            <div id="deleteLogSettingEnabled" class="form-group">
                <label>
                    {{ 'PrivacyManager_UseDeleteLog'|translate }}
                </label>
                <div class="form-help">
                    {{ 'PrivacyManager_DeleteLogInfo'|translate(deleteData.deleteTables)|raw }}
                    {% if not canDeleteLogActions %}
                        <br/>
                        <br/>
                        {{ 'PrivacyManager_CannotLockSoDeleteLogActions'|translate(dbUser) }}
                    {% endif %}
                </div>
                <label class="radio">
                    <input id="deleteEnable-1" type="radio" name="deleteEnable" value="1" {% if deleteData.config.delete_logs_enable == '1' %} checked {% endif %}/>
                    {{ 'General_Yes'|translate }}
                </label>
                <label class="radio">
                    <input class="indented-radio-button" id="deleteEnable-2" type="radio" name="deleteEnable" value="0"
                            {% if deleteData.config.delete_logs_enable == '0' %} checked {% endif %}/>
                    {{ 'General_No'|translate }}
                </label>
                <div class="clearfix"><br/></div>
                <div class="alert alert-warning" style="width: 40%;">
                    {{ 'PrivacyManager_DeleteLogDescription2'|translate|raw }}
                    <a href="http://piwik.org/faq/general/#faq_125" rel="noreferrer"  target="_blank">
                        {{ 'General_ClickHere'|translate }}
                    </a>
                </div>
            </div>

            <div id="deleteLogSettings" class="form-group">
                <label for="deleteOlderThan">
                    {{ 'PrivacyManager_DeleteLogsOlderThan'|translate }}
                </label>
                <div class="form-help">
                    {{ 'PrivacyManager_LeastDaysInput'|translate("1") }}
                </div>
                <div class="input-group">
                    <input type="text" id="deleteOlderThan" value="{{ deleteData.config.delete_logs_older_than }}" name="deleteOlderThan"/>
                    <span class="input-group-addon">{{ 'Intl_PeriodDays'|translate }}</span>
                </div>
            </div>

            <h2 id="deleteReportsAnchor" class="secondary">{{ 'PrivacyManager_DeleteOldArchivedReports'|translate }}</h2>

            <div id="deleteReportsSettingEnabled" class="form-group">
                <label>
                    {{ 'PrivacyManager_UseDeleteReports'|translate }}
                </label>
                <div class="form-help">
                    {{ 'PrivacyManager_DeleteReportsDetailedInfo'|translate('archive_numeric_*','archive_blob_*') }}
                </div>
                <label class="radio">
                    <input id="deleteReportsEnable-1" type="radio" name="deleteReportsEnable" value="1" {% if deleteData.config.delete_reports_enable == '1' %}checked="checked"{% endif %} />
                    {{ 'General_Yes'|translate }}
                </label>
                <label class="radio">
                    <input class="indented-radio-button" id="deleteReportsEnable-2" type="radio" name="deleteReportsEnable" value="0" {% if deleteData.config.delete_reports_enable == '0' %}checked="checked"{% endif %}/>
                    {{ 'General_No'|translate }}
                </label>
                <div class="clearfix"><br/></div>
                <div class="alert alert-warning" style="width: 40%;">
                    {% set deleteOldLogs %}{{ 'PrivacyManager_UseDeleteLog'|translate }}{% endset %}
                    {{ 'PrivacyManager_DeleteReportsInfo'|translate('<em>','</em>')|raw }}
                    <span id='deleteOldReportsMoreInfo'><br/><br/>
                        {{ 'PrivacyManager_DeleteReportsInfo2'|translate(deleteOldLogs) }}<br/><br/>
                        {{ 'PrivacyManager_DeleteReportsInfo3'|translate(deleteOldLogs) }}</span>
                </div>
            </div>

            <div id="deleteReportsSettings">
                <div class="form-group">
                    <label for="deleteReportsOlderThan">
                        {{ 'PrivacyManager_DeleteReportsOlderThan'|translate }}
                    </label>
                    <div class="form-help">
                        {{ 'PrivacyManager_LeastMonthsInput'|translate("3") }}
                    </div>
                    <div class="input-group">
                        <input type="text" id="deleteReportsOlderThan" value="{{ deleteData.config.delete_reports_older_than }}" name="deleteReportsOlderThan"/>
                        <span class="input-group-addon">{{ 'Intl_PeriodMonths'|translate }}</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="checkbox">
                        <input id="deleteReportsKeepBasic" type="checkbox" name="deleteReportsKeepBasic" value="1"
                               {% if deleteData.config.delete_reports_keep_basic_metrics %}checked="checked"{% endif %}>
                        {{ 'PrivacyManager_KeepBasicMetrics'|translate }}
                        <span class="form-description">{{ 'General_Recommended'|translate }}</span>
                    </label>
                </div>
                <h3>
                    {{ 'PrivacyManager_KeepDataFor'|translate }}
                </h3>
                <div class="form-group">
                    <label class="checkbox">
                        <input id="deleteReportsKeepDay" type="checkbox" name="deleteReportsKeepDay" value="1"
                               {% if deleteData.config.delete_reports_keep_day_reports %}checked="checked"{% endif %}>
                        {{ 'General_DailyReports'|translate }}
                    </label>
                    <label class="checkbox">
                        <input type="checkbox" name="deleteReportsKeepWeek" value="1" id="deleteReportsKeepWeek"
                               {% if deleteData.config.delete_reports_keep_week_reports %}checked="checked"{% endif %}>
                        {{ 'General_WeeklyReports'|translate }}
                    </label>
                    <label class="checkbox">
                        <input type="checkbox" name="deleteReportsKeepMonth" value="1" id="deleteReportsKeepMonth"
                               {% if deleteData.config.delete_reports_keep_month_reports %}checked="checked"{% endif %}>
                        {{ 'General_MonthlyReports'|translate }}
                        <span class="form-description">{{ 'General_Recommended'|translate }}</span>
                    </label>
                    <label class="checkbox">
                        <input type="checkbox" name="deleteReportsKeepYear" value="1" id="deleteReportsKeepYear"
                               {% if deleteData.config.delete_reports_keep_year_reports %}checked="checked"{% endif %}>
                        {{ 'General_YearlyReports'|translate }}
                        <span class="form-description">{{ 'General_Recommended'|translate }}</span>
                    </label>
                    <label class="checkbox">
                        <input type="checkbox" name="deleteReportsKeepRange" value="1" id="deleteReportsKeepRange"
                               {% if deleteData.config.delete_reports_keep_range_reports %}checked="checked"{% endif %}>
                        {{ 'General_RangeReports'|translate }}
                    </label>
                    <label class="checkbox">
                        <input type="checkbox" name="deleteReportsKeepSegments" value="1" id="deleteReportsKeepSegments"
                               {% if deleteData.config.delete_reports_keep_segment_reports %}checked="checked"{% endif %}>
                        {{ 'PrivacyManager_KeepReportSegments'|translate }}
                    </label>
                </div>
            </div>


            <h2 for="deleteLowestInterval" id="scheduleSettingsHeadline">
                {{ 'PrivacyManager_DeleteSchedulingSettings'|translate }}
            </h2>
            <div id="deleteSchedulingSettings" class="form-group">
                <div class="form-help">
                    {% if deleteData.lastRun %}<strong>{{ 'PrivacyManager_LastDelete'|translate }}:</strong>
                        {{ deleteData.lastRunPretty }}
                        <br/>
                        <br/>
                    {% endif %}
                    <strong>{{ 'PrivacyManager_NextDelete'|translate }}:</strong>
                    {{ deleteData.nextRunPretty|raw }}
                    <br/>
                    <br/>
                    <em><a id="purgeDataNowLink" href="#">{{ 'PrivacyManager_PurgeNow'|translate }}</a></em>
                        <span class="loadingPiwik" style="display:none;"><img
                                    src="./plugins/Morpheus/images/loading-blue.gif"/> {{ 'PrivacyManager_PurgingData'|translate }}</span>
                    <span id="db-purged-message" style="display: none;"><em>{{ 'PrivacyManager_DBPurged'|translate }}</em></span>
                </div>

                <label>{{ 'PrivacyManager_DeleteDataInterval'|translate }}</label>
                <select id="deleteLowestInterval" name="deleteLowestInterval">
                    <option {% if deleteData.config.delete_logs_schedule_lowest_interval == '1' %} selected="selected" {% endif %}
                            value="1"> {{ 'Intl_PeriodDay'|translate }}</option>
                    <option {% if deleteData.config.delete_logs_schedule_lowest_interval == '7' %} selected="selected" {% endif %}
                            value="7">{{ 'Intl_PeriodWeek'|translate }}</option>
                    <option {% if deleteData.config.delete_logs_schedule_lowest_interval == '30' %} selected="selected" {% endif %}
                            value="30">{{ 'Intl_PeriodMonth'|translate }}</option>
                </select>
            </div>

            <h3 id="databaseSizeHeadline">
                {{ 'PrivacyManager_ReportsDataSavedEstimate'|translate }}
            </h3>
            <div {% if deleteData.config.delete_reports_enable == '0' and deleteData.config.delete_logs_enable == '0' %}style="display:none;"{% endif %}
                 id="deleteDataEstimateSect" class="form-group">
                {% if deleteData.config.enable_auto_database_size_estimate == '0' %}
                    <div class="form-help">
                        <a id="getPurgeEstimateLink" href="#">{{ 'PrivacyManager_GetPurgeEstimate'|translate }}</a>
                    </div>
                {% endif %}
                <div id="deleteDataEstimate"></div>
                <span class="loadingPiwik" style="display:none;">
                    <img src="./plugins/Morpheus/images/loading-blue.gif"/> {{ 'General_LoadingData'|translate }}
                </span>
            </div>

            <input type="button" value="{{ 'General_Save'|translate }}" id="deleteLogSettingsSubmit" class="submit"/>

        </form>

    {% endif %}

    <h2 id="DNT">{{ 'PrivacyManager_DoNotTrack_SupportDNTPreference'|translate }}</h2>
    <p>
        {% if dntSupport %}
            {% set action='deactivateDoNotTrack' %}
            {% set nonce=deactivateNonce %}
            <strong>{{ 'PrivacyManager_DoNotTrack_Enabled'|translate }}</strong>
            <br/>
            {{ 'PrivacyManager_DoNotTrack_EnabledMoreInfo'|translate }}
        {% else %}
            {% set action='activateDoNotTrack' %}
            {% set nonce=activateNonce %}
            {{ 'PrivacyManager_DoNotTrack_Disabled'|translate }} {{ 'PrivacyManager_DoNotTrack_DisabledMoreInfo'|translate }}
        {% endif %}
    </p>
    <div class="form-group">
        <div class="form-help">
            {{ 'PrivacyManager_DoNotTrack_Description'|translate }}
        </div>
        <a class="btn" href='{{ {'module':'PrivacyManager','nonce':nonce,'action':action} | urlRewriteWithParameters }}#DNT'>
            {% if dntSupport %}
                {{ 'PrivacyManager_DoNotTrack_Disable'|translate }}
            {% else %}
                {{ 'PrivacyManager_DoNotTrack_Enable'|translate }}
            {% endif %}
        </a>

        {% if dntSupport %}
            ({{ 'General_NotRecommended'|translate }})
        {% else %}
            ({{ 'General_Recommended'|translate }})
        {% endif %}
    </div>
{% endif %}

<h2 id="optOutAnchor">{{ 'CoreAdminHome_OptOutForYourVisitors'|translate }}</h2>
<p>
    {{ 'CoreAdminHome_OptOutExplanation'|translate }}
    {% set optOutUrl %}{{ piwikUrl }}index.php?module=CoreAdminHome&action=optOut&language={{ language }}{% endset %}
    {% set iframeOptOut %}<iframe style="border: 0; height: 200px; width: 600px;" src="{{ optOutUrl }}"></iframe>{% endset %}
</p>
<pre>{{ iframeOptOut|e('html') }}</pre>
<p>
    {{ 'CoreAdminHome_OptOutExplanationBis'|translate("<a href='" ~ optOutUrl ~ "' rel='noreferrer' target='_blank'>","</a>")|raw }}
</p>

<div style="height:100px;"></div>
{% endblock %}
