<!--
*********************************************************************************
* Start out by getting the ihds object
*********************************************************************************
-->
<%@ page import="com.ai.htmlgen.*" %>
<%@ page import="com.ai.application.utils.*" %>
<%@ page import="com.ai.common.*" %>
<% 
   ihds pageData = (ihds)request.getAttribute("Aspire.formHandler");
   if (pageData == null)
   {
      out.println("<html><head></head><body><h2 class=error>No data available for this screen</h2></body></html>");
      return;      
   }         
   IExpressionEvaluator exprEval = ExpressionEvaluatorFactory.getSelf();
   IDictionary dictionary = new FormHandlerDictionary((IFormHandler)pageData);
%>
<!--
*********************************************************************************
* HTML page start
*********************************************************************************
-->
<html>

<head>
<title>Welcome to Aspire</title>
<link rel="stylesheet" type="text/css" href="/akc/style/style.css">
<script src="/akc/js/genericedits1.js"></script>

<!--
*********************************************************************************
* Java script functions
*********************************************************************************
-->
<script>
function search()
{

   fieldValues=getFieldValues(document.mainform,"EntityTypeListBox,NameTextField,DunsTextField");

/*
   additionalWhereClause = getFieldValuesAsAWhereClause(document.mainform
         ,"EntityTypeListBox,SeveritySelectBox,ProblemDescTextField,StatusSelectBox,ModuleSelectBox,AssignedToSelectBox,udf1TextField,udf2TextField"
         ,"problem_id,severity,problem_short_description,status_name,module_name,assigned_to,udf1,udf2"
         ,"int,string,string,string,string,string,string,string"
         ,"None");
*/         
   additionalWhereClause = getFieldValuesAsAWhereClause(document.mainform
         ,"EntityTypeListBox,NameTextField"
         ,"le.type_id,le.name"
         ,"int,string"
         ,"None");
         
   awc = " and " + additionalWhereClause;
   
   url = "/akc/servlet/DisplayServlet?url=dbLocationsURL"
       + "&whereclause=" + escape(awc)
       + "&fieldValues=" + escape(fieldValues)
       
//   alert(fieldValues);
//   alert(url);
   document.location = url;   
}

function onloadFunction()
{
   var fieldValues = "<%=pageData.getValue("fieldValues")%>";
   if (fieldValues  != "")
   {
//      alert(fieldValues);
      setFieldValues(document.mainform,fieldValues);
   }
}

function gotoReport(reportId)
{
   url = eval("document.folderform.report" + reportId + ".value");
   relativeUrl = getRelativeURL(url);
   relativeUrl += "&reportId=" + reportId
   document.location=relativeUrl;
}

function gotoUpdateReport(rownum)
{
   url = eval("document.folderform.updateReport" + rownum + ".value");
   relativeUrl = getRelativeURL(url);
   document.location=relativeUrl;
}
function deleteReport(reportId, contentId)
{
   openFolderName = "<%=pageData.getValue("openFolderName")%>";
   
   finalUrl="";
   
   if (contentId == "")
   {
      finalUrl="/akc/servlet/UpdateServlet?request_name=DeleteReport"
            + "&reportId=" + reportId 
            + "&contentId=" + contentId
            + "&openFolderName=" + escape(openFolderName);
   }
   else
   {
      finalUrl="/akc/servlet/UpdateServlet?request_name=DeleteReportWithContent"
            + "&reportId=" + reportId 
            + "&contentId=" + contentId
            + "&openFolderName=" + escape(openFolderName);
   }
//   alert(finalUrl);         
   document.location=finalUrl;
      
}
function createFolder()
{
   folderName = document.folderform.NewFolderTextField.value;
   if (folderName == "")
   {
      alert("Folder name is required to create a new folder");
      return;
   }
   
   url = "/akc/servlet/UpdateServlet?request_name=CreateFolder&folderName=" +escape(folderName);
   document.location=url;
//   alert(folderName);
}

function moveToFolder()
{
   //get a list of reports
   // if the reports are null error and out
   reports = getSelectedCheckBoxValues(document.folderform,"ReportCheckBox",",")
   selFolderId = getValueString(document.folderform.FolderListBox);

   url="/akc/servlet/UpdateServlet?request_name=MoveReports";
   url += "&folderId=" + selFolderId;
   url += "&reportIds=" + reports;

//   alert(url);
   document.location = url;
}

function setFolderAccess(folderId,access)
{
   openFolderName = "<%=pageData.getValue("openFolderName")%>";
   finalUrl="/akc/servlet/UpdateServlet?request_name=SetFolderAccess"
            + "&folderId=" + folderId
            + "&access=" + access
            + "&openFolderName=" + escape(openFolderName);
//   alert(finalUrl);         
   document.location=finalUrl;   
}
</script>
<!--
**********************************************************
* Master page Header, and body header
**********************************************************
-->
<%=pageData.getValue("aspire_masterpage_header")%>
</head>

<body >
<%=pageData.getValue("aspire_masterpage_tophalf")%>

