/[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 636 by nhaye, Fri Nov 2 14:24:05 2012 UTC revision 637 by nhaye, Thu Nov 8 17:48:54 2012 UTC
# Line 423  class utils extends application { Line 423  class utils extends application {
423          return $file_list;          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) && 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                        $this -> addToMessage("error", _("Un retour d'avis existe deja."));
462                        return false;
463                    }
464                }
465            }
466            // if no file by that name exists, create the directory
467            
468            if (!file_exists($dir)) {
469                if (!mkdir($dir, 0775)) {
470                    $this -> addToMessage("error", _("Erreur dans la création de répertoire."));
471                    return false;
472                }
473            }
474            
475            
476            // store the file contents into the file named:
477            //      consultation_<ID>_<file_name_received>
478            $file_len = strlen($fichier_base64);
479    
480            $filename = $dir."/".$prefix.$basename;
481    
482            $file = fopen($filename, 'w');
483            if (!$file) {
484                $this -> addToMessage("error", _("Echec a la creation du fichier."));
485                return false;
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                $this -> addToMessage("error", _("La sauvegarde du fichier a echoue"));
493                // remove the file
494                // the return value from shell can't be used for checking since
495                // one can not know if the NULL returned is because there was no
496                // output or because there was an error
497                $ret = shell_exec("rm -f $filename 2>&1");
498                //if ($ret == NULL) { // an error occured while deleting the file
499                //}
500                return false;
501            }
502            fclose($file);
503            $this -> addToMessage("ok",_("Fichier enregistre"));
504            return true;
505        }
506  }  }
507    
508  ?>  ?>

Legend:
Removed from v.636  
changed lines
  Added in v.637

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26