37 |
*/ |
*/ |
38 |
class utils extends application { |
class utils extends application { |
39 |
|
|
40 |
|
// {{{ |
41 |
|
|
42 |
|
// Ajout de variables de session contenant la division pour permettre une |
43 |
|
// utilisation plus efficace dans les requetes |
44 |
|
function triggerAfterLogin($utilisateur = NULL) { |
45 |
|
// |
46 |
|
$sql = "SELECT instructeur.division, division.code |
47 |
|
FROM ".DB_PREFIXE."instructeur |
48 |
|
LEFT JOIN ".DB_PREFIXE."division |
49 |
|
ON instructeur.division = division.division |
50 |
|
WHERE instructeur.om_utilisateur='".$utilisateur["om_utilisateur"]."'"; |
51 |
|
$res = $this->db->query($sql); |
52 |
|
$this->addToLog("triggerAfterLogin(): db->query(\"".$sql."\");", VERBOSE_MODE); |
53 |
|
$this->isDatabaseError($res); |
54 |
|
$row = $res->fetchrow(DB_FETCHMODE_ASSOC); |
55 |
|
// |
56 |
|
if (isset($row["division"]) && $row["division"] != NULL) { |
57 |
|
$_SESSION["division"] = $row["division"]; |
58 |
|
$_SESSION["division_code"] = $row["code"]; |
59 |
|
} else { |
60 |
|
$_SESSION["division"] = "0"; |
61 |
|
$_SESSION["division_code"] = ""; |
62 |
|
} |
63 |
|
|
64 |
|
} |
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 |
|
} |
74 |
|
} |
75 |
|
|
76 |
|
// }}} |
77 |
|
|
78 |
|
|
79 |
|
var $om_utilisateur = array(); |
80 |
|
var $user_is_instr = false; |
81 |
|
var $user_is_service_ext = false; |
82 |
|
|
83 |
|
/** |
84 |
|
* Surcharge du constructeur de la classe |
85 |
|
*/ |
86 |
|
function __construct($flag = NULL, $right = NULL, $title = NULL, $icon = NULL, $help = NULL) { |
87 |
|
parent::__construct($flag, $right, $title, $icon, $help); |
88 |
|
$this->getUserInfos(); |
89 |
|
} |
90 |
/** |
/** |
91 |
* Desctructeur de la classe, cette methode (appelee automatiquement) |
* Desctructeur de la classe, cette methode (appelee automatiquement) |
92 |
* 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 |
442 |
// Fonctionnement standard |
// Fonctionnement standard |
443 |
return parent::isAccredited($obj, $operator); |
return parent::isAccredited($obj, $operator); |
444 |
} |
} |
445 |
|
|
446 |
|
/* |
447 |
|
* Methode permettant de lister tous les fichiers d'un dossier |
448 |
|
*/ |
449 |
|
function get_folder_file_list($id_folder) { |
450 |
|
|
451 |
|
$file_list = array(); |
452 |
|
if(is_dir('../trs/'.$id_folder)) { |
453 |
|
if($dossier = opendir('../trs/'.$id_folder)) { |
454 |
|
|
455 |
|
while(false !== ($fichier = readdir($dossier))) { |
456 |
|
|
457 |
|
if($fichier != '.' && $fichier != '..' && !is_dir($fichier)) { |
458 |
|
|
459 |
|
$file_list[]=$fichier; |
460 |
|
} // On ferme le if (qui permet de ne pas afficher index.php, etc.) |
461 |
|
|
462 |
|
} // On termine la boucle |
463 |
|
|
464 |
|
closedir($dossier); |
465 |
|
|
466 |
|
} else { |
467 |
|
$this->displayMessage("error", _("Les documents du dossier ne sont pas accessible.")); |
468 |
|
} |
469 |
|
} else { |
470 |
|
$this->displayMessage("error", _("Ce dossier n'a pas de document.")); |
471 |
|
} |
472 |
|
return $file_list; |
473 |
|
} |
474 |
|
|
475 |
|
/* |
476 |
|
* Store the data recived in the request into a file on the |
477 |
|
* local filesystem. |
478 |
|
* @todo This function will need to be changed for the save to |
479 |
|
* be on GED |
480 |
|
* @param mixed $data The data received with the request |
481 |
|
* @param string $id The consultation ID |
482 |
|
* @return string OK on success, KO otherwise |
483 |
|
*/ |
484 |
|
|
485 |
|
function storeDecisionFile(&$fichier_base64, $basename, $dossier, $prefix = '') { |
486 |
|
|
487 |
|
if (empty($fichier_base64)) { |
488 |
|
$this -> addToMessage("error", _("Le fichier est vide")); |
489 |
|
return false; |
490 |
|
} |
491 |
|
$dir = $this->getPathFolderTrs().$dossier; |
492 |
|
|
493 |
|
// if a file already exists by that name and it |
494 |
|
// is not a directory, back out |
495 |
|
/*if (file_exists($dir) AND is_dir($dir)) { |
496 |
|
$this -> addToMessage("error", _("Le repertoire n'existe pas, le fichier ne peut pas etre enregistre.")); |
497 |
|
return false; |
498 |
|
}*/ |
499 |
|
// if a dirextory by that name exists, make sure it does |
500 |
|
// not already contain an avis de consultation, MAYBE WE DON'T NEED THIS |
501 |
|
if (file_exists($dir) AND is_dir($dir)) { |
502 |
|
$dir_contents = trim(shell_exec('ls '.$dir)); |
503 |
|
if (strpos($dir_contents, ' ') != false) { |
504 |
|
$dir_contents = explode(' ', $dir_contents); |
505 |
|
} else { |
506 |
|
$dir_contents = array($dir_contents); |
507 |
|
} |
508 |
|
foreach ($dir_contents as $basefname) { // very useful for consultation |
509 |
|
if (strpos($basefname, $prefix)!==false) { |
510 |
|
return _("Un retour d'avis existe deja."); |
511 |
|
|
512 |
|
} |
513 |
|
} |
514 |
|
} else { |
515 |
|
return _("Le dossier n'existe pas."); |
516 |
|
} |
517 |
|
// if no file by that name exists, create the directory |
518 |
|
|
519 |
|
if (!file_exists($dir)) { |
520 |
|
if (!mkdir($dir, 0775)) { |
521 |
|
return _("Erreur dans la création de répertoire."); |
522 |
|
} |
523 |
|
} |
524 |
|
|
525 |
|
|
526 |
|
// store the file contents into the file named: |
527 |
|
// consultation_<ID>_<file_name_received> |
528 |
|
$file_len = strlen($fichier_base64); |
529 |
|
|
530 |
|
$filename = $dir."/".$prefix.$basename; |
531 |
|
|
532 |
|
$file = fopen($filename, 'w'); |
533 |
|
if (!$file) { |
534 |
|
return _("Echec a la creation du fichier."); |
535 |
|
} |
536 |
|
// check that the number of bytes written is equal to the length |
537 |
|
// of the data received |
538 |
|
$num_written = fwrite($file, $fichier_base64, $file_len); |
539 |
|
|
540 |
|
if (!$num_written) { |
541 |
|
// remove the file |
542 |
|
// the return value from shell can't be used for checking since |
543 |
|
// one can not know if the NULL returned is because there was no |
544 |
|
// output or because there was an error |
545 |
|
$ret = shell_exec("rm -f $filename 2>&1"); |
546 |
|
//if ($ret == NULL) { // an error occured while deleting the file |
547 |
|
//} |
548 |
|
return _("La sauvegarde du fichier a echoue"); |
549 |
|
} |
550 |
|
fclose($file); |
551 |
|
return true; |
552 |
|
} |
553 |
|
|
554 |
|
/** |
555 |
|
* |
556 |
|
*/ |
557 |
|
function notExistsError ($explanation = NULL) { |
558 |
|
// message |
559 |
|
$message_class = "error"; |
560 |
|
$message = _("Cette page n'existe pas."); |
561 |
|
$this->addToMessage ($message_class, $message); |
562 |
|
// |
563 |
|
$this->setFlag(NULL); |
564 |
|
$this->display(); |
565 |
|
|
566 |
|
// |
567 |
|
die(); |
568 |
|
} |
569 |
|
|
570 |
|
/** |
571 |
|
* Méthode de récupération des informations de l'utilisateur connecté. |
572 |
|
*/ |
573 |
|
function getUserInfos() { |
574 |
|
|
575 |
|
// Si l'utilisateur est loggé $_SESSION existe |
576 |
|
if(isset($_SESSION['login']) AND !empty($_SESSION['login'])) { |
577 |
|
|
578 |
|
// Récupération des infos utilisateur |
579 |
|
$sqlUser = "SELECT om_utilisateur, nom, email, login, om_collectivite, om_profil ". |
580 |
|
"FROM om_utilisateur WHERE login = '".$_SESSION['login']."'"; |
581 |
|
$resUser=$this->db->query($sqlUser); |
582 |
|
$this->addToLog("getUserInfos(): db->query(\"".$sqlUser."\");", VERBOSE_MODE); |
583 |
|
$this->isDatabaseError($resUser); |
584 |
|
$this->om_utilisateur=&$resUser->fetchRow(DB_FETCHMODE_ASSOC); |
585 |
|
|
586 |
|
// Récupération des infos instructeur |
587 |
|
$sqlInstr = "SELECT instructeur.instructeur, instructeur.nom, instructeur.telephone, division.code, division.libelle ". |
588 |
|
"FROM instructeur INNER JOIN division ON division.division=instructeur.division ". |
589 |
|
"WHERE instructeur.om_utilisateur = ".$this->om_utilisateur['om_utilisateur']; |
590 |
|
$resInstr=$this->db->query($sqlInstr); |
591 |
|
$this->addToLog("getUserInfos(): db->query(\"".$sqlInstr."\");", VERBOSE_MODE); |
592 |
|
$this->isDatabaseError($resInstr); |
593 |
|
$tempInstr=&$resInstr->fetchRow(DB_FETCHMODE_ASSOC); |
594 |
|
// Si il y a un resultat c'est un instructeur |
595 |
|
if(count($tempInstr)>0) { |
596 |
|
$this->user_is_instr=true; |
597 |
|
$this->om_utilisateur = array_merge($this->om_utilisateur,$tempInstr); |
598 |
|
} |
599 |
|
|
600 |
|
// Récupération des infos de services ext consultés |
601 |
|
$sqlServExt = "SELECT service.service, service.abrege, service.libelle ". |
602 |
|
"FROM service ". |
603 |
|
"INNER JOIN lien_service_om_utilisateur ON lien_service_om_utilisateur.service=service.service ". |
604 |
|
"WHERE lien_service_om_utilisateur.om_utilisateur = ".$this->om_utilisateur['om_utilisateur']; |
605 |
|
$resServExt=$this->db->query($sqlServExt); |
606 |
|
$this->addToLog("getUserInfos(): db->query(\"".$sqlServExt."\");", VERBOSE_MODE); |
607 |
|
$this->isDatabaseError($resServExt); |
608 |
|
|
609 |
|
while ($tempServExt=&$resServExt->fetchRow(DB_FETCHMODE_ASSOC)) { |
610 |
|
$this->om_utilisateur['service'][]=$tempServExt; |
611 |
|
} |
612 |
|
// Si il y a un resultat c'est un utilisateur de service |
613 |
|
if(isset($this->om_utilisateur['service'])) { |
614 |
|
$this->user_is_service_ext=true; |
615 |
|
} |
616 |
|
} |
617 |
|
} |
618 |
|
|
619 |
|
/** |
620 |
|
* getter user_is_service_ext |
621 |
|
*/ |
622 |
|
function isUserServiceExt() { |
623 |
|
return $this->user_is_service_ext; |
624 |
|
} |
625 |
|
/** |
626 |
|
* getter user_is_instr |
627 |
|
*/ |
628 |
|
function isUserInstructeur() { |
629 |
|
return $this->user_is_instr; |
630 |
|
} |
631 |
} |
} |
632 |
|
|
633 |
?> |
?> |