<%=exprEval.evaluate("substitute(publicHeader)",dictionary)%>
<!--
*********************************************************************************
* Folder control: create, list, move 
*********************************************************************************
-->
<form name="folderform">
<!--
*********************************************************************************
* ControlPanel div - begin
*********************************************************************************
-->
<div class="ControlPanel" style="float:right;">
<h3>File away selected Items</h3>
<div style="background-color:gray;margin:1em 1em 1em 1em;">
<p>Choose a folder and
<input class="button" type="button" value="Move" name="B1" onClick="moveToFolder()">
the selected items
</p>

<p>
<select class="select" size="1" name="FolderListBox">
<!--RLF_TAG BGN_LOOP FoldersLoop -->
<%
   ihds foldersLoop = pageData.getChild("FoldersLoop");
   for(foldersLoop.moveToFirst();!foldersLoop.isAtTheEnd();foldersLoop.moveToNext())
   {
%>

<option value="<%=foldersLoop.getValue("folder_id")%>" > <%=foldersLoop.getValue("folder_name")%> </option>

<%}%>
<!--RLF_TAG END_LOOP FoldersLoop -->
</select>
<p> 
</div>

<h3>Create a new folder</h3>
<div style="background-color:gray;margin:1em 1em 1em 1em;">
<p>Enter a new Folder name and <input class="button" type="button" value="Create" name="B2" onClick="createFolder()">
<p><input type="text" name="NewFolderTextField" size="20">
<p> 
</div>


<h3>Delete selected items</h3>
<p>Click on <input type="button" class="button" value="Delete" name="B3"> to delete the selected items
</p>
<!--
*********************************************************************************
* ControlPanel div - end
*********************************************************************************
-->
</div>
<!--
*********************************************************************************
* Paint each folder
*********************************************************************************
-->
<%
   ihds folderList = pageData.getChild("FoldersLoop1");
   String ownerUserId = pageData.getValue("profile_user");
   out.println("<dl>");
   for(folderList.moveToFirst();!folderList.isAtTheEnd();folderList.moveToNext())
   {
//      ihds reportLoop = folderList.getChild("itemsLoop");
      String curFolderName = folderList.getValue("folder_name");
      String openFolderName = pageData.getValue("openFolderName");
      if (openFolderName.equals(""))
      {
         openFolderName = "Default Folder";
      }
      String targetUrl = "/akc/servlet/DisplayServlet?url=ShowFiledReportsJSPURL&openFolderName=" 
            + com.ai.common.StringUtils.urlEncodeS(curFolderName);
      
      String curFolderAccess = folderList.getValue("public");
      String curFolderId = folderList.getValue("folder_id");
      
      String cfa_string = curFolderAccess.equals("Y") ? "public" : "private";
      String cfa_value = curFolderAccess.equals("Y") ? "N" : "Y";
      
      String summaryUrl = "/akc/display?url=NotesMPTitlesURL&order_by_format=news&folderName="
         + com.ai.common.StringUtils.urlEncodeS(curFolderName)
         + "&ownerUserId=" + ownerUserId;
         
%>

<!--
*********************************************************************************
* Folder content
*********************************************************************************
-->
<dd class="folder">
   <a href="<%=targetUrl%>"><%=folderList.getValue("folder_name")%> </a>
      
   <a href="javascript:setFolderAccess('<%=curFolderId%>','<%=cfa_value%>')"> <%=cfa_string%> </a>
      
   <a href="<%=summaryUrl%>">summary</a>
</dd>

<%
if (!(curFolderName.equals(openFolderName)))
{
   //No need to paint this
//   reportLoop.close();
   continue;
}
// This is the current folder
ihds reportLoop = folderList.getChild("itemsLoop");
if (reportLoop.isAtTheEnd() == true)
{
   out.println("<p>No reports available in this folder</p>");
}
else
{
   out.println("<dl>");
   for(reportLoop.moveToFirst();!reportLoop.isAtTheEnd();reportLoop.moveToNext()){
%>

<!--
*********************************************************************************
* report content
*********************************************************************************
-->
<dd>
<input type="checkbox" name="ReportCheckBox" value="<%=reportLoop.getValue("report_id")%>">   

 <a href="javascript:gotoReport('<%=reportLoop.getValue("report_id")%>')"><%=reportLoop.getValue("report_short_name")%> </a>
 <input type="hidden" name="report<%=reportLoop.getValue("report_id")%>" value='<%=reportLoop.getValue("url")%>'>

<%
if (!(reportLoop.getValue("update_url").equals("")))
{
%>
 <a href="javascript:gotoUpdateReport('<%=reportLoop.getValue("report_id")%>')">edit</a>
 <input type="hidden" name="updateReport<%=reportLoop.getValue("report_id")%>" value='<%=reportLoop.getValue("update_url")%>'>
<%}%>

 <a class="delete" href="javascript:deleteReport('<%=reportLoop.getValue("report_id")%>','<%=reportLoop.getValue("report_content_id")%>')">delete</a>
</dd>

      <%}//end of inner report loop 
      out.println("</dl>");
%>
   <%}//end of else %>
<%}//end of outer folder loop 
      out.println("</dl>");
%>
</form>
<!--
**********************************************************
* Master page bottom half of the body
**********************************************************
-->
<%=pageData.getValue("aspire_masterpage_bottomhalf")%>
</body></html>