<%@ page import="oracle.portal.provider.v1.*,oracle.portal.provider.v1.http.*,java.sql.*" %>

<%

    // The form submit URL refers to the current Portal page.  All portlets
    // on this page share this URL.  This means that the per portlet parameters
    // are in the same request.  Portlets must ensure that its paramerters don't
    // collide either with other portlets or other instances of itself.  This
    // is generally accomplished by using "fully-qualified" parameter names. A
    // fully-qualified parameter name prepends the (unique) portlet reference to
    // the parameter.  The JPDK provides a utility to accomplish this.

    String custName = HttpPortletRendererUtil.portletParameter(request, "myCustName");
    String companyName = HttpPortletRendererUtil.portletParameter(request, "myCompanyName");
    String feedbackText = HttpPortletRendererUtil.portletParameter(request, "myFeedbackText");
    String submitFeedback = HttpPortletRendererUtil.portletParameter(request, "mySubmitFeedback");

%>

This Feedback portlet accepts your valuable feedback. <p> 
<p>

<form name="feedback" method="POST" action="<%= HttpPortletRendererUtil.htmlFormActionLink(request,PortletRendererUtil.PAGE_LINK) %>" >

<%= HttpPortletRendererUtil.htmlFormHiddenFields(request,PortletRendererUtil.PAGE_LINK) %>


<b> 
<%
    if (request.getParameter(submitFeedback) != null )
    {
%>
       <%= insertFeedback(request.getParameter(custName), request.getParameter(companyName), request.getParameter(feedbackText))  %>
<%
    }
%>
</b>

<label> Customer Name: <input type="text" size="30" name="<%= custName %>" value=""  > </label> <br>
<label> Company Name: <input type="text" size="30" name="<%= companyName %>" value=""  > </label> <br>
<b>Provide your feedback below:</b> <br>
<textarea cols="42" rows=4 name="<%= feedbackText %>" value="" wrap=virtual > </textarea> <br>
<input type=submit name="<%= submitFeedback %>" value="Submit your feedback" > 
</form>

<%! private String insertFeedback(String custName, String compName, String fbText) throws SQLException {
        Connection conn = null;
        PreparedStatement stmt = null;
        String retStr =  "<P> Feedback not saved! </P> \n";
        try {

            // Load the Driver
            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

            // Get a Thin JDBC Connection. You need to change the code to point
            // to your host name, port number, and Oracle SID. The 
            // username/password created by the SQl script is feedback/feedback.
            conn = DriverManager.getConnection("jdbc:oracle:thin:@ncnc-sun8.us.oracle.com:1521:ORA816", "feedback", "feedback");

            // To improve performance, don't commit automatically
            conn.setAutoCommit(false);

            // Prepare the INSERT statement for the FEEDBACK_DETAILS table
            stmt = conn.prepareStatement("INSERT INTO FEEDBACK_DETAILS( CUSTOMER_NAME, COMPANY_NAME, FEEDBACK_TEXT) values (?, ?, ? ) " );
            
            stmt.setString(1, custName );
            stmt.setString(2, compName );
            stmt.setString(3, fbText );

            // Execute the Prepared statement to check number of rows inserted
            if (stmt.executeUpdate() == 1) {
                retStr =  "<P> Feedback saved! </P> \n";
            }
        } catch (SQLException e )  {
            retStr = "<P> SQL Error: <PRE> " + e + " </PRE> </P> \n";

        } finally  {
            if (stmt != null) stmt.close();
            if (conn != null) conn.close();
            return(retStr);
        }
    }
%>
