<%-- 
  Copyright 2003 Sun Microsystems, Inc. All rights reserved. 
  Use is subject to license terms.
 --%> 
<%@ page import="java.util.Enumeration" %>
<%@ page import="java.util.*" %>
<%@ page import="com.iplanet.sso.SSOTokenManager" %>
<%@ page import="com.iplanet.sso.SSOToken" %>
<%@ page import="com.sun.identity.sm.ServiceSchema" %>
<%@ page import="com.sun.identity.sm.ServiceSchemaManager" %>
<%@ page import="com.sun.identity.sm.AttributeSchema" %>
<%@ page import="com.iplanet.am.sdk.AMStoreConnection" %>
<%@ page import="com.iplanet.am.sdk.AMException" %>
<%@ page import="com.iplanet.sso.SSOException" %>
<%@ page import="com.iplanet.am.sdk.AMUser"%>
<%@ page import="com.sun.portal.search.soif.SOIF"%>
<%@ page import="com.sun.portal.providers.*, 
		com.sun.portal.providers.context.*,
		 com.sun.portal.providers.jsp.JSPProvider,
		 com.sun.portal.search.util.Decoder,
		 com.sun.portal.search.util.Encoder"%>
<%@ page import="com.sun.portal.subscriptions.providers.*"%>

<%@ taglib uri="/tld/jx.tld" prefix="jx" %>
<%@ taglib uri="/tld/desktop.tld" prefix="dt" %>
<%@ taglib uri="/tld/desktopProviderContext.tld" prefix="dtpc" %>
<%@ taglib uri="/tld/desktopTheme.tld" prefix="dttheme" %>

<dt:obtainChannel channel="$JSPProvider">
<dtpc:providerContext>
    <dttheme:getAttribute name="titleBarColor" id="subSectionTitle" scope="request"/> 
    <dttheme:getAttribute name="borderColor" id="subSectionHeader" scope="request"/> 
    <jx:declare id="subSectionTitle" type="java.lang.String"/>
    <jx:declare id="subSectionHeader" type="java.lang.String"/>
    <STYLE type="text/css">
        .subSectionTitle { background: <dttheme:getAttribute name="tabColor" default="#C0C0C0"/>; 
                           color: <dttheme:getAttribute name="tabFontColor" default="#000000"/>;
                           font-size:large; font-weight: bold;}
        .subSectionHeader { background:  <dttheme:getAttribute name="titleBarColor"/>; 
                            color: <dttheme:getAttribute name="titleFontColor" default="#000000"/>;
                            font-weight: bold;}
        .newSubscription {border-bottom: thin solid <dttheme:getAttribute name="titleBarColor"/> }
        .newSubscriptionError {border-bottom: thin solid red; background: red}
        .newSpan {border: thin solid red}
    </STYLE>

<dtpc:getStringProperty key="fontFace1" id="fontFace"/>
<jx:declare id="fontFace" type="java.lang.String"/>

<%
AMUser user = null;
Set categoriesSet = null;
Set discussionsSet = null;
Set savedSearchSet = null;
SearchSubscription subItem = null;
HashMap subElements = null;

