<% /** * $RCSfile: post.jsp,v $ * $Revision: 1.2 $ * $Date: 2012/10/12 05:44:29 $ */ %> <%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %> <%@ taglib uri="struts-bean" prefix="bean" %> <%@ page import="com.Yasna.forum.*, com.Yasna.forum.util.*, com.Yasna.util.*" errorPage="errorforum.jsp" %> <%@ page contentType="text/html; charset=iso-8859-1"%> <%String contextpaths=request.getContextPath(); %> Common Template
<% int forumID=1; int threadID=1;int messageID=1; boolean reply=false; String name= ""; String email=""; String subject=""; String body = ""; String referringPage = ""; String productType=""; String mobileNo=""; boolean doPost=false; String keyparam=(String) request.getParameter("keyparam"); //out.println("keyparam-->"+keyparam); if(keyparam==null) { keyparam=""; } //////////////////////// // Authorization check // check for the existence of an authorization token Authorization authToken = SkinUtils.getUserAuthorization(request,response); // if the token was null, they're not authorized. Since this skin will // allow guests to view forums, we'll set a "guest" authentication // token if( authToken == null ) { out.print("authToken"); authToken = AuthorizationFactory.getAnonymousAuthorization(); } %> <% /////////////////////// // page forum variables // do not delete these ForumFactory forumFactory = ForumFactory.getInstance(authToken); User user = forumFactory.getProfileManager().getUser(authToken.getUserID()); %> <% ///////////////// // get parameters String key=(String) request.getParameter("key"); //System.out.println("key--->"+key); if(key==null||key.equalsIgnoreCase("")) { key=""; } try{ if(key=="key" || key.equalsIgnoreCase("key")){ String f1=(String)request.getParameter("forum"); if(f1==null) f1="1"; forumID=Integer.parseInt(f1); //out.println("forumID--->"+forumID); String t1=(String)request.getParameter("thread"); if(t1==null) t1="1"; threadID=Integer.parseInt(t1); String m1=(String)request.getParameter("message"); if(m1==null) m1="1"; messageID=Integer.parseInt(m1); } else{ forumID = ParamUtils.getIntParameter(request,"forum",-1); threadID = ParamUtils.getIntParameter(request,"thread",-1); messageID = ParamUtils.getIntParameter(request,"message",-1); } doPost = ParamUtils.getBooleanParameter(request,"doPost"); reply = ParamUtils.getBooleanParameter(request,"reply"); name = ParamUtils.getParameter(request,"name"); email = ParamUtils.getParameter(request,"email"); subject = ParamUtils.getParameter(request,"subject"); body = ParamUtils.getParameter(request,"body"); referringPage = ParamUtils.getParameter(request,"referer"); productType=ParamUtils.getParameter(request,"productType"); mobileNo=ParamUtils.getParameter(request,"mobileNo"); }catch(NumberFormatException e){ System.out.print(e.getMessage()); } %> <% /////////////////////////////////////// // Create forum, parent message objects // Load the forum -- if an exception is thrown, we'll redirect to // the error page Forum forum = forumFactory.getForum(forumID); // Load the forum message and thread it is associated with. Do // this only if we're replying to a message ForumThread thread = null; ForumMessage parentMessage = null; if( reply ) { thread = forum.getThread(threadID); parentMessage = thread.getMessage(messageID); } %> <% ///////////////// // error check boolean errors = false; String errorMessage = ""; if( doPost && subject == null ) { errors = true; //out.println(""); errorMessage = "Please enter a subject"; } else if( doPost && body == null ) { errors = true; errorMessage = "Sorry, you can't post a blank message. Please enter a message."; } %> <% ///////////////////////// // Create the new message if( doPost && !errors ) { // Create a new message object ForumMessage newMessage = forum.createMessage(user); newMessage.setSubject(subject); newMessage.setBody(body); newMessage.setproductType(productType); // add the name and email as an extended property if this user // is a guest if( user.isAnonymous() ) { if( name != null ) { newMessage.setProperty("name",name); SkinUtils.store(request,response,"yazd.post.name",name); } if( email != null ) { newMessage.setProperty("email",email); SkinUtils.store(request,response,"yazd.post.email",email); } if( mobileNo != null ) { newMessage.setProperty("mobileNo",mobileNo); SkinUtils.store(request,response,"yazd.post.mobile",mobileNo); } try{ if( productType != null ) { newMessage.setProperty("productType",productType); SkinUtils.store(request,response,"yazd.post.productType",productType); } }catch(Exception e){ e.printStackTrace(); } } // if this is a reply, add it to the thread if( reply ) { thread.addMessage(parentMessage,newMessage); } else { // it is a new posting forum.addThread(forum.createThread(newMessage)); } response.sendRedirect("viewForum.do?forum="+forumID); return; } %> <% ////////////////////// // Header file include // The header file looks for the variable "title" String title = "Yazd Forums: Post a message"; %> <% ////////////////////// // breadcrumb variable // load up different breadcrumbs based on if this is a reply to a message // or a new post. String[][] breadcrumbs = null; if( reply ) { breadcrumbs = new String[][] { { "Home", "home.do" }, { forum.getName(), ("viewForum.do?forum=" + forumID) }, { thread.getName(), ("viewThread.do?forum=" + forumID + "&thread=" + threadID) }, { "Reply to Message", "" } }; } else { breadcrumbs = new String[][] { { "Home", "home.do" }, { forum.getName(), ("viewForum.do?forum="+forumID) }, { "Post New Message", "" } }; } %> <%@ include file="breadcrumb.jsp" %> <% ///////////// // Toolbar // The toolbar file looks for the following variables. To make a particular // "button" not appear, set a variable to null. boolean showToolbar = true; String viewLink = "viewForum.do?forum="+forumID; String postLink = null; String replyLink = null; String searchLink = null; // we can show a link to a user account if the user is logged in (handled // in the toolbar jsp) String accountLink = "userAccount.do"; %> <%@ include file="toolbar.jsp" %>

