001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * Created on 02/10/2005 20:04:15
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.view.forum;
044:
045: import java.util.Iterator;
046: import java.util.List;
047:
048: import net.jforum.Command;
049: import net.jforum.JForumExecutionContext;
050: import net.jforum.dao.DataAccessDriver;
051: import net.jforum.dao.ModerationLogDAO;
052: import net.jforum.dao.PostDAO;
053: import net.jforum.dao.TopicDAO;
054: import net.jforum.entities.ModerationLog;
055: import net.jforum.entities.Post;
056: import net.jforum.entities.Topic;
057: import net.jforum.repository.ForumRepository;
058: import net.jforum.repository.SecurityRepository;
059: import net.jforum.security.SecurityConstants;
060: import net.jforum.util.I18n;
061: import net.jforum.util.preferences.ConfigKeys;
062: import net.jforum.util.preferences.SystemGlobals;
063: import net.jforum.util.preferences.TemplateKeys;
064: import net.jforum.view.forum.common.PostCommon;
065: import net.jforum.view.forum.common.ViewCommon;
066:
067: /**
068: * @author Rafael Steil
069: * @version $Id: ModerationAction.java,v 1.6 2007/07/28 14:17:09 rafaelsteil Exp $
070: */
071: public class ModerationAction extends Command {
072: /**
073: * @throws UnsupportedOperationException always
074: * @see net.jforum.Command#list()
075: */
076: public void list() {
077: throw new UnsupportedOperationException();
078: }
079:
080: public void showActivityLog() {
081: if (!SecurityRepository
082: .canAccess(SecurityConstants.PERM_MODERATION_LOG)) {
083: this .denied();
084: return;
085: }
086:
087: ModerationLogDAO dao = DataAccessDriver.getInstance()
088: .newModerationLogDAO();
089:
090: int start = ViewCommon.getStartPage();
091: int recordsPerPage = SystemGlobals
092: .getIntValue(ConfigKeys.TOPICS_PER_PAGE);
093:
094: List list = dao.selectAll(start, recordsPerPage);
095: boolean canAccessFullModerationLog = SecurityRepository
096: .canAccess(SecurityConstants.PERM_FULL_MODERATION_LOG);
097:
098: PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
099: TopicDAO topicDao = DataAccessDriver.getInstance()
100: .newTopicDAO();
101:
102: for (Iterator iter = list.iterator(); iter.hasNext();) {
103: ModerationLog log = (ModerationLog) iter.next();
104:
105: if (log.getPostId() > 0) {
106: Post post = postDao.selectById(log.getPostId());
107:
108: if (post.getId() > 0
109: && ForumRepository.getForum(post.getForumId()) == null) {
110: iter.remove();
111: continue;
112: }
113: } else if (log.getTopicId() > 0) {
114: Topic topic = topicDao.selectRaw(log.getTopicId());
115:
116: if (topic.getId() > 0
117: && ForumRepository.getForum(topic.getForumId()) == null) {
118: iter.remove();
119: continue;
120: }
121: }
122:
123: if (log.getOriginalMessage() != null
124: && canAccessFullModerationLog) {
125: Post post = new Post();
126: post.setText(log.getOriginalMessage());
127:
128: log.setOriginalMessage(PostCommon
129: .preparePostForDisplay(post).getText());
130: }
131: }
132:
133: this .setTemplateName(TemplateKeys.MODERATION_SHOW_ACTIVITY_LOG);
134: this .context.put("activityLog", list);
135: this .context.put("canAccessFullModerationLog",
136: canAccessFullModerationLog);
137:
138: int totalRecords = dao.totalRecords();
139:
140: ViewCommon.contextToPagination(start, totalRecords,
141: recordsPerPage);
142: }
143:
144: private void denied() {
145: this .setTemplateName(TemplateKeys.MODERATION_LOG_DENIED);
146: this .context.put("message", I18n
147: .getMessage("ModerationLog.denied"));
148: }
149:
150: public void doModeration() {
151: String returnUrl = this .request.getParameter("returnUrl");
152:
153: new ModerationHelper().doModeration(returnUrl);
154:
155: this .context.put("returnUrl", returnUrl);
156:
157: if (JForumExecutionContext.getRequest().getParameter(
158: "topicMove") != null) {
159: this .setTemplateName(TemplateKeys.MODERATION_MOVE_TOPICS);
160: }
161: }
162:
163: public void moveTopic() {
164: new ModerationHelper().moveTopicsSave(this .request
165: .getParameter("returnUrl"));
166: }
167:
168: public void moderationDone() {
169: this
170: .setTemplateName(new ModerationHelper()
171: .moderationDone(this .request
172: .getParameter("returnUrl")));
173: }
174: }
|