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


    File:               show_foto.asp
    Description:        ASP to browse a directory of pictures
    Parameters:
        root_path       absolute path on the webserver to the directory where the pictures are
                        stored. Including starting slash and ending slash. (only forward slashes are
                        allowed)
        loc_key         key of the location to select the pictures from.
        nrOfPict        optional, number of pictures to be displayed per line
    Note:               !

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->

<%
FCLTHeader.Requires({ plugins: ["jQuery"] });

var loc_key = getQParamInt("loc_key");
// var root_path = getQParam("root_path", ""); // unsafe
var root_path = custpath + "/location_images/";

var nrOfPicturesPerLine = getQParamInt("nrOfPict", 4);

sql = "SELECT alg_locatie_code"
    + " FROM alg_locatie WHERE alg_locatie_key = " + loc_key;

var sub_path = "";
oRs = Oracle.Execute(sql);
while (!oRs.eof)
{
  sub_path = oRs(0).value;
  oRs.MoveNext();
}
oRs.close();

%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript">
      function ShowPicture(imageName)
      {
        newWindow = window.open(imageName, "newWindow", "resizable=yes, scrollbars=yes");
      	newWindow.document.close();
      	newWindow.focus();
      }
    </script>
  </head>
  <body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
<%
      var lPath = Server.MapPath(root_path + sub_path + '/');

      var fso, f, fc;
      fso = new ActiveXObject("Scripting.FileSystemObject");

      var dir_found = false;
      try
      {
        f = fso.GetFolder(lPath);
        fc = new Enumerator(f.files);
        dir_found = true;
      }
      catch(e){};

      if (dir_found)
      {
        imageHeight = parseInt(400 / nrOfPicturesPerLine);

        i = 1;
        for (; !fc.atEnd(); fc.moveNext())
        {
          if (i % nrOfPicturesPerLine == 1 || nrOfPicturesPerLine == 1)
          {
%>          <tr valign="top">
<%        }
          var filename_local = "../../.." + root_path + sub_path + '/' + fc.item().Name;
%>
          <td height="170">
            <div align="center">
              <table width="100%" border="0" cellspacing="0" cellpadding="10">
                <tr>
                  <td>
                    <div align="center">
                      <a href="javascript:" onClick="ShowPicture('<%=safe.jsstring(filename_local)%>')">
                        <img src="<%=safe.htmlattr(filename_local)%>"
                             height="<%=imageHeight%>" border="0" alt="<%=L("lcl_alg_klik_detail")%>">
                      </a>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td>
                    <div align="center"><%=fc.item().Name%><br/>
                    <%=fc.item().DateLastModified%></div>
                  </td>
                </tr>
              </table>
            </div>
          </td>
<%        if (i % nrOfPicturesPerLine == nrOfPicturesPerLine || nrOfPicturesPerLine == 1)
          { %>
            </tr>
<%        }
          i++;
        }
      }
      else
      {
        shared.simpel_page(L("lcl_shared_no_photos_present"));
      } %>
    </table>
  </body>
</html>