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.SimpleDateFormat;
15  import java.util.Calendar;
16  
17  import javax.servlet.http.HttpServletRequest;
18  import javax.servlet.http.HttpServletResponse;
19  import javax.servlet.http.HttpSession;
20  
21  import org.apache.struts.action.Action;
22  import org.apache.struts.action.ActionForm;
23  import org.apache.struts.action.ActionForward;
24  import org.apache.struts.action.ActionMapping;
25  
26  import fr.hyphonem.conges.data.UserData;
27  import fr.hyphonem.conges.forms.CreateUserForm;
28  
29  /**
30   * @author Stephane Gauchet pour Hyphonem
31   */
32  public class CreateUserAction extends Action {
33  
34  	public ActionForward execute(ActionMapping mapping, ActionForm form,
35  			HttpServletRequest request, HttpServletResponse response)
36  			throws Exception {
37  		HttpSession session = request.getSession();
38  		if (session.getAttribute("user") == null) {
39  			return mapping.findForward("invalidsession");
40  		}
41  
42  		UserData userd = (UserData) session.getAttribute("user");
43  		if (!userd.isModif() && userd.isEmployee()) {
44  			return mapping.findForward("invalidaction");
45  		}
46  
47  		CreateUserForm cu = new CreateUserForm();
48  
49  		if (request.getAttribute("createUserForm") != null) {
50  			CreateUserForm cuEnErreur = (CreateUserForm) request
51  					.getAttribute("createUserForm");
52  			cu.setChief(cuEnErreur.isChief());
53  			cu.setDayoff1(cuEnErreur.isDayoff1());
54  			cu.setDayoff2(cuEnErreur.isDayoff2());
55  			cu.setDayoff3(cuEnErreur.isDayoff3());
56  			cu.setDayoff4(cuEnErreur.isDayoff4());
57  			cu.setDayoff5(cuEnErreur.isDayoff5());
58  			cu.setDayoff6(cuEnErreur.isDayoff6());
59  			cu.setDayoff7(cuEnErreur.isDayoff7());
60  			cu.setEmail(cuEnErreur.getEmail());
61  			cu.setEmployee(cuEnErreur.isEmployee());
62  			cu.setEntryDate(cuEnErreur.getEntryDate());
63  			cu.setLoginacreer(cuEnErreur.getLoginacreer());
64  			cu.setNom(cuEnErreur.getNom());
65  			cu.setPasswordacreer(cuEnErreur.getPasswordacreer());
66  			cu.setPays(cuEnErreur.getPays());
67  			cu.setPrenom(cuEnErreur.getPrenom());
68  			cu.setTeam(cuEnErreur.getTeam());
69  		} else {
70  			cu.setLoginacreer("");
71  			cu.setPasswordacreer("");
72  			cu.setDayoff1(false);
73  			cu.setDayoff2(false);
74  			cu.setDayoff3(false);
75  			cu.setDayoff4(false);
76  			cu.setDayoff5(false);
77  			cu.setDayoff6(true);
78  			cu.setDayoff7(true);
79  			cu.setChief(false);
80  			cu.setEmail("");
81  			cu.setEmployee(true);
82  			Calendar cal = Calendar.getInstance();
83  			SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
84  			cu.setEntryDate(sdf.format(cal.getTime()));
85  			cu.setNom("");
86  			cu.setPays((String) session.getServletContext().getAttribute(
87  					"country"));
88  			cu.setPrenom("");
89  			cu.setTeam("");
90  		}
91  
92  		request.setAttribute("createUserForm", cu);
93  
94  		return mapping.findForward("success");
95  	}
96  
97  }