001: /*
002: * Copyright (c) 2003, 2004 Rafael Steil
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: * This file creation date: Mar 31, 2005 / 11:21:41 AM
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.view.admin;
044:
045: import net.jforum.dao.BannerDAO;
046: import net.jforum.dao.DataAccessDriver;
047: import net.jforum.entities.Banner;
048: import net.jforum.util.I18n;
049: import net.jforum.util.preferences.TemplateKeys;
050:
051: /**
052: * ViewHelper class for banner administration.
053: *
054: * @author Samuel Yung
055: * @version $Id: BannerAction.java,v 1.5 2006/08/20 12:19:14 sergemaslyukov Exp $
056: */
057: public class BannerAction extends AdminCommand {
058: // Listing
059: public void list() {
060: this .context.put("banners", DataAccessDriver.getInstance()
061: .newBannerDAO().selectAll());
062: this .setTemplateName(TemplateKeys.BANNER_LIST);
063: }
064:
065: // Insert
066: public void insert() {
067: this .context.put("action", "insertSave");
068: this .setTemplateName(TemplateKeys.BANNER_INSERT);
069: }
070:
071: // Saves a new banner
072: public void insertSave() {
073: BannerDAO dao = DataAccessDriver.getInstance().newBannerDAO();
074:
075: dao.addNew(getBanner());
076:
077: this .list();
078: }
079:
080: // Edit a banner
081: public void edit() {
082: int bannerId = this .request.getIntParameter("banner_id");
083: BannerDAO dao = DataAccessDriver.getInstance().newBannerDAO();
084:
085: this .context.put("banner", dao.selectById(bannerId));
086: this .setTemplateName(TemplateKeys.BANNER_EDIT);
087: this .context.put("action", "editSave");
088: }
089:
090: // Save information for an existing banner
091: public void editSave() {
092: int bannerId = this .request.getIntParameter("banner_id");
093:
094: Banner banner = getBanner();
095: banner.setId(bannerId);
096:
097: DataAccessDriver.getInstance().newBannerDAO().update(banner);
098:
099: this .list();
100: }
101:
102: // Delete a banner
103: public void delete() {
104: String bannerId = this .request.getParameter("banner_id");
105: if (bannerId == null) {
106: this .list();
107: return;
108: }
109:
110: BannerDAO dao = DataAccessDriver.getInstance().newBannerDAO();
111:
112: int id = Integer.parseInt(bannerId);
113: if (dao.canDelete(id)) {
114: dao.delete(id);
115: } else {
116: this .context.put("errorMessage", I18n
117: .getMessage(I18n.CANNOT_DELETE_BANNER));
118: }
119:
120: this .list();
121: }
122:
123: protected Banner getBanner() {
124: Banner b = new Banner();
125: b.setComment(request.getParameter("comment"));
126: b.setActive(request.getIntParameter("active") == 1);
127: b.setType(Integer.parseInt(request.getParameter("type")));
128: b.setName(request.getParameter("name"));
129: b.setDescription(request.getParameter("description"));
130: b.setWidth(Integer.parseInt(request.getParameter("width")));
131: b.setHeight(Integer.parseInt(request.getParameter("height")));
132: b.setUrl(request.getParameter("url"));
133: b.setPlacement(Integer.parseInt(request
134: .getParameter("placement")));
135: b.setWeight(Integer.parseInt(request.getParameter("weight")));
136: b.setViews(Integer.parseInt(request.getParameter("views")));
137: b.setClicks(Integer.parseInt(request.getParameter("clicks")));
138:
139: return b;
140: }
141: }
|