<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" import="com.novell.webaccess.common.JSPConduit, com.novell.emframe.dev.eMFrameUtils,
                                                                             com.novell.emframe.fw.config.ModuleInfo,
                                                                             com.novell.emframe.fw.util.ModuleGet,
                                                                             java.util.*" %>
<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %>

<%   JSPConduit c = JSPConduit.getJSPConduit(request);
   c.stringTable("DevResources");
   c.stringTable("BaseResources");
   c.stringTable("FwResources");%>

<HTML><HEAD><TITLE></TITLE>
<LINK rel='stylesheet' href='<%= c.getModulesUrl() + "/dev/css/hf_style.css" %>'>
<jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
	<script language="javascript">
   function checkboxSelect()
   {
      var i=0;
      var tag="Modules";
      var len = tag.length;
      if(document.getElementById("selectall").checked)
      {
         for(i=0; i<document.ModulesToInstall.elements.length; i++)
         {
            var s = document.ModulesToInstall.elements[i].name;
            if (s.substring(0,len)==tag)
            {
               document.ModulesToInstall.elements[i].checked=true;
            }
         }
      }
      else
      {
         for(i=0; i<document.ModulesToInstall.elements.length; i++)
         {
            var s = document.ModulesToInstall.elements[i].name;
            if (s.substring(0,len)==tag)
            {
               document.ModulesToInstall.elements[i].checked=false;
            }
         }
      }
   }


   function getSelectedModules()
   {
      var i = 0;
      var count = 0;
      var selectedItems = new Array();

      for(i=0; i<document.ModulesToInstall.elements.length; i++)
      {
         if (document.ModulesToInstall.elements[i].checked == true)
         {
            // Add it to the list
//            alert(document.ModulesToInstall.elements[i].value);
            if(document.ModulesToInstall.elements[i].value == "selectall")
            {
               continue;
            }
            selectedItems[count] = document.ModulesToInstall.elements[i].value;
            count++;
         }
      }
      return (pack(selectedItems));
   }



   function removeSelectedModules()
   {
      var i = 0;
      var count = 0;
      var selectedItems = new Array();

      for(i=0; i<document.ModulesToInstall.elements.length; i++)
      {
         if (document.ModulesToInstall.elements[i].checked == true)
         {
            // Add it to the list
            selectedItems[count] = document.ModulesToInstall.elements[i].value;
            count++;
         }
      }

      var strUrl = "webacc?NPService=<%= c.var("taskId") %>&moduleaction=Remove&selectedItems=" + pack(selectedItems);
      window.location.href = strUrl;

   }

    function installSelectedModules()
   {
      var sPackedModules = getSelectedModules();

      var strUrl = "webacc?NPService=<%= c.var("taskId") %>&moduleaction=PluginDependency&selectedItems=" + sPackedModules;
      window.location.href = strUrl;
   }


   function newModulesToCopy()
   {
      var strUrl = "webacc?NPService=<%= c.var("taskId") %>&moduleaction=SelectModulesToCopy&merge=ModulesToCopy";
      window.location.href = strUrl;
   }
	
  function showInfo(xmlname)
  {
      var url = "frameservice?NPService=fw.LaunchService&NPAction=Launch&launch=<%= c.var("taskId") %>&launcher=fw.LaunchService&lifecycle=New&repeatable=true&moduleaction=ShowInfo&xmlname="+xmlname;
      var date = new Date();
      url += "&unique=" + date.getTime();
      window.open(url, "InfoXml", "toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=500");
  } 

   </script>
</HEAD>
<BODY TEXT="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000" bgcolor="#FFFFFF">
<FORM name="ModulesToInstall" method="post" action="webacc">
   <input type=hidden name="NPService" value="<%= c.var("taskId" ) %>">
   <input type=hidden name="moduleaction" value="InstallModules">

   <!-- End of hidden tags -->

   <% c.set("TaskHeader.title", c.string("ModulesToInstall.ModulesToInstall"));
	   c.set("TaskHeader.iconUrl", "dir/object16.gif");
      c.set("TaskHeader.helpFile", "base/modulestoinstall.html");%>

   <jsp:include page='<%= c.getPath("dev/TaskHeader_inc.jsp") %>' flush="true" />

