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

     File:          fac_like.asp
     Description:   Beoordelen van een (eigen) afgehandelde melding etc
     Parameters:    key
                    xmlnode
     Context:       vanuit de lijst van eigen afgemelde zaken
                    of een deeplink vanuit een bon

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

var key = getQParamInt("key");
var node = getQParam("node");

var this_like = like.func_enabled_like(key, node);
user.auth_required_or_abort(this_like.canChange);

var oordeel = getFParam("oordeel", null);
var TransitParam = buildTransitParam(["key", "node"]);


// validatie:
// is het van mij
// mag ik het etc.
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
  </head>

  <script type="text/javascript">

    function fac_cancel()
    {
      FcltMgr.closeDetail(window, { cancel: true } );
    }

    function fac_submit()
    {
      if (!$("[name=flike_oordeel]:checked").val())
      {
        alert("<%=L('lcl_fac_like_geenoordeel')%>");
        return false;
      }
      $.post($("form[name=flike]")[0].action, $("[name=flike]").serialize(), FcltCallbackClose, "json");
      return true; // disable button
    }

    function togglerPressed()
    {
      $("#flike_opmerk").show();
      FcltMgr.resized(window);
    }
  </script>

  <body class="modal" id="fac_like">
    <form id="flike" name="flike" action="fac_like_save.asp?x=x<%=TransitParam%>" method="post">
<%
      BLOCK_START("facLike", L("lcl_fac_like_block"));
      var table = "";
      var txt= "??";
      switch (node) {
         case "melding"    : table = "mld_melding";
                             var sql = "SELECT isd.ins_srtdiscipline_prefix || TO_CHAR (m.mld_melding_key) item"
                                     + "  FROM mld_melding m"
                                     + "     , ins_srtdiscipline isd"
                                     + "     , ins_tab_discipline id"
                                     + "     , mld_stdmelding sm"
                                     + " WHERE m.mld_stdmelding_key = sm.mld_stdmelding_key"
                                     + "   AND sm.mld_ins_discipline_key = id.ins_discipline_key"
                                     + "   AND id.ins_srtdiscipline_key = isd.ins_srtdiscipline_key"
                                     + "   AND m.mld_melding_key = " + key;
                             oRs = Oracle.Execute(sql);
                             txt = L("lcl_complain").toLowerCase() + " " + oRs("item").Value;  break;
                             oRs.Close();
         case "reservering": table = "res_rsv_ruimte";
                             var sql = "SELECT TO_CHAR(res_reservering_key) || '/' || TO_CHAR(res_rsv_ruimte_volgnr) item"
                                     + "  FROM res_rsv_ruimte"
                                     + " WHERE res_rsv_ruimte_key = " + key;
                             oRs = Oracle.Execute(sql);
                             txt = L("lcl_reservation").toLowerCase() + " R" + oRs("item").Value; break;
                             oRs.Close();
         case "bestelling" : table = "bes_bestelling";
                             txt = L("lcl_bes_bestelling").toLowerCase() + " B" + key;  break;
      }
      var sql = "SELECT " + table + "_satisfaction"
              + ", "      + table + "_satisfaction_op"
              + "  FROM " + table
              + " WHERE " + table + "_key = " + key;
      var oRs = Oracle.Execute(sql);
      var oordeel = oRs(0).value;
      var opmerking = oRs(1).value;
      oRs.Close();

%>
      <div class="flikehead"><%=L("lcl_fac_like_oordeel").format(txt)%></div>
      <ul class="flikeopts">
<%      if (S("fac_like_excellent") > 0)
        { %>
          <li>
           <label>
            <input type="radio" id="flike_oordeel" name="flike_oordeel" value="<%=S('fac_like_excellent')%>"<%=(oordeel==S("fac_like_excellent")? " checked" : "")%>>
            <%=rating.stars(S("fac_like_excellent"), {rating: {note: L("lcl_faclike_statisf5")}})%>&nbsp&nbsp<%=L("lcl_faclike_statisf5")%>
           </label>
          </li>
<%      }
        if (S("fac_like_good") > 0)
        { %>
          <li>
           <label>
            <input type="radio" id="flike_oordeel" name="flike_oordeel" value="<%=S('fac_like_good')%>"<%=(oordeel==S("fac_like_good")? " checked" : "")%>>
            <%=rating.stars(S("fac_like_good"), {rating: {note: L("lcl_faclike_statisf4")}})%>&nbsp&nbsp<%=L("lcl_faclike_statisf4")%>
           </label>
          </li>
<%      }
        if (S("fac_like_normal") > 0)
        { %>
          <li>
           <label>
            <input type="radio" id="flike_oordeel" name="flike_oordeel" value="<%=S('fac_like_normal')%>"<%=(oordeel==S("fac_like_normal")? " checked" : "")%>>
            <%=rating.stars(S("fac_like_normal"), {rating: {note: L("lcl_faclike_statisf3")}})%>&nbsp&nbsp<%=L("lcl_faclike_statisf3")%>
           </label>
          </li>
<%      }
        if (S("fac_like_poor") > 0)
        { %>
          <li>
           <label>
            <input type="radio" id="flike_oordeel" name="flike_oordeel" value="<%=S('fac_like_poor')%>"<%=(oordeel==S("fac_like_poor")? " checked" : "")%>>
            <%=rating.stars(S("fac_like_poor"), {rating: {note: L("lcl_faclike_statisf2")}})%>&nbsp&nbsp<%=L("lcl_faclike_statisf2")%>
           </label>
          </li>
<%      }
        if (S("fac_like_bad") > 0)
        { %>
          <li>
           <label>
            <input type="radio" id="flike_oordeel" name="flike_oordeel" value="<%=S('fac_like_bad')%>"<%=(oordeel==S("fac_like_bad")? " checked" : "")%>>
            <%=rating.stars(S("fac_like_bad"), {rating: {note: L("lcl_faclike_statisf1")}})%>&nbsp&nbsp<%=L("lcl_faclike_statisf1")%>
           </label>
          </li>
<%      } %>
      </ul>

      <div id="flike_op">
        <img src="../pictures/togglerdown.png" onClick="togglerPressed()">
        <label onClick="togglerPressed()"><%=L("lcl_fac_like_remark")%></label>
      </div>
      <textarea class="fldtxt" rows="3" maxlength="2000" id="flike_opmerk" name="flike_opmerk"
                    style="<%=(opmerking ? null : "display:none")%>"><%=safe.textarea(opmerking)%></textarea>

      <div class="flikefoot"><%=L("lcl_fac_help_improve")%></div>
<%
      BLOCK_END();
      buttons = [];

      buttons.push({title: L("lcl_fac_like_submit"), icon: "submit.png", action: "fac_submit()" });
      buttons.push({title: L("lcl_cancel"), icon: "cancel.png", action: "fac_cancel()" });
      CreateButtons(buttons);
      IFACE.FORM_END();
%>
    </form>
  </body>
</html>
