<% /*
     $Revision$
     $Id$

     File:    fac/fac_like.inc
     Context:

     Hulpfuncties voor fac_like
*/

like = {
          // TODO: S("facilities_flike_past") er nog in betrekken?

          // Autorisatie is relatief simpel: hij moet op jou naam staan of je moet contactpersoon zijn
          func_enabled_like: function (key, node)
          {
            var result = {};
            var sql;
            switch (node.toUpperCase().substring(0,1))
            {
                case "M": sql = "SELECT prs_perslid_key, prs_perslid_key_voor FROM mld_melding WHERE mld_melding_key = " + key; break;
                case "R": sql = "SELECT res_rsv_ruimte_host_key, res_rsv_ruimte_contact_key FROM res_rsv_ruimte WHERE res_rsv_ruimte_key = " + key; break;
                case "B": sql = "SELECT prs_perslid_key, prs_perslid_key_voor FROM bes_bestelling WHERE bes_bestelling_key = " + key; break;
                default: INTERNAL_ERROR_UNKNOWN_LIKENODE;
            }
            var oRs = Oracle.Execute(sql);
            if (!oRs.Eof)
            {
                result.canChange = oRs(0).Value == user_key || oRs(1).Value == user_key;
            }
            oRs.Close();

            return result;
          },
          save_like: function (key, node, oordeel_int, opmerking)
          {
            if (oordeel_int >= 0 && oordeel_int <= 10)
            {
              var table = "";
              switch (node.toUpperCase().substring(0,1))
              {
                  case "M": table = "mld_melding"; break;
                  case "R": table = "res_rsv_ruimte"; break;
                  case "B": table = "bes_bestelling"; break;
                  default: INTERNAL_ERROR_UNKNOWN_LIKENODE;
              }
              var sql = "UPDATE " + table
                      + "   SET " + table + "_satisfaction = " + oordeel_int
                      + (opmerking?"     , " + table + "_satisfaction_op = " + safe.quoted_sql(opmerking):"")
                      + " WHERE " + table + "_key = " + key;
              Oracle.Execute(sql);
             }
          }
       }
%>