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.ChooseUserForm;
30  
31  /**
32   * @author Stephane Gauchet pour Hyphonem
33   * 
34   */
35  public class ChooseUserAction extends Action {
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  		ChooseUserForm choiceUser = (ChooseUserForm) form;
50  		String userLogin = choiceUser.getChoixUser();
51  
52  		UserData userToModify = new UserData();
53  
54  		// lecture du fichier XML des users
55  		String dataDirPath = (String) session.getAttribute("dataDirPath");
56  		AccessData ad = new AccessDataMng().getInstance(dataDirPath);
57  		try {
58  			userToModify = ad.searchUser(userLogin);
59  		} catch (Exception e) {
60  			// System.out.println(e.getMessage());
61  			userToModify = null;
62  		}
63  
64  		Vector employees = (Vector) session.getServletContext().getAttribute(
65  				"employees");
66  		if (employees != null) {
67  			EmployeeData employee = new EmployeeData();
68  			for (int i = 0; i < employees.size(); i++) {
69  				employee = (EmployeeData) employees.get(i);
70  				if (employee.getNom().equals(userToModify.getNom())
71  						&& employee.getPrenom()
72  								.equals(userToModify.getPrenom())) {
73  					session.setAttribute("indexEmployee", "" + i);
74  					session.setAttribute("employee", employee);
75  					break;
76  				}
77  			}
78  		}
79  
80  		session.setAttribute("modifUser", userToModify);
81  
82  		return mapping.findForward("success");
83  	}
84  }