{% extends 'admin.twig' %}

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

{% block content %}
{% import 'macros.twig' as piwik %}
{% if isSuperUser %}

<div piwik-content-intro>
    <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>
</div>

<div piwik-content-block
     id="anonymizeIPAnchor"
     content-title="{{ 'PrivacyManager_UseAnonymizeIp'|translate|e('html_attr') }}">
    <div piwik-form ng-controller="AnonymizeIpController as anonymizeIp">

        <div piwik-field uicontrol="checkbox" name="anonymizeIpSettings"
             ng-model="anonymizeIp.enabled"
             title="{{ 'PrivacyManager_UseAnonymizeIp'|translate|e('html_attr') }}"
             value="{{ anonymizeIP.enabled }}"
             inline-help="{{ 'PrivacyManager_AnonymizeIpInlineHelp'|translate|e('html_attr') }} {{ 'PrivacyManager_AnonymizeIpDescription'|translate|e('html_attr') }}">
        </div>

        <div ng-show="anonymizeIp.enabled">
            <div piwik-field uicontrol="radio" name="maskLength"
                 ng-model="anonymizeIp.maskLength"
                 title="{{ 'PrivacyManager_AnonymizeIpMaskLengtDescription'|translate|e('html_attr') }}"
                 value="{{ anonymizeIP.maskLength }}"
                 options="{{ maskLengthOptions|json_encode }}"
                 inline-help="{{ 'PrivacyManager_GeolocationAnonymizeIpNote'|translate|e('html_attr') }}">
            </div>

            <div piwik-field uicontrol="radio" name="useAnonymizedIpForVisitEnrichment"
                 ng-model="anonymizeIp.useAnonymizedIpForVisitEnrichment"
                 title="{{ 'PrivacyManager_UseAnonymizedIpForVisitEnrichment'|translate|e('html_attr') }}"
                 value="{% if anonymizeIP.useAnonymizedIpForVisitEnrichment %}1{% else %}0{% endif %}"
                 options="{{ useAnonymizedIpForVisitEnrichmentOptions|json_encode }}"
                 inline-help="{{ 'PrivacyManager_UseAnonymizedIpForVisitEnrichmentNote'|translate|e('html_attr') }}">
            </div>
        </div>

        <div piwik-save-button onconfirm="anonymizeIp.save()" saving="anonymizeIp.isLoading"></div>
    </div>
</div>

