37 |
*/ |
*/ |
38 |
class utils extends application { |
class utils extends application { |
39 |
|
|
40 |
|
var $om_utilisateur = array(); |
41 |
|
var $user_is_instr = false; |
42 |
|
var $user_is_service_ext = false; |
43 |
|
|
44 |
/** |
/** |
45 |
* Constructeur |
* Surcharge du constructeur de la classe |
|
* |
|
|
* @param |
|
|
* @param |
|
|
* @param |
|
|
* @param |
|
|
* @param |
|
46 |
*/ |
*/ |
47 |
function __construct($flag = NULL, $right = NULL, $title = NULL, $icon = NULL, $help = NULL) { |
function __construct($flag = NULL, $right = NULL, $title = NULL, $icon = NULL, $help = NULL) { |
48 |
|
parent::__construct($flag, $right, $title, $icon, $help); |
49 |
// |
$this->getUserInfos(); |
|
$this->timestart = microtime(true); |
|
|
|
|
|
// Logger |
|
|
$this->addToLog("__construct() : 0.000 sec", VERBOSE_MODE); |
|
|
|
|
|
// Logger |
|
|
$this->addToLog("__construct()", EXTRA_VERBOSE_MODE); |
|
|
|
|
|
// Instanciation de la classe message |
|
|
$this->m = new message(); |
|
|
|
|
|
// |
|
|
$this->setParamsFromFiles(); |
|
|
$this->checkParams(); |
|
|
|
|
|
// |
|
|
$this->setDefaultValues(); |
|
|
|
|
|
// Transformation des cinq éléments paramètres en attribut de l'objet |
|
|
$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(); |
|
|
} |
|
|
} |
|
|
|
|
|
// |
|
|
if (!in_array($this->flag, $this->special_flags)) { |
|
|
|
|
|
// |
|
|
$this->getAllRights(); |
|
|
|
|
|
// |
|
|
$this->getCollectivite(); |
|
|
|
|
|
// |
|
|
$this->isAuthorized(); |
|
|
|
|
|
} |
|
|
|
|
|
// |
|
|
$this->setMoreParams(); |
|
|
|
|
|
// Affichage HTML |
|
|
$this->display(); |
|
|
|
|
50 |
} |
} |
51 |
|
/** |
|
|
|
|
|
|
|
/** |
|
52 |
* Desctructeur de la classe, cette methode (appelee automatiquement) |
* Desctructeur de la classe, cette methode (appelee automatiquement) |
53 |
* permet d'afficher le footer de la page, le footer HTML, et de |
* permet d'afficher le footer de la page, le footer HTML, et de |
54 |
* deconnecter la base de donnees |
* deconnecter la base de donnees |
390 |
} |
} |
391 |
} |
} |
392 |
|
|
393 |
|
/** |
394 |
|
* |
395 |
|
*/ |
396 |
|
function isAccredited($obj = NULL, $operator = "AND") { |
397 |
|
// Lorsque l'utilisateur a le login 'admin' alors il est authorisé à |
398 |
|
// accéder à toutes les fonctions du logiciel |
399 |
|
// XXX à modifier pour changer ça vers un profil et non un login utilisateur |
400 |
|
if ($_SESSION["login"] == "admin") { |
401 |
|
return true; |
402 |
|
} |
403 |
|
// Fonctionnement standard |
404 |
|
return parent::isAccredited($obj, $operator); |
405 |
|
} |
406 |
|
|
407 |
|
/* |
408 |
|
* Methode permettant de lister tous les fichiers d'un dossier |
409 |
|
*/ |
410 |
|
function get_folder_file_list($id_folder) { |
411 |
|
|
412 |
|
$file_list = array(); |
413 |
|
if(is_dir('../trs/'.$id_folder)) { |
414 |
|
if($dossier = opendir('../trs/'.$id_folder)) { |
415 |
|
|
416 |
|
while(false !== ($fichier = readdir($dossier))) { |
417 |
|
|
418 |
|
if($fichier != '.' && $fichier != '..' && !is_dir($fichier)) { |
419 |
|
|
420 |
|
$file_list[]=$fichier; |
421 |
|
} // On ferme le if (qui permet de ne pas afficher index.php, etc.) |
422 |
|
|
423 |
|
} // On termine la boucle |
424 |
|
|
425 |
|
closedir($dossier); |
426 |
|
|
427 |
|
} else { |
428 |
|
$this->displayMessage("error", _("Les documents du dossier ne sont pas accessible.")); |
429 |
|
} |
430 |
|
} else { |
431 |
|
$this->displayMessage("error", _("Ce dossier n'a pas de document.")); |
432 |
|
} |
433 |
|
return $file_list; |
434 |
|
} |
435 |
|
|
436 |
|
/* |
437 |
|
* Store the data recived in the request into a file on the |
438 |
|
* local filesystem. |
439 |
|
* @todo This function will need to be changed for the save to |
440 |
|
* be on GED |
441 |
|
* @param mixed $data The data received with the request |
442 |
|
* @param string $id The consultation ID |
443 |
|
* @return string OK on success, KO otherwise |
444 |
|
*/ |
445 |
|
|
446 |
|
function storeDecisionFile(&$fichier_base64, $basename, $dossier, $prefix = '') { |
447 |
|
|
448 |
|
if (empty($fichier_base64)) { |
449 |
|
$this -> addToMessage("error", _("Le fichier est vide")); |
450 |
|
return false; |
451 |
|
} |
452 |
|
$dir = $this->getPathFolderTrs().$dossier; |
453 |
|
|
454 |
|
// if a file already exists by that name and it |
455 |
|
// is not a directory, back out |
456 |
|
/*if (file_exists($dir) AND is_dir($dir)) { |
457 |
|
$this -> addToMessage("error", _("Le repertoire n'existe pas, le fichier ne peut pas etre enregistre.")); |
458 |
|
return false; |
459 |
|
}*/ |
460 |
|
// if a dirextory by that name exists, make sure it does |
461 |
|
// not already contain an avis de consultation, MAYBE WE DON'T NEED THIS |
462 |
|
if (file_exists($dir) AND is_dir($dir)) { |
463 |
|
$dir_contents = trim(shell_exec('ls '.$dir)); |
464 |
|
if (strpos($dir_contents, ' ') != false) { |
465 |
|
$dir_contents = explode(' ', $dir_contents); |
466 |
|
} else { |
467 |
|
$dir_contents = array($dir_contents); |
468 |
|
} |
469 |
|
foreach ($dir_contents as $basefname) { // very useful for consultation |
470 |
|
if (strpos($basefname, $prefix)!==false) { |
471 |
|
return _("Un retour d'avis existe deja."); |
472 |
|
|
473 |
|
} |
474 |
|
} |
475 |
|
} else { |
476 |
|
return _("Le dossier n'existe pas."); |
477 |
|
} |
478 |
|
// if no file by that name exists, create the directory |
479 |
|
|
480 |
|
if (!file_exists($dir)) { |
481 |
|
if (!mkdir($dir, 0775)) { |
482 |
|
return _("Erreur dans la création de répertoire."); |
483 |
|
} |
484 |
|
} |
485 |
|
|
486 |
|
|
487 |
|
// store the file contents into the file named: |
488 |
|
// consultation_<ID>_<file_name_received> |
489 |
|
$file_len = strlen($fichier_base64); |
490 |
|
|
491 |
|
$filename = $dir."/".$prefix.$basename; |
492 |
|
|
493 |
|
$file = fopen($filename, 'w'); |
494 |
|
if (!$file) { |
495 |
|
return _("Echec a la creation du fichier."); |
496 |
|
} |
497 |
|
// check that the number of bytes written is equal to the length |
498 |
|
// of the data received |
499 |
|
$num_written = fwrite($file, $fichier_base64, $file_len); |
500 |
|
|
501 |
|
if (!$num_written) { |
502 |
|
// remove the file |
503 |
|
// the return value from shell can't be used for checking since |
504 |
|
// one can not know if the NULL returned is because there was no |
505 |
|
// output or because there was an error |
506 |
|
$ret = shell_exec("rm -f $filename 2>&1"); |
507 |
|
//if ($ret == NULL) { // an error occured while deleting the file |
508 |
|
//} |
509 |
|
return _("La sauvegarde du fichier a echoue"); |
510 |
|
} |
511 |
|
fclose($file); |
512 |
|
return true; |
513 |
|
} |
514 |
|
|
515 |
|
/** |
516 |
|
* |
517 |
|
*/ |
518 |
|
function notExistsError ($explanation = NULL) { |
519 |
|
// message |
520 |
|
$message_class = "error"; |
521 |
|
$message = _("Cette page n'existe pas."); |
522 |
|
$this->addToMessage ($message_class, $message); |
523 |
|
// |
524 |
|
$this->setFlag(NULL); |
525 |
|
$this->display(); |
526 |
|
|
527 |
|
// |
528 |
|
die(); |
529 |
|
} |
530 |
|
|
531 |
|
/** |
532 |
|
* Méthode de récupération des informations de l'utilisateur connecté. |
533 |
|
*/ |
534 |
|
function getUserInfos() { |
535 |
|
|
536 |
|
// Si l'utilisateur est loggé $_SESSION existe |
537 |
|
if(isset($_SESSION['login']) AND !empty($_SESSION['login'])) { |
538 |
|
|
539 |
|
// Récupération des infos utilisateur |
540 |
|
$sqlUser = "SELECT om_utilisateur, nom, email, login, om_collectivite, om_profil ". |
541 |
|
"FROM om_utilisateur WHERE login = '".$_SESSION['login']."'"; |
542 |
|
$resUser=$this->db->query($sqlUser); |
543 |
|
$this->addToLog("getUserInfos(): db->query(\"".$sqlUser."\");", VERBOSE_MODE); |
544 |
|
$this->isDatabaseError($resUser); |
545 |
|
$this->om_utilisateur=&$resUser->fetchRow(DB_FETCHMODE_ASSOC); |
546 |
|
|
547 |
|
// Récupération des infos instructeur |
548 |
|
$sqlInstr = "SELECT instructeur.instructeur, instructeur.nom, instructeur.telephone, division.code, division.libelle ". |
549 |
|
"FROM instructeur INNER JOIN division ON division.division=instructeur.division ". |
550 |
|
"WHERE instructeur.om_utilisateur = ".$this->om_utilisateur['om_utilisateur']; |
551 |
|
$resInstr=$this->db->query($sqlInstr); |
552 |
|
$this->addToLog("getUserInfos(): db->query(\"".$sqlInstr."\");", VERBOSE_MODE); |
553 |
|
$this->isDatabaseError($resInstr); |
554 |
|
$tempInstr=&$resInstr->fetchRow(DB_FETCHMODE_ASSOC); |
555 |
|
// Si il y a un resultat c'est un instructeur |
556 |
|
if(count($tempInstr)>0) { |
557 |
|
$this->user_is_instr=true; |
558 |
|
$this->om_utilisateur = array_merge($this->om_utilisateur,$tempInstr); |
559 |
|
} |
560 |
|
|
561 |
|
// Récupération des infos de services ext consultés |
562 |
|
$sqlServExt = "SELECT service.service, service.abrege, service.libelle ". |
563 |
|
"FROM service ". |
564 |
|
"INNER JOIN lien_service_om_utilisateur ON lien_service_om_utilisateur.service=service.service ". |
565 |
|
"WHERE lien_service_om_utilisateur.om_utilisateur = ".$this->om_utilisateur['om_utilisateur']; |
566 |
|
$resServExt=$this->db->query($sqlServExt); |
567 |
|
$this->addToLog("getUserInfos(): db->query(\"".$sqlServExt."\");", VERBOSE_MODE); |
568 |
|
$this->isDatabaseError($resServExt); |
569 |
|
|
570 |
|
while ($tempServExt=&$resServExt->fetchRow(DB_FETCHMODE_ASSOC)) { |
571 |
|
$this->om_utilisateur['service'][]=$tempServExt; |
572 |
|
} |
573 |
|
// Si il y a un resultat c'est un utilisateur de service |
574 |
|
if(isset($this->om_utilisateur['service'])) { |
575 |
|
$this->user_is_service_ext=true; |
576 |
|
} |
577 |
|
} |
578 |
|
} |
579 |
|
|
580 |
|
/** |
581 |
|
* getter user_is_service_ext |
582 |
|
*/ |
583 |
|
function isUserServiceExt() { |
584 |
|
return $this->user_is_service_ext; |
585 |
|
} |
586 |
|
/** |
587 |
|
* getter user_is_instr |
588 |
|
*/ |
589 |
|
function isUserInstructeur() { |
590 |
|
return $this->user_is_instr; |
591 |
|
} |
592 |
} |
} |
593 |
|
|
594 |
?> |
?> |