Exemplo n.º 1
0
 @SuppressWarnings("unchecked")
 public ActionForward execute(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response) {
   request.setAttribute("jsprun_action", "21");
   int annid = Common.toDigit(request.getParameter("id"));
   int total = 0;
   int page = Common.intval(request.getParameter("page"));
   HttpSession session = request.getSession();
   int timestamp = (Integer) (request.getAttribute("timestamp"));
   String groupid = session.getAttribute("jsprun_groupid").toString();
   Members member = (Members) session.getAttribute("user");
   Map<String, String> settings = ForumInit.settings;
   int ppp =
       member != null && member.getPpp() > 0
           ? member.getPpp()
           : Integer.valueOf(settings.get("postperpage"));
   List<Map<String, String>> announces =
       dataBaseService.executeQuery(
           "SELECT id, groups FROM jrun_announcements WHERE type!=2 AND starttime<='"
               + timestamp
               + "' AND (endtime='0' OR endtime>'"
               + timestamp
               + "') ORDER BY displayorder, starttime DESC, id DESC");
   if (announces != null && announces.size() > 0) {
     for (Map<String, String> announce : announces) {
       String groups = announce.get("groups");
       if (groups.length() == 0 || Common.in_array(groups.split(","), groupid)) {
         total++;
         if (annid > 0 && Integer.valueOf(announce.get("id")) == annid) {
           page = (int) Math.ceil((double) total / (double) ppp);
         }
       }
     }
   }
   page = Math.max(1, page);
   Map<String, Integer> multiInfo = Common.getMultiInfo(total, ppp, page);
   page = multiInfo.get("curpage");
   int start_limit = multiInfo.get("start_limit");
   Map<String, Object> multi =
       Common.multi(total, ppp, page, "announcement.jsp", 0, 10, true, false, null);
   request.setAttribute("multi", multi);
   List<Map<String, String>> announcements =
       dataBaseService.executeQuery(
           "SELECT * FROM jrun_announcements WHERE type!=2 AND starttime<='"
               + timestamp
               + "' AND (endtime='0' OR endtime>'"
               + timestamp
               + "') ORDER BY displayorder, starttime DESC, id DESC LIMIT "
               + start_limit
               + ", "
               + ppp);
   if (announcements != null && announcements.size() > 0) {
     String timeoffset = (String) session.getAttribute("timeoffset");
     String dateformat = (String) session.getAttribute("dateformat");
     SimpleDateFormat sdf_all = Common.getSimpleDateFormat(dateformat, timeoffset);
     List<Map<String, String>> announcementList = new ArrayList<Map<String, String>>();
     for (Map<String, String> announcement : announcements) {
       String groups = announcement.get("groups");
       if (groups.length() == 0 || Common.in_array(groups.split(","), groupid)) {
         announcement.put("authorenc", Common.encode(announcement.get("author")));
         int endtime = Integer.parseInt(announcement.get("endtime"));
         announcement.put(
             "starttime", Common.gmdate(sdf_all, Integer.parseInt(announcement.get("starttime"))));
         announcement.put(
             "endtime",
             endtime > 0 ? Common.gmdate(sdf_all, endtime) : getMessage(request, "unlimite"));
         String message = announcement.get("message");
         if ("1".equals(announcement.get("type"))) {
           message = "<a href=\"" + message + "\" target=\"_blank\">" + message + "</a>";
         }
         announcement.put("message", Common.nl2br(message));
         announcementList.add(announcement);
       }
     }
     request.setAttribute("announcements", announcementList);
     request.setAttribute("annid", annid);
     return mapping.findForward("toAnnouncement");
   } else {
     request.setAttribute("errorInfo", getMessage(request, "announcement_nonexistence"));
     return mapping.findForward("showMessage");
   }
 }
Exemplo n.º 2
0
 @SuppressWarnings("unchecked")
 public ActionForward fromAttachments(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response) {
   try {
     if (submitCheck(request, "searchsubmit")) {
       AttachmentsForm attachementsForm = null;
       HttpSession session = request.getSession();
       if (form != null) {
         Map<String, String> settings = ForumInit.settings;
         int currentpage = 1;
         String page = request.getParameter("page");
         currentpage = page == null || page.equals("") ? 1 : Integer.valueOf(page.trim());
         attachementsForm = (AttachmentsForm) form;
         String sql = attachmentsService.findByAttachmentsForm(attachementsForm);
         List<Map<String, String>> count =
             dataBaseService.executeQuery("select count(*) as count " + sql);
         int totalsize = Common.toDigit(count.get(0).get("count"));
         int currpage = currentpage;
         LogPage loginpage = new LogPage(totalsize, 10, currpage);
         if (currentpage > loginpage.getTotalPage()) {
           currentpage = loginpage.getTotalPage();
         }
         int beginsize = (currentpage - 1) * 10;
         session.setAttribute("attaforms", attachementsForm);
         List<Map<String, String>> list =
             dataBaseService.executeQuery(
                 "select a.aid,a.filename,a.attachment,a.downloads,a.remote,a.filesize,p.fid,p.author,t.tid,t.subject,f.name "
                     + sql
                     + " limit "
                     + beginsize
                     + ",10");
         if (list != null && list.size() > 0) {
           List<Map<String, String>> showlist = new ArrayList<Map<String, String>>();
           String path = JspRunConfig.realPath + settings.get("attachdir") + "/";
           Map<String, String> ftpmap = dataParse.characterParse(settings.get("ftp"), false);
           String attachurl = ftpmap.get("attachurl");
           ftpmap = null;
           for (Map<String, String> map : list) {
             if (map.get("remote").equals("1")) {
               File file = new File(attachurl + "/" + map.get("attachment"));
               if (!file.exists()) {
                 map.put("nomatched", getMessage(request, "a_post_attachments_far"));
               }
               map.put("attachment", attachurl + "/" + map.get("attachment"));
             } else {
               File file = new File(path + map.get("attachment"));
               if (!file.exists()) {
                 map.put("nomatched", getMessage(request, "a_post_attachments_lost"));
               }
               map.put("attachment", map.get("attachment"));
             }
             if (attachementsForm.getNomatched() == 0
                 || (attachementsForm.getNomatched() == 1 && map.get("nomatched") != null)) {
               showlist.add(map);
             }
           }
           request.setAttribute("showlist", showlist);
         } else {
           request.setAttribute("showlist", list);
         }
         request.setAttribute("logpage", loginpage);
       }
       short groupid = (Short) session.getAttribute("jsprun_groupid");
       Members member = (Members) session.getAttribute("user");
       request.setAttribute(
           "forumselect",
           Common.forumselect(
               false,
               false,
               groupid,
               member != null ? member.getExtgroupids() : "",
               attachementsForm.getInforum() + ""));
       request.setAttribute("notfirst", "notfirst");
       return mapping.findForward("toAttachments");
     }
   } catch (Exception e) {
     request.setAttribute("message", e.getMessage());
     return mapping.findForward("message");
   }
   Common.requestforward(response, "admincp.jsp?action=attachments");
   return null;
 }