<%--	<div class="formdescriptextml0"><%= c.string("HomePage.NPMBody") %></div>--%>
<%--   <%--%>
<%--      String sError = (String)request.getAttribute( "ModulesError" );--%>
<%--      if( sError != null && sError.length() != 0 )--%>
<%--      { %>--%>
<%--         <table border="0" cellpadding="3" cellspacing="0">--%>
<%--            <tr>--%>
<%--                  <td>--%>
<%--                     <img ALIGN="absmiddle"--%>
<%--                        alt="<%= c.string( "Error" ) %>"--%>
<%--                        border="0"--%>
<%--                        src="<%= c.getModulesUrl() + "/dev/images/error32.gif" %>"/>--%>
<%--                  </td>--%>
<%--                  <td>--%>
<%--                     <div class="errormessage">--%>
<%--                        <%= sError %>--%>
<%--                     </div>--%>
<%--                  </td>--%>
<%--            </tr>--%>
<%--         </table>--%>
<%--   <% } %>--%>
   <table border="0" cellpadding="3" cellspacing="0">
      <tr>
         <td class="formdescriptextml0"><%= c.string("HomePage.NPMBody") %></td>
      </tr>
   </table>
   <br>
   <iman:messagebar />
	<TABLE width="100%" border="0" cellspacing="0" cellpadding="3">
      	<TR class="tablehead1">
      		<TD colspan="7"><%= c.string( "ModulesToInstall.NPM" ) %></TD>
 		</TR>
      <tr class="tablesubhead1">
         <td colspan="7">
            <a href="#" onClick="javascript:newModulesToCopy(); return false;">
               <%= c.string( "ModulesToInstall.New" ) %>
            </a>
            |
            <a href="#" onClick="javascript:installSelectedModules(); return false;">
               <%= c.string( "ModulesToInstall.Install" ) %>
            </a>
            |
            <a href="#" onClick="javascript:removeSelectedModules(); return false;">
               <%= c.string( "ModulesToInstall.Remove" ) %>
            </a>
            |
            <a href="webacc?NPService=<%= c.var("taskId") %>&moduleaction=Refresh">
               <%= c.string( "ModulesToInstall.Refresh" ) %>
            </a>
         </td>
      </tr>
		<tr class="tablesubhead1">
			<td style="border-bottom: 1px solid black; padding-left:7"  nowrap='true'><input onclick="checkboxSelect()" id="selectall" type="checkbox" name="selectall" value="selectall" title='<%= c.string( "ModulesToInstall.SelectAll" ) %>' alt='<%= c.string( "ModulesToInstall.SelectAll" ) %>'>
			<td style="border-bottom: 1px solid black; padding-left:7" nowrap='true'><%= c.string( "ModulesToInstall.Name" ) %></td>
            <td style="border-bottom: 1px solid black; padding-left:7" nowrap='true'><%= c.string( "ModulesToInstall.Version" ) %></td>
            <td style="border-bottom: 1px solid black; padding-left:7" nowrap='true'><%= c.string( "ModulesToInstall.Location" ) %></td>
			<td width="100%" style="border-bottom: 1px solid black; padding-left:7"  nowrap='true' colspan="7"><%= c.string( "ModulesToInstall.Description" ) %></td>
		</tr>
      <%
         ArrayList htModules = (ArrayList)request.getAttribute( "ModulesToInstall");
         if(htModules.size() > 0)
         {
            for(int i = 0; i < htModules.size(); i++)
            {
               ModuleInfo mInfo = (ModuleInfo)htModules.get(i);
               String sModuleID =  mInfo.getModuleID();
               String sFileName = mInfo.getFilename();
               if (!sFileName.equalsIgnoreCase("custom.npm"))
               {
                  String strUrl = mInfo.getUrl();
                  String strIsLocal = c.string( "ModulesToInstall.LocalDirectory");
                  if (!mInfo.isLocal())
                  {
                     strIsLocal = c.string( "ModulesToInstall.NovellDownloads");
                  }

                  out.write( "<tr class='smalltext' ><td style='padding-left:10'>"); %>
                  <input type="checkbox" name="Modules<%= i %>" value="<%= sModuleID %>">
                  <%
                  out.write( "</td><td nowrap='true' style='padding-left:10'>" + mInfo.getModuleTitle() + "</td><td style='padding-left:10'>" + mInfo.getModuleVersion() + "</td><td style='padding-left:10' nowrap='true' title='" + strUrl + "'>" + strIsLocal + "</td><td style='padding-left:10'>" + mInfo.getModuleDescription() + "</td>" );%>
                  
             	  <% String xmlname=mInfo.getInfo_url(); 
             	  	 if(xmlname!=null && xmlname!="")
             	  	 {
             	 %> 
             	  
             	  <td>    
                  <div class="margintop2"> 
                  <a href="#" onClick="javascript:showInfo('<%= xmlname %>'); return false;">
                  <img class="margin5r" src="<%= c.getModulesUrl() + "/dev/images/info_icon16.gif" %>" alt="Info about plugin" align="absmiddle" border="0"></a></div></td></tr>	                 
               <% }%>
               <%   
               }
            }
         }
         else
         {
		 	// Bug 199589 - Added message to be displayed if we get an error and can't contact the download site.
			boolean bool = ModuleGet.errorOnLastDescriptorDocDownload();
			if (bool == true)
			{
				out.write( "<tr><td colspan='5' style='padding:30'><i>" + c.string( "ModulesToInstall.NoModulesToInstallTimedOut" ) + "</i></td></tr>");
			}
			else
			{
				out.write( "<tr><td colspan='5' style='padding:30'><i>" + c.string( "ModulesToInstall.NoModulesToInstall" ) + "</i></td></tr>");
			}
            //out.write( "<tr><td colspan='5' style='padding:30'><i>" + c.string( "ModulesToInstall.NoModulesToInstall" ) + "</i></td></tr>");
         }
		 %>
      <tr>
         <jsp:include page='<%= c.getPath("dev/Bar_inc.jsp") %>' flush="true" />
      </tr>
      <tr>
         <a href="webacc?NPService=fw.LaunchService&NPAction=Return&returnID=<%= c.var("taskId") %>"><IMG src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Close.image") %>" border=0></a>
      </tr>
   </TABLE>


</FORM>
</BODY></HTML>

