37 |
*/ |
*/ |
38 |
class utils extends application { |
class utils extends application { |
39 |
|
|
40 |
/** |
// {{{ |
|
* Constructeur |
|
|
* |
|
|
* @param |
|
|
* @param |
|
|
* @param |
|
|
* @param |
|
|
* @param |
|
|
*/ |
|
|
function __construct($flag = NULL, $right = NULL, $title = NULL, $icon = NULL, $help = NULL) { |
|
41 |
|
|
42 |
// |
// Ajout de variables de session contenant la division pour permettre une |
43 |
$this->timestart = microtime(true); |
// utilisation plus efficace dans les requetes |
44 |
|
function triggerAfterLogin($utilisateur = NULL) { |
45 |
// Logger |
// |
46 |
$this->addToLog("__construct() : 0.000 sec", VERBOSE_MODE); |
$sql = "SELECT instructeur.division, division.code |
47 |
|
FROM ".DB_PREFIXE."instructeur |
48 |
// Logger |
LEFT JOIN ".DB_PREFIXE."division |
49 |
$this->addToLog("__construct()", EXTRA_VERBOSE_MODE); |
ON instructeur.division = division.division |
50 |
|
WHERE instructeur.om_utilisateur='".$utilisateur["om_utilisateur"]."'"; |
51 |
// Instanciation de la classe message |
$res = $this->db->query($sql); |
52 |
$this->m = new message(); |
$this->addToLog("triggerAfterLogin(): db->query(\"".$sql."\");", VERBOSE_MODE); |
53 |
|
$this->isDatabaseError($res); |
54 |
// |
$row = $res->fetchrow(DB_FETCHMODE_ASSOC); |
55 |
$this->setParamsFromFiles(); |
// |
56 |
$this->checkParams(); |
if (isset($row["division"]) && $row["division"] != NULL) { |
57 |
|
$_SESSION["division"] = $row["division"]; |
58 |
// |
$_SESSION["division_code"] = $row["code"]; |
59 |
$this->setDefaultValues(); |
} else { |
60 |
|
$_SESSION["division"] = "0"; |
61 |
// Transformation des cinq éléments paramètres en attribut de l'objet |
$_SESSION["division_code"] = ""; |
|
$this->setFlag($flag); |
|
|
$this->setTitle($title); |
|
|
$this->setRight($right); |
|
|
$this->setHelp($help); |
|
|
$this->setIcon($icon); |
|
|
|
|
|
// Vérification de l'authentification de l'utilisateur et stockage du |
|
|
// résultat en attribut de l'objet |
|
|
$this->authenticated = $this->isAuthenticated(); |
|
|
|
|
|
// Déconnexion de l'utilisateur |
|
|
if ($this->flag == "logout") { |
|
|
$this->logout(); |
|
|
} |
|
|
|
|
|
// Connexion de l'utilisateur |
|
|
if ($this->flag == "login") { |
|
|
$this->login(); |
|
|
} |
|
|
|
|
|
// Demande de redéfinition du mot de passe |
|
|
if ($this->flag == "password_reset") { |
|
|
if ($this->authenticated) { |
|
|
$this->redirectAuthenticatedUsers(); |
|
|
} |
|
|
} |
|
|
|
|
|
// |
|
|
if ($this->authenticated) { |
|
|
// Connexion à la base de données si l'utilisateur est authentifié |
|
|
$this->connectDatabase(); |
|
|
// on verifie que l'utilisateur connecté est toujours valide |
|
|
if (!defined('REST_REQUEST')) { |
|
|
$this->checkIfUserIsAlwaysValid(); |
|
|
} |
|
62 |
} |
} |
63 |
|
|
64 |
// |
} |
|
if (!in_array($this->flag, $this->special_flags)) { |
|
|
|
|
|
// |
|
|
$this->getAllRights(); |
|
|
|
|
|
// |
|
|
$this->getCollectivite(); |
|
|
|
|
|
// |
|
|
$this->isAuthorized(); |
|
65 |
|
|
66 |
|
// Affichage des actions supplémentaires |
67 |
|
function displayActionExtras() { |
68 |
|
// Affichage de la division si l'utilisateur en possède une |
69 |
|
if ($_SESSION["division"] != 0) { |
70 |
|
echo "\t\t\t<li class=\"action-division\">"; |
71 |
|
echo "(".$_SESSION['division_code'].")"; |
72 |
|
echo "</li>\n"; |
73 |
} |
} |
|
|
|
|
// |
|
|
$this->setMoreParams(); |
|
|
|
|
|
// Affichage HTML |
|
|
$this->display(); |
|
|
|
|
74 |
} |
} |
75 |
|
|
76 |
|
// }}} |
|
|
|
|
/** |
|
|
* Desctructeur de la classe, cette methode (appelee automatiquement) |
|
|
* permet d'afficher le footer de la page, le footer HTML, et de |
|
|
* deconnecter la base de donnees |
|
|
* |
|
|
* @return void |
|
|
*/ |
|
|
function __destruct() { |
|
|
|
|
|
// Footer |
|
|
if (!defined('REST_REQUEST')) { |
|
|
$this->displayFooter(); |
|
|
} |
|
|
|
|
|
// Deconnexion SGBD |
|
|
$this->disconnectDatabase(); |
|
|
|
|
|
// Logger |
|
|
$this->addToLog("__destruct()", EXTRA_VERBOSE_MODE); |
|
|
|
|
|
// Logger |
|
|
$this->addToLog("__destruct() : ".$this->elapsedtime()." sec", VERBOSE_MODE); |
|
|
|
|
|
// Affichage des logs |
|
|
logger::instance()->displayLog(); |
|
|
|
|
|
// Footer HTML |
|
|
if (!defined('REST_REQUEST')) { |
|
|
$this->displayHTMLFooter(); |
|
|
} |
|
|
} |
|
|
|
|
77 |
|
|
78 |
|
|
79 |
|
var $om_utilisateur = array(); |
80 |
|
var $user_is_instr = false; |
81 |
|
var $user_is_service_ext = false; |
82 |
|
|
83 |
/** |
/** |
84 |
* Cette methode permet de charger les differents fichiers de configs dans |
* Surcharge du constructeur de la classe |
|
* des attributs de la classe |
|
|
* |
|
|
* @return void |
|
85 |
*/ |
*/ |
86 |
function setParamsFromFiles() { |
function __construct($flag = NULL, $right = NULL, $title = NULL, $icon = NULL, $help = NULL) { |
87 |
|
parent::__construct($flag, $right, $title, $icon, $help); |
88 |
// |
$this->getUserInfos(); |
89 |
if (file_exists("../dyn/config.inc.php")) { |
} |
|
include_once("../dyn/config.inc.php"); |
|
|
} |
|
|
if (isset($config)) { |
|
|
$this->config = $config; |
|
|
} |
|
|
|
|
|
// |
|
|
if (file_exists("../dyn/database.inc.php")) { |
|
|
include("../dyn/database.inc.php"); |
|
|
} |
|
|
|
|
|
if (isset($conn)) { |
|
|
$this->conn = $conn; |
|
|
// |
|
|
foreach($this->conn as $key => $conn) { |
|
|
$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' => (isset($conn[12]) ? $conn[12]: ""), |
|
|
'directory' => (isset($conn[13]) ? $conn[13]: ""), |
|
|
'mail' => (isset($conn[14]) ? $conn[14]: ""), |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
// |
|
|
if (file_exists("../dyn/directory.inc.php")) { |
|
|
include_once("../dyn/directory.inc.php"); |
|
|
} |
|
|
if (isset($directory)) { |
|
|
$this->directory = $directory; |
|
|
} |
|
|
|
|
|
// |
|
|
if (file_exists("../dyn/mail.inc.php")) { |
|
|
include_once("../dyn/mail.inc.php"); |
|
|
} |
|
|
if (isset($mail)) { |
|
|
$this->mail = $mail; |
|
|
} |
|
|
|
|
|
// |
|
|
if (file_exists("../dyn/menu.inc.php")) { |
|
|
include_once("../dyn/menu.inc.php"); |
|
|
} |
|
|
if (isset($menu)) { |
|
|
$this->menu = $menu; |
|
|
} |
|
90 |
|
|
|
// |
|
|
if (file_exists("../dyn/actions.inc.php")) { |
|
|
include_once("../dyn/actions.inc.php"); |
|
|
} |
|
|
if (isset($actions)) { |
|
|
$this->actions = $actions; |
|
|
} |
|
91 |
|
|
|
// |
|
|
if (file_exists("../dyn/shortlinks.inc.php")) { |
|
|
include_once("../dyn/shortlinks.inc.php"); |
|
|
} |
|
|
if (isset($shortlinks)) { |
|
|
$this->shortlinks = $shortlinks; |
|
|
} |
|
92 |
|
|
|
// |
|
|
if (file_exists("../dyn/footer.inc.php")) { |
|
|
include_once("../dyn/footer.inc.php"); |
|
|
} |
|
|
if (isset($footer)) { |
|
|
$this->footer = $footer; |
|
|
} |
|
|
|
|
|
// |
|
|
if (file_exists("../dyn/version.inc.php")) { |
|
|
include_once("../dyn/version.inc.php"); |
|
|
} |
|
|
if (isset($version)) { |
|
|
$this->version = $version; |
|
|
} |
|
93 |
|
|
|
} |
|
|
|
|
|
|
|
94 |
/** |
/** |
95 |
* Cette méthode permet de vérifier si l'utilisateur est autorisé ou non à |
* Cette méthode permet de vérifier si l'utilisateur est autorisé ou non à |
96 |
* accéder à un élément et permet d'agir en conséquence |
* accéder à un élément et permet d'agir en conséquence |
306 |
} |
} |
307 |
|
|
308 |
|
|
|
/** |
|
|
* |
|
|
*/ |
|
|
function addToLog($message, $type = DEBUG_MODE) { |
|
|
// |
|
|
if (!defined('REST_REQUEST')) { |
|
|
logger::instance()->log("class ".get_class($this)." - ".$message, $type); |
|
|
} |
|
|
} |
|
309 |
|
|
310 |
/** |
/** |
311 |
* Envoie un mail avec piece jointe |
* Envoie un mail avec piece jointe |
340 |
|
|
341 |
// |
// |
342 |
$mail->IsSMTP(); |
$mail->IsSMTP(); |
343 |
|
|
344 |
|
$mail->SMTPAuth = true; // enable SMTP authentication |
345 |
|
$mail->SMTPSecure = "tls"; |
346 |
$mail->Username = $this->mail_config["mail_username"]; |
$mail->Username = $this->mail_config["mail_username"]; |
347 |
$mail->Password = $this->mail_config["mail_pass"]; |
$mail->Password = $this->mail_config["mail_pass"]; |
348 |
if ($this->mail_config["mail_username"] == '') { |
if ($this->mail_config["mail_username"] == '') { |
389 |
} |
} |
390 |
} |
} |
391 |
|
|
392 |
|
/** |
393 |
|
* |
394 |
|
*/ |
395 |
|
function isAccredited($obj = NULL, $operator = "AND") { |
396 |
|
// Lorsque l'utilisateur a le login 'admin' alors il est authorisé à |
397 |
|
// accéder à toutes les fonctions du logiciel |
398 |
|
// XXX à modifier pour changer ça vers un profil et non un login utilisateur |
399 |
|
if ($_SESSION["login"] == "admin") { |
400 |
|
return true; |
401 |
|
} |
402 |
|
// Fonctionnement standard |
403 |
|
return parent::isAccredited($obj, $operator); |
404 |
|
} |
405 |
|
|
406 |
|
/** |
407 |
|
* Méthode de création de répertoire dans le dossier /trs correspondant |
408 |
|
* à l'id du tableau de configuration de la connexion à la base de donnée |
409 |
|
* (dyn/database.inc.php) |
410 |
|
**/ |
411 |
|
function createFolder($folder) { |
412 |
|
if (!mkdir($this->getPathFolderTrs().$folder)) { |
413 |
|
// message |
414 |
|
$message_class = "error"; |
415 |
|
$message = _("Echec lors de la creation du repertoires."); |
416 |
|
$this->addToMessage ($message_class, $message); |
417 |
|
} |
418 |
|
} |
419 |
|
|
420 |
|
/* |
421 |
|
* Methode permettant de lister tous les fichiers d'un dossier |
422 |
|
*/ |
423 |
|
function getFolderFileList($id_folder) { |
424 |
|
|
425 |
|
$file_list = array(); |
426 |
|
if(is_dir($this->getPathFolderTrs().$id_folder)) { |
427 |
|
if($dossier = opendir($this->getPathFolderTrs().$id_folder)) { |
428 |
|
|
429 |
|
while(false !== ($fichier = readdir($dossier))) { |
430 |
|
|
431 |
|
if($fichier != '.' && $fichier != '..' && !is_dir($fichier)) { |
432 |
|
$file_list[]=array( $fichier, |
433 |
|
filemtime($this->getPathFolderTrs().$id_folder."/".$fichier)); |
434 |
|
} // On ferme le if (qui permet de ne pas afficher index.php, etc.) |
435 |
|
|
436 |
|
} // On termine la boucle |
437 |
|
|
438 |
|
closedir($dossier); |
439 |
|
|
440 |
|
} else { |
441 |
|
$this->displayMessage("error", _("Les documents du repertoire ne sont pas accessible.")); |
442 |
|
} |
443 |
|
} else { |
444 |
|
$this->displayMessage("error", _("Ce repertoire n'a pas de document.")); |
445 |
|
} |
446 |
|
return $file_list; |
447 |
|
} |
448 |
|
|
449 |
|
/* |
450 |
|
* Store the data recived in the request into a file on the |
451 |
|
* local filesystem. |
452 |
|
* @todo This function will need to be changed for the save to |
453 |
|
* be on GED |
454 |
|
* @param mixed $data The data received with the request |
455 |
|
* @param string $id The consultation ID |
456 |
|
* @return string OK on success, KO otherwise |
457 |
|
*/ |
458 |
|
|
459 |
|
function storeDecisionFile(&$fichier_base64, $basename, $dossier, $prefix = '') { |
460 |
|
|
461 |
|
if (empty($fichier_base64)) { |
462 |
|
$this -> addToMessage("error", _("Le fichier est vide")); |
463 |
|
return false; |
464 |
|
} |
465 |
|
$dir = $this->getPathFolderTrs().$dossier; |
466 |
|
|
467 |
|
// if a file already exists by that name and it |
468 |
|
// is not a directory, back out |
469 |
|
/*if (file_exists($dir) AND is_dir($dir)) { |
470 |
|
$this -> addToMessage("error", _("Le repertoire n'existe pas, le fichier ne peut pas etre enregistre.")); |
471 |
|
return false; |
472 |
|
}*/ |
473 |
|
// if a dirextory by that name exists, make sure it does |
474 |
|
// not already contain an avis de consultation, MAYBE WE DON'T NEED THIS |
475 |
|
if (file_exists($dir) AND is_dir($dir)) { |
476 |
|
$dir_contents = trim(shell_exec('ls '.$dir)); |
477 |
|
if (strpos($dir_contents, ' ') != false) { |
478 |
|
$dir_contents = explode(' ', $dir_contents); |
479 |
|
} else { |
480 |
|
$dir_contents = array($dir_contents); |
481 |
|
} |
482 |
|
foreach ($dir_contents as $basefname) { // very useful for consultation |
483 |
|
if (strpos($basefname, $prefix)!==false) { |
484 |
|
return _("Un retour d'avis existe deja."); |
485 |
|
|
486 |
|
} |
487 |
|
} |
488 |
|
} else { |
489 |
|
$this->createFolder($dossier); |
490 |
|
} |
491 |
|
|
492 |
|
// store the file contents into the file named: |
493 |
|
// consultation_<ID>_<file_name_received> |
494 |
|
$file_len = strlen($fichier_base64); |
495 |
|
|
496 |
|
$filename = $dir."/".$prefix.$basename; |
497 |
|
|
498 |
|
$file = fopen($filename, 'w'); |
499 |
|
if (!$file) { |
500 |
|
return _("Echec a la creation du fichier."); |
501 |
|
} |
502 |
|
// check that the number of bytes written is equal to the length |
503 |
|
// of the data received |
504 |
|
$num_written = fwrite($file, $fichier_base64, $file_len); |
505 |
|
|
506 |
|
if (!$num_written) { |
507 |
|
// remove the file |
508 |
|
// the return value from shell can't be used for checking since |
509 |
|
// one can not know if the NULL returned is because there was no |
510 |
|
// output or because there was an error |
511 |
|
$ret = shell_exec("rm -f $filename 2>&1"); |
512 |
|
//if ($ret == NULL) { // an error occured while deleting the file |
513 |
|
//} |
514 |
|
return _("La sauvegarde du fichier a echoue"); |
515 |
|
} |
516 |
|
fclose($file); |
517 |
|
return true; |
518 |
|
} |
519 |
|
|
520 |
|
/** |
521 |
|
* |
522 |
|
*/ |
523 |
|
function notExistsError ($explanation = NULL) { |
524 |
|
// message |
525 |
|
$message_class = "error"; |
526 |
|
$message = _("Cette page n'existe pas."); |
527 |
|
$this->addToMessage ($message_class, $message); |
528 |
|
// |
529 |
|
$this->setFlag(NULL); |
530 |
|
$this->display(); |
531 |
|
|
532 |
|
// |
533 |
|
die(); |
534 |
|
} |
535 |
|
|
536 |
|
/** |
537 |
|
* Méthode de récupération des informations de l'utilisateur connecté. |
538 |
|
*/ |
539 |
|
function getUserInfos() { |
540 |
|
|
541 |
|
// Si l'utilisateur est loggé $_SESSION existe |
542 |
|
if(isset($_SESSION['login']) AND !empty($_SESSION['login'])) { |
543 |
|
|
544 |
|
// Récupération des infos utilisateur |
545 |
|
$sqlUser = "SELECT om_utilisateur, nom, email, login, om_collectivite, om_profil ". |
546 |
|
"FROM om_utilisateur WHERE login = '".$_SESSION['login']."'"; |
547 |
|
$resUser=$this->db->query($sqlUser); |
548 |
|
$this->addToLog("getUserInfos(): db->query(\"".$sqlUser."\");", VERBOSE_MODE); |
549 |
|
$this->isDatabaseError($resUser); |
550 |
|
$this->om_utilisateur=&$resUser->fetchRow(DB_FETCHMODE_ASSOC); |
551 |
|
|
552 |
|
// Récupération des infos instructeur |
553 |
|
$sqlInstr = "SELECT instructeur.instructeur, instructeur.nom, instructeur.telephone, division.code, division.libelle ". |
554 |
|
"FROM instructeur INNER JOIN division ON division.division=instructeur.division ". |
555 |
|
"WHERE instructeur.om_utilisateur = ".$this->om_utilisateur['om_utilisateur']; |
556 |
|
$resInstr=$this->db->query($sqlInstr); |
557 |
|
$this->addToLog("getUserInfos(): db->query(\"".$sqlInstr."\");", VERBOSE_MODE); |
558 |
|
$this->isDatabaseError($resInstr); |
559 |
|
$tempInstr=&$resInstr->fetchRow(DB_FETCHMODE_ASSOC); |
560 |
|
// Si il y a un resultat c'est un instructeur |
561 |
|
if(count($tempInstr)>0) { |
562 |
|
$this->user_is_instr=true; |
563 |
|
$this->om_utilisateur = array_merge($this->om_utilisateur,$tempInstr); |
564 |
|
} |
565 |
|
|
566 |
|
// Récupération des infos de services ext consultés |
567 |
|
$sqlServExt = "SELECT service.service, service.abrege, service.libelle ". |
568 |
|
"FROM service ". |
569 |
|
"INNER JOIN lien_service_om_utilisateur ON lien_service_om_utilisateur.service=service.service ". |
570 |
|
"WHERE lien_service_om_utilisateur.om_utilisateur = ".$this->om_utilisateur['om_utilisateur']; |
571 |
|
$resServExt=$this->db->query($sqlServExt); |
572 |
|
$this->addToLog("getUserInfos(): db->query(\"".$sqlServExt."\");", VERBOSE_MODE); |
573 |
|
$this->isDatabaseError($resServExt); |
574 |
|
|
575 |
|
while ($tempServExt=&$resServExt->fetchRow(DB_FETCHMODE_ASSOC)) { |
576 |
|
$this->om_utilisateur['service'][]=$tempServExt; |
577 |
|
} |
578 |
|
// Si il y a un resultat c'est un utilisateur de service |
579 |
|
if(isset($this->om_utilisateur['service'])) { |
580 |
|
$this->user_is_service_ext=true; |
581 |
|
} |
582 |
|
} |
583 |
|
} |
584 |
|
|
585 |
|
/** |
586 |
|
* getter user_is_service_ext |
587 |
|
*/ |
588 |
|
function isUserServiceExt() { |
589 |
|
return $this->user_is_service_ext; |
590 |
|
} |
591 |
|
/** |
592 |
|
* getter user_is_instr |
593 |
|
*/ |
594 |
|
function isUserInstructeur() { |
595 |
|
return $this->user_is_instr; |
596 |
|
} |
597 |
} |
} |
598 |
|
|
599 |
?> |
?> |