2
0

MemoBoard.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.communityserver.communityboard.boards;
  16. import java.text.DateFormat;
  17. import java.util.Date;
  18. import java.util.logging.Logger;
  19. import javolution.text.TextBuilder;
  20. import com.l2jserver.communityserver.cache.HtmCache;
  21. import com.l2jserver.communityserver.communityboard.CommunityBoard;
  22. import com.l2jserver.communityserver.communityboard.CommunityBoardManager;
  23. import com.l2jserver.communityserver.model.Forum;
  24. import com.l2jserver.communityserver.model.Topic;
  25. import com.l2jserver.communityserver.model.Post;
  26. import com.l2jserver.communityserver.model.Topic.ConstructorType;
  27. public final class MemoBoard extends CommunityBoard
  28. {
  29. private static Logger _log = Logger.getLogger(MemoBoard.class.getName());
  30. public MemoBoard(final CommunityBoardManager mgr)
  31. {
  32. super(mgr);
  33. }
  34. @Override
  35. public void parseCmd(final int playerObjId, final String cmd)
  36. {
  37. Forum playerForum = getCommunityBoardManager().getPlayerForum(playerObjId);
  38. if (cmd.equals("_bbsmemo"))
  39. showPage(playerObjId, playerForum, 1);
  40. else if (cmd.split(";")[1].equalsIgnoreCase("crea"))
  41. showWrite(playerObjId, null);
  42. else if (cmd.split(";")[1].equalsIgnoreCase("list"))
  43. showPage(playerObjId, playerForum, Integer.valueOf(cmd.split(";")[2]));
  44. else if (cmd.split(";")[1].equalsIgnoreCase("read"))
  45. {
  46. Topic t = playerForum.gettopic(Topic.MEMO);
  47. Post p = t.getPost(Integer.valueOf(cmd.split(";")[2]));
  48. if (p == null)
  49. _log.info("Memo read command: " + cmd.split(";")[2]);
  50. else
  51. showPost(playerObjId, p);
  52. }
  53. else if (cmd.split(";")[1].equalsIgnoreCase("del"))
  54. {
  55. playerForum.gettopic(Topic.MEMO).rmPostByID(Integer.valueOf(cmd.split(";")[2]));
  56. showPage(playerObjId, playerForum, 1);
  57. }
  58. else if (cmd.split(";")[1].equalsIgnoreCase("edit"))
  59. {
  60. Post p = playerForum.gettopic(Topic.MEMO).getPost(Integer.valueOf(cmd.split(";")[2]));
  61. showWrite(playerObjId, p);
  62. }
  63. else
  64. _log.info("Memo command missing: " + cmd.split(";")[1]);
  65. }
  66. public final void showPage(final int playerObjId, Forum f, int index)
  67. {
  68. String content = HtmCache.getInstance().getHtm("data/staticfiles/html/memo.htm");
  69. if (f == null)
  70. {
  71. _log.info("Forum is NULL!!!");
  72. super.send(playerObjId, content);
  73. return;
  74. }
  75. Topic t = f.gettopic(Topic.MEMO);
  76. TextBuilder mList = new TextBuilder();
  77. int i = 0;
  78. for (Post p : t.getAllPosts())
  79. {
  80. if (i > ((index - 1) * 10 + 9))
  81. {
  82. break;
  83. }
  84. if (i++ >= ((index - 1) * 10))
  85. {
  86. mList.append("<img src=\"L2UI.SquareBlank\" width=\"750\" height=\"3\">");
  87. mList.append("<table border=0 cellspacing=0 cellpadding=0 width=750>");
  88. mList.append("<tr> ");
  89. mList.append("<td FIXWIDTH=5></td>");
  90. mList.append("<td FIXWIDTH=511><a action=\"bypass _bbsmemo;read;" + p.getID() + "\">" + p.getTitle() + "</a></td>");
  91. mList.append("<td FIXWIDTH=148 align=center></td>");
  92. mList.append("<td FIXWIDTH=86 align=center>" + DateFormat.getInstance().format(new Date(p.getDate())) + "</td>");
  93. mList.append("<td FIXWIDTH=5></td>");
  94. mList.append("</tr>");
  95. mList.append("<tr><td height=5></td></tr>");
  96. mList.append("</table>");
  97. mList.append("<img src=\"L2UI.SquareBlank\" width=\"750\" height=\"3\">");
  98. mList.append("<img src=\"L2UI.SquareGray\" width=\"750\" height=\"1\">");
  99. }
  100. }
  101. content = content.replaceAll("%memoList%", mList.toString());
  102. mList.clear();
  103. mList.clear();
  104. if (index == 1)
  105. {
  106. mList.append("<td><button action=\"\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
  107. }
  108. else
  109. {
  110. mList.append("<td><button action=\"bypass _bbsmemo;list;" + (index - 1) + "\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
  111. }
  112. int nbp;
  113. nbp = t.getAllPosts().size() / 10;
  114. if (nbp * 10 != t.getAllPosts().size())
  115. {
  116. nbp++;
  117. }
  118. for (i = 1; i <= nbp; i++)
  119. {
  120. if (i == index)
  121. {
  122. mList.append("<td> " + i + " </td>");
  123. }
  124. else
  125. {
  126. mList.append("<td><a action=\"bypass _bbsmemo;list;" + i + "\"> " + i + " </a></td>");
  127. }
  128. }
  129. if (index == nbp)
  130. {
  131. mList.append("<td><button action=\"\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
  132. }
  133. else
  134. {
  135. mList.append("<td><button action=\"bypass _bbsmemo;list;" + (index + 1) + "\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
  136. }
  137. content = content.replaceAll("%memoListLength%", mList.toString());
  138. super.send(playerObjId, content);
  139. }
  140. public final void showWrite(final int playerObjId, Post p)
  141. {
  142. String title = " ";
  143. String message = " ";
  144. String content = HtmCache.getInstance().getHtm("data/staticfiles/html/memo-write.htm");
  145. content = content.replaceAll("%playerObjId%", String.valueOf(playerObjId));
  146. if (p == null)
  147. content = content.replaceAll("%job%", "new");
  148. else
  149. {
  150. content = content.replaceAll("%job%", "edit");
  151. content = content.replaceAll("%postId%", String.valueOf(p.getID()));
  152. title = p.getTitle();
  153. message = p.getText();
  154. }
  155. super.sendWrite(playerObjId, content, message, title, title);
  156. }
  157. public final void showPost(final int playerObjId, Post p)
  158. {
  159. p.increaseReadCount();
  160. String content = HtmCache.getInstance().getHtm("data/staticfiles/html/memo-show.htm");
  161. content = content.replaceAll("%memoName%", p.getTitle());
  162. content = content.replaceAll("%postId%", String.valueOf(p.getID()));
  163. content = content.replaceAll("%memoOwnerName%", getCommunityBoardManager().getPlayer(p.getOwnerId()).getName());
  164. content = content.replaceAll("%postDate%", DateFormat.getInstance().format(new Date(p.getDate())));
  165. content = content.replaceAll("%mes%", p.getText());
  166. super.send(playerObjId, content);
  167. }
  168. @Override
  169. public final void parseWrite(final int playerObjId, final String ar1, final String ar2, final String ar3, final String ar4, final String ar5)
  170. {
  171. Forum playerForum = getCommunityBoardManager().getPlayerForum(playerObjId);
  172. if (ar1.equalsIgnoreCase("new"))
  173. {
  174. int postId = playerForum.gettopic(Topic.MEMO).getNewPostId();
  175. Post p = new Post(ConstructorType.CREATE, playerForum.getSqlDPId(), postId, playerObjId, "", System.currentTimeMillis(), Topic.MEMO, playerForum.getID(), super.edtiPlayerTxT(ar3), super.edtiPlayerTxT(ar4), 0, 0);
  176. playerForum.gettopic(Topic.MEMO).addPost(p);
  177. }
  178. else if (ar1.equalsIgnoreCase("edit"))
  179. {
  180. playerForum.gettopic(Topic.MEMO).getPost(Integer.valueOf(ar2)).updatePost(super.edtiPlayerTxT(ar3), super.edtiPlayerTxT(ar4));
  181. }
  182. else
  183. _log.info("Memo Write command missing: " + ar1);
  184. showPage(playerObjId, playerForum, 1);
  185. }
  186. }