View Javadoc

1   /*Copyright (C) 2004-... Stephane Gauchet for Hyphonem
2   
3    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
4   
5    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6   
7    You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8    
9    Written by St�phane Gauchet
10   mail me at : sgauchet@free.fr
11   */
12  package fr.hyphonem.conges.actions;
13  
14  import java.text.ParseException;
15  import java.text.SimpleDateFormat;
16  import java.util.Calendar;
17  import java.util.Date;
18  
19  import javax.servlet.ServletException;
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpServletResponse;
22  import javax.servlet.http.HttpSession;
23  
24  import org.apache.struts.action.Action;
25  import org.apache.struts.action.ActionForm;
26  import org.apache.struts.action.ActionForward;
27  import org.apache.struts.action.ActionMapping;
28  
29  import fr.hyphonem.conges.forms.AbsForm;
30  
31  /**
32   * @author Stephane Gauchet pour Hyphonem
33   * 
34   */
35  public class CreateEvtAction extends Action {
36  
37  	/**
38  	 * Constructor for CreateEvtAction.
39  	 */
40  	public CreateEvtAction() {
41  		super();
42  	}
43  
44  	public ActionForward execute(ActionMapping mapping, ActionForm form,
45  			HttpServletRequest request, HttpServletResponse response)
46  			throws java.io.IOException, ServletException {
47  		HttpSession session = request.getSession();
48  		if (session.getAttribute("user") == null) {
49  			return mapping.findForward("invalidsession");
50  		}
51  
52  		String date = request.getParameter("date");
53  
54  		if (date == null) {
55  			// on met la date du jour
56  			Calendar today = Calendar.getInstance();
57  			int day = today.get(Calendar.DAY_OF_MONTH);
58  			int month = today.get(Calendar.MONTH) + 1;
59  			int year = today.get(Calendar.YEAR);
60  			date = day + "/" + month + "/" + year;
61  		}
62  		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
63  		Date dateDeb;
64  		try {
65  			dateDeb = sdf.parse(date);
66  			AbsForm absenceForm = new AbsForm();
67  			// AbsForm absenceForm = (AbsForm)form;
68  			absenceForm.setDatedeb(sdf.format(dateDeb));
69  			absenceForm.setDatefin(sdf.format(dateDeb));
70  			if (request.getParameter("type") != null) {
71  				String type = request.getParameter("type");
72  				if (type.equals("matin")) {
73  					absenceForm.setCbmatin(true);
74  				} else {
75  					absenceForm.setCbmatin(false);
76  				}
77  				if (type.equals("aprem")) {
78  					absenceForm.setCbaprem(true);
79  				} else {
80  					absenceForm.setCbaprem(false);
81  				}
82  			} else {
83  				absenceForm.setCbmatin(true);
84  				absenceForm.setCbaprem(true);
85  			}
86  
87  			absenceForm.setEdition(false);
88  			request.setAttribute("absForm", absenceForm);
89  		} catch (ParseException e) {
90  			dateDeb = null;
91  		}
92  
93  		return mapping.findForward("success");
94  	}
95  }