<%@language = "javascript" %>
<% /*
    $Revision$
    $Id$

    File:          fac_anonimize.asp
    Description:   Anonimiseringscherm
    Parameters:
    Context:       Via URL (alleen prssys)
    Note:

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<%
FCLTHeader.Requires({plugins:["jQuery"], js: []});

var autfunction = "WEB_PRSSYS";
var authparams = user.checkAutorisation(autfunction);
var module = getQParam("module", "");
var anonymize_period = S("anonymize_period");
%>
<html>
<head>
<%
  FCLTHeader.Generate() %>

  <script type="text/javascript">
    var anysearch = false;
    async function doSubmit()
    {
      if (!await validateForm("u2"))
        return false;

      document.forms.u2.submit();
    }
  </script>
</head>
<body id="searchbody">
  <form name="u2" method="get" action="fac_anonymize_list.asp" target="workFrame">
    <% SEARCH_PAGE_START({ header: L("lcl_filterblok") });
      SEARCH_BLOCK_START();

              // Startdatum bepalen door van de nog niet geanonimiseerde personen, de persoon te nemen met de laagste verwijder datum.
              sql = "SELECT MIN(sd.startdatum) minstartdatum"
                  + "  FROM (SELECT CASE"
                  + "               WHEN MIN(bez_afspraak_datum) > TO_DATE('01-01-2000 00:00', 'DD-MM-YYYY HH24:MI')"
                  + "               THEN MIN(bez_afspraak_datum)"
                  + "               ELSE TO_DATE('01-01-2000 00:00', 'DD-MM-YYYY HH24:MI')"
                  + "               END startdatum"
                  + "          FROM bez_afspraak"
                  + "         WHERE bez_afspraak_datum < TRUNC(SYSDATE - " + anonymize_period + ")"
                  + "           AND NOT EXISTS"
                  + "                   (SELECT ft.fac_tracking_key"
                  + "                      FROM fac_tracking ft"
                  + "                     WHERE ft.fac_tracking_refkey = bez_afspraak_key"
                  + "                       AND ft.fac_srtnotificatie_key = (SELECT fac_srtnotificatie_key"
                  + "                                                          FROM fac_srtnotificatie"
                  + "                                                         WHERE fac_srtnotificatie_code = 'BEZANO'))"
                  + "         UNION"
                  + "        SELECT CASE"
                  + "               WHEN MIN(p.prs_perslid_verwijder) > TO_DATE('01-01-2000 00:00', 'DD-MM-YYYY HH24:MI')"
                  + "               THEN MIN(p.prs_perslid_verwijder)"
                  + "               ELSE TO_DATE('01-01-2000 00:00', 'DD-MM-YYYY HH24:MI')"
                  + "               END startdatum"
                  + "          FROM prs_perslid p"
                  + "         WHERE p.prs_perslid_verwijder IS NOT NULL"
                  + "           AND p.prs_perslid_verwijder < SYSDATE - " + anonymize_period
                  + "           AND NOT EXISTS"
                  + "                   (SELECT ft.fac_tracking_key"
                  + "                      FROM fac_tracking ft"
                  + "                     WHERE ft.fac_tracking_refkey = p.prs_perslid_key"
                  + "                       AND ft.fac_srtnotificatie_key = (SELECT fac_srtnotificatie_key"
                  + "                                                          FROM fac_srtnotificatie"
                  + "                                                         WHERE fac_srtnotificatie_code = 'PRSANO'))"
                  + "       ) sd"
              oRs = Oracle.Execute(sql);
              var startdatum = new Date(oRs("minstartdatum").Value);
              var einddatum = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - anonymize_period);

              // <!-- Datum tot -->
              FCLTcalendar("einddatum",
                           { label: L("lcl_period_to"),
                             datum: einddatum,
                             maxDate: einddatum,
                             trclass: "primsearch",
                             required: true,
                             volgnr: 2,
                             opmerk: L("lcl_fac_atleast_anoperiod").format(anonymize_period)
                           });
SEARCH_BLOCK_END();
SEARCH_BLOCK_START();
%>
          <!-- Second column -->
        <td>
          <div id="anointotext1"><%=L("lcl_fac_ano_intotext1")%></div>
          <div id="anointotext2"><%=L("lcl_fac_ano_intotext2")%></div>
        </td>
      </tr>
<%    SEARCH_BLOCK_END();
      var buttons =  [ {title: L("lcl_overview_list"), action: "doSubmit()", icon: "fa-clipboard-list" } ];
      SIMPLE_BLOCK_START();
      CreateButtons(buttons, { entersubmit: true, showIcons: true});
      SIMPLE_BLOCK_END();
      SEARCH_PAGE_END();
%>
    </form>

<div id="result">
 <iframe width="100%" height="100%" src="../Shared/empty.asp"
         name="workFrame" id="workFrame"  onload='FcltMgr.iframeLoaded(this)'
         frameborder="0" scrolling="no"></iframe>
</div>

</body>
</html><% ASPPAGE_END(); %>
