1 |
<?php |
<?php |
2 |
/** |
/** |
3 |
* |
* Ce fichier est destine a permettre la surcharge de certaines methodes de |
4 |
|
* la classe om_application pour des besoins specifiques de l'application |
5 |
* |
* |
6 |
* @package openmairie_exemple |
* @package openmairie_exemple |
7 |
* @version SVN : $Id: utils.class.php 318 2010-12-06 12:16:35Z fmichon $ |
* @version SVN : $Id: utils.class.php 547 2011-08-25 12:03:42Z fmichon $ |
8 |
*/ |
*/ |
9 |
|
|
10 |
/** |
/** |
36 |
* |
* |
37 |
*/ |
*/ |
38 |
class utils extends application { |
class utils extends application { |
39 |
|
|
40 |
var $schema; //*** |
// {{{ |
|
|
|
41 |
|
|
42 |
/** |
/** |
|
* Cette methode permet de charger les differents fichiers de configs dans |
|
|
* des attributs de la classe |
|
43 |
* |
* |
|
* @return void |
|
44 |
*/ |
*/ |
45 |
function setParamsFromFiles() { |
function isAccredited($obj = NULL, $operator = "AND") { |
46 |
|
// Lorsque l'utilisateur a le login 'admin' alors il est authorisé à |
47 |
// |
// accéder à toutes les fonctions du logiciel |
48 |
if (file_exists("../dyn/config.inc.php")) { |
// XXX à modifier pour changer ça vers un profil et non un login utilisateur |
49 |
include_once("../dyn/config.inc.php"); |
if ($_SESSION["login"] == "admin") { |
50 |
} |
return true; |
|
if (isset($config)) { |
|
|
$this->config = $config; |
|
51 |
} |
} |
52 |
|
// Fonctionnement standard |
53 |
|
return parent::isAccredited($obj, $operator); |
54 |
|
} |
55 |
|
|
56 |
|
// }}} |
57 |
|
|
58 |
|
// {{{ |
59 |
|
|
60 |
|
var $om_utilisateur = array(); |
61 |
|
var $user_is_instr = NULL; |
62 |
|
var $user_is_service = NULL; |
63 |
|
var $user_is_admin = NULL; |
64 |
|
var $user_is_service_ext = NULL; |
65 |
|
var $user_is_qualificateur = NULL; |
66 |
|
var $user_is_chef = NULL; |
67 |
|
var $user_is_divisionnaire = NULL; |
68 |
|
var $user_is_service_int = NULL; |
69 |
|
|
70 |
|
/** |
71 |
|
* Méthode de récupération des informations de l'utilisateur connecté. |
72 |
|
*/ |
73 |
|
function getUserInfos() { |
74 |
|
|
75 |
// |
// Si l'utilisateur est loggé $_SESSION existe |
76 |
if (file_exists("../dyn/database.inc.php")) { |
if(isset($_SESSION['login']) AND !empty($_SESSION['login'])) { |
77 |
include_once("../dyn/database.inc.php"); |
|
78 |
|
// Récupération des infos utilisateur |
79 |
|
$sqlUser = "SELECT om_utilisateur, nom, email, login, om_collectivite, om_profil ". |
80 |
|
"FROM ".DB_PREFIXE."om_utilisateur WHERE login = '".$_SESSION['login']."'"; |
81 |
|
$resUser=$this->db->query($sqlUser); |
82 |
|
$this->addToLog("getUserInfos(): db->query(\"".$sqlUser."\");", VERBOSE_MODE); |
83 |
|
if ( database::isError($resUser)){ |
84 |
|
die(); |
85 |
|
} |
86 |
|
$this->om_utilisateur=&$resUser->fetchRow(DB_FETCHMODE_ASSOC); |
87 |
|
|
88 |
|
// Récupère le profil et test si c'est un |
89 |
|
$sqlProfil = "SELECT libelle FROM ".DB_PREFIXE."om_profil WHERE om_profil = ".$this->om_utilisateur['om_profil']; |
90 |
|
$resProfil=$this->db->getOne($sqlProfil); |
91 |
|
$this->addToLog("getUserInfos(): db->getOne(\"".$sqlProfil."\");", VERBOSE_MODE); |
92 |
|
if (database::isError($resProfil)){ |
93 |
|
die(); |
94 |
|
} |
95 |
|
// Sauvegarde le libelle du profil |
96 |
|
$this->om_utilisateur["libelle_profil"] = $resProfil; |
97 |
|
|
98 |
|
// si c'est un administrateur technique |
99 |
|
if ($resProfil == "ADMINISTRATEUR TECHNIQUE") { |
100 |
|
$this->user_is_admin = true; |
101 |
|
} else { |
102 |
|
$this->user_is_admin = false; |
103 |
|
} |
104 |
|
|
105 |
|
//si c'est un service externe |
106 |
|
if ($resProfil == "SERVICE CONSULTÉ") { |
107 |
|
$this->user_is_service_ext = true; |
108 |
|
} else { |
109 |
|
$this->user_is_service_ext = false; |
110 |
|
} |
111 |
|
|
112 |
|
//si c'est un service interne |
113 |
|
if ($resProfil == "SERVICE CONSULTÉ INTERNE") { |
114 |
|
$this->user_is_service_int = true; |
115 |
|
} else { |
116 |
|
$this->user_is_service_int = false; |
117 |
|
} |
118 |
|
|
119 |
|
// si c'est un qualificateur |
120 |
|
if ($resProfil == "QUALIFICATEUR") { |
121 |
|
$this->user_is_qualificateur = true; |
122 |
|
} else { |
123 |
|
$this->user_is_qualificateur = false; |
124 |
|
} |
125 |
|
|
126 |
|
// si c'est un chef de service |
127 |
|
if ($resProfil == "CHEF DE SERVICE") { |
128 |
|
$this->user_is_chef = true; |
129 |
|
} else { |
130 |
|
$this->user_is_chef = false; |
131 |
|
} |
132 |
|
|
133 |
|
// si c'est un divisionnaire |
134 |
|
if ($resProfil == "DIVISIONNAIRE") { |
135 |
|
$this->user_is_divisionnaire = true; |
136 |
|
} else { |
137 |
|
$this->user_is_divisionnaire = false; |
138 |
|
} |
139 |
|
|
140 |
|
// Récupération des infos instructeur |
141 |
|
$sqlInstr = "SELECT instructeur.instructeur, instructeur.nom, instructeur.telephone, |
142 |
|
division.division, division.code, division.libelle ". |
143 |
|
"FROM ".DB_PREFIXE."instructeur INNER JOIN ".DB_PREFIXE."division ON division.division=instructeur.division ". |
144 |
|
"WHERE instructeur.om_utilisateur = ".$this->om_utilisateur['om_utilisateur']; |
145 |
|
$resInstr=$this->db->query($sqlInstr); |
146 |
|
$this->addToLog("getUserInfos(): db->query(\"".$sqlInstr."\");", VERBOSE_MODE); |
147 |
|
if ( database::isError($resInstr)){ |
148 |
|
die(); |
149 |
|
} |
150 |
|
$tempInstr=&$resInstr->fetchRow(DB_FETCHMODE_ASSOC); |
151 |
|
// Si il y a un resultat c'est un instructeur |
152 |
|
if(count($tempInstr)>0) { |
153 |
|
$this->user_is_instr=true; |
154 |
|
$this->om_utilisateur = array_merge($this->om_utilisateur,$tempInstr); |
155 |
|
} else { |
156 |
|
$this->user_is_instr=false; |
157 |
|
} |
158 |
|
|
159 |
|
// Récupération des infos de services consultés |
160 |
|
$sqlServ = "SELECT service.service, service.abrege, service.libelle ". |
161 |
|
"FROM ".DB_PREFIXE."service ". |
162 |
|
"INNER JOIN ".DB_PREFIXE."lien_service_om_utilisateur ON lien_service_om_utilisateur.service=service.service ". |
163 |
|
"WHERE lien_service_om_utilisateur.om_utilisateur = ".$this->om_utilisateur['om_utilisateur']; |
164 |
|
$resServ=$this->db->query($sqlServ); |
165 |
|
$this->addToLog("getUserInfos(): db->query(\"".$sqlServ."\");", VERBOSE_MODE); |
166 |
|
if ( database::isError($resServ)){ |
167 |
|
die(); |
168 |
|
} |
169 |
|
|
170 |
|
while ($tempServ=&$resServ->fetchRow(DB_FETCHMODE_ASSOC)) { |
171 |
|
$this->om_utilisateur['service'][]=$tempServ; |
172 |
|
} |
173 |
|
// Si il y a un resultat c'est un utilisateur de service |
174 |
|
if(isset($this->om_utilisateur['service'])) { |
175 |
|
$this->user_is_service=true; |
176 |
|
} else { |
177 |
|
$this->user_is_service=false; |
178 |
|
} |
179 |
} |
} |
180 |
|
} |
181 |
if (isset($conn)) { |
|
182 |
$this->conn = $conn; |
/** |
183 |
|
* getter user_is_service |
184 |
|
*/ |
185 |
|
function isUserService() { |
186 |
|
// |
187 |
|
if (is_null($this->user_is_service)) { |
188 |
// |
// |
189 |
foreach($this->conn as $key => $conn) { |
$this->getUserInfos(); |
|
$this->database[$key] = array( |
|
|
'title' => $conn[0], |
|
|
'phptype' => $conn[1], |
|
|
'dbsyntax' => $conn[2], |
|
|
'username' => $conn[3], |
|
|
'password' => $conn[4], |
|
|
'protocol' => $conn[5], |
|
|
'hostspec' => $conn[6], |
|
|
'port' => $conn[7], |
|
|
'socket' => $conn[8], |
|
|
'database' => $conn[9], |
|
|
'formatdate' => $conn[10], |
|
|
'schema' => $conn[11], //**** |
|
|
'prefixe' => $conn[12], //**** |
|
|
); |
|
|
} |
|
190 |
} |
} |
|
|
|
191 |
// |
// |
192 |
if (file_exists("../dyn/menu.inc.php")) { |
return $this->user_is_service; |
193 |
include_once("../dyn/menu.inc.php"); |
} |
194 |
|
|
195 |
|
/** |
196 |
|
* getter user_is_instr |
197 |
|
*/ |
198 |
|
function isUserInstructeur() { |
199 |
|
// |
200 |
|
if (is_null($this->user_is_instr)) { |
201 |
|
// |
202 |
|
$this->getUserInfos(); |
203 |
} |
} |
204 |
if (isset($menu)) { |
// |
205 |
$this->menu = $menu; |
return $this->user_is_instr; |
206 |
|
} |
207 |
|
|
208 |
|
function isUserAdministrateur() { |
209 |
|
// |
210 |
|
if (is_null($this->user_is_admin)) { |
211 |
|
// |
212 |
|
$this->getUserInfos(); |
213 |
} |
} |
|
|
|
214 |
// |
// |
215 |
if (file_exists("../dyn/actions.inc.php")) { |
return $this->user_is_admin; |
216 |
include_once("../dyn/actions.inc.php"); |
} |
217 |
|
|
218 |
|
/** |
219 |
|
* getter user_is_service_ext |
220 |
|
*/ |
221 |
|
function isUserServiceExt() { |
222 |
|
// |
223 |
|
if (is_null($this->user_is_service_ext)) { |
224 |
|
// |
225 |
|
$this->getUserInfos(); |
226 |
} |
} |
227 |
if (isset($actions)) { |
// |
228 |
$this->actions = $actions; |
return $this->user_is_service_ext; |
229 |
|
} |
230 |
|
|
231 |
|
/** |
232 |
|
* getter user_is_service_int |
233 |
|
*/ |
234 |
|
function isUserServiceInt() { |
235 |
|
// |
236 |
|
if (is_null($this->user_is_service_int)) { |
237 |
|
// |
238 |
|
$this->getUserInfos(); |
239 |
} |
} |
|
|
|
240 |
// |
// |
241 |
if (file_exists("../dyn/shortlinks.inc.php")) { |
return $this->user_is_service_int; |
242 |
include_once("../dyn/shortlinks.inc.php"); |
} |
243 |
|
|
244 |
|
/** |
245 |
|
* getter user_is_qualificateur |
246 |
|
*/ |
247 |
|
function isUserQualificateur() { |
248 |
|
// |
249 |
|
if (is_null($this->user_is_qualificateur)) { |
250 |
|
// |
251 |
|
$this->getUserInfos(); |
252 |
} |
} |
253 |
if (isset($shortlinks)) { |
// |
254 |
$this->shortlinks = $shortlinks; |
return $this->user_is_qualificateur; |
255 |
|
} |
256 |
|
|
257 |
|
/** |
258 |
|
* getter user_is_chef |
259 |
|
*/ |
260 |
|
function isUserChef() { |
261 |
|
// |
262 |
|
if (is_null($this->user_is_chef)) { |
263 |
|
// |
264 |
|
$this->getUserInfos(); |
265 |
} |
} |
|
|
|
266 |
// |
// |
267 |
if (file_exists("../dyn/footer.inc.php")) { |
return $this->user_is_chef; |
268 |
include_once("../dyn/footer.inc.php"); |
} |
269 |
|
|
270 |
|
/** |
271 |
|
* getter user_is_divisionnaire |
272 |
|
*/ |
273 |
|
function isUserDivisionnaire() { |
274 |
|
// |
275 |
|
if (is_null($this->user_is_divisionnaire)) { |
276 |
|
// |
277 |
|
$this->getUserInfos(); |
278 |
} |
} |
279 |
if (isset($footer)) { |
// |
280 |
$this->footer = $footer; |
return $this->user_is_divisionnaire; |
281 |
|
} |
282 |
|
|
283 |
|
// Ajout de variables de session contenant la division pour permettre une |
284 |
|
// utilisation plus efficace dans les requetes |
285 |
|
function triggerAfterLogin($utilisateur = NULL) { |
286 |
|
// |
287 |
|
$sql = "SELECT instructeur.division, division.code |
288 |
|
FROM ".DB_PREFIXE."instructeur |
289 |
|
LEFT JOIN ".DB_PREFIXE."division |
290 |
|
ON instructeur.division = division.division |
291 |
|
WHERE instructeur.om_utilisateur='".$utilisateur["om_utilisateur"]."'"; |
292 |
|
$res = $this->db->query($sql); |
293 |
|
$this->addToLog("triggerAfterLogin(): db->query(\"".$sql."\");", VERBOSE_MODE); |
294 |
|
if ( database::isError($res)){ |
295 |
|
die(); |
296 |
} |
} |
297 |
|
$row = $res->fetchrow(DB_FETCHMODE_ASSOC); |
298 |
// |
// |
299 |
if (file_exists("../dyn/version.inc.php")) { |
if (isset($row["division"]) && $row["division"] != NULL) { |
300 |
include_once("../dyn/version.inc.php"); |
$_SESSION["division"] = $row["division"]; |
301 |
|
$_SESSION["division_code"] = $row["code"]; |
302 |
|
} else { |
303 |
|
$_SESSION["division"] = "0"; |
304 |
|
$_SESSION["division_code"] = ""; |
305 |
} |
} |
306 |
if (isset($version)) { |
|
307 |
$this->version = $version; |
} |
308 |
|
|
309 |
|
// Affichage des actions supplémentaires |
310 |
|
function displayActionExtras() { |
311 |
|
// Affichage de la division si l'utilisateur en possède une |
312 |
|
if ($_SESSION["division"] != 0) { |
313 |
|
echo "\t\t\t<li class=\"action-division\">"; |
314 |
|
echo "(".$_SESSION['division_code'].")"; |
315 |
|
echo "</li>\n"; |
316 |
} |
} |
|
|
|
317 |
} |
} |
318 |
|
|
319 |
|
// }}} |
320 |
|
|
321 |
|
|
322 |
|
function getDivisionFromDossier($dossier) { |
323 |
|
// |
324 |
|
$sql = "select division from ".DB_PREFIXE."dossier "; |
325 |
|
$sql .= " where dossier='".$dossier."'"; |
326 |
|
// |
327 |
|
$division = $this->db->getOne($sql); |
328 |
|
$this->addToLog("getDivisionFromDossier(): db->getone(\"".$sql."\")", VERBOSE_MODE); |
329 |
|
database::isError($division); |
330 |
|
// |
331 |
|
return $division; |
332 |
|
} |
333 |
|
|
334 |
|
// {{{ GESTION DES FICHIERS |
335 |
|
|
336 |
/** |
/** |
337 |
* Cette methode permet de parametrer les valeurs par defaut pour les |
* |
|
* fichiers css et javascript a appeler sur toutes les pages |
|
|
* |
|
|
* @return void |
|
338 |
*/ |
*/ |
339 |
function setDefaultValues() { |
function notExistsError ($explanation = NULL) { |
340 |
|
// message |
341 |
$js = array( |
$message_class = "error"; |
342 |
"../js/iepngfix_tilebg.js", |
$message = _("Cette page n'existe pas."); |
343 |
"../lib/jquery-ui/js/jquery-1.4.2.min.js", |
$this->addToMessage ($message_class, $message); |
344 |
"../lib/jquery-ui/js/jquery.ui.datepicker-fr.js", |
// |
345 |
"../lib/jquery-ui/js/jquery-ui-1.8.6.custom.min.js", |
$this->setFlag(NULL); |
346 |
"../lib/jquery-misc/jquery.collapsible-v.2.1.3.js", |
$this->display(); |
|
"../js/script.js", |
|
|
); |
|
|
$this->setHTMLHeadJs($js); |
|
|
|
|
|
|
|
|
$css = array( |
|
|
"../css/main.css", |
|
|
"../lib/jquery-ui/css/".$this->config['theme']."/jquery-ui-1.8.6.custom.css", |
|
|
"../css/specific.css", |
|
|
); |
|
|
if (file_exists("../css/specific_".$this->config['theme'].".css")) { |
|
|
array_push($css, "../css/specific_".$this->config['theme'].".css"); |
|
|
} |
|
|
$this->setHTMLHeadCss($css); |
|
|
|
|
|
$extras = "\t<link rel=\"stylesheet\" type=\"text/css\" media=\"print\" href=\"../css/print.css\" />\n"; |
|
|
$this->setHTMLHeadExtras($extras); |
|
|
// $this->setStyleForHeader("ui-widget-header ui-state-active"); // essai jquery |
|
347 |
|
|
348 |
|
// |
349 |
|
die(); |
350 |
} |
} |
351 |
|
|
352 |
|
// }}} |
353 |
/** |
/** |
354 |
* Cette methode permet d'affecter des parametres dans un attribut de |
* Retourne le statut du dossier d'instruction |
355 |
* l'objet. |
* @param string $idx Identifiant du dossier d'instruction |
356 |
* |
* @return string Le statut du dossier d'instruction |
|
* @return void |
|
357 |
*/ |
*/ |
358 |
function setMoreParams() { |
function getStatutDossier($idx){ |
359 |
|
|
360 |
// |
$statut = ''; |
|
if (file_exists("../dyn/var.inc")) { |
|
|
include_once("../dyn/var.inc"); |
|
|
} |
|
361 |
|
|
362 |
|
//Si l'identifiant du dossier d'instruction fourni est correct |
363 |
|
if ( $idx != '' ){ |
364 |
|
|
365 |
|
//On récupère le statut de l'état du dossier à partir de l'identifiant du |
366 |
|
//dossier d'instruction |
367 |
|
$sql = "SELECT etat.statut |
368 |
|
FROM ".DB_PREFIXE."dossier |
369 |
|
LEFT JOIN |
370 |
|
".DB_PREFIXE."etat |
371 |
|
ON |
372 |
|
dossier.etat = etat.etat |
373 |
|
WHERE dossier ='".$idx."'"; |
374 |
|
$statut = $this->db->getOne($sql); |
375 |
|
$this->addToLog("getStatutDossier() : db->getOne(\"".$sql."\")", VERBOSE_MODE); |
376 |
|
if ( database::isError($statut)){ |
377 |
|
die(); |
378 |
|
} |
379 |
|
} |
380 |
|
return $statut; |
381 |
|
} |
382 |
|
|
383 |
|
/** |
384 |
|
* Formate le champ pour le type Timestamp |
385 |
|
* @param date $date_str Date |
386 |
|
* @param boolean $show Format pour l'affichage |
387 |
|
* @return mixed False si le traitement échoue ou la date formatée |
388 |
|
*/ |
389 |
|
function formatTimestamp ($date_str, $show = true) { |
390 |
|
|
391 |
|
// Sépare la date et l'heure |
392 |
|
$date = explode(" ", $date_str); |
393 |
|
if (count($date) != 2) { |
394 |
|
return false; |
395 |
|
} |
396 |
|
|
397 |
|
// Date en BDD |
398 |
|
$date_db = explode ('-', $date[0]); |
399 |
|
// Date en affichage |
400 |
|
$date_show = explode ('/', $date[0]); |
401 |
|
|
402 |
|
// Contrôle la composition de la date |
403 |
|
if (count ($date_db) != 3 and count ($date_show) != 3) { |
404 |
|
return false; |
405 |
|
} |
406 |
|
|
407 |
|
if (count ($date_db) == 3) { |
408 |
|
// Vérifie que c'est une date valide |
409 |
|
if (!checkdate($date_db[1], $date_db[2], $date_db[0])) { |
410 |
|
return false; |
411 |
|
} |
412 |
|
// Si c'est pour l'affichage de la date |
413 |
|
if ($show == true) { |
414 |
|
return $date_db [2]."/".$date_db [1]."/".$date_db [0]." ".$date[1]; |
415 |
|
} else { |
416 |
|
return $date[0]; |
417 |
|
} |
418 |
|
} |
419 |
|
|
420 |
// |
// |
421 |
if (isset($chemin_plan)) { |
if (count ($date_show) == 3) { |
422 |
$this->config['chemin_plan'] = $chemin_plan; |
// Vérifie que c'est une date valide |
423 |
} else { |
if (!checkdate($date_show[1], $date_show[0], $date_show[2])) { |
424 |
$this->config['chemin_plan'] = "../trs/"; |
return false; |
425 |
|
} |
426 |
|
// Si c'est pour l'affichage de la date |
427 |
|
if ($show == true) { |
428 |
|
return $date[0]; |
429 |
|
} else { |
430 |
|
return $date_show [2]."-".$date_show [1]."-".$date_show [0]." ".$date[1]; |
431 |
|
} |
432 |
|
|
433 |
} |
} |
434 |
|
return false; |
435 |
|
|
436 |
} |
} |
437 |
|
} |
438 |
|
|
|
} //fin class |
|
|
?> |
|
439 |
|
?> |