/*
 * Created on 28-Apr-2006
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package uk.ac.roe.wfau;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;



/**
 * @author mar
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ShowCols {
    static String startCell="<td align=\"right\" nowrap=\"nowrap\">";
    static String endCell="</td> \n";
    static String displayURL=WSAHTMLSchema.baseCGIURL+"display.cgi?";
    static String GIURL=WSAHTMLSchema.baseJSPURL+"GetImage?mode=show&";
    public static boolean areColsInRS(String [] strArr, ResultSetMetaData rsmd) {
        boolean [] present = new boolean [strArr.length];
        for (int i=0;i < present.length;i++) {
            present[i]=false;
        }
        try {
        for (int i=1;i<=rsmd.getColumnCount();i++) {
            for (int j=0;j<strArr.length;j++) {
                if (strArr[j].equalsIgnoreCase(rsmd.getColumnName(i))) {
                    present[j]=true;
                }
            }
        }
        for (int i=0;i < present.length;i++) {
            if (!present[i]) {
                return false;
            }
        }
        
        return true;
        } catch (SQLException se ){
            return false;
        }
    }
    
    
   
    
    public static String getMFLinkCell(ResultSet rs) {
        StringBuffer tempSB=new StringBuffer(startCell);
        try {
        String compFile=rs.getString("compfile");
        String comp=compFile.substring(0,Math.max(0,compFile.lastIndexOf('_')));
        tempSB.append("<a href=\""+displayURL+"file="+rs.getString("filename")+"&multiframeid="+
                rs.getString("multiframeid")+"&noExt="+rs.getString("numDetectors")+
                "&comp="+comp+"\" target=display>view<a/>");
        tempSB.append(endCell);
        return tempSB.toString();
        } 
        catch (SQLException se ){
            return "&nbsp;";
        }
        /*
        <td align=\"right\" nowrap=\"nowrap\">"
        + "<input type=checkbox name=ch value=\"" + strArray[RACol].trim() + ":"
        + strArray[DecCol].trim() + "\">" + "</td> \n");
        */
        
    }
    public static String getGIFLinkCell(ResultSet rs,String database) {
        StringBuffer tempSB=new StringBuffer(startCell);
        try {
        
        tempSB.append("<a href=\""+GIURL+"ra="+rs.getString("ra")+"&dec="+
                rs.getString("dec")+"&fsid="+rs.getString("framesetID")+"&database="+database+"\" target=getI>view<a/>");
        tempSB.append(endCell);
        return tempSB.toString();
        } 
        catch (SQLException se ){
            return "&nbsp;";
        }
  
        
    }
    public static String getGIMLinkCell(ResultSet rs,String database) {
        StringBuffer tempSB=new StringBuffer(startCell);
        try {
        
        tempSB.append("<a href=\""+GIURL+"ra="+rs.getString("ra")+"&dec="+
                rs.getString("dec")+"&mfid="+rs.getString("multiframeID")+"&database="+database+"\" target=getI>view<a/>");
        tempSB.append(endCell);
        return tempSB.toString();
        } 
        catch (SQLException se ){
            return "&nbsp;";
        }
  
        
    }

}
