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.util.Vector;
15  
16  import javax.servlet.http.HttpServletRequest;
17  import javax.servlet.http.HttpServletResponse;
18  import javax.servlet.http.HttpSession;
19  
20  import org.apache.struts.action.Action;
21  import org.apache.struts.action.ActionForm;
22  import org.apache.struts.action.ActionForward;
23  import org.apache.struts.action.ActionMapping;
24  
25  import fr.hyphonem.conges.AccessData;
26  import fr.hyphonem.conges.AccessDataMng;
27  import fr.hyphonem.conges.data.EmployeeData;
28  import fr.hyphonem.conges.data.UserData;
29  import fr.hyphonem.conges.forms.ModifyUserForm;
30  
31  /**
32   * @author Stephane Gauchet pour Hyphonem
33   */
34  public class ModifUsersAction extends Action {
35  
36  	public ActionForward execute(ActionMapping mapping, ActionForm form,
37  			HttpServletRequest request, HttpServletResponse response)
38  			throws Exception {
39  		HttpSession session = request.getSession();
40  		if (session.getAttribute("user") == null) {
41  			return mapping.findForward("invalidsession");
42  		}
43  
44  		UserData userd = (UserData) session.getAttribute("user");
45  		if (!userd.isModif() && userd.isEmployee()) {
46  			return mapping.findForward("invalidaction");
47  		}
48  
49  		Vector lstOfUsers = new Vector();
50  
51  		// lecture du fichier XML des users
52  		String dataDirPath = (String) session.getAttribute("dataDirPath");
53  		AccessData ad = new AccessDataMng().getInstance(dataDirPath);
54  		try {
55  			lstOfUsers = ad.readUsers();
56  		} catch (Exception e) {
57  			System.out.println(e.getMessage());
58  			lstOfUsers = null;
59  		}
60  		session.setAttribute("lstOfUsers", lstOfUsers);
61  
62  		ModifyUserForm mu = new ModifyUserForm();
63  
64  		UserData userToModify = new UserData();
65  
66  		if (session.getAttribute("modifUser") == null) {
67  			userToModify = (UserData) session.getAttribute("user");
68  		} else {
69  			userToModify = (UserData) session.getAttribute("modifUser");
70  		}
71  		session.setAttribute("modifUser", userToModify);
72  
73  		mu.setEmail(userToModify.getEmail());
74  		mu.setChief(userToModify.isModif());
75  		mu.setNom(userToModify.getNom());
76  		mu.setPrenom(userToModify.getPrenom());
77  		mu.setLogin(userToModify.getLogin());
78  		mu.setPassword(userToModify.getPassword());
79  		mu.setEmployee(userToModify.isEmployee());
80  
81  		// on recherche dans la liste des employes le user a modifier
82  		String entryDate = "";
83  		boolean dayoff1 = false;
84  		boolean dayoff2 = false;
85  		boolean dayoff3 = false;
86  		boolean dayoff4 = false;
87  		boolean dayoff5 = false;
88  		boolean dayoff6 = true;
89  		boolean dayoff7 = true;
90  
91  		Vector employees = (Vector) session.getServletContext().getAttribute(
92  				"employees");
93  		for (int i = 0; i < employees.size(); i++) {
94  			EmployeeData emp = (EmployeeData) employees.get(i);
95  
96  			if (emp.getNom().equals(userToModify.getNom())
97  					&& emp.getPrenom().equals(userToModify.getPrenom())) {
98  				entryDate = emp.getEntryDate();
99  				dayoff1 = emp.isDayoff1();
100 				dayoff2 = emp.isDayoff2();
101 				dayoff3 = emp.isDayoff3();
102 				dayoff4 = emp.isDayoff4();
103 				dayoff5 = emp.isDayoff5();
104 				dayoff6 = emp.isDayoff6();
105 				dayoff7 = emp.isDayoff7();
106 			}
107 		}
108 		mu.setEntryDate(entryDate);
109 
110 		mu.setTeam(userToModify.getTeam());
111 		mu.setDayoff1(dayoff1);
112 		mu.setDayoff2(dayoff2);
113 		mu.setDayoff3(dayoff3);
114 		mu.setDayoff4(dayoff4);
115 		mu.setDayoff5(dayoff5);
116 		mu.setDayoff6(dayoff6);
117 		mu.setDayoff7(dayoff7);
118 
119 		request.setAttribute("modifUserForm", mu);
120 
121 		return mapping.findForward("success");
122 	}
123 
124 }