{% if isDataPurgeSettingsEnabled %}
    <div piwik-content-block id="deleteLogsAnchor"
         content-title="{{ 'PrivacyManager_DeleteOldVisitorLogs'|translate|e('html_attr') }}">
        <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>

        <p>{{ 'PrivacyManager_DeleteDataDescription'|translate }} {{ 'PrivacyManager_DeleteDataDescription2'|translate }}</p>

        <div piwik-form
             ng-controller="DeleteOldLogsController as deleteOldLogs"
             id="formDeleteSettings">
            <div id="deleteLogSettingEnabled">

                <div id="deleteLogInfoInlineHelp" class="inline-help-node">
                    {{ 'PrivacyManager_DeleteLogInfo'|translate(deleteData.deleteTables)|raw }}
                    {% if not canDeleteLogActions %}
                        <br/><br/>
                        {{ 'PrivacyManager_CannotLockSoDeleteLogActions'|translate(dbUser) }}
                    {% endif %}
                </div>

                <div piwik-field uicontrol="checkbox" name="deleteEnable"
                     ng-model="deleteOldLogs.enabled"
                     ng-change="deleteOldLogs.reloadDbStats()"
                     title="{{ 'PrivacyManager_UseDeleteLog'|translate|e('html_attr') }}"
                     value="{{ deleteData.config.delete_logs_enable }}"
                     inline-help="#deleteLogInfoInlineHelp">
                </div>

                <div class="alert alert-warning" style="width: 50%;">
                    {{ '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" ng-show="deleteOldLogs.enabled">
                <div piwik-field uicontrol="text" name="deleteOlderThan"
                     ng-model="deleteOldLogs.deleteOlderThan"
                     ng-change="deleteOldLogs.reloadDbStats()"
                     title="{{ 'PrivacyManager_DeleteLogsOlderThan'|translate|e('html_attr') }} ({{ 'Intl_PeriodDays'|translate }})"
                     value="{{ deleteData.config.delete_logs_older_than }}"
                     inline-help="{{ 'PrivacyManager_LeastDaysInput'|translate("1")|e('html_attr') }}">
                </div>
            </div>

            <div piwik-save-button onconfirm="deleteOldLogs.save()" saving="deleteOldLogs.isLoading"></div>
        </div>
    </div>

    <div piwik-content-block id="deleteReportsAnchor"
            content-title="{{ 'PrivacyManager_DeleteOldArchivedReports'|translate|e('html_attr') }}">

        <div piwik-form
             ng-controller="DeleteOldReportsController as deleteReports" 
             id="formDeleteSettings">

            <div id="deleteReportsSettingEnabled">

                <div piwik-field uicontrol="checkbox" name="deleteReportsEnable"
                     ng-model="deleteReports.enabled"
                     ng-change="deleteReports.reloadDbStats()"
                     title="{{ 'PrivacyManager_UseDeleteReports'|translate|e('html_attr') }}"
                     value="{{ deleteData.config.delete_reports_enable }}"
                     inline-help="{{ 'PrivacyManager_DeleteReportsDetailedInfo'|translate('archive_numeric_*','archive_blob_*')|e('html_attr') }}">
                </div>

                <div class="alert alert-warning" style="width: 50%;">
                    {% set deleteOldLogs %}{{ 'PrivacyManager_UseDeleteLog'|translate }}{% endset %}
                    {{ 'PrivacyManager_DeleteReportsInfo'|translate('','')|raw }}
                    <span ng-show="deleteReports.enabled">
                        <br/><br/>
                        {{ 'PrivacyManager_DeleteReportsInfo2'|translate(deleteOldLogs) }}<br/><br/>
                        {{ 'PrivacyManager_DeleteReportsInfo3'|translate(deleteOldLogs) }}
                    </span>
                </div>

            </div>

            <div id="deleteReportsSettings" ng-show="deleteReports.enabled">

                <div piwik-field uicontrol="text" name="deleteReportsOlderThan"
                     ng-model="deleteReports.deleteOlderThan"
                     ng-change="deleteReports.reloadDbStats()"
                     title="{{ 'PrivacyManager_DeleteReportsOlderThan'|translate|e('html_attr') }} ({{ 'Intl_PeriodMonths'|translate }})"
                     value="{{ deleteData.config.delete_reports_older_than }}"
                     inline-help="{{ 'PrivacyManager_LeastMonthsInput'|translate("3")|e('html_attr') }}">
                </div>

                <div piwik-field uicontrol="checkbox" name="deleteReportsKeepBasic"
                     ng-model="deleteReports.keepBasic"
                     ng-change="deleteReports.reloadDbStats()"
                     title="{{ 'PrivacyManager_KeepBasicMetrics'|translate|e('html_attr') }} ({{ 'General_Recommended'|translate|e('html_attr') }})"
                     value="{{ deleteData.config.delete_reports_keep_basic_metrics }}"
                     inline-help="{{ 'PrivacyManager_DeleteReportsDetailedInfo'|translate('archive_numeric_*','archive_blob_*')|e('html_attr') }}">
                </div>

                <h3>
                    {{ 'PrivacyManager_KeepDataFor'|translate }}
                </h3>
                <div>

                    <div piwik-field uicontrol="checkbox" name="deleteReportsKeepDay"
                         ng-model="deleteReports.keepDataForDay"
                         ng-change="deleteReports.reloadDbStats()"
                         title="{{ 'General_DailyReports'|translate|e('html_attr') }}"
                         value="{{ deleteData.config.delete_reports_keep_day_reports }}">
                    </div>
                    <div piwik-field uicontrol="checkbox" name="deleteReportsKeepWeek"
                         ng-model="deleteReports.keepDataForWeek"
                         ng-change="deleteReports.reloadDbStats()"
                         title="{{ 'General_WeeklyReports'|translate|e('html_attr') }}"
                         value="{{ deleteData.config.delete_reports_keep_week_reports }}">
                    </div>
                    <div piwik-field uicontrol="checkbox" name="deleteReportsKeepMonth"
                         ng-model="deleteReports.keepDataForMonth"
                         ng-change="deleteReports.reloadDbStats()"
                         title="{{ 'General_MonthlyReports'|translate|e('html_attr') }} ({{ 'General_Recommended'|translate|e('html_attr') }})"
                         value="{{ deleteData.config.delete_reports_keep_month_reports }}">
                    </div>
                    <div piwik-field uicontrol="checkbox" name="deleteReportsKeepYear"
                         ng-model="deleteReports.keepDataForYear"
                         ng-change="deleteReports.reloadDbStats()"
                         title="{{ 'General_YearlyReports'|translate|e('html_attr') }} ({{ 'General_Recommended'|translate|e('html_attr') }})"
                         value="{{ deleteData.config.delete_reports_keep_year_reports }}">
                    </div>
                    <div piwik-field uicontrol="checkbox" name="deleteReportsKeepRange"
                         ng-model="deleteReports.keepDataForRange"
                         ng-change="deleteReports.reloadDbStats()"
                         title="{{ 'General_RangeReports'|translate|e('html_attr') }}"
                         value="{{ deleteData.config.delete_reports_keep_range_reports }}">
                    </div>
                    <div piwik-field uicontrol="checkbox" name="deleteReportsKeepSegments"
                         ng-model="deleteReports.keepDataForSegments"
                         ng-change="deleteReports.reloadDbStats()"
                         title="{{ 'PrivacyManager_KeepReportSegments'|translate|e('html_attr') }}"
                         value="{{ deleteData.config.delete_reports_keep_segment_reports }}">
                    </div>
                </div>
            </div>

            <div piwik-save-button onconfirm="deleteReports.save()" saving="deleteReports.isLoading"></div>
        </div>
    </div>

    <div piwik-form
         ng-controller="ScheduleReportDeletionController as reportDeletionSchedule"
         id="formDeleteSettings">

        <div piwik-content-block id="scheduleSettingsHeadline"
             ng-show="reportDeletionSchedule.model.isEitherDeleteSectionEnabled()"
             content-title="{{ 'PrivacyManager_DeleteSchedulingSettings'|translate|e('html_attr') }}">

            <div id="deleteSchedulingSettings">
                <div id="deleteSchedulingSettingsInlineHelp" class="inline-help-node">
                    {% if deleteData.lastRun %}<strong>{{ 'PrivacyManager_LastDelete'|translate }}:</strong>
                        {{ deleteData.lastRunPretty }}
                        <br/>
                        <br/>
                    {% endif %}
                    <strong>{{ 'PrivacyManager_NextDelete'|translate }}:</strong>
                    {{ deleteData.nextRunPretty|raw }}
                    <br/>
                    <br/>
                    <a id="purgeDataNowLink" href="#"
                           ng-show="reportDeletionSchedule.showPurgeNowLink"
                           ng-click="reportDeletionSchedule.executeDataPurgeNow()">{{ 'PrivacyManager_PurgeNow'|translate }}</a>

                        <div piwik-activity-indicator
                             loading-message="'{{ 'PrivacyManager_PurgingData'|translate|e('html_attr') }}'"
                             loading="reportDeletionSchedule.loadingDataPurge"></div>
                    <span id="db-purged-message"
                          ng-show="reportDeletionSchedule.dataWasPurged"
                    >{{ 'PrivacyManager_DBPurged'|translate }}</span>
                </div>

                <div piwik-field uicontrol="select" name="deleteLowestInterval"
                     ng-model="reportDeletionSchedule.deleteLowestInterval"
                     options="{{ scheduleDeletionOptions|json_encode }}"
                     title="{{ 'PrivacyManager_DeleteDataInterval'|translate|e('html_attr') }}"
                     value="{{ deleteData.config.delete_logs_schedule_lowest_interval }}"
                     inline-help="#deleteSchedulingSettingsInlineHelp">
                </div>
            </div>

            <div id="deleteDataEstimateSect" class="form-group row">

                <h3 class="col s12" id="databaseSizeHeadline">
                    {{ 'PrivacyManager_ReportsDataSavedEstimate'|translate }}
                </h3>
                <div class="col s12 m6">
                    <div id="deleteDataEstimate" ng-show="reportDeletionSchedule.model.showEstimate"
                          ng-bind-html="reportDeletionSchedule.model.estimation"></div>
                    &nbsp;
                    <div piwik-activity-indicator loading="reportDeletionSchedule.model.loadingEstimation"></div>
                </div>
                <div class="col s12 m6">
                    {% if deleteData.config.enable_auto_database_size_estimate == '0' %}
                    <div class="form-help">
                        <a id="getPurgeEstimateLink"
                           ng-click="reportDeletionSchedule.model.reloadDbStats(true)"
                           href="#">{{ 'PrivacyManager_GetPurgeEstimate'|translate }}</a>
                    </div>
                    {% endif %}
                </div>
            </div>

            <div piwik-save-button onconfirm="reportDeletionSchedule.save()" saving="reportDeletionSchedule.isLoading"></div>

        </div>
    {% endif %}
</div>
<div piwik-content-block
    id="DNT"
    content-title="{{ 'PrivacyManager_DoNotTrack_SupportDNTPreference'|translate|e('html_attr') }}">
    <p>
        {% if dntSupport %}
            <strong>{{ 'PrivacyManager_DoNotTrack_Enabled'|translate }}</strong>
            <br/>
            {{ 'PrivacyManager_DoNotTrack_EnabledMoreInfo'|translate }}
        {% else %}
            {{ 'PrivacyManager_DoNotTrack_Disabled'|translate }} {{ 'PrivacyManager_DoNotTrack_DisabledMoreInfo'|translate }}
        {% endif %}
    </p>

    <div piwik-form ng-controller="DoNotTrackPreferenceController as doNotTrack">

        {# {{ {'module':'PrivacyManager','nonce':nonce,'action':action} | urlRewriteWithParameters }}#DNT #}
        <div piwik-field uicontrol="radio" name="doNotTrack"
             ng-model="doNotTrack.enabled"
             options="{{ doNotTrackOptions|json_encode }}"
             value="{% if dntSupport %}1{% else %}0{% endif %}"
             inline-help="{{ 'PrivacyManager_DoNotTrack_Description'|translate|e('html_attr') }}">
        </div>

        <div piwik-save-button onconfirm="doNotTrack.save()" saving="doNotTrack.isLoading"></div>

    </div>


{% endif %}
</div>
<div piwik-content-block
     id="optOutAnchor"
     content-title="{{ 'CoreAdminHome_OptOutForYourVisitors'|translate|e('html_attr') }}">
    <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 piwik-select-on-focus>{{ iframeOptOut|e('html') }}</pre>
    <p>
        {{ 'CoreAdminHome_OptOutExplanationBis'|translate("<a href='" ~ optOutUrl ~ "' rel='noreferrer' target='_blank'>","</a>")|raw }}
    </p>
</div>
{% endblock %}