<% if( errors ) { %>

<%= errorMessage %>

<% } %>
"> <% if(keyparam.equalsIgnoreCase("postreply")||keyparam=="postreply") { if( user.isAnonymous() ) { %> <%} } // show name and email textfields if the user is a guest if( user.isAnonymous() ) {%> <% // try to retrieve persisted values of name and email String storedName = SkinUtils.retrieve(request,response,"yazd.post.name"); String storedEmail = SkinUtils.retrieve(request,response,"yazd.post.email"); String storedMobileNo =SkinUtils.retrieve(request,response,"yazd.post.mobile"); %> <% } %> <% // Create the subject in the form we're going to display. If this // is a new message, just a blank text field will show up. If this // is a reply, the subject of the old message will appear. String formSubject = ""; if( reply ) { formSubject = parentMessage.getSubject(); if( !formSubject.startsWith("Re: ") ) { formSubject = "Re: " + formSubject; } } else if( doPost && errors && subject != null ) { formSubject = subject; } %>   <% // Create the subject in the form we're going to display. If this // is a new message, just a blank text field will show up. If this // is a reply, the subject of the old message will appear. //String formproductType = ""; //if( reply ) { // formproductType = parentMessage.getproductType(); //} //else if( doPost && errors && productType != null ) { // formproductType = productType; //} %> <% if( reply ) { // replace \r\n (windows newlines) with unix newlines (\n) String parentBody = parentMessage.getUnfilteredBody(); parentBody = StringUtils.replace(parentBody,"\r\n","\n"); parentBody = StringUtils.replace(parentBody,"\n","\\n"); parentBody = StringUtils.replace(parentBody,"\r",""); // replace quotes parentBody = StringUtils.replace(parentBody,"\"","\\\""); %> <% } %>
Name " size="30" maxlength="100">
Email " size="30" maxlength="100">
Mobile No " size="30" maxlength="100">
<% if( reply ) { %> Reply to:  <%= parentMessage.getSubject() %> <% } else { %> Post New Message <% } %>
 
Subject   
  <% // only show a "quote original" link if this is a reply if( reply ) { %> [ quote original ]    <% } %> <%-- [ :) ]    [ :( ] --%>
<%= (reply)?"Your Reply":"Message" %>   
  " class="inputbutton">