boolean subscriptionsService = false;
try { 
    SSOTokenManager mgr = SSOTokenManager.getInstance(); 
    SSOToken token = mgr.createSSOToken(request);
    pageContext.setAttribute("accessToken", token); 
    if (token !=null) {
        AMStoreConnection amstore = new AMStoreConnection(token);
        user = amstore.getUser(token.getPrincipal().getName() );
        subscriptionsService = user.getAssignedServices().contains("SunPortalSubscriptionsService");
            categoriesSet = (Set) user.getAttribute("sunPortalCategorySubscriptions");
            discussionsSet = (Set) user.getAttribute("sunPortalDiscussionSubscriptions");
            savedSearchSet = (Set) user.getAttribute("sunPortalSavedSearch");
    } else {
            %><dtpc:logError value="SSO Token problem"/><%
    } 
} catch (Exception e) {
    %><dtpc:logError value="Cannot get user's subscriptions of its profile"/><%
}
if ((user == null) || (subscriptionsService == false)) {
    if (user == null) {
        %><b>Only registered users may use the subscription service. Please register.</b><%
    } else if (subscriptionsService == false) {
        %><b>You do not have access to the subscription service.<br>
                Please refer to the administrator to assign the susbscription service to your profile.</b>
        <%
    }
}else {
%>
<table  border="0"  width="100%" cellpadding="1" cellspacing="0" > <%-- top level table --%>
    <tr>
        <td valign="top" align="left" colspan="6" class="subSectionTitle">Categories</td>
    </tr>
    <%
    int catNdx = 0;
    int maxCat = 0;
    try {
        maxCat =  Integer.parseInt((String) ((Set) user.getAttribute("sunPortalMaxCategorySubscriptions")).iterator().next());
    } catch (Exception e) {
        %>exception in getting max Categories<%
    }
    if (categoriesSet != null) {
        if ((categoriesSet.size() > 0) || (request.getParameter("newCatSubscription") != null)) {
            Iterator categoryIterator = categoriesSet.iterator();
            String catName = null;
            String catTarget = null;
            String catScope = null;
            String catSince = "0";
            String catRating = null;
            String catServer = null;
            String catDatabase = null;
%>
    <tr>
        <%
        if (categoriesSet.size() > 0) {
        %>
        <td class="subSectionHeader">unsubscribe</td>
        <%} else {%>
        <td class="subSectionHeader"><br></td>
        <%}%>
        <td class="subSectionHeader">name</td>
        <td class="subSectionHeader">query</td>
        <td class="subSectionHeader">since</td>
        <td class="subSectionHeader">category</td>
        <td class="subSectionHeader">rating</td>
    </tr>
<%
            while (categoryIterator.hasNext()) {
                String catSubStr = (String) categoryIterator.next();
                catNdx++;
                if (catNdx > maxCat) break;
                    subItem = new SearchSubscription("http://panoramic.red.iplanet.com/portal/search",
                                    Subscription.CATEGORY_SRCH_SUB, catSubStr,
                                    "hl-url,hl-title,title,hl-description,score,classification,hl-classification,rd-rating");
                    subItem.parse();
                    subElements = subItem.getElements();
                    catName = (String) subElements.get("name");
                    catTarget = (String) subElements.get("target");
                    catScope = (String) subElements.get("scope");
                    catSince = (String) subElements.get("since");
                    catRating = (String) subElements.get("rating");
                    catServer = (String) subElements.get("server");
                    catDatabase = (String) subElements.get("database");
%>
    <tr>
        <td align="left" width="1%" nowrap="nowrap">
            <input type="checkbox" name="_unsub_cat_<%=catNdx%>">&nbsp
        </td>
        <td align="left" width="1%" nowrap="nowrap">
             <input type="text" name="_rename_cat_<%=catNdx%>" size="20" value="<%=Encoder.htmlEncode(catName)%>">
        </td>
        <td align="left" width="1%" nowrap="nowrap">
            <input type="text" name="_rescope_cat_<%=catNdx%>" size="20" value="<%=Encoder.htmlEncode(catScope)%>">
        </td>
        <td align="left" width="1%" nowrap="nowrap">
            <select name="_resince_cat_<%=catNdx%>" >
                <option value="0" 
                <% if (catSince.equals("0")) {%> selected="selected"<%}%>>
                forever</option>
                <option  value="7"  
                <% if (catSince.equals("7")) {%> selected="selected"<%}%>>
                last week</option>
                <option  value="30"  
                <% if (catSince.equals("30")) {%> selected="selected"<%}%>>
                last month</option>
                <option value="180"  
                <% if (catSince.equals("180")) {%> selected="selected"<%}%>>
                last 6 months</option>
                <option value="365"  
                <% if (catSince.equals("365")) {%> selected="selected"<%}%>>
                last year</option>
            </select>
        </td>
        <td align="left" width="1%" nowrap="nowrap">
            <input type="text" name="_retarget_cat_<%=catNdx%>" size="20" value="<%=Encoder.htmlEncode(catTarget)%>">
        </td>
        <td align="left" width="1%" nowrap="nowrap">
            <select name="_rerate_cat_<%=catNdx%>" >
                <option value="-1" 
                    <% if (catRating.equals("-1")) {%> selected="selected"<%}%>>
                Irrelevant</option>
                <option  value="0"  
                    <% if (catRating.equals("0")) {%> selected="selected"<%}%>>
                Routine</option>
                <option  value="1"  
                    <% if (catRating.equals("1")) {%> selected="selected"<%}%>>
                Interesting</option>
                <option value="2"  
                    <% if (catRating.equals("2")) {%> selected="selected"<%}%>>
                Important</option>
                <option value="3"  
                    <% if (catRating.equals("3")) {%> selected="selected"<%}%>>
                Must read</option>
            </select>
        </td>
        <input type="hidden" name="_reserver_cat_<%=catNdx%>" value="<%=catServer%>">
        <input type="hidden" name="_redatabase_cat_<%=catNdx%>" value="<%=catDatabase%>">
    </tr>
<%
            } // end of while on categories
            String newCatSubscription = (String) request.getParameter("newCatSubscription");
            String newServer = (String) request.getParameter("newServer");
            String newDB = (String) request.getParameter("newDB");

            if (newCatSubscription != null) {
                    if (catNdx < maxCat) {
                        //adding a new line for the user to store in his new category
                        %>
    <tr>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
            new subscription
        </td>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
             <input type="text" name="_new_name_cat" size="20" value="">
        </td>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
        <%
        String _new_scope_cat = (String) request.getParameter("scope");
        if (_new_scope_cat == null) _new_scope_cat = "";
        %>
            <input type="text" name="_new_scope_cat" size="20" value='<%=Encoder.htmlEncode(_new_scope_cat)%>'>
        </td>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
            <select name="_new_since_cat" >
                <option value="0" 
                <% if (catSince.equals("0")) {%> selected="selected"<%}%>>
                forever</option>
                <option  value="7"  
                <% if (catSince.equals("7")) {%> selected="selected"<%}%>>
                last week</option>
                <option  value="30"  
                <% if (catSince.equals("30")) {%> selected="selected"<%}%>>
                last month</option>
                <option value="180"  
                <% if (catSince.equals("180")) {%> selected="selected"<%}%>>
                last 6 months</option>
                <option value="365"  
                <% if (catSince.equals("365")) {%> selected="selected"<%}%>>
                last year</option>
            </select>
        </td>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
            <input type="text" name="_new_target_cat" size="20" value="<%=Encoder.htmlEncode(newCatSubscription)%>">
        </td>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
            <select name="_new_rating_cat" >
                <option value="-1">Irrelevant</option>
                <option  value="0" selected="selected">Routine</option>
                <option  value="1">Interesting</option>
                <option value="2">Important</option>
                <option value="3">Must Read</option>
                </select>
        </td>
        <input type="hidden" name="newServer" size="20" value="<%=Encoder.htmlEncode(newServer)%>">
        <input type="hidden" name="newDB" size="20" value="<%=Encoder.htmlEncode(newDB)%>">

    </tr>
<%
                    } else {
%>
    <tr>
        <td colspan="6" class="newSubscriptionError">You have reached the maximum number of category subscriptions.</td>
    </tr>
<%
                    }
            }
        } else {// end if categorySet has at least one
%>
    <tr>
        <td colspan="6" >No category subscriptions</td>
    </tr>
<%
        }
    } else {
%>
    <tr>
        <td colspan="6" >No category subscriptions</td>
    </tr>
<%
    }
%>
    <tr><td width="1%" nowrap="nowrap">&nbsp;</td></tr>
    <tr>
        <td valign="top" align="left" colspan="6" class="subSectionTitle">Discussions</td>
    </tr>
<%
    int discNdx = 0;
    int maxDisc = 0;
    try {
        maxDisc =  Integer.parseInt((String) ((Set) user.getAttribute("sunPortalMaxDiscussionSubscriptions")).iterator().next());
    } catch (Exception e) {
            %>exception in getting max Disc<%
    }
    if (discussionsSet != null) {
        if ((discussionsSet.size() > 0) || (request.getParameter("newDiscSubscription") != null)) {
            Iterator discussionIterator = discussionsSet.iterator();
            String discName = null;
            String discTarget = null;
            String discScope = null;
            String discSince = "0";
            String discRating = "0";
            String discServer = null;
            String discDatabase = null;
%>
    <tr>
        <%
        if (discussionsSet.size() > 0) {
        %>
        <td class="subSectionHeader">unsubscribe</td>
        <%} else {%>
        <td class="subSectionHeader"><br></td>
        <%}%>
        <td class="subSectionHeader">name</td>
        <td class="subSectionHeader">query</td>
        <td class="subSectionHeader">since</td>
        <td class="subSectionHeader"><br></td>
        <td class="subSectionHeader">rating</td>
    </tr>
<%
            while (discussionIterator.hasNext()) {
                    String discSubStr = (String) discussionIterator.next();
                    discNdx++;
                    if (discNdx > maxDisc) break;
                        subItem = new SearchSubscription("http://panoramic.red.iplanet.com/portal/search",
                                Subscription.DISCUSSION_SRCH_SUB, discSubStr,
                                "hl-url,hl-title,title,hl-description,score,classification,hl-classification,rd-rating,hl-rd-reference-id, rd-reference-id");
                        subItem.parse(); 
                        subElements = subItem.getElements();
                        discName = (String) subElements.get("name");
                        discTarget = (String) subElements.get("target");
                        discScope = (String) subElements.get("scope");
                        discRating = (String) subElements.get("rating");
                        discSince = (String) subElements.get("since");
                        discServer = (String) subElements.get("server");
                        discDatabase = (String) subElements.get("database");
%>
    <tr>
        <td align="left" width="1%" nowrap="nowrap">
                <input type="checkbox" name="_unsub_disc_<%=discNdx%>">&nbsp
        </td>
        <td align="left" width="1%" nowrap="nowrap">
            <input type="text" name="_rename_disc_<%=discNdx%>" size="20" value="<%=Encoder.htmlEncode(discName)%>">
            <input type="hidden" name="_retarget_disc_<%=discNdx%>" size="20" value="<%=discTarget%>">
        </td>
        <td align="left" width="1%" nowrap="nowrap">
            <input type="text" name="_rescope_disc_<%=discNdx%>" size="20" value="<%=Encoder.htmlEncode(discScope)%>">
        </td>
        <td align="left" width="1%" nowrap="nowrap">
            <select name="_resince_disc_<%=discNdx%>" >
                <option value="0" 
                <% if (discSince.equals("0")) {%> selected="selected"<%}%>>
                forever</option>
                <option  value="7"  
                <% if (discSince.equals("7")) {%> selected="selected"<%}%>>
                last week</option>
                <option  value="30"  
                <% if (discSince.equals("30")) {%> selected="selected"<%}%>>
                last month</option>
                <option value="180"  
                <% if (discSince.equals("180")) {%> selected="selected"<%}%>>
                last 6 months</option>
                <option value="365"  
                <% if (discSince.equals("365")) {%> selected="selected"<%}%>>
                last year</option>
            </select>
        </td>
        <td width="1%" nowrap="nowrap">&nbsp;</td>
        <td align="left" width="1%" nowrap="nowrap">
            <select name="_rerate_disc_<%=discNdx%>" >
                <option value="-1" 
                <% if (discRating.equals("-1")) {%> selected="selected"<%}%>>
                Irrelevant</option>
                <option  value="0"  
                <% if (discRating.equals("0")) {%> selected="selected"<%}%>>
                Routine</option>
                <option  value="1"  
                <% if (discRating.equals("1")) {%> selected="selected"<%}%>>
                Interesting</option>
                <option value="2"  
                <% if (discRating.equals("2")) {%> selected="selected"<%}%>>
                Important</option>
                <option value="3"  
                <% if (discRating.equals("3")) {%> selected="selected"<%}%>>
                Must Read</option>
            </select>
        </td>
        <input type="hidden" name="_reserver_disc_<%=discNdx%>" value="<%=discServer%>">
        <input type="hidden" name="_redatabase_disc_<%=discNdx%>" value="<%=discDatabase%>">
    </tr>
<%
            } // end of while on discussions
                String newDiscSubscription = (String) request.getParameter("newDiscSubscription");
                String newDiscTitle = (String) request.getParameter("newDiscTitle");
                String scope = (String) request.getParameter("scope");
                String newServer = (String) request.getParameter("newServer");
                String newDB = (String) request.getParameter("newDB");
                if (newDiscSubscription != null) {
                    if (discNdx < maxDisc) {
                        //adding a new line for the user to store in his new discussion
%>
    <tr>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
            new subscription
        </td>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
            <input type="text" name="_new_name_disc" size="20" value="<%=Encoder.htmlEncode(newDiscTitle)%>">
            <input type="hidden" name="_new_target_disc" size="20" value="<%=Encoder.htmlEncode(newDiscSubscription)%>">
        </td>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
        <%
        if (scope == null) scope = "";
        %>
            <input type="text" name="_new_scope_disc" size="20" value="<%=Encoder.htmlEncode(scope)%>">
        </td>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
            <select name="_new_since_disc" >
                <option value="0" 
                <% if (discSince.equals("0")) {%> selected="selected"<%}%>>
                forever</option>
                <option  value="7"  
                <% if (discSince.equals("7")) {%> selected="selected"<%}%>>
                last week</option>
                <option  value="30"  
                <% if (discSince.equals("30")) {%> selected="selected"<%}%>>
                last month</option>
                <option value="180"  
                <% if (discSince.equals("180")) {%> selected="selected"<%}%>>
                last 6 months</option>
                <option value="365"  
                <% if (discSince.equals("365")) {%> selected="selected"<%}%>>
                last year</option>
            </select>
        </td>
        <td width="1%" nowrap="nowrap" class="newSubscription">&nbsp;</td>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
            <select name="_new_rate_disc" >
                <option value="-1">Irrelevant</option>
                <option  value="0"  selected="selected">Routine</option>
                <option  value="1">Interesting</option>
                <option value="2">Important</option>
                <option value="3">Must Read</option>
                </select>
        </td>
        <input type="hidden" name="newServer" size="20" value="<%=Encoder.htmlEncode(newServer)%>">
        <input type="hidden" name="newDB" size="20" value="<%=Encoder.htmlEncode(newDB)%>">

    </tr>
<%
                    } else {
%>
    <tr>
        <td colspan="6" class="newSubscriptionError">You have reached the maximum number of discussion subscriptions.</td>
    </tr>
<%
                }
            }
        } else {// end if discussionsSet has at least one
%>
    <tr>
        <td colspan="6" >No discussion subscriptions</td>
    </tr>
<%
        }
    } else {
%>
    <tr>
        <td colspan="6" >No discussion subscriptions</td>
    </tr>
<%
    }
%>
    <tr><td width="1%" nowrap="nowrap">&nbsp;</td></tr>
    <tr>
        <td valign="top" align="left" colspan="6" class="subSectionTitle">Saved Searches</td>
    </tr>
<%
    int savedSearchNdx = 0;
    int maxSavedSearch = 0;
    try {
        maxSavedSearch =  Integer.parseInt((String) ((Set) user.getAttribute("sunPortalMaxSavedSearch")).iterator().next());
    } catch (Exception e) {
        %>exception in getting max saved search<%
    }
    if (savedSearchSet != null) {
        if ((savedSearchSet.size() > 0) || (request.getParameter("newSavedSearchSubscription") != null)) {
            Iterator savedSearchIterator = savedSearchSet.iterator();
            String savedSearchName = null;
            String savedSearchScope = null;
            String savedSearchSince = "0";
            String savedSearchRating = "0";
            String savedSearchServer = null;
            String savedSearchDatabase = null;
%>
    <tr>
            <%
            if (savedSearchSet.size() > 0) {
            %>
        <td class="subSectionHeader">unsubscribe</td>
            <%} else {%>
        <td class="subSectionHeader"><br></td>
            <%}%>
        <td class="subSectionHeader">name</td>
        <td class="subSectionHeader">query</td>
        <td class="subSectionHeader">since</td>
        <td class="subSectionHeader"><br></td>
        <td class="subSectionHeader">rating</td>
    </tr>
        <%
            while (savedSearchIterator.hasNext()) {
                String savedSearchSubStr = (String) savedSearchIterator.next();
                savedSearchNdx++;
                if (savedSearchNdx > maxSavedSearch) break;
                    subItem = new SearchSubscription("http://panoramic.red.iplanet.com/portal/search",
                            Subscription.SAVED_SRCH_SUB, savedSearchSubStr,
                            "hl-url,hl-title,title,hl-description,score,classification,hl-classification,rd-rating");
                    subItem.parse(); 
                    subElements = subItem.getElements();

                    savedSearchName = (String) subElements.get("name");
                    savedSearchScope = (String) subElements.get("scope");
                    savedSearchSince = (String) subElements.get("since");
                    savedSearchRating = (String) subElements.get("rating");
                    savedSearchServer = (String) subElements.get("server");
                    savedSearchDatabase =  (String) subElements.get("database");
                %>
    <tr>
        <td align="left" width="1%" nowrap="nowrap">
            <input type="checkbox" name="_unsub_savedSearch_<%=savedSearchNdx%>">&nbsp
        </td>
        <td align="left" width="1%" nowrap="nowrap">
            <input type="text" name="_rename_savedSearch_<%=savedSearchNdx%>" size="20" value="<%=Encoder.htmlEncode(savedSearchName)%>">
        </td>
        <td align="left" width="1%" nowrap="nowrap">
            <input type="text" name="_rescope_savedSearch_<%=savedSearchNdx%>" size="20" value="<%=Encoder.htmlEncode(savedSearchScope)%>">
        </td>
        <td align="left" width="1%" nowrap="nowrap">
            <select name="_resince_savedSearch_<%=savedSearchNdx%>" >
                <option value="0" 
                <% if (savedSearchSince.equals("0")) {%> selected="selected"<%}%>>
                forever</option>
                <option  value="7"  
                <% if (savedSearchSince.equals("7")) {%> selected="selected"<%}%>>
                last week</option>
                <option  value="30"  
                <% if (savedSearchSince.equals("30")) {%> selected="selected"<%}%>>
                last month</option>
                <option value="180"  
                <% if (savedSearchSince.equals("180")) {%> selected="selected"<%}%>>
                last 6 months</option>
                <option value="365"  
                <% if (savedSearchSince.equals("365")) {%> selected="selected"<%}%>>
                last year</option>
            </select>
        </td>
        <td width="1%" nowrap="nowrap">&nbsp;</td>
        <td align="left" width="1%" nowrap="nowrap">
            <select name="_rerate_savedSearch_<%=savedSearchNdx%>" >
                <option value="-1" 
                    <% if (savedSearchRating.equals("-1")) {%> selected="selected"<%}%>>
                Irrelevant</option>
                <option  value="0"  
                    <% if (savedSearchRating.equals("0")) {%> selected="selected"<%}%>>
                Routine</option>
                <option  value="1"  
                    <% if (savedSearchRating.equals("1")) {%> selected="selected"<%}%>>
                Interesting</option>
                <option value="2"  
                    <% if (savedSearchRating.equals("2")) {%> selected="selected"<%}%>>
                Important</option>
                <option value="3"  
                    <% if (savedSearchRating.equals("3")) {%> selected="selected"<%}%>>
                Must read</option>
            </select>
        </td>
        <input type="hidden" name="_reserver_savedSearch_<%=savedSearchNdx%>" value="<%=savedSearchServer%>">
        <input type="hidden" name="_redatabase_savedSearch_<%=savedSearchNdx%>" value="<%=savedSearchDatabase%>">
        <td width="1%" align="left" nowrap="nowrap"><br></td>
    </tr>
<%
            } // end of while on saved searches
            String newSavedSearchSubscription = (String) request.getParameter("newSavedSearchSubscription");
            String newSavedSearchTitle = (String) request.getParameter("title");
            String newServer = (String) request.getParameter("newServer");
            String newDB = (String) request.getParameter("newDB");
            if (newSavedSearchSubscription != null) {
                if (savedSearchNdx < maxSavedSearch) {
                    //adding a new line for the user to store in his new saved search
%>
    <tr>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
            new subscription
        </td>
<%
                    if (newSavedSearchSubscription == null) newSavedSearchSubscription = "";
                    if (newSavedSearchTitle == null) newSavedSearchTitle = "";
%>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
             <input type="text" name="_new_name_savedSearch" size="20" value="<%=Encoder.htmlEncode(newSavedSearchTitle)%>">
        </td>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
            <input type="text" name="_new_scope_savedSearch" size="20" value="<%=Encoder.htmlEncode(newSavedSearchSubscription)%>">
        </td>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
            <select name="_new_since_savedSearch" >
                <option value="0" 
                <% if (savedSearchSince.equals("0")) {%> selected="selected"<%}%>>
                forever</option>
                <option  value="7"  
                <% if (savedSearchSince.equals("7")) {%> selected="selected"<%}%>>
                last week</option>
                <option  value="30"  
                <% if (savedSearchSince.equals("30")) {%> selected="selected"<%}%>>
                last month</option>
                <option value="180"  
                <% if (savedSearchSince.equals("180")) {%> selected="selected"<%}%>>
                last 6 months</option>
                <option value="365"  
                <% if (savedSearchSince.equals("365")) {%> selected="selected"<%}%>>
                last year</option>
            </select>
        </td>
        <td width="1%" nowrap="nowrap" class="newSubscription">&nbsp;</td>
        <td align="left" width="1%" nowrap="nowrap" class="newSubscription">
            <select name="_new_rate_search" >
                <option value="-1">Irrelevant</option>
                <option  value="0" selected="selected">Routine</option>
                <option  value="1">Interesting</option>
                <option value="2">Important</option>
                <option value="3">Must Read</option>
                </select>
        </td>
        <td width="1%" align="left" nowrap="nowrap" class="newSubscription"><br></td>
        <input type="hidden" name="newServer" size="20" value="<%=Encoder.htmlEncode(newServer)%>">
        <input type="hidden" name="newDB" size="20" value="<%=Encoder.htmlEncode(newDB)%>">

    </tr>
<%
                } else {
%>
    <tr>
        <td colspan="6" class="newSubscriptionError">You have reached the maximum number of saved search subscriptions.</td>
    </tr>
<%
                }
            }
        } else {// end if savedSearchSet has at least one
%>
    <tr>
        <td colspan="6">No saved search subscriptions</td>
    </tr>
<%
        }
    } else {
%>
    <tr>
        <td colspan="6">No saved search subscriptions</td>
    </tr>
<%
    }
%>
</table> <%-- end of main table --%>
<%
} // end of else : user is rightfully using discussion edit channel
%>
</dtpc:providerContext>
</dt:obtainChannel>
</center>
