<%@ LANGUAGE = JavaScript %>
<% /*
    $Revision$
    $Id$

    File:           alg_cnd_aggregate.asp
    Description:    Laten berekenen van de geaggregeerde conditiescores

    Parameters:     keys (van het onroerend goed)
                    level: "L", "G"
    Context:        Vanuit show-schermen en of vanuit overzichten
    Result:         JSON object
    Note:

*/
var JSON_Result = true;
%>
<!--#include file="../Shared/common.inc"-->
<!--#include file="alg.inc" -->
<%
protectRequest.validateToken();

var level = getFParam("level");
var alg_key_arr = getFParamIntArray("key");

var autfunction = "WEB_ALGUSE"; // of iets met CND?

var authParams = user.checkAutorisation(autfunction);

var result = {};
var tobecndaggr = 0;
var ingesloten = [];
for (var i = 0; i < alg_key_arr.length; i++)
{
  var this_alg = alg.func_enabled(alg_key_arr[i], level);
  if (this_alg.canCndAggr)
  {
    ingesloten.push(alg_key_arr[i]);
    tobecndaggr++;
  }
}
user.anything_todo_or_abort(tobecndaggr > 0); // We klagen niet over enkele wel en enkele niet.

for (var i = 0; i < ingesloten.length; i++)
{
  switch (level)
  {
    case "L":
       sql = "BEGIN cnd.update_aggr_scores(" + ingesloten[i] + "); END;";
       break;
    case "G":
       sql = "BEGIN cnd.update_aggr_scores(NULL," + ingesloten[i] + "); END;";
       break
  }

  var err = Oracle.Execute(sql, true);
  if (err.friendlyMsg)
    abort_with_warning(err.friendlyMsg);

  result.success = true;
}

Response.Write(JSON.stringify(result));
%><% ASPPAGE_END(); %>
