Subversion Repositories Applications.papyrus

Rev

Rev 2017 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
<?php
2
 
3
/**
4
 * Classe controleur pour l'application administration des administrateurs
5
 */
6
class AdminAdministrateur extends Controleur {
7
 
8
	/**
9
	 * Fonction d'affichage par défaut, elle appelle la liste des administrateurs
10
	 */
11
	function index() {
12
 
13
		$this->charger_admin() ;
14
	}
15
 
16
	/**
17
	 * Charge la liste des administrateurs et l'envoie à la vue
18
	 * @param array un tableau contenant les erreurs à afficher s'il y en a
19
	 */
20
	function chargerAdmin($erreurs = array()) {
21
 
22
		$this->chargerModele('ListeAdmin');
23
		$data['erreurs'] = $erreurs;
24
		$data['admin'] = $this->ListeAdmin->chargerAdmin();
25
		$this->chargerVue('liste_admin',$data);
26
 
27
		return $this->liste_admin;
28
	}
29
 
30
	/**
31
	 * Charge les détails d'un administrateur demandé et l'envoi à la
32
	 * vue qui permet de les modifier
33
	 */
34
	function modifAdmin($id) {
35
 
36
		$this->chargerModele('ListeAdmin');
37
		$data['admin'] = $this->ListeAdmin->loadDetailsAdmin($id);
38
		$this->chargerVue('modif_admin',$data);
39
 
40
		return $this->modif_admin;
41
 
42
	}
43
 
44
	/**
45
	 * Fonction appelée lors de la validation du formulaire de modification
46
	 * des détails d'un administrateurs. Elle modifie les détails dans la base
47
	 * de données. S'il y a une erreur et rappelle la formulaire et notifie l'erreur,
48
	 * sinon elle charge la liste des administrateurs
49
	 */
50
	function modifAdminVa($id,$nom,$prenom,$mail,$lang,$pass,$pass_conf) {
51
 
52
	$this->chargerModele('ListeAdmin') ;
53
	$res = $this->ListeAdmin->modifDetailsAdmin($id,$nom,$prenom,$mail,$lang,$pass,$pass_conf) ;
54
 
55
		if(count($res) == 0) {
56
			return $this->chargerAdmin() ;
57
		} else {
58
 
59
			$admin['ga_id_administrateur'] = $id ;
60
			$admin['ga_nom'] = $nom ;
61
			$admin['ga_prenom'] = $prenom ;
62
			$admin['ga_mail']  = $mail ;
63
			$admin['ga_ce_i18n'] = $lang ;
64
			$data['admin'] = $admin ;
65
			$data['erreurs'] = $res ;
66
			$this->chargerVue('modif_admin',$data);
67
 
68
			return $this->modif_admin;
69
		}
70
 
71
	}
72
 
73
	/**
74
	 * Supprime un administrateur dans la base de données,
75
	 * renvoie la liste des administrateurs, en affichant des erreurs
76
	 * s'il y en a.
77
	 *
78
	 */
79
	function supprAdmin() {
80
 
81
		$id = $_GET['id_admin'] ;
82
		$this->chargerModele('ListeAdmin') ;
83
		$res = $this->ListeAdmin->suppAdmin($id) ;
84
		if($res == '') {
85
			return $this->chargerAdmin() ;
86
		} else {
87
			$erreurs['supp'] = $res ;
88
			return $this->chargerAdmin($erreurs) ;
89
		}
90
	}
91
 
92
	/**
93
	 * Appelle la vue contenant le formulaire d'ajout d'un administrateur
94
	 */
95
	function ajoutAdmin() {
96
 
97
		$admin['ga_id_administrateur'] = '';
98
		$admin['ga_nom'] = '';
99
		$admin['ga_prenom'] = '';
100
		$admin['ga_mail']  = '';
101
		$admin['ga_ce_i18n'] = '';
102
		$data['admin'] = $admin;
103
		$this->chargerVue('ajout_admin',$data);
104
 
105
		return $this->ajout_admin;
106
	}
107
 
108
	/**
109
	 * Fonction appelée lors de la validation du formulaire d'ajout d'un administrateur.
110
	 * Elle ajoute celui-ci les dans la base de données
111
	 * S'il y a une erreur et rappelle la formulaire et notifie l'erreur,
112
	 * sinon elle charge la liste des administrateurs
113
	 */
114
	function ajoutAdminVa($nom,$prenom,$mail,$lang,$pass,$pass_conf) {
115
 
116
	if(empty($nom) || empty($prenom) || empty($mail) || empty($pass) || empty($pass_conf)) {
117
		$res = array('champs' => 'Tous les champs sont obligatoires') ;
118
		$data['erreurs'] = $res ;
119
		$admin['ga_nom'] = $nom ;
120
		$admin['ga_prenom'] = $prenom ;
121
		$admin['ga_mail']  = $mail ;
122
		$admin['ga_ce_i18n'] = $lang ;
123
		$data['admin'] = $admin ;
124
		$this->chargerVue('ajout_admin',$data);
125
 
126
		return $this->ajout_admin;
127
	}
128
 
129
	$this->chargerModele('ListeAdmin') ;
130
	$res = $this->ListeAdmin->ajoutAdmin($nom,$prenom,$mail,$lang,$pass,$pass_conf) ;
131
		if(count($res) == 0) {
132
			return $this->chargerAdmin() ;
133
		} else {
134
 
135
			$admin['ga_nom'] = $nom ;
136
			$admin['ga_prenom'] = $prenom ;
137
			$admin['ga_mail']  = $mail ;
138
			$admin['ga_ce_i18n'] = $lang ;
139
			$data['admin'] = $admin ;
140
			$data['erreurs'] = $res ;
141
			$this->chargerVue('ajout_admin',$data);
142
 
143
			return $this->ajout_admin;
144
		}
145
	}
146
 
147
	 /** Apelle le formulaire d'identification (dans le cas où l'utilisateur n'est pas identifié)
148
	 */
149
	function demanderIdent() {
150
		$this->chargerVue('ident_admin',null) ;
151
 
152
		return $this->ident_admin;
153
	}
154
 
155
	/**
156
	 * Renvoie la tête de page de l'application
157
	 */
158
	function adminTete() {
159
 
160
		$tete = '<h1>Gestion des administrateurs de Papyrus</h1>';
161
 
162
		return $tete;
163
	}
164
 
165
	/**
166
	 * Renvoie le pied de page de l'application
167
	 */
168
	function adminPied() {
169
 
170
	$pied = '';
171
 
172
		return $pied ;
173
	}
174
 
175
}
176
 
177
?>