/[openfoncier]/trunk/obj/utils.class.php
ViewVC logotype

Diff of /trunk/obj/utils.class.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 556 by fmichon, Tue Oct 30 15:30:20 2012 UTC revision 675 by nhaye, Tue Nov 13 11:23:15 2012 UTC
# Line 37  require_once PATH_OPENMAIRIE."om_applica Line 37  require_once PATH_OPENMAIRIE."om_applica
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
# Line 471  class utils extends application { Line 380  class utils extends application {
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  ?>  ?>

Legend:
Removed from v.556  
changed lines
  Added in v.675

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26