37 |
*/ |
*/ |
38 |
class utils extends application { |
class utils extends application { |
39 |
|
|
40 |
|
|
41 |
/** |
/** |
|
* Constructeur |
|
|
* |
|
|
* @param |
|
|
* @param |
|
|
* @param |
|
|
* @param |
|
|
* @param |
|
|
*/ |
|
|
function __construct($flag = NULL, $right = NULL, $title = NULL, $icon = NULL, $help = NULL) { |
|
|
|
|
|
// |
|
|
$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(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
42 |
* Desctructeur de la classe, cette methode (appelee automatiquement) |
* Desctructeur de la classe, cette methode (appelee automatiquement) |
43 |
* 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 |
44 |
* deconnecter la base de donnees |
* deconnecter la base de donnees |
72 |
|
|
73 |
|
|
74 |
|
|
|
/** |
|
|
* Cette methode permet de charger les differents fichiers de configs dans |
|
|
* des attributs de la classe |
|
|
* |
|
|
* @return void |
|
|
*/ |
|
|
function setParamsFromFiles() { |
|
|
|
|
|
// |
|
|
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; |
|
|
} |
|
|
|
|
|
// |
|
|
if (file_exists("../dyn/actions.inc.php")) { |
|
|
include_once("../dyn/actions.inc.php"); |
|
|
} |
|
|
if (isset($actions)) { |
|
|
$this->actions = $actions; |
|
|
} |
|
|
|
|
|
// |
|
|
if (file_exists("../dyn/shortlinks.inc.php")) { |
|
|
include_once("../dyn/shortlinks.inc.php"); |
|
|
} |
|
|
if (isset($shortlinks)) { |
|
|
$this->shortlinks = $shortlinks; |
|
|
} |
|
|
|
|
|
// |
|
|
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; |
|
|
} |
|
|
|
|
|
} |
|
75 |
|
|
|
|
|
76 |
/** |
/** |
77 |
* 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 à |
78 |
* accéder à un élément et permet d'agir en conséquence |
* accéder à un élément et permet d'agir en conséquence |
126 |
// On recupere la liste des cles du tableau associatif de configuration |
// On recupere la liste des cles du tableau associatif de configuration |
127 |
// de la connexion aux bases de donnees |
// de la connexion aux bases de donnees |
128 |
$database_keys = array_keys($this->database); |
$database_keys = array_keys($this->database); |
|
//print ' database keys:'; |
|
|
//print_r($database_keys); |
|
129 |
// Si il y a plusieurs cles |
// Si il y a plusieurs cles |
130 |
if (count($database_keys) != 0) { |
if (count($database_keys) != 0) { |
131 |
// On configure la premiere par defaut |
// On configure la premiere par defaut |
163 |
} |
} |
164 |
|
|
165 |
// On renvoi le tableau de parametres pour la connexion a la base |
// On renvoi le tableau de parametres pour la connexion a la base |
|
//print ' $coll:'.$coll.' '; |
|
|
//print ' database:'; |
|
|
//print_r($this->database[$coll]); |
|
166 |
$this->database_config = $this->database[$coll]; |
$this->database_config = $this->database[$coll]; |
167 |
} |
} |
168 |
|
|
201 |
$this->display(); |
$this->display(); |
202 |
} |
} |
203 |
// On arrete le script |
// On arrete le script |
|
//print 'and we die'; |
|
204 |
die(); |
die(); |
205 |
} else { |
} else { |
206 |
// On affecte la resource a l'attribut de la classe du meme nom |
// On affecte la resource a l'attribut de la classe du meme nom |
298 |
} |
} |
299 |
} |
} |
300 |
|
|
301 |
|
/** |
302 |
|
* Envoie un mail avec piece jointe |
303 |
|
* |
304 |
|
* @param string $title Titre du mail |
305 |
|
* @param string $message Corps du mail |
306 |
|
* @param string $recipient Destinataire du mail |
307 |
|
* @param array $file Destinataire du mail |
308 |
|
* @access public |
309 |
|
* @return bool True si le mail est correctement envoye, false sinon. |
310 |
|
*/ |
311 |
|
public function sendMail($title, $message, $recipient, $file = array()) { |
312 |
|
|
313 |
|
@include_once "../php/phpmailer/class.phpmailer.php"; |
314 |
|
|
315 |
|
if (!class_exists("PHPMailer")) { |
316 |
|
$this->addToLog("sendMail(): !class_exists(\"PHPMailer\")", DEBUG_MODE); |
317 |
|
return false; |
318 |
|
} |
319 |
|
|
320 |
|
// |
321 |
|
$this->setMailConfig(); |
322 |
|
|
323 |
|
// |
324 |
|
if ($this->mail_config == false) { |
325 |
|
$this->addToLog("sendMail(): aucune configuration mail", DEBUG_MODE); |
326 |
|
return false; |
327 |
|
} |
328 |
|
|
329 |
|
// |
330 |
|
$mail = new PHPMailer(true); |
331 |
|
|
332 |
|
// |
333 |
|
$mail->IsSMTP(); |
334 |
|
|
335 |
|
$mail->SMTPAuth = true; // enable SMTP authentication |
336 |
|
$mail->SMTPSecure = "tls"; |
337 |
|
$mail->Username = $this->mail_config["mail_username"]; |
338 |
|
$mail->Password = $this->mail_config["mail_pass"]; |
339 |
|
if ($this->mail_config["mail_username"] == '') { |
340 |
|
$mail->SMTPAuth = false; |
341 |
|
} else { |
342 |
|
$mail->SMTPAuth = true; |
343 |
|
} |
344 |
|
$mail->Port = $this->mail_config["mail_port"]; |
345 |
|
$mail->Host = $this->mail_config["mail_host"]; |
346 |
|
$mail->AddReplyTo($this->mail_config["mail_from"], $this->mail_config["mail_from_name"]); |
347 |
|
$mail->From = $this->mail_config["mail_from"]; |
348 |
|
$mail->FromName = $this->mail_config["mail_from_name"]; |
349 |
|
foreach (explode(",",$recipient) as $adresse) { |
350 |
|
if (!$this->checkValidEmailAddress($adresse)) { |
351 |
|
$this->addToLog("sendMail(): courriel incorrect ".$adresse, DEBUG_MODE); |
352 |
|
return false; |
353 |
|
} else |
354 |
|
$mail->AddAddress(trim($adresse)); |
355 |
|
} |
356 |
|
$mail->IsHTML(true); |
357 |
|
|
358 |
|
// Corps du message |
359 |
|
$mail_body ="<html>"; |
360 |
|
$mail_body .= "<head><title>".$title."</title></head>"; |
361 |
|
$mail_body .= "<body>".$message."</body>"; |
362 |
|
$mail_body .= "</html>"; |
363 |
|
|
364 |
|
$mail->Subject = $title; |
365 |
|
$mail->MsgHTML($mail_body); |
366 |
|
foreach($file as $oneFile) { |
367 |
|
|
368 |
|
if($oneFile['stream']){ |
369 |
|
$mail->AddStringAttachment($oneFile['content'], $oneFile['title'], $oneFile['encoding'] = 'base64',$oneFile['type'] = 'application/octet-stream'); |
370 |
|
} else{ |
371 |
|
$mail->AddAttachment($oneFile['url']); |
372 |
|
} |
373 |
|
} |
374 |
|
// Envoie de l'email |
375 |
|
if ($mail->Send()) { |
376 |
|
return true; |
377 |
|
} else { |
378 |
|
$this->addToLog("sendMail(): ".$mail->ErrorInfo, DEBUG_MODE); |
379 |
|
return false; |
380 |
|
} |
381 |
|
} |
382 |
|
|
383 |
|
/** |
384 |
|
* |
385 |
|
*/ |
386 |
|
function isAccredited($obj = NULL, $operator = "AND") { |
387 |
|
// Lorsque l'utilisateur a le login 'admin' alors il est authorisé à |
388 |
|
// accéder à toutes les fonctions du logiciel |
389 |
|
// XXX à modifier pour changer ça vers un profil et non un login utilisateur |
390 |
|
if ($_SESSION["login"] == "admin") { |
391 |
|
return true; |
392 |
|
} |
393 |
|
// Fonctionnement standard |
394 |
|
return parent::isAccredited($obj, $operator); |
395 |
|
} |
396 |
|
|
397 |
|
/* |
398 |
|
* Methode permettant de lister tous les fichiers d'un dossier |
399 |
|
*/ |
400 |
|
function get_folder_file_list($id_folder) { |
401 |
|
|
402 |
|
$file_list = array(); |
403 |
|
if(is_dir('../trs/'.$id_folder)) { |
404 |
|
if($dossier = opendir('../trs/'.$id_folder)) { |
405 |
|
|
406 |
|
while(false !== ($fichier = readdir($dossier))) { |
407 |
|
|
408 |
|
if($fichier != '.' && $fichier != '..' && !is_dir($fichier)) { |
409 |
|
|
410 |
|
$file_list[]=$fichier; |
411 |
|
} // On ferme le if (qui permet de ne pas afficher index.php, etc.) |
412 |
|
|
413 |
|
} // On termine la boucle |
414 |
|
|
415 |
|
closedir($dossier); |
416 |
|
|
417 |
|
} else { |
418 |
|
$this->displayMessage("error", _("Les documents du dossier ne sont pas accessible.")); |
419 |
|
} |
420 |
|
} else { |
421 |
|
$this->displayMessage("error", _("Ce dossier n'a pas de document.")); |
422 |
|
} |
423 |
|
return $file_list; |
424 |
|
} |
425 |
|
|
426 |
|
/* |
427 |
|
* Store the data recived in the request into a file on the |
428 |
|
* local filesystem. |
429 |
|
* @todo This function will need to be changed for the save to |
430 |
|
* be on GED |
431 |
|
* @param mixed $data The data received with the request |
432 |
|
* @param string $id The consultation ID |
433 |
|
* @return string OK on success, KO otherwise |
434 |
|
*/ |
435 |
|
|
436 |
|
function storeDecisionFile(&$fichier_base64, $basename, $dossier, $prefix = '') { |
437 |
|
|
438 |
|
if (empty($fichier_base64)) { |
439 |
|
$this -> addToMessage("error", _("Le fichier est vide")); |
440 |
|
return false; |
441 |
|
} |
442 |
|
$dir = $this->getPathFolderTrs().$dossier; |
443 |
|
|
444 |
|
// if a file already exists by that name and it |
445 |
|
// is not a directory, back out |
446 |
|
/*if (file_exists($dir) AND is_dir($dir)) { |
447 |
|
$this -> addToMessage("error", _("Le repertoire n'existe pas, le fichier ne peut pas etre enregistre.")); |
448 |
|
return false; |
449 |
|
}*/ |
450 |
|
// if a dirextory by that name exists, make sure it does |
451 |
|
// not already contain an avis de consultation, MAYBE WE DON'T NEED THIS |
452 |
|
if (file_exists($dir) AND is_dir($dir)) { |
453 |
|
$dir_contents = trim(shell_exec('ls '.$dir)); |
454 |
|
if (strpos($dir_contents, ' ') != false) { |
455 |
|
$dir_contents = explode(' ', $dir_contents); |
456 |
|
} else { |
457 |
|
$dir_contents = array($dir_contents); |
458 |
|
} |
459 |
|
foreach ($dir_contents as $basefname) { // very useful for consultation |
460 |
|
if (strpos($basefname, $prefix)!==false) { |
461 |
|
return _("Un retour d'avis existe deja."); |
462 |
|
|
463 |
|
} |
464 |
|
} |
465 |
|
} else { |
466 |
|
return _("Le dossier n'existe pas."); |
467 |
|
} |
468 |
|
// if no file by that name exists, create the directory |
469 |
|
|
470 |
|
if (!file_exists($dir)) { |
471 |
|
if (!mkdir($dir, 0775)) { |
472 |
|
return _("Erreur dans la création de répertoire."); |
473 |
|
} |
474 |
|
} |
475 |
|
|
476 |
|
|
477 |
|
// store the file contents into the file named: |
478 |
|
// consultation_<ID>_<file_name_received> |
479 |
|
$file_len = strlen($fichier_base64); |
480 |
|
|
481 |
|
$filename = $dir."/".$prefix.$basename; |
482 |
|
|
483 |
|
$file = fopen($filename, 'w'); |
484 |
|
if (!$file) { |
485 |
|
return _("Echec a la creation du fichier."); |
486 |
|
} |
487 |
|
// check that the number of bytes written is equal to the length |
488 |
|
// of the data received |
489 |
|
$num_written = fwrite($file, $fichier_base64, $file_len); |
490 |
|
|
491 |
|
if (!$num_written) { |
492 |
|
// remove the file |
493 |
|
// the return value from shell can't be used for checking since |
494 |
|
// one can not know if the NULL returned is because there was no |
495 |
|
// output or because there was an error |
496 |
|
$ret = shell_exec("rm -f $filename 2>&1"); |
497 |
|
//if ($ret == NULL) { // an error occured while deleting the file |
498 |
|
//} |
499 |
|
return _("La sauvegarde du fichier a echoue"); |
500 |
|
} |
501 |
|
fclose($file); |
502 |
|
return true; |
503 |
|
} |
504 |
} |
} |
505 |
|
|
506 |
?> |